////////////////////////////// // // clockCycles -- returns the number of clock cycles since last reboot // HARDWARE DEPENDENT -- currently only for Intel Pentiums // which are faster than 75 Mhz. // // When compiling in Visual C++ on Windows computers (or perhaps // any other Windows C compiler) define the preprocessor variable // VISUAL // That will select the Windows-specific code for acessing tye // CPU clock cycle counter. Otherwise, the Linux OS code for // accessing the counter will be used. // #ifdef VISUAL #include typedef LONGLONG int64bits; #else typedef long long int int64bits; #endif int64bits SigTimer::clockCycles() { #ifndef VISUAL int64bits output; // For Pentiums, you can get the number of clock cycles elapsed // since the last reboot with the following assembler code: __asm__ volatile (".byte 0x0f, 0x31" : "=A" (output)); #else int64bits output; unsigned long high_end, low_end; __asm { __asm _emit 0x0f __asm _emit 0x31 mov high_end, edx mov low_end, eax } output = high_end; output = output << 32; output += low_end; #endif return output; }