This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Bignums and .sleb128
On Mon, Jan 31, 2005 at 09:32:46PM +0000, Richard Sandiford wrote:
> Daniel Jacobowitz <drow@false.org> writes:
> > I spent most of this morning chasing a bug in .sleb128 support. After
> > I finished running around in circles and discovered that Richard Sandiford
> > had fixed it two weeks ago (thanks!) I compared the testcases I'd written
> > with the ones that he committed. There were a couple of differences,
> > basically related to this comment from bignum.h:
> >
> > * Bignums are >= 0. *
>
> Ugh, didn't notice that, sorry. But I think that comment fell by the
> wayside the moment we tried to handle '-' for O_bigs. After all, the
> precision of bignums is completely arbitrary, so if the result of
> -bignum is supposed to be unsigned, there's no obvious cut-off
> point for the sign extension.
Yes. I tried disabling that entirely, but it breaks the .quad and sleb
tests.
> 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. So right now 2**64-1 is a negative bignum, and 2**48-1
is a negative bignum, and 2**56-1 is a positive bignum.
> > So generating a sleb128 from one is pretty strange - the sign bit is
> > ambiguously handled.
>
> Perhaps, but the problem isn't limited to sleb128. E.g.:
>
> .quad -0xffffffffffff
>
> acts in the same way as ".quad 1", not ".quad 0xffff000000000001".
>
> The direction of recent changes suggests there really is a need
> for negative bignums, so IMO we should try to support them.
I don't much care. I was working on basically the same testcase you
were; GCC with long long HOST_WIDE_INT will output enumerators as
.sleb128 0xffffffff. I just encountered all the other bogus bits when
I tried to write tests for .sleb128.
One approach to fix the problem would be to define X_unsigned as a
secondary "sign bit" for the bignum. The core changes for that would
be easy. It's the backends that bother me.
--
Daniel Jacobowitz