[flang-commits] [PATCH] D123707: [flang] Fold IBITS() intrinsic function
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Apr 13 17:06:33 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG34cc706b9664: [flang] Fold IBITS() intrinsic function (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123707/new/
https://reviews.llvm.org/D123707
Files:
flang/lib/Evaluate/fold-integer.cpp
flang/test/Evaluate/fold-ibits.f90
Index: flang/test/Evaluate/fold-ibits.f90
===================================================================
--- /dev/null
+++ flang/test/Evaluate/fold-ibits.f90
@@ -0,0 +1,13 @@
+! RUN: %python %S/test_folding.py %s %flang_fc1
+! Tests folding of IBITS exhaustively over POS/LEN ranges
+module m1
+ implicit integer(a-z)
+ integer, parameter :: res1(*) = [((ibits(not(0),pos,len),len=0,31-pos),pos=0,31)]
+ integer, parameter :: expect1(*) = [((maskr(len),len=0,31-pos),pos=0,31)]
+ logical, parameter :: test1 = all(res1 == expect1)
+ logical, parameter :: test2 = all([((ibits(0,pos,len),len=0,31-pos),pos=0,31)] == 0)
+ integer, parameter :: mess = z'a5a55a5a'
+ integer, parameter :: res3(*) = [((ibits(mess,pos,len),len=0,31-pos),pos=0,31)]
+ integer, parameter :: expect3(*) = [((iand(shiftr(mess,pos),maskr(len)),len=0,31-pos),pos=0,31)]
+ logical, parameter :: test3 = all(res3 == expect3)
+end module
Index: flang/lib/Evaluate/fold-integer.cpp
===================================================================
--- flang/lib/Evaluate/fold-integer.cpp
+++ flang/lib/Evaluate/fold-integer.cpp
@@ -562,6 +562,28 @@
}
return std::invoke(fptr, i, posVal);
}));
+ } else if (name == "ibits") {
+ return FoldElementalIntrinsic<T, T, Int4, Int4>(context, std::move(funcRef),
+ ScalarFunc<T, T, Int4, Int4>([&](const Scalar<T> &i,
+ const Scalar<Int4> &pos,
+ const Scalar<Int4> &len) -> Scalar<T> {
+ auto posVal{static_cast<int>(pos.ToInt64())};
+ auto lenVal{static_cast<int>(len.ToInt64())};
+ if (posVal < 0) {
+ context.messages().Say(
+ "bit position for IBITS(POS=%d,LEN=%d) is negative"_err_en_US,
+ posVal, lenVal);
+ } else if (lenVal < 0) {
+ context.messages().Say(
+ "bit length for IBITS(POS=%d,LEN=%d) is negative"_err_en_US,
+ posVal, lenVal);
+ } else if (posVal + lenVal > i.bits) {
+ context.messages().Say(
+ "IBITS(POS=%d,LEN=%d) must have POS+LEN no greater than %d"_err_en_US,
+ posVal + lenVal, i.bits);
+ }
+ return i.IBITS(posVal, lenVal);
+ }));
} else if (name == "index" || name == "scan" || name == "verify") {
if (auto *charExpr{UnwrapExpr<Expr<SomeCharacter>>(args[0])}) {
return std::visit(
@@ -949,7 +971,7 @@
} else if (name == "ubound") {
return UBOUND(context, std::move(funcRef));
}
- // TODO: dot_product, ibits, ishftc, matmul, sign, transfer
+ // TODO: dot_product, ishftc, matmul, sign, transfer
return Expr<T>{std::move(funcRef)};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123707.422698.patch
Type: text/x-patch
Size: 2738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220414/b7298830/attachment.bin>
More information about the flang-commits
mailing list