Codewarrior Compiler Efficiency

"jdonner" <[email protected]> Fri, 4 Apr 2008 12:38:34 -0500
Newsgroups gmane.comp.hardware.motorola.microcontrollers.coldfire
Message-ID <056b01c8967a$b5126fc0$6501a8c0@SSP3000>
I am using an MCF52223 and Codewarrior for Coldfire Version 6.0.

I am trying to optimize my software for speed and cannot get the compiler to help me.  This is a routine to setup the PIT and toggle a pin at the PIT period.

------------------------------------------------------------------------------------------------------------------------------------------------
 MCF_PIT0_PCSR=0x0236; // disable PIT
 MCF_PIT0_PMR=30;
 MCF_PIT0_PCSR=0x0237; // setup for PITclktime=2*4/75MHz=.1067us

 // Test PIT
 for(;;){
  while(!(MCF_PIT0_PCSR&MCF_PIT_PCSR_PIF)){};
  MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;
  TEST_TOGGLE;
 }

------------------------------------------------------------------------------------------------------------------------------------------------
The compiler generates the following:

 MCF_PIT0_PCSR=0x0236; // disable PIT
00000596: 303C0236        move.w   #566,d0
0000059A: 33C040150000    move.w   d0,0x40150000 (0x40150000)

 MCF_PIT0_PMR=30;
000005A0: 701E            moveq    #30,d0
000005A2: 33C040150002    move.w   d0,0x40150002 (0x40150002)

 MCF_PIT0_PCSR=0x0237; // setup for PITclktime=2*4/75MHz=.1067us
000005A8: 303C0237        move.w   #567,d0
000005AC: 33C040150000    move.w   d0,0x40150000 (0x40150000)

 // Test PIT
 for(;;){
  while(!(MCF_PIT0_PCSR&MCF_PIT_PCSR_PIF)){};
000005B2: 323940150000    move.w   0x40150000 (0x40150000),d1
000005B8: 7000            moveq    #0,d0
000005BA: 3001            move.w   d1,d0
000005BC: 028000000004    andi.l   #0x4,d0
000005C2: 4A80            tst.l    d0
000005C4: 67EC            beq.s    main+0xb2 (0x5b2)       ; 0x000005b2
  MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;
000005C6: 41F940150000    lea      0x40150000 (0x40150000),a0
000005CC: 3210            move.w   (a0),d1
000005CE: 7000            moveq    #0,d0
000005D0: 3001            move.w   d1,d0
000005D2: 08C00002        bset     #2,d0
000005D6: 3080            move.w   d0,(a0)
  TEST_TOGGLE;
000005D8: 41F940100012    lea      0x40100012 (0x40100012),a0
000005DE: 1210            move.b   (a0),d1
000005E0: 7000            moveq    #0,d0
000005E2: 1001            move.b   d1,d0
000005E4: 0A8000000008    eori.l   #0x8,d0
000005EA: 1080            move.b   d0,(a0)
 }
000005EC: 60C4            bra.s    main+0xb2 (0x5b2)       ; 0x000005b2

------------------------------------------------------------------------------------------------------------------------------------------------
Is there a more efficient way to write the while() loop that doesn't cause the 32 bit stuff?
Is there a more efficient way to clear the PIF flag?

Jeff Donner
Software Systems Plus, Inc.
 816-407-7749