Skip to content

Commit 19a8c57

Browse files
feat: Use APInt built-in methods
1 parent 31d0b09 commit 19a8c57

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4584,19 +4584,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
45844584
case X86::BI__builtin_ia32_kunpcksi:
45854585
return interp__builtin_elementwise_int_binop(
45864586
S, OpPC, Call, [](const APSInt &A, const APSInt &B) {
4587-
// Generic kunpack: extract
4588-
// lower half of each operand
4589-
// and concatenate Result =
4590-
// (A[HalfWidth-1:0] <<
4591-
// HalfWidth) |
4592-
// B[HalfWidth-1:0]
4593-
unsigned HalfWidth = A.getBitWidth() / 2;
4594-
APSInt Result(A.getLoBits(HalfWidth).zext(A.getBitWidth()),
4595-
A.isUnsigned());
4596-
Result <<= HalfWidth;
4597-
Result |= APSInt(B.getLoBits(HalfWidth).zext(B.getBitWidth()),
4598-
B.isUnsigned());
4599-
return Result;
4587+
// Generic kunpack: extract lower half of each operand and concatenate
4588+
// Result = A[HalfWidth-1:0] concat B[HalfWidth-1:0]
4589+
unsigned BW = A.getBitWidth();
4590+
return APSInt(A.trunc(BW / 2).concat(B.trunc(BW / 2)), A.isUnsigned());
46004591
});
46014592

46024593
case X86::BI__builtin_ia32_phminposuw128:

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16296,12 +16296,9 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1629616296
return false;
1629716297

1629816298
// Generic kunpack: extract lower half of each operand and concatenate
16299-
// Result = (A[HalfWidth-1:0] << HalfWidth) | B[HalfWidth-1:0]
16300-
unsigned HalfWidth = A.getBitWidth() / 2;
16301-
APSInt Result(A.getLoBits(HalfWidth).zext(A.getBitWidth()), A.isUnsigned());
16302-
Result <<= HalfWidth;
16303-
Result |=
16304-
APSInt(B.getLoBits(HalfWidth).zext(B.getBitWidth()), B.isUnsigned());
16299+
// Result = A[HalfWidth-1:0] concat B[HalfWidth-1:0]
16300+
unsigned BW = A.getBitWidth();
16301+
APSInt Result(A.trunc(BW / 2).concat(B.trunc(BW / 2)), A.isUnsigned());
1630516302
return Success(Result, E);
1630616303
}
1630716304

0 commit comments

Comments
 (0)