Optimizing parameters in C function for MIPs/gcc -
i'm trying optimize code, , discovered gcc treats 2 uint_64 parameters differently struct 2 uint_64's in it. if have:
void testfn2parm( uint64_t p1, uint64_t p2 ) { tp[0] = p1; tp[1] = p2; }
it resolves to:
void testfn2parm( uint64_t p1, uint64_t p2 ) { tp[0] = p1; 1d18: 3c020000 lui v0,0x0 1d1c: fc440000 sd a0,0(v0) tp[1] = p2; 1d20: 64430000 daddiu v1,v0,0 1d24: 03e00008 jr ra 1d28: fc650008 sd a1,8(v1) 1d2c: 00000000 nop
where a0
, a1
values of parameters -- no stack access. however, if do:
struct ts { uint64_t t64[2]; }; void testfntsparm( struct ts ts ) { tp[0] = ts.t64[0]; tp[1] = ts.t64[1]; }
which same thing, get:
void testfntsparm( struct ts ts ) { 1d88: dc830008 ld v1,8(a0) tp[0] = ts.t64[0]; 1d8c: 3c020000 lui v0,0x0 1d90: dc840000 ld a0,0(a0) tp[1] = ts.t64[1]; 1d94: 64450000 daddiu a1,v0,0 1d98: fca30008 sd v1,8(a1) 1d9c: 03e00008 jr ra 1da0: fc440000 sd a0,0(v0) 1da4: 00000000 nop
notice ld commands. in case a0
starts stack pointer. i'm wondering if there's clever ways around this, doesn't involve rewriting calling functions? (i'm using cross-compiler mips based on gcc 4.7)
Comments
Post a Comment