1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-22 12:33:33 +02:00
Commit Graph

176 Commits

Author SHA1 Message Date
John McCall
69bc985550 Teach APFloat how to create both QNaNs and SNaNs and with arbitrary-width
payloads.  APFloat's internal folding routines always make QNaNs now,
instead of sometimes making QNaNs and sometimes SNaNs depending on the
type.

llvm-svn: 97364
2010-02-28 02:51:25 +00:00
Dan Gohman
f9067da535 Add a ceilLogBase2 function to APInt.
llvm-svn: 83932
2009-10-13 01:49:02 +00:00
Chris Lattner
c02ffc37e0 remove the dead std::ostream APInt inserter
llvm-svn: 79875
2009-08-23 23:11:28 +00:00
Daniel Dunbar
3a5a25d5d5 Convert APint::{fromString,APInt,getBitsNeeded} to use StringRef.
- Patch by Erick Tryzelaar, with some edits (and a bug fix) from me.

llvm-svn: 78885
2009-08-13 02:33:34 +00:00
Dan Gohman
148d3bb9b4 Reapply 74494, this time removing the conflicting definition of operator<<
in APIntTest.cpp.

llvm-svn: 74550
2009-06-30 20:10:56 +00:00
Bill Wendling
1121a4ce5e Temporarily revert r74494. It was causing failures in the unit tests.
llvm-svn: 74515
2009-06-30 07:05:27 +00:00
Dan Gohman
f207911974 Define an operator<< for APInt to be used with std::ostream.
This will allow it to be used in unittests that use gtest's
EXPECT_EQ.

llvm-svn: 74494
2009-06-30 01:28:08 +00:00
Jay Foad
9768cabf4a Move helper functions for optimizing division by constant into the APInt
class.

llvm-svn: 70488
2009-04-30 10:15:35 +00:00
Douglas Gregor
d2b9d57e20 Add a static APInt::getNumWords
llvm-svn: 68977
2009-04-13 19:43:10 +00:00
Dan Gohman
770f4158e5 Use CHAR_BIT instead of hard-coding 8 in several places where it
is appropriate. This helps visually differentiate host-oriented
calculations from target-oriented calculations.

llvm-svn: 68227
2009-04-01 18:45:54 +00:00
Misha Brukman
380e3db1b4 Fixed lint errors:
* Alphabetized #includes
* Removed trailing whitespace
* Wrapped or shortened lines over 80 chars

llvm-svn: 65181
2009-02-20 22:20:18 +00:00
Bill Wendling
a03453cace These function return 'void'. Don't have 'return' return anything.
llvm-svn: 64136
2009-02-09 12:31:26 +00:00
Chris Lattner
816e00f6a0 eliminate use of uint32_t to improve compatibility with cygwin
llvm-svn: 62591
2009-01-20 18:23:14 +00:00
Misha Brukman
da77da48f3 Removed trailing whitespace.
llvm-svn: 62000
2009-01-09 19:25:42 +00:00
Chris Lattner
a249224590 Fix isIntN to work with APInts > 64 bits. This method is only
used by clang apparently.

llvm-svn: 60446
2008-12-02 23:33:29 +00:00
Eli Friedman
401743c904 Fix bogus assertion using getSExtValue for legitimate values, like -1 in
an 128-bit-wide integer.  No testcase; the issue I ran into depends on 
local changes.

llvm-svn: 60311
2008-12-01 00:43:48 +00:00
Chris Lattner
fc98ac247e random cleanup
llvm-svn: 57383
2008-10-11 22:06:50 +00:00
Chris Lattner
fe3155fc62 Switch the asmprinter (.ll) and all the stuff it requires over to
use raw_ostream instead of std::ostream.  Among other goodness,
this speeds up llvm-dis of kc++ with a release build from 0.85s
to 0.49s (88% faster).

Other interesting changes:
 1) This makes Value::print be non-virtual.
 2) AP[S]Int and ConstantRange can no longer print to ostream directly, 
    use raw_ostream instead.
 3) This fixes a bug in raw_os_ostream where it didn't flush itself 
    when destroyed.
 4) This adds a new SDNode::print method, instead of only allowing "dump".


A lot of APIs have both std::ostream and raw_ostream versions, it would
be useful to go through and systematically anihilate the std::ostream 
versions.

This passes dejagnu, but there may be minor fallout, plz let me know if
so and I'll fix it.

llvm-svn: 55263
2008-08-23 22:23:09 +00:00
Chris Lattner
bb8a53802b remove redundant include
llvm-svn: 55116
2008-08-21 06:41:07 +00:00
Chris Lattner
16121a7f73 Fix the build with gcc 4.3 as the host, patch by Zhongxing Xu!
llvm-svn: 55115
2008-08-21 06:25:28 +00:00
Nick Lewycky
d9012655db Fix build on GCC 4.3.
llvm-svn: 55110
2008-08-21 05:36:03 +00:00
Chris Lattner
c9fdd97035 Move the fast-path (<=i64) cases of various APInt methods inline
and the slow-path cases out of line.  This speeds up instcombine
a bit in real world cases.  Patch contributed by m-s.

llvm-svn: 55063
2008-08-20 17:02:31 +00:00
Chris Lattner
c0610874cc Rework the routines that convert AP[S]Int into a string. Now, instead of
returning an std::string by value, it fills in a SmallString/SmallVector
passed in.  This significantly reduces string thrashing in some cases.

More specifically, this:
 - Adds an operator<< and a print method for APInt that allows you to 
   directly send them to an ostream.
 - Reimplements APInt::toString to be much simpler and more efficient
   algorithmically in addition to not thrashing strings quite as much.

This speeds up llvm-dis on kc++ by 7%, and may also slightly speed up the
asmprinter.  This also fixes a bug I introduced into the asmwriter in a
previous patch w.r.t. alias printing.

llvm-svn: 54873
2008-08-17 07:19:36 +00:00
Chris Lattner
4e4a482a41 remove a dead APInt ctor.
llvm-svn: 54869
2008-08-17 04:58:58 +00:00
Duncan Sands
e667a05fcb Correct a comment.
llvm-svn: 53401
2008-07-10 11:21:59 +00:00
Wojciech Matyjewicz
1de28ac425 First step to fix PR2088. Implement routine to compute the
multiplicative inverse of a given number. Modify udivrem to allow input and 
output pairs of arguments to overlap. Patch is based on the work by Chandler
Carruth.

llvm-svn: 52638
2008-06-23 19:39:50 +00:00
Duncan Sands
a487df7710 Remove some DAG combiner assumptions about sizes
of integer types.  Fix the isMask APInt method to
actually work (hopefully) rather than crashing
because it adds apints of different bitwidths.
It looks like isShiftedMask is also broken, but
I'm leaving that one to the APInt people (it is
not used anywhere).

llvm-svn: 52142
2008-06-09 11:32:28 +00:00
Dan Gohman
edc136d18f Fix an error in the comment for APInt::getMinSignedBits.
llvm-svn: 51720
2008-05-30 00:46:49 +00:00
Evan Cheng
c2d34f03bf Suppress -Wshorten-64-to-32 warnings for 64-bit hosts.
llvm-svn: 50590
2008-05-02 21:15:08 +00:00
Dan Gohman
2b8022a8c6 Add support to APInt for shift and rotate operations with APInt
instead of uint32_t for the shift/rotate count operand type.

llvm-svn: 47741
2008-02-29 01:40:47 +00:00
Bill Wendling
ebb707d162 Detabify
llvm-svn: 47597
2008-02-26 10:49:39 +00:00
Dan Gohman
62071ec646 Remove inline keywords from in-class function definitions, for
consistency.

llvm-svn: 47393
2008-02-20 19:29:58 +00:00
Dan Gohman
00fed8a97e Add an intersects method to APInt, to capture a common idiom.
llvm-svn: 47379
2008-02-20 16:08:11 +00:00
Dan Gohman
5562e340b7 Fix a typo in a comment.
llvm-svn: 47097
2008-02-13 22:32:12 +00:00
Dan Gohman
588498082a Rename APInt's isPositive to isNonNegative, to reflect what it
actually does.

llvm-svn: 47090
2008-02-13 22:09:18 +00:00
Dan Gohman
d22101a970 Add countTrailingOnes member functions to APInt.
llvm-svn: 47086
2008-02-13 21:11:05 +00:00
Dan Gohman
547ea0a60d Fix a typo in a comment.
llvm-svn: 47085
2008-02-13 20:56:53 +00:00
Dan Gohman
f65b0b112c Change APInt::getBitsSet to accept a "half-open" range, where the
hiBit parameter marks the index one past the last desired set bit.

llvm-svn: 47032
2008-02-12 21:47:33 +00:00
Dan Gohman
b7bbe43ad3 Correct the order of the arguments in the examples in the comments
for APInt::getBitsSet. And fix an off-by-one bug in "wrapping" mode.

llvm-svn: 46978
2008-02-11 23:45:14 +00:00
Dan Gohman
3d296e049c Add an isSignedIntN, like isIntN but for signed integer values instead of
unsigned.

llvm-svn: 46894
2008-02-08 21:58:15 +00:00
Ted Kremenek
99c2b963e8 Changed argument name for 'Profile' method to potentially fix a name conflict
reported in pr1929 (http://llvm.org/PR1929).

llvm-svn: 46193
2008-01-19 17:21:43 +00:00
Ted Kremenek
702d3b8f37 Added FoldingSet style 'profiling' support for APInt.
llvm-svn: 46188
2008-01-19 04:23:33 +00:00
Chris Lattner
e0b1ee937a Don't attribute in file headers anymore. See llvmdev for the
discussion of this change.  Boy are my fingers tired. ;-)

llvm-svn: 45411
2007-12-29 19:59:42 +00:00
Chris Lattner
d62e99bd4a eliminate dependency on Bitcode headers.
llvm-svn: 44709
2007-12-08 19:01:44 +00:00
Chris Lattner
36854c740d Fix PR1816, by correcting the broken definition of APInt::countTrailingZeros.
llvm-svn: 44296
2007-11-23 22:42:31 +00:00
Ted Kremenek
7c8260f21b Fixed default ctor for APInt to properly initialize BitWidth to a
non-random value.

llvm-svn: 43795
2007-11-07 00:27:59 +00:00
Ted Kremenek
3f3b4818ef Added serialization support for APInt.
llvm-svn: 43405
2007-10-26 21:50:10 +00:00
Ted Kremenek
0347caa918 Fixed incorrect "path name" in preamble (comment) of header file.
llvm-svn: 43401
2007-10-26 20:42:45 +00:00
Neil Booth
f003f9bf1a Add a new function tcExtract for extracting a bignum from an
arbitrary range of bits embedded in the middle of another bignum.
This kind of operation is desirable in many cases of software
floating point, e.g. converting bignum integers to floating point
numbers of fixed precision (you want to extract the precision most
significant bits).

Elsewhere, add an assertion, and exit the shift functions early if
the shift count is zero.

llvm-svn: 42745
2007-10-08 13:47:12 +00:00
Neil Booth
2c4419d71b Generalize tcFullMultiply so that the operands can be of differing
part widths.  Also, return the number of parts actually required to
hold the result's value.
Remove an over-cautious condition from rounding of float->hex conversion.

llvm-svn: 42669
2007-10-06 00:24:48 +00:00
Dale Johannesen
c7279629cc Change APFloat::convertFromInteger to take the incoming
bit width instead of number of words allocated, which
makes it actually work for int->APF conversions.
Adjust callers.  Add const to one of the APInt constructors
to prevent surprising match when called with const
argument.

llvm-svn: 42210
2007-09-21 22:09:37 +00:00
Devang Patel
547d418b8e Do not hide APInt::dump() inside #ifndef NDEBUG.
llvm-svn: 42068
2007-09-17 22:24:00 +00:00
Dale Johannesen
575bd6070a Remove the assumption that FP's are either float or
double from some of the many places in the optimizers
it appears, and do something reasonable with x86
long double.
Make APInt::dump() public, remove newline, use it to
dump ConstantSDNode's.
Allow APFloats in FoldingSet.
Expand X86 backend handling of long doubles (conversions
to/from int, mostly).

llvm-svn: 41967
2007-09-14 22:26:36 +00:00
Chris Lattner
d49a347b87 getMinSignedBits needs to take into consider the sign bit when the value is positive.
llvm-svn: 41566
2007-08-29 16:21:18 +00:00
Chris Lattner
742b745b0c rename APInt::toString -> toStringUnsigned for symmetry with toStringSigned()
Add an APSInt::toString() method.

llvm-svn: 41309
2007-08-23 05:15:32 +00:00
Chris Lattner
401698e8b5 initial checkin of Neil's APFloat work.
llvm-svn: 41203
2007-08-20 22:49:32 +00:00
Chris Lattner
4c6c787315 This adds a bunch of static functions that implement unsigned
two's complement bignum arithmetic.  They could be used to
implement much of APInt, but the idea is they are enough to
implement APFloat as well, which the current APInt interface
is not suited for.

Patch by Neil Booth!

llvm-svn: 41124
2007-08-16 15:56:55 +00:00
Reid Spencer
2a23af68c8 Document a missing parameter.
llvm-svn: 40852
2007-08-05 19:36:39 +00:00
Reid Spencer
a17d02ad08 Add some things needed by the llvm-gcc version supporting bit accurate integer
types:
1. Functions to compute div/rem at the same time.
2. Further assurance that an APInt with 0 bitwidth cannot be constructed.
3. Left and right rotate operations.
4. An exactLogBase2 function which requires an exact power of two or it
   returns -1.

llvm-svn: 37025
2007-05-13 23:44:59 +00:00
Chris Lattner
d710ec51bf remove useless type qualifiers
llvm-svn: 36676
2007-05-03 17:09:36 +00:00
Reid Spencer
6e7854339e Implement a getBitsNeeded method to determine how many bits are needed to
represent a string in binary form by an APInt.

llvm-svn: 35968
2007-04-13 19:19:07 +00:00
Chris Lattner
5af0826c0b fix a comment bug Reid noticed
llvm-svn: 35864
2007-04-10 16:33:06 +00:00
Chris Lattner
9359e7f928 add a method
llvm-svn: 35860
2007-04-10 06:43:18 +00:00
Chris Lattner
5d12d66728 trivial optimization
llvm-svn: 35648
2007-04-04 06:18:21 +00:00
Chris Lattner
b5e5784b28 add missing operator
llvm-svn: 35613
2007-04-03 04:25:46 +00:00
Chris Lattner
3ff8b2cf06 add a helper function.
llvm-svn: 35585
2007-04-02 05:41:00 +00:00
Zhou Sheng
551fa60212 Remove unused methods.
llvm-svn: 35553
2007-04-01 12:45:33 +00:00
Duncan Sands
def480579a Correct typo.
llvm-svn: 35504
2007-03-30 06:39:42 +00:00
Reid Spencer
4984ab6c01 Compute getLowBitsSet correctly. Using the complement of a 64-bit value
and shifting down without regard for the bitwidth of the APInt can lead
to incorrect initialization values. Instead, check for the word size case
(to avoid undef results from shift) and then do (1 << loBitsSet) - 1

llvm-svn: 35344
2007-03-25 21:58:42 +00:00
Reid Spencer
b5b291924a Fix a typo in a comment.
llvm-svn: 35316
2007-03-25 01:13:46 +00:00
Reid Spencer
16d08887ef Actually, for getHighBitsSet and getLowBitsSet, don't make a 0 bit size
illegal. Instead do the 0 valued construction for the user. This is because
the caller may not know (or care to check) that the number of bits set is
zero.

llvm-svn: 35315
2007-03-25 00:01:47 +00:00
Reid Spencer
d24dc1f9a6 Make it illegal to set 0 bits in getHighBitsSet and getLowBitsSet. For that
they should have used the uint64_t constructor. This avoids causing
undefined results via shifts by the word size when the bit width is an
exact multiple of the word size.

llvm-svn: 35313
2007-03-24 23:47:58 +00:00
Reid Spencer
fb188ea881 In the getBitsSet function, don't optimize for a common case that is
already covered by getLowBitsSet (i.e. when loBits==0). Consequently, remove
the default value for loBits and reorder the arguments to the more natural
loBits, hiBits order. This makes it more clear that this function is for bit
groups in the middle of the bit width and not towards one end or the other.

llvm-svn: 35312
2007-03-24 23:42:47 +00:00
Reid Spencer
091d6cf3b7 Don't invoke undefined behavior in shifts in the functions getHighBitsSet
and getLowBitsSet.

llvm-svn: 35311
2007-03-24 23:35:54 +00:00
Reid Spencer
0e466b183f Implement the getBitsSet function.
llvm-svn: 35310
2007-03-24 23:27:48 +00:00
Reid Spencer
1aa3f64ef4 Implement the getHighBitsSet and getLowBitsSet functions.
llvm-svn: 35308
2007-03-24 23:05:35 +00:00
Reid Spencer
30351837ca Get the signs in the right place!
llvm-svn: 35307
2007-03-24 22:50:43 +00:00
Reid Spencer
0ceb493ee2 Undo the last change and make this really implement remainder and not
modulus. The previous change was a result of incorrect documentation in
the LangRef.html.

llvm-svn: 35305
2007-03-24 22:37:23 +00:00
Reid Spencer
c1dfceab8b Correct the implementation of srem to be remainder, not modulus. The sign of
the result must follow the sign of the divisor.

llvm-svn: 35302
2007-03-24 21:56:22 +00:00
Reid Spencer
52ea41bb97 Clean up this interface:
1. Group similar methods into doxygen groups
2. Reorganize the groups into a consist flow.
3. Significantly improve the quality of the documentation on several methods
4. Rewrite srem and sdiv to eliminate a copy and improve readability.
5. Eliminate unneeded forward references.

llvm-svn: 35300
2007-03-24 18:09:18 +00:00
Reid Spencer
76c1fef30a Fix a comment.
llvm-svn: 35246
2007-03-21 22:22:19 +00:00
Zhou Sheng
a9c0018850 Correct the name: isStrictPositive --> isStrictlyPositive.
llvm-svn: 35201
2007-03-20 02:18:16 +00:00
Reid Spencer
c3422e56d6 Add an indication of signedness to the uint64_t constructor so sign bits
can be extended. This helps fix test/Assembler/2007-03-19-NegValue.ll

llvm-svn: 35179
2007-03-19 20:36:48 +00:00
Zhou Sheng
6ecf1045a6 Add isStrictPositive() to APInt to determine if this APInt Value > 0.
llvm-svn: 35156
2007-03-19 05:22:18 +00:00
Zhou Sheng
dfcf9376bc Add zextOrCopy() into APInt for convenience.
llvm-svn: 35079
2007-03-13 06:16:26 +00:00
Zhou Sheng
9643d0a422 Add getSignBit() and operator<<= into APInt for convenience.
llvm-svn: 35059
2007-03-11 07:16:10 +00:00
Zhou Sheng
b6d1ac8682 Correct the calculation in APInt::logBase2().
llvm-svn: 34929
2007-03-05 16:42:58 +00:00
Reid Spencer
e2bf55dfe8 Regularize the interface for conversion functions to/from float/double.
llvm-svn: 34881
2007-03-03 08:34:02 +00:00
Reid Spencer
503dda5840 Make getNumWords public so that those using getRawData stand a chance of
not reading beyond the end of the buffer returned.

llvm-svn: 34873
2007-03-03 06:17:23 +00:00
Reid Spencer
47b01d6acb Add names for some of the operators. This is needed for the macros in
the Interpreter.

llvm-svn: 34872
2007-03-03 05:37:23 +00:00
Reid Spencer
e5244b132b Add isPositive for symmetry with isNegative.
llvm-svn: 34862
2007-03-03 00:24:39 +00:00
Reid Spencer
d86182b19b Add an abs() function to get the absolute value.
llvm-svn: 34819
2007-03-01 23:37:09 +00:00
Reid Spencer
003170430b Add doubleToBits and floatToBits methods.
llvm-svn: 34807
2007-03-01 20:39:01 +00:00
Reid Spencer
90b6227b81 Add bitsToDouble and bitsToFloat methods for re-interpretation of bits as FP.
llvm-svn: 34800
2007-03-01 20:06:51 +00:00
Reid Spencer
6a95676875 Add methods for bit width modification: sextOrTrunc, zextOrTrunc.
llvm-svn: 34789
2007-03-01 17:15:32 +00:00
Reid Spencer
b6dd32889e Add a square root function.
llvm-svn: 34775
2007-03-01 05:39:56 +00:00
Reid Spencer
0f2d45e42c Make APInt a little more friendly to its users:
* Add support for + and - of a uint64_t.
  * Make trunc/sext/zext return *this so it can be chained with other ops
  * Add smin, smax, umin, umax functions for getting min/max values.

llvm-svn: 34742
2007-02-28 17:33:36 +00:00
Reid Spencer
949b3612a8 getActiveWords should return the number of words, not the index of the
highest active words. Increment its result by one.

llvm-svn: 34713
2007-02-28 02:20:49 +00:00
Reid Spencer
355cec42d1 Add some syntactic sugar.
llvm-svn: 34704
2007-02-27 23:47:33 +00:00
Reid Spencer
edbe747bab Implement countLeadingOnes() and getMinSignedBits(). This helps to minimize
the bit width of negative numbers by computing the minimum bit width for a
negative value. E.g. 0x1800000000000000 could be just 0x8000000000000000

llvm-svn: 34695
2007-02-27 21:59:26 +00:00