static inline void markvar (i_bb_t b, i_local_t var) { if (!sc_var(var)) return; if (sc_fp(var)) bv_set(b->fv_use, fp_id(var)); else bv_set(b->iv_use, var); }
static void test_bv_xor(TestCase *tc, void *data) { # define XOR_SIZE 1000 static const int xor_cnt = 500; BitVector *xor_bv; BitVector *bv1 = bv_new(); BitVector *bv2 = bv_new(); char set[XOR_SIZE]; char set1[XOR_SIZE]; char set2[XOR_SIZE]; int i; int count = 0; (void)data; memset(set, 0, XOR_SIZE); memset(set1, 0, XOR_SIZE); memset(set2, 0, XOR_SIZE); for (i = 0; i < xor_cnt; i++) { int bit = rand() % XOR_SIZE; bv_set(bv1, bit); set1[bit] = 1; } for (i = 0; i < xor_cnt; i++) { int bit = rand() % XOR_SIZE; bv_set(bv2, bit); set2[bit] = 1; } for (i = 0; i < XOR_SIZE; i++) { if (set1[i] != set2[i]) { set[i] = 1; count++; } } xor_bv = bv_xor(bv1, bv2); Aiequal(count, xor_bv->count); for (i = 0; i < XOR_SIZE; i++) { if (!Aiequal(set[i], bv_get(xor_bv, i))) { Tmsg("At position %d, bv1 is %d and bv2 is %d\n", i, bv_get(bv1, i), bv_get(bv2, i)); } } bv1 = bv_xor_x(bv1, bv2); Assert(bv_eq(bv1, xor_bv), "BitVectors should be equal"); bv_destroy(bv2); bv_destroy(xor_bv); bv2 = bv_new(); xor_bv = bv_xor(bv1, bv2); Assert(bv_eq(bv1, xor_bv), "XORed BitVector equals bv1"); bv_destroy(bv1); bv_destroy(bv2); bv_destroy(xor_bv); }
static void test_bv_or(TestCase *tc, void *data) { # define OR_SIZE 1000 static const int or_cnt = 500; BitVector *or_bv; BitVector *bv1 = bv_new(); BitVector *bv2 = bv_new(); char set[OR_SIZE]; int i; int count = 0; (void)data; memset(set, 0, OR_SIZE); for (i = 0; i < or_cnt; i++) { int bit = rand() % OR_SIZE; bv_set(bv1, bit); if (0 == set[bit]) { count++; set[bit] = 1; } } for (i = 0; i < or_cnt; i++) { int bit = rand() % OR_SIZE; bv_set(bv2, bit); if (0 == set[bit]) { count++; set[bit] = 1; } } or_bv = bv_or(bv1, bv2); Aiequal(count, or_bv->count); for (i = 0; i < OR_SIZE; i++) { Aiequal(set[i], bv_get(or_bv, i)); } bv1 = bv_or_x(bv1, bv2); Assert(bv_eq(bv1, or_bv), "BitVectors should be equal"); bv_destroy(bv2); bv_destroy(or_bv); bv2 = bv_new(); or_bv = bv_or(bv1, bv2); Assert(bv_eq(bv1, or_bv), "ORed BitVector equals bv1"); bv_destroy(bv1); bv_destroy(bv2); bv_destroy(or_bv); }
int acl_set_create(const unsigned int set) { journal_ftrace(__func__); /* * acl set 0 is a special set initialized by acl_set_init() */ if (set > 0 && !bv_test(set, set_states, ACLSETSIZ)) { // sanitize journal_notice("---------failure is normal---------\n"); mem_fun.set_destroy(set); journal_notice("-----------------------------------\n"); if (mem_fun.set_create(set)) { // XXX - log_notice_msg does not work here ? */ journal_notice("%s %u :: %s:%i\n", "unable to initialize acl set", set, __FILE__, __LINE__); return 1; } bv_set(set, set_states, ACLSETSIZ); } return 0; }
static void sim_handle_cmd(struct simulator *sim, struct cmd *cmd) { struct signal *signal; PRINT_CMD("CMD %s", cmd_names[cmd->type]); switch (cmd->type) { case CMD_ECHO: PRINT_CMD(" arg=%s", cmd->data.echo.arg); break; case CMD_TIME: PRINT_CMD(" picos=%" PICO, cmd->data.time.picos); sim->picos = cmd->data.time.picos; break; case CMD_VALUE: signal = cmd->data.value.signal; PRINT_CMD(" signal %s set to '%s' at %" PICO " ps", signal->name, cmd->data.value.value, cmd->data.value.time.picos); if (bv_get(&sim->events, signal->index)) { PRINT_CMD("Signal %s set multiple times during time %" PICO " = %s -> %s \n", signal->name, cmd->data.value.time.picos, signal->value, cmd->data.value.value); } signal_set_value(signal, cmd->data.value.value); sim->picos = cmd->data.value.time.picos; signal->event = 1; bv_set(&sim->events, signal->index, 1); sim->any_event = 1; break; case CMD_READ: signal = cmd->data.read.signal; PRINT_CMD(" %s read '%s'", signal->name, cmd->data.read.value); signal_set_value(signal, cmd->data.read.value); break; } PRINT_CMD("\n"); }
static BitVector *set_bits(BitVector *bv, char *bits) { static int bit_array[SET_BITS_MAX_CNT]; const int bit_cnt = s2l(bits, bit_array); int i; for (i = 0; i < bit_cnt; i++) { bv_set(bv, bit_array[i]); } return bv; }
/* * Switch the folder over to reporting MSNs rather than UIDs. */ EXPORTED void search_folder_use_msn(search_folder_t *folder, struct index_state *state) { int uid; unsigned msgno; bitvector_t msns = BV_INITIALIZER; search_folder_foreach(folder, uid) { msgno = index_finduid(state, uid); if (index_getuid(state, msgno) == (unsigned)uid) bv_set(&msns, msgno); }
static void test_bv_eq_hash(TestCase *tc, void *data) { static int const COUNT = 1000; int i; BitVector *bv1 = bv_new(); BitVector *bv2 = bv_new(); (void)data; test_bveq(bv1, bv2); Assert(bv_eq(bv1, bv1), "bv_eq on self should work"); bv_set(bv1, 1); test_bvneq(bv1, bv2); bv_set(bv2, 11); test_bvneq(bv1, bv2); bv_set(bv1, 11); bv_set(bv2, 1); test_bveq(bv1, bv2); /* This will increase size of bv1 to 1000 */ bv_unset(bv1, 1000); /* difference in size shouldn't matter */ test_bveq(bv1, bv2); for (i = 0; i < COUNT; i++) { int bit = rand() % COUNT; bv_set(bv1, bit); bv_set(bv2, bit); } test_bveq(bv1, bv2); bv_destroy(bv1); bv_destroy(bv2); /* although the saet bits will be equal, the extension will be different*/ bv1 = set_bits(bv_new(), "1, 3, 5"); bv2 = bv_not_x(set_bits(bv_new(), "0, 2, 4")); bv_set(bv2, 5); test_bvneq(bv1, bv2); bv_destroy(bv2); bv2 = set_bits(bv_new(), "1, 3, 5"); bv1 = bv_not_x(bv1); bv2 = bv_not_x(bv2); bv_unset(bv1, 1000); test_bvneq(bv1, bv2); bv_destroy(bv1); bv_destroy(bv2); }
/* * call-seq: * bv[i] = bool -> bool * * Set the bit and _i_ to *val* (+true+ or * +false+). */ VALUE frt_bv_set(VALUE self, VALUE rindex, VALUE rstate) { BitVector *bv; int index = FIX2INT(rindex); GET_BV(bv, self); if (index < 0) { rb_raise(rb_eIndexError, "%d < 0", index); } if (RTEST(rstate)) { bv_set(bv, index); } else { bv_unset(bv, index); } return rstate; }
/** * Test simple BitVector scanning */ static void test_bv_scan(TestCase *tc, void *data) { int i; BitVector *bv = bv_new(); BitVector *not_bv; (void)data; /* suppress unused argument warning */ for (i = 6; i <= 10; i++) { bv_set(bv, i); } not_bv = bv_not(bv); for (i = 6; i <= 10; i++) { Aiequal(i, bv_scan_next(bv)); Aiequal(i, bv_scan_next_unset(not_bv)); } Aiequal(-1, bv_scan_next(bv)); Aiequal(-1, bv_scan_next_unset(bv)); bv_destroy(bv); bv_destroy(not_bv); }
/*Spring 2015 course_os: Sathya Sankaran, Rakan Stanbouly, Jason Sim creates a process and initializes the PCB @param file pointer to location in memory of file @return pcb pointer upon success @return 0 if there is no more room in pcb table */ pcb* __process_create() { int32_t pcb_index = bv_firstFree(pcb_map); if (pcb_index < 0) { return NULL; } pcb* pcb_p = (pcb*) kmalloc(sizeof(pcb)); if (!pcb_p) { return NULL; } //initialize PCB pcb_p->stored_vas = vm_new_vas(); pcb_p->PID = pcb_index; //4-13-15: function pointer should point to main() of file pointer. // TODO: Eventually should be able to pass parameters. Put them on the stack (argv/argc) pcb_p->current_state = PROCESS_NEW; pcb_p->has_executed = 0; pcb_table[pcb_index] = pcb_p; bv_set(pcb_index, pcb_map); return pcb_p; }
// Sobel edge detector static int calc_edge_overlay() { int shutter_fullpress = kbd_is_key_pressed(KEY_SHOOT_FULL); const unsigned char* img = vid_get_viewport_active_buffer(); if (!img) return shutter_fullpress; const unsigned char* ptrh1 = NULL; // previous pixel line const unsigned char* ptrh2 = NULL; // current pixel line const unsigned char* ptrh3 = NULL; // next pixel line unsigned char* smptr = NULL; // pointer to line in smbuf int x, y, xdiv3; int conv1, conv2; const int y_min = camera_screen.edge_hmargin+ slice *slice_height; const int y_max = camera_screen.edge_hmargin+(slice+1)*slice_height; const int x_min = 6; const int x_max = (viewport_width - 2) * 3; img += vid_get_viewport_image_offset(); // offset into viewport for when image size != viewport size (e.g. 16:9 image on 4:3 LCD) xoffset = 0; yoffset = 0; // Reserve buffers ensure_allocate_imagebuffer(); if( !is_buffer_ready() ) return 0; // In every 6 bytes the Y of four pixels are described in the // viewport (UYVYYY format). For edge detection we only // consider the second in the current and the first // in the next pixel. // Clear all edges in the current slice int compressed_slice = edgebuf->ptrLen / EDGE_SLICES; memset(edgebuf->ptr + slice*compressed_slice, 0, compressed_slice); if (conf.edge_overlay_filter) { // Prefill smbuf with three lines of avergae-filtered data. // This looks much more complex then it actually is. // We really are just summing up nine pixels in a 3x3 box // and averaging the current pixel based on them. And // we do it 4 bytes at a time because of the UYVYYY format. for (y = -1; y <= 1; ++y) { shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL); ptrh1 = img + (y_min+y-1) * viewport_byte_width*viewport_yscale; smptr = smbuf + (y+1) * viewport_byte_width; average_filter_row(ptrh1, smptr, x_min, x_max); } } for (y = y_min; y < y_max; ++y) { shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL); if (conf.edge_overlay_filter) { // We need to shift up our smbuf one line, // and fill in the last line (which now empty) // with average-filtered data from img. // By storing only three lines of smoothed picture // in memory, we save memory. // Shift memcpy(smbuf, smbuf+viewport_byte_width, viewport_byte_width*2); // Filter new line ptrh1 = img + y * viewport_byte_width*viewport_yscale; smptr = smbuf + 2 * viewport_byte_width; average_filter_row(ptrh1, smptr, x_min, x_max); ptrh1 = smbuf; } else { ptrh1 = img + (y-1) * viewport_byte_width*viewport_yscale; } ptrh2 = ptrh1 + viewport_byte_width*viewport_yscale; ptrh3 = ptrh2 + viewport_byte_width*viewport_yscale; // Now we do sobel on the current line for (x = x_min, xdiv3 = x_min/3; x < x_max; x += 6, xdiv3 += 2) { // convolve vert (second Y) conv1 = *(ptrh1 + x + 1) * ( 1) + *(ptrh1 + x + 4) * (-1) + *(ptrh2 + x + 1) * ( 2) + *(ptrh2 + x + 4) * (-2) + *(ptrh3 + x + 1) * ( 1) + *(ptrh3 + x + 4) * (-1); if (conv1 < 0) // abs() conv1 = -conv1; // convolve vert (first Y of next pixel) conv2 = *(ptrh1 + x + 1) * ( 1) + *(ptrh1 + x + 3) * ( 2) + *(ptrh1 + x + 4) * ( 1) + *(ptrh3 + x + 1) * (-1) + *(ptrh3 + x + 3) * (-2) + *(ptrh3 + x + 4) * (-1); if (conv2 < 0) // abs() conv2 = -conv2; if (conv1 + conv2 > conf.edge_overlay_thresh) { bv_set(edgebuf, (y-camera_screen.edge_hmargin)*viewport_width + xdiv3, 1); } // Do it once again for the next 'pixel' // convolve vert (second Y) conv1 = *(ptrh1 + x + 5) * ( 1) + *(ptrh1 + x + 9) * (-1) + *(ptrh2 + x + 5) * ( 2) + *(ptrh2 + x + 9) * (-2) + *(ptrh3 + x + 5) * ( 1) + *(ptrh3 + x + 9) * (-1); if (conv1 < 0) // abs() conv1 = -conv1; // convolve vert (first Y of next pixel) conv2 = *(ptrh1 + x + 5) * ( 1) + *(ptrh1 + x + 7) * ( 2) + *(ptrh1 + x + 9) * ( 1) + *(ptrh3 + x + 5) * (-1) + *(ptrh3 + x + 7) * (-2) + *(ptrh3 + x + 9) * (-1); if (conv2 < 0) // abs() conv2 = -conv2; if (conv1 + conv2 > conf.edge_overlay_thresh) { bv_set(edgebuf, (y-camera_screen.edge_hmargin)*viewport_width + xdiv3+1, 1); } } // for x } // for y // For an even more improved edge overlay, enabling the following lines will // post-filter the results of the edge detection, removing false edge 'dots' // from the display. However, the speed hit is large. In the developer's opinion // this code is not needed, but if you want that additional quality and do not // care so much about performance, you can enable it. // // if (conf.edge_overlay_filter) // { // // Here we do basic filtering on the detected edges. // // If a pixel is marked as edge but just a few of its // // neighbors are also edges, then we assume that the // // current pixel is just noise and delete the mark. // // bit_vector_t* bv_tmp = bv_create(edgebuf->nElem, edgebuf->nBits); // if (bv_tmp != NULL) // { // memset(bv_tmp->ptr, 0, bv_tmp->ptrLen); // // for (y = 1; y < viewport_height-1; ++y) // { // shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL); // // for (x=12; x<(viewport_width - 4); ++x) // { // int bEdge = bv_get(edgebuf, y*viewport_width + x); // if (bEdge) // { // // Count the number of neighbor edges // int sum = // bv_get(edgebuf, (y-1)*viewport_width + (x-1)) + // bv_get(edgebuf, (y-1)*viewport_width + (x)) + // bv_get(edgebuf, (y-1)*viewport_width + (x+1)) + // // bv_get(edgebuf, (y)*viewport_width + (x-1)) + //// bv_get(&edgebuf, (y)*viewport_width + (x)) + // we only inspect the neighbors // bv_get(edgebuf, (y)*viewport_width + (x+1)) + // // bv_get(edgebuf, (y+1)*viewport_width + (x-1)) + // bv_get(edgebuf, (y+1)*viewport_width + (x)) + // bv_get(edgebuf, (y+1)*viewport_width + (x+1)); // // if (!conf.edge_overlay_show) // { // if (sum >= 5) // if we have at least 5 neighboring edges // bv_set(bv_tmp, y*viewport_width + x, 1); // keep the edge // // else // // there is no need to delete because the buffer is already zeroed // } // } // } // for x // } // for y // // // Swap the filtered edge buffer for the real one // bit_vector_t* swap_tmp = edgebuf; // edgebuf = bv_tmp; // bv_free(swap_tmp); // } // NULL-check // } // if filtering return shutter_fullpress; }
/** * Stress test BitVector Scanning as well as bv_set_fast. This test has been * run successfully with BV_DENSE_SCAN_SIZE set to 20000000 and BV_SCAN_INC * set to 97. When running this test with high numbers, be sure use -q on the * command line or the test will take a very long time. */ static void test_bv_scan_stress(TestCase *tc, void *data) { int i; BitVector *bv = bv_new_capa(BV_SCAN_SIZE); BitVector *not_bv; (void)data; /* suppress unused argument warning */ for (i = BV_SCAN_INC; i < BV_SCAN_SIZE; i += BV_SCAN_INC) { bv_set_fast(bv, i); Aiequal(bv_get(bv, i), 1); Aiequal(bv_get(bv, i-1), 0); Aiequal(bv_get(bv, i+1), 0); } not_bv = bv_not(bv); for (i = BV_SCAN_INC; i < BV_SCAN_SIZE; i += BV_SCAN_INC) { Aiequal(i, bv_scan_next_from(bv, i - BV_SCAN_INC / 2)); Aiequal(i, bv_scan_next_unset_from(not_bv, i - BV_SCAN_INC / 2)); } Aiequal(-1, bv_scan_next_from(bv, i - BV_SCAN_INC / 2)); Aiequal(-1, bv_scan_next_unset_from(not_bv, i - BV_SCAN_INC / 2)); /* test scan_next_from where size is actually greater than the highest set * bit */ bv_unset(bv, bv->size); bv_set(not_bv, not_bv->size); bv_scan_reset(bv); bv_scan_reset(not_bv); for (i = BV_SCAN_INC; i < BV_SCAN_SIZE; i += BV_SCAN_INC) { Aiequal(i, bv_scan_next_from(bv, i - BV_SCAN_INC / 2)); Aiequal(i, bv_scan_next_unset_from(not_bv, i - BV_SCAN_INC / 2)); } Aiequal(-1, bv_scan_next_from(bv, i - BV_SCAN_INC / 2)); Aiequal(-1, bv_scan_next_unset_from(not_bv, i - BV_SCAN_INC / 2)); bv_scan_reset(bv); bv_scan_reset(not_bv); for (i = BV_SCAN_INC; i < BV_SCAN_SIZE; i += BV_SCAN_INC) { Aiequal(i, bv_scan_next(bv)); Aiequal(i, bv_scan_next_unset(not_bv)); } Aiequal(-1, bv_scan_next(bv)); Aiequal(-1, bv_scan_next_unset(not_bv)); bv_clear(bv); bv_destroy(not_bv); for (i = 0; i < BV_DENSE_SCAN_SIZE; i++) { bv_set(bv, i); } not_bv = bv_not(bv); for (i = 0; i < BV_DENSE_SCAN_SIZE; i++) { Aiequal(i, bv_scan_next_from(bv, i)); Aiequal(i, bv_scan_next_unset_from(not_bv, i)); } Aiequal(-1, bv_scan_next_from(bv, i)); Aiequal(-1, bv_scan_next_unset_from(not_bv, i)); bv_scan_reset(bv); bv_scan_reset(not_bv); for (i = 0; i < BV_DENSE_SCAN_SIZE; i++) { Aiequal(i, bv_scan_next(bv)); Aiequal(i, bv_scan_next_unset(not_bv)); } Aiequal(-1, bv_scan_next(bv)); Aiequal(-1, bv_scan_next_unset(not_bv)); bv_destroy(bv); bv_destroy(not_bv); }
/** * Test basic BitVector get/set/unset operations */ static void test_bv(TestCase *tc, void *data) { int i; BitVector *bv = bv_new(); (void)data; /* suppress unused argument warning */ Aiequal(0, bv->size); Aiequal(0, bv->count); Aiequal(0, bv_recount(bv)); bv_set(bv, 10); Aiequal(1, bv_get(bv, 10)); Aiequal(11, bv->size); Aiequal(1, bv->count); Aiequal(1, bv_recount(bv)); bv_set(bv, 10); Aiequal(1, bv_get(bv, 10)); Aiequal(11, bv->size); Aiequal(1, bv->count); Aiequal(1, bv_recount(bv)); bv_set(bv, 20); Aiequal(1, bv_get(bv, 20)); Aiequal(21, bv->size); Aiequal(2, bv->count); Aiequal(2, bv_recount(bv)); bv_unset(bv, 21); Aiequal(0, bv_get(bv, 21)); Aiequal(22, bv->size); Aiequal(2, bv->count); Aiequal(2, bv_recount(bv)); bv_unset(bv, 20); Aiequal(0, bv_get(bv, 20)); Aiequal(22, bv->size); Aiequal(1, bv->count); Aiequal(1, bv_recount(bv)); Aiequal(1, bv_get(bv, 10)); bv_set(bv, 100); Aiequal(1, bv_get(bv, 100)); Aiequal(101, bv->size); Aiequal(2, bv->count); Aiequal(2, bv_recount(bv)); Aiequal(1, bv_get(bv, 10)); bv_clear(bv); Aiequal(0, bv_get(bv, 10)); Aiequal(0, bv->size); Aiequal(0, bv->count); Aiequal(0, bv_recount(bv)); bv_unset(bv, 20); Aiequal(21, bv->size); /* test setting bits at intervals for a large number of bits */ bv_clear(bv); for (i = BV_INT; i < BV_SIZE; i += BV_INT) { bv_set(bv, i); } for (i = BV_INT; i < BV_SIZE; i += BV_INT) { Aiequal(1, bv_get(bv, i)); Aiequal(0, bv_get(bv, i - 1)); Aiequal(0, bv_get(bv, i + 1)); } /* test setting all bits */ bv_clear(bv); for (i = 0; i < BV_SIZE; i++) { bv_set(bv, i); } for (i = 0; i < BV_SIZE; i++) { Aiequal(1, bv_get(bv, i)); } /* test random bits */ bv_clear(bv); for (i = 0; i < BV_SIZE; i++) { if ((rand() % 2) == 0) { bv_set(bv, i); Aiequal(1, bv_get(bv, i)); } } bv_destroy(bv); }
static void test_bv_and(TestCase *tc, void *data) { # define AND_SIZE 1000 static const int and_cnt = 500; BitVector *and_bv; BitVector *bv1 = bv_new(); BitVector *bv2 = bv_new(); BitVector *not_bv1, *not_bv2, *or_bv, *not_and_bv; char set1[AND_SIZE]; char set2[AND_SIZE]; int i; int count = 0; (void)data; memset(set1, 0, AND_SIZE); memset(set2, 0, AND_SIZE); for (i = 0; i < and_cnt; i++) { int bit = rand() % AND_SIZE; bv_set(bv1, bit); set1[bit] = 1; } for (i = 0; i < and_cnt; i++) { int bit = rand() % AND_SIZE; bv_set(bv2, bit); if (1 == set1[bit] && !set2[bit]) { count++; set2[bit] = 1; } } not_bv1 = bv_not(bv1); not_bv2 = bv_not(bv2); and_bv = bv_and(not_bv1, not_bv2); not_and_bv = bv_not(and_bv); or_bv = bv_or(bv1, bv2); Assert(bv_eq(not_and_bv, or_bv), "BitVectors should be equal"); bv_destroy(not_bv1); bv_destroy(not_bv2); bv_destroy(and_bv); bv_destroy(not_and_bv); bv_destroy(or_bv); and_bv = bv_and(bv1, bv2); Aiequal(count, and_bv->count); for (i = 0; i < AND_SIZE; i++) { Aiequal(set2[i], bv_get(and_bv, i)); } bv1 = bv_and_x(bv1, bv2); Assert(bv_eq(bv1, and_bv), "BitVectors should be equal"); bv_destroy(bv2); bv_destroy(and_bv); bv2 = bv_new(); and_bv = bv_and(bv1, bv2); Assert(bv_eq(bv2, and_bv), "ANDed BitVector should be empty"); bv_destroy(bv1); bv_destroy(bv2); bv_destroy(and_bv); bv1 = bv_new(); bv_not_x(bv1); bv2 = bv_new(); bv_set(bv2, 10); bv_set(bv2, 11); bv_set(bv2, 20); and_bv = bv_and(bv1, bv2); Assert(bv_eq(bv2, and_bv), "ANDed BitVector should be equal"); bv_destroy(bv1); bv_destroy(bv2); bv_destroy(and_bv); }