Bignums and .sleb128

Paul Schlie schlie@comcast.net
Tue Feb 1 01:09:00 GMT 2005


So to be clearer:

 -1 == -0x1 == -0xF...

So: assuming signed char:8, short:16, int:32, etc.

 -1 == (signed char)+0xFF == (short)+0xFFFF == (int)+0xFFFFFFFF
 -1 == (signed char)-0xFF == (short)-0xFFFF == (int)-0xFFFFFFFF

and correspondingly:

   1 == (unsigned char)+0x1        == (unsigned short)+0x1, etc.
 255 == (unsigned char)-0x1, 65536 == (unsigned short)-0x1, etc.

As:

 +0xF == [0...]1111 == 15 (as non-explicitly negative constant is unsigned)
 -0xF == [1...]1111 == -1 (as  an explicitly negative constant is signed)


> From: Paul Schlie <schlie@comcast.net>
>> Daniel Jacobowitz <drow@false.org> writes:
>>>> You said later that:
>>>> 
>>>>> If we're going to use these semantics, at least the '-' case in
>>>>> operand() needs to be fixed.
>>>> 
>>>> but I wasn't sure what you meant by "these semantics".  Do you mean
>>>> treating bignums as signed, or treating them as unsigned?  By my reading,
>>>> operand()'s current handling of '-' already assumes they are signed,
>>>> just like the sleb128 code does (and did ;).
>>> It doesn't work, because sometimes bignums are signed and sometimes
>>> they aren't.  Consider -0xffffffffffff; the current code will return 1.
>>> If you want to treat the input as unsigned, then you need to add a new
>>> word with the sign bit.  Note that with one less leading 'f', it
>>> suddenly works.
> 
> Strongly suspect that the proper idiom to is to treat all non-explicitly
> negative constants as being unsigned values; where the point of confusion
> is that with the exception of decimal numbers; binary, octal, and hex
> digits directly correspond to N-bit patters which were likely specified
> as such with the implicit intent they be preserved, the only remaining
> ambiguity is whether the most-significant specified set-bit is intended
> to be sign-extended if the value is stored with greater precision than
> than the otherwise required as determined by the most-significant non-0
> bit position i.e.:
> 
>   -0x1 == [1...]1, where [1...] represents the variable precision
>   sign-extension of the most significant bit explicitly specified, which
>   would otherwise only require a signed-bit-field:1, but would need to
>   be sign extended to fill the remaining most-significant bits if stored
>   with greater precision as may be required.
> 
> Thereby all constant values may be treated uniformly:
> 
>   +1 == +0b01 == +0x1 ...
> 
>   -1 == -0b01 == -0x1 ...
> 
>   +2 == +0b10 == +0x2 ...
> 
>   -2 == -0b10 == -0x2 ...
> 
> 
> Which seems quite sensible.
> 
>   




More information about the Binutils mailing list