Subject: Re: MIPS and load (32bit) constants ...
To: Andrew Cagney <cagney@highland.oz.au>
From: Ted Lemon <mellon@ncd.com>
List: port-pmax
Date: 07/12/1994 17:37:48
> I'm assuming that the MIPS, for a.out format, by convention loads a
> 32bit constant using a pair of load/shift/add 16bit instructions.

Yes.   The sequence for loading constants is:

	lui reg,value>>16
	ori reg,value&0xffff

And for loading a value from an address:

if bit fifteen is set:
	lui reg,(addr>>16)+1
	lw  reg,addr&0xffff(reg)
else:
	lui reg,addr>>16
	lw  reg,addr&0xffff(reg)

this is because the indirect offset is signed.

> 	Is this convention used when the code is for an object
> 	file format that supports more then the text and data
> 	segment (eg coff, elf, ...)?

Yes, except that some data is grouped into the ``small data segment'',
which contains 64k or less of data.   A register is loaded with an
address somewhere in the middle of this section, and conventionally
called ``gp''.   To load data from this section, one instruction can
be used:

	lw	reg, offset(gp)

...where offset is a sixteen-bit signed difference between the address
of the object to be loaded and the address that is loaded in gp.   The
address which will be loaded into gp is known at link time, so
figuring out the offset is relatively easy.   This results in a very
significant performance boost - I measured a 30% difference in speed
in gcc on a complicated source file, for example.

			       _MelloN_

------------------------------------------------------------------------------