mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-10 02:36:06 +00:00
Implement bit-accurate sext instruction.
This patch fixes test/Integer/2007-01-17-TruncSext.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33394 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6df4c4576f
commit
c00a43092e
@ -1347,21 +1347,25 @@ GenericValue Interpreter::executeSExtInst(Value *SrcVal, const Type *DstTy,
|
|||||||
assert(SBitWidth <= 64 && DBitWidth <= 64 &&
|
assert(SBitWidth <= 64 && DBitWidth <= 64 &&
|
||||||
"Integer types > 64 bits not supported");
|
"Integer types > 64 bits not supported");
|
||||||
assert(SBitWidth < DBitWidth && "Invalid sign extend");
|
assert(SBitWidth < DBitWidth && "Invalid sign extend");
|
||||||
int64_t Extended = 0;
|
|
||||||
if (SBitWidth == 1)
|
// Normalize to a 64-bit value.
|
||||||
// For sign extension from bool, we must extend the source bits.
|
uint64_t Normalized = 0;
|
||||||
Extended = 0 - (Src.Int1Val & 1);
|
if (SBitWidth <= 8)
|
||||||
else if (SBitWidth <= 8)
|
Normalized = Src.Int8Val;
|
||||||
Extended = (int64_t) (int8_t)Src.Int8Val;
|
|
||||||
else if (SBitWidth <= 16)
|
else if (SBitWidth <= 16)
|
||||||
Extended = (int64_t) (int16_t)Src.Int16Val;
|
Normalized = Src.Int16Val;
|
||||||
else if (SBitWidth <= 32)
|
else if (SBitWidth <= 32)
|
||||||
Extended = (int64_t) (int32_t)Src.Int32Val;
|
Normalized = Src.Int32Val;
|
||||||
else
|
else
|
||||||
Extended = (int64_t) Src.Int64Val;
|
Normalized = Src.Int64Val;
|
||||||
|
|
||||||
|
// Now do the bit-accurate sign extension manually.
|
||||||
|
bool isSigned = (Normalized & (1 << (SBitWidth-1))) != 0;
|
||||||
|
if (isSigned)
|
||||||
|
Normalized |= ~SITy->getBitMask();
|
||||||
|
|
||||||
// Now that we have a sign extended value, assign it to the destination
|
// Now that we have a sign extended value, assign it to the destination
|
||||||
INTEGER_ASSIGN(Dest, DBitWidth, Extended);
|
INTEGER_ASSIGN(Dest, DBitWidth, Normalized);
|
||||||
return Dest;
|
return Dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user