@@ -16024,6 +16024,37 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
16024
16024
return Builder.CreateIntCast(MulResult, ResType, IsSigned);
16025
16025
}
16026
16026
16027
+ case X86::BI_udiv128: {
16028
+ llvm::Type *ResType = ConvertType(E->getType());
16029
+ llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128);
16030
+ llvm::Type *Int64Ty = llvm::IntegerType::get(getLLVMContext(), 64);
16031
+
16032
+ // Retrieve operands
16033
+ Value *HighDividend = Builder.CreateIntCast(Ops[0], Int128Ty, false);
16034
+ Value *LowDividend = Builder.CreateZExt(Ops[1], Int128Ty);
16035
+ Value *Divisor = Ops[2];
16036
+
16037
+ // Combine HighDividend and LowDividend into a 128-bit dividend
16038
+ Value *Dividend = Builder.CreateShl(HighDividend, 64);
16039
+ Dividend = Builder.CreateOr(Dividend, LowDividend);
16040
+
16041
+ // Create Divisor and extend it to 128-bit
16042
+ Value *DivisorExt = Builder.CreateZExt(Divisor, Int128Ty);
16043
+
16044
+ // Perform division
16045
+ Value *Quotient = Builder.CreateUDiv(Dividend, DivisorExt);
16046
+ Value *Remainder = Builder.CreateURem(Dividend, DivisorExt);
16047
+
16048
+ // Truncate results to 64 bits
16049
+ Quotient = Builder.CreateTrunc(Quotient, Int64Ty);
16050
+ Remainder = Builder.CreateTrunc(Remainder, Int64Ty);
16051
+
16052
+ // Store remainder
16053
+ Address RemainderAddr = EmitPointerWithAlignment(E->getArg(3));
16054
+ Builder.CreateStore(Remainder, RemainderAddr);
16055
+
16056
+ return Quotient; // Return the quotient as the result
16057
+ }
16027
16058
case X86::BI__faststorefence: {
16028
16059
return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
16029
16060
llvm::SyncScope::System);
0 commit comments