rp-rs / rp2040-project-template

A basic rp2040-hal project with blinky and rtt logging example code. With this you can quickly get started on a new rp2040 project
480 stars 98 forks source link

Use built-in math functions (Faster math) #52

Closed alwon1 closed 1 year ago

alwon1 commented 1 year ago

In Section 2.8.3.1. Bootrom Functions of the RP2040 Datasheet mentions several floating-point math functions implemented that should have better performance than what would typically be produced by the compiler as they use additional hardware to improve the performance of these functions.

It has been a while since I looked at this, but the C SDK uses these as the default math functions by using them as a replacement for the standard compiler built-in functions. If this is the case, passing these functions through to LLVM during compilation could improve the performance of these math operations by default.

The Most important to implement would be the functions in divider.h in the C SDK, as they are the most likely to be used.

ithinuel commented 1 year ago

Support for these is implemented. You can check https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal%2Fsrc%2Ffloat

Unless you enable the rp2040-hal feature disable-intrinsics, you'll be using the accelerated version rather than the software implementation.

9names commented 1 year ago

You do miss the f64 instructions if you don't enable the rom-v2-intrinsics feature - but we don't enable that by default because some people have early revision chips

alwon1 commented 1 year ago

Looks like I missed that. Is it possible to add documentation about those flags in this repo?

9names commented 1 year ago

Sounds like a good idea. Would you like to do it?