Using System.MathF in core math functions
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
I noticed the F# compiler uses `System.Math` for both `float` and `float32` values for implementing functions like `sin` and `sqrt`. Could the core functions use `System.MathF` for `float32` values instead, when `System.MathF` is available? This would allow for better codegen by avoiding conversions between `float` and `float32` and using faster hardware instructions (e.g. `sqrtss` over `sqrtsd`)
Simple codegen comparison: https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AbEAzAzmgFxAENcBbAHwgAcYA7AAgGUBPXAmMgWACheMYBBrgCWdAIIMAFAhANsGCMQIBmAEwBKBgF5hYhgn6C9dAELTZ8xcvVbdAWWUALAGIA6JmJkbeRobgBHKAJJGTkFJVVNHWEgoUMeAX848zCrSNsYxwJXDzjvXx4gA==
The obvious alternative would be to do nothing. It's a small benefit. I think it would be a really small change if `MathF` were available on all .NET platforms, but since it is not I don't really know what the impact would be to make the implementation conditionally choose `Math` versus `MathF` depending on the target framework.
Contributor guide
Assessment
This issue has not been assessed yet.