https://github.com/Michael-Chen-NJU created https://github.com/llvm/llvm-project/pull/238758
Add the scalar Bitmanip intrinsics `__riscv_wzip8p_64` and `__riscv_wzip16p_64` using the existing packed zip intrinsics. From 61f643f04d68c31adc32c8c6bb84d2fb185a9535 Mon Sep 17 00:00:00 2001 From: Michael-Chen-NJU <[email protected]> Date: Wed, 4 Nov 2026 19:46:50 +0800 Subject: [PATCH] [Clang][RISCV] Add scalar widening zip intrinsics --- clang/lib/Headers/riscv_packed_simd.h | 11 +++++ clang/test/CodeGen/RISCV/rvp-intrinsics.c | 48 +++++++++++++++++++ .../riscv_packed_simd.c | 14 ++++++ 3 files changed, 73 insertions(+) diff --git a/clang/lib/Headers/riscv_packed_simd.h b/clang/lib/Headers/riscv_packed_simd.h index 89f678a63e94e6..10c253741587a9 100644 --- a/clang/lib/Headers/riscv_packed_simd.h +++ b/clang/lib/Headers/riscv_packed_simd.h @@ -972,6 +972,17 @@ __packed_zip4(pzip_u8x8, uint8x8_t, uint8x4_t) __packed_zip2(pzip_i16x4, int16x4_t, int16x2_t) __packed_zip2(pzip_u16x4, uint16x4_t, uint16x2_t) +/* Scalar Widening Zip */ +static __inline__ uint64_t __DEFAULT_FN_ATTRS +__riscv_wzip8p_64(uint32_t __rs1, uint32_t __rs2) { + return (uint64_t)__riscv_pzip_u8x8((uint8x4_t)__rs1, (uint8x4_t)__rs2); +} + +static __inline__ uint64_t __DEFAULT_FN_ATTRS +__riscv_wzip16p_64(uint32_t __rs1, uint32_t __rs2) { + return (uint64_t)__riscv_pzip_u16x4((uint16x2_t)__rs1, (uint16x2_t)__rs2); +} + /* Packed Unzip */ __packed_unzipe4(punzipe_i8x4, int8x4_t, int8x8_t) __packed_unzipo4(punzipo_i8x4, int8x4_t, int8x8_t) diff --git a/clang/test/CodeGen/RISCV/rvp-intrinsics.c b/clang/test/CodeGen/RISCV/rvp-intrinsics.c index 956d80beb1228b..0a64157fbd2ca4 100644 --- a/clang/test/CodeGen/RISCV/rvp-intrinsics.c +++ b/clang/test/CodeGen/RISCV/rvp-intrinsics.c @@ -204,6 +204,54 @@ uint32_t test_asubu_u32(uint32_t a, uint32_t b) { return __riscv_asubu_u32(a, b); } +/* Scalar Widening Zip */ + +// CHECK-LABEL: define dso_local i64 @test_wzip8p_64( +// RV32-SAME: i32 noundef [[RS1:%.*]], i32 noundef [[RS2:%.*]]) #[[ATTR0]] { +// RV64-SAME: i32 noundef signext [[RS1:%.*]], i32 noundef signext [[RS2:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[TMP0:%.*]] = bitcast i32 [[RS1]] to <4 x i8> +// CHECK-NEXT: [[TMP1:%.*]] = bitcast i32 [[RS2]] to <4 x i8> +// CHECK-NEXT: [[SHUFFLE_I:%.*]] = shufflevector <4 x i8> [[TMP0]], <4 x i8> [[TMP1]], <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7> +// CHECK-NEXT: [[TMP2:%.*]] = bitcast <8 x i8> [[SHUFFLE_I]] to i64 +// CHECK-NEXT: ret i64 [[TMP2]] +// +uint64_t test_wzip8p_64(uint32_t rs1, uint32_t rs2) { + return __riscv_wzip8p_64(rs1, rs2); +} + +// CHECK-LABEL: define dso_local i64 @test_wzip16p_64( +// RV32-SAME: i32 noundef [[RS1:%.*]], i32 noundef [[RS2:%.*]]) #[[ATTR0]] { +// RV64-SAME: i32 noundef signext [[RS1:%.*]], i32 noundef signext [[RS2:%.*]]) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: [[TMP0:%.*]] = bitcast i32 [[RS1]] to <2 x i16> +// CHECK-NEXT: [[TMP1:%.*]] = bitcast i32 [[RS2]] to <2 x i16> +// CHECK-NEXT: [[SHUFFLE_I:%.*]] = shufflevector <2 x i16> [[TMP0]], <2 x i16> [[TMP1]], <4 x i32> <i32 0, i32 2, i32 1, i32 3> +// CHECK-NEXT: [[TMP2:%.*]] = bitcast <4 x i16> [[SHUFFLE_I]] to i64 +// CHECK-NEXT: ret i64 [[TMP2]] +// +uint64_t test_wzip16p_64(uint32_t rs1, uint32_t rs2) { + return __riscv_wzip16p_64(rs1, rs2); +} + +// CHECK-LABEL: define dso_local i64 @test_wzip8p_64_constant( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: ret i64 -105873736745117663 +// +uint64_t test_wzip8p_64_constant(void) { + return __riscv_wzip8p_64(0x87654321, 0xfedcba98); +} + +// CHECK-LABEL: define dso_local i64 @test_wzip16p_64_constant( +// CHECK-SAME: ) #[[ATTR0]] { +// CHECK-NEXT: [[ENTRY:.*:]] +// CHECK-NEXT: ret i64 -82041822207524063 +// +uint64_t test_wzip16p_64_constant(void) { + return __riscv_wzip16p_64(0x87654321, 0xfedcba98); +} + /* Scalar Saturating Addition and Subtraction */ // RV32-LABEL: define dso_local i32 @test_sadd_i32( diff --git a/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c b/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c index d1c002629d006f..24b640756a5f9b 100644 --- a/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c +++ b/cross-project-tests/intrinsic-header-tests/riscv_packed_simd.c @@ -24,6 +24,20 @@ unsigned test_cls_32(int32_t a) { return __riscv_cls_32(a); } // RV64-NEXT: srai uint32_t test_rev_32(uint32_t a) { return __riscv_rev_32(a); } +// CHECK-LABEL: test_wzip8p_64: +// RV32: wzip8p{{[[:space:]]}} +// RV64: zip8p{{[[:space:]]}} +uint64_t test_wzip8p_64(uint32_t rs1, uint32_t rs2) { + return __riscv_wzip8p_64(rs1, rs2); +} + +// CHECK-LABEL: test_wzip16p_64: +// RV32: wzip16p{{[[:space:]]}} +// RV64: zip16p{{[[:space:]]}} +uint64_t test_wzip16p_64(uint32_t rs1, uint32_t rs2) { + return __riscv_wzip16p_64(rs1, rs2); +} + // CHECK-LABEL: test_slx_32: // RV32: slx{{[[:space:]]}} // RV64: andi _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
