9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] 6a bug
@ 2011-11-16 22:25 erik quanstrom
  2011-11-16 22:35 ` Charles Forsyth
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: erik quanstrom @ 2011-11-16 22:25 UTC (permalink / raw)
  To: 9fans

i plan to look at this when i get home, but it appears that 6a
doesn't like big numbers.  demo script follows

- erik
-------
; cat >a.s <<'EOF'
#define KZERO	(0xffffff0000000000ull)

TEXT bignumber(SB), 1, $0
	ADDQ	$KZERO, AX
	RET
EOF
; cat >ac.c<<EOF
#include <u.h>
#include <libc.h>

extern uvlong bignumber(uvlong);

void
main(void)
{
	print("%llux\n", bignumber(0));
	exits("");
}
EOF
; 6a a.s; 6c ac.c; 6l a.6 ac.6



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

* Re: [9fans] 6a bug
  2011-11-16 22:25 [9fans] 6a bug erik quanstrom
@ 2011-11-16 22:35 ` Charles Forsyth
  2011-11-16 22:36   ` Charles Forsyth
  2011-11-16 22:50 ` Russ Cox
       [not found] ` <CAOw7k5hJz=F13tUpq7mU3gSnSWr7H=y4rKCN-OUO-FOavBGygA@mail.gmail.c>
  2 siblings, 1 reply; 9+ messages in thread
From: Charles Forsyth @ 2011-11-16 22:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

AX is the wrong register. REGARG is BP. actually, it's "RARG" in 6a, in case it
changes, although that seems less likely now.

On 16 November 2011 14:25, erik quanstrom <quanstro@labs.coraid.com> wrote:
> i plan to look at this when i get home, but it appears that 6a
> doesn't like big numbers.  demo script follows
>
> - erik
> -------
> ; cat >a.s <<'EOF'
> #define KZERO   (0xffffff0000000000ull)
>
> TEXT bignumber(SB), 1, $0
>        ADDQ    $KZERO, AX
>        RET
> EOF
> ; cat >ac.c<<EOF
> #include <u.h>
> #include <libc.h>
>
> extern uvlong bignumber(uvlong);
>
> void
> main(void)
> {
>        print("%llux\n", bignumber(0));
>        exits("");
> }
> EOF
> ; 6a a.s; 6c ac.c; 6l a.6 ac.6
>
>



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

* Re: [9fans] 6a bug
  2011-11-16 22:35 ` Charles Forsyth
@ 2011-11-16 22:36   ` Charles Forsyth
  0 siblings, 0 replies; 9+ messages in thread
From: Charles Forsyth @ 2011-11-16 22:36 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

PS: the return value does go in AX



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

* Re: [9fans] 6a bug
  2011-11-16 22:25 [9fans] 6a bug erik quanstrom
  2011-11-16 22:35 ` Charles Forsyth
@ 2011-11-16 22:50 ` Russ Cox
  2011-11-16 23:27   ` Charles Forsyth
       [not found] ` <CAOw7k5hJz=F13tUpq7mU3gSnSWr7H=y4rKCN-OUO-FOavBGygA@mail.gmail.c>
  2 siblings, 1 reply; 9+ messages in thread
From: Russ Cox @ 2011-11-16 22:50 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I'm a little surprised 6a accepts the ull suffix.

Russ


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

* Re: [9fans] 6a bug
  2011-11-16 22:50 ` Russ Cox
@ 2011-11-16 23:27   ` Charles Forsyth
  0 siblings, 0 replies; 9+ messages in thread
From: Charles Forsyth @ 2011-11-16 23:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

we aim to please!

		while(c == 'U' || c == 'u' || c == 'l' || c == 'L')
			c = GETC();

On 16 November 2011 14:50, Russ Cox <rsc@swtch.com> wrote:
> I'm a little surprised 6a accepts the ull suffix.
>
> Russ
>
>



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

* Re: [9fans] 6a bug
       [not found] ` <CAOw7k5hJz=F13tUpq7mU3gSnSWr7H=y4rKCN-OUO-FOavBGygA@mail.gmail.c>
@ 2011-11-17  0:50   ` erik quanstrom
  2011-11-17 16:07     ` Russ Cox
       [not found]     ` <CADSkJJU2s1r8Qi=F9eT=+i2mCatxB+c_70teMBkQ3ToOsazGDA@mail.gmail.c>
  0 siblings, 2 replies; 9+ messages in thread
From: erik quanstrom @ 2011-11-17  0:50 UTC (permalink / raw)
  To: charles.forsyth, 9fans

On Wed Nov 16 17:36:39 EST 2011, charles.forsyth@gmail.com wrote:
> AX is the wrong register. REGARG is BP. actually, it's "RARG" in 6a, in case it
> changes, although that seems less likely now.
>

well my example is slightly booged then.  i just needed a label.
the point still stands that 6l is not liking the *value*.  this actually
comes from _start64v, and i wanted to simplify it.  if you replace
the given value with $10, it 6l will not complain.

_start64v: doasm: notfound from=75 to=10 (423)	ADDQ	$-1099511627776,AX
_start64v: doasm: notfound from=75 to=10 (423)	ADDQ	$-1099511627776,AX
_start64v: doasm: notfound from=75 to=10 (423)	ADDQ	$-1099511627776,AX

- erik



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

* Re: [9fans] 6a bug
  2011-11-17  0:50   ` erik quanstrom
@ 2011-11-17 16:07     ` Russ Cox
  2011-11-17 16:13       ` Charles Forsyth
       [not found]     ` <CADSkJJU2s1r8Qi=F9eT=+i2mCatxB+c_70teMBkQ3ToOsazGDA@mail.gmail.c>
  1 sibling, 1 reply; 9+ messages in thread
From: Russ Cox @ 2011-11-17 16:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs; +Cc: charles.forsyth

On Wed, Nov 16, 2011 at 7:50 PM, erik quanstrom <quanstro@quanstro.net> wrote:
> well my example is slightly booged then.  i just needed a label.
> the point still stands that 6l is not liking the *value*.  this actually
> comes from _start64v, and i wanted to simplify it.  if you replace
> the given value with $10, it 6l will not complain.

This is a detail of the x86-64 architecture.
An immediate in an arithmetic instruction must
fit in a signed 32-bit int, and this one does not.
You've written an impossible instruction, and the
linker is telling you in own cryptic way.
The assemblers do not know such details, never have.

You need to MOVQ that constant into a register
and then use the register as the argument to ADDQ.

Russ


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

* Re: [9fans] 6a bug
  2011-11-17 16:07     ` Russ Cox
@ 2011-11-17 16:13       ` Charles Forsyth
  0 siblings, 0 replies; 9+ messages in thread
From: Charles Forsyth @ 2011-11-17 16:13 UTC (permalink / raw)
  To: Russ Cox; +Cc: Fans of the OS Plan 9 from Bell Labs

I'd replied, but "Reply"'s default is never right (either way).
It's as you say, and the reason it worked in the kernel is
that KZERO was a different value, which did satisfy the hardware's constraint.

On some of the older RISC machines, the loader might generate impossible
constants into a register itself, but that relied on defining a global REGTMP,
which was fine on a 32-ish register machine (you hardly ever need that many)
but not so good on the amd64 where the original registers are strange and
in short supply, and the new registers have a penalty, and there are only 16
in all.


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

* Re: [9fans] 6a bug
       [not found]     ` <CADSkJJU2s1r8Qi=F9eT=+i2mCatxB+c_70teMBkQ3ToOsazGDA@mail.gmail.c>
@ 2011-11-17 16:15       ` erik quanstrom
  0 siblings, 0 replies; 9+ messages in thread
From: erik quanstrom @ 2011-11-17 16:15 UTC (permalink / raw)
  To: 9fans

> This is a detail of the x86-64 architecture.
> An immediate in an arithmetic instruction must
> fit in a signed 32-bit int, and this one does not.
> You've written an impossible instruction, and the
> linker is telling you in own cryptic way.
> The assemblers do not know such details, never have.
>
> You need to MOVQ that constant into a register
> and then use the register as the argument to ADDQ.

yup.  that's the problem.  i had forgotten this rule because
i changed from one 64-bit constant to another.  the tricky
bit about the first constant was that it was a sign-extended
32-bit constant, and the linker knew this little nugget.
so imagine my surprise when changing

#define KZERO		(0xfffffffff0000000ull)

to

#define KZERO		(0xffffff0000000000ull)

resulted in linker errors.

it all makes sense now.  (even if it is repulsive.)

- erik



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

end of thread, other threads:[~2011-11-17 16:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-16 22:25 [9fans] 6a bug erik quanstrom
2011-11-16 22:35 ` Charles Forsyth
2011-11-16 22:36   ` Charles Forsyth
2011-11-16 22:50 ` Russ Cox
2011-11-16 23:27   ` Charles Forsyth
     [not found] ` <CAOw7k5hJz=F13tUpq7mU3gSnSWr7H=y4rKCN-OUO-FOavBGygA@mail.gmail.c>
2011-11-17  0:50   ` erik quanstrom
2011-11-17 16:07     ` Russ Cox
2011-11-17 16:13       ` Charles Forsyth
     [not found]     ` <CADSkJJU2s1r8Qi=F9eT=+i2mCatxB+c_70teMBkQ3ToOsazGDA@mail.gmail.c>
2011-11-17 16:15       ` erik quanstrom

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 NNTP newsgroup(s).