<commit_before>/* 
 * _HMC_UTIL_C_
 * 
 * HYBRID MEMORY CUBE SIMULATION LIBRARY 
 * 
 * UTILITY FUNCTIONS
 * 
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hmc_sim.h"


/* ----------------------------------------------------- HMCSIM_UTIL_DECODE_BANK */
/* 
 * HMCSIM_UTIL_DECODE_BANK 
 * 
 */
extern int hmcsim_util_decode_bank( 	struct hmcsim_t *hmc, 
					uint32_t dev, 
					uint32_t bsize, 
					uint64_t addr,<commit_msg>adding function to decode vault from address <commit_after>/* 
 * _HMC_UTIL_C_
 * 
 * HYBRID MEMORY CUBE SIMULATION LIBRARY 
 * 
 * UTILITY FUNCTIONS
 * 
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hmc_sim.h"


/* ----------------------------------------------------- HMCSIM_UTIL_DECODE_VAULT */
/* 
 * HMCSIM_UTIL_DECODE_VAULT
 * 
 */
extern int hmcsim_util_decode_vault( 	struct hmcsim_t *hmc, 
					uint32_t dev, 
					uint32_t bsize, 
					uint64_t addr,
					uint32_t *vault )
{
	/* vars */
	uint32_t num_links	= 0x00;
	uint32_t capacity	= 0x00;
	uint32_t tmp		= 0x00;
	/* ---- */

	/*
	 * sanity check 
	 * 
	 */
	if( hmc == NULL ){ 
		return -1;
	}

	num_links	= hmc->num_links;
	capacity	= hmc->capacity;	

	/* 
	 * link layout 
	 * 
	 */
	if( num_links == 4 ){ 
		/* 
	 	 * 4-link device 
		 *
		 */
		if( capacity == 2 ){

			switch( bsize )
			{
				case 32:
					/* [8:5] */
					tmp = (uint32_t)((addr>>5) & 0xF);
					break;
				case 64:
					/* [9:6] */
					tmp = (uint32_t)((addr>>6) & 0xF);
					break;
				case 128:
					/* [10:7] */
					tmp = (uint32_t)((addr>>7) & 0xF);
					break;
				default:
					break;
			}

		} else if( capacity == 4 ){ 

			switch( bsize )
			{
				case 32:
					/* [12:9] */
					tmp = (uint32_t)((addr>>9) & 0xF);
					break;
				case 64:
					/* [13:10] */
					tmp = (uint32_t)((addr>>10) & 0xF);
					break;
				case 128:
					/* [14:11] */
					tmp = (uint32_t)((addr>>11) & 0xF);
					break;
				default:
					break;
			}

		}
	} else if( num_links == 8 ){ 
		/* 
	 	 * 8-link device 
		 *
		 */
		if( capacity == 4 ){
	
			switch( bsize )
			{
				case 32:
					/* [9:5] */
					tmp = (uint32_t)((addr>>5) & 0x7);
					break;
				case 64:
					/* [10:6] */
					tmp = (uint32_t)((addr>>6) & 0x7);
					break;
				case 128:
					/* [11:7] */
					tmp = (uint32_t)((addr>>7) & 0x7);
					break;
				default:
					break;
			}

			
		} else if( capacity == 8 ){ 

			switch( bsize )
			{
				case 32:
					/* [9:5] */
					tmp = (uint32_t)((addr>>5) & 0x1F);
					break;
				case 64:
					/* [10:6] */
					tmp = (uint32_t)((addr>>6) & 0x1F);
					break;
				case 128:
					/* [10:7] */
					tmp = (uint32_t)((addr>>7) & 0xF);
					break;
				default:
					break;
			}

		}
	} else {	
		return -1;
	}

	/* 
	 * write out the value 
	 * 
 	 */
	*vault = tmp;

	return 0;
}

/* ----------------------------------------------------- HMCSIM_UTIL_DECODE_BANK */
/* 
 * HMCSIM_UTIL_DECODE_BANK 
 * 
 */
extern int hmcsim_util_decode_bank( 	struct hmcsim_t *hmc, 
					uint32_t dev, 
					uint32_t bsize, 
					uint64_t addr,
{'fraction_non_alphanumeric': 0.2104746317512275, 'fraction_numerical': 0.05335515548281506, 'mean_word_length': 1.650477016478751, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5418856', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1255, 'n_words': 243}