int addr_randomize(long long int *addr, int numc) { long long int addr_temp=0; long int addr_last_bits=0; unsigned int offset=0; unsigned int columns=0; unsigned int channels=0; unsigned int tablelen=0; long int temp=0; //Apply the random addresses to a total of MAX_TABLE_LEN bits with the last bank bit as the LSB if(ADDRESS_MAPPING==1) { offset=log_base2(CACHE_LINE_SIZE); columns=log_base2(NUM_COLUMNS); channels=log_base2(NUM_CHANNELS); tablelen=log_base2(MAX_TABLE_LEN); temp=1<<(offset+columns+channels); temp=temp-1; addr_last_bits=addr[numc] & temp; addr_temp=addr[numc]>>(offset+columns+channels); temp=1<<tablelen; temp=temp-1; addr_temp=addr_temp & temp; //Extracting the next MAX_TABLE_LEN bits only addr_temp=rand_table[numc][addr_temp]; //Extracted the random address addr[numc]=addr[numc] >> (offset+columns+channels+tablelen); addr[numc]=addr[numc] << tablelen; addr[numc]=addr[numc] | addr_temp; //appended the MAX_TABLE_LEN bits now addr[numc]=addr[numc] << (offset+columns+channels); addr[numc]=addr[numc] | addr_last_bits; //new address }
void set_cache() { int i, n; cache.nsb = log_base2(cache.ns); cache.lsb = log_base2(cache.ls); // tag bits, #tags mapping to each set cache.ntb = MAX_TAG_BITS; cache.nt = 1 << cache.ntb; // tag + set bits, set + line bits, # of tag + set cache.t_sb = cache.ntb + cache.nsb; cache.s_lb = cache.nsb + cache.lsb; cache.nt_s = 1 << cache.t_sb; // cache line mask cache.l_msk = (1 << cache.lsb) - 1; // set mask cache.s_msk = 0; for (i = 1; i < cache.ns; i <<= 1) cache.s_msk |= i; cache.s_msk <<= cache.lsb; // tag mask cache.t_msk = 0; for (i = 1; i < cache.nt; i <<= 1) cache.t_msk |= i; cache.t_msk <<= cache.lsb + cache.nsb; // set+tag mask cache.t_s_msk = cache.t_msk | cache.s_msk; }
void Par_bitonic_sort_decr( int list_size /* in */, KEY_T* local_list /* in/out */, int proc_set_size /* in */, MPI_Comm comm /* in */ ) { unsigned eor_bit; int proc_set_dim; int stage; int partner; int my_rank; MPI_Comm_rank(comm, &my_rank); proc_set_dim = log_base2(proc_set_size); eor_bit = 1 << (proc_set_dim - 1); for (stage = 0; stage < proc_set_dim; stage++) { partner = my_rank ^ eor_bit; if (my_rank > partner) Merge_split(list_size, local_list, LOW, partner, comm); else Merge_split(list_size, local_list, HIGH, partner, comm); eor_bit = eor_bit >> 1; } } /* Par_bitonic_sort_decr */
/* ============================================================================ Function: = Bitonic_sort_decr Purpose: = Use bitonic sort to sort the keys in my_list into = decreasing order. ============================================================================== Input arg: = 1. my_rank: The size of the processors array. = 2. my_list[]: A pointer to an array. = 3. neighbors_list[]: A pointer to an array. = 4. list_size: The size of the processors array. = 5. partner_size: The size of partner pairing. = 6. comm: The mpi communicator channel. ============================================================================== Note: = len is a power of 2 =========================================================================== */ void Bitonic_sort_decr(int my_rank, int my_list[], int neighbors_list[], int list_size, int partner_size, MPI_Comm comm) { unsigned xor_bit; int partner, stage, stage_limit; stage_limit = log_base2(partner_size); xor_bit = 1 << (stage_limit - 1); for(stage = 0; stage < stage_limit; stage++) { partner = my_rank ^ xor_bit; if(my_rank > partner) { Merge_split(1, my_rank, list_size, my_list, neighbors_list, partner, comm); } else { Merge_split(0, my_rank, list_size, my_list, neighbors_list, partner, comm); } xor_bit = xor_bit >> 1; } } /* Bitonic_sort_decr */
/** Same as previous but without SliceIGroup table. */ void PpsSliceGroupHeaderCut(unsigned char *data, int *Position, PPS *pt_pps) { int i; int iGroup; if ( pt_pps -> num_slice_groups_minus1 > 0 ) { pt_pps -> slice_group_map_type = (unsigned char) read_ue(data, Position); if ( pt_pps -> slice_group_map_type == 0 ) for ( iGroup = 0 ; iGroup <= pt_pps -> num_slice_groups_minus1 ; iGroup++ ) pt_pps -> run_length_minus1 [iGroup] = (short) read_ue(data, Position); else if ( pt_pps -> slice_group_map_type == 2 ) for ( iGroup = 0 ; iGroup < pt_pps -> num_slice_groups_minus1 ; iGroup++ ) { pt_pps -> top_left_tab [iGroup] = (short) read_ue(data, Position);// pt_pps -> bottom_right_tab [iGroup] = (short) read_ue(data, Position);// } else if ( pt_pps -> slice_group_map_type == 3 || pt_pps -> slice_group_map_type == 4 || pt_pps -> slice_group_map_type == 5 ) { pt_pps -> slice_group_change_direction_flag = (unsigned char) getNbits(data, Position, 1); pt_pps -> slice_group_change_rate_minus1 = (short) read_ue(data, Position) + 1; } else if ( pt_pps -> slice_group_map_type == 6 ) { short log2_num_slice_groups_minus1 = (short) log_base2(pt_pps -> num_slice_groups_minus1 + 1); short pic_size_in_map_units_minus1 = (short) read_ue(data, Position); for ( i = 0 ; i <= pic_size_in_map_units_minus1 ; i++ ) { getNbits(data, Position, log2_num_slice_groups_minus1); } } } }
struct cache_t *cache_create(char *name, unsigned int num_sets, unsigned int block_size, unsigned int assoc, enum cache_policy_t policy) { struct cache_t *cache; struct cache_block_t *block; unsigned int set, way; /* Create cache */ cache = calloc(1, sizeof(struct cache_t)); if (!cache) fatal("%s: out of memory", __FUNCTION__); /* Name */ cache->name = strdup(name); if (!cache->name) fatal("%s: out of memory", __FUNCTION__); /* Initialize */ cache->num_sets = num_sets; cache->block_size = block_size; cache->assoc = assoc; cache->policy = policy; /* Derived fields */ assert(!(num_sets & (num_sets - 1))); assert(!(block_size & (block_size - 1))); assert(!(assoc & (assoc - 1))); cache->log_block_size = log_base2(block_size); cache->block_mask = block_size - 1; /* Create array of sets */ cache->sets = calloc(num_sets, sizeof(struct cache_set_t)); if (!cache->sets) fatal("%s: out of memory", __FUNCTION__); /* Initialize array of sets */ for (set = 0; set < num_sets; set++) { /* Create array of blocks */ cache->sets[set].blocks = calloc(assoc, sizeof(struct cache_block_t)); if (!cache->sets[set].blocks) fatal("%s: out of memory", __FUNCTION__); /* Initialize array of blocks */ cache->sets[set].way_head = &cache->sets[set].blocks[0]; cache->sets[set].way_tail = &cache->sets[set].blocks[assoc - 1]; for (way = 0; way < assoc; way++) { block = &cache->sets[set].blocks[way]; block->way = way; block->way_prev = way ? &cache->sets[set].blocks[way - 1] : NULL; block->way_next = way < assoc - 1 ? &cache->sets[set].blocks[way + 1] : NULL; } } /* Return it */ return cache; }
struct cache_t *cache_create(char *name, unsigned int num_sets, unsigned int block_size, unsigned int assoc, enum cache_policy_t policy) { struct cache_t *cache; struct cache_block_t *block; unsigned int set, way; /* Initialize */ cache = xcalloc(1, sizeof(struct cache_t)); cache->name = xstrdup(name); cache->num_sets = num_sets; cache->block_size = block_size; cache->assoc = assoc; cache->policy = policy; /* Derived fields */ assert(!(num_sets & (num_sets - 1))); assert(!(block_size & (block_size - 1))); assert(!(assoc & (assoc - 1))); cache->log_block_size = log_base2(block_size); cache->block_mask = block_size - 1; /* Initialize array of sets */ cache->sets = xcalloc(num_sets, sizeof(struct cache_set_t)); for (set = 0; set < num_sets; set++) { /* Initialize array of blocks */ cache->sets[set].blocks = xcalloc(assoc, sizeof(struct cache_block_t)); cache->sets[set].way_head = &cache->sets[set].blocks[0]; cache->sets[set].way_tail = &cache->sets[set].blocks[assoc - 1]; for (way = 0; way < assoc; way++) { block = &cache->sets[set].blocks[way]; block->way = way; block->way_prev = way ? &cache->sets[set].blocks[way - 1] : NULL; block->way_next = way < assoc - 1 ? &cache->sets[set].blocks[way + 1] : NULL; block->core = -1; } // initialize the way split counters for partitioning cache->sets[set].way_split = xcalloc(2, sizeof(int)); cache->sets[set].way_split[0] = 0; cache->sets[set].way_split[1] = 0; } // initialize partitions cache->partitions = xcalloc(2, sizeof(struct cache_part_t)); int core = 0; for(core = 0; core < 2; core++){ cache->partitions[core].ways_alloced = 0; cache->partitions[core].req_bytes = 0; } /* Return it */ return cache; }
/* Stride Prefetcher */ void stride_prefetcher(struct cache_t *cp, md_addr_t addr) { #if 0 int counter = 0; while (pc) { if (pc & 1) printf("1"); else printf("0"); if (counter == 0 && pc&1 != 0 || counter == 1 && pc&1 != 0 || counter == 2 && pc&1 != 0) assert(0); pc >>= 1; counter++; } printf("\n"); #endif #if 1 md_addr_t pc = get_PC(); // The last three bits do not change unsigned int index = (pc >> 3) & (cp->prefetch_type - 1); unsigned int tag = (pc >> (log_base2(cp->prefetch_type) + 3)); #endif // Scenario 1 if (cp->rpt[index].tag != tag) { cp->rpt[index].tag = tag; cp->rpt[index].prev_addr = addr; cp->rpt[index].stride = 0; cp->rpt[index].state = initial; cp->rpt[index].is_neg = 0; } else { // Scenario 2 md_addr_t prev_addr = cp->rpt[index].prev_addr; md_addr_t new_stride = MAX(addr, prev_addr) - MIN(addr, prev_addr); int new_is_neg = prev_addr > addr ? 1 : 0; int stride_condition = new_stride == cp->rpt[index].stride && new_is_neg == cp->rpt[index].is_neg; assert(stride_condition == 1 || stride_condition == 0); cp->rpt[index].state = update_state(cp->rpt[index].state, stride_condition); if (!stride_condition && (cp->rpt[index].state == transient || cp->rpt[index].state== no_prediction)) { cp->rpt[index].stride = new_stride; cp->rpt[index].is_neg = new_is_neg; } cp->rpt[index].prev_addr = addr; if (cp->rpt[index].state != no_prediction) { if (cp->rpt[index].is_neg) { prefetch(cp, addr - cp->rpt[index].stride); } else { prefetch(cp, addr + cp->rpt[index].stride); } } } }
sql_hash * hash_new(sql_allocator *sa, int size, fkeyvalue key) { int i; sql_hash *ht = SA_ZNEW(sa, sql_hash); ht->sa = sa; ht->size = (1<<log_base2(size-1)); ht->key = key; ht->buckets = SA_NEW_ARRAY(sa, sql_hash_e*, ht->size); for(i = 0; i < ht->size; i++) ht->buckets[i] = NULL; return ht; }
//this method is the entrance from cache.c int exthitOrMissFunc(profile_cache* pc, md_addr_t addr) { int i; int setNum=(addr>>log_base2(pc->nbsize))&(pc->nsets-1); int tag=addr>>(log_base2(pc->nbsize)+log_base2(pc->nsets)); for (i = 0; i < pc->dmax; i++) { //hit if (pc->extcache[setNum][i].tag == tag) { // printf("%d ", i); pc->exthitPoint = i; pc->exthitOrMiss = 1; break; } else { //miss pc->exthitOrMiss = 0; } } if (pc->exthitOrMiss == 1) { if(warmup<=0) pc->extnum_hits++; exthitStackShift(pc, setNum, pc->exthitPoint); } else { if(warmup<=0) pc->extnum_misses++; extmissStackShift(pc, setNum, tag); } return pc->exthitOrMiss; }
void render_block(int x, int y, int number) { char str[5]; char border; int i, j; if(number) { border = borders[(log_base2(number)-1) % numborders]; sprintf(str, "%d", number); i = x+2; j = y+2; write_str(i, j, str); } else { border = '.'; } render_border(x, y, border); }
/* create and initialize a general cache structure */ struct cache_t * /* pointer to cache created */ cache_create_mshr(char *name, /* name of the cache */ int nsets, /* total number of sets in cache */ int bsize, /* block (line) size of cache */ int balloc, /* allocate data space for blocks? */ int usize, /* size of user data to alloc w/blks */ int assoc, /* associativity of cache */ enum cache_policy policy, /* replacement policy w/in sets */ /* block access function, see description w/in struct cache def */ unsigned int (*blk_access_fn)(enum mem_cmd cmd, md_addr_t baddr, int bsize, struct cache_blk_t *blk, tick_t now), unsigned int hit_latency,/* latency in cycles for a hit */ unsigned int num_mshr)/*number of MSHRs*/ { struct cache_t *cp; struct cache_blk_t *blk; int i, j, bindex; /* check all cache parameters */ if (nsets <= 0) fatal("cache size (in sets) `%d' must be non-zero", nsets); if ((nsets & (nsets-1)) != 0) fatal("cache size (in sets) `%d' is not a power of two", nsets); /* blocks must be at least one datum large, i.e., 8 bytes for SS */ if (bsize < 8) fatal("cache block size (in bytes) `%d' must be 8 or greater", bsize); if ((bsize & (bsize-1)) != 0) fatal("cache block size (in bytes) `%d' must be a power of two", bsize); if (usize < 0) fatal("user data size (in bytes) `%d' must be a positive value", usize); if (assoc <= 0) fatal("cache associativity `%d' must be non-zero and positive", assoc); if ((assoc & (assoc-1)) != 0) fatal("cache associativity `%d' must be a power of two", assoc); if (!blk_access_fn) fatal("must specify miss/replacement functions"); /* allocate the cache structure */ cp = (struct cache_t *) calloc(1, sizeof(struct cache_t) + (nsets-1)*sizeof(struct cache_set_t)); if (!cp) fatal("out of virtual memory"); /* initialize user parameters */ cp->name = mystrdup(name); cp->nsets = nsets; cp->bsize = bsize; cp->balloc = balloc; cp->usize = usize; cp->assoc = assoc; cp->policy = policy; cp->hit_latency = hit_latency; /* miss/replacement functions */ cp->blk_access_fn = blk_access_fn; /* compute derived parameters */ cp->hsize = CACHE_HIGHLY_ASSOC(cp) ? (assoc >> 2) : 0; cp->blk_mask = bsize-1; cp->set_shift = log_base2(bsize); cp->set_mask = nsets-1; cp->tag_shift = cp->set_shift + log_base2(nsets); cp->tag_mask = (1 << (32 - cp->tag_shift))-1; cp->tagset_mask = ~cp->blk_mask; cp->bus_free = 0; /* start mshr creation */ cp->ready = 0; /* cache ready to be used*/ if (num_mshr > 0) { //printf("mshr created\n"); cp->num_mshr = num_mshr; cp->mshr = (struct cache_mshr_t *) (malloc(sizeof(struct cache_mshr_t) * cp->num_mshr)); } else { cp->num_mshr = -1; /* mshrs infinite */ cp->mshr=NULL; } /* mshr initialization */ for (i=0; i<cp->num_mshr; i++) { cp->mshr[i].block_addr=0; cp->mshr[i].target_num=0; cp->mshr[i].ready=0; } /* end mshr initialization*/ /* print derived parameters during debug */ debug("%s: cp->hsize = %d", cp->name, cp->hsize); debug("%s: cp->blk_mask = 0x%08x", cp->name, cp->blk_mask); debug("%s: cp->set_shift = %d", cp->name, cp->set_shift); debug("%s: cp->set_mask = 0x%08x", cp->name, cp->set_mask); debug("%s: cp->tag_shift = %d", cp->name, cp->tag_shift); debug("%s: cp->tag_mask = 0x%08x", cp->name, cp->tag_mask); /* initialize cache stats */ cp->hits = 0; cp->misses = 0; cp->replacements = 0; cp->writebacks = 0; cp->invalidations = 0; /* initialize mshr stats TODO*/ cp->mshr_accesses = 0; cp->mshr_hits_under_misses = 0; cp->mshr_hit_rate = 0; cp->mshr_full = 0; cp->mshr_target_full = 0; /* blow away the last block accessed */ cp->last_tagset = 0; cp->last_blk = NULL; /* allocate data blocks */ cp->data = (byte_t *)calloc(nsets * assoc, sizeof(struct cache_blk_t) + (cp->balloc ? (bsize*sizeof(byte_t)) : 0)); if (!cp->data) fatal("out of virtual memory"); /* slice up the data blocks */ for (bindex=0,i=0; i<nsets; i++) { cp->sets[i].way_head = NULL; cp->sets[i].way_tail = NULL; /* get a hash table, if needed */ if (cp->hsize) { cp->sets[i].hash = (struct cache_blk_t **)calloc(cp->hsize, sizeof(struct cache_blk_t *)); if (!cp->sets[i].hash) fatal("out of virtual memory"); } /* NOTE: all the blocks in a set *must* be allocated contiguously, otherwise, block accesses through SET->BLKS will fail (used during random replacement selection) */ cp->sets[i].blks = CACHE_BINDEX(cp, cp->data, bindex); /* link the data blocks into ordered way chain and hash table bucket chains, if hash table exists */ for (j=0; j<assoc; j++) { /* locate next cache block */ blk = CACHE_BINDEX(cp, cp->data, bindex); bindex++; /* invalidate new cache block */ blk->status = 0; blk->tag = 0; blk->ready = 0; blk->user_data = (usize != 0 ? (byte_t *)calloc(usize, sizeof(byte_t)) : NULL); /* insert cache block into set hash table */ if (cp->hsize) link_htab_ent(cp, &cp->sets[i], blk); /* insert into head of way list, order is arbitrary at this point */ blk->way_next = cp->sets[i].way_head; blk->way_prev = NULL; if (cp->sets[i].way_head) cp->sets[i].way_head->way_prev = blk; cp->sets[i].way_head = blk; if (!cp->sets[i].way_tail) cp->sets[i].way_tail = blk; } } return cp; }
extern "C" void glui_3dsmoke_setup(int main_window) { int i; if(nsmoke3dinfo<=0&&nvolrenderinfo<=0)return; if(CHECKBOX_meshvisptr!=NULL)FREEMEMORY(CHECKBOX_meshvisptr); NewMemory((void **)&CHECKBOX_meshvisptr,nmeshes*sizeof(GLUI_Checkbox *)); glui_3dsmoke=glui_bounds; if(smoketest==1) { PANEL_testsmoke = glui_3dsmoke->add_panel_to_panel(ROLLOUT_smoke3d,_("Test smoke")); PANEL_testsmoke->set_alignment(GLUI_ALIGN_LEFT); CHECKBOX_show_smoketest=glui_3dsmoke->add_checkbox_to_panel(PANEL_testsmoke,_("Show test smoke"),&show_smoketest); SPINNER_extinct=glui_3dsmoke->add_spinner_to_panel(PANEL_testsmoke,_("Mass extinction coeff (m2/g)"),GLUI_SPINNER_FLOAT,&smoke_extinct,SMOKETEST,Smoke3d_CB); SPINNER_extinct->set_float_limits(0.0,10.0); SPINNER_smokedens=glui_3dsmoke->add_spinner_to_panel(PANEL_testsmoke,_("Smoke density (g/m3)"),GLUI_SPINNER_FLOAT,&smoke_dens,SMOKETEST,Smoke3d_CB); SPINNER_smokedens->set_float_limits(0.0,1.0); SPINNER_pathlength=glui_3dsmoke->add_spinner_to_panel(PANEL_testsmoke,_("Path length (m)"),GLUI_SPINNER_FLOAT,&smoke_pathlength,SMOKETEST,Smoke3d_CB); SPINNER_pathlength->set_float_limits(0.0,20.0); TEXT_smokealpha=glui_3dsmoke->add_statictext_to_panel(PANEL_testsmoke,_("Alpha")); TEXT_smokedepth=glui_3dsmoke->add_statictext_to_panel(PANEL_testsmoke,_("Depth")); update_alpha(); } PANEL_overall = glui_3dsmoke->add_panel_to_panel(ROLLOUT_smoke3d,"",GLUI_PANEL_NONE); #ifdef pp_GPU CHECKBOX_smokeGPU=glui_3dsmoke->add_checkbox_to_panel(PANEL_overall,_("Use GPU"),&usegpu,VOL_SMOKE,Smoke3d_CB); #endif if(active_smokesensors==1) { PANEL_smokesensor = glui_3dsmoke->add_panel_to_panel(PANEL_overall,_("Visibility")); RADIO_smokesensors = glui_3dsmoke->add_radiogroup_to_panel(PANEL_smokesensor,&show_smokesensors); glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,_("Hidden")); glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,_("Grey (0-255)")); glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,"I/I0 (0.0-1.0)"); glui_3dsmoke->add_radiobutton_to_group(RADIO_smokesensors,_("Scaled optical depth (SCD)")); glui_3dsmoke->add_statictext_to_panel(PANEL_smokesensor,"SCD=C/K=C*L/Ln(I/I0) (0-Inf)"); SPINNER_cvis=glui_3dsmoke->add_spinner_to_panel(PANEL_smokesensor,"C",GLUI_SPINNER_FLOAT,&smoke3d_cvis); SPINNER_cvis->set_float_limits(1.0,20.0); #ifdef _DEBUG CHECKBOX_test_smokesensors=glui_3dsmoke->add_checkbox_to_panel(PANEL_smokesensor,"Test visibility sensor",&test_smokesensors); #endif } PANEL_colormap = glui_3dsmoke->add_panel_to_panel(PANEL_overall,_("Color")); glui_3dsmoke->add_checkbox_to_panel(PANEL_colormap,"Show colormap",&show_firecolormap,SHOW_FIRECOLORMAP,Smoke3d_CB); RADIO_use_colormap = glui_3dsmoke->add_radiogroup_to_panel(PANEL_colormap,&firecolormap_type,FIRECOLORMAP_TYPE,Smoke3d_CB); RADIOBUTTON_direct=glui_3dsmoke->add_radiobutton_to_group(RADIO_use_colormap,"Use specified color, opacity, albedo"); RADIOBUTTON_constraint=glui_3dsmoke->add_radiobutton_to_group(RADIO_use_colormap,"Use colormap with constraints"); RADIOBUTTON_noconstraint=glui_3dsmoke->add_radiobutton_to_group(RADIO_use_colormap,"Use colormap without constraints"); ROLLOUT_colormap3 = glui_3dsmoke->add_rollout_to_panel(PANEL_colormap,"fire color/opacity, smoke albedo",false); PANEL_colormap3a = glui_3dsmoke->add_panel_to_panel(ROLLOUT_colormap3,"",GLUI_PANEL_NONE); SPINNER_smoke3d_fire_red=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3a,_("red"),GLUI_SPINNER_INT,&fire_red,FIRE_RED,Smoke3d_CB); SPINNER_smoke3d_fire_red->set_int_limits(0,255); SPINNER_smoke3d_fire_green=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3a,_("green"),GLUI_SPINNER_INT,&fire_green,FIRE_GREEN,Smoke3d_CB); SPINNER_smoke3d_fire_green->set_int_limits(0,255); SPINNER_smoke3d_fire_blue=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3a,_("blue"),GLUI_SPINNER_INT,&fire_blue,FIRE_BLUE,Smoke3d_CB); SPINNER_smoke3d_fire_blue->set_int_limits(0,255); PANEL_colormap3b = glui_3dsmoke->add_panel_to_panel(ROLLOUT_colormap3,"",GLUI_PANEL_NONE); SPINNER_smoke3d_fire_halfdepth=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3b,_("fire half depth (m)"),GLUI_SPINNER_FLOAT,&fire_halfdepth,FIRE_HALFDEPTH,Smoke3d_CB); SPINNER_smoke3d_fire_halfdepth->set_float_limits(0.0,10.0); SPINNER_smoke3d_smoke_albedo=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap3b,_("smoke albedo"),GLUI_SPINNER_FLOAT,&smoke_albedo,SMOKE_SHADE,Smoke3d_CB); SPINNER_smoke3d_smoke_albedo->set_float_limits(0.0,1.0); if(ncolorbars>0) { LISTBOX_smoke_colorbar=glui_3dsmoke->add_listbox_to_panel(ROLLOUT_colormap3,_("colormap:"),&fire_colorbar_index,SMOKE_COLORBAR_LIST,Smoke3d_CB); for(i=0; i<ncolorbars; i++) { colorbardata *cbi; cbi = colorbarinfo + i; cbi->label_ptr=cbi->label; LISTBOX_smoke_colorbar->add_item(i,cbi->label_ptr); } LISTBOX_smoke_colorbar->set_int_val(fire_colorbar_index); } PANEL_colormap2 = glui_3dsmoke->add_panel_to_panel(PANEL_colormap,"",GLUI_PANEL_NONE); #define HRRPUV_CUTOFF_MAX (hrrpuv_max_smv-0.01) PANEL_colormap2b = glui_3dsmoke->add_rollout_to_panel(PANEL_colormap2,"HRRPUV (kW/m3)"); SPINNER_hrrpuv_cutoff=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2b,_("cutoff"),GLUI_SPINNER_FLOAT,&global_hrrpuv_cutoff,GLOBAL_FIRE_CUTOFF,Smoke3d_CB); SPINNER_hrrpuv_cutoff->set_float_limits(0.0,HRRPUV_CUTOFF_MAX); { char label[256]; strcpy(label,"Temperature ("); strcat(label,degC); strcat(label,")"); PANEL_colormap2a = glui_3dsmoke->add_rollout_to_panel(PANEL_colormap2,label); } SPINNER_temperature_min=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2a,_("min"),GLUI_SPINNER_FLOAT, &temperature_min,TEMP_MIN,Smoke3d_CB); SPINNER_temperature_cutoff=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2a,_("cutoff"),GLUI_SPINNER_FLOAT, &temperature_cutoff,TEMP_CUTOFF,Smoke3d_CB); SPINNER_temperature_max=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap2a,_("max"),GLUI_SPINNER_FLOAT, &temperature_max,TEMP_MAX,Smoke3d_CB); Smoke3d_CB(TEMP_MIN); Smoke3d_CB(TEMP_CUTOFF); Smoke3d_CB(TEMP_MAX); if(nsmoke3dinfo>0) { PANEL_meshvis = glui_3dsmoke->add_rollout_to_panel(PANEL_overall,"Mesh Visibility",false); for(i=0; i<nmeshes; i++) { mesh *meshi; meshi = meshinfo + i; glui_3dsmoke->add_checkbox_to_panel(PANEL_meshvis,meshi->label,meshvisptr+i); } } Smoke3d_CB(FIRECOLORMAP_TYPE); glui_3dsmoke->add_column_to_panel(PANEL_overall,false); if(nsmoke3dinfo<=0||nvolrenderinfo<=0) { smoke_render_option=RENDER_SLICE; if(nsmoke3dinfo>0)smoke_render_option=RENDER_SLICE; if(nvolrenderinfo>0)smoke_render_option=RENDER_VOLUME; } // slice render dialog if(nsmoke3dinfo>0) { ROLLOUT_slices = glui_3dsmoke->add_rollout_to_panel(PANEL_overall,_("Slice render settings"),false, SLICERENDER_ROLLOUT, Smoke_Rollout_CB); ADDPROCINFO(smokeprocinfo, nsmokeprocinfo, ROLLOUT_slices, SLICERENDER_ROLLOUT); ROLLOUT_slices->set_alignment(GLUI_ALIGN_LEFT); #ifdef pp_GPU if(gpuactive==0) { usegpu=0; CHECKBOX_smokeGPU->disable(); } #endif #ifdef pp_CULL CHECKBOX_smokecullflag=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,_("Cull hidden slices"),&cullsmoke,CULL_SMOKE,Smoke3d_CB); if(cullactive==0) { cullsmoke=0; CHECKBOX_smokecullflag->disable(); } CHECKBOX_show_cullports=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,_("Show cull ports"),&show_cullports); SPINNER_cull_portsize=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,_("Cull port size"),GLUI_SPINNER_INT,&cull_portsize,CULL_PORTSIZE,Smoke3d_CB); { int ijk_max=0; for(i=0; i<nmeshes; i++) { mesh *meshi; meshi = meshinfo + i; if(ijk_max<meshi->ibar+1)ijk_max=meshi->ibar+1; if(ijk_max<meshi->jbar+1)ijk_max=meshi->jbar+1; if(ijk_max<meshi->kbar+1)ijk_max=meshi->kbar+1; } SPINNER_cull_portsize->set_int_limits(3,ijk_max); } #else CHECKBOX_smokecullflag=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,"Cull hidden slices",&smokecullflag); #endif #ifdef _DEBUG CHECKBOX_smokedrawtest=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,"Show only back slices",&smokedrawtest); CHECKBOX_smokedrawtest2=glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_slices,"Show only X slices",&smokedrawtest2); SPINNER_smokedrawtest_nummin=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,"Back slice",GLUI_SPINNER_INT,&smokedrawtest_nummin); SPINNER_smokedrawtest_nummin->set_int_limits(1,ijkbarmax); SPINNER_smokedrawtest_nummax=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,"Front slice",GLUI_SPINNER_INT,&smokedrawtest_nummax); SPINNER_smokedrawtest_nummax->set_int_limits(1,ijkbarmax); #endif RADIO_skipframes = glui_3dsmoke->add_radiogroup_to_panel(ROLLOUT_slices,&smokeskipm1); glui_3dsmoke->add_radiobutton_to_group(RADIO_skipframes,_("Display all")); glui_3dsmoke->add_radiobutton_to_group(RADIO_skipframes,_(" ... Every 2nd")); glui_3dsmoke->add_radiobutton_to_group(RADIO_skipframes,_(" ... Every 3rd")); #ifdef pp_GPU SPINNER_smoke3d_rthick=glui_3dsmoke->add_spinner_to_panel(ROLLOUT_slices,_("Thickness"), GLUI_SPINNER_FLOAT,&smoke3d_rthick,SMOKE_RTHICK,Smoke3d_CB); SPINNER_smoke3d_rthick->set_float_limits(1.0,255.0); smoke3d_thick = log_base2(smoke3d_rthick); #else SPINNER_smoke3d_thick=glui_3dsmoke->add_spinner_to_panel(PANEL_colormap,"Thickness", GLUI_SPINNER_INT,&smoke3d_thick,SMOKE_THICK,Smoke3d_CB); SPINNER_smoke3d_thick->set_int_limits(0,7); #endif PANEL_absorption = glui_3dsmoke->add_panel_to_panel(ROLLOUT_slices,_("Absorption adjustments")); PANEL_absorption->set_alignment(GLUI_ALIGN_LEFT); RADIO_alpha = glui_3dsmoke->add_radiogroup_to_panel(PANEL_absorption,&adjustalphaflag); glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("None")); glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("adjust off-center")); glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("zero at boundaries")); glui_3dsmoke->add_radiobutton_to_group(RADIO_alpha,_("both")); } // volume render dialog if(nvolrenderinfo > 0) { ROLLOUT_volume = glui_3dsmoke->add_rollout_to_panel(PANEL_overall, _("Volume render settings"), false, VOLRENDER_ROLLOUT, Smoke_Rollout_CB); ADDPROCINFO(smokeprocinfo, nsmokeprocinfo, ROLLOUT_volume, VOLRENDER_ROLLOUT); if(have_volcompressed == 1) { RADIO_loadvol = glui_3dsmoke->add_radiogroup_to_panel(ROLLOUT_volume, &glui_load_volcompressed, LOAD_COMPRESSED_DATA, Smoke3d_CB); glui_3dsmoke->add_radiobutton_to_group(RADIO_loadvol, _("Load full data")); glui_3dsmoke->add_radiobutton_to_group(RADIO_loadvol, _("Load compressed data")); } glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Load data in background"), &use_multi_threading); CHECKBOX_compress_volsmoke = glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Compress data while loading"), &glui_compress_volsmoke); if(have_volcompressed == 1) { Smoke3d_CB(LOAD_COMPRESSED_DATA); } glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Display data as b/w"), &volbw); glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Show data while moving scene"), &show_volsmoke_moving); glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Load data only at render times"), &load_at_rendertimes); SPINNER_fire_opacity_factor = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("Fire opacity multiplier"), GLUI_SPINNER_FLOAT, &fire_opacity_factor); SPINNER_fire_opacity_factor->set_float_limits(1.0, 10.0); SPINNER_mass_extinct = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("Mass extinction coeff"), GLUI_SPINNER_FLOAT, &mass_extinct); SPINNER_mass_extinct->set_float_limits(100.0, 100000.0); glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Freeze"), &freeze_volsmoke); #ifdef _DEBUG CHECKBOX_usevolrender = glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Show"), &usevolrender, VOL_SMOKE, Smoke3d_CB); glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, "block smoke", &block_volsmoke); glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, "debug", &smoke3dVoldebug); #endif CHECKBOX_combine_meshes = glui_3dsmoke->add_checkbox_to_panel(ROLLOUT_volume, _("Combine meshes"), &combine_meshes, COMBINE_MESHES, Smoke3d_CB); SPINNER_nongpu_vol_factor = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("non-gpu grid multiplier"), GLUI_SPINNER_FLOAT, &nongpu_vol_factor, NONGPU_VOL_FACTOR, Smoke3d_CB); SPINNER_nongpu_vol_factor->set_float_limits(1.0, 10.0); SPINNER_gpu_vol_factor = glui_3dsmoke->add_spinner_to_panel(ROLLOUT_volume, _("gpu grid multiplier"), GLUI_SPINNER_FLOAT, &gpu_vol_factor, GPU_VOL_FACTOR, Smoke3d_CB); SPINNER_gpu_vol_factor->set_float_limits(1.0, 10.0); PANEL_generate_images = glui_3dsmoke->add_rollout_to_panel(ROLLOUT_volume, _("Generate images"), false); SPINNER_startframe = glui_3dsmoke->add_spinner_to_panel(PANEL_generate_images, _("start frame"), GLUI_SPINNER_INT, &vol_startframe0, START_FRAME, Smoke3d_CB); SPINNER_skipframe = glui_3dsmoke->add_spinner_to_panel(PANEL_generate_images, _("skip frame"), GLUI_SPINNER_INT, &vol_skipframe0, SKIP_FRAME, Smoke3d_CB); Smoke3d_CB(START_FRAME); Smoke3d_CB(SKIP_FRAME); if(ntours > 0) { selectedtour_index = -1; selectedtour_index_old = -1; LISTBOX_VOL_tour = glui_3dsmoke->add_listbox_to_panel(PANEL_generate_images, "Tour:", &selectedtour_index, VOL_TOUR_LIST, Smoke3d_CB); LISTBOX_VOL_tour->add_item(-1, "Manual"); LISTBOX_VOL_tour->add_item(-999, "-"); for(i = 0; i < ntours; i++) { tourdata *touri; touri = tourinfo + i; LISTBOX_VOL_tour->add_item(i, touri->label); } LISTBOX_VOL_tour->set_int_val(selectedtour_index); } strcpy(vol_prefix, fdsprefix); EDIT_vol_prefix = glui_3dsmoke->add_edittext_to_panel(PANEL_generate_images, "image prefix:", GLUI_EDITTEXT_TEXT, vol_prefix, VOL_PREFIX, Smoke3d_CB); EDIT_vol_prefix->set_w(200); BUTTON_startrender = glui_3dsmoke->add_button_to_panel(PANEL_generate_images, _("Generate images"), GENERATE_IMAGES, Smoke3d_CB); BUTTON_cancelrender = glui_3dsmoke->add_button_to_panel(PANEL_generate_images, _("Cancel"), CANCEL_GENERATE_IMAGES, Smoke3d_CB); BUTTON_volunload = glui_3dsmoke->add_button_to_panel(PANEL_generate_images, _("Unload"), VOL_UNLOAD_ALL, Smoke3d_CB); } Update_Smoke_Type(); #ifdef pp_GPU Smoke3d_CB(VOL_SMOKE); #endif Smoke3d_CB(SMOKE_OPTIONS); }
extern "C" void Smoke3d_CB(int var) { int i; char *tour_label; char *vol_prefixptr; updatemenu=1; switch(var) { float temp_min, temp_max; case VOL_UNLOAD_ALL: UnLoadVolSmoke3DMenu(-1); break; case VOL_PREFIX: break; case VOL_TOUR_LIST: TOUR_CB(TOUR_LIST); break; case START_FRAME: if(vol_startframe0<0) { vol_startframe0=0; SPINNER_startframe->set_int_val(vol_startframe0); } break; case SKIP_FRAME: if(vol_skipframe0<1) { vol_skipframe0=1; SPINNER_skipframe->set_int_val(vol_skipframe0); } break; case CANCEL_GENERATE_IMAGES: Script_CB(SCRIPT_CANCEL_NOW); break; case GENERATE_IMAGES: if(selected_tour==NULL) { tour_label=NULL; } else { tour_label=selected_tour->label; } trim(vol_prefix); vol_prefixptr=trim_front(vol_prefix); if(strlen(vol_prefixptr)==0)vol_prefixptr=fdsprefix; init_volrender_script(vol_prefixptr, tour_label, vol_startframe0, vol_skipframe0); break; case NONGPU_VOL_FACTOR: init_volrender_surface(NOT_FIRSTCALL); break; case GPU_VOL_FACTOR: break; case COMBINE_MESHES: define_volsmoke_textures(); break; case SHOW_FIRECOLORMAP: Update_Smokecolormap(smoke_render_option); if(show_firecolormap==1) { show_glui_colorbar(); } else { hide_glui_colorbar(); } break; case TEMP_MIN: temp_min = 20.0; temp_max = (float)(10.0*(int)(temperature_cutoff/10.0)-10.0); SPINNER_temperature_min->set_float_limits(temp_min,temp_max); Update_Smokecolormap(smoke_render_option); break; case TEMP_CUTOFF: temp_min = (float)(10*(int)(temperature_min/10.0) + 10.0); temp_max = (float)(10*(int)(temperature_max/10.0) - 10.0); SPINNER_temperature_cutoff->set_float_limits(temp_min,temp_max); Update_Smokecolormap(smoke_render_option); break; case TEMP_MAX: temp_min = (float)(10*(int)(temperature_cutoff/10.0)+10.0); temp_max = 1800.0; SPINNER_temperature_max->set_float_limits(temp_min,temp_max); Update_Smokecolormap(smoke_render_option); break; case LOAD_COMPRESSED_DATA: if(load_volcompressed==1) { CHECKBOX_compress_volsmoke->disable(); } else { CHECKBOX_compress_volsmoke->enable(); } break; case SMOKE_OPTIONS: if(firecolormap_type!=FIRECOLORMAP_NOCONSTRAINT&&smoke_render_option==RENDER_SLICE) { PANEL_colormap2b->enable(); SPINNER_hrrpuv_cutoff->enable(); PANEL_colormap2b->open(); } else { PANEL_colormap2b->disable(); PANEL_colormap2b->close(); } if(smoke_render_option==RENDER_SLICE) { if(PANEL_colormap2a!=NULL) { PANEL_colormap2a->disable(); PANEL_colormap2a->close(); } if(PANEL_absorption!=NULL)PANEL_absorption->enable(); firecolormap_type=firecolormap_type_save; RADIO_use_colormap->set_int_val(firecolormap_type); RADIOBUTTON_direct->enable(); SPINNER_smoke3d_fire_halfdepth->enable(); } else { if(PANEL_colormap2a!=NULL) { PANEL_colormap2a->enable(); PANEL_colormap2a->open(); } if(PANEL_absorption!=NULL)PANEL_absorption->disable(); firecolormap_type_save=firecolormap_type; firecolormap_type=FIRECOLORMAP_CONSTRAINT; RADIO_use_colormap->set_int_val(firecolormap_type); RADIOBUTTON_direct->disable(); SPINNER_smoke3d_fire_halfdepth->disable(); } Smoke3d_CB(FIRECOLORMAP_TYPE); Update_Smoke_Type(); break; case FIRECOLORMAP_TYPE: if(firecolormap_type==FIRECOLORMAP_CONSTRAINT&&smoke_render_option==RENDER_VOLUME) { PANEL_colormap2a->open(); PANEL_colormap2a->enable(); } else { PANEL_colormap2a->close(); PANEL_colormap2a->disable(); } if(firecolormap_type!=FIRECOLORMAP_NOCONSTRAINT&&smoke_render_option==RENDER_SLICE) { PANEL_colormap2b->enable(); SPINNER_hrrpuv_cutoff->enable(); PANEL_colormap2b->open(); } else { PANEL_colormap2b->disable(); PANEL_colormap2b->close(); } if(firecolormap_type!=FIRECOLORMAP_DIRECT) { LISTBOX_smoke_colorbar->enable(); ROLLOUT_colormap3->disable(); ROLLOUT_colormap3->close(); if(fire_colorbar_index_save!=-1) { SmokeColorBarMenu(fire_colorbar_index_save); } else { SmokeColorBarMenu(fire_colorbar_index); } } else { LISTBOX_smoke_colorbar->disable(); ROLLOUT_colormap3->enable(); ROLLOUT_colormap3->open(); SPINNER_smoke3d_smoke_albedo->enable(); SPINNER_smoke3d_fire_red->enable(); SPINNER_smoke3d_fire_green->enable(); SPINNER_smoke3d_fire_blue->enable(); SPINNER_smoke3d_fire_halfdepth->enable(); fire_colorbar_index_save=fire_colorbar_index; } if(LISTBOX_smoke_colorbar->get_int_val()!=fire_colorbar_index) { LISTBOX_smoke_colorbar->set_int_val(fire_colorbar_index); } Update_Smokecolormap(smoke_render_option); break; case SMOKE_COLORBAR_LIST: SmokeColorBarMenu(fire_colorbar_index); Update_Smokecolormap(smoke_render_option); updatemenu=1; break; case SMOKETEST: update_alpha(); break; case FRAMELOADING: smoke3dframestep = smoke3dframeskip+1; updatemenu=1; break; case SAVE_SETTINGS: writeini(LOCAL_INI,NULL); break; case GLOBAL_FIRE_CUTOFF: glutPostRedisplay(); force_redisplay=1; Idle_CB(); Update_Smokecolormap(smoke_render_option); break; case FIRE_RED: case FIRE_GREEN: case FIRE_BLUE: case SMOKE_SHADE: glutPostRedisplay(); force_redisplay=1; Update_Smokecolormap(smoke_render_option); Idle_CB(); break; case FIRE_HALFDEPTH: for(i=0; i<nmeshes; i++) { mesh *meshi; meshi = meshinfo + i; meshi->update_firehalfdepth=1; } glutPostRedisplay(); force_redisplay=1; Update_Smokecolormap(smoke_render_option); Idle_CB(); break; #ifdef pp_GPU case SMOKE_RTHICK: smoke3d_thick = log_base2(smoke3d_rthick); glutPostRedisplay(); force_redisplay=1; Idle_CB(); break; #else case SMOKE_THICK: glutPostRedisplay(); force_redisplay=1; Idle_CB(); break; #endif #ifdef pp_CULL case CULL_PORTSIZE: initcull(cullsmoke); break; case CULL_SMOKE: initcull(cullsmoke); break; #endif case VOL_NGRID: glutPostRedisplay(); break; case VOL_SMOKE: { volrenderdata *vr; vr = &meshinfo->volrenderinfo; if(vr!=NULL&&vr->smokeslice!=NULL&&vr->smokeslice->slicetype==SLICE_CENTER) { if(usegpu==1&&combine_meshes==1) { combine_meshes=0; update_combine_meshes(); Smoke3d_CB(COMBINE_MESHES); } if(usegpu==0&&combine_meshes==0) { combine_meshes=1; update_combine_meshes(); Smoke3d_CB(COMBINE_MESHES); } } } if(smoke_render_option==RENDER_SLICE) { #ifdef pp_GPU if(usegpu==1) { RADIO_skipframes->set_int_val(0); RADIO_skipframes->disable(); #ifdef pp_CULL if(cullactive==1) { CHECKBOX_smokecullflag->enable(); } SPINNER_cull_portsize->enable(); CHECKBOX_show_cullports->enable(); #endif } else { RADIO_skipframes->enable(); #ifdef pp_CULL CHECKBOX_smokecullflag->disable(); SPINNER_cull_portsize->disable(); CHECKBOX_show_cullports->disable(); #endif } #else RADIO_skipframes->enable(); #endif } break; default: #ifdef _DEBUG abort(); #endif break; } }
/* Open Ended Prefetcher */ void open_ended_prefetcher(struct cache_t *cp, md_addr_t addr) { md_addr_t pc = get_PC(); // The last three bits do not change unsigned int index = (pc >> 3) & (DEFAULT_RPT_SIZE - 1); unsigned int tag = (pc >> (log_base2(DEFAULT_RPT_SIZE) + 3)); assert(index >= 0 && index < rdim); //unsigned int hist_index = (cp->prev_hist_addr & (rdim - 1)); //unsigned int hist_tag = cp->prev_hist_addr >> log_base2(rdim); // Scenario 1 if (cp->rpt[index].tag != tag) { cp->rpt[index].tag = tag; cp->rpt[index].prev_addr = addr; cp->rpt[index].stride = 0; cp->rpt[index].state = initial; cp->rpt[index].is_neg = 0; history_push_back(cp, addr, index, tag); return; //if (cp->prev_hist_addr != 0) //history_push_back(cp, addr, hist_index, hist_tag); } else { // Scenario 2 md_addr_t prev_addr = cp->rpt[index].prev_addr; md_addr_t new_stride = MAX(addr, prev_addr) - MIN(addr, prev_addr); int new_is_neg = prev_addr > addr ? 1 : 0; int stride_condition = new_stride == cp->rpt[index].stride && new_is_neg == cp->rpt[index].is_neg; assert(stride_condition == 1 || stride_condition == 0); cp->rpt[index].state = update_state(cp->rpt[index].state, stride_condition); if (!stride_condition && (cp->rpt[index].state == transient || cp->rpt[index].state== no_prediction)) { cp->rpt[index].stride = new_stride; cp->rpt[index].is_neg = new_is_neg; } cp->rpt[index].prev_addr = addr; if (cp->rpt[index].state != no_prediction) { if (cp->rpt[index].is_neg) { prefetch(cp, addr - cp->rpt[index].stride); } else { prefetch(cp, addr + cp->rpt[index].stride); } } else { int i; for (i = cp->idx[index] - 2; i >= 0; i--) { if (cp->ht[index][i] == addr) { prefetch(cp, cp->ht[index][i + 1]); break; } } //if (cp->idx[hist_index] - 1 >= 0) { //prefetch(cp, cp->ht[hist_index][cp->idx[hist_index] - 1]); //} } //if (cp->prev_hist_addr != 0) //history_push_back(cp, addr, hist_index, hist_tag); } history_push_back(cp, addr, index, tag); //cp->prev_hist_addr = addr; }
static void introsort(int *a, int n) { introsort_loop(a, n, 2 * log_base2(n)); insertion_sort(a, n); }
struct dram_system_t *dram_system_config_with_file(struct config_t *config, char *system_name) { int j; int controller_sections = 0; unsigned int highest_addr = 0; char *section; char section_str[MAX_STRING_SIZE]; char *row_buffer_policy_map[] = {"OpenPage", "ClosePage", "hybird"}; char *scheduling_policy_map[] = {"RankBank", "BankRank"}; struct dram_system_t *system; /* Controller parameters * FIXME: we should create a default variation for times this values * are not assigned. For now we set it as DRAM DDR3 Micron * */ unsigned int num_physical_channels = 1; unsigned int request_queue_depth = 32; enum dram_controller_row_buffer_policy_t rb_policy = open_page_row_buffer_policy; enum dram_controller_scheduling_policy_t scheduling_policy = rank_bank_round_robin; unsigned int dram_num_ranks = 8; unsigned int dram_num_devices_per_rank = 1; unsigned int dram_num_banks_per_device = 1; unsigned int dram_num_rows_per_bank = 8192; unsigned int dram_num_columns_per_row = 1024; unsigned int dram_num_bits_per_column = 16; unsigned int dram_timing_tCAS = 24; unsigned int dram_timing_tRCD = 10; unsigned int dram_timing_tRP = 10; unsigned int dram_timing_tRAS = 24; unsigned int dram_timing_tCWL = 9; unsigned int dram_timing_tCCD = 4; system = dram_system_create(system_name); /* DRAM system configuration */ snprintf(section_str, sizeof section_str, "DRAMsystem.%s", system_name); for (section = config_section_first(config); section; section = config_section_next(config)) { if (strcasecmp(section, section_str)) continue; system->num_logical_channels = config_read_int(config, section, "NumLogicalChannels", system->num_logical_channels); } /* Create controllers */ for (section = config_section_first(config); section; section = config_section_next(config)) { char *delim = "."; char *token; char *controller_name; /* First token must be 'Network' */ snprintf(section_str, sizeof section_str, "%s", section); token = strtok(section_str, delim); if (!token || strcasecmp(token, "DRAMsystem")) continue; /* Second token must be the name of the network */ token = strtok(NULL, delim); if (!token || strcasecmp(token, system_name)) continue; /* Third token must be 'Node' */ token = strtok(NULL, delim); if (!token || strcasecmp(token, "Controller")) continue; /* Get name */ controller_name = strtok(NULL, delim); token = strtok(NULL, delim); if (!controller_name || token) fatal("%s:%s: wrong format for controller name .\n%s", system->name, section, dram_err_config); /* Read Properties */ num_physical_channels = config_read_int(config, section, "NumPhysicalChannels", num_physical_channels); dram_num_ranks = config_read_int(config, section, "NumRanks", dram_num_ranks); dram_num_devices_per_rank = config_read_int(config, section, "NumDevicesPerRank", dram_num_devices_per_rank); dram_num_banks_per_device = config_read_int(config, section, "NumBanksPerDevice", dram_num_banks_per_device); dram_num_rows_per_bank = config_read_int(config, section, "NumRowsPerBank", dram_num_rows_per_bank); dram_num_columns_per_row = config_read_int(config, section, "NumColumnPerRow", dram_num_columns_per_row); dram_num_bits_per_column = config_read_int(config, section, "NumBitsPerColumn", dram_num_bits_per_column); request_queue_depth = config_read_int(config, section, "RequestQueueDepth", request_queue_depth); rb_policy = config_read_enum(config, section, "RowBufferPolicy", rb_policy, row_buffer_policy_map, 3); scheduling_policy = config_read_enum(config, section, "SchedulingPolicy", scheduling_policy, scheduling_policy_map, 2); dram_timing_tCAS = config_read_int(config, section, "tCAS", dram_timing_tCAS); dram_timing_tRCD = config_read_int(config, section, "tRCD", dram_timing_tRCD); dram_timing_tRP = config_read_int(config, section, "tRP", dram_timing_tRP); dram_timing_tRAS = config_read_int(config, section, "tRAS", dram_timing_tRAS); dram_timing_tCWL = config_read_int(config, section, "tCWL", dram_timing_tCWL); dram_timing_tCCD = config_read_int(config, section, "tCCD", dram_timing_tCCD); /* Create controller */ struct dram_controller_t *controller; controller = dram_controller_create(request_queue_depth, rb_policy, scheduling_policy); /* Assign controller parameters */ controller->id = controller_sections; if (!controller_sections) controller->lowest_addr = 0; else controller->lowest_addr = highest_addr + 1; controller->highest_addr = controller->lowest_addr + ((dram_num_bits_per_column * dram_num_devices_per_rank) / 8 * dram_num_columns_per_row * dram_num_rows_per_bank * dram_num_banks_per_device * dram_num_ranks * num_physical_channels) - 1; controller->dram_addr_bits_rank = log_base2(dram_num_ranks); controller->dram_addr_bits_row = log_base2(dram_num_rows_per_bank); controller->dram_addr_bits_bank = log_base2(dram_num_banks_per_device); controller->dram_addr_bits_column = log_base2(dram_num_columns_per_row); controller->dram_addr_bits_physical_channel = log_base2(num_physical_channels); controller->dram_addr_bits_byte = log_base2(dram_num_bits_per_column * dram_num_devices_per_rank / 8); controller->dram_timing_tCAS = dram_timing_tCAS; controller->dram_timing_tRCD = dram_timing_tRCD; controller->dram_timing_tRP = dram_timing_tRP; controller->dram_timing_tRAS = dram_timing_tRAS; controller->dram_timing_tCWL = dram_timing_tCWL; controller->dram_timing_tCCD = dram_timing_tCCD; /* Update the highest address in memory system */ highest_addr = controller->highest_addr; /* Add controller to system */ list_add(system->dram_controller_list, controller); /* Create and add DRAM*/ for (j = 0; j < num_physical_channels; j++) { struct dram_t *dram; dram = dram_create(dram_num_ranks, dram_num_devices_per_rank, dram_num_banks_per_device, dram_num_rows_per_bank, dram_num_columns_per_row, dram_num_bits_per_column); dram->timing_tCAS = dram_timing_tCAS; dram->timing_tRCD = dram_timing_tRCD; dram->timing_tRP = dram_timing_tRP; dram->timing_tRAS = dram_timing_tRAS; dram->timing_tCWL = dram_timing_tCWL; dram_controller_add_dram(list_get(system->dram_controller_list, controller_sections), dram); } controller_sections++; } if (controller_sections != system->num_logical_channels) fatal("%s: number of controllers should match the number of logical" "channels \n%s", system->name, dram_err_config); /* Request Section */ for (section = config_section_first(config); section; section = config_section_next(config)) { char *delim = "."; char *token; char *token_endl; /* First token must be 'Network' */ snprintf(section_str, sizeof section_str, "%s", section); token = strtok(section_str, delim); if (!token || strcasecmp(token, "DRAMsystem")) continue; /* Second token must be the name of the network */ token = strtok(NULL, delim); if (!token || strcasecmp(token, system_name)) continue; /* Third token must be 'Commands' */ token = strtok(NULL, delim); if (!token || strcasecmp(token, "Requests")) continue; token_endl = strtok(NULL, delim); if (token_endl) fatal("%s: %s: bad format for Commands section.\n%s", system_name, section, dram_err_config); /* Requests */ dram_config_request_create(system, config, section); config_check(config); } /* Return dram_system on success */ return system; }
static void sim_check_options(struct opt_odb_t *odb, /* options database */ int argc, char **argv) /* command line arguments */ { char name[128], c; if (ruu_ifq_size < 1 || (ruu_ifq_size & (ruu_ifq_size - 1)) != 0) fatal("inst fetch queue size must be positive > 0 and a power of two"); pipe_ibuf_size = ruu_ifq_size; fetch_width = ruu_decode_width * fetch_speed; //if (ruu_branch_penalty < 1) // fatal("mis-prediction penalty must be at least 1 cycle"); if (!mystricmp(pred_type, "perfect")) { /* perfect predictor */ bpred_scheme = NO_BPRED; } #if 0 else if (!mystricmp(pred_type, "taken")) { /* static predictor, not taken */ //pred = bpred_create(BPredTaken, 0, 0, 0, 0, 0, 0, 0, 0, 0); } else if (!mystricmp(pred_type, "nottaken")) { /* static predictor, taken */ //pred = bpred_create(BPredNotTaken, 0, 0, 0, 0, 0, 0, 0, 0, 0); } #endif else if (!mystricmp(pred_type, "bimod")) { /* bimodal predictor, bpred_create() checks BTB_SIZE */ if (bimod_nelt != 1) fatal("bad bimod predictor config (<table_size>)"); if (btb_nelt != 2) fatal("bad btb config (<num_sets> <associativity>)"); bpred_scheme = LOCAL; BHT_SIZE = btb_config[0]; BHT = log_base2(BHT_SIZE); BHT_MSK = BHT_SIZE - 1; } else if (!mystricmp(pred_type, "2lev")) { if (twolev_nelt != 4) fatal("bad 2-level pred config (<l1size> <l2size> <hist_size> <xor>)"); if (btb_nelt != 2) fatal("bad btb config (<num_sets> <associativity>)"); if ((twolev_config[1] & (twolev_config[1] - 1)) != 0) fatal("Branch History Table (BHT) size %d is not power of 2!\n", twolev_config[1]); if ((twolev_config[2] < 0) || (twolev_config[2] > 4)) fatal("Branch History Register (BHR) bits %d is not within [0, 4]\n", twolev_config[2]); if (twolev_config[2] == 0) bpred_scheme = LOCAL; if (twolev_config[3] == FALSE) bpred_scheme = GAG; else bpred_scheme = GSHARE; BHT_SIZE = twolev_config[1]; BHT = log_base2(BHT_SIZE); BHT_MSK = BHT_SIZE - 1; BHR = twolev_config[2]; BHR_PWR = 1 << BHR; BHR_MSK = BHR_PWR - 1; if ( (1 << BHR) > BHT_SIZE) fatal("The combination of Branch History Register (BHR) bits %d and \nBranch History Table size %d is invalid because 2^BHR > BHT \n", BHR, BHT_SIZE); } #if 0 else if (!mystricmp(pred_type, "comb")) { /* combining predictor, bpred_create() checks args */ if (twolev_nelt != 4) fatal("bad 2-level pred config (<l1size> <l2size> <hist_size> <xor>)"); if (bimod_nelt != 1) fatal("bad bimod predictor config (<table_size>)"); if (comb_nelt != 1) fatal("bad combining predictor config (<meta_table_size>)"); if (btb_nelt != 2) fatal("bad btb config (<num_sets> <associativity>)"); pred = bpred_create(BPredComb, /* bimod table size */bimod_config[0], /* l1 size */twolev_config[0], /* l2 size */twolev_config[1], /* meta table size */comb_config[0], /* history reg size */twolev_config[2], /* history xor address */twolev_config[3], /* btb sets */btb_config[0], /* btb assoc */btb_config[1], /* ret-addr stack size */ras_size); } #endif else fatal("cannot parse predictor type `%s'", pred_type); #if 0 if (ruu_decode_width < 1 || (ruu_decode_width & (ruu_decode_width-1)) != 0) fatal("issue width must be positive non-zero and a power of two"); if (ruu_issue_width < 1 || (ruu_issue_width & (ruu_issue_width-1)) != 0) fatal("issue width must be positive non-zero and a power of two"); if (ruu_commit_width < 1) fatal("commit width must be positive non-zero"); #endif if (RUU_size < 2) fatal("Re-order buffer size must be greater than one!"); pipe_iwin_size = RUU_size; PROLOG_SIZE = pipe_iwin_size + pipe_ibuf_size; EPILOG_SIZE = pipe_iwin_size * 2; LSQ_size = pipe_iwin_size; #if 0 if (LSQ_size < 2 || (LSQ_size & (LSQ_size-1)) != 0) fatal("LSQ size must be a positive number > 1 and a power of two"); #endif /* use a level 1 D-cache? */ if (!mystricmp(cache_dl1_opt, "none")) { #if 0 cache_dl1 = NULL; #endif enable_dcache = enable_scp_dcache = 0; /* the level 2 D-cache cannot be defined */ if (strcmp(cache_dl2_opt, "none")) fatal("the l1 data cache must defined if the l2 cache is defined"); #if 0 cache_dl2 = NULL; #endif } else /* dl1 is defined */ { enable_scp_dcache = 1; if (sscanf(cache_dl1_opt, "%[^:]:%d:%d:%d:%c", name, &nsets_dl1, &bsize_dl1, &assoc_dl1, &c) != 5) fatal("bad l1 D-cache parms: <name>:<nsets>:<bsize>:<assoc>:<repl>"); /* sudiptac ::: enable level 1 data cache analysis */ enable_dcache = 1; #if 0 cache_dl1 = cache_create(name, nsets, bsize, /* balloc */FALSE, /* usize */0, assoc, cache_char2policy(c), dl1_access_fn, /* hit lat */cache_dl1_lat); #endif /* is the level 2 D-cache defined? */ if (!mystricmp(cache_dl2_opt, "none")) enable_ul2cache = 0; #if 0 cache_dl2 = NULL; #endif else { if (sscanf(cache_dl2_opt, "%[^:]:%d:%d:%d:%c", name, &nsets_dl2, &bsize_dl2, &assoc_dl2, &c) != 5) fatal("bad l2 D-cache parms: " "<name>:<nsets>:<bsize>:<assoc>:<repl>"); enable_scp_dl2cache = 1; } }
/* create and initialize a general cache structure */ struct cache_t * /* pointer to cache created */ cache_create(char *name, /* name of the cache */ int nsets, /* total number of sets in cache */ int bsize, /* block (line) size of cache */ int balloc, /* allocate data space for blocks? */ int usize, /* size of user data to alloc w/blks */ int assoc, /* associativity of cache */ enum cache_policy policy, /* replacement policy w/in sets */ /* block access function, see description w/in struct cache def */ unsigned int (*blk_access_fn)(enum mem_cmd cmd, md_addr_t baddr, int bsize, struct cache_blk_t *blk, tick_t now), unsigned int hit_latency, /* latency in cycles for a hit */ int isL2) /*FP-BC add L2 identifier to cache creation */ { struct cache_t *cp; struct cache_blk_t *blk; int i, j, bindex; /* check all cache parameters */ if (nsets <= 0) fatal("cache size (in sets) `%d' must be non-zero", nsets); if ((nsets & (nsets-1)) != 0) fatal("cache size (in sets) `%d' is not a power of two", nsets); /* blocks must be at least one datum large, i.e., 8 bytes for SS */ if (bsize < 8) fatal("cache block size (in bytes) `%d' must be 8 or greater", bsize); if ((bsize & (bsize-1)) != 0) fatal("cache block size (in bytes) `%d' must be a power of two", bsize); if (usize < 0) fatal("user data size (in bytes) `%d' must be a positive value", usize); if (assoc <= 0) fatal("cache associativity `%d' must be non-zero and positive", assoc); if ((assoc & (assoc-1)) != 0 || (isL2 && assoc < 2)) /*FC-BC Add check for L2 caches to make sure they aren't direct mapped*/ fatal("cache associativity `%d' must be a power of two greater than 1", assoc); if (!blk_access_fn) fatal("must specify miss/replacement functions"); if(isL2){ nsets *= 2; } /* allocate the cache structure */ /*FP-BC space must be allocated for the structure itself, as well as the space for the main cache data and the shared data pool*/ cp = (struct cache_t *) calloc(1, sizeof(struct cache_t) + (nsets-1)*sizeof(struct cache_set_t)); if (!cp) fatal("out of virtual memory"); /* initialize user parameters */ cp->name = mystrdup(name); cp->nsets = nsets; /*FP-BC number of sets in new cache structure is double the input*/ cp->bsize = bsize; cp->balloc = balloc; cp->usize = usize; if(isL2){ cp->assoc = assoc / 2; /*FP-BC associativity in new cache structure is half the input*/ } else cp->assoc = assoc; cp->policy = policy; cp->hit_latency = hit_latency; cp->isL2 = isL2; /* miss/replacement functions */ cp->blk_access_fn = blk_access_fn; /* initialize cache stats */ cp->hits = 0; cp->misses = 0; cp->replacements = 0; cp->writebacks = 0; cp->invalidations = 0; /* blow away the last block accessed */ cp->last_tagset = 0; cp->last_blk = NULL; /* allocate data blocks */ cp->data = (byte_t *)calloc(nsets * assoc, //maybe needs 2x? sizeof(struct cache_blk_t) + (cp->balloc ? (bsize*sizeof(byte_t)) : 0)); if (!cp->data) fatal("out of virtual memory"); /*FP-BC configure full flag and FSR to initial values */ if(isL2) { //Set FSR and full flag to initial values cp->FSR = (nsets/2) + 1; cp->fullFlag = FALSE; } /* slice up the data blocks */ for (bindex=0,i=0; i<nsets; i++) //maybe needs 2x? { //fprintf(stderr, "here\n" ); cp->sets[i].way_head = NULL; //fprintf(stderr, "and here\n" ); cp->sets[i].way_tail = NULL; cp->sets[i].fullBit = 0; cp->sets[i].usageCtr = 0; cp->sets[i].fwdPtr = 0; /* get a hash table, if needed */ if (cp->hsize) { cp->sets[i].hash = (struct cache_blk_t **)calloc(cp->hsize, sizeof(struct cache_blk_t *)); if (!cp->sets[i].hash) fatal("out of virtual memory"); } /* NOTE: all the blocks in a set *must* be allocated contiguously, otherwise, block accesses through SET->BLKS will fail (used during random replacement selection) */ cp->sets[i].blks = CACHE_BINDEX(cp, cp->data, bindex); /* link the data blocks into ordered way chain and hash table bucket chains, if hash table exists */ for (j=0; j<assoc; j++) { /* locate next cache block */ blk = CACHE_BINDEX(cp, cp->data, bindex); bindex++; /* invalidate new cache block */ blk->status = 0; blk->tag = 0; blk->ready = 0; blk->user_data = (usize != 0 ? (byte_t *)calloc(usize, sizeof(byte_t)) : NULL); /* insert cache block into set hash table */ if (cp->hsize) link_htab_ent(cp, &cp->sets[i], blk); /* insert into head of way list, order is arbitrary at this point */ blk->way_next = cp->sets[i].way_head; blk->way_prev = NULL; if (cp->sets[i].way_head) cp->sets[i].way_head->way_prev = blk; cp->sets[i].way_head = blk; if (!cp->sets[i].way_tail) cp->sets[i].way_tail = blk; } } /*FP-BC number of sets in new cache structure must be stored as if the cache pool doesn't exist*/ if(isL2){ cp->nsets = nsets/2; nsets = nsets/2; } else cp->nsets = nsets; /* compute derived parameters */ cp->hsize = CACHE_HIGHLY_ASSOC(cp) ? (assoc >> 2) : 0; cp->blk_mask = bsize-1; cp->set_shift = log_base2(bsize); cp->set_mask = nsets-1; cp->tag_shift = cp->set_shift + log_base2(nsets); cp->tag_mask = (1 << (32 - cp->tag_shift))-1; cp->tagset_mask = ~cp->blk_mask; cp->bus_free = 0; /* print derived parameters during debug */ debug("%s: cp->hsize = %d", cp->name, cp->hsize); debug("%s: cp->blk_mask = 0x%08x", cp->name, cp->blk_mask); debug("%s: cp->set_shift = %d", cp->name, cp->set_shift); debug("%s: cp->set_mask = 0x%08x", cp->name, cp->set_mask); debug("%s: cp->tag_shift = %d", cp->name, cp->tag_shift); debug("%s: cp->tag_mask = 0x%08x", cp->name, cp->tag_mask); return cp; }