Skip to content

Optimization Case 1 – storing a return value

March 15, 2013

I don’t know how much of this I’m going to do or document but for example in the loop function code I see:

;  len = encpacketReceive();
	Ccall _encpacketReceive
	cpy2 R11,R15 ;LOADU2(reg)
	st2 R11,'O',sp,(-4+10); ASGNU2(addr,reg)

So the copy from r15 to r11 is a waste of 4 instructions.

Compiling the c code to symbolic I get:

;  len = encpacketReceive();
    2. ADDRGP2 encpacketReceive
   1' CALLU2 #2 {unsigned int function}
   4. ADDRLP2 len
   3' ASGNU2 #4 #1 2 1

which I read as ASGNU2(ADDRLP29(len),CALLU2(ADDRGP2(encpacketreceive))
and looking at my machine description I see:

ar:   ADDRGP2     "%a"
reg:  CALLU2(ar)  "\tCcall %0\n"  1
stmt: ASGNU2(addr,reg)  "\tst2 R%1,%0; ASGNU2(addr,reg)\n"  1

which tells the compiler how to do each step but doesn’t encourage combinations.

So I will try giving it a combo play as:

stmt: ASGNU2(addr,CALLU2(ar))  "\tccall %1\tst2 retVal,%0; ASGNU2(addr,CALLU2(ar))\n"  0

which got me nowhere.

I have done one other combination instruction so i know they can work. Looking at the emitted assembler again, I’ll try combining the asgnu2 and loadu2 as

stmt: ASGNU2(addr,LOADU2(reg))  "\tst2 R%1,%0; ASGNU2(addr,LOADU2(reg))*\n"  0

and nothing!

So I’ll give this up for the day – it may be that a post processing peephole optimizer is going to be needed.

On consideration, I think this is because the R15 targeting is being done by the code and isn’t seen by the normal templates.


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: