-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
ARM CPUs with hardware floating point (VFP) have additional registers, s0-s31 (also labelled by d0-d15). Of these, s16-s31 are callee save and so in principle should be saved and restored by the NLR code.
Currently they are not saved. This has not been an issue so far because gcc (up to v8) only uses these s16-s31 registers when doing floating point calculations and MicroPython doesn't call into NLR-sensitive code during a floating point calculation (eg no NLR push/pop during sin(x)
or during binary ops between two complex numbers). (At least this has never been observed, no problems related to this have been reported so far.)
But gcc 9 uses more aggressive optimisation and may use s16-s31 to save normal integer values instead of using the stack, and these values may be corrupted by NLR not restoring them correctly. Compiling stm32 with gcc 9.1.0 does lead to such issues (eg test suit run on PYBv1.0 fails on multiple tests).
The workaround for now would be to only use gcc 8.x or below.
Probably the only proper fix is to save registers s16-s31 (or maybe just s16-s23 since gcc 9 doesn't seem to use registers above these) in the NLR context.