GCC/ARM_CM4F wasted word on main stack

hawk777 wrote on Monday, November 04, 2013:

Hi! Looking at the GCC/ARM_CM4F target port.c xPortPendSVHandler, I believe a word of stack space is wasted pushing r14 (the link register) on the main stack, this being done on line 449 in the 7.5.3 release. It looks like this code was copied from the CM3 target, where the push of r14 in that instruction made sense, as the exception return value was the same for all tasks and so could simply be saved on the main stack between call and return of vTaskSwitchContext. In the CM4F, on the other hand, different tasks have different exception return values depending on whether or not the task uses the FPU; as such, the push on line 445 saving the callee-save integer registers onto the process stack was extended to include the link register, r14, and the corresponding load on line 460 updated to match. However, because r14 is saved on the process stack, I believe there is no longer any reason to save it on the main stack on line 449 and restore it on line 455; certainly the LR is never used between line 455 when restored the first time and line 460 when restored the second time! This is just wasting a word of main stack space, and a little bit of CPU time, for on benefit, as far as I can tell.

rtel wrote on Monday, November 04, 2013:

Looks like you could be right. I will test it with the additional push/pop removed.