[feature request] Is there any float arithmatic round support?
- Dominant language
- C++
- Stars
- 5.8k
- Forks
- 471
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 81
Description
Hello,
I wonder is there any round arithmetic support?
I'm writing a project, which needs to control the round direction of the float point arithmetic. for example:
```cpp
// c++23
#include
#include
#include
#include
#include
#include
#include
namespace hn = hwy::HWY_NAMESPACE;
#pragma STDC FENV_ACCESS ON
#pragma STDC FENV_ROUND FE_DYNAMIC
#pragma GCC optimize "-frounding-math"
int main(void) {
const hn::ScalableTag d;
auto x = hn::Set(d, std::bit_cast(0b1ULL));
auto y = hn::Set(d, 1.5);
auto z = hn::Zero(d);
std::println("normal fma: {} {}", fma(std::bit_cast(0b1ULL), 1.5, 0),
hn::GetLane(hn::MulAdd(x, y, z)));
fesetround(FE_DOWNWARD);
std::println("FE_DOWNWARD fma: {} {}",
fma(std::bit_cast(0b1ULL), 1.5, 0),
hn::GetLane(hn::MulAdd(x, y, z)));
fesetround(FE_UPWARD);
std::println("FE_UPWARD fma: {} {}",
fma(std::bit_cast(0b1ULL), 1.5, 0),
hn::GetLane(hn::MulAdd(x, y, z)));
}
#pragma GCC reset_options
```
compile with gcc 14.2.0, in Debug build, it output:
```
normal fma: 1e-323 1e-323
FE_DOWNWARD fma: 5e-324 5e-324
FE_UPWARD fma: 1e-323 1e-323
```
but in release build, it output
```
normal fma: 1e-323 1e-323
FE_DOWNWARD fma: 1e-323 1e-323
FE_UPWARD fma: 1e-323 1e-323
```
the \'s `fma` output wrong result, seems like a gcc's [bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678), but there is also no way to control round direction using Highway. I wonder whether is it possible, since there is intrinsic like `_mm512_fmadd_round_pd` to do fma with round.
Contributor guide
Assessment
This issue has not been assessed yet.