Port-sparc64 archive

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

Re: sethi and 64-bit constants



On Mon, 31 Mar 2008, raymond.meyer%rambler.ru@localhost wrote:

> On Monday 31 March 2008 16:21:18 Martin Husemann wrote:
> > On Mon, Mar 31, 2008 at 02:53:09PM +0100, 
> > raymond.meyer%rambler.ru@localhost wrote:
> > > Say I have a 64-bit pointer, I would like to load this address into a
> > > register. Sparc sethi instruction has space for 22-bit constants, so how
> > > can I use it to load 64-bit data?
> >
> > For imediate values, you use the
> >
> >     setx value, tempreg, destreg

In general, full 64-bit constants use something like this:

        sethi   %hh(val), %t1
        or      %t1, %hm(val), %t1
        sethi   %lm(val), %t2
        or      %t2, %lo(val), %t2
        or      %t1, %t2, %r1

For 44-bit constants you can do:

        sethi   %h44(val), %t1
        or      %t1, %m44(c), %t1
        sllx    %t1, 12, %t1
        or      %t1, %l44(c), %r1

32-bit constants can be generated with the old:

        sethi   %hi(val), %t1
        or      %t1, %lo(val), %r1

Negative 32-bit constants can be generated with:

        sethi   %hix(val), %t1
        xor     %t1, %lox(val), %r1

And, of course, 12-bit constants can be generated with:

        or      %g0, val, %r1

Which one you use would depend on the number of significant bits in
the constant.  This is true of just about all RISC machines, although
the number of bits that can be generated by specific instruction
sequences varies by architecture.


> >
> > pseudo instruction, which (depending on the value) may generate upto 6
> > instructions.
> >
> So do you know the rules by which those instructions are generated?
> 
> > For the address of a pointer, the answer depends on your memory model.
> > On NetBSD, by default we assume that both text and data segmants are < 2GB,
> > so a 32 bit constant is enough to load the address of a pointer.
> >
> What if you need to mmap() a 4GB memory region. Is it possible on NetBSD or 
> there are restrictions?

The memory model restricts the size of address constants that are
generated by the compiler and relocated by the dynamic linker.  If
your program has less than 4GB of text, initialized data, and static
data, there is no reason to use anything other than sethi/or to 
generate the address constant.  All 64-bits are stored in registers
and pointers, however, so you can malloc() or mmap() as much as you
want until you run out of swap, crash into some other mmapped segment
or bump into the 40-bit address space hole.

Keep in mind that even in the small memory model (<4GB), text, data
and the heap (malloc() space) are in the low part of the address space
(below the 40-bit address space hole) but the stack and default
(shared library) mmap() range are in the negative part of the 
process address space (above the 40-bit address space hole). 

Anyway, before you end up bumping into any of the above issues,
you will probably hit issues involving the process limits structure,
and certain "sanity tests" in the mmap() code that prevent you from
mapping in very large address space sections.  (The limits issue has
to do with supporting the compat32 emulations.)  These restrictions
are true across all architectures.

Eduardo


Home | Main Index | Thread Index | Old Index