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 SizeT APINT_BITS_PER_WORD = | |
Jim Stichnoth
2014/12/12 21:54:16
This should be static const, or an enum value.
Karl
2014/12/12 22:46:12
Done.
| |
29 static_cast<uint32_t>(sizeof(uint64_t)) * CHAR_BIT; | |
Jim Stichnoth
2014/12/12 21:54:16
I'm not sure the static_cast is actually needed, b
Karl
2014/12/12 22:46:12
Simplified.
| |
30 | |
31 APInt(SizeT Bits, uint64_t Val) : BitWidth(Bits), Val(Val) { | |
32 assert(BitWidth && "bitwidth too small"); | |
33 assert(Bits <= APINT_BITS_PER_WORD && "bitwidth too big"); | |
Jim Stichnoth
2014/12/12 21:54:16
Use Bits in both asserts, or BitWidth in both asse
Karl
2014/12/12 22:46:12
Done.
| |
34 clearUnusedBits(); | |
35 } | |
36 | |
37 uint32_t getBitWidth() const { return BitWidth; } | |
38 | |
39 uint64_t getSExtValue() const { | |
Jim Stichnoth
2014/12/12 21:54:16
Should this return int64_t like the llvm::Constant
Karl
2014/12/12 22:46:12
Done.
| |
40 return static_cast<int64_t>((Val << (APINT_BITS_PER_WORD - BitWidth)) >> | |
Karl
2014/12/12 22:46:13
Bug was missing parenthesis before last ">>" on li
| |
41 (APINT_BITS_PER_WORD - BitWidth)); | |
42 } | |
43 | |
44 uint64_t getRawData() const { return Val; } | |
45 | |
46 private: | |
47 uint32_t BitWidth; // The number of bits in this APInt. | |
48 uint64_t Val; // The (64-bit) equivalent integer value. | |
49 | |
50 /// Clear unused high order bits. | |
51 void clearUnusedBits() { | |
52 // If all bits are used, we want to leave the value alone. | |
53 if (BitWidth == APINT_BITS_PER_WORD) | |
54 return; | |
55 | |
56 // Mask out the high bits. | |
57 Val &= ~static_cast<uint64_t>(0) >> (APINT_BITS_PER_WORD - BitWidth); | |
58 } | |
59 }; | |
60 | |
61 } // end of namespace Ice | |
62 | |
63 #endif // SUBZERO_SRC_ICEAPINT_H | |
OLD | NEW |