[llvm] r197271 - [block-freq] Add the APInt method extractBit.
Michael Gottesman
mgottesman at apple.com
Fri Dec 13 14:05:52 PST 2013
r197277.
On Dec 13, 2013, at 1:41 PM, Michael Gottesman <mgottesman at apple.com> wrote:
> Ah! I did not see that! Thanks Ben. I am going to rip this out and convert my test to test that (no point in wasting a test).
>
> Michael
>
> On Dec 13, 2013, at 12:58 PM, Benjamin Kramer <benny.kra at gmail.com> wrote:
>
>>
>> On 13.12.2013, at 21:47, Michael Gottesman <mgottesman at apple.com> wrote:
>>
>>> Author: mgottesman
>>> Date: Fri Dec 13 14:47:34 2013
>>> New Revision: 197271
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=197271&view=rev
>>> Log:
>>> [block-freq] Add the APInt method extractBit.
>>
>> Don't we already have an operator[] overload that does exactly the same thing?
>>
>> - Ben
>>
>>>
>>> Modified:
>>> llvm/trunk/include/llvm/ADT/APInt.h
>>> llvm/trunk/lib/Support/APInt.cpp
>>> llvm/trunk/unittests/ADT/APIntTest.cpp
>>>
>>> Modified: llvm/trunk/include/llvm/ADT/APInt.h
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=197271&r1=197270&r2=197271&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/ADT/APInt.h (original)
>>> +++ llvm/trunk/include/llvm/ADT/APInt.h Fri Dec 13 14:47:34 2013
>>> @@ -1244,6 +1244,9 @@ public:
>>> /// as "bitPosition".
>>> void flipBit(unsigned bitPosition);
>>>
>>> + /// \brief Returns true if the bit in bitPosition is set.
>>> + bool extractBit(unsigned bitPosition) const;
>>> +
>>> /// @}
>>> /// \name Value Characterization Functions
>>> /// @{
>>>
>>> Modified: llvm/trunk/lib/Support/APInt.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=197271&r1=197270&r2=197271&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/Support/APInt.cpp (original)
>>> +++ llvm/trunk/lib/Support/APInt.cpp Fri Dec 13 14:47:34 2013
>>> @@ -607,6 +607,14 @@ void APInt::flipBit(unsigned bitPosition
>>> else setBit(bitPosition);
>>> }
>>>
>>> +bool APInt::extractBit(unsigned bitPosition) const {
>>> + assert(bitPosition < BitWidth && "Out of the bit-width range!");
>>> + if (isSingleWord())
>>> + return VAL & maskBit(bitPosition);
>>> + else
>>> + return pVal[whichWord(bitPosition)] & maskBit(bitPosition);
>>> +}
>>> +
>>> unsigned APInt::getBitsNeeded(StringRef str, uint8_t radix) {
>>> assert(!str.empty() && "Invalid string length");
>>> assert((radix == 10 || radix == 8 || radix == 16 || radix == 2 ||
>>>
>>> Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=197271&r1=197270&r2=197271&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
>>> +++ llvm/trunk/unittests/ADT/APIntTest.cpp Fri Dec 13 14:47:34 2013
>>> @@ -597,4 +597,30 @@ TEST(APIntTest, tcDecrement) {
>>> EXPECT_EQ(APInt::tcCompare(test, expected, 4), 0);
>>> }
>>> }
>>> +
>>> +TEST(APIntTest, extractBit) {
>>> + // Single word check.
>>> + uint64_t E1 = 0x2CA7F46BF6569915ULL;
>>> + APInt A1(64, E1);
>>> + for (unsigned i = 0, e = 64; i < e; ++i) {
>>> + EXPECT_EQ(bool(E1 & (1ULL << i)),
>>> + A1.extractBit(i));
>>> + }
>>> +
>>> + // Multiword check.
>>> + integerPart E2[4] = {
>>> + 0xeb6eb136591cba21ULL,
>>> + 0x7b9358bd6a33f10aULL,
>>> + 0x7e7ffa5eadd8846ULL,
>>> + 0x305f341ca00b613dULL
>>> + };
>>> + APInt A2(integerPartWidth*4, ArrayRef<integerPart>(E2, 4));
>>> + for (unsigned i = 0; i < 4; ++i) {
>>> + for (unsigned j = 0; j < integerPartWidth; ++j) {
>>> + EXPECT_EQ(bool(E2[i] & (1ULL << j)),
>>> + A2.extractBit(i*integerPartWidth + j));
>>> + }
>>> + }
>>> +}
>>> +
>>> }
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list