-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Arbitrary bitwidth integers #1415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Basic Work Plan: Each item below will be considered an iteration. An iteration consists of making The iterations planned are the following (in roughly this order):
|
Related to #8, you'll have to change ConstantInt to be able to hold arbitrary bitwidth constants. Before To specifically implement #8 and ConstantInt, you probably want to make a very simple library for int64_t X = V->getZExtValue(); The random arithmetic will have to be done with the library instead of with inline C types and math. -Chris |
For this PR, i'd like to just handle bit width between 1 and 64bits. This means |
I think that handling <= 64 bits before arbitrary width integers makes sense. You'll still need a basic constant manipulation library to handle constant folding of arbitrary width -Chris |
As Chris suggested, ConstantIntegral and ConstantBool will be merged into |
The inital design of BitSet is as following: class BitSet { private: typedef uint64_t _WordTy; std::vector<_WordTy> WordVec; inline size_t BITSET_WORDS(uint16_t __n) { static size_t whichWord(size_t pos) static size_t whichByte(size_t pos) static size_t whichBit(size_t pos) static _WordTy maskBit(size_t pos) _WordTy& getWord(size_t pos) _WordTy getWord(size_t pos) const public: enum { /// Create a new BitSet of numbits bit-width, and initalized as all zeros. /// Create a new BitSet with Integer Value translated from a string. BitSet(const BitSet& BS) : WordVec(BS.WordVec) {} /// Initial bits bitwise-copied from a single word. BitSet& operator=(const BitSet& RHS) const BitSet operator++(int); const BitSet operator--(int); BitSet& operator&=(const BitSet& RHS); BitSet& operator|=(const BitSet& RHS); BitSet& operator^=(const BitSet& RHS); BitSet& operator<<=(size_t shiftAmt); BitSet& operator>>=(size_t shiftAmt); BitSet& operator~() const; BitSet& operator*=(const BitSet& RHS); /// getMaxValue - This is only for bitwidth <= 64 and /// getMinValue - This is only for bitwidth <= 64 and /// @brief Set every bit to 1. /// Set the given bit to 1 whose poition is given as "pos" /// @brief Set every bit to 0. /// Set the given bit to 0 whose position is given as "pos" /// @brief Toggle every bit to its opposite value. /// Toggle a given bit to its opposite value whose position is given as "pos" /// @brief Array-indexing support. /// Retuns a numerical interpretation of the BitSet if its bit-width <= 64 /// Retuns a character interpretation of the BitSet. /// Returns the number of bits which are set. /// Returns the total number of bits; /// Comparison of two BitSets. /// Return the index of the first "on" bit or BitsNum if all zero. BitSet operator<<(size_t shiftAmt) const; }; BitSet operator&(const BitSet& BS1, const BitSet& BS2); BitSet operator*(const BitSet& BS1, const BitSet& BS2); |
This looks right-minded, but I have concerns about efficiency. Instead, I'd like to see an approach that
The basic design of #2 permits AInt (or whatever) to be constructed on the stack with no additional -Chris |
As a meta issue, please feel free to split this up into sub-bugs for each separate issue. For example,
These can all be marked as blocking this bug. |
Current committed progress: ConstantIntegral, ConstantBool and ConstantInt have been merged to a single BoolTy has been renamed Int1Ty |
The arbitrary bitwidth integers have been implemented. This is what's left for this enhancement
|
-Chris |
That (#4) was intended to be convered under #2. The test suite will consist of |
There are now two remaining items, both being worked on by Sheng:
Once these two items are done, Sheng, this bug can be resolved. |
All tasks for this PR have been completed. |
Should this really be closed even when simple things like constant folding are broken? |
Actually, I retract that, constant folding may not be broken. Have you verified that it works though? |
Yes, there's a test suite for it. It passes. Is there something you know that I |
Nope, I just wanted to make sure you tested it. You tried stuff like 'ashr i7 -1, 3' -> -1 etc? |
Not that particular test case, but many similar ones. I just added that one to |
ok, sounds great! |
mentioned in issue llvm/llvm-bugzilla-archive#1120 |
Extended Description
This PR is a follow-up of pr950. It extends the LLVM core libraries
to accept Bit Accurate Types (BATs) into the IR. The BAT is a extension to
integral types. It supports not only traditional integral types like
BoolTy, ByteTy, IntTy, and ShortTy, LongTy (these common cases will be
renamed into Int1Ty, Int8Ty like), but also non-byte-width BATs
like Int13. The LLVM core libraries will include BATs without
modifying the existing types except rename. To do this, a subclass of
Type, saying IntType will be added into LLVM to represent BATs. Bytecode
Reader and LLVM Assembly parser will also be updated to handle BATs.
Since this is a fairly extensive change to LLVM, this bug will be used
to trackthe progress of the work as it proceeds.
The text was updated successfully, but these errors were encountered: