Skip to content

Commit 8e287c1

Browse files
author
Aditi-Medhane
committed
[PowerPC] Add BCDCOPYSIGN and BCDSETSIGN Instruction Support
1 parent c0a9c90 commit 8e287c1

File tree

7 files changed

+89
-2
lines changed

7 files changed

+89
-2
lines changed

clang/include/clang/Basic/BuiltinsPPC.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,10 @@ TARGET_BUILTIN(__builtin_altivec_vctzh, "V8UsV8Us", "", "power9-vector")
515515
TARGET_BUILTIN(__builtin_altivec_vctzw, "V4UiV4Ui", "", "power9-vector")
516516
TARGET_BUILTIN(__builtin_altivec_vctzd, "V2ULLiV2ULLi", "", "power9-vector")
517517

518+
//P9 BCD builtins
519+
TARGET_BUILTIN(__builtin_ppc_bcdcopysign, "V16UcV16UcV16Uc", "", "power9-vector")
520+
TARGET_BUILTIN(__builtin_ppc_bcdsetsign, "V16UcV16UcUc", "t", "power9-vector")
521+
518522
// P7 BCD builtins.
519523
TARGET_BUILTIN(__builtin_cdtbcd, "UiUi", "", "isa-v206-instructions")
520524
TARGET_BUILTIN(__builtin_cbcdtd, "UiUi", "", "isa-v206-instructions")

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
8888
}
8989

9090
static void defineXLCompatMacros(MacroBuilder &Builder) {
91+
Builder.defineMacro("__builtin_bcdcopysign", "__builtin_ppc_bcdcopysign");
92+
Builder.defineMacro("__builtin_bcdsetsign", "__builtin_ppc_bcdsetsign");
9193
Builder.defineMacro("__cdtbcd", "__builtin_ppc_cdtbcd");
9294
Builder.defineMacro("__cbcdtd", "__builtin_ppc_cbcdtd");
9395
Builder.defineMacro("__addg6s", "__builtin_ppc_addg6s");

clang/lib/Sema/SemaPPC.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
106106
switch (BuiltinID) {
107107
default:
108108
return false;
109+
case PPC::BI__builtin_ppc_bcdsetsign:
110+
return SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 1);
109111
case PPC::BI__builtin_altivec_crypto_vshasigmaw:
110112
case PPC::BI__builtin_altivec_crypto_vshasigmad:
111113
return SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 1) ||
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
// REQUIRES: powerpc-registered-target
3+
// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -O2 -target-cpu pwr9 \
4+
// RUN: -emit-llvm %s -o - | FileCheck %s
5+
// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -O2 -target-cpu pwr9 \
6+
// RUN: -emit-llvm %s -o - | FileCheck %s
7+
// RUN: %clang_cc1 -triple powerpc-unknown-unknown -O2 -target-cpu pwr9 \
8+
// RUN: -emit-llvm %s -o - | FileCheck %s
9+
10+
// CHECK-LABEL: test_bcdcopysign
11+
// CHECK: [[TMP0:%.*]] = tail call <16 x i8> @llvm.ppc.bcdcopysign(<16 x i8> %a, <16 x i8> %b)
12+
// CHECK-NEXT: ret <16 x i8> [[TMP0]]
13+
vector unsigned char test_bcdcopysign(vector unsigned char a, vector unsigned char b) {
14+
return __builtin_ppc_bcdcopysign(a, b);
15+
}
16+
17+
// CHECK-LABEL: test_bcdsetsign_imm0
18+
// CHECK: [[TMP0:%.*]] = tail call <16 x i8> @llvm.ppc.bcdsetsign(<16 x i8> %a, i32 0)
19+
// CHECK-NEXT: ret <16 x i8> [[TMP0]]
20+
vector unsigned char test_bcdsetsign_imm0(vector unsigned char a) {
21+
return __builtin_ppc_bcdsetsign(a, '\0');
22+
}
23+
24+
// CHECK-LABEL: test_bcdsetsign_imm1
25+
// CHECK: [[TMP0:%.*]] = tail call <16 x i8> @llvm.ppc.bcdsetsign(<16 x i8> %a, i32 1)
26+
// CHECK-NEXT: ret <16 x i8> [[TMP0]]
27+
vector unsigned char test_bcdsetsign_imm1(vector unsigned char a) {
28+
return __builtin_ppc_bcdsetsign(a, '\1');
29+
}

llvm/include/llvm/IR/IntrinsicsPowerPC.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,14 @@ let TargetPrefix = "ppc" in { // All intrinsics start with "llvm.ppc.".
668668
def int_ppc_addg6s: ClangBuiltin<"__builtin_addg6s">,
669669
DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>;
670670

671+
// BCD Format conversion intrinsics
672+
def int_ppc_bcdcopysign : ClangBuiltin<"__builtin_ppc_bcdcopysign">,
673+
DefaultAttrsIntrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty, llvm_v16i8_ty], [IntrNoMem]>;
674+
def int_ppc_bcdsetsign : ClangBuiltin<"__builtin_ppc_bcdsetsign">,
675+
DefaultAttrsIntrinsic<[llvm_v16i8_ty], [llvm_v16i8_ty, llvm_i32_ty],
676+
[IntrNoMem, ImmArg<ArgIndex<1>>]>;
677+
678+
671679
def int_ppc_bcdadd : ClangBuiltin<"__builtin_ppc_bcdadd">,
672680
DefaultAttrsIntrinsic<
673681
[llvm_v16i8_ty], [llvm_v16i8_ty, llvm_v16i8_ty, llvm_i32_ty],

llvm/lib/Target/PowerPC/PPCInstrAltivec.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,9 +1626,11 @@ def BCDCTSQ_rec : VX_VT5_EO5_VB5_XO9_o <0, 385, "bcdctsq.", []>;
16261626

16271627
// Decimal Copy-Sign/Set-Sign
16281628
let Defs = [CR6] in
1629-
def BCDCPSGN_rec : VX1_VT5_VA5_VB5<833, "bcdcpsgn.", []>;
1629+
def BCDCPSGN_rec : VX1_VT5_VA5_VB5<833, "bcdcpsgn.",
1630+
[(set v16i8:$VD, (int_ppc_bcdcopysign v16i8:$VA, v16i8:$VB))]>;
16301631

1631-
def BCDSETSGN_rec : VX_VT5_EO5_VB5_PS1_XO9_o<31, 385, "bcdsetsgn.", []>;
1632+
def BCDSETSGN_rec : VX_VT5_EO5_VB5_PS1_XO9_o<31, 385, "bcdsetsgn.",
1633+
[(set v16i8:$VD, (int_ppc_bcdsetsign v16i8:$VB, i32:$PS))]>;
16321634

16331635
// Decimal Shift/Unsigned-Shift/Shift-and-Round
16341636
def BCDS_rec : VX_VT5_VA5_VB5_PS1_XO9_o<193, "bcds." , []>;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown -mcpu=pwr9 \
3+
; RUN: --ppc-asm-full-reg-names < %s | FileCheck %s
4+
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-unknown -mcpu=pwr9 \
5+
; RUN: --ppc-asm-full-reg-names < %s | FileCheck %s
6+
; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64-ibm-aix-xcoff \
7+
; RUN: -ppc-asm-full-reg-names < %s | FileCheck %s
8+
9+
define dso_local <16 x i8> @test_bcdcopysign(<16 x i8> noundef %a, <16 x i8> noundef %b) {
10+
; CHECK-LABEL: test_bcdcopysign:
11+
; CHECK: # %bb.0: # %entry
12+
; CHECK-NEXT: bcdcpsgn. v2, v2, v3
13+
; CHECK-NEXT: blr
14+
entry:
15+
%0 = tail call <16 x i8> @llvm.ppc.bcdcopysign(<16 x i8> %a, <16 x i8> %b)
16+
ret <16 x i8> %0
17+
}
18+
19+
define dso_local <16 x i8> @test_bcdsetsign_imm0(<16 x i8> noundef %a) {
20+
; CHECK-LABEL: test_bcdsetsign_imm0:
21+
; CHECK: # %bb.0: # %entry
22+
; CHECK-NEXT: bcdsetsgn. v2, v2, 0
23+
; CHECK-NEXT: blr
24+
entry:
25+
%0 = tail call <16 x i8> @llvm.ppc.bcdsetsign(<16 x i8> %a, i32 0)
26+
ret <16 x i8> %0
27+
}
28+
29+
define dso_local <16 x i8> @test_bcdsetsign_imm1(<16 x i8> noundef %a) {
30+
; CHECK-LABEL: test_bcdsetsign_imm1:
31+
; CHECK: # %bb.0: # %entry
32+
; CHECK-NEXT: bcdsetsgn. v2, v2, 1
33+
; CHECK-NEXT: blr
34+
entry:
35+
%0 = tail call <16 x i8> @llvm.ppc.bcdsetsign(<16 x i8> %a, i32 1)
36+
ret <16 x i8> %0
37+
}
38+
39+
declare <16 x i8> @llvm.ppc.bcdcopysign(<16 x i8>, <16 x i8>)
40+
declare <16 x i8> @llvm.ppc.bcdsetsign(<16 x i8>, i32)

0 commit comments

Comments
 (0)