|
|
|
|
|
by CWuestefeld
4516 days ago
|
|
And if we're talking about the cost in cycles of the operations for jump versus compare, shouldn't we also then consider the cost of the calculation of the pivot points? I haven't done assembly language in a couple of decades, but it seems to me that the cost of calculating the traditional pivot point will be rather cheaper than that for the dual pivots. At least back in the day, a division by two was a trivial operation (arithmetic shift right by 1), whereas the division by three would require an actual calculation: not a big deal, but more expensive than the ASR. |
|
More complicated method: http://www.hackersdelight.org/divcMore.pdf
But the compiler will( should, look at generated code ) optimize the constant division anyway.
---
Behold, division by three using only addition and shifting( works up to 32767 ):
---This one works up to 32767, and then produces a wrong result every ~32767 numbers or so. The result is of by one. When you get over a million, every number is of by a couple of digits.
I don't think the additions are worth it.