Author Topic: Register passing in SP5  (Read 9305 times)

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Register passing in SP5
« on: February 04, 2008, 11:08:36 PM »
Mark, how hard is it to enable register passing in the SP5 code, assuming we
recompile any libs, and check the assembler .S files for param passing ?

 Thanks,
 John

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Register passing in SP5
« Reply #1 on: February 05, 2008, 10:40:57 AM »
Hi John

Register passing is now used in SP6 since it is indeed more efficient.
This can also easily be activated in SP5, where the only change required is in the startup.s file (with Codewarrior - I don't know whether this is possible with GNU):

_mcf5xxx_wr_vbr:
/*  move.l  4(SP),D0 */                    /* {2} remove this when working with parameters passed in registers */
   .long    0x4e7b0801                     /* assembler code for movec d0,VBR */
    nop
    rts   

Just removing one line solves it. Then any libraries must be compiled the same and it should all work.

Regards

Mark

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Register passing in SP5
« Reply #2 on: February 05, 2008, 03:07:46 PM »
Thanks Mark, I'll give it a shot ...

 John

Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Register passing in SP5
« Reply #3 on: February 05, 2008, 07:56:11 PM »
Mark, I set the project to use register passing. We also
use the fp_coldfire.a math library located in the
FreeScaleCW6.3 tree. There is no project in their tree to rebuild
it ,so I used it as is. The uTasker project ran OK. When I disassembled the calls to  fp_coldfire.a I noticed that the compiler must know it's stack passing and uses that method. Overall the project saved about 6K of code and 176 byes less of
stack usage using register passing. I also disabled using A6
stack frames and saved over 2K of code usage. Do you think
this will be a problem ?

 Thanks,
 John

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: Register passing in SP5
« Reply #4 on: February 05, 2008, 10:04:28 PM »
Hi John

I try to stay as much at the C-level where the details of parameter passing and stack are left up to the compiler. There shouldn't be any code in the project (apart from a very small amount of assembler and library, if used) which is compiler setting dependent.

However, as you have seen, the operation of the compiler does influence code size and also operational speed (as does the optimiser setting used).

I tend to use ALWAYS use full optimisation for space (also for debugging*) based on the fact that it is best to test with the same code and characteristics which will be used later in the release version, and the fact that also optimisation for size will usually produce quite good optimisations for speed (apart from things like loop roll out where loops will be expanded to a series of blocks of the content to avoid any loop variable checking and flow control change - but at the price of code size).

If minimum code size is your priority and certain setting allow this to be improved I would stick with it. It is up to the compiler to ensure that the C-code works, irrespective of the exact compiler settings - if it runs during normal tests this will probably already have proved that it is suitable.

*You probably already know that debugging with CodeWarrior with full optimisation can be tricky. I tend to switch on mixed mode display when doing this so that the assembler code can be seen, which sometimes makes more sense when the program flow jumps around. It also enables single stepping in the assembler code in switch states from FLASH (this doesn't tend to work otherwise due to limited hardware breakpoints). However I also try to avoid the debugging of code on the target which is not very hardware specific - which is generally a very small part of real projects. Instead general C code can be tested and debugged in the uTasker simulator (VS) much easier and more efficiently.

Regards

Mark


Offline johnr

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: Register passing in SP5
« Reply #5 on: February 06, 2008, 10:23:08 PM »
Hi Mark, the SP5 code with reg passing and no A6 stack frames looks like it's
working so far. A co worker has  ported over a small pre-emptive RTOS which
ran on a 8051 type CPU so he can run some of his code with uTasker.
We are using an unused TIMER set for 10ms to preempt the RTOS code. We only
do this when uTasker is idle. We also use a trap to implement an RTOS Yield function.
We are testing it with 2 RTOS tasks running and so far it seems to be working.
I moved the top of the heap down and we have about 12K of free stack ram
to add more RTOS tasks etc. The fp_coldfire.a lib hasn't had a problem with
the pre-emptive RTOS tasks so far in my testing.

 Thanks,
 John