User manual

mikroC PRO for dsPIC
MikroElektronika
159
Without SSA enabled, this example is consisted of 5 asm instructions :
;rbuild.c,10 :: if(y+k)
0x0218 0x90008E MOV [_WREG14+0], _WREG1
0x021A 0x470062 ADD _WREG14, #2, _WREG0
0x021C 0x408010 ADD _WREG1, [_WREG0], _WREG0
0x021E 0x320001 BRA Z L_main0
L__main2:
;rbuild.c,11 :: asm nop;
0x0220 0x000000 NOP
Proper Coding Recommendations
To get the maximum out of the SSA, user should regard the following rules during the coding process :
- Routines should not contain too many parameters (not more than 4 words).
- Don’t change the value of the parameter in the function body (it is better to use a new local variable).
- If the function1 parameters are passed as function2 parameters, then parameter order should
remain the same :
f2(int a, int b) { }
f1(int x, int y) {
// routine call
f2(x,y); // x->a and y->b (1 to 1 and 2 to 2) is far more efcient than :
f2(y,x); // y->a and x->b (1 to 2 and 2 to 1)
}
- Large amount of nested loops and complex structures as its members should be avoided.
- When writing a code in assembly, keep in mind that there are registers reserved exclusively for
routine parameters.
- Using goto and label statements in nested loops should be avoided.
- Obtaining address of the local variable with the global pointer and using it to alter the variable’s address
should be avoided.
Notes :
- mcl les compiled with or without SSA enabled are fully compatible and can be used and mixed without
any restrictions, except function pointers.
- All function prototypes and function pointers have to be built using the same optimizer because of different
calling conventions in different optimizers. In SSA, function parameters are passed via working registers,
and without SSA they end up on the function frame.
- This means that you cannot have a function implementation which is optimized using SSA optimizer, and to
call this function via function pointer in another module which is optimized using NON-SSA.
When using pointers to functions, compiler must know exactly how to pass function parameters and how to
execute function call.