I did not use CW in the past and getting now new experience with CW toolchain. We ported our application to CW recently and met resources problem taking ~85% of the flash memory available on MCF52259 MCU. At the first glance it shows that the hardware platform is not scaled properly to the application and should be respinned with more resources. A few days ago I decided to try another compiler (IAR CF) and to my big surprise the application size reduced by ~30%. I ported all application code and the result was still there 30% less size.
Curios, I created a small project for both compilers and tried side by side comparison for function code sizes. The project is FreeRtos based demo with basic task switching. I took one module (tasks.c) and here is the result. CW v.7.1 and IAR CF v.1.22.
No optimization:
CW No optimization IAR No optimization
HEX DEC HEX DEC %
xTaskGenericCreate 162 354 176 374 106
vTaskStartScheduler 60 96 52 82 85
vTaskSuspendAll E 14 8 8 57
xTaskResumeAll 11C 284 112 274 96
vTaskIncrementTick EC 236 C8 200 85
vTaskSwitchContext 114 276 11A 282 102
prvIdleTask 10 16 E 14 88
prvInitialiseTCBVariables 7E 126 6C 108 86
prvInitialiseTaskLists 88 136 82 130 96
prvCheckTasksWaitingTermination 8A 138 7E 126 91
prvAllocateTCBAndStack 7C 124 8E 142 115
prvDeleteTCB 26 38 1E 30 79
TOTAL 1838 TOTAL 1770 96%
Both compiles create almost similar results. I think for 2k code 4% difference is neglectable.
Optimization L3 for code size:
CW L3 optimization IAR Medium optimization
HEX DEC HEX DEC %
xTaskGenericCreate 15C 348 150 336 97
vTaskStartScheduler 62 98 46 70 71
vTaskSuspendAll E 14 8 8 57
xTaskResumeAll 118 280 F0 240 86
vTaskIncrementTick FA 250 CA 202 81
vTaskSwitchContext 128 296 DA 218 74
prvIdleTask C 12 8 8 67
prvInitialiseTCBVariables 76 118 56 86 73
prvInitialiseTaskLists 7E 126 6E 110 87
prvCheckTasksWaitingTermination 8C 140 72 114 81
prvAllocateTCBAndStack 74 116 58 88 76
prvDeleteTCB 26 38 1A 26 68
TOTAL 1836 TOTAL 1506 82%
It looks likeas CW optimization doesn't work properly.
I pushed it to level 4:
CW L4 optimization IAR High optimization
HEX DEC HEX DEC %
xTaskGenericCreate 15C 348 1E6 486 140
vTaskStartScheduler 62 98 46 70 71
vTaskSuspendAll E 14 8 8 57
xTaskResumeAll 118 280 EA 234 84
vTaskIncrementTick FA 250 A4 164 66
vTaskSwitchContext 128 296 DA 218 74
prvIdleTask C 12 76 118 983
prvInitialiseTCBVariables 76 118
prvInitialiseTaskLists 7E 126
prvCheckTasksWaitingTermination 8C 140
prvAllocateTCBAndStack 74 116
prvDeleteTCB 26 38
TOTAL 1836 TOTAL 1298 71%
At that level IAR compiler starts inlining so some functions was eliminated but still the code size reduced even more.CW did not improve at all.
Am I doing something wrong? For me it looks like quite mediocre performance.
Regards, Dmitri.
Could you share your project for further analysis? Or you can visit http://www.freescale.com/support and submit a service request with for this issue:
Category = Technical Request
Topic = CodeWarrior
Thanks,
Kevin
Levels of optimization usually refer to code speed, not code size. If you want to optimize for code size, you have to inidicate that option to the compiler, and there are typically fewer choices of levels.
When using CodeWarrior for ColdFire, you will get smaller code by enabling the register paramater passing convention. IPA (inter-procedural analysis) and automatic inlining might also help.
I tried you recipe, It improves but still loosing to IAR quite a lot:
CW L4 optimization IAR High optimization
HEX DEC HEX DEC %
xTaskGenericCreate 2A4 586 1E6 486 140
vTaskStartScheduler 62 98 46 70 71
vTaskSuspendAll E 14 8 8 57
xTaskResumeAll 118 280 EA 234 84
vTaskIncrementTick FA 250 A4 164 66
vTaskSwitchContext 128 296 DA 218 74
prvIdleTask 96 150 76 118 983
TOTAL 1674 TOTAL 1298 78%