3 ms·
It seems rather petty to criticize the use of uint64_t in the 64-bit versions in multiple places when the original does the same: 32-bit version: const unsi
by taylortx 6y ago
It seems rather petty to criticize the use of uint64_t in the 64-bit versions in multiple places when the original does the same:
32-bit version:
const unsigned b = 65536; // Number base (16 bits).
unsigned un1, un0, // Norm. dividend LSD's.
vn1, vn0, // Norm. divisor digits.
q1, q0, // Quotient digits.
un32, un21, un10,// Dividend digit pairs.
rhat; // A remainder.
So a properly adapted 64-bit version should use uint64_t and a 32-bit number base.
I did not attempt to follow the author's arguments why he advocates for 32-bit variables or why that deviation from the original would be correct. Using 64-bit does not seem to be any bottleneck at all here, so why bother.
- tangus 6y agoBut why? The Hacker's Delight author justifies it: >Several of the variables below could be "short," but having them fullwords gives better code on gcc/Intel. But does the same happen in the "adapted" code? Does forcing 64 bit variables on a 32 bit architecture give better code? Wouldn't it have been better to just leave the compiler to choose the best appropriate size? (I guess you do that by just declaring the variable as unsigned? I'm no C guru...) Also, the fact that all of them renamed the variable un32 to un64 tells you that they didn't have the slightest idea about what they were doing :D