Topic : RC51 - optimisation - function parms unecessarily stored to mem

Forum : 8051

Original Post
Post Information Post
May 18, 2007 - 6:21pm
Guest

In the large model:

PUBLIC S16 foo(S16 a, S16 b)
{
return bar(a, -b);
}

makes

; FUNCTION _foo (BEGIN)
; Register R2R3 is assigned to parameter a
; SOURCE LINE # 154
0000 8E02 MOV AR2,R6
0002 8F03 MOV AR3,R7
0004 900000 R MOV DPTR,#b
0007 EC MOV A,R4
0008 F0 MOVX @DPTR,A
0009 A3 INC DPTR
000A ED MOV A,R5
000B F0 MOVX @DPTR,A
000C F4 CPL A
000D FD MOV R5,A
000E 900000 R MOV DPTR,#b
0011 E0 MOVX A,@DPTR
0012 F4 CPL A
0013 FC MOV R4,A
0014 0D INC R5
0015 ED MOV A,R5
0016 7001 JNZ ?LAB4
0018 0C INC R4
0019 ?LAB4:
0019 120000 R LCALL bar
001C 22 RET

Parameter 'a' is handled in registers (good) but 'b' is passed out to xdata, then read back, before being 'minused'. The same thing happens if #pragma AUTO is set; 'b' is stacked, then read back.

I've seen this patttern often. It seems the compiler doesn't look ahead to see if addtional parameters can be kept in the register bank. There's an oppotunity for optimisation.

regards Steven Pruzina

Replies
Post Information Post
+1
0
-1
May 21, 2007 - 2:34pm
Raisonance Support Team

Steven,

We added your improvement in our bug database, and it will be implemented in the next release.

Regards,

Stéphane