OLD | NEW |
(Empty) | |
| 1 //===-- subzero/src/IceAPInt.h - Constant integer conversions --*- C++ -*--===// |
| 2 // |
| 3 // The LLVM Compiler Infrastructure |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 /// |
| 10 /// \file |
| 11 /// \brief This file implements a class to represent 64 bit integer constant |
| 12 /// values, and thier conversion to variable bit sized integers. |
| 13 /// |
| 14 /// Note: This is a simplified version of llvm/include/llvm/ADT/APInt.h for use |
| 15 /// with Subzero. |
| 16 //===----------------------------------------------------------------------===// |
| 17 |
| 18 #ifndef SUBZERO_SRC_ICEAPINT_H |
| 19 #define SUBZERO_SRC_ICEAPINT_H |
| 20 |
| 21 #include "IceDefs.h" |
| 22 |
| 23 namespace Ice { |
| 24 |
| 25 class APInt { |
| 26 public: |
| 27 /// Bits in an (internal) value. |
| 28 static const SizeT APINT_BITS_PER_WORD = sizeof(uint64_t) * CHAR_BIT; |
| 29 |
| 30 APInt(SizeT Bits, uint64_t Val) : BitWidth(Bits), Val(Val) { |
| 31 assert(Bits && "bitwidth too small"); |
| 32 assert(Bits <= APINT_BITS_PER_WORD && "bitwidth too big"); |
| 33 clearUnusedBits(); |
| 34 } |
| 35 |
| 36 uint32_t getBitWidth() const { return BitWidth; } |
| 37 |
| 38 int64_t getSExtValue() const { |
| 39 return static_cast<int64_t>(Val << (APINT_BITS_PER_WORD - BitWidth)) >> |
| 40 (APINT_BITS_PER_WORD - BitWidth); |
| 41 } |
| 42 |
| 43 uint64_t getRawData() const { return Val; } |
| 44 |
| 45 private: |
| 46 uint32_t BitWidth; // The number of bits in this APInt. |
| 47 uint64_t Val; // The (64-bit) equivalent integer value. |
| 48 |
| 49 /// Clear unused high order bits. |
| 50 void clearUnusedBits() { |
| 51 // If all bits are used, we want to leave the value alone. |
| 52 if (BitWidth == APINT_BITS_PER_WORD) |
| 53 return; |
| 54 |
| 55 // Mask out the high bits. |
| 56 Val &= ~static_cast<uint64_t>(0) >> (APINT_BITS_PER_WORD - BitWidth); |
| 57 } |
| 58 }; |
| 59 |
| 60 } // end of namespace Ice |
| 61 |
| 62 #endif // SUBZERO_SRC_ICEAPINT_H |
OLD | NEW |