gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Re: LENGTH() on Solaris 10/sparc -- problem found


From: john o goyo
Subject: [Gm2] Re: LENGTH() on Solaris 10/sparc -- problem found
Date: Sat, 7 Aug 2010 20:43:48 -0400

On 24-Jul-10, at 3:48 AM, Gaius Mulley wrote:
john o goyo <address@hidden> writes:
[...]

2. How are open arrays passed on the stack?

a structure is passed on the stack which contains:

struct unbounded {
  char *startofstring;
  unsigned int high;
}

Of course, I was quite wrong in asking about the stack. Sparc is a risc machine and the first 6 parameters are always passed in registers. In this case, the pointer above is passed in register %o0 and the integer above is passed in register %o1.

Here is my test code.

MODULE LengthTestSilent;

FROM M2RTS IMPORT Length;

VAR
  n, m :CARDINAL;
  s :ARRAY[0..15] OF CHAR;
BEGIN
  s := "Woe is I";
  n := LENGTH(s);

  m := Length(s);

  IF n # m THEN
    HALT
  END (*IF*)
END LengthTestSilent.

Here is the result of a some single stepping in gdb.

8       BEGIN
9         s := "Woe is I";
10        n := LENGTH(s);
11
12        m := Length(s);
13
(gdb) n
10        n := LENGTH(s);
(gdb) s
M2RTS_Length (a={_m2_contents = 0x10012c260, _m2_high_1 = 0})
    at ../../../src/gcc-4.1.2/gcc/gm2/gm2-libs-iso/M2RTS.mod:290
290        l := 0 ;
(gdb) p/x $i0
$10 = 0x10012c260
(gdb) p/x $i1
$11 = 0xf
(gdb) c
Continuing.

Breakpoint 3, _M2_LengthTestSilent_init () at LengthTestSilent.mod:12
12        m := Length(s);
(gdb) s
M2RTS_Length (a={_m2_contents = 0x10012c260, _m2_high_1 = 15})
    at ../../../src/gcc-4.1.2/gcc/gm2/gm2-libs-iso/M2RTS.mod:290
290        l := 0 ;
(gdb) p/x $i1
$12 = 0xf00000000


To explain, when a procedure is invoked, the outgoing parameters are placed in registers %o0.. %o6. In the called procedure, these are renamed as %i0..%i6. We see above that LENGTH(s) put a 64-bit quantity in %o1 but Length(s) put a 32-bit quantity, incorrectly converted to a 64-bit quantity, in %o1. This I discovered from the assembler output. The former is a simple "mov 15, %o1" whereas the latter from a convoluted path of several temporary variables.

As to why only the top 32 bits are used in the called procedure, the 64-bit quantity is read as a 32-bit quantity and this is a big-endian machine.

john



reply via email to

[Prev in Thread] Current Thread [Next in Thread]