-
Notifications
You must be signed in to change notification settings - Fork 8.2k
rpi_pico: Add support for ROM math functions #52896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Some pico-sdk drivers call a panic function, originally implemented as part of the Pico's C runtime. This commit adds a Zephyr compatible implementation of panic, so that those drivers could be compiled with Zephyr. Signed-off-by: Yonatan Schachter <[email protected]>
The RP2040's BOOTROM contains ABI functions for working with floating point numbers and large integers. When using the implementations that are already in the ROM, there is no need to link these to the user's binary, thus reducing the binary size. Moreover, these implementations take advantage of a hardware divider, thus improving the performance of float division. Signed-off-by: Yonatan Schachter <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR mostly good.
But this PR changes the basic calculation implementations.
I think adding a unit test for float calculations would be better.
| { | ||
| va_list args; | ||
|
|
||
| va_start(args, fmt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referencing to original PICO-SDK implementation,
It would be better to check null-pointer here.
| return 0; | ||
| } | ||
|
|
||
| /* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part should be better to separate commit.
|
As you mentioned, the bootrom float/double libraries rely on the hardware divider to speed up operations. However, the divider state must be backed up and restored. The FreeRTOS port implements this here. The Pico SDK appears to implement this behavior correctly, but should be verified. Was this tested in a high-preemption environment? |
|
@cesarvandevelde Thanks for pointing it out, you're absolutely right. Unfortunately, this would require changing the PendSV handler, which is a bit complicated. I'll draft this for now, until a solution is found. |
|
More bad news: Zephyr's linker configuration interferes with The Commenting the line below works: Of course, this is not a real solution. There are other instances of cross-referencing in In any case, the performance gains are noticable and worth pursuing. Once I got the branch to work, I tried it out on a 128 x 32 px Mandelbrot. Render time decreased from 14.537s to 9.782s (33% faster). |
I don't think this is necessary. The FreeRTOS port only backs up the divider upon context switch if This alternate behavior uses a critical section to guard against concurrent use. I don't quite understand why divider state must be stored in that case though. The critical section would also guard against RTOS task switching while the divider is in use... The default behavior in the Pico SDK is to always save/restore divider state after each use: That should make it safe to use in a pre-emptive environment. However:
|
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
The RP2040's BOOTROM contains ABI functions for working with floating
point numbers and large integers. When using the implementations that
are already in the ROM, there is no need to link these to the user's
binary, thus reducing the binary size.
Moreover, these implementations take advantage of a hardware divider,
thus improving the performance of float division.
Proof of it working
Compiling the following app (with no optimizations):
Yields the following call:
Which is implemented as:
R3 is loaded with a pointer to a lookup table that points to the implementation in ROM. It then loads the address of __aeabi_fadd in ROM, and jumps.