[llvm-commits] [llvm] r127828 - in /llvm/trunk: include/llvm/ADT/APInt.h lib/Support/APInt.cpp unittests/ADT/APIntTest.cpp

Benjamin Kramer benny.kra at googlemail.com
Fri Mar 18 04:13:48 PDT 2011


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.

> As an experiment, I just tried making
> BuildUDIV call ComputeMaskedBits to get some leading zeros; effect on
> the following C code:

ComputeMaskedBits is on the TODO list, apart from eliminating a shift we can also use that information
to shrink the magic constant as described at [1]. This seems non-trivial though.

[1]: http://www.cs.uiowa.edu/~jones/bcd/divide.html#correcting



More information about the llvm-commits mailing list