Code Comments
Programming Forum and web based access to our favorite programming groups.Boltar <boltar2003@yahoo.co.uk> writes: > On Apr 1, 11:58 pm, "robertwess...@yahoo.com" > <robertwess...@yahoo.com> wrote: > > Well that begs the question of why the cpu integer div instruction > doesn't simply check the divisors least significant bit to see if its > set to zero (even) and if it is then use bit shifting to get the > result. Same for multiply. (Others have already mentioned that you need a power of 2, not just a multiple of 2, but that doesn't invalidate the idea.) A plausible explanation is that chip designers assume that most multiplications and divisions by constant powers of 2 will be optimized to shifts by the compiler. Thus such a hardware check will benefit only cases where a run-time value just happens to be a power of 2, and will likely slow down *all* multiplications and divisions. On the other hand, I'm no hardware expert. Perhaps such a test can be done in parallel without slowing anything down. If so, perhaps it's already being done (it would be invisible to user code, or nearly so). -- Keith Thompson (The_Other_Keith) <kst-u@mib.org> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.