Measure the cost of a 32-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.
| 422 | // fairly expensive scenario. Someone with fancy ALU knowledge could |
| 423 | // probably pick worse values. |
| 424 | double div32() |
| 425 | { |
| 426 | int count = 1000000; |
| 427 | uint64_t start = Cycles::rdtsc(); |
| 428 | // NB: Expect an x86 processor exception is there's overflow. |
| 429 | uint32_t numeratorHi = 0xa5a5a5a5U; |
| 430 | uint32_t numeratorLo = 0x55aa55aaU; |
| 431 | uint32_t divisor = 0xaa55aa55U; |
| 432 | uint32_t quotient; |
| 433 | uint32_t remainder; |
| 434 | for (int i = 0; i < count; i++) { |
| 435 | __asm__ __volatile__("div %4" : |
| 436 | "=a"(quotient), "=d"(remainder) : |
| 437 | "a"(numeratorLo), "d"(numeratorHi), "r"(divisor) : |
| 438 | "cc"); |
| 439 | } |
| 440 | uint64_t stop = Cycles::rdtsc(); |
| 441 | return Cycles::toSeconds(stop - start)/count; |
| 442 | } |
| 443 | |
| 444 | // Measure the cost of a 64-bit divide. Divides don't take a constant |
| 445 | // number of cycles. Values were chosen here semi-randomly to depict a |