newlib patches
Lately i have been looking into newlib, although there is again a new release 1.19 i am still looking at 1.18. What is so interesting about it? Well, i have noticed that the pspsdk is using integer math for all it's floating point operations, after studying the documentation is was simple to enable hardware floating point math just by using a configuration flag: --enable-newlib-hw-fp. After this point i've noticed that using the -fast-math with gcc does nothing, why? Apparently newlib only has support (or so it seems to me) for NEC processors, so after a couple of hacking i added basic support for fast math function replacements. I did not add all functions but just some basic ones:
- sinf(float x)
- cosf(float x)
- asinf(float x)
- acosf(float x)
- atanf(float x)
- absf(float x)
- sqrtf(float x)
- expef(float x)
- logef(float x)
The idea here is that just by enabling the -fast-math flag you can benefit from some performance improvement. It is obvious to say that this is all experimental stuff it might work or not with your code, we need to test and see how it behaves. Now, It may be already lots of changes, but something that has been puzzling me for a while is why does ODE (Open Dynamics Engine) work on the PSP, after changing some mails on the ODE mailing list i got some info that NaNs and Infs do not work as expected, so i decided to patch again new lib for that too. Now here is a thing that is more complicated than it sounds. Newlib floating point math has several implementations, ISO, IEEE, X... so which one to change? i opted for the default one, math.h defines 2 functions:
- isnan
- isinf
These were functions that were changed and remained on math.h as macros, that expand to fpclassify comparisons, however there are 2 extra functions:
- __isnanf
- __isinff
These ones are real implementations, so i patched these 2 to use the PSP fpu processor to check if a number is NaN or INF. I will be testing this changes but if some of the users of minpsp, you for example :) would like to help to test just build the toolchain and try it out or let me know and i will build a test toolchain for alpha testers.