public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Bignums and .sleb128
@ 2005-01-31 19:54 Daniel Jacobowitz
  2005-01-31 21:33 ` Richard Sandiford
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2005-01-31 19:54 UTC (permalink / raw)
  To: binutils

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.                                               *

So generating a sleb128 from one is pretty strange - the sign bit is
ambiguously handled.  To see what I mean, try the attached patch to the
testsuite; several of the new tests fail.  Richard's patch adds this:

  /* Add a sequence of sign bits if the top bit of X_add_number is not
     the sign of the original value.  */
  if ((exp->X_add_number < 0) != !exp->X_unsigned)
    generic_bignum[i++] = exp->X_unsigned ? 0 : LITTLENUM_MASK;

which is pretty similar to what I did, but violates the documentation and (I
think) the expectations of various other bits of gas.  If we're going to use
these semantics, at least the '-' case in operand() needs to be fixed.

I consider the current state "still very broken".  Should we try to fix this
(I can't even see where to start; O_big has percolated into lots of strange
places, so changing its semantics would be tricky)?  Otherwise, can we
reject the internally ambiguous constructs?

The tests:

Index: testsuite/gas/all/sleb128.d
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gas/testsuite/gas/all/sleb128.d,v
retrieving revision 1.2
diff -u -p -r1.2 sleb128.d
--- testsuite/gas/all/sleb128.d	24 Jan 2005 15:32:19 -0000	1.2
+++ testsuite/gas/all/sleb128.d	31 Jan 2005 19:21:44 -0000
@@ -52,6 +52,29 @@ Contents of section .data:
 # -0x100000000 :           111_0000 .....................................
 #    000000000 :           000_0000 0000_000 0_0000_00 00_0000_0 000_0000
 # -0x1000      :                             1_0000_00 00_0000_0
+#   fffffffff  :           111_1111 1111_111 1_1111_11 11_1111_1 111_1111 
+# 0xfffffff    : .................. 1111_111 1_1111_11 11_1111_1
 #
- 00.. 70808080 80808040 00000000 00000000 .*
+ 00.. 70808080 80808040 ffffffff ffffffff .*
+#
+# 0xfffffff    : 00_0000_1 111_1111 ............................
+#   fffffffff  :           111_1111 1111_111 1_1111_11 11_1111_1 111_1111 
+#   fffffffff  : 11_1111_1 111_1111 1111_111 1_1111_11 11_1111_1
+# 0xffffff     : 00_1111_1 111_1111 1111_111 1_1111_11
+#
+ 0... ff01ffff ffffffff ffffffff ffffff1f
+#
+#   fffffffff  :           000_0000 0000_000 0_0000_00 00_0000_0 000_0001
+# -0xfffffff   : 111_000_0 000_0000 0000_000 0_0000_00 00_0000_0
+#   fffffffff  :           000_0000 0000_000 0_0000_00 00_0000_0 000_0001
+#   fffffffff  : ..................................... 00_0000_0
+# -0xffffff    : .....................................
+#
+ 0... 81808080 80808080 80f08180 80808080 .*
+#
+#   fffffffff  :           ..............................................
+#   fffffffff  : 00_0000_0 000_0000 0000_000 0_0000_00 .........
+# -0xffffff    : 11_0000_0 000_0000 0000_000 0_0000_00
+#
+ 0... 80808080 80808060 00000000 00000000 .*
 #pass
Index: testsuite/gas/all/sleb128.s
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gas/testsuite/gas/all/sleb128.s,v
retrieving revision 1.1
diff -u -p -r1.1 sleb128.s
--- testsuite/gas/all/sleb128.s	19 Jan 2005 11:53:53 -0000	1.1
+++ testsuite/gas/all/sleb128.s	31 Jan 2005 18:51:59 -0000
@@ -19,4 +19,9 @@
 	.sleb128	-0x100000000
 	.sleb128	-0x1000000000000
 
+	.sleb128	0xffffffffffffffff
+	.sleb128	0xffffffffffffffffffffffff
+	.sleb128	-0xffffffffffffffff
+	.sleb128	-0xffffffffffffffffffffffff
+
 	.fill		32


-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: Bignums and .sleb128
@ 2005-02-01  0:53 Paul Schlie
  2005-02-01  1:09 ` Paul Schlie
  2005-02-01  3:29 ` Daniel Jacobowitz
  0 siblings, 2 replies; 9+ messages in thread
From: Paul Schlie @ 2005-02-01  0:53 UTC (permalink / raw)
  To: Daniel Jacobowitz, Richard Sandiford; +Cc: binutils

> 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.

  


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-02-01  5:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-31 19:54 Bignums and .sleb128 Daniel Jacobowitz
2005-01-31 21:33 ` Richard Sandiford
2005-01-31 21:57   ` Daniel Jacobowitz
2005-01-31 22:18     ` Richard Sandiford
2005-01-31 22:22       ` Daniel Jacobowitz
2005-02-01  0:53 Paul Schlie
2005-02-01  1:09 ` Paul Schlie
2005-02-01  5:04   ` Paul Schlie
2005-02-01  3:29 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).