std-simd icon indicating copy to clipboard operation
std-simd copied to clipboard

sin and cos of std::simd come out wrong with clang++

Open kfjahnke opened this issue 4 years ago • 1 comments

version / revision | Operating System | Compiler & Version | Compiler Flags | CPU repo as per Dec 14 2020 | ubuntu 20.04 | clang++ 10.0.0 | --std=c++17 | Haswell core i5

Here's a strange one, affecting only clang++, both for single and double precision. Other trigonometric funcions I tested come out right.

Testcase

#include <iostream>
#include <experimental/simd>

typedef std::experimental::simd
          < float ,
            std::experimental::simd_abi::fixed_size < 4 >
          > f4_t ;

int main ( int argc , char * argv[] )
{
  f4_t f4 ( .5f ) ;

  f4_t r4 = sin ( f4 ) ;
  std::cout << "sin " << f4[0] << " -> " << r4[0] << std::endl ;

  r4 = cos ( f4 ) ;
  std::cout << "cos " << f4[0] << " -> " << r4[0] << std::endl ;
}

compiled with: clang++ -std=c++17 sincos.cc -osincos

Actual Results

sin 0.5 -> 0 cos 0.5 -> 1

compiled with g++ -std=c++17 sincos.cc -osincos as expected:

Expected Results

sin 0.5 -> 0.479426 cos 0.5 -> 0.877583

kfjahnke avatar Dec 14 '20 16:12 kfjahnke

It seems to be coming from here: https://github.com/VcDevel/std-simd/blob/c69cb8f6a8627c186427b08662b05693176c73b2/experimental/bits/simd_builtin.h#L51.

The _andnot returns a 0 for _S_absmask with clang, the correct value should be 0x7FFFFFFF.

r-devulap avatar Mar 29 '21 15:03 r-devulap