sin and cos of std::simd come out wrong with clang++
kfjahnke opened this issue · 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
It seems to be coming from here:
std-simd/experimental/bits/simd_builtin.h
Line 51 in c69cb8f
The _andnot
returns a 0 for _S_absmask
with clang, the correct value should be 0x7FFFFFFF.