Skip to content

Commit 62a18f9

Browse files
committed
format
1 parent 7ab45f8 commit 62a18f9

File tree

2 files changed

+63
-45
lines changed

2 files changed

+63
-45
lines changed

clang/lib/CodeGen/TargetBuiltins/X86.cpp

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,64 +75,74 @@ static Value *getMaskVecValue(CodeGenFunction &CGF, Value *Mask,
7575
return MaskVec;
7676
}
7777

78-
static Value *emitX86Round(CodeGenFunction &CGF,
79-
Value *X,
80-
unsigned M) {
78+
static Value *emitX86Round(CodeGenFunction &CGF, Value *X, unsigned M) {
8179
unsigned RoundingMask = 0b11;
8280
unsigned UpdatePEBit = 0b100;
8381
unsigned UseMXCSRBit = 0b1000;
84-
82+
8583
unsigned roundingMode = M & RoundingMask;
8684
bool updatePE = M & UpdatePEBit;
8785
bool useMXCSR = M & UseMXCSRBit;
88-
86+
8987
Intrinsic::ID ID = Intrinsic::not_intrinsic;
9088
LLVMContext &Ctx = CGF.CGM.getLLVMContext();
91-
89+
9290
if (useMXCSR) {
9391
ID = Intrinsic::experimental_constrained_nearbyint;
94-
92+
9593
auto PE_metatadata = updatePE ? "fpexcept.strict" : "fpexcept.ignore";
9694

97-
Value *ExceptMode = MetadataAsValue::get(
98-
Ctx,
99-
MDString::get(Ctx, PE_metatadata)
100-
);
95+
Value *ExceptMode =
96+
MetadataAsValue::get(Ctx, MDString::get(Ctx, PE_metatadata));
10197

102-
Value *RoundingMode = MetadataAsValue::get(
103-
Ctx,
104-
MDString::get(Ctx, "rounding.dynamic")
105-
);
98+
Value *RoundingMode =
99+
MetadataAsValue::get(Ctx, MDString::get(Ctx, "rounding.dynamic"));
106100

107101
Function *F = CGF.CGM.getIntrinsic(ID, X->getType());
108102
return CGF.Builder.CreateCall(F, {X, ExceptMode, RoundingMode});
109-
}
103+
}
110104

111105
if (updatePE) {
112106
switch (roundingMode) {
113-
case 0b00: ID = Intrinsic::experimental_constrained_roundeven; break;
114-
case 0b01: ID = Intrinsic::experimental_constrained_floor; break;
115-
case 0b10: ID = Intrinsic::experimental_constrained_ceil; break;
116-
case 0b11: ID = Intrinsic::experimental_constrained_trunc; break;
117-
default: llvm_unreachable("Invalid rounding mode");
107+
case 0b00:
108+
ID = Intrinsic::experimental_constrained_roundeven;
109+
break;
110+
case 0b01:
111+
ID = Intrinsic::experimental_constrained_floor;
112+
break;
113+
case 0b10:
114+
ID = Intrinsic::experimental_constrained_ceil;
115+
break;
116+
case 0b11:
117+
ID = Intrinsic::experimental_constrained_trunc;
118+
break;
119+
default:
120+
llvm_unreachable("Invalid rounding mode");
118121
}
119122

120-
Value *ExceptMode =MetadataAsValue::get(
121-
Ctx,
122-
MDString::get(Ctx, "fpexcept.strict")
123-
);
123+
Value *ExceptMode =
124+
MetadataAsValue::get(Ctx, MDString::get(Ctx, "fpexcept.strict"));
124125

125126
Function *F = CGF.CGM.getIntrinsic(ID, X->getType());
126127
return CGF.Builder.CreateCall(F, {X, ExceptMode});
127128
}
128129

129130
// Otherwise we can use the standard ops
130131
switch (roundingMode) {
131-
case 0b00: ID = Intrinsic::roundeven; break;
132-
case 0b01: ID = Intrinsic::floor; break;
133-
case 0b10: ID = Intrinsic::ceil; break;
134-
case 0b11: ID = Intrinsic::trunc; break;
135-
default: llvm_unreachable("Invalid rounding mode");
132+
case 0b00:
133+
ID = Intrinsic::roundeven;
134+
break;
135+
case 0b01:
136+
ID = Intrinsic::floor;
137+
break;
138+
case 0b10:
139+
ID = Intrinsic::ceil;
140+
break;
141+
case 0b11:
142+
ID = Intrinsic::trunc;
143+
break;
144+
default:
145+
llvm_unreachable("Invalid rounding mode");
136146
}
137147

138148
Function *F = CGF.CGM.getIntrinsic(ID, X->getType());
@@ -907,18 +917,18 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
907917
case X86::BI__builtin_ia32_roundps:
908918
case X86::BI__builtin_ia32_roundpd:
909919
case X86::BI__builtin_ia32_roundps256:
910-
case X86::BI__builtin_ia32_roundpd256: {
920+
case X86::BI__builtin_ia32_roundpd256: {
911921
unsigned M = cast<ConstantInt>(Ops[1])->getZExtValue();
912922
return emitX86Round(*this, Ops[0], M);
913923
}
914924
case X86::BI__builtin_ia32_roundss:
915925
case X86::BI__builtin_ia32_roundsd: {
916926
unsigned M = cast<ConstantInt>(Ops[2])->getZExtValue();
917-
927+
918928
Value *idx = Builder.getInt32(0);
919929
Value *ValAt0 = Builder.CreateExtractElement(Ops[1], idx);
920930
Value *RoundedAt0 = emitX86Round(*this, ValAt0, M);
921-
931+
922932
return Builder.CreateInsertElement(Ops[0], RoundedAt0, idx);
923933
}
924934
case X86::BI__builtin_ia32_lzcnt_u16:

llvm/include/llvm/IR/IntrinsicsX86.td

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,20 @@ let TargetPrefix = "x86" in { // All intrinsics start with "llvm.x86.".
626626

627627
// FP rounding ops
628628
let TargetPrefix = "x86" in { // All intrinsics start with "llvm.x86.".
629-
def int_x86_sse41_round_ss : DefaultAttrsIntrinsic<[llvm_v4f32_ty], [llvm_v4f32_ty, llvm_v4f32_ty,
630-
llvm_i32_ty], [IntrNoMem, ImmArg<ArgIndex<2>>]>;
631-
def int_x86_sse41_round_ps : DefaultAttrsIntrinsic<[llvm_v4f32_ty], [llvm_v4f32_ty,
632-
llvm_i32_ty], [IntrNoMem, ImmArg<ArgIndex<1>>]>;
633-
def int_x86_sse41_round_sd : DefaultAttrsIntrinsic<[llvm_v2f64_ty], [llvm_v2f64_ty, llvm_v2f64_ty,
634-
llvm_i32_ty], [IntrNoMem, ImmArg<ArgIndex<2>>]>;
635-
def int_x86_sse41_round_pd : DefaultAttrsIntrinsic<[llvm_v2f64_ty], [llvm_v2f64_ty,
636-
llvm_i32_ty], [IntrNoMem, ImmArg<ArgIndex<1>>]>;
629+
def int_x86_sse41_round_ss
630+
: DefaultAttrsIntrinsic<[llvm_v4f32_ty],
631+
[llvm_v4f32_ty, llvm_v4f32_ty, llvm_i32_ty],
632+
[IntrNoMem, ImmArg<ArgIndex<2>>]>;
633+
def int_x86_sse41_round_ps
634+
: DefaultAttrsIntrinsic<[llvm_v4f32_ty], [llvm_v4f32_ty, llvm_i32_ty],
635+
[IntrNoMem, ImmArg<ArgIndex<1>>]>;
636+
def int_x86_sse41_round_sd
637+
: DefaultAttrsIntrinsic<[llvm_v2f64_ty],
638+
[llvm_v2f64_ty, llvm_v2f64_ty, llvm_i32_ty],
639+
[IntrNoMem, ImmArg<ArgIndex<2>>]>;
640+
def int_x86_sse41_round_pd
641+
: DefaultAttrsIntrinsic<[llvm_v2f64_ty], [llvm_v2f64_ty, llvm_i32_ty],
642+
[IntrNoMem, ImmArg<ArgIndex<1>>]>;
637643
}
638644

639645
// Vector min element
@@ -917,10 +923,12 @@ let TargetPrefix = "x86" in { // All intrinsics start with "llvm.x86.".
917923
def int_x86_avx_rcp_ps_256 : ClangBuiltin<"__builtin_ia32_rcpps256">,
918924
DefaultAttrsIntrinsic<[llvm_v8f32_ty], [llvm_v8f32_ty], [IntrNoMem]>;
919925

920-
def int_x86_avx_round_pd_256 : DefaultAttrsIntrinsic<[llvm_v4f64_ty], [llvm_v4f64_ty, llvm_i32_ty],
921-
[IntrNoMem, ImmArg<ArgIndex<1>>]>;
922-
def int_x86_avx_round_ps_256 : DefaultAttrsIntrinsic<[llvm_v8f32_ty], [llvm_v8f32_ty, llvm_i32_ty],
923-
[IntrNoMem, ImmArg<ArgIndex<1>>]>;
926+
def int_x86_avx_round_pd_256
927+
: DefaultAttrsIntrinsic<[llvm_v4f64_ty], [llvm_v4f64_ty, llvm_i32_ty],
928+
[IntrNoMem, ImmArg<ArgIndex<1>>]>;
929+
def int_x86_avx_round_ps_256
930+
: DefaultAttrsIntrinsic<[llvm_v8f32_ty], [llvm_v8f32_ty, llvm_i32_ty],
931+
[IntrNoMem, ImmArg<ArgIndex<1>>]>;
924932
}
925933

926934
// Horizontal ops

0 commit comments

Comments
 (0)