Skip to content

Commit

Permalink
Merge branch 'backengineering:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
killvxk authored Jan 9, 2025
2 parents e223cff + 34b54ee commit fd88427
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions clang/include/clang/Basic/BuiltinsX86_64.def
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ TARGET_HEADER_BUILTIN(__mulh, "LLiLLiLLi", "nch", INTRIN_H, ALL_MS_LANGUAGES
TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nch", INTRIN_H, ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_mul128, "LLiLLiLLiLLi*", "nch", INTRIN_H, ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_umul128, "ULLiULLiULLiULLi*", "nch", INTRIN_H, ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(_udiv128, "ULLiULLiULLiULLiULLi*", "nch", INTRIN_H, ALL_MS_LANGUAGES, "")

TARGET_HEADER_BUILTIN(__faststorefence, "v", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
TARGET_HEADER_BUILTIN(__shiftleft128, "ULLiULLiULLiUc", "nch", INTRIN_H, ALL_MS_LANGUAGES, "")
Expand Down
31 changes: 31 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16024,6 +16024,37 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
return Builder.CreateIntCast(MulResult, ResType, IsSigned);
}

case X86::BI_udiv128: {
llvm::Type *ResType = ConvertType(E->getType());
llvm::Type *Int128Ty = llvm::IntegerType::get(getLLVMContext(), 128);
llvm::Type *Int64Ty = llvm::IntegerType::get(getLLVMContext(), 64);

// Retrieve operands
Value *HighDividend = Builder.CreateIntCast(Ops[0], Int128Ty, false);
Value *LowDividend = Builder.CreateZExt(Ops[1], Int128Ty);
Value *Divisor = Ops[2];

// Combine HighDividend and LowDividend into a 128-bit dividend
Value *Dividend = Builder.CreateShl(HighDividend, 64);
Dividend = Builder.CreateOr(Dividend, LowDividend);

// Create Divisor and extend it to 128-bit
Value *DivisorExt = Builder.CreateZExt(Divisor, Int128Ty);

// Perform division
Value *Quotient = Builder.CreateUDiv(Dividend, DivisorExt);
Value *Remainder = Builder.CreateURem(Dividend, DivisorExt);

// Truncate results to 64 bits
Quotient = Builder.CreateTrunc(Quotient, Int64Ty);
Remainder = Builder.CreateTrunc(Remainder, Int64Ty);

// Store remainder
Address RemainderAddr = EmitPointerWithAlignment(E->getArg(3));
Builder.CreateStore(Remainder, RemainderAddr);

return Quotient; // Return the quotient as the result
}
case X86::BI__faststorefence: {
return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
llvm::SyncScope::System);
Expand Down
2 changes: 1 addition & 1 deletion llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(NOT DEFINED LLVM_VERSION_MINOR)
set(LLVM_VERSION_MINOR 2)
endif()
if(NOT DEFINED LLVM_VERSION_PATCH)
set(LLVM_VERSION_PATCH 1)
set(LLVM_VERSION_PATCH 2)
endif()
if(NOT DEFINED LLVM_VERSION_SUFFIX)
set(LLVM_VERSION_SUFFIX newworld)
Expand Down

0 comments on commit fd88427

Please sign in to comment.