String FieldVisitorDump::operator() (const Array & x) const { String res; WriteBufferFromString wb(res); wb.write("Array_[", 7); for (auto it = x.begin(); it != x.end(); ++it) { if (it != x.begin()) wb.write(", ", 2); writeString(applyVisitor(*this, *it), wb); } writeChar(']', wb); return res; }
String FieldVisitorDump::operator() (const Tuple & x_def) const { auto & x = x_def.t; String res; WriteBufferFromString wb(res); wb.write("Tuple_(", 7); for (auto it = x.begin(); it != x.end(); ++it) { if (it != x.begin()) wb.write(", ", 2); writeString(applyVisitor(*this, *it), wb); } writeChar(')', wb); return res; }
static SkFlattenable* reincarnate_flattenable(SkFlattenable* obj) { SkFlattenable::Factory fact = obj->getFactory(); if (NULL == fact) { return NULL; } SkFlattenableWriteBuffer wb(1024); obj->flatten(wb); size_t size = wb.size(); SkAutoSMalloc<1024> storage(size); // make a copy into storage wb.flatten(storage.get()); SkFlattenableReadBuffer rb(storage.get(), size); return fact(rb); }
static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info) { // just need a safe amount of storage, but ensure that it is 4-byte aligned. int32_t storage[(sizeof(SkImageInfo)*2) / sizeof(int32_t)]; SkBinaryWriteBuffer wb(storage, sizeof(storage)); info.flatten(wb); SkASSERT(wb.bytesWritten() < sizeof(storage)); SkReadBuffer rb(storage, wb.bytesWritten()); // pick a noisy byte pattern, so we ensure that unflatten sets all of our fields SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlphaType) 0xB8); info2.unflatten(rb); REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); REPORTER_ASSERT(reporter, info == info2); }
bool dp_check(string str, vector<string> inp){ int size = str.length(); vector<bool> wb(size+1, false); if(size == 0) return true; for(int i=1; i<=size; i++){ if(wb[i] == false && check_in_dict(str.substr(0,i), inp)) wb[i] = true; if(wb[i] == true){ if(i == size) return true; for(int j=i+1; j<=size; j++){ if(wb[j] == false && check_in_dict(str.substr(i,j-i), inp)) wb[j] = true; if(wb[j] == true && j == size) return true; } } } print_vector(wb); return false; }
int main(int, char **argv) { int retval = 0; WhiteBear wb(1); const int Nx = 100; const double R = 1.0, a = 5.0, kT = 1, nval = 0.1; const double energy = 42.53522950699669281; Vector inp = wb.createInput(Nx, Nx, Nx, R, a, a, a, Vector(Nx*Nx*Nx), kT); wb.get_x(inp) = wb.get_x(inp)*0 + nval; retval += check_functional_value("WhiteBear", wb, inp, energy); if (retval == 0) { printf("\n%s passes!\n", argv[0]); } else { printf("\n%s fails %d tests!\n", argv[0], retval); return retval; } }
void naomi_m1_board::enc_fill() { while(buffer_actual_size < BUFFER_SIZE && !stream_ended) { switch(lookb(3)) { // 00+2 - 0000+esc case 0: case 1: { skipb(2); int addr = getb(2); if(addr) wb(dict[addr]); else wb(getb(8)); break; } // 010+2 case 2: skipb(3); wb(dict[getb(2)+4]); break; // 011+3 case 3: skipb(3); wb(dict[getb(3)+8]); break; // 10+5 case 4: case 5: skipb(2); wb(dict[getb(5)+16]); break; // 11+6 case 6: case 7: { skipb(2); int addr = getb(6)+48; if(addr == 111) stream_ended = true; else wb(dict[addr]); break; } } } while(buffer_actual_size < BUFFER_SIZE) buffer[buffer_actual_size++] = 0; }
/*************************************** MAIN ******************************/ int main() { MIPS_SIM* sim = malloc(sizeof(MIPS_SIM)); /* init sim structure */ FDB* fdBasket = malloc(sizeof(FDB)); /* init Baskets */ DEB* deBasket = malloc(sizeof(DEB)); EMB* emBasket = malloc(sizeof(EMB)); MWB* mwBasket = malloc(sizeof(MWB)); simDefault(sim); /* set default values */ basketDefault(fdBasket, deBasket, emBasket, mwBasket); /* default values for baskets */ initProgram(); /* prompt user for file and read in mips program to buffer */ /* Multi Cycle Loop */ do { printf("Count: %d\n", count); wb(sim, fdBasket, deBasket, emBasket, mwBasket); /* write back */ m(sim, emBasket, mwBasket); /* memory write */ exe(sim, fdBasket, deBasket, emBasket, mwBasket); /* execute */ if(sim->regs[2] == 10 && mem[(sim->pcValue-4)/4] == 0xC) /* program finished */ break; d(sim, fdBasket, deBasket); /* instruction decode */ f(sim, fdBasket); /* instruction fetch */ sim->numClock++; count++; printf("Enter to continue...\n"); getc(stdin); } while(sim->regs[2] != 10); /* run until user quits or $v0 is 10 */ printf("\n Total instunctions: %d\n", sim->numOfInstr); printf(" Total read-write instructions: %d\n", sim->numOfRWs); printf(" Total clock cycles: %d\n\n", sim->numClock); printf("\n count: %d\n", count); free(sim); free(fdBasket); free(deBasket); free(emBasket); free(mwBasket); return 0; } /* End Main */
static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info) { // Need a safe amount of 4-byte aligned storage. Note that one of the test ICC profiles // is ~7500 bytes. const size_t storageBytes = 8000; SkAutoTMalloc<uint32_t> storage(storageBytes / sizeof(uint32_t)); SkBinaryWriteBuffer wb(storage.get(), storageBytes); info.flatten(wb); SkASSERT(wb.bytesWritten() < storageBytes); SkReadBuffer rb(storage.get(), wb.bytesWritten()); // pick a noisy byte pattern, so we ensure that unflatten sets all of our fields SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlphaType) 0xB8); info2.unflatten(rb); REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); REPORTER_ASSERT(reporter, info == info2); }
int main(int argc, char *argv[]) { // default threads int num_threads = 4; // create a pool of toy algorithms printf("Creating the pool of algos:\n"); std::vector<AlgoBase*> chain = lhcbChain(); // command-line parser if ( argc > 1 ) num_threads = atoi(argv[1]); if ( num_threads < 1 ) exit(1); // enabling a certain number of working threads printf("Init %i working threads\n", num_threads); tbb::task_scheduler_init init(num_threads); //apparently this value can be changed only once per application run // declaring a Whiteboard instance with a number of internal slots Whiteboard wb("Central Whiteboard", 200); unsigned int events(40); unsigned int n_parallel(20); bool test = false; if ( argc > 3 && atoi(argv[3]) == 1 ) test = true; if(test) { timestamp_t time = 0; int times = 0; for (int nn=0; nn<5; ++nn) { time += schedule(wb, chain, events, n_parallel); ++times; } printf("%i threads - Time: %f\n\n\n", num_threads, time/(double)times ); } else { schedule(wb, chain,events, n_parallel); } // do a final cleanup for (unsigned int i = 0; i < chain.size(); ++i) { delete chain[i]; } }
int main(int, char **argv) { int retval = 0; const int Nx = 20; const double R = 1.0, a = 2.0, kT = 1, nval = 0.1; const double energy = 2.72225468848892; printf("about to create input\n"); WhiteBear wb(Nx, Nx, Nx); wb.R() = R; wb.a1() = a; wb.a2() = a; wb.a3() = a; wb.kT() = kT; wb.n() = nval; retval += check_functional_value("WhiteBear", wb, energy, 2e-11); printf("n0 = %g\n", wb.get_n0()[0]); printf("n1 = %g\n", wb.get_n1()[0]); printf("n2 = %g\n", wb.get_n2()[0]); printf("n3 = %g\n", wb.get_n3()[0]); for (int i=0;i<Nx*Nx*Nx/2;i++) wb.n()[i] = 0.1*nval; //FIXME: the following test OUGHT to pass, but currently fails. :( //retval += wb.run_finite_difference_test("WhiteBear"); HomogeneousWhiteBear hwb; hwb.R() = R; hwb.kT() = kT; hwb.n() = nval; retval += check_functional_value("HomogeneousWhiteBear", hwb, energy/uipow(a,3), 2e-11); printf("n0 = %g\n", hwb.get_n0()); printf("n1 = %g\n", hwb.get_n1()); printf("n2 = %g\n", hwb.get_n2()); printf("n3 = %g\n", hwb.get_n3()); if (retval == 0) { printf("\n%s passes!\n", argv[0]); } else { printf("\n%s fails %d tests!\n", argv[0], retval); return retval; } }
void RawProcessingFilter::filterImage() { m_destImage = m_orgImage; // emulate LibRaw custom output profile if (!m_customOutputProfile.isNull()) { // Note the m_destImage is not yet ready in load()! IccTransform trans; trans.setIntent(IccTransform::Perceptual); trans.setEmbeddedProfile(m_destImage); trans.setOutputProfile(m_customOutputProfile); trans.apply(m_orgImage, m_observer); m_destImage.setIccProfile(m_customOutputProfile); } postProgress(20); if (!m_settings.wb.isDefault()) { WBFilter wb(m_settings.wb, this, m_orgImage, m_destImage, 20, 40); } postProgress(40); if (!m_settings.bcg.isDefault()) { BCGFilter bcg(m_settings.bcg, this, m_orgImage, m_destImage, 40, 70); } postProgress(70); if (!m_settings.curvesAdjust.isEmpty()) { CurvesFilter curves(m_settings.curvesAdjust, this, m_orgImage, m_destImage, 70, 100); } postProgress(100); }
int mainEntryClickHouseCompressor(int argc, char ** argv) { boost::program_options::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") ("decompress,d", "decompress") ("block-size,b", boost::program_options::value<unsigned>()->default_value(DBMS_DEFAULT_BUFFER_SIZE), "compress in blocks of specified size") ("hc", "use LZ4HC instead of LZ4") ("zstd", "use ZSTD instead of LZ4") ("level", "compression level") ("none", "use no compression instead of LZ4") ("stat", "print block statistics of compressed data") ; boost::program_options::variables_map options; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options); if (options.count("help")) { std::cout << "Usage: " << argv[0] << " [options] < in > out" << std::endl; std::cout << desc << std::endl; return 1; } try { bool decompress = options.count("decompress"); bool use_lz4hc = options.count("hc"); bool use_zstd = options.count("zstd"); bool stat_mode = options.count("stat"); bool use_none = options.count("none"); unsigned block_size = options["block-size"].as<unsigned>(); DB::CompressionMethod method = DB::CompressionMethod::LZ4; if (use_lz4hc) method = DB::CompressionMethod::LZ4HC; else if (use_zstd) method = DB::CompressionMethod::ZSTD; else if (use_none) method = DB::CompressionMethod::NONE; DB::CompressionSettings settings(method, options.count("level") > 0 ? options["level"].as<int>() : DB::CompressionSettings::getDefaultLevel(method)); DB::ReadBufferFromFileDescriptor rb(STDIN_FILENO); DB::WriteBufferFromFileDescriptor wb(STDOUT_FILENO); if (stat_mode) { /// Output statistic for compressed file. checkAndWriteHeader(rb, wb); } else if (decompress) { /// Decompression DB::CompressedReadBuffer from(rb); DB::copyData(from, wb); } else { /// Compression DB::CompressedWriteBuffer to(wb, settings, block_size); DB::copyData(rb, to); } } catch (...) { std::cerr << DB::getCurrentExceptionMessage(true); return DB::getCurrentExceptionCode(); } return 0; }
int main( int argc, char ** argv ) { FILE * pFile; int i, do_continue; char in_file[MAX_STR+1], out_file[MAX_STR+1], line[MAX_STR+1]; do_continue = i = 0; pFile = NULL; do { printf("Input file? "); fgets( in_file, MAX_STR, stdin ); printf("Output file? "); fgets( out_file, MAX_STR, stdin ); sscanf( in_file, "%s\n", in_file ); sscanf( out_file, "%s\n", out_file ); pFile = fopen( in_file, "r" ); if( pFile == NULL ) return 1; fout = fopen( out_file, "w" ); if( fout == NULL ) return 2; if( init( pFile ) ) goto unable_to_parse; do { fprintf( fout, "c#%d ", cycle ); wb(); mem3(); mem2(); mem1(); ex(); id(); if2(); if1(); /* pretend all stages are happening simultaneously */ fprintf( fout, "\n"); /* move everything down the pipeline */ if( !MEM3_stall ) { WB = MEM3; WB_count = MEM3_count; } if( !MEM2_stall ) { MEM3 = MEM2; MEM3_count = MEM2_count; } if( !MEM1_stall ) { MEM2 = MEM1; MEM2_count = MEM1_count; } if( !EX_stall ) { MEM1 = EX; MEM1_count = EX_count; } if( !ID_stall ) { EX = ID; EX_count = ID_count; } else MEM1 = EMPTY; if( !IF2_stall ) { ID = IF2; ID_count = IF2_count; } if( !IF1_stall ) { IF2 = IF1; IF2_count = IF1_count; ++inst_cycle; } if( flush ) { IF1 = EMPTY; IF2 = EMPTY; ID = EMPTY; EX = EMPTY; flush = FALSE; --inst_cycle; } ++cycle; Registers[0] = 0; /* reset R0 if it was accidently set */ } while( ( (IF1 != EMPTY) || (IF2 != EMPTY) || (ID != EMPTY) || (EX != EMPTY) || (MEM1 != EMPTY) || (MEM2 != EMPTY) || (MEM3 != EMPTY) || (WB != EMPTY) ) ); /* print end status */ print_regs( fout ); print_mem( fout ); unable_to_parse: for( i = 0; i < instcount; ++i ) free( Instructions[i] ); fclose( pFile ); fclose( fout ); printf("would you like to run again? "); fgets( line, MAX_STR, stdin ); do_continue = ( line[0] == 'y' || line[0] == 'Y' ) ? 1 : 0; } while( do_continue ); goto end; for( i = 0; i < instcount; ++i ) free( Instructions[i] ); fclose( pFile ); fclose( fout ); end: return 0; }
/** \brief the main program interacting with the user. The program is command line interactive. */ int main(int argc, char * const argv[]){ mapp::driver d; d.insert("hello",hello_execute); d.insert("synapse", nest::synapse_execute); d.insert("event",event_execute); // d.insert("spike",spike_execute); d.insert("kernel",coreneuron10_kernel_execute); d.insert("solver",coreneuron10_solver_execute); d.insert("cstep",coreneuron10_cstep_execute); d.insert("keyvalue",keyvalue_execute); d.insert("replib",replib_execute); //direct run if(argv[1] != NULL){ try { d.execute(argc,argv); } catch(mapp::driver_exception & e) { if(e.error_code != mapp::MAPP_USAGE) std::cerr << "caught exception: " << e.what() << "\n"; } catch(std::exception & e) { std::cerr << "caught exception: " << e.what() << "\n"; } return 0; } std::cout << "Welcome to NeuroMapp! Please enter " << "the name of the miniapp you wish to execute " << "followed by any arguments you wish to pass to it." << std::endl << "Please avoid preceding and trailing whitespace!" << std::endl << "To finish type quit" << std::endl << ">? "; // interactive run while(1) { #ifdef NEUROMAPP_CURSOR char* input = readline(""); add_history(input); std::string command(input); #else std::string command; std::getline(std::cin, command); #endif // I need to split the string into an arranesty of strings to pass it // in an argv style std::vector<std::string> command_v; command_v.push_back(argv[0]); std::istringstream command_stream(command); std::istream_iterator<std::string> wb(command_stream),we; std::copy(wb,we,std::back_inserter(command_v)); if( command_v[1].compare("quit") == 0 ) break; mapp::argv_data A(command_v.begin(),command_v.end()); try { d.execute(A.argc(),A.argv()); } catch(mapp::driver_exception & e) { if(e.error_code != mapp::MAPP_USAGE) std::cerr << "caught exception: " << e.what() << "\n"; } catch(std::exception & e) { std::cerr << "caught exception: " << e.what() << "\n"; } std::cout << std::endl << ">? "; } return 0; }
void ww(MMU * pmmu,uint16_t address, uint16_t val) { wb(pmmu,address, val & 255); wb(pmmu,address + 1, (val >> 8) & 255); }
// Returns whether word was written int ww(word address, word value) { // Write the least significant byte first return wb(address, value & 0x00FF) || wb(address + 1, value & 0xFF00); }
void Naa2TlvConverter::separateRegions() { if (!m_regionRas) return; const int lx = m_regionRas->getLx(); const int ly = m_regionRas->getLy(); const int wrap = lx; // we assume that m_regions contains almost no information (except: // m_regions[i].colorIndex == i) m_regions.clear(); WorkRaster<int> wb(lx, ly); // work buffer QVector<int> regionMap; // wb pixels => region indices QList<int> freeRegions; for (int y = 0; y < ly; y++) { unsigned short *waScanLine = m_regionRas->pixels(y); int *wbScanLine = wb.pixels(y); for (int x = 0; x < lx; x++) { int c = waScanLine[x]; int cUp = y > 0 ? waScanLine[x - wrap] : -1; int cLeft = x > 0 ? waScanLine[x - 1] : -1; int cUpLeft = x > 0 && y > 0 ? waScanLine[x - wrap - 1] : -1; if (c != cUp && c != cLeft && c != cUpLeft) { // no connection: create a new region Q_ASSERT(0 <= c && c < m_colors.count()); RegionInfo region; region.colorIndex = c; int regionIndex; if (!freeRegions.empty()) { // use a previously discarded region regionIndex = freeRegions.back(); freeRegions.pop_back(); m_regions[regionIndex] = region; } else { // create a new region regionIndex = m_regions.count(); m_regions.append(region); } wbScanLine[x] = regionMap.count(); regionMap.append(regionIndex); } else { // at least one connection if (c == cUpLeft) wbScanLine[x] = wbScanLine[x - wrap - 1]; else if (c == cUp) wbScanLine[x] = wbScanLine[x - wrap]; else { Q_ASSERT(c == cLeft); wbScanLine[x] = wbScanLine[x - 1]; } } // merge if needed if (cUp == cLeft && cUp >= 0 && regionMap[wbScanLine[x - 1]] != regionMap[wbScanLine[x - wrap]]) { // merge int pixelToDiscard = wbScanLine[x - 1]; int pixelToKeep = wbScanLine[x - wrap]; Q_ASSERT(pixelToDiscard != pixelToKeep); int regionToDiscard = regionMap[pixelToDiscard]; int regionToKeep = regionMap[pixelToKeep]; Q_ASSERT(regionToDiscard != regionToKeep); Q_ASSERT(m_regions[regionToDiscard].type != RegionInfo::Unused); Q_ASSERT(m_regions[regionToKeep].type != RegionInfo::Unused); for (int i = 0; i < regionMap.count(); i++) if (regionMap[i] == regionToDiscard) regionMap[i] = regionToKeep; // wbScanLine[x] = pixelToKeep; m_regions[regionToDiscard].type = RegionInfo::Unused; freeRegions.append(regionToDiscard); } } } // fill gaps for (;;) { // just remove topmost Unused regions if (!m_regions.empty() && m_regions.back().type == RegionInfo::Unused) { m_regions.pop_back(); int k = m_regions.count(); freeRegions.removeAll(k); } else if (!freeRegions.empty()) { // last region is used, but there is at least a free region with lower // index: move it there int regionToDiscard = m_regions.count() - 1; int regionToKeep = freeRegions.back(); freeRegions.pop_back(); Q_ASSERT(m_regions[regionToKeep].type == RegionInfo::Unused); Q_ASSERT(m_regions[regionToDiscard].type != RegionInfo::Unused); Q_ASSERT(regionToKeep < regionToDiscard); m_regions[regionToKeep] = m_regions[regionToDiscard]; // pop the region to discard m_regions.pop_back(); // update map for (int i = 0; i < regionMap.count(); i++) if (regionMap[i] == regionToDiscard) regionMap[i] = regionToKeep; } else break; } Q_ASSERT(freeRegions.empty()); for (int i = 0; i < m_regions.count(); i++) m_regions[i].pixelCount = 0; // wb => m_regionRas for (int y = 0; y < ly; y++) { unsigned short *regionScanLine = m_regionRas->pixels(y); int *wbScanLine = wb.pixels(y); for (int x = 0; x < lx; x++) { int regionIndex = regionMap[wbScanLine[x]]; regionScanLine[x] = (unsigned short)regionIndex; m_regions[regionIndex].pixelCount++; } } }
int main(int argc, char** argv) { // wordsmith /path/to/dict/file std::string dict_file("/usr/share/dict/words"); if (argc >= 2) { dict_file = argv[1]; } std::cout << "Generating word bucket from " << dict_file << "..." << std::endl; WordBucket wb(dict_file); std::string input, my_letters; std::cout << "Enter 'l abcdefg' to specify your letters." << std::endl; std::cout << "Enter 'c' to clear your letters." << std::endl; std::cout << "Enter 'e __a_b__' to query an expression." << std::endl; std::cout << "Enter 'w __a_b__' to get top-scoring words for an expression." << std::endl; std::cout << "Enter 'q' to quit." << std::endl; while (true) { std::cout << "> "; getline(std::cin, input); try { if (input.at(0) == 'q') { break; } else if (input.at(0) == 'c') { my_letters.clear(); std::cout << "Cleared your letters." << std::endl; } else if (input.at(0) == 'l') { if (input.size() > 2) { my_letters = input.substr(2); std::cout << "Set your letters to: " << my_letters << std::endl; } else { std::cout << "Your letters are: " << my_letters << std::endl; } } else if ((input.at(0) == 'w' || input.at(0) == 'e') && input.size() > 2) { Expressionizer e(input.substr(2)); ExpressionSeq es(e.get_all_expressions()); for (ExpressionSeq::const_iterator it = es.begin() ; it != es.end() ; ++it) { const Expression& e(*it); std::cout << " " << e << ": "; PossibleWordSeq pws; wb.generate_words_for(*it, my_letters, pws); for (PossibleWordSeq::const_iterator it2 = pws.begin() ; it2 != pws.end() ; ++it2) { std::cout << " " << *it2; } std::cout << std::endl; } } else { std::cout << "Invalid input: " << input << std::endl; } } catch (const std::exception& ex) { std::cout << "Error: " << ex.what() << std::endl; } } std::cout << "Done!" << std::endl; return 0; }
GlyphInfo GetGlyphInfoSys(Font font, int chr) { static Font fnt[GLYPHINFOCACHE]; static int pg[GLYPHINFOCACHE]; static GlyphInfo li[GLYPHINFOCACHE][256]; ONCELOCK { for(int i = 0; i < GLYPHINFOCACHE; i++) pg[i] = -1; } int page = chr >> 8; int q = CombineHash(font, page) % GLYPHINFOCACHE; if(fnt[q] != font || pg[q] != page) { fnt[q] = font; pg[q] = page; HFONT hfont = GetWin32Font(font, 0); if(!hfont) { GlyphInfo n; memset(&n, 0, sizeof(GlyphInfo)); return n; } HDC hdc = Win32_IC(); HFONT ohfont = (HFONT) ::SelectObject(hdc, hfont); int from = page << 8; GlyphInfo *t = li[q]; /* if(page >= 32) { wchar h[3]; h[0] = 'x'; h[1] = 'x'; h[2] = 'x'; int w0 = sGetCW(hdc, h, 2); for(int i = 0; i < 256; i++) { h[1] = from + i; t[i].width = sGetCW(hdc, h, 3) - w0; t[i].lspc = t[i].rspc = 0; } } else */{ bool abca = false, abcw = false; Buffer<ABC> abc(256); abcw = ::GetCharABCWidthsW(hdc, from, from + 256 - 1, abc); #ifndef PLATFORM_WINCE if(!abcw) abca = ::GetCharABCWidthsA(hdc, from, from + 256 - 1, abc); #endif if(abcw) { for(ABC *s = abc, *lim = abc + 256; s < lim; s++, t++) { t->width = s->abcA + s->abcB + s->abcC; t->lspc = s->abcA; t->rspc = s->abcC; } } else { Buffer<int> wb(256); #ifdef PLATFORM_WINCE ::GetCharWidth32(hdc, from, from + 256 - 1, wb); #else ::GetCharWidthW(hdc, from, from + 256 - 1, wb); #endif for(int *s = wb, *lim = wb + 256; s < lim; s++, t++) { t->width = *s - GetFontInfoSys(font).overhang; if(abca) { ABC aa = abc[(byte)ToAscii(from++)]; t->lspc = aa.abcA; t->rspc = aa.abcC; } else t->lspc = t->rspc = 0; } } } #ifndef PLATFORM_WINCE WORD pos[256]; WCHAR wch[256]; for(int i = 0; i < 256; i++) wch[i] = from + i; Win32_GetGlyphIndices(hdc, wch, 256, pos, 1); for(int i = 0; i < 256; i++) if(pos[i] == 0xffff) { li[q][i].width = (int16)0x8000; li[q][i].lspc = li[q][i].rspc = 0; } #endif ::SelectObject(hdc, ohfont); } return li[q][chr & 255]; }
int fetch_decode(int bk_cycle){ //printf("in fetch_decode\n"); executed_ins = NULL; int free_slot; int fetch_count=0; free_slot= 4- cpre_issue->count; int i; struct decoded_ins *new_ins; for(i=0;i<2;i++){ if(free_slot ==0){ return fetch_count; } if(waiting_ins !=NULL){ //pending branch ins execute_branch(waiting_ins); return fetch_count; } new_ins = cr_decoded_ins(mem[adr2sub(pc)]); int opcode; opcode = get_opcode(new_ins->binary); //handle special instructions switch (opcode){ case 27:{ //NOP pc +=4; executed_ins = new_ins; fetch_count++; return fetch_count; } case 16:{ //JUMP pc = new_ins->imd26 * 4; executed_ins = new_ins; fetch_count++; return fetch_count; } case 17:{ //JR pc = reg[new_ins->rs]; executed_ins = new_ins; fetch_count++; return fetch_count; } case 21:{ //BREAK executed_ins = new_ins; issue(); alu1(); alu2(); memory(); wb(); cout_state(bk_cycle,output_file); ///this cycle I decided manually exit(0); } case 18: case 19: case 20:{ if(execute_branch(new_ins)){ //if succeed, return fetch_count++; return fetch_count; }else{ //if failed, put in waiting_ins, return waiting_ins= new_ins; fetch_count++; return fetch_count; } } }//end of special case switch enq_preissue(new_ins); fetch_count++; free_slot--; pc+=4; }//end of for loop return fetch_count; }
int main(int argc, char ** argv) { boost::program_options::options_description desc("Allowed options"); desc.add_options() ("help,h", "produce help message") ("d,decompress", "decompress") ("block-size,b", boost::program_options::value<unsigned>()->default_value(DBMS_DEFAULT_BUFFER_SIZE), "compress in blocks of specified size") ("hc", "use LZ4HC instead of LZ4") #ifdef USE_QUICKLZ ("qlz", "use QuickLZ (level 1) instead of LZ4") #endif ("zstd", "use ZSTD instead of LZ4") ("stat", "print block statistics of compressed data") ; boost::program_options::variables_map options; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options); if (options.count("help")) { std::cout << "Usage: " << argv[0] << " [options] < in > out" << std::endl; std::cout << desc << std::endl; return 1; } try { bool decompress = options.count("d"); #ifdef USE_QUICKLZ bool use_qlz = options.count("qlz"); #else bool use_qlz = false; #endif bool use_lz4hc = options.count("hc"); bool use_zstd = options.count("zstd"); bool stat_mode = options.count("stat"); unsigned block_size = options["block-size"].as<unsigned>(); DB::CompressionMethod method = DB::CompressionMethod::LZ4; if (use_qlz) method = DB::CompressionMethod::QuickLZ; else if (use_lz4hc) method = DB::CompressionMethod::LZ4HC; else if (use_zstd) method = DB::CompressionMethod::ZSTD; DB::ReadBufferFromFileDescriptor rb(STDIN_FILENO); DB::WriteBufferFromFileDescriptor wb(STDOUT_FILENO); if (stat_mode) { /// Вывести статистику для сжатого файла. stat(rb, wb); } else if (decompress) { /// Разжатие DB::CompressedReadBuffer from(rb); DB::copyData(from, wb); } else { /// Сжатие DB::CompressedWriteBuffer to(wb, method, block_size); DB::copyData(rb, to); } } catch (const DB::Exception & e) { std::cerr << e.what() << ", " << e.message() << std::endl << std::endl << "Stack trace:" << std::endl << e.getStackTrace().toString() << std::endl; throw; } return 0; }