MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / div64

Function div64

runtime/Perf.cc:448–466  ·  view source on GitHub ↗

Measure the cost of a 64-bit divide. Divides don't take a constant number of cycles. Values were chosen here semi-randomly to depict a fairly expensive scenario. Someone with fancy ALU knowledge could probably pick worse values.

Source from the content-addressed store, hash-verified

446// fairly expensive scenario. Someone with fancy ALU knowledge could
447// probably pick worse values.
448double div64()
449{
450 int count = 1000000;
451 // NB: Expect an x86 processor exception is there's overflow.
452 uint64_t start = Cycles::rdtsc();
453 uint64_t numeratorHi = 0x5a5a5a5a5a5UL;
454 uint64_t numeratorLo = 0x55aa55aa55aa55aaUL;
455 uint64_t divisor = 0xaa55aa55aa55aa55UL;
456 uint64_t quotient;
457 uint64_t remainder;
458 for (int i = 0; i < count; i++) {
459 __asm__ __volatile__("divq %4" :
460 "=a"(quotient), "=d"(remainder) :
461 "a"(numeratorLo), "d"(numeratorHi), "r"(divisor) :
462 "cc");
463 }
464 uint64_t stop = Cycles::rdtsc();
465 return Cycles::toSeconds(stop - start)/count;
466}
467
468// Measure the cost of calling a non-inlined function.
469double functionCall()

Callers

nothing calls this directly

Calls 1

rdtscFunction · 0.85

Tested by

no test coverage detected