Commit Graph

78 Commits

Author SHA1 Message Date
Reid Spencer 67378b22bb We want the number of bits needed, not the power of 2.
llvm-svn: 35977
2007-04-14 00:00:10 +00:00
Reid Spencer 9329e7b626 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
Reid Spencer c49f2ef236 Fix an approximate calculation in an assertion not to give false negatives.
llvm-svn: 35901
2007-04-11 13:00:04 +00:00
Zhou Sheng 0458c1db71 Fix a bug in getAllOnesValue() which broke
some test cases for bitwidth > 64.

llvm-svn: 35232
2007-03-21 04:34:37 +00:00
Jeff Cohen e06855e684 Fix (and simplify) 48-bit byte swap.
Get pos/neg infinity the correct way.

llvm-svn: 35223
2007-03-20 20:42:36 +00:00
Reid Spencer b1ec2e8ec7 Fix coding standards violation.
llvm-svn: 35189
2007-03-19 21:19:02 +00:00
Reid Spencer 6fae35acd3 Implement extension of sign bits for negative values in the uint64_t
constructor. This helps to fix test/Assembler/2007-03-19-NegValue.ll

llvm-svn: 35180
2007-03-19 20:37:47 +00:00
Reid Spencer 6223c05805 Revert the last patch as it violates the conditions of sext/zext.
llvm-svn: 35068
2007-03-12 18:37:25 +00:00
Zhou Sheng 3999ffa0c8 For APInt::z/sext(width), if width == BitWidth, just return *this.
llvm-svn: 35065
2007-03-12 17:47:45 +00:00
Jeff Cohen b622c11f77 Unbreak VC++ build.
llvm-svn: 34917
2007-03-05 00:00:42 +00:00
Reid Spencer 1825dd0d7c Fix ashr for bitwidths > 64. This is now validated up to 1024 bits.
llvm-svn: 34852
2007-03-02 22:39:11 +00:00
Reid Spencer cf8175617d Use a better algorithm for rounding sqrt results. Change the FIXME about
this to a NOTE: because pari/gp results start to get rounded incorrectly
after 192 bits of precision. APInt and pari/gp never differ by more than
1, but APInt is more accurate because it does not lose precision after 192
bits as does pari/gp.

llvm-svn: 34834
2007-03-02 04:21:55 +00:00
Reid Spencer c44bdae16b Add a FIXME
llvm-svn: 34828
2007-03-02 02:01:34 +00:00
Reid Spencer c442c84c8f Fix a problem where shifting by 64-bits leads to incorrect results on PPC
but not on X86 becuase shift by word size is "undefined".

llvm-svn: 34825
2007-03-02 01:19:42 +00:00
Reid Spencer 1b8dfcbaaa Combine two lines that can be.
llvm-svn: 34818
2007-03-01 23:30:25 +00:00
Reid Spencer 2f6ad4d3c3 Make the static table of results in sqrt const.
llvm-svn: 34791
2007-03-01 17:47:31 +00:00
Reid Spencer 742d1704e1 Add methods for bit width modification: sextOrTrunc, zextOrTrunc.
llvm-svn: 34789
2007-03-01 17:15:32 +00:00
Reid Spencer c8841d2ea2 Use a real table in sqrt to shorten and quicken the code.
Thanks for the idea Chris.

llvm-svn: 34779
2007-03-01 06:23:32 +00:00
Reid Spencer d99feafd5f Add a square root function.
llvm-svn: 34775
2007-03-01 05:39:56 +00:00
Reid Spencer 91d3b3fce9 Make the trunc/sext/zext methods return APInt& so that these operations
can be chained together with other operations.

llvm-svn: 34743
2007-02-28 17:34:32 +00:00
Reid Spencer 66d0d572c2 Fix a bug in RoundDoubleToAPInt where it would force the size to 64 bits
instead of honoring the client's requested bit width.

llvm-svn: 34712
2007-02-28 01:30:08 +00:00
Reid Spencer c2d433d47a Join two lines that can be joined.
llvm-svn: 34705
2007-02-27 23:49:07 +00:00
Reid Spencer 31acef50ad 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
Reid Spencer 70cb5d4287 Improve APInt interface:
1. Add unsigned and signed versions of methods so a "bool" argument doesn't
   need to be passed in.
2. Make the various getMin/getMax functions all be inline since they are
   so simple.
3. Simplify sdiv and srem code.

llvm-svn: 34680
2007-02-27 20:24:31 +00:00
Reid Spencer 997d9e4585 Conform to single person attribution in file comment.
llvm-svn: 34678
2007-02-27 19:31:09 +00:00
Reid Spencer 54abdcf30b 1. Fix three serious bugs in the comparison code.
2. Change RoundDoubleToAPInt to take a bit width parameter. Use that
   parameter to limit the bit width of the result.

llvm-svn: 34673
2007-02-27 18:23:40 +00:00
Reid Spencer 011651745c Get rid of extraneous // in file comment.
llvm-svn: 34662
2007-02-27 07:35:18 +00:00
Reid Spencer 974551a7e9 Simplify and document RoundDoubleToAPInt.
llvm-svn: 34648
2007-02-27 01:28:10 +00:00
Reid Spencer 7c16cd2746 1. Make sure all delete operators of arrays use the array form of delete.
2. Rewrite operator=(const APInt& RHS) to allow the RHS to be a different
   bit width than the LHS. This makes it possible to use APInt as the key
   of a DenseMap, as needed for the IntConstants map in Constants.cpp
3. Fix operator=(uint64_t) to clear unused bits in case the client assigns
   a value that has more bits than the APInt allows.
4. Assert that bit widths are equal in operator==
5. Revise getHashValue() to put the bit width in the low order six bits.
   This should help to make i1 0, i2 0, ... i64 0 all distinct in the
   IntConstants DenseMap.

llvm-svn: 34646
2007-02-26 23:38:21 +00:00
Reid Spencer b2bc985a4e Implement the getHashValue method.
Fix toString use of getValue to use getZExtValue()

llvm-svn: 34642
2007-02-26 21:02:27 +00:00
Reid Spencer f09418d428 Re-enable this. The header was committed.
llvm-svn: 34634
2007-02-26 08:10:54 +00:00
Chris Lattner d9fc268035 another missing header :( :( :(
llvm-svn: 34632
2007-02-26 07:51:00 +00:00
Reid Spencer aa8dcfe441 1. Remove redundant calls to clearUsedBits().
2. Fix countTrailingZeros to use a faster algorithm.
3. Simplify sext() slightly by using isNegative().
4. Implement ashr using word-at-a-time logic instead of bit-at-a-time
5. Rename locals named isNegative so they don't clash with method name.
6. Fix fromString to compute negated value correctly.

llvm-svn: 34629
2007-02-26 07:44:38 +00:00
Reid Spencer 44eef169fa Rewrite lshr to not do bit by bit copy but to copy and shift whole words.
This makes it much more efficient.

llvm-svn: 34618
2007-02-26 01:19:48 +00:00
Reid Spencer fb55b7b99d Fix sext operation. Shifting by zero would leave an incorrect mask.
llvm-svn: 34617
2007-02-25 23:54:00 +00:00
Reid Spencer b6b5cc3e2f 1. Fix the flip() method to correctly flip all words of the APInt.
2. Implement the trunc, sext, and zext operations.
3. Improve fromString to accept negative values as input.

llvm-svn: 34616
2007-02-25 23:44:53 +00:00
Reid Spencer a41e93be3d 1. Provide more detail in file comment.
2. Move comments for methods to .h file, delete them in .cpp file.
3. All places that were doing manual clear of high order bits now call the
   clearUnusedBits() method in order to not depend on undefined behavior
   of the >> operator when the number of bits shifted equals the word size.
4. Reduced # of loc by using the new result of clearUnusedBits() method.
5. Simplified logic (decreased indentation) in a few places.
6. Added code comments to larger functions that needed them.
7. Added FIXME notes about weak implementations of things (e.g. bit-by-bit
   shift right is sub-optimal).

llvm-svn: 34603
2007-02-25 19:32:03 +00:00
Reid Spencer 28555779b4 Allow this to compile now that the header file is checked in.
llvm-svn: 34581
2007-02-25 07:30:14 +00:00
Chris Lattner 4ae31ba82c this doesn't compile, disable it
llvm-svn: 34571
2007-02-25 02:32:44 +00:00
Reid Spencer 522ca7cd8b Clean up lshr and ashr to coding standards.
Handle the single word cases for shiftAmt == BitWidth.

llvm-svn: 34569
2007-02-25 01:56:07 +00:00
Reid Spencer ab0e08ae2f Whoops, last word with bits in large shift left wasn't correct.
llvm-svn: 34565
2007-02-25 01:08:58 +00:00
Reid Spencer a5c84d95fa Fix the > 64 bits case for left shift.
llvm-svn: 34564
2007-02-25 00:56:44 +00:00
Reid Spencer 468ad911cb Fix the remainder shifting in KnuthDiv.
llvm-svn: 34562
2007-02-24 20:38:01 +00:00
Reid Spencer 632ebdf8bd 1. Fix a bug in fromString for the <= 64bits case
2. Fix shl when shiftAmount == BitWidth.

llvm-svn: 34560
2007-02-24 20:19:37 +00:00
Reid Spencer df6cf5ab71 1. Fix last bug in KnuthDiv. All divide tests pass up to 1024 bits now.
2. Clean up comments, style, coding standards, etc.
3. Simplify a constructor.

Extended testing revealed some additional bugs in shifting. I'll fix these
tomorrow.

llvm-svn: 34559
2007-02-24 10:01:42 +00:00
Reid Spencer a5e0d200c9 1. Make internal functions take const arguments where they should, just
to be safe.
2. Make internal functions that return a carry/borrow return bool instead
   of uint64_t because the carry/borrow can only be in range [0,1].
3. Assert that the pointers to KnuthDiv are all different so that the
   result and operands can't overlap.
4. Add debug output to KnuthDiv function.
5. Fix a problem with KnuthDiv by separating the b's complement operation
   from the subtraction borrow operation. This fixes a wide range of
   division problems, but alas, not all of them.

llvm-svn: 34554
2007-02-24 03:58:46 +00:00
Reid Spencer cb292e4a20 1. Fix a carry out problem in add if destination and x point to the same
memory (as done in fromString).
2. Implement Knuth divide more closely to what is recommended in his book.
3. Fix computation of the remainder for Knuth Divide (bad shifting).
4. Remove some cruft from the file

llvm-svn: 34518
2007-02-23 01:57:13 +00:00
Reid Spencer 867b4064ae When converting from 64 to 32-bits, use the actual number of words to
extract the value, not the number of words implied by the active bits.
This fixes numerous, but not all divide bugs.

llvm-svn: 34484
2007-02-22 00:58:45 +00:00
Reid Spencer e4ce71d07a Fix countLeadingZeros in the case that the bitwidth evenly divides the
word size. This fixes all reads of uninitialized data (buffer over read)
and makes APInt.cpp memory clean, per valgrind. The only remaining
problem is division in a few cases.

llvm-svn: 34483
2007-02-22 00:22:00 +00:00
Reid Spencer 58a6a43cb3 Reorganize some code to make it clearer, avoid a few uninitialized memory
reads, and reduce the number of temporary APInt instances we construct.

llvm-svn: 34467
2007-02-21 08:21:52 +00:00