Skip to content

Commit

Permalink
[RISCV] Split __builtin_riscv_xperm4/8 into separate _32 and _64 buil…
Browse files Browse the repository at this point in the history
…tins.

Part of an effort to remove uses of 'long' to mean XLen from the builtin
interfaces.

Also makes the builtin names match riscv-non-isa/riscv-c-api-doc#44.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D154681
  • Loading branch information
topperc authored and veselypeta committed Sep 4, 2024
2 parents 51ea93e + a1b7db3 commit c0fe373
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions clang/include/clang/Basic/BuiltinsRISCV.def
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ TARGET_BUILTIN(__builtin_riscv_clmulh, "LiLiLi", "nc", "zbc|zbkc")
TARGET_BUILTIN(__builtin_riscv_clmulr, "LiLiLi", "nc", "zbc")

// Zbkx
TARGET_BUILTIN(__builtin_riscv_xperm4, "LiLiLi", "nc", "zbkx")
TARGET_BUILTIN(__builtin_riscv_xperm8, "LiLiLi", "nc", "zbkx")
TARGET_BUILTIN(__builtin_riscv_xperm4_32, "iii", "nc", "zbkx,32bit")
TARGET_BUILTIN(__builtin_riscv_xperm4_64, "WiWiWi", "nc", "zbkx,64bit")
TARGET_BUILTIN(__builtin_riscv_xperm8_32, "iii", "nc", "zbkx,32bit")
TARGET_BUILTIN(__builtin_riscv_xperm8_64, "WiWiWi", "nc", "zbkx,64bit")

// Zbkb extension
TARGET_BUILTIN(__builtin_riscv_brev8, "LiLi", "nc", "zbkb")
Expand Down
12 changes: 8 additions & 4 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20584,8 +20584,10 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
case RISCV::BI__builtin_riscv_clmul:
case RISCV::BI__builtin_riscv_clmulh:
case RISCV::BI__builtin_riscv_clmulr:
case RISCV::BI__builtin_riscv_xperm4:
case RISCV::BI__builtin_riscv_xperm8:
case RISCV::BI__builtin_riscv_xperm4_32:
case RISCV::BI__builtin_riscv_xperm4_64:
case RISCV::BI__builtin_riscv_xperm8_32:
case RISCV::BI__builtin_riscv_xperm8_64:
case RISCV::BI__builtin_riscv_brev8:
case RISCV::BI__builtin_riscv_zip_32:
case RISCV::BI__builtin_riscv_unzip_32: {
Expand Down Expand Up @@ -20627,10 +20629,12 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
break;

// Zbkx
case RISCV::BI__builtin_riscv_xperm8:
case RISCV::BI__builtin_riscv_xperm8_32:
case RISCV::BI__builtin_riscv_xperm8_64:
ID = Intrinsic::riscv_xperm8;
break;
case RISCV::BI__builtin_riscv_xperm4:
case RISCV::BI__builtin_riscv_xperm4_32:
case RISCV::BI__builtin_riscv_xperm4_64:
ID = Intrinsic::riscv_xperm4;
break;

Expand Down
8 changes: 4 additions & 4 deletions clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// RV32ZBKX-NEXT: [[TMP2:%.*]] = call i32 @llvm.riscv.xperm8.i32(i32 [[TMP0]], i32 [[TMP1]])
// RV32ZBKX-NEXT: ret i32 [[TMP2]]
//
long xperm8(long rs1, long rs2)
int xperm8(int rs1, int rs2)
{
return __builtin_riscv_xperm8(rs1, rs2);
return __builtin_riscv_xperm8_32(rs1, rs2);
}

// RV32ZBKX-LABEL: @xperm4(
Expand All @@ -29,7 +29,7 @@ long xperm8(long rs1, long rs2)
// RV32ZBKX-NEXT: [[TMP2:%.*]] = call i32 @llvm.riscv.xperm4.i32(i32 [[TMP0]], i32 [[TMP1]])
// RV32ZBKX-NEXT: ret i32 [[TMP2]]
//
long xperm4(long rs1, long rs2)
int xperm4(int rs1, int rs2)
{
return __builtin_riscv_xperm4(rs1, rs2);
return __builtin_riscv_xperm4_32(rs1, rs2);
}
4 changes: 2 additions & 2 deletions clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
long xperm8(long rs1, long rs2)
{
return __builtin_riscv_xperm8(rs1, rs2);
return __builtin_riscv_xperm8_64(rs1, rs2);
}

// RV64ZBKX-LABEL: @xperm4(
Expand All @@ -31,5 +31,5 @@ long xperm8(long rs1, long rs2)
//
long xperm4(long rs1, long rs2)
{
return __builtin_riscv_xperm4(rs1, rs2);
return __builtin_riscv_xperm4_64(rs1, rs2);
}

0 comments on commit c0fe373

Please sign in to comment.