openwch / ch32v307

Including the SDK、HDK、Datasheet of RISC-V MCU CH32V307 and other relevant development materials

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CH32V3X: Improvement on FreeRTOS port

mean00 opened this issue · comments

commented

Hi
The CH32v3X FreeRTOS port can be compiled two ways :

  • with FPU support where all the FPU registers are always saved/restored. This is big in CPU and stack usage.
  • without FPU support, where they are never saved/restored. That could lead to FPU register corruption.

There might be a middle ground, where you use the "dirty bits" of the mstatus register.
The "dirty bits" are telling if the FPU has been used or not as i understand it
If not, no need to save/restore the FPU registers
If so, you need to save/restore the FPU registers

In order for it to work, you have to move mstatus earlier in the saved register list, so that it can be checked on the fly
and say if the FPU registers need to be saved/restored later on.

If my understanding is correct, you get the best of both world : FPU compatibility when you use it, no extra cost when you dont (on a per thread basis).

I have a temptative patch implementing the above if that's of interest.

Thank you.