On 8/4/24 12:35 PM, Mary Bennett wrote:
Spec:
github.com/openhwgroup/core-v-sw/blob/master/specifications/corev-builtin-spec.md
Contributors:
Mary Bennett <mary.bennett...@gmail.com>
Nandni Jamnadas <nandni.jamna...@embecosm.com>
Pietra Ferreira <pietra.ferre...@embecosm.com>
Charlie Keaney
Jessica Mills
Craig Blackmore <craig.blackm...@embecosm.com>
Simon Cook <simon.c...@embecosm.com>
Jeremy Bennett <jeremy.benn...@embecosm.com>
Helene Chelin <helene.che...@embecosm.com>
gcc/ChangeLog:
* common/config/riscv/riscv-common.cc: Add XCVbitmanip.
* config/riscv/constraints.md: Likewise.
* config/riscv/corev.def: Likewise.
* config/riscv/corev.md: Likewise.
* config/riscv/predicates.md: Likewise.
* config/riscv/riscv-builtins.cc (AVAIL): Likewise.
* config/riscv/riscv-ftypes.def: Likewise.
* config/riscv/riscv.opt: Likewise.
* doc/extend.texi: Add XCVbitmanip builtin documentation.
* doc/sourcebuild.texi: Likewise.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/cv-bitmanip-compile-bclr.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-bclrr.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-bitrev.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-bset.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-bsetr.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-clb.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-cnt.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-extract.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-extractr.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-extractu.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-extractur.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-ff1.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-fl1.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-insert.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-insertr.c: New test.
* gcc.target/riscv/cv-bitmanip-compile-ror.c: New test.
* gcc.target/riscv/cv-bitmanip-fail-compile-bclr.c: New test.
* gcc.target/riscv/cv-bitmanip-fail-compile-bitrev.c: New test.
* gcc.target/riscv/cv-bitmanip-fail-compile-bset.c: New test.
* gcc.target/riscv/cv-bitmanip-fail-compile-extract.c: New test.
* gcc.target/riscv/cv-bitmanip-fail-compile-extractu.c: New test.
* gcc.target/riscv/cv-bitmanip-fail-compile-insert.c: New test.
* lib/target-supports.exp: Add proc for the XCVbitmanip extension.
---
@@ -281,3 +286,14 @@
"Shifting immediate for SIMD shufflei3."
(and (match_code "const_int")
(match_test "IN_RANGE (ival, -64, -1)")))
+
+(define_constraint "CV_bit_si10"
+ "A 10-bit unsigned immediate for CORE-V bitmanip."
+ (and (match_code "const_int")
+ (match_test "IN_RANGE (ival, 0, 1023)")))
+
+(define_constraint "CV_bit_in10"
+ "A 10-bit unsigned immediate for CORE-V bitmanip insert."
+ (and (match_code "const_int")
+ (and (match_test "IN_RANGE (ival, 0, 1023)")
+ (match_test "(ival & 31) + ((ival >> 5) & 31) <= 32"))))
I probably asked this before, but this seems really odd. why would we
need 10 bits for a bitmanip operations?
@@ -2651,3 +2653,189 @@
}
[(set_attr "type" "branch")
(set_attr "mode" "none")])
+
+;; XCVBITMANIP builtins
+
+(define_insn "riscv_cv_bitmanip_extract"
+ [(set (match_operand:SI 0 "register_operand" "=r,r")
+ (sign_extract:SI
+ (match_operand:SI 1 "register_operand" "r,r")
+ (ashiftrt:SI
+ (match_operand:HI 2 "bit_extract_operand" "CV_bit_si10,r")
+ (const_int 5))
+ (plus:SI
+ (and:SI
+ (match_dup 2)
+ (const_int 31))
+ (const_int 1))))]
That (ashiftrt (operand) (const_int 5) seems really weird to me and it's
almost certainly related to the question about needing 10 bits in
predicates.
+
+(define_insn "riscv_cv_bitmanip_ff1"
+ [(set (match_operand:SI 0 "register_operand" "=r")
+ (ctz:SI (match_operand:SI 1 "register_operand" "r")))]
+
+ "TARGET_XCVBITMANIP && !TARGET_64BIT"
+ "cv.ff1\t%0,%1"
+ [(set_attr "type" "bitmanip")
+ (set_attr "mode" "SI")])
+
+(define_insn "riscv_cv_bitmanip_fl1"
+ [(set (match_operand:SI 0 "register_operand" "=r")
+ (minus:SI
+ (const_int 31)
+ (clz:SI (match_operand:SI 1 "register_operand" "r"))))]
+
+ "TARGET_XCVBITMANIP && !TARGET_64BIT"
+ "cv.fl1\t%0,%1"
+ [(set_attr "type" "bitmanip")
+ (set_attr "mode" "SI")])
So presumably only available in 32bit mode? Which means they're no
great candidates for merging with the standard patterns since they use
the GPR iterator. Similarly for popcount.
I'm leaning more and more against trying to merge any of this with
bitmanip.md. I think it'll largely come down to whether or not there
appears to be an ability to merge the single bit manipulation patterns.
Right now with the weird 10 bit stuff above, that doesn't look likely
either.
Jeff