================
@@ -75,6 +75,80 @@ static Value *getMaskVecValue(CodeGenFunction &CGF, Value
*Mask,
return MaskVec;
}
+static Value *emitX86Round(CodeGenFunction &CGF, Value *X, unsigned M) {
+ unsigned RoundingMask = 0b11;
+ unsigned UpdatePEBit = 0b100;
+ unsigned UseMXCSRBit = 0b1000;
+
+ unsigned roundingMode = M & RoundingMask;
+ bool updatePE = M & UpdatePEBit;
+ bool useMXCSR = M & UseMXCSRBit;
+
+ Intrinsic::ID ID = Intrinsic::not_intrinsic;
+ LLVMContext &Ctx = CGF.CGM.getLLVMContext();
+
+ if (useMXCSR) {
+ ID = Intrinsic::experimental_constrained_nearbyint;
+
+ auto PE_metatadata = updatePE ? "fpexcept.strict" : "fpexcept.ignore";
+
+ Value *ExceptMode =
+ MetadataAsValue::get(Ctx, MDString::get(Ctx, PE_metatadata));
+
+ Value *RoundingMode =
+ MetadataAsValue::get(Ctx, MDString::get(Ctx, "rounding.dynamic"));
+
+ Function *F = CGF.CGM.getIntrinsic(ID, X->getType());
+ return CGF.Builder.CreateCall(F, {X, ExceptMode, RoundingMode});
+ }
+
+ if (updatePE) {
+ switch (roundingMode) {
+ case 0b00:
+ ID = Intrinsic::experimental_constrained_roundeven;
+ break;
+ case 0b01:
+ ID = Intrinsic::experimental_constrained_floor;
+ break;
+ case 0b10:
+ ID = Intrinsic::experimental_constrained_ceil;
+ break;
+ case 0b11:
+ ID = Intrinsic::experimental_constrained_trunc;
+ break;
+ default:
+ llvm_unreachable("Invalid rounding mode");
+ }
+
+ Value *ExceptMode =
+ MetadataAsValue::get(Ctx, MDString::get(Ctx, "fpexcept.strict"));
+
+ Function *F = CGF.CGM.getIntrinsic(ID, X->getType());
+ return CGF.Builder.CreateCall(F, {X, ExceptMode});
+ }
+
+ // Otherwise we can use the standard ops
----------------
tbaederr wrote:
```suggestion
// Otherwise we can use the standard ops.
```
https://github.com/llvm/llvm-project/pull/171227
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits