static void WriteMap(const char* map_out_path, MFRNodeArray &nodes, MFREdgeArray &edges, MFRQuadTree &quadTree) { fprintf(stderr,"Writing mapinfo\n");fflush(stderr); { char mapinfo_json_fname[1024]; sprintf(mapinfo_json_fname,"%smapinfo.json", map_out_path); FILE* mapinfo_json_file = MFRUtils::OpenFile(mapinfo_json_fname,"w"); fprintf(mapinfo_json_file,"{\n"); fprintf(mapinfo_json_file," \"minsize\" : %f,\n", quadTree.minsize); fprintf(mapinfo_json_file," \"maxsize\" : %f,\n", quadTree.maxsize); fprintf(mapinfo_json_file," \"data-format-version\" : %d,\n", FormatVersionNumber() ); fprintf(mapinfo_json_file," \"maxNodesPerQuad\" : %d,\n",quadTree.maxNodesPerQuadUsed); fprintf(mapinfo_json_file," \"totalMapWidth\" : %f,\n",quadTree.totalMapWidth); fprintf(mapinfo_json_file," \"totalMapHeight\" : %f,\n",quadTree.totalMapHeight); fprintf(mapinfo_json_file," \"nrnodes\" : %d,\n",nodes.nrnodes); fprintf(mapinfo_json_file," \"nredges\" : %d,\n",edges.nredges); fprintf(mapinfo_json_file," \"averageLineLength\" : %f,\n", quadTree.averageLineLength); fprintf(mapinfo_json_file," \"averageQuadWidth\" : %f,\n", quadTree.averageQuadWidth); fprintf(mapinfo_json_file," \"averageQuadHeight\" : %f,\n", quadTree.averageQuadHeight); fprintf(mapinfo_json_file," \"symTableSize\" : %d,\n", TableSize(nodes.nrnodes)); fprintf(mapinfo_json_file," \"quadtree\" : \n"); write_root(mapinfo_json_file, quadTree.root); fprintf(mapinfo_json_file,"}\n"); fclose(mapinfo_json_file); } fprintf(stderr,"Finished writing map\n");fflush(stderr); }
static void DeleteHashMap(HashMapT *self) { size_t n = TableSize(self->map); size_t i; for (i = 0; i < n; i++) { EntryT *entry = &self->map[i]; bool firstEntry = TRUE; if (!entry->key) continue; while (entry) { EntryT *next = entry->next; MemUnref(entry->key); if (entry->ownership) MemUnref(entry->value); if (!firstEntry) MemUnref(entry); firstEntry = FALSE; entry = next; } } MemUnref(self->map); }
PtrT StackPushNew(StackT *self) { if (self->top < (int)TableSize(self->data)) { self->top++; return StackGet(self, 0); } return NULL; }
void CCommandLineInterpreter::InterpretOutputTypeOption(char * string) { // Interpret output file format option from command line int opt; for (opt = 0; opt < TableSize(TypeOptionNames); opt++) { int len = (int)strlen(TypeOptionNames[opt].b); if (strncmp(string, TypeOptionNames[opt].b, len) == 0) { // Match found if (OutputType) err.submit(2003, string); // More than one output type specified if (DumpOptions) err.submit(2007); // Both dump and convert specified // Save desired output type OutputType = TypeOptionNames[opt].a; // Check if name is followed by a word size int wordsize = 0; if (string[len]) wordsize = atoi(string+len); switch (wordsize) { case 0: // No word size specified break; case 32: case 64: // Valid word size DesiredWordSize = wordsize; break; default: // Illegal word size err.submit(2002, wordsize); } break; // Finished searching } } // Check if found if (opt >= TableSize(TypeOptionNames)) err.submit(2004, string-1); if (OutputType == CMDL_OUTPUT_MASM) { // Get subtype for (opt = 0; opt < TableSize(SubtypeNames); opt++) { int len = (int)strlen(SubtypeNames[opt].b); if (strncmp(string, SubtypeNames[opt].b, len) == 0) { // Match found SubType = SubtypeNames[opt].a; break; } } } }
static EntryT *GetEntry(HashMapT *self, StrT str) { size_t hash = 0; size_t c; while ((c = *str++)) hash = c + (hash << 6) + (hash << 16) - hash; return &self->map[hash % TableSize(self->map)]; }
int Reduced_SpharmonicTableSize(int bw, int m) { int i, sum; sum = 0; for (i=0; i<m; i++) sum += TableSize(i,bw); return sum; }
void HashMapIter(HashMapT *self, HashMapIterFuncT func) { size_t n = TableSize(self->map); size_t i; for (i = 0; i < n; i++) { EntryT *entry = &self->map[i]; if (!entry->key) continue; while (entry) { func(entry->key, entry->value); entry = entry->next; } } }
/* Update the mask of pending interrupts. This operation must be called when the state of some 68HC11 IO registers changes. It looks the different registers that indicate a pending interrupt (timer, SCI, SPI, ...) and records the interrupt if it's there and enabled. */ void interrupts_update_pending (struct interrupts *interrupts) { int i; uint8 *ioregs; unsigned long clear_mask; unsigned long set_mask; clear_mask = 0; set_mask = 0; ioregs = &interrupts->cpu->ios[0]; for (i = 0; i < TableSize(idefs); i++) { struct interrupt_def *idef = &idefs[i]; uint8 data; /* Look if the interrupt is enabled. */ if (idef->enable_paddr) { data = ioregs[idef->enable_paddr]; if (!(data & idef->enabled_mask)) { /* Disable it. */ clear_mask |= (1 << idef->int_number); continue; } } /* Interrupt is enabled, see if it's there. */ data = ioregs[idef->int_paddr]; if (!(data & idef->int_mask)) { /* Disable it. */ clear_mask |= (1 << idef->int_number); continue; } /* Ok, raise it. */ set_mask |= (1 << idef->int_number); } /* Some interrupts are shared (M6811_INT_SCI) so clear the interrupts before setting the new ones. */ interrupts->pending_mask &= ~clear_mask; interrupts->pending_mask |= set_mask; }
static void WriteHashtable(const char* map_out_path, MFRNodeArray &nodes, MFREdgeArray &edges, MFRQuadTree &quadTree) { int tablesize = TableSize(nodes.nrnodes); HashTable hashtable(map_out_path, tablesize); int i; for (i=0;i<nodes.nrnodes;i++) { int bin = hashtable.Hash(nodes.nodes[i].nodeidp); if (!hashtable.first[bin]) { fprintf(hashtable.Bucket(bin),",\n"); } hashtable.first[bin] = 0; fprintf(hashtable.Bucket(bin),"\"%s\" : [%f, %f, \"%s\" ]\n",nodes.nodes[i].nodeidp, nodes.nodes[i].x, nodes.nodes[i].y, nodes.nodes[i].quadNode->quadid); } }
int Spharmonic_TableSize(int bw) { int m, sum; if (bw > 512) { sum = 0; for (m=0; m<bw; m++) sum += TableSize(m,bw); return sum; } else { return ( (((4*(bw*bw*bw)) + (6*(bw*bw)) - (8*bw))/24) + bw ); } }
/* Update the mask of pending interrupts. This operation must be called when the state of some 68HC11 IO register changes. It looks the different registers that indicate a pending interrupt (timer, SCI, SPI, ...) and records the interrupt if it's there and enabled. */ void interrupts_update_pending (struct interrupts *interrupts) { int i; uint8 *ioregs; unsigned long clear_mask; unsigned long set_mask; clear_mask = 0; set_mask = 0; ioregs = &interrupts->cpu->ios[0]; for (i = 0; i < TableSize(idefs); i++) { struct interrupt_def *idef = &idefs[i]; uint8 data; /* Look if the interrupt is enabled. */ if (idef->enable_paddr) { data = ioregs[idef->enable_paddr]; if (!(data & idef->enabled_mask)) { /* Disable it. */ clear_mask |= (1 << idef->int_number); continue; } } /* Interrupt is enabled, see if it's there. */ data = ioregs[idef->int_paddr]; if (!(data & idef->int_mask)) { /* Disable it. */ clear_mask |= (1 << idef->int_number); continue; } /* Ok, raise it. */ set_mask |= (1 << idef->int_number); } /* Some interrupts are shared (M6811_INT_SCI) so clear the interrupts before setting the new ones. */ interrupts->pending_mask &= ~clear_mask; interrupts->pending_mask |= set_mask; /* Keep track of when the interrupt is raised by the device. Also implements the breakpoint-on-interrupt. */ if (set_mask) { signed64 cycle = cpu_current_cycle (interrupts->cpu); int must_stop = 0; for (i = 0; i < M6811_INT_NUMBER; i++) { if (!(set_mask & (1 << i))) continue; interrupts->interrupts[i].cpu_cycle = cycle; if (interrupts->interrupts[i].stop_mode & SIM_STOP_WHEN_RAISED) { must_stop = 1; sim_io_printf (CPU_STATE (interrupts->cpu), "Interrupt %s raised\n", interrupt_names[i]); } } if (must_stop) sim_engine_halt (CPU_STATE (interrupts->cpu), interrupts->cpu, 0, cpu_get_pc (interrupts->cpu), sim_stopped, SIM_SIGTRAP); } }
void StackReset(StackT *self) { self->top = -1; memset(self->data, 0, TableSize(self->data) * TableElemSize(self->data)); }
void Transpose_CosPmlTableGen(int bw, int m, double *cos_pml_table, double *result) { /* recall that cospml_table has had all the zeroes stripped out, and that if m is odd, then it is really a Gml function, which affects indexing a bit. */ double *trans_tableptr, *tableptr; int i, row, rowsize, stride, offset, costable_offset; /* note that the number of non-zero entries is the same as in the non-transposed case */ trans_tableptr = result; /* now traverse the cos_pml_table , loading appropriate values into the rows of transposed array */ if ( m == bw - 1 ) memcpy( result, cos_pml_table, sizeof(double)*TableSize(m,bw)); else { for (row = 0; row < bw; row++) { /* if m odd, no need to do last row - all zeroes */ if (row == (bw-1)) { if ( m % 2 ) return; } /* get the rowsize for the transposed array */ rowsize = Transpose_RowSize(row, m, bw); /* compute the starting point for values in cos_pml_table */ if (row <= m) { if ((row % 2) == 0) tableptr = cos_pml_table + (row/2); else tableptr = cos_pml_table + (m/2) + 1 + (row/2); } else { /* if row > m, then the highest degree coefficient of P(m,row) should be the first coefficient loaded into the transposed array, so figure out where this point is. */ offset = 0; if ( (m%2) == 0 ) { for (i=m; i<=row; i++) offset += RowSize(m, i); } else { for (i=m;i<=row+1;i++) offset += RowSize(m, i); } /* now we are pointing one element too far, so decrement */ offset--; tableptr = cos_pml_table + offset; } /* stride is how far we need to jump between values in cos_pml_table, i.e., to traverse the columns of the cos_pml_table. Need to set initial value. Stride always increases by 2 after that */ if (row <= m) stride = m + 2 - (m % 2) + (row % 2); else stride = row + 2; /* now load up this row of the transposed table */ costable_offset = 0; for (i=0; i < rowsize; i++) { trans_tableptr[i] = tableptr[costable_offset]; costable_offset += stride; stride += 2; } /* closes i loop */ trans_tableptr += rowsize; } /* closes row loop */ } }