Calculate the rotate amount modulo the bit width.
| 1054 | |
| 1055 | // Calculate the rotate amount modulo the bit width. |
| 1056 | static unsigned rotateModulo(unsigned BitWidth, const APInt &rotateAmt) { |
| 1057 | unsigned rotBitWidth = rotateAmt.getBitWidth(); |
| 1058 | APInt rot = rotateAmt; |
| 1059 | if (rotBitWidth < BitWidth) { |
| 1060 | // Extend the rotate APInt, so that the urem doesn't divide by 0. |
| 1061 | // e.g. APInt(1, 32) would give APInt(1, 0). |
| 1062 | rot = rotateAmt.zext(BitWidth); |
| 1063 | } |
| 1064 | rot = rot.urem(APInt(rot.getBitWidth(), BitWidth)); |
| 1065 | return rot.getLimitedValue(BitWidth); |
| 1066 | } |
| 1067 | |
| 1068 | APInt APInt::rotl(const APInt &rotateAmt) const { |
| 1069 | return rotl(rotateModulo(BitWidth, rotateAmt)); |