diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-03-21 15:00:35 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-03-21 15:00:35 +0000 |
commit | 155dda9134c4f771ffc75864a6a0554309ec0531 (patch) | |
tree | 10aca4ba2ea82b5e4a0af626147204498de58685 /llvm/lib/Support/APInt.cpp | |
parent | 0d2ad420df9446392c7d8b645b3fa88f553f860c (diff) | |
download | bcm5719-llvm-155dda9134c4f771ffc75864a6a0554309ec0531.tar.gz bcm5719-llvm-155dda9134c4f771ffc75864a6a0554309ec0531.zip |
Implement constant folding for bitreverse
llvm-svn: 263945
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 83455f67665..970c703cb51 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -787,6 +787,36 @@ APInt APInt::byteSwap() const { return Result; } +APInt APInt::reverseBits() const { + switch (BitWidth) { + case 64: + return APInt(BitWidth, llvm::reverseBits<uint64_t>(VAL)); + case 32: + return APInt(BitWidth, llvm::reverseBits<uint32_t>(VAL)); + case 16: + return APInt(BitWidth, llvm::reverseBits<uint16_t>(VAL)); + case 8: + return APInt(BitWidth, llvm::reverseBits<uint8_t>(VAL)); + default: + break; + } + + APInt Val(*this); + APInt Reversed(*this); + int S = BitWidth - 1; + + const APInt One(BitWidth, 1); + + for ((Val = Val.lshr(1)); Val != 0; (Val = Val.lshr(1))) { + Reversed <<= 1; + Reversed |= (Val & One); + --S; + } + + Reversed <<= S; + return Reversed; +} + APInt llvm::APIntOps::GreatestCommonDivisor(const APInt& API1, const APInt& API2) { APInt A = API1, B = API2; |