Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cross product for gcc 8 #24205

Merged
merged 2 commits into from Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions DataFormats/Math/interface/SSEVec.h
Expand Up @@ -60,8 +60,9 @@ namespace mathSSE {
v4 = _mm_shuffle_ps(v2, v1, _MM_SHUFFLE(3, 1, 0, 1));

v3 = _mm_mul_ps(v3, v4);
const __m128 neg = _mm_set_ps(0.0f,0.0f,-0.0f,0.0f);
return _mm_xor_ps(_mm_sub_ps(v5, v3), neg);
const __m128i neg = _mm_set_epi32(0,0,0x80000000,0);
__m128i ret = __m128i(_mm_sub_ps(v5, v3));
return __m128(_mm_xor_si128(ret,neg));
}
#endif // CMS_USE_SSE

Expand Down Expand Up @@ -94,9 +95,9 @@ namespace mathSSE {
v4 = _mm256_permute_pd(v4,5);

v3 = _mm256_mul_pd(v3, v4);
const __m256d neg = _mm256_set_pd(0.0,0.0,-0.0,0.0);
return _mm256_xor_pd(_mm256_sub_pd(v5, v3), neg);

__m256d ret = _mm256_sub_pd(v5, v3);
const __m256i neg = _mm256_set_epi64x(0,0,0x8000000000000000,0);
return __m256d(_mm256_xor_si256(__m256i(ret), neg));
}

#endif // CMS_USE_AVX
Expand Down Expand Up @@ -884,14 +885,14 @@ inline double dot(mathSSE::Vec4D a, mathSSE::Vec4D b) {
inline mathSSE::Vec4D cross(mathSSE::Vec4D a, mathSSE::Vec4D b) __attribute__((always_inline)) __attribute__ ((pure));

inline mathSSE::Vec4D cross(mathSSE::Vec4D a, mathSSE::Vec4D b) {
const __m128d neg = _mm_set_pd ( 0.0 , -0.0 );
const __m128i neg = _mm_set_epi64x( 0, 0x8000000000000000 );
// lh .z * rh .x , lh .z * rh .y
__m128d l1 = _mm_mul_pd ( _mm_unpacklo_pd ( a.vec[1] , a.vec[1] ), b.vec[0] );
// rh .z * lh .x , rh .z * lh .y
__m128d l2 = _mm_mul_pd ( _mm_unpacklo_pd ( b.vec[1], b.vec[1] ), a.vec[0] );
__m128d m1 = _mm_sub_pd ( l1 , l2 ); // l1 - l2
m1 = _mm_shuffle_pd ( m1 , m1 , 1 ); // switch the elements
m1 = _mm_xor_pd ( m1 , neg ); // change the sign of the first element
m1 = __m128d(_mm_xor_si128 ( __m128i(m1) , neg )); // change the sign of the first element
// lh .x * rh .y , lh .y * rh .x
l1 = _mm_mul_pd ( a.vec[0] , _mm_shuffle_pd ( b.vec[0] , b.vec[0] , 1 ) );
// lh .x * rh .y - lh .y * rh .x
Expand Down
3 changes: 3 additions & 0 deletions DataFormats/Math/test/BuildFile.xml
Expand Up @@ -34,6 +34,9 @@
</release>
<bin file="SSEVec_t.cpp" name="DataFormatsSSEVec_t">
</bin>
<bin file="crossV4_t.cpp" name="DataFormatscrossV4_t">
<flags CXXFLAGS="-Ofast"/>
</bin>
<bin file="sign_t.cpp" name="DataFormatsSign_t">
</bin>
<bin file="eta_t.cpp" name="DataFormatsEta_t">
Expand Down
39 changes: 39 additions & 0 deletions DataFormats/Math/test/crossV4_t.cpp
@@ -0,0 +1,39 @@
#include <iostream>
#include "DataFormats/Math/interface/SSEVec.h"

int main() {
{
mathSSE::Vec4<float> yAxis(-0.0144846,0.932024,-0.362108);
mathSSE::Vec4<float> zAxis(-0.204951,0.351689,0.913406);

auto xAxis = ::cross(yAxis,zAxis);

const mathSSE::Vec4<float> correctXAxis(0.978666,0.0874447,0.185925);
std::cout <<" x axis "<<xAxis<<std::endl;
if ( abs(xAxis.o.theX-correctXAxis.o.theX )> 0.000001 or
abs(xAxis.o.theY-correctXAxis.o.theY) > 0.000001 or
abs(xAxis.o.theZ-correctXAxis.o.theZ) > 0.000001) {
std::cout <<"BAD since not same as "<<correctXAxis<<std::endl;
return 1;
}
}
{
mathSSE::Vec4<double> yAxis(-0.0144846,0.932024,-0.362108);
mathSSE::Vec4<double> zAxis(-0.204951,0.351689,0.913406);

auto xAxis = ::cross(yAxis,zAxis);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const mathSSE::Vec4<float> correctXAxis(0.978666,0.0874447,0.185925);
std::cout <<" x axis "<<xAxis<<std::endl;
if ( abs(xAxis.o.theX-correctXAxis.o.theX )> 0.000001 or
abs(xAxis.o.theY-correctXAxis.o.theY) > 0.000001 or
abs(xAxis.o.theZ-correctXAxis.o.theZ) > 0.000001) {
std::cout <<"BAD since not same as "<<correctXAxis<<std::endl;
return 1;
}
}


return 0;
}