static void flow_uninit_scan_statements (flownode_t *node, set_t *defs, set_t *uninit) { set_t *stuse; set_t *stdef; statement_t *st; set_iter_t *var_i; flowvar_t *var; operand_t *op; // defs holds only reaching definitions. make it hold only reaching // uninitialized definitions set_intersection (defs, uninit); stuse = set_new (); stdef = set_new (); for (st = node->sblock->statements; st; st = st->next) { flow_analyze_statement (st, stuse, stdef, 0, 0); for (var_i = set_first (stuse); var_i; var_i = set_next (var_i)) { var = node->graph->func->vars[var_i->element]; if (set_is_intersecting (defs, var->define)) { def_t *def = flowvar_get_def (var); if (def) { if (options.warnings.uninited_variable) { warning (st->expr, "%s may be used uninitialized", def->name); } } else { bug (st->expr, "st %d, uninitialized temp %s", st->number, operand_string (var->op)); } } // avoid repeat warnings in this node set_difference (defs, var->define); } for (var_i = set_first (stdef); var_i; var_i = set_next (var_i)) { var = node->graph->func->vars[var_i->element]; // kill any reaching uninitialized definitions for this variable set_difference (defs, var->define); if (var->op->op_type == op_temp) { op = var->op; if (op->o.tempop.alias) { var = op->o.tempop.alias->o.tempop.flowvar; if (var) set_difference (defs, var->define); } for (op = op->o.tempop.alias_ops; op; op = op->next) { var = op->o.tempop.flowvar; if (var) set_difference (defs, var->define); } } } } set_delete (stuse); set_delete (stdef); }
static void programer(set s) { set s1, s2; if(setpower(s) > 1) { split(s,&s1,&s2); prgcode[ncode][0] = set_first(&s1,1); prgcode[ncode][1] = set_first(&s2,1); ncode++; programer(s1); programer(s2); } }
static void emitindex(set *index) { int n,l; l=set_first(index,1); if(!l) return; writeF(" Index "); for(n=0;(n<4)&&l;n++) { if(n) writeF(","); writeF("m%d",l); set_del1(index,l); l=set_first(index,1); } writeF("$\n"); }
static void flow_find_loops (flowgraph_t *graph) { flownode_t *node; set_iter_t *succ; flowloop_t *loop, *l; flowloop_t *loop_list = 0; int i; for (i = 0; i < graph->num_nodes; i++) { node = graph->nodes[i]; for (succ = set_first (node->successors); succ; succ = set_next (succ)) { if (set_is_member (node->dom, succ->element)) { loop = make_loop (graph, node->id, succ->element); for (l = loop_list; l; l = l->next) { if (l->head == loop->head && !set_is_subset (l->nodes, loop->nodes) && !set_is_subset (loop->nodes, l->nodes)) { set_union (l->nodes, loop->nodes); delete_loop (loop); loop = 0; break; } } if (loop) { loop->next = loop_list; loop_list = loop; } } } } graph->loops = loop_list; }
void *hamt_delete(struct hamt_root *root, uint128_t *hash) { if (unlikely(ston(root->slot) == NULL)) { return NULL; } struct hamt_state s; s.level = 0; s.ptr[0] = &root->slot; void *found_item = __hamt_search(root, hash, &s); if (unlikely(found_item == NULL)) { return NULL; } if (unlikely(s.level == 0)) { root->slot = (struct hamt_slot){0}; goto done; } struct hamt_slot *found_slot = s.ptr[s.level]; s.level--; struct hamt_node *node = ston(*s.ptr[s.level]); int slice = slice_get(*hash, s.level); if (set_count(node->mask) != 2) { *s.ptr[s.level] = ntos(__hamt_del_node(root, node, slice)); goto done; } else { // set_count == 2 struct hamt_slot other_slot = \ __hamt_get_other_slot(node, found_slot); if(!is_leaf(&other_slot)) { uint64_t other_slice = set_first(set_del(node->mask, slice)); __hamt_free_node(root, node); *s.ptr[s.level] = ntos(__hamt_new_node1(root, other_slice, other_slot)); goto done; } else { while (1) { __hamt_free_node(root, node); if (unlikely(s.level == 0)) { root->slot = other_slot; goto done; } s.level--; node = ston(*s.ptr[s.level]); if (set_count(node->mask) != 1) { break; } } slice = slice_get(*hash, s.level); int slot = set_slot_number(node->mask, slice); node->slots[slot] = other_slot; goto done; } } done: return found_item; }
static void flow_find_dominators (flowgraph_t *graph) { set_t *work; flownode_t *node; int i; set_iter_t *pred; int changed; if (!graph->num_nodes) return; // First, create a base set for the initial state of the non-initial nodes work = set_new (); for (i = 0; i < graph->num_nodes; i++) set_add (work, i); set_add (graph->nodes[0]->dom, 0); // initialize dom for the non-initial nodes for (i = 1; i < graph->num_nodes; i++) { set_assign (graph->nodes[i]->dom, work); } do { changed = 0; for (i = 1; i < graph->num_nodes; i++) { node = graph->nodes[i]; pred = set_first (node->predecessors); set_empty (work); for (pred = set_first (node->predecessors); pred; pred = set_next (pred)) set_intersection (work, graph->nodes[pred->element]->dom); set_add (work, i); if (!set_is_equivalent (work, node->dom)) changed = 1; set_assign (node->dom, work); } } while (changed); set_delete (work); }
static void *__hamt_down(struct hamt_state *s) { if (!is_leaf(s->ptr[s->level])) { struct hamt_node *node = ston(*s->ptr[s->level]); int slice = set_first(node->mask); s->hash = slice_set(s->hash, slice, s->level); int slot = set_slot_number(node->mask, slice); s->ptr[s->level + 1] = &node->slots[slot]; s->level += 1; return __hamt_down(s); } else { return to_leaf(s->ptr[s->level]); } }
static flowloop_t * make_loop (flowgraph_t *graph, unsigned n, unsigned d) { flowloop_t *loop = new_loop (); flownode_t *node; set_t *stack = set_new (); set_iter_t *pred; loop->head = d; set_add (loop->nodes, d); insert_loop_node (loop, n, stack); while (!set_is_empty (stack)) { set_iter_t *ss = set_first (stack); unsigned m = ss->element; set_del_iter (ss); set_remove (stack, m); node = graph->nodes[m]; for (pred = set_first (node->predecessors); pred; pred = set_next (pred)) insert_loop_node (loop, pred->element, stack); } set_delete (stack); return loop; }
static void flow_find_predecessors (flowgraph_t *graph) { int i; flownode_t *node; set_iter_t *succ; for (i = 0; i < graph->num_nodes + 2; i++) { node = graph->nodes[i]; for (succ = set_first (node->successors); succ; succ = set_next (succ)) { set_add (graph->nodes[succ->element]->predecessors, i); } } }
static void context_free(Context *context) { sd_event_source *es; Connection *c; assert(context); while ((es = set_steal_first(context->listen))) sd_event_source_unref(es); while ((c = set_first(context->connections))) connection_free(c); set_free(context->listen); set_free(context->connections); }
static void __ohamt_delete(struct ohamt_root *root, uint128_t hash, struct ohamt_state *s) { if (unlikely(s->level == 0)) { root->slot = (struct ohamt_slot){0}; goto done; } struct ohamt_slot *found_slot = s->ptr[s->level]; s->level--; struct ohamt_node *node = ston(*s->ptr[s->level]); int slice = slice_get(hash, s->level); if (set_count(node->mask) != 2) { *s->ptr[s->level] = ntos(__ohamt_del_node(root, node, slice)); goto done; } else { // set_count == 2 struct ohamt_slot other_slot = \ __ohamt_get_other_slot(node, found_slot); if(!is_leaf(&other_slot)) { uint64_t other_slice = set_first(set_del(node->mask, slice)); __ohamt_free_node(root, node); *s->ptr[s->level] = ntos(__ohamt_new_node1(root, other_slice, other_slot)); goto done; } else { while (1) { __ohamt_free_node(root, node); if (unlikely(s->level == 0)) { root->slot = other_slot; goto done; } s->level--; node = ston(*s->ptr[s->level]); if (set_count(node->mask) != 1) { break; } } slice = slice_get(hash, s->level); int slot = set_slot_number(node->mask, slice); node->slots[slot] = other_slot; goto done; } } done: return; }
static void df_search (flowgraph_t *graph, set_t *visited, int *i, int n) { flownode_t *node; set_iter_t *edge; int succ; set_add (visited, n); node = graph->nodes[n]; for (edge = set_first (node->edges); edge; edge = set_next (edge)) { succ = graph->edges[edge->element].head; if (!set_is_member (visited, succ)) { set_add (graph->dfst, edge->element); df_search (graph, visited, i, succ); } } node->dfn = --*i; graph->dfo[node->dfn] = n; }
static void flow_make_edges (flowgraph_t *graph) { int i, j; flownode_t *node; set_iter_t *succ; if (graph->edges); free (graph->edges); graph->edges = malloc (graph->num_edges * sizeof (flowedge_t *)); for (j = 0, i = 0; i < graph->num_nodes + 2; i++) { node = graph->nodes[i]; for (succ = set_first (node->successors); succ; succ = set_next (succ), j++) { set_add (node->edges, j); graph->edges[j].tail = i; graph->edges[j].head = succ->element; } } }
void skein256_update(skein_t* ctx, int firstlast, UBIType type, W64 len, W64* data) { W64 buf[4] = {0,0,0,0}; W64* k = ctx->key; W64* tweak = ctx->tweak; int lastlen; /* Process message */ if(firstlast & 1) { init_tweak(type, tweak); } /* If this is not the last update, don't do last block processing */ if(!(firstlast & 2) && len % 32 == 0) { ++len; } while(len > 32) { add_bytes(32, tweak); encrypt256(k, tweak[0], tweak[1], data, k); set_first(0, tweak); k[0] ^= *data; ++data; k[1] ^= *data; ++data; k[2] ^= *data; ++data; k[3] ^= *data; ++data; len -= 32; } /* Process last block */ if(firstlast & 2) { lastlen = len % 32; if(lastlen == 0 && len > 0) { lastlen = 32; } add_bytes(lastlen, tweak); set_last(1, tweak); memcpy(buf, data, lastlen); encrypt256(k, tweak[0], tweak[1], buf, k); k[0] ^= buf[0]; k[1] ^= buf[1]; k[2] ^= buf[2]; k[3] ^= buf[3]; } }
static void dns_transaction_tentative(DnsTransaction *t, DnsPacket *p) { _cleanup_free_ char *pretty = NULL; DnsZoneItem *z; assert(t); assert(p); if (manager_our_packet(t->scope->manager, p) != 0) return; in_addr_to_string(p->family, &p->sender, &pretty); log_debug("Transaction on scope %s on %s/%s got tentative packet from %s", dns_protocol_to_string(t->scope->protocol), t->scope->link ? t->scope->link->name : "*", t->scope->family == AF_UNSPEC ? "*" : af_to_name(t->scope->family), pretty); /* RFC 4795, Section 4.1 says that the peer with the * lexicographically smaller IP address loses */ if (memcmp(&p->sender, &p->destination, FAMILY_ADDRESS_SIZE(p->family)) >= 0) { log_debug("Peer has lexicographically larger IP address and thus lost in the conflict."); return; } log_debug("We have the lexicographically larger IP address and thus lost in the conflict."); t->block_gc++; while ((z = set_first(t->zone_items))) { /* First, make sure the zone item drops the reference * to us */ dns_zone_item_probe_stop(z); /* Secondly, report this as conflict, so that we might * look for a different hostname */ dns_zone_item_conflict(z); } t->block_gc--; dns_transaction_gc(t); }
static void flow_uninitialized (flowgraph_t *graph) { int i; flownode_t *node; flowvar_t *var; set_iter_t *var_i; set_t *defs; set_t *uninitialized; uninitialized = set_new (); node = graph->nodes[graph->num_nodes]; set_assign (uninitialized, node->reaching_defs.out); defs = set_new (); for (i = 0; i < graph->num_nodes; i++) { node = graph->nodes[graph->dfo[i]]; set_empty (defs); // collect definitions of all variables "used" in this node. use from // the live vars analysis is perfect for the job for (var_i = set_first (node->live_vars.use); var_i; var_i = set_next (var_i)) { var = graph->func->vars[var_i->element]; set_union (defs, var->define); } // interested in only those defintions that actually reach this node set_intersection (defs, node->reaching_defs.in); // if any of the definitions come from the entry dummy block, then // the statements need to be scanned in case an aliasing definition // kills the dummy definition before the usage, and also so the line // number information can be obtained from the statement. if (set_is_intersecting (defs, uninitialized)) flow_uninit_scan_statements (node, defs, uninitialized); } set_delete (defs); }
gboolean mouse_clicked(GtkWidget *widget, GdkEventButton *event) { // Handle click event on canvas int index; double coordx, coordy; select_t *select = NULL; // Length from click location to nearest dot mouse_discarded = 0; if (event->button == 8) { // back button if (event->state == GDK_SHIFT_MASK) set_prev_count(); else if (event->state == GDK_CONTROL_MASK) set_first(); else set_prev(); fldstate.mouse_clicked = 0x0; } else if (event->button == 9) { // forward button if (event->state == GDK_SHIFT_MASK) set_next_count(); else if (event->state == GDK_CONTROL_MASK) set_last(); else set_next(); fldstate.mouse_clicked = 0x0; } else if (event->button == 1) { fldstate.mouse_clicked = 0x1; mouse_clickx = event->x; mouse_clicky = event->y; pixel_to_field(&mouse_clickx, &mouse_clicky); fldstate.mouse_clickx = mouse_clickx; fldstate.mouse_clicky = mouse_clicky; switch(mouse_currentMode) { case SELECTONE: // select 1 performer select = field_get_in_area(mouse_clickx, mouse_clicky); if (event->state == GDK_CONTROL_MASK) { // ctrl-click select_toggle_multiple(pstate.select, select); } else if ((event->state & ~GDK_SHIFT_MASK)== 0) { // regular click if (select_empty(select)) { //select_dots_discard(); select_clear(pstate.select); mouse_discarded = 1; break; } index = select_get_form(select); if (!select_form_empty(select) && !select_check_form(pstate.select, index)) { // select form with ability to scale form select_clear(pstate.select); mouse_discarded = 1; select_add_form(pstate.select, select_get_form(select)); select_update_center(pstate.select); } else if (select_form_empty(select) && isSelected(select_get_dot(select)) != 1) { // dot is not selected select_clear(pstate.select); mouse_discarded = 1; if ((index = select_get_dot(select))!= -1) { select_add_dot(pstate.select, index); } } else { // hold click; dots being moved fldstate.mouse_clicked |= 0x2; } } dr_canvas_refresh(drill); break; case ADDPERF: // Add performers by clicking on canvas coordx = event->x; coordy = event->y; pixel_to_field(&coordx, &coordy); index = perf_add(); //coords_set_coord(pshow, index, coordx, coordy); coords_set(pshow->sets->currset->coords[index], coordx, coordy); dr_canvas_refresh(drill); break; case ADDFORM: break; } } else fldstate.mouse_clicked = 0; return TRUE; }
// meaning of *pass* is in [zz_material.h] bool zz_material_terrain::set (int pass) { zz_texture * firstmap, * secondmap, * lightmap; int shader_format = get_shader_format(); if (shader_format == SHADER_FORMAT_DEFAULT) return false; firstmap = (shader_format & SHADER_FORMAT_FIRSTMAP) ? textures[0] : 0; secondmap = (shader_format & SHADER_FORMAT_SECONDMAP) ? textures[1] : 0; lightmap = (shader_format & SHADER_FORMAT_LIGHTMAP) ? textures[2] : 0; bool l_use_shadow = (shader_format & SHADER_FORMAT_SHADOWMAP) > 0; // texture binding int texture_stage = 0; if (firstmap) firstmap->set(texture_stage++); if (secondmap) secondmap->set(texture_stage++); if (lightmap) lightmap->set(texture_stage++); if (l_use_shadow) s_renderer->set_texture_shadowmap(texture_stage++); #ifdef _DEBUG static bool debug_flags_multi [] = {true, true, true, true, true, true, true}; static bool debug_flags_single [] = {true, true, true, true, true, true, true}; #endif // set texture stage if (s_renderstate->use_multipass) { if (firstmap) { if (secondmap) { TEST_FLAGS_MULTI(0); set_first_second(); } else if (lightmap) { TEST_FLAGS_MULTI(1); set_first_light(); } else if (l_use_shadow) { TEST_FLAGS_MULTI(2); set_first_shadow(); } else { TEST_FLAGS_MULTI(3); set_first(); } } else if (lightmap) { if (l_use_shadow) { TEST_FLAGS_MULTI(4); set_light_shadow(); } else { TEST_FLAGS_MULTI(5); set_light(); } } else if (l_use_shadow) { TEST_FLAGS_MULTI(6); set_shadow(); } else { return false; } } else { if (firstmap) { if (secondmap) { if (lightmap) { if (l_use_shadow) { TEST_FLAGS_SINGLE(0); set_first_second_light_shadow(); } else { TEST_FLAGS_SINGLE(1); set_first_second_light(); } } else { if (l_use_shadow) { TEST_FLAGS_SINGLE(2); set_first_second_shadow(); } else { TEST_FLAGS_SINGLE(3); set_first_second(); } } } else { if (lightmap) { if (l_use_shadow) { TEST_FLAGS_SINGLE(4); set_first_light_shadow(); } else { TEST_FLAGS_SINGLE(5); set_first_light(); } } else { TEST_FLAGS_SINGLE(6); set_first(); } } } else { return false; } } set_alpha_stage(pass, lightmap ? true : false, l_use_shadow); return true; }
int save_file(char *filename) { // save a file // sets set_t *currset; // performers perf_t **perfs; // coordinates coord_t **coords; // file pointer FILE *fp; // loop var int i; int done; double coordx, coordy; // open file set_first(); update_tempo(); currset = pshow->sets->firstset; if (!filename) return -1; if (!(fp = fopen(filename,"w"))) return -1; fprintf(fp, "#drillwriter\n"); fprintf(fp, "name = %s\n", pshow->showname); fprintf(fp, "info = %s\n", pshow->showinfo); fprintf(fp, "perfnum = %i\n", pshow->perfnum); fprintf(fp, "\n"); // store performers perfs = pshow->perfs; for (i=0; i<pshow->perfnum; i++) { if (perfs[i]->valid != -1 && perfs[i]->valid != 0) { fprintf(fp, "index = %i\n", perfs[i]->index); fprintf(fp, "symbol = %s\n", perfs[i]->symbol); fprintf(fp, "valid = %i\n", perfs[i]->valid); fprintf(fp, "\n"); } } fprintf(fp, "sets:\n\n"); done = 0; do { // store set info coords = currset->coords; update_tempo(); fprintf(fp, "set = %i\n", pstate.setnum); fprintf(fp, "counts = %i\n", currset->counts); fprintf(fp, "tempo = %i\n", pshow->currtempo->tempo); fprintf(fp, "coords:\n"); for(i=0; i<pshow->perfnum; i++) { if (perfs[i]->valid) { coords_retrieve(coords[i], &coordx, &coordy); //fprintf(fp, "%i: %f %f\n", i, coords[i]->x, coords[i]->y); fprintf(fp, "%i: %f %f\n", i, coordx, coordy); } } fprintf(fp, "done\n"); fprintf(fp, "\n"); set_next(); //if (currset->next == NULL) if ((currset = set_get_next(pshow->sets, pstate.setnum)) == NULL) done = 1; currset = pshow->sets->currset; } while (done == 0); fclose(fp); return 0; }
int open_file(char *filename) { // open a file (for now, just save_file) // loop vars int i, j; // file pointer FILE *fp; // stream string char *buffer; // data storage char *data; // operation storage char *operation; // name storage char *name; // info storage char *info; // performer storage char *perfnum_buffer; // performer number int perfnum; // exit code int excode; // sizing for allocation int size; // finished flag int done; // placeholder for char int index; // coord number int cnum; // coordinates double x, y; // new operation char *op; // Structures // performer structures perf_t **perfs; perf_t *perf; // Set structure set_t *currset; // open file for reading if (!filename) return -1; if (!(fp = fopen(filename,"r"))) return -1; // check for valid file excode = file_getValidLine(fp, &buffer); if (strcmp(buffer, "#drillwriter")) { // not a valid save file return -1; } free(buffer); // get the name excode = file_getValidLine(fp, &buffer); size = strlen(buffer); name = (char*)malloc((size+2)*sizeof(char)); if (!name) return -1; strncpy(name, buffer, size+1); excode = file_linetoOps(name, &op, '='); free(op); free(buffer); // store name free(pshow->showname); pshow->showname = (char*)malloc((strlen(name)+1)*sizeof(char)); if (!pshow->showname) return -1; strcpy(pshow->showname, name); free(name); // get info excode = file_getValidLine(fp, &buffer); size = strlen(buffer); info = (char*)malloc((size+2)*sizeof(char)); if (!info) return -1; strncpy(info, buffer, size+1); excode = file_linetoOps(info, &op, '='); free(op); free(buffer); // store info free(pshow->showinfo); pshow->showinfo = (char*)malloc((strlen(info)+1)*sizeof(char)); if (!pshow->showinfo) return -1; strcpy(pshow->showinfo, info); free(info); // get perfnum excode = file_getValidLine(fp, &buffer); size = strlen(buffer); perfnum_buffer = (char*)malloc((size+2)*sizeof(char)); if (!perfnum_buffer) return -1; strncpy(perfnum_buffer, buffer, size+1); excode = file_linetoOps(perfnum_buffer, &op, '='); free(op); free(buffer); perfnum = atoi(perfnum_buffer); free(perfnum_buffer); // make the show show_destroy(&pshow); excode = show_construct(&pshow, perfnum); //printf("perfnum = %i\n", perfnum); // build performers buffer = (char*)malloc(sizeof(char)); if (!buffer) return -1; // get performer info perfs = pshow->perfs; perf = perfs[0]; done = 0; i = -1; do { if (i != -1) { if (perfs[i]) perf = perfs[i]; else exit(-1); } // grab performer pieces free(buffer); // get a valid line excode = file_getValidLine(fp, &buffer); size = strlen(buffer); // get operations at data from line data = (char*)malloc((size+2)*sizeof(char)); if (!data) return -1; strncpy(data, buffer, size+1); excode = file_linetoOps(data, &operation, '='); // interpret data based on operation if (!strcmp(operation, "index")) { // info perf->index = atoi(data); i++; } else if (!strcmp(operation, "symbol")) { // symbol free(perf->symbol); perf->symbol = (char*)malloc((size+1)*sizeof(char)); if (!perf->symbol) return -1; strcpy(perf->symbol, data); } else if (!strcmp(operation, "valid")) { // validity flag perf->valid = atoi(data); } else if (!strcmp(operation, "sets:")) { // moving to coords. finished with perfs done = 1; } free(data); free(operation); } while (done == 0); for (i=i+1; i<perfnum; i++) perfs[i]->valid = 0; // go to first set set_first(); currset = pshow->sets->currset; // get set information do { free(buffer); excode = file_getValidLine(fp, &buffer); //printf("buffer = %s\n", buffer); size = strlen(buffer); data = (char*)malloc((size+2)*sizeof(char)); if (!data) return -1; strncpy(data, buffer, size+1); file_linetoOps(data, &operation, '='); //printf("op = %s data = %s\n", operation, data); // find correct operation if (!strcmp(operation, "set")) { // set if (atoi(data) != 0) { // need a new set //add_set(); set_add_after_current(); currset = pshow->sets->currset; } } else if (!strcmp(operation, "counts")) { // counts currset->counts = atoi(data); } else if (!strcmp(operation, "tempo")) { // tempo //printf("changing tempo\n"); //printf("%i: new tempo = %i\n", pstate.setnum, atoi(data)); change_tempo(atoi(data), &pshow->currtempo); update_tempo(); //printf("ping\n"); } else if (!strcmp(operation, "coords:")) { // store coords i = 0; do { free(buffer); excode = file_getValidLine(fp, &buffer); if (excode == -1) exit(-1); else if (!strcmp(buffer, "done")) break; size = strlen(buffer); free(data); data = (char*)malloc((size+2)*sizeof(char)); if (excode == -1) exit(-1); strncpy(data, buffer, size+1); for (j=0; j<size && buffer[j] != ':'; j++) data[j] = buffer[j]; data[j] = '\0'; cnum = atoi(data); j++; // pass any whitespace for (j=j; j<size && buffer[j] == ' '; j++) { } index = j; // get first number for (j=j; j<size && buffer[j] != ' '; j++) { data[j-index] = buffer[j]; } data[j-index] = '\0'; x = atof(data); // pass whitespace for (j=j; j<size && buffer[j] == ' '; j++) { } index = j; // get second number for (j=j; j<size; j++) { data[j-index] = buffer[j]; } data[j-index] = '\0'; y = atof(data); //printf("(x,y) = %i %.2f %.2f\n", cnum, x, y); //printf("valid = %i\n", perfs[i]->valid); //if (perfs[i]->valid != 0) //{ //coords_set_coord(pshow, cnum, x, y); coords_set(pshow->sets->currset->coords[cnum], x, y); //} perf_set_valid(pshow->perfs[i]); i++; } while (i < perfnum); } free(operation); free(data); } while (excode != 1); free(buffer); set_first(); update_tempo(); fclose(fp); // update valid flags //printf("perfnum = %i\n", perfnum); undo_destroy(&pstate.undobr, pshow); return 0; }
static void flow_reaching_defs (flowgraph_t *graph) { int i; int changed; flownode_t *node; statement_t *st; set_t *stdef = set_new (); set_t *stgen = set_new (); set_t *stkill = set_new (); set_t *oldout = set_new (); set_t *gen, *kill, *in, *out, *uninit; set_iter_t *var_i; set_iter_t *pred_i; flowvar_t *var; // First, create out for the entry dummy node using fake statement numbers. kill = set_new (); for (i = 0; i < graph->func->num_statements; i++) set_add (kill, i); uninit = set_new (); for (i = 0; i < graph->func->num_vars; i++) { var = graph->func->vars[i]; set_union (uninit, var->define);// do not want alias handling here set_difference (uninit, kill); // remove any gens from the function } graph->nodes[graph->num_nodes]->reaching_defs.out = uninit; graph->nodes[graph->num_nodes]->reaching_defs.in = set_new (); graph->nodes[graph->num_nodes]->reaching_defs.gen = set_new (); graph->nodes[graph->num_nodes]->reaching_defs.kill = set_new (); // Calculate gen and kill for each block, and initialize in and out for (i = 0; i < graph->num_nodes; i++) { node = graph->nodes[i]; gen = set_new (); kill = set_new (); for (st = node->sblock->statements; st; st = st->next) { flow_analyze_statement (st, 0, stdef, 0, 0); set_empty (stgen); set_empty (stkill); for (var_i = set_first (stdef); var_i; var_i = set_next (var_i)) { var = graph->func->vars[var_i->element]; flow_kill_aliases (stkill, var, uninit); set_remove (stkill, st->number); set_add (stgen, st->number); } set_difference (gen, stkill); set_union (gen, stgen); set_difference (kill, stgen); set_union (kill, stkill); } node->reaching_defs.gen = gen; node->reaching_defs.kill = kill; node->reaching_defs.in = set_new (); node->reaching_defs.out = set_new (); } changed = 1; while (changed) { changed = 0; // flow down the graph for (i = 0; i < graph->num_nodes; i++) { node = graph->nodes[graph->dfo[i]]; in = node->reaching_defs.in; out = node->reaching_defs.out; gen = node->reaching_defs.gen; kill = node->reaching_defs.kill; for (pred_i = set_first (node->predecessors); pred_i; pred_i = set_next (pred_i)) { flownode_t *pred = graph->nodes[pred_i->element]; set_union (in, pred->reaching_defs.out); } set_assign (oldout, out); set_assign (out, in); set_difference (out, kill); set_union (out, gen); if (!set_is_equivalent (out, oldout)) changed = 1; } } set_delete (oldout); set_delete (stdef); set_delete (stgen); set_delete (stkill); }
static void flow_build_vars (function_t *func) { statement_t *s; operand_t *operands[4]; int num_vars = 0; int i, j; set_t *stuse; set_t *stdef; set_iter_t *var_i; flowvar_t *var; // first, count .return and .param_[0-7] as they are always needed for (i = 0; i < num_flow_params; i++) { flow_params[i].op.o.def = param_symbol (flow_params[i].name)->s.def; num_vars += count_operand (&flow_params[i].op); } // then run through the statements in the function looking for accessed // variables for (i = 0; i < func->num_statements; i++) { s = func->statements[i]; flow_analyze_statement (s, 0, 0, 0, operands); for (j = 0; j < 4; j++) num_vars += count_operand (operands[j]); } if (!num_vars) return; func->vars = malloc (num_vars * sizeof (daglabel_t *)); stuse = set_new (); stdef = set_new (); func->num_vars = 0; // incremented by add_operand // first, add .return and .param_[0-7] as they are always needed for (i = 0; i < num_flow_params; i++) add_operand (func, &flow_params[i].op); // then run through the statements in the function adding accessed // variables for (i = 0; i < func->num_statements; i++) { s = func->statements[i]; flow_analyze_statement (s, 0, 0, 0, operands); for (j = 0; j < 4; j++) add_operand (func, operands[j]); flow_analyze_statement (s, stuse, stdef, 0, 0); for (var_i = set_first (stdef); var_i; var_i = set_next (var_i)) { var = func->vars[var_i->element]; set_add (var->define, i); } for (var_i = set_first (stuse); var_i; var_i = set_next (var_i)) { var = func->vars[var_i->element]; set_add (var->use, i); } } func->global_vars = set_new (); // mark all global vars (except .return and .param_N) for (i = num_flow_params; i < func->num_vars; i++) { if (flowvar_is_global (func->vars[i])) set_add (func->global_vars, i); } // create dummy defs for local vars for (i = 0; i < func->num_vars; i++) { int offset, size; int j; var = func->vars[i]; if (flowvar_is_global (var) || flowvar_is_param (var)) continue; if (var->op->op_type == op_temp) { j = func->symtab->space->size + var->number; set_add (var->define, func->num_statements + j); } else { offset = def_offset (var->op->o.def); size = def_size (var->op->o.def); for (j = offset; j < offset + size; j++) set_add (var->define, func->num_statements + j); } } set_delete (stuse); set_delete (stdef); }
map_overlay_pair::~map_overlay_pair() { set_first(nullptr, false); set_second(nullptr, false); }
static int setpower(set ss) { int sp, i; for(i=set_first(&ss,1),sp=0;i;sp++, i=set_first(&ss,i+1)){;} return sp; }
static void flow_live_vars (flowgraph_t *graph) { int i, j; flownode_t *node; set_t *use; set_t *def; set_t *stuse = set_new (); set_t *stdef = set_new (); set_t *tmp = set_new (); set_iter_t *succ; statement_t *st; int changed = 1; // first, calculate use and def for each block, and initialize the in and // out sets. for (i = 0; i < graph->num_nodes; i++) { node = graph->nodes[i]; use = set_new (); def = set_new (); for (st = node->sblock->statements; st; st = st->next) { flow_analyze_statement (st, stuse, stdef, 0, 0); live_set_use (stuse, use, def); live_set_def (stdef, use, def); } node->live_vars.use = use; node->live_vars.def = def; node->live_vars.in = set_new (); node->live_vars.out = set_new (); } // create in for the exit dummy block using the global vars used by the // function use = set_new (); set_assign (use, graph->func->global_vars); node = graph->nodes[graph->num_nodes + 1]; node->live_vars.in = use; node->live_vars.out = set_new (); node->live_vars.use = set_new (); node->live_vars.def = set_new (); while (changed) { changed = 0; // flow UP the graph because live variable analysis uses information // from a node's successors rather than its predecessors. for (j = graph->num_nodes - 1; j >= 0; j--) { node = graph->nodes[graph->dfo[j]]; set_empty (tmp); for (succ = set_first (node->successors); succ; succ = set_next (succ)) set_union (tmp, graph->nodes[succ->element]->live_vars.in); if (!set_is_equivalent (node->live_vars.out, tmp)) { changed = 1; set_assign (node->live_vars.out, tmp); } set_assign (node->live_vars.in, node->live_vars.out); set_difference (node->live_vars.in, node->live_vars.def); set_union (node->live_vars.in, node->live_vars.use); } } set_delete (stuse); set_delete (stdef); set_delete (tmp); }
/* * Parse the generator output. Find the generators which are vertices * (non-rays) add their corresponding inequalities to an output set. * * Returns a matrix where each row contains the x-coordinate of the vertex, * y-coordinate of the vertex, and 0-based index of the inequality which bounds * the polytope to the right of the vertex. output_size is set to the total * length of the ouptut. */ static double *list_extreme_vertices(const dd_MatrixPtr generators, const dd_SetFamilyPtr incidence, const size_t nrows, long lower_bound_index, /*OUT*/ size_t * output_size) { assert(generators->rowsize > 0); assert(generators->colsize > 2); set_type cur_vert_set, next_vert_set, s; dd_rowrange i; long elem; size_t out_row = 0, r; size_t vertex_count = count_vertices(generators); /* Last vertex intersects with upper bound - not output */ *output_size = 3 * (vertex_count - 1); double *output = (double *) malloc(sizeof(double) * (*output_size)); /* Sorted indices into generators */ size_t *indices = sort_generators(generators); assert(*output_size > 0); /* Loop over vertices in generators, extracting solutions * * For vertices 0..n_vertices-2, find the inequality incident to the vertex * also incident in the next vertex. */ for (i = 0; i < vertex_count - 1; i++) { r = indices[i]; assert(is_vertex(generators->matrix[r][0])); assert(is_vertex(generators->matrix[indices[i + 1]][0])); assert(out_row < vertex_count - 1); cur_vert_set = incidence->set[r]; next_vert_set = incidence->set[indices[i + 1]]; /* Sets should be same size */ assert(cur_vert_set[0] == next_vert_set[0]); set_initialize(&s, cur_vert_set[0]); set_int(s, cur_vert_set, next_vert_set); /* Remove added index for first item */ /*if (!i)*/ /*set_delelem(s, lower_bound_index);*/ /* Set may have > 1 solution if ~identical slopes and intercepts due to * rounding. */ /*assert(set_card(s) == 1); */ /* Only one item in the set */ elem = set_first(s); set_free(s); /* Fill output row */ int base = out_row * 3; output[base] = *generators->matrix[r][1]; /* x */ output[base + 1] = *generators->matrix[r][2]; /* y */ output[base + 2] = (double) (elem - 1); /* ineq index, converted to 0-base */ out_row++; } free(indices); return output; }
static void split(set s,set *ss1,set *ss2) { int nsub; set s1_, s2_,s1,s2; int w, w_; int i, j, l, cross, cross_,dim; int *nextelem; dim=1<<(setpower(s)-1); nextelem=m_alloc(dim*sizeof(int)); for(l=set_first(&s,1),w=0,nsub=0;l; ) { int l1; w += vertinfo[l-1].weight; l1=set_first(&s,l+1); if(l1) { nextelem[nsub]=l; for(i=1; i<=nsub; i++) nextelem[nsub+i]=-nextelem[nsub-i]; nsub = 2 * nsub + 1; } l=l1; } l = nextelem[0]-1; w -= 2 * vertinfo[l].weight; s2=set_constr(l+1,_E); s1=set_aun(s,s2); cross = 0; for(j=0; j<vertinfo[l].vlnc; j++) if(set_in(vertinfo[l].link[j],s1))cross++; s1_=s1; s2_=s2; w_ = w; cross_ = cross; for (i = 1; i < nsub; i++) { l = abs(nextelem[i])-1; if (nextelem[i] > 0) { set_del1(&s1_,l+1); for (j = 0; j < vertinfo[l].vlnc; j++) { int ll=vertinfo[l].link[j]; if(set_in(ll,s1_)) (cross_)++; else if(set_in(ll,s2_)) (cross_)--; } set_add1(&s2_,l+1); w_ -= 2 * vertinfo[l].weight; } else { set_del1(&s2_,l+1); for (j = 0; j < vertinfo[l].vlnc; j++) { int ll=vertinfo[l].link[j]; if(set_in(ll,s2_)) (cross_)++; else if(set_in(ll,s1_)) (cross_)--; } set_add1(&s1_,l+1); w_ += 2 * vertinfo[l].weight; } if (MEMORY_OPTIM) { if(abs(w_) < abs(w) || (abs(w_) == abs(w) && cross_ < cross)) { s1=s1_; s2=s2_; w = w_; cross = cross_; } } else { if(cross_ < cross || (cross_ == cross && abs(w_) < abs(w))) { s1=s1_; s2=s2_; w = w_; cross = cross_; } } } free(nextelem); *ss1=s1; *ss2=s2; }