[llvm] [ADT] Add fshl/fshr operations to APInt (PR #153790)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 16 07:06:38 PDT 2025


================
@@ -2410,6 +2410,33 @@ LLVM_ABI std::optional<unsigned> GetMostSignificantDifferentBit(const APInt &A,
 /// A.getBitwidth() or NewBitWidth must be a whole multiples of the other.
 LLVM_ABI APInt ScaleBitMask(const APInt &A, unsigned NewBitWidth,
                             bool MatchAllBits = false);
+
+/// Perform a funnel shift left.
+///
+/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
+/// the combined value is shifted left by Shift, and the most significant bits
+/// are extracted to produce a result that is the same size as the original
+/// arguments.
+///
+/// Examples:
+/// (1) fshl(i8 255, i8 0, i8 15) = 128 (0b10000000)
+/// (2) fshl(i8 15, i8 15, i8 11) = 120 (0b01111000)
+/// (3) fshl(i8 0, i8 255, i8 8)  = 0   (0b00000000)
+LLVM_ABI APInt fshl(const APInt &Hi, const APInt &Lo, const APInt &Shift);
+
+/// Perform a funnel shift right.
+///
+/// Concatenate Hi and Lo (Hi is the most significant bits of the wide value),
+/// the combined value is shifted right by Shift, and the least significant bits
+/// are extracted to produce a result that is the same size as the original
+/// arguments.
+///
+/// Examples:
----------------
kuhar wrote:

Also here, what's the result of shifting by more than the combined bitwidth?

https://github.com/llvm/llvm-project/pull/153790


More information about the llvm-commits mailing list