int main() { uint64_t startTick, endTick, hSeconds; for(int i = 0; i < 20; i++) { startTick = ArchGetTickTime(); ArchNap(NAPTIME); endTick = ArchGetTickTime(); hSeconds = ArchTicksToNanoseconds(endTick - startTick) / 10000000; if(hSeconds < MINNAPTIME || hSeconds > MAXNAPTIME) { ARCH_ERROR("ArchTiming failed, possibly due to a " "process being swapped out. Try running " "it again, and if does not fail " "consistently it's ok to ignore this."); } } ArchNap(0); uint64_t ticks = ArchGetTickTime(); assert( (uint64_t) ArchTicksToNanoseconds(ticks) == uint64_t(static_cast<double>(ticks)*ArchGetNanosecondsPerTick() + .5)); double nanos = double(ArchTicksToNanoseconds(ticks)) / 1e9; double secs = ArchTicksToSeconds(ticks); double epsilon = 0.0001; assert( (nanos - epsilon <= secs) && (nanos + epsilon >= secs) ); return 0; }
ARCH_HIDDEN void Arch_ValidateAssumptions() { enum SomeEnum { BLAH }; /* * We do an atomic compare-and-swap on enum's, treating then as ints, * so we are assuming that an enum is the same size as an int. */ if (sizeof(SomeEnum) != sizeof(int)) ARCH_ERROR("sizeof(enum) != sizeof(int)"); if (sizeof(int) != 4) ARCH_ERROR("sizeof(int) != 4"); /* * Verify that the exponent and significand of float and double are * IEEE-754 compliant. */ if (sizeof(float) != sizeof(uint32_t) || ArchFloatToBitPattern(5.6904566e-28f) != 0x12345678 || ArchBitPatternToFloat(0x12345678) != 5.6904566e-28f) { // CODE_COVERAGE_OFF ARCH_ERROR("float is not IEEE-754 compliant"); //CODE_COVERAGE_ON } if (sizeof(double) != sizeof(uint64_t) || ArchDoubleToBitPattern( 5.6263470058989390e-221) != 0x1234567811223344ULL || ArchBitPatternToDouble( 0x1234567811223344ULL) != 5.6263470058989390e-221) { // CODE_COVERAGE_OFF ARCH_ERROR("double is not IEEE-754 compliant"); //CODE_COVERAGE_ON } /* * Lots of things depend on characters being able to compare with EOF. */ int ic = EOF; char c = ic; if (c != EOF) { // CODE_COVERAGE_OFF ARCH_ERROR("testing a char against EOF fails"); //CODE_COVERAGE_ON } /* * Check the demangler on a very simple type. */ if (ArchGetDemangled<int>() != "int") { // CODE_COVERAGE_OFF ARCH_ERROR("C++ demangling is badly broken."); // CODE_COVERAGE_ON } /* * Make sure that the ARCH_CACHE_LINE_SIZE constant is set as expected * on the current hardware architecture. */ if (ARCH_CACHE_LINE_SIZE != Arch_ObtainCacheLineSize()) { // CODE_COVERAGE_OFF ARCH_ERROR("ARCH_CACHE_LINE_SIZE is not set correctly."); // CODE_COVERAGE_ON } }