[llvm-commits] [llvm] r100233 - in /llvm/trunk: ./ include/llvm/Support/ lib/Target/ARM/ lib/Target/ARM/Disassembler/ test/MC/Disassembler/ utils/TableGen/

Johnny Chen johnny.chen at apple.com
Sun Apr 4 18:48:09 PDT 2010


Hi Jakob,

Thanks.  You're welcome to modify the MathExtras.h stuff.
Right now, arm disassembler is the only client of SignExtend32<B>(int32_t x).
I originally use a bit-field hack but Chris thinks it is non-portable.

On Apr 4, 2010, at 6:31 PM, Jakob Stoklund Olesen wrote:

> 
> On Apr 2, 2010, at 3:27 PM, Johnny Chen wrote:
> 
>> Modified: llvm/trunk/include/llvm/Support/MathExtras.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MathExtras.h?rev=100233&r1=100232&r2=100233&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Support/MathExtras.h (original)
>> +++ llvm/trunk/include/llvm/Support/MathExtras.h Fri Apr  2 17:27:38 2010
>> @@ -457,6 +457,18 @@
>>  return (x < 0) ? -x : x;
>> }
>> 
>> +/// SignExtend32 - Sign extend B-bit number x to 32-bit int.
>> +/// Usage int32_t r = SignExtend32<5>(x);
>> +template <unsigned B> inline int32_t SignExtend32(int32_t x) {
>> +  return (x << (32 - B)) >> (32 - B);
>> +}
>> +
>> +/// SignExtend64 - Sign extend B-bit number x to 64-bit int.
>> +/// Usage int64_t r = SignExtend64<5>(x);
>> +template <unsigned B> inline int64_t SignExtend64(int32_t x) {
> 
> Should be (int64_t x).
> 
>> +  return (x << (64 - B)) >> (64 - B);
>> +}
>> +
> 
> I wonder if this is safe? These functions depend on signed overflow which is undefined behavior.
> 





More information about the llvm-commits mailing list