/* expand hash size to size*2 */ int hash_expand( hash_t *h, unsigned int newsize ) { hash_link_t *p; int i, j, m, n; int d=0; #ifdef DEBUG printf("*hash_expand\n"); #endif //if( newsize==0 ) newsize = primes[h->nprime]; if( newsize > h->maxsize ) newsize=h->maxsize; if( h->size >= newsize ) return(1); //printf("hash_expand %u --> %u\n", h->size, newsize); if( newsize % h->size == 0 ) d = newsize/h->size; p = (hash_link_t *) realloc( h->data, newsize*sizeof(hash_link_t) ); if( p==NULL ) { printf("%s[%d] :", __FILE__, __LINE__); perror("realloc"); return(-1); } #ifdef HASH_DEBUG printf("+%d\n", (newsize-h->size)*sizeof(hash_link_t) ); #endif h->data=p; for( i=h->size; i<newsize; i++ ) { p=&h->data[i]; /* p->bucket= (hash_node_t *) malloc( h->buckets*sizeof(hash_node_t) ); if( p->bucket==NULL ) { printf("%s[%d] :", __FILE__, __LINE__); perror("malloc"); return(-2); } p->buckets=h->buckets; */ p->bucket=NULL; p->buckets=0; p->used=0; //bzero(p->bucket, h->buckets*sizeof(hash_node_t)); } for( i=0; i<h->size; i++) { p=&h->data[i]; for(j=0; j<p->used; j++) { if( d ) { /* special move */ m = p->bucket[j].v/h->size; n = m%d; if( n ) { /* move p->bucket[j] to h->data[j+n*h->size] */ if( hash_move( h, i, j, i+n*h->size ) <0 ) { hash_clear( h, i, j ); printf("hash_move fault, unit lost!\n"); } j--; } } else { /* normal move */ m = p->bucket[j].v%newsize; if( m == i ) continue; if( hash_move( h, i, j, m ) <0 ) { hash_clear( h, i, j ); printf("hash_move fault, unit lost!\n"); } j--; } } } h->size=newsize; //hash_dump(h); return(0); }
void frame_switch(uint16 oldframe, uint16 newframe) { if (oldframe == newframe) return; #ifdef LOG_CALLS if (current_thread) { int lastpc = pc; int i; char buf[10]; char *funcname; for (i = current_thread->num_frames; i >= 0; i--) { int fpc = current_thread->frames[i].pc & ~1; int fp = current_thread->frames[i].fp; funcname = symbols_get(fpc, 0); if (!funcname) { snprintf(buf, 10, "0x%04x", fpc); funcname=buf; } fprintf(framelog, " %04x: %30s%s [%04x+%04x]\n", fp, funcname, current_thread->frames[i].pc & 1 ? "(I)" : " ", fpc, lastpc - fpc); lastpc = (memory[fp] << 8 | memory[fp+1]); } } #endif #ifdef VERBOSE_FRAME printf("Frame switch: %04x --> %04x cycles: %11ld\n", oldframe, newframe, cycles); #endif if (current_thread) { current_thread->switchcycle = cycles; current_thread->savefp = oldframe; hash_move(&threads, 0, oldframe); } current_thread = hash_move(&threads, newframe, 0); #ifdef LOG_CALLS fprintf(framelog, "Frame switch: %04x --> %04x\n", oldframe, newframe); if (current_thread) { int lastpc = pc; int i; char buf[10]; char *funcname; for (i = current_thread->num_frames; i >= 0; i--) { int fpc = current_thread->frames[i].pc & ~1; int fp = current_thread->frames[i].fp; funcname = symbols_get(fpc, 0); if (!funcname) { snprintf(buf, 10, "0x%04x", fpc); funcname=buf; } fprintf(framelog, " %04x: %30s%s [%04x+%04x]\n", fp, funcname, current_thread->frames[i].pc & 1 ? "(I)" : " ", fpc, lastpc - fpc); lastpc = (memory[fp] << 8 | memory[fp+1]); } } #endif if (!current_thread) { current_thread = hash_create(&threads, 0, sizeof(thread_info) + 2* sizeof(frame_info)); current_thread->minfp = newframe; current_thread->size_frames = 2; current_thread->num_frames = 0; current_thread->switchcycle = cycles; memset(¤t_thread->frames[0], 0, sizeof(frame_info)); current_thread->frames[0].startcycle = cycles; current_thread->frames[0].pc = pc; } current_thread->frames[current_thread->num_frames].threadcycles += cycles - current_thread->switchcycle; }