[compiler-rt] [compiler-rt][builtins]Fix complex division for aarch64 (PR #106664)

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 31 13:06:43 PDT 2024


alexander-shaposhnikov wrote:

Yeah. Signalling NaNs can come from the source code / other libraries doing bitwise manipulations.
E.g. one may consider the following c++ code snippet:
```
  std::complex<float> x = {
     std::numeric_limits<float>::infinity(),
     std::numeric_limits<float>::signaling_NaN()};

  auto y = std::complex<float>(1, 0) / x;
  std::cout << y << std::endl;
```
If one compiles this code with g++ (on ARM) it will print (0, 0), while clang + compiler-rt would yield (nan, nan).
On x86_64 both of them produce (0, 0) 
(as expected (to the best of my knowledge), see also https://en.cppreference.com/w/c/numeric/complex).

The difference stems from 
```
float __c = bit_cast<float>(0x7f800000); / * infinity */
float __d = bit_cast<float>(0x7f800001); /* signaling nan */
float current_max = __compiler_rt_fmaxf(__c, __d) /* nan, but infinity is expected */;
float new_max = __compiler_rt_fmaxX(__c, __d) /* infinity, If either argument is NaN,  __compiler_rt_fmaxX returns the other argument (see the implementation of __compiler_rt_fmaxX) */;
```



https://github.com/llvm/llvm-project/pull/106664


More information about the llvm-commits mailing list