Shifting to the right of a signed value when the MSB is one is technically
undefined behavior, even though in my experience it's done the "right thing"
and sign extended the value. This replaces the arithmetic right shift code in
ARM that uses that coincidence with some code that relies on bit math.
return base >> shamt;
case ASR:
if (shamt == 0)
- return (int32_t)base >> 31;
+ return (base >> 31) | -((base & (1 << 31)) >> 31);
else
- return (int32_t)base >> shamt;
+ return (base >> shamt) | -((base & (1 << 31)) >> shamt);
case ROR:
if (shamt == 0)
return (cfval << 31) | (base >> 1); // RRX
return base >> shamt;
case ASR:
if (shamt >= 32)
- return (int32_t)base >> 31;
+ return (base >> 31) | -((base & (1 << 31)) >> 31);
else
- return (int32_t)base >> shamt;
+ return (base >> shamt) | -((base & (1 << 31)) >> shamt);
case ROR:
shamt = shamt & 0x1f;
if (shamt == 0)