[llvm-commits] [llvm] r127828 - in /llvm/trunk: include/llvm/ADT/APInt.h lib/Support/APInt.cpp unittests/ADT/APIntTest.cpp
Cameron Zwarich
zwarich at apple.com
Fri Mar 18 07:23:22 PDT 2011
On Mar 18, 2011, at 4:13 AM, Benjamin Kramer wrote:
> On 18.03.2011, at 09:03, Eli Friedman wrote:
>
>> On Thu, Mar 17, 2011 at 1:39 PM, Benjamin Kramer
>> <benny.kra at googlemail.com> wrote:
>>> Author: d0k
>>> Date: Thu Mar 17 15:39:06 2011
>>> New Revision: 127828
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=127828&view=rev
>>> Log:
>>> Add an argument to APInt's magic udiv calculation to specify the number of bits that are known zero in the divided number.
>>>
>>> This will come in handy soon.
>>
>> Hmm... what exactly is the effect of using LeadingZeros as opposed to
>> truncating the input APInt?
>
> The algorithm takes the sign bit into account to determine the needed fixups after multiplying with
> the magic constant. Truncating the input APInt (and thus reducing its BitWidth) will give different
> results.
There is actually a newer algorithm that is better than the Hacker's Delight one in many cases (for unsigned division it requires only a multiply and an AND for ~80% of all divisors):
http://comjnl.oxfordjournals.org/content/51/4/470.abstract
I've been meaning to implement it some time, at least for the cases where it is better.
Cameron
More information about the llvm-commits
mailing list