Commit Graph

54 Commits

Author SHA1 Message Date
Benjamin Kramer
15df8bebdc [APInt] Remove special case for i1.
Add a unit test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239062 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-04 18:19:13 +00:00
Pawel Bylica
9ee9f1a334 Fix APInt long division algorithm
Summary: This patch fixes step D4 of Knuth's division algorithm implementation. Negative sign of the step result was not always detected due to incorrect "borrow" handling.

Test Plan: Unit test that reveals the bug included.

Reviewers: chandlerc, yaron.keren

Reviewed By: yaron.keren

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D9196

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235699 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-24 07:38:39 +00:00
Yaron Keren
2adb40ecb6 Another test to exercise APInt divide step D6.
This is divrem_big7 since divrem_big6 is used in Pawel upcoming patch.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235536 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-22 18:49:59 +00:00
Yaron Keren
61ac65ddec Fix rare case where APInt divide algorithm applied un-needed transformation.
APInt uses Knuth's D algorithm for long division. In rare cases the
implementation applied a transformation that was not needed.

Added unit tests for long division. KnuthDiv() procedure is fully covered.
There is a case in APInt::divide() that I believe is never used (marked with
a comment) as all users of divide() handle trivial cases earlier.

Patch by Pawel Bylica!

  http://reviews.llvm.org/D8448



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233312 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-26 19:45:19 +00:00
Benjamin Kramer
eaf3cbd897 [APInt] Add an isSplat helper and use it in some places.
To complement getSplat. This is more general than the binary
decomposition method as it also handles non-pow2 splat sizes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233195 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-25 16:49:59 +00:00
Richard Trieu
1bcf09e589 Disable -Wunknown-pragmas in a test so that Clang without -Wself-move will not
complain that the flag doesn't exist.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225931 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-14 01:50:12 +00:00
Aaron Ballman
df70ab2592 Silence warnings about unknown pragmas for compilers that are not Clang. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225788 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-13 14:30:07 +00:00
Richard Trieu
cd7eb37ca4 Disable a warning for self move since the test is checking for this behavior.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225754 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-13 02:10:33 +00:00
Craig Topper
3512034554 Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or just letting them be implicitly created.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216525 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-27 05:25:25 +00:00
David Blaikie
8ebea0132d Fix -Wsign-compare warnings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215483 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-12 23:23:05 +00:00
Reid Kleckner
151f8cef74 APInt: Make self-move-assignment a no-op to fix stage3 clang-cl
It's not clear what the semantics of a self-move should be.  The
consensus appears to be that a self-move should leave the object in a
moved-from state, which is what our existing move assignment operator
does.

However, the MSVC 2013 STL will perform self-moves in some cases.  In
particular, when doing a std::stable_sort of an already sorted APSInt
vector of an appropriate size, one of the merge steps will self-move
half of the elements.

We don't notice this when building with MSVC, because MSVC will not
synthesize the move assignment operator for APSInt.  Presumably MSVC
does this because APInt, the base class, has user-declared special
members that implicitly delete move special members.  Instead, MSVC
selects the copy-assign operator, which defends against self-assignment.
Clang, on the other hand, selects the move-assign operator, and we get
garbage APInts.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215478 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-12 22:01:39 +00:00
Duncan P. N. Exon Smith
42e0bc88a3 Clean up whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200579 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-31 21:45:51 +00:00
Michael Gottesman
7320de5ce2 [APInt] Fix nearestLogBase2 to return correct answers for very large APInt and APInt with a bitwidth of 1.
I also improved the comments, added some more tests, etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199610 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-19 20:33:48 +00:00
Michael Gottesman
e7413972a4 [APInt] Fixed bug where APInt(UINT32_MAX, 0) would blow up when being constructed.
This was due to arithmetic overflow in the getNumBits() computation. Now we
cast BitWidth to a uint64_t so that does not occur during the computation. After
the computation is complete, the uint64_t is truncated when the function
returns.

I know that this is not something that is likely to happen, but it *IS* a valid
input and we should not blow up.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199609 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-19 20:33:38 +00:00
Michael Gottesman
cadf450e17 Remove APInt::extractBit since it is already implemented via operator[]. Change tests for extractBit to test operator[].
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197277 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-13 22:00:19 +00:00
Michael Gottesman
46f829ee25 [block-freq] Add the method APInt::nearestLogBase2().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197272 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-13 20:47:37 +00:00
Michael Gottesman
5bb504f4ea [block-freq] Add the APInt method extractBit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197271 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-13 20:47:34 +00:00
Michael Gottesman
a32edcfbc5 [APInt] Implement tcDecrement as a counterpart to tcIncrement. This is for use in APFloat IEEE-754R 2008 nextUp/nextDown function.
rdar://13852078

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182801 91177308-0d34-0410-b5e6-96231b3b80d8
2013-05-28 19:50:20 +00:00
Benjamin Kramer
ad4da0fc32 Move the SplatByte helper to APInt and generalize it a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175621 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-20 13:00:06 +00:00
Meador Inge
35b1423ee6 ADT: Correct APInt::getActiveWords for zero values
PR15138 was opened because of a segfault in the Bitcode writer.
The actual issue ended up being a bug in APInt where calls to
APInt::getActiveWords returns a bogus value when the APInt value
is 0.  This patch fixes the problem by ensuring that getActiveWords
returns 1 for 0 valued APInts.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174641 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-07 18:36:50 +00:00
Chandler Carruth
5a88dda4be Sort the #include lines for unittest/...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169250 91177308-0d34-0410-b5e6-96231b3b80d8
2012-12-04 10:23:08 +00:00
Nuno Lopes
a7a2a3635f fix the quotient returned by sdivrem() for the case when LHS is negative and RHS is positive
based on a patch by Preston Briggs, with some modifications

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157231 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-22 01:09:48 +00:00
Benjamin Kramer
0ae29a6b37 Add a unittest for rotating a really big APInt.
Clang miscompiles it under certain circumstances, and it's a good exercise for APInt.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149986 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-07 16:27:39 +00:00
Eli Friedman
3a3a424a24 Some unittests for APInt rotates; patch by Cameron McInally.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147186 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-22 22:11:19 +00:00
Dylan Noblesmith
efb0d1e42f APInt: update asserts for base-36
Hexatridecimal was added in r139695.

And fix the unittest that now triggers the assert.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146754 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-16 20:36:31 +00:00
Eli Friedman
9eb6b4d91b Fix APInt::operator*= so that it computes the correct result for large integers where there is unsigned overflow. Fix APFloat::toString so that it doesn't depend on the incorrect behavior in common cases (and computes the correct result in some rare cases). Fixes PR11086.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141441 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-07 23:40:49 +00:00
Douglas Gregor
dcd9996241 Add APInt support for converting to/from hexatridecimal strings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139695 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-14 15:54:46 +00:00
Jeffrey Yasskin
3ba292dbc2 Add APInt(numBits, ArrayRef<uint64_t> bigVal) constructor to prevent future ambiguity
errors like the one corrected by r135261.  Migrate all LLVM callers of the old
constructor to the new one.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135431 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-18 21:45:40 +00:00
Dylan Noblesmith
5f36bb1759 unittests: add test for APInt::toString()
Follow up to r133032.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133107 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-15 23:36:34 +00:00
Benjamin Kramer
d9103df51b 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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127828 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-17 20:39:06 +00:00
Cameron Zwarich
8d7285d0e5 The signed version of our "magic number" computation for the integer approximation
of a constant had a minor typo introduced when copying it from the book, which
caused it to favor negative approximations over positive approximations in many
cases. Positive approximations require fewer operations beyond the multiplication.

In the case of division by 3, we still generate code that is a single instruction
larger than GCC's code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126097 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-21 00:22:02 +00:00
Jay Foad
7a874ddda0 PR5207: Rename overloaded APInt methods set(), clear(), flip() to
setAllBits(), setBit(unsigned), etc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120564 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-01 08:53:58 +00:00
Jakob Stoklund Olesen
bc9c36bb7c Attempt to unbreak the FreeBSD buildbot by XFAILing a unit test that seems to be
miscompiled by the system gcc-4.2.1

The test remains enabled for the second-stage test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113824 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-14 00:51:58 +00:00
Chandler Carruth
48b17fa5be Switch from EXPECT_EQ({true,false, ...) to the more canonical
EXPECT_{TRUE,FALSE}(...) macros. This also prevents suprious warnings about
bool-to-pointer conversion that occurs withit EXPECT_EQ.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-13 17:28:05 +00:00
Jeffrey Yasskin
b5f59f5cf0 Fix death tests in -Asserts builds.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98701 91177308-0d34-0410-b5e6-96231b3b80d8
2010-03-17 01:18:45 +00:00
Duncan Sands
937708cea9 Pacify the compiler (signed with unsigned comparison) by making
these constants unsigned.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83962 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-13 09:23:11 +00:00
Dan Gohman
cbc7cc63b6 Add a ceilLogBase2 function to APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83932 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-13 01:49:02 +00:00
Daniel Dunbar
393317975c Fix a few more conversion warnings on 4.0
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82232 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-18 17:48:05 +00:00
Daniel Dunbar
f74610b5e7 Another try at fixing compile warnings on 4.0
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82148 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-17 17:46:53 +00:00
Daniel Dunbar
9c29730bb3 Attempt to fix some 4.0.0 build warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81752 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-14 02:38:53 +00:00
Daniel Dunbar
46e124668a Simplify, now that gtest supports raw_ostream directly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81102 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-06 02:31:26 +00:00
Chris Lattner
32e1eef631 split raw_os_ostream out to its own header and implementation file. This
means that raw_ostream no longer has to #include <iosfwd>.  Nothing in llvm
should use raw_os_ostream.h, but llvm-gcc and some unit tests do.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79886 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-24 04:02:06 +00:00
Daniel Dunbar
2571440d1e Unbreak unit tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79879 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-24 02:02:58 +00:00
Bill Wendling
5504225c2a Correct for recent assert change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79601 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-21 06:35:41 +00:00
Erick Tryzelaar
ae8f78d4de Fix bug with APInt::getBitsNeeded with for base 10 numbers 0-9.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79593 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-21 03:15:28 +00:00
Erick Tryzelaar
bb97531a5a Allow '+' to appear in APInt strings, and add more unit tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79592 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-21 03:15:14 +00:00
Erick Tryzelaar
2ad40a3663 Wrap unit test death tests in GTEST_HAS_DEATH_TEST
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79218 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-17 00:55:33 +00:00
Erick Tryzelaar
1b9104ff80 Add failure tests to APInt unit test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79209 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-16 23:36:01 +00:00
Daniel Dunbar
689ad6ef3f Convert APint::{fromString,APInt,getBitsNeeded} to use StringRef.
- Patch by Erick Tryzelaar, with some edits (and a bug fix) from me.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78885 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-13 02:33:34 +00:00
Dan Gohman
38a253ddf7 Reapply 74494, this time removing the conflicting definition of operator<<
in APIntTest.cpp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74550 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-30 20:10:56 +00:00