On Fri, Dec 04, 2015 at 08:20:05AM +0000, Matt Redfearn wrote: > >Although, it could still be reduced: > >PTR_ADDU sp, gp, _THREAD_SIZE - 32 - PT_SIZE > > > >Assuming the immediate is in range of signed 16bit. > > The immediate would be 32552, so in range of signed 16bit, but that would be > brittle if either _THREAD_SIZE or PT_SIZE were to change in future.... The maximum value possible for _THREAD_SIZE would be with 64k pages for which the expression will exceed the signed 16 bit range. The good news is that GAS is smart enough to cope with the situation by suitably expanding the instruction into a macro unless ".set noat" or ".set nomacro" mode are enabled: $ cat s.s addu $sp, $gp, 65536 [ralf@h7 tmp]$ mips-linux-as -O2 -als -o s.o s.s GAS LISTING s.s page 1 1 0000 3C010001 addu $sp, $gp, 65536 1 0381E821 1 00000000 1 00000000 GAS LISTING s.s page 2 NO DEFINED SYMBOLS NO UNDEFINED SYMBOLS [ralf@h7 tmp]$ mips-linux-objdump -d s.o s.o: file format elf32-tradbigmips Disassembly of section .text: 00000000 <.text>: 0: 3c010001 lui at,0x1 4: 0381e821 addu sp,gp,at ... And of course that macro should better not be expanded in a branch delay slot ... Ralf