From aa2d48cb02429f79fefb6808cbe5580fee4b611c Mon Sep 17 00:00:00 2001 From: ath0 Date: Thu, 16 May 2024 19:17:30 -0400 Subject: [PATCH] Fix funnel shift Funnel shift was using _sym_extract_helper incorrectly. The first bit index must be >= the second bit index. This caused hangs in _sym_extract_helper. Also, according to the docs llvm.fshl extracts the most-significant bits, while llvm.fshr extracts the least-significant. https://llvm.org/docs/LangRef.html#llvm-fshl-intrinsic --- src/RuntimeCommon.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RuntimeCommon.cpp b/src/RuntimeCommon.cpp index 127c81d..50061d8 100644 --- a/src/RuntimeCommon.cpp +++ b/src/RuntimeCommon.cpp @@ -437,7 +437,7 @@ SymExpr _sym_build_funnel_shift_left(SymExpr a, SymExpr b, SymExpr c) { SymExpr concat = _sym_concat_helper(a, b); SymExpr shift = _sym_build_unsigned_rem(c, _sym_build_integer(bits, bits)); - return _sym_extract_helper(_sym_build_shift_left(concat, shift), 0, bits); + return _sym_extract_helper(_sym_build_shift_left(concat, shift), 2 * bits - 1, bits); } SymExpr _sym_build_funnel_shift_right(SymExpr a, SymExpr b, SymExpr c) { @@ -445,8 +445,8 @@ SymExpr _sym_build_funnel_shift_right(SymExpr a, SymExpr b, SymExpr c) { SymExpr concat = _sym_concat_helper(a, b); SymExpr shift = _sym_build_unsigned_rem(c, _sym_build_integer(bits, bits)); - return _sym_extract_helper(_sym_build_logical_shift_right(concat, shift), 0, - bits); + return _sym_extract_helper(_sym_build_logical_shift_right(concat, shift), bits - 1, + 0); } SymExpr _sym_build_abs(SymExpr expr) {