Commit 92bfbd49 authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

Fix stack-overflow in kernels

The were a couple of places where a load of a stack variable was too
wide. Detected with the

  -fsanitize=address

flag of GCC, that we should probably incorporate into our CI tests.
parent c8b105a7
......@@ -72,8 +72,6 @@
#define offset 4
#define __AVX_DATATYPE __m256d
#define _AVX_LOAD _mm256_load_pd
#define _AVX_LOADU _mm_loadu_pd
#define _AVX_STOREU _mm_storeu_pd
#define _AVX_STORE _mm256_store_pd
#define _AVX_ADD _mm256_add_pd
#define _AVX_MUL _mm256_mul_pd
......@@ -108,8 +106,6 @@
#define offset 8
#define __AVX_DATATYPE __m256
#define _AVX_LOAD _mm256_load_ps
#define _AVX_LOADU _mm_loadu_ps
#define _AVX_STOREU _mm_storeu_ps
#define _AVX_STORE _mm256_store_ps
#define _AVX_ADD _mm256_add_ps
#define _AVX_MUL _mm256_mul_ps
......@@ -503,12 +499,11 @@ static __forceinline void hh_trafo_complex_kernel_16_AVX_2hv_single(float comple
h2_imag = _AVX_XOR(h2_imag, sign);
#ifdef DOUBLE_PRECISION_COMPLEX
__m128d tmp_s_128 = _AVX_LOADU(s_dbl);
tmp2 = _mm256_broadcast_pd(&tmp_s_128);
tmp2 = _mm256_set_pd(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
#ifdef SINGLE_PRECISION_COMPLEX
__m128 tmp_s_128 = _AVX_LOADU(s_dbl);
tmp2 = _mm256_broadcast_ps(&tmp_s_128);
tmp2 = _mm256_set_ps(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0],
s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
tmp1 = _AVX_MUL(h2_imag, tmp2);
......@@ -518,9 +513,8 @@ static __forceinline void hh_trafo_complex_kernel_16_AVX_2hv_single(float comple
tmp2 = _AVX_ADDSUB( _AVX_MUL(h2_real, tmp2), _AVX_SHUFFLE(tmp1, tmp1, _SHUFFLE));
#endif
_AVX_STOREU(s_dbl, _CAST(tmp2));
h2_real = _AVX_SET1(s_dbl[0]);
h2_imag = _AVX_SET1(s_dbl[1]);
h2_real = _AVX_SET1(tmp2[0]);
h2_imag = _AVX_SET1(tmp2[1]);
tmp1 = _AVX_MUL(h1_imag, y1);
#ifdef __ELPA_USE_FMA__
......@@ -934,23 +928,21 @@ static __forceinline void hh_trafo_complex_kernel_12_AVX_2hv_single(float comple
h2_imag = _AVX_XOR(h2_imag, sign);
#ifdef DOUBLE_PRECISION_COMPLEX
__m128d tmp_s_128 = _AVX_LOADU(s_dbl);
tmp2 = _mm256_broadcast_pd(&tmp_s_128);
tmp2 = _mm256_set_pd(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
#ifdef SINGLE_PRECISION_COMPLEX
__m128 tmp_s_128 = _AVX_LOADU(s_dbl);
tmp2 = _mm256_broadcast_ps(&tmp_s_128);
tmp2 = _mm256_set_ps(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0],
s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
tmp1 = _AVX_MUL(h2_imag, tmp2);
#ifdef __ELPA_USE_FMA__
tmp2 = _AVX_FMADDSUB(h2_real, tmp2, _AVX_SHUFFLE(tmp1, tmp1, _SHUFFLE));
#else
tmp2 = _AVX_ADDSUB( _AVX_MUL(h2_real, tmp2), _AVX_SHUFFLE(tmp1, tmp1, _SHUFFLE));
#endif
_AVX_STOREU(s_dbl, _CAST(tmp2));
h2_real = _AVX_SET1(s_dbl[0]);
h2_imag = _AVX_SET1(s_dbl[1]);
h2_real = _AVX_SET1(tmp2[0]);
h2_imag = _AVX_SET1(tmp2[1]);
tmp1 = _AVX_MUL(h1_imag, y1);
#ifdef __ELPA_USE_FMA__
......@@ -1283,12 +1275,11 @@ static __forceinline void hh_trafo_complex_kernel_8_AVX_2hv_single(float complex
h2_imag = _AVX_XOR(h2_imag, sign);
#ifdef DOUBLE_PRECISION_COMPLEX
__m128d tmp_s_128 = _AVX_LOADU(s_dbl);
tmp2 = _mm256_broadcast_pd(&tmp_s_128);
tmp2 = _mm256_set_pd(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
#ifdef SINGLE_PRECISION_COMPLEX
__m128 tmp_s_128 = _AVX_LOADU(s_dbl);
tmp2 = _mm256_broadcast_ps(&tmp_s_128);
tmp2 = _mm256_set_ps(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0],
s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
tmp1 = _AVX_MUL(h2_imag, tmp2);
......@@ -1297,9 +1288,8 @@ static __forceinline void hh_trafo_complex_kernel_8_AVX_2hv_single(float complex
#else
tmp2 = _AVX_ADDSUB( _AVX_MUL(h2_real, tmp2), _AVX_SHUFFLE(tmp1, tmp1, _SHUFFLE));
#endif
_AVX_STOREU(s_dbl, _CAST(tmp2));
h2_real = _AVX_SET1(s_dbl[0]);
h2_imag = _AVX_SET1(s_dbl[1]);
h2_real = _AVX_SET1(tmp2[0]);
h2_imag = _AVX_SET1(tmp2[1]);
tmp1 = _AVX_MUL(h1_imag, y1);
#ifdef __ELPA_USE_FMA__
......@@ -1547,13 +1537,13 @@ static __forceinline void hh_trafo_complex_kernel_4_AVX_2hv_single(float complex
h2_real = _AVX_XOR(h2_real, sign);
h2_imag = _AVX_XOR(h2_imag, sign);
__AVX_DATATYPE tmp2;
#ifdef DOUBLE_PRECISION_COMPLEX
__m128d tmp_s_128 = _AVX_LOADU(s_dbl);
__AVX_DATATYPE tmp2 = _mm256_broadcast_pd(&tmp_s_128);
tmp2 = _mm256_set_pd(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
#ifdef SINGLE_PRECISION_COMPLEX
__m128 tmp_s_128 = _AVX_LOADU(s_dbl);
__AVX_DATATYPE tmp2 = _mm256_broadcast_ps(&tmp_s_128);
tmp2 = _mm256_set_ps(s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0],
s_dbl[1], s_dbl[0], s_dbl[1], s_dbl[0]);
#endif
tmp1 = _AVX_MUL(h2_imag, tmp2);
#ifdef __ELPA_USE_FMA__
......@@ -1561,9 +1551,8 @@ static __forceinline void hh_trafo_complex_kernel_4_AVX_2hv_single(float complex
#else
tmp2 = _AVX_ADDSUB( _AVX_MUL(h2_real, tmp2), _AVX_SHUFFLE(tmp1, tmp1, _SHUFFLE));
#endif
_AVX_STOREU(s_dbl, _CAST(tmp2));
h2_real = _AVX_SET1(s_dbl[0]);
h2_imag = _AVX_SET1(s_dbl[1]);
h2_real = _AVX_SET1(tmp2[0]);
h2_imag = _AVX_SET1(tmp2[1]);
tmp1 = _AVX_MUL(h1_imag, y1);
#ifdef __ELPA_USE_FMA__
......
......@@ -63,6 +63,7 @@
#include <complex.h>
#include <x86intrin.h>
#include <pmmintrin.h>
#define __forceinline __attribute__((always_inline))
......@@ -475,7 +476,11 @@ static __forceinline void hh_trafo_complex_kernel_4_SSE_2hv_single(float complex
h2_real = _SSE_XOR(h2_real, sign);
h2_imag = _SSE_XOR(h2_imag, sign);
#ifdef SINGLE_PRECISION_COMPLEX
tmp2 = _mm_castpd_ps(_mm_load_pd1((double *) s_dbl));
#else
tmp2 = _SSE_LOADU(s_dbl);
#endif
tmp1 = _SSE_MUL(h2_imag, tmp2);
#ifdef __ELPA_USE_FMA__
......@@ -484,20 +489,13 @@ static __forceinline void hh_trafo_complex_kernel_4_SSE_2hv_single(float complex
tmp2 = _SSE_ADDSUB( _SSE_MUL(h2_real, tmp2), _SSE_SHUFFLE(tmp1, tmp1, _SHUFFLE));
#endif
_SSE_STOREU(s_dbl, tmp2);
#ifdef DOUBLE_PRECISION_COMPLEX
h2_real = _mm_set1_pd(s_dbl[0]);
h2_imag = _mm_set1_pd(s_dbl[1]);
// h2_real = _mm_loaddup_pd(&s_dbl[0]);
// h2_imag = _mm_loaddup_pd(&s_dbl[1]);
h2_real = _mm_movedup_pd(tmp2);
h2_imag = _mm_set1_pd(tmp2[1]);
#endif
#ifdef SINGLE_PRECISION_COMPLEX
h2_real = _mm_set1_ps(s_dbl[0]);
h2_imag = _mm_set1_ps(s_dbl[1]);
// h2_real = _mm_moveldup_ps(_mm_castpd_ps(_mm_loaddup_pd( (double *)(&s_dbl[0]) )));
// h2_imag = _mm_moveldup_ps(_mm_castpd_ps(_mm_loaddup_pd( (double *)(&s_dbl[1]) )));
h2_real = _mm_moveldup_ps(tmp2);
h2_imag = _mm_movehdup_ps(tmp2);
#endif
tmp1 = _SSE_MUL(h1_imag, y1);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment