Zero extend to a new width.
| 933 | |
| 934 | // Zero extend to a new width. |
| 935 | APInt APInt::zext(unsigned width) const { |
| 936 | assert(width > BitWidth && "Invalid APInt ZeroExtend request"); |
| 937 | |
| 938 | if (width <= APINT_BITS_PER_WORD) |
| 939 | return APInt(width, U.VAL); |
| 940 | |
| 941 | APInt Result(getMemory(getNumWords(width)), width); |
| 942 | |
| 943 | // Copy words. |
| 944 | std::memcpy(Result.U.pVal, getRawData(), getNumWords() * APINT_WORD_SIZE); |
| 945 | |
| 946 | // Zero remaining words. |
| 947 | std::memset(Result.U.pVal + getNumWords(), 0, |
| 948 | (Result.getNumWords() - getNumWords()) * APINT_WORD_SIZE); |
| 949 | |
| 950 | return Result; |
| 951 | } |
| 952 | |
| 953 | APInt APInt::zextOrTrunc(unsigned width) const { |
| 954 | if (BitWidth < width) |
no test coverage detected