2016-01-02 14:51:32 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: ./lib/simd/Grid_sse4.h
|
|
|
|
|
|
|
|
Copyright (C) 2015
|
|
|
|
|
|
|
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
Author: neo <cossu@post.kek.jp>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2015-05-19 09:21:17 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
/*! @file Grid_sse4.h
|
2015-05-20 09:22:40 +01:00
|
|
|
@brief Optimization libraries for SSE4 instructions set
|
|
|
|
|
|
|
|
Using intrinsics
|
2015-05-19 09:21:17 +01:00
|
|
|
*/
|
2015-06-16 15:34:45 +01:00
|
|
|
// Time-stamp: <2015-06-16 23:27:54 neo>
|
2015-05-19 09:21:17 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <pmmintrin.h>
|
|
|
|
|
2017-04-12 19:32:37 +01:00
|
|
|
|
2015-12-16 09:09:37 +00:00
|
|
|
namespace Grid {
|
2015-05-19 09:21:17 +01:00
|
|
|
namespace Optimization {
|
2015-05-27 16:07:17 +01:00
|
|
|
|
|
|
|
template<class vtype>
|
|
|
|
union uconv {
|
|
|
|
__m128 f;
|
|
|
|
vtype v;
|
|
|
|
};
|
|
|
|
|
|
|
|
union u128f {
|
|
|
|
__m128 v;
|
|
|
|
float f[4];
|
|
|
|
};
|
|
|
|
union u128d {
|
|
|
|
__m128d v;
|
|
|
|
double f[2];
|
|
|
|
};
|
2015-05-19 09:21:17 +01:00
|
|
|
|
|
|
|
struct Vsplat{
|
|
|
|
//Complex float
|
|
|
|
inline __m128 operator()(float a, float b){
|
|
|
|
return _mm_set_ps(b,a,b,a);
|
|
|
|
}
|
|
|
|
// Real float
|
|
|
|
inline __m128 operator()(float a){
|
|
|
|
return _mm_set_ps(a,a,a,a);
|
|
|
|
}
|
|
|
|
//Complex double
|
|
|
|
inline __m128d operator()(double a, double b){
|
|
|
|
return _mm_set_pd(b,a);
|
|
|
|
}
|
|
|
|
//Real double
|
|
|
|
inline __m128d operator()(double a){
|
|
|
|
return _mm_set_pd(a,a);
|
|
|
|
}
|
|
|
|
//Integer
|
|
|
|
inline __m128i operator()(Integer a){
|
|
|
|
return _mm_set1_epi32(a);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Vstore{
|
|
|
|
//Float
|
|
|
|
inline void operator()(__m128 a, float* F){
|
|
|
|
_mm_store_ps(F,a);
|
|
|
|
}
|
|
|
|
//Double
|
|
|
|
inline void operator()(__m128d a, double* D){
|
|
|
|
_mm_store_pd(D,a);
|
|
|
|
}
|
|
|
|
//Integer
|
|
|
|
inline void operator()(__m128i a, Integer* I){
|
|
|
|
_mm_store_si128((__m128i *)I,a);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-05-20 09:22:40 +01:00
|
|
|
struct Vstream{
|
|
|
|
//Float
|
2015-05-22 09:33:15 +01:00
|
|
|
inline void operator()(float * a, __m128 b){
|
|
|
|
_mm_stream_ps(a,b);
|
2015-05-20 09:22:40 +01:00
|
|
|
}
|
|
|
|
//Double
|
2015-05-22 09:33:15 +01:00
|
|
|
inline void operator()(double * a, __m128d b){
|
|
|
|
_mm_stream_pd(a,b);
|
2015-05-20 09:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-05-19 09:21:17 +01:00
|
|
|
struct Vset{
|
|
|
|
// Complex float
|
|
|
|
inline __m128 operator()(Grid::ComplexF *a){
|
|
|
|
return _mm_set_ps(a[1].imag(), a[1].real(),a[0].imag(),a[0].real());
|
|
|
|
}
|
|
|
|
// Complex double
|
|
|
|
inline __m128d operator()(Grid::ComplexD *a){
|
|
|
|
return _mm_set_pd(a[0].imag(),a[0].real());
|
|
|
|
}
|
|
|
|
// Real float
|
|
|
|
inline __m128 operator()(float *a){
|
|
|
|
return _mm_set_ps(a[3],a[2],a[1],a[0]);
|
|
|
|
}
|
|
|
|
// Real double
|
|
|
|
inline __m128d operator()(double *a){
|
|
|
|
return _mm_set_pd(a[1],a[0]);
|
|
|
|
}
|
|
|
|
// Integer
|
|
|
|
inline __m128i operator()(Integer *a){
|
2015-06-16 15:34:45 +01:00
|
|
|
return _mm_set_epi32(a[3],a[2],a[1],a[0]);
|
2015-05-19 09:21:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-05-20 09:22:40 +01:00
|
|
|
template <typename Out_type, typename In_type>
|
2015-05-19 09:21:17 +01:00
|
|
|
struct Reduce{
|
2015-05-20 09:22:40 +01:00
|
|
|
//Need templated class to overload output type
|
|
|
|
//General form must generate error if compiled
|
|
|
|
inline Out_type operator()(In_type in){
|
|
|
|
printf("Error, using wrong Reduce function\n");
|
|
|
|
exit(1);
|
|
|
|
return 0;
|
2015-05-19 09:21:17 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
// Arithmetic operations
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
struct Sum{
|
|
|
|
//Complex/Real float
|
|
|
|
inline __m128 operator()(__m128 a, __m128 b){
|
|
|
|
return _mm_add_ps(a,b);
|
|
|
|
}
|
|
|
|
//Complex/Real double
|
|
|
|
inline __m128d operator()(__m128d a, __m128d b){
|
|
|
|
return _mm_add_pd(a,b);
|
|
|
|
}
|
|
|
|
//Integer
|
|
|
|
inline __m128i operator()(__m128i a, __m128i b){
|
|
|
|
return _mm_add_epi32(a,b);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Sub{
|
|
|
|
//Complex/Real float
|
|
|
|
inline __m128 operator()(__m128 a, __m128 b){
|
|
|
|
return _mm_sub_ps(a,b);
|
|
|
|
}
|
|
|
|
//Complex/Real double
|
|
|
|
inline __m128d operator()(__m128d a, __m128d b){
|
|
|
|
return _mm_sub_pd(a,b);
|
|
|
|
}
|
|
|
|
//Integer
|
|
|
|
inline __m128i operator()(__m128i a, __m128i b){
|
|
|
|
return _mm_sub_epi32(a,b);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-08 16:43:28 +00:00
|
|
|
struct MultRealPart{
|
|
|
|
inline __m128 operator()(__m128 a, __m128 b){
|
|
|
|
__m128 ymm0;
|
|
|
|
ymm0 = _mm_shuffle_ps(a,a,_MM_SELECT_FOUR_FOUR(2,2,0,0)); // ymm0 <- ar ar,
|
|
|
|
return _mm_mul_ps(ymm0,b); // ymm0 <- ar bi, ar br
|
|
|
|
}
|
|
|
|
inline __m128d operator()(__m128d a, __m128d b){
|
|
|
|
__m128d ymm0;
|
|
|
|
ymm0 = _mm_shuffle_pd(a,a,0x0); // ymm0 <- ar ar, ar,ar b'00,00
|
|
|
|
return _mm_mul_pd(ymm0,b); // ymm0 <- ar bi, ar br
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct MaddRealPart{
|
|
|
|
inline __m128 operator()(__m128 a, __m128 b, __m128 c){
|
|
|
|
__m128 ymm0 = _mm_shuffle_ps(a,a,_MM_SELECT_FOUR_FOUR(2,2,0,0)); // ymm0 <- ar ar,
|
2016-12-18 02:09:37 +00:00
|
|
|
return _mm_add_ps(_mm_mul_ps( ymm0, b),c);
|
2016-12-08 16:43:28 +00:00
|
|
|
}
|
2016-12-18 02:07:45 +00:00
|
|
|
inline __m128d operator()(__m128d a, __m128d b, __m128d c){
|
2016-12-08 16:43:28 +00:00
|
|
|
__m128d ymm0 = _mm_shuffle_pd( a, a, 0x0 );
|
|
|
|
return _mm_add_pd(_mm_mul_pd( ymm0, b),c);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-19 09:21:17 +01:00
|
|
|
struct MultComplex{
|
|
|
|
// Complex float
|
|
|
|
inline __m128 operator()(__m128 a, __m128 b){
|
|
|
|
__m128 ymm0,ymm1,ymm2;
|
2015-09-25 16:55:04 +01:00
|
|
|
ymm0 = _mm_shuffle_ps(a,a,_MM_SELECT_FOUR_FOUR(2,2,0,0)); // ymm0 <- ar ar,
|
2015-05-20 09:22:40 +01:00
|
|
|
ymm0 = _mm_mul_ps(ymm0,b); // ymm0 <- ar bi, ar br
|
2015-09-25 16:55:04 +01:00
|
|
|
ymm1 = _mm_shuffle_ps(b,b,_MM_SELECT_FOUR_FOUR(2,3,0,1)); // ymm1 <- br,bi
|
|
|
|
ymm2 = _mm_shuffle_ps(a,a,_MM_SELECT_FOUR_FOUR(3,3,1,1)); // ymm2 <- ai,ai
|
2015-05-20 09:22:40 +01:00
|
|
|
ymm1 = _mm_mul_ps(ymm1,ymm2); // ymm1 <- br ai, ai bi
|
2015-05-19 09:21:17 +01:00
|
|
|
return _mm_addsub_ps(ymm0,ymm1);
|
|
|
|
}
|
|
|
|
// Complex double
|
|
|
|
inline __m128d operator()(__m128d a, __m128d b){
|
|
|
|
__m128d ymm0,ymm1,ymm2;
|
2015-05-20 09:22:40 +01:00
|
|
|
ymm0 = _mm_shuffle_pd(a,a,0x0); // ymm0 <- ar ar,
|
2015-05-19 09:21:17 +01:00
|
|
|
ymm0 = _mm_mul_pd(ymm0,b); // ymm0 <- ar bi, ar br
|
2015-05-20 09:22:40 +01:00
|
|
|
ymm1 = _mm_shuffle_pd(b,b,0x1); // ymm1 <- br,bi b01
|
|
|
|
ymm2 = _mm_shuffle_pd(a,a,0x3); // ymm2 <- ai,ai b11
|
|
|
|
ymm1 = _mm_mul_pd(ymm1,ymm2); // ymm1 <- br ai, ai bi
|
2015-05-19 09:21:17 +01:00
|
|
|
return _mm_addsub_pd(ymm0,ymm1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Mult{
|
2015-10-08 23:38:52 +01:00
|
|
|
|
|
|
|
inline void mac(__m128 &a, __m128 b, __m128 c){
|
2015-12-16 09:09:37 +00:00
|
|
|
a= _mm_add_ps(_mm_mul_ps(b,c),a);
|
2015-10-08 23:38:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void mac(__m128d &a, __m128d b, __m128d c){
|
2015-12-16 09:09:37 +00:00
|
|
|
a= _mm_add_pd(_mm_mul_pd(b,c),a);
|
2015-10-08 23:38:52 +01:00
|
|
|
}
|
|
|
|
|
2015-05-19 09:21:17 +01:00
|
|
|
// Real float
|
|
|
|
inline __m128 operator()(__m128 a, __m128 b){
|
|
|
|
return _mm_mul_ps(a,b);
|
|
|
|
}
|
|
|
|
// Real double
|
|
|
|
inline __m128d operator()(__m128d a, __m128d b){
|
|
|
|
return _mm_mul_pd(a,b);
|
|
|
|
}
|
|
|
|
// Integer
|
|
|
|
inline __m128i operator()(__m128i a, __m128i b){
|
2015-06-16 15:34:45 +01:00
|
|
|
return _mm_mullo_epi32(a,b);
|
2015-05-19 09:21:17 +01:00
|
|
|
}
|
2015-05-20 09:22:40 +01:00
|
|
|
};
|
2015-05-19 09:21:17 +01:00
|
|
|
|
2016-09-26 09:42:22 +01:00
|
|
|
struct Div{
|
|
|
|
// Real float
|
|
|
|
inline __m128 operator()(__m128 a, __m128 b){
|
|
|
|
return _mm_div_ps(a,b);
|
|
|
|
}
|
|
|
|
// Real double
|
|
|
|
inline __m128d operator()(__m128d a, __m128d b){
|
|
|
|
return _mm_div_pd(a,b);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-20 09:22:40 +01:00
|
|
|
struct Conj{
|
|
|
|
// Complex single
|
|
|
|
inline __m128 operator()(__m128 in){
|
|
|
|
return _mm_xor_ps(_mm_addsub_ps(_mm_setzero_ps(),in), _mm_set1_ps(-0.f));
|
|
|
|
}
|
|
|
|
// Complex double
|
|
|
|
inline __m128d operator()(__m128d in){
|
|
|
|
return _mm_xor_pd(_mm_addsub_pd(_mm_setzero_pd(),in), _mm_set1_pd(-0.f));//untested
|
|
|
|
}
|
|
|
|
// do not define for integer input
|
2015-05-19 09:21:17 +01:00
|
|
|
};
|
|
|
|
|
2015-05-20 09:22:40 +01:00
|
|
|
struct TimesMinusI{
|
|
|
|
//Complex single
|
|
|
|
inline __m128 operator()(__m128 in, __m128 ret){
|
|
|
|
__m128 tmp =_mm_addsub_ps(_mm_setzero_ps(),in); // r,-i
|
2015-09-25 16:55:04 +01:00
|
|
|
return _mm_shuffle_ps(tmp,tmp,_MM_SELECT_FOUR_FOUR(2,3,0,1));
|
2015-05-20 09:22:40 +01:00
|
|
|
}
|
|
|
|
//Complex double
|
|
|
|
inline __m128d operator()(__m128d in, __m128d ret){
|
|
|
|
__m128d tmp =_mm_addsub_pd(_mm_setzero_pd(),in); // r,-i
|
|
|
|
return _mm_shuffle_pd(tmp,tmp,0x1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TimesI{
|
|
|
|
//Complex single
|
|
|
|
inline __m128 operator()(__m128 in, __m128 ret){
|
2015-09-25 16:55:04 +01:00
|
|
|
__m128 tmp =_mm_shuffle_ps(in,in,_MM_SELECT_FOUR_FOUR(2,3,0,1));
|
2015-05-20 09:22:40 +01:00
|
|
|
return _mm_addsub_ps(_mm_setzero_ps(),tmp); // r,-i
|
|
|
|
}
|
|
|
|
//Complex double
|
|
|
|
inline __m128d operator()(__m128d in, __m128d ret){
|
|
|
|
__m128d tmp = _mm_shuffle_pd(in,in,0x1);
|
|
|
|
return _mm_addsub_pd(_mm_setzero_pd(),tmp); // r,-i
|
|
|
|
}
|
|
|
|
};
|
2015-05-19 09:21:17 +01:00
|
|
|
|
2015-09-25 16:55:04 +01:00
|
|
|
struct Permute{
|
|
|
|
|
|
|
|
static inline __m128 Permute0(__m128 in){
|
2016-04-15 18:17:42 +01:00
|
|
|
return _mm_shuffle_ps(in,in,_MM_SELECT_FOUR_FOUR(1,0,3,2)); //AB CD -> CD AB
|
2015-09-25 16:55:04 +01:00
|
|
|
};
|
|
|
|
static inline __m128 Permute1(__m128 in){
|
2016-04-15 18:17:42 +01:00
|
|
|
return _mm_shuffle_ps(in,in,_MM_SELECT_FOUR_FOUR(2,3,0,1)); //AB CD -> BA DC
|
2015-09-25 16:55:04 +01:00
|
|
|
};
|
|
|
|
static inline __m128 Permute2(__m128 in){
|
|
|
|
return in;
|
|
|
|
};
|
|
|
|
static inline __m128 Permute3(__m128 in){
|
|
|
|
return in;
|
|
|
|
};
|
|
|
|
|
2016-04-15 18:17:42 +01:00
|
|
|
static inline __m128d Permute0(__m128d in){ //AB -> BA
|
2015-09-25 16:55:04 +01:00
|
|
|
return _mm_shuffle_pd(in,in,0x1);
|
|
|
|
};
|
|
|
|
static inline __m128d Permute1(__m128d in){
|
|
|
|
return in;
|
|
|
|
};
|
|
|
|
static inline __m128d Permute2(__m128d in){
|
|
|
|
return in;
|
|
|
|
};
|
|
|
|
static inline __m128d Permute3(__m128d in){
|
|
|
|
return in;
|
|
|
|
};
|
2017-02-15 11:11:04 +00:00
|
|
|
};
|
|
|
|
|
2017-04-12 19:32:37 +01:00
|
|
|
|
|
|
|
#ifndef _mm_alignr_epi64
|
|
|
|
#define _mm_alignr_epi32(a,b,n) _mm_alignr_epi8(a,b,(n*4)%16)
|
|
|
|
#define _mm_alignr_epi64(a,b,n) _mm_alignr_epi8(a,b,(n*8)%16)
|
|
|
|
#endif
|
|
|
|
struct PrecisionChange {
|
|
|
|
static inline __m128i StoH (__m128 a,__m128 b) {
|
|
|
|
__m128i ha = _mm_cvtps_ph(a,0);
|
|
|
|
__m128i hb = _mm_cvtps_ph(b,0);
|
|
|
|
__m128i h =(__m128i) _mm_shuffle_ps((__m128)ha,(__m128)hb,_MM_SELECT_FOUR_FOUR(1,0,1,0));
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
static inline void HtoS (__m128i h,__m128 &sa,__m128 &sb) {
|
|
|
|
sa = _mm_cvtph_ps(h);
|
|
|
|
h = (__m128)_mm_alignr_epi32((__m128i)h,(__m128i)h,2);
|
|
|
|
sb = _mm_cvtph_ps(h);
|
|
|
|
}
|
|
|
|
static inline __m128 DtoS (__m128d a,__m128d b) {
|
|
|
|
__m128 sa = _mm_cvtpd_ps(a);
|
|
|
|
__m128 sb = _mm_cvtpd_ps(b);
|
|
|
|
__m128 s = _mm_shuffle_ps(sa,sb,_MM_SELECT_FOUR_FOUR(1,0,1,0));
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
static inline void StoD (__m128 s,__m128d &a,__m128d &b) {
|
|
|
|
a = _mm_cvtps_pd(s);
|
|
|
|
s = (__m128)_mm_alignr_epi32((__m128i)s,(__m128i)s,2);
|
|
|
|
b = _mm_cvtps_pd(s);
|
|
|
|
}
|
2017-04-13 08:38:12 +01:00
|
|
|
static inline __m128i DtoH (__m128d a,__m128d b,__m128d c,__m128d d) {
|
2017-04-12 19:32:37 +01:00
|
|
|
__m128 sa,sb;
|
|
|
|
sa = DtoS(a,b);
|
|
|
|
sb = DtoS(c,d);
|
|
|
|
return StoH(sa,sb);
|
|
|
|
}
|
|
|
|
static inline void HtoD (__m128i h,__m128d &a,__m128d &b,__m128d &c,__m128d &d) {
|
|
|
|
__m128 sa,sb;
|
|
|
|
HtoS(h,sa,sb);
|
|
|
|
StoD(sa,a,b);
|
|
|
|
StoD(sb,c,d);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-15 11:11:04 +00:00
|
|
|
struct Exchange{
|
|
|
|
// 3210 ordering
|
|
|
|
static inline void Exchange0(__m128 &out1,__m128 &out2,__m128 in1,__m128 in2){
|
|
|
|
out1= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(1,0,1,0));
|
|
|
|
out2= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(3,2,3,2));
|
|
|
|
};
|
|
|
|
static inline void Exchange1(__m128 &out1,__m128 &out2,__m128 in1,__m128 in2){
|
2017-04-12 19:32:37 +01:00
|
|
|
out1= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(2,0,2,0)); /*ACEG*/
|
|
|
|
out2= _mm_shuffle_ps(in1,in2,_MM_SELECT_FOUR_FOUR(3,1,3,1)); /*BDFH*/
|
|
|
|
out1= _mm_shuffle_ps(out1,out1,_MM_SELECT_FOUR_FOUR(3,1,2,0)); /*AECG*/
|
|
|
|
out2= _mm_shuffle_ps(out2,out2,_MM_SELECT_FOUR_FOUR(3,1,2,0)); /*AECG*/
|
2017-02-15 11:11:04 +00:00
|
|
|
};
|
|
|
|
static inline void Exchange2(__m128 &out1,__m128 &out2,__m128 in1,__m128 in2){
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
static inline void Exchange3(__m128 &out1,__m128 &out2,__m128 in1,__m128 in2){
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
};
|
2015-09-25 16:55:04 +01:00
|
|
|
|
2017-02-15 11:11:04 +00:00
|
|
|
static inline void Exchange0(__m128d &out1,__m128d &out2,__m128d in1,__m128d in2){
|
|
|
|
out1= _mm_shuffle_pd(in1,in2,0x0);
|
|
|
|
out2= _mm_shuffle_pd(in1,in2,0x3);
|
|
|
|
};
|
|
|
|
static inline void Exchange1(__m128d &out1,__m128d &out2,__m128d in1,__m128d in2){
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
static inline void Exchange2(__m128d &out1,__m128d &out2,__m128d in1,__m128d in2){
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
static inline void Exchange3(__m128d &out1,__m128d &out2,__m128d in1,__m128d in2){
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
};
|
2015-09-25 16:55:04 +01:00
|
|
|
};
|
|
|
|
|
2016-04-19 22:24:18 +01:00
|
|
|
struct Rotate{
|
|
|
|
|
|
|
|
static inline __m128 rotate(__m128 in,int n){
|
|
|
|
switch(n){
|
|
|
|
case 0: return tRotate<0>(in);break;
|
|
|
|
case 1: return tRotate<1>(in);break;
|
|
|
|
case 2: return tRotate<2>(in);break;
|
|
|
|
case 3: return tRotate<3>(in);break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static inline __m128d rotate(__m128d in,int n){
|
|
|
|
switch(n){
|
|
|
|
case 0: return tRotate<0>(in);break;
|
|
|
|
case 1: return tRotate<1>(in);break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
|
|
|
}
|
2016-12-18 02:14:17 +00:00
|
|
|
|
2016-04-22 18:30:30 +01:00
|
|
|
template<int n> static inline __m128 tRotate(__m128 in){ return (__m128)_mm_alignr_epi32((__m128i)in,(__m128i)in,n); };
|
|
|
|
template<int n> static inline __m128d tRotate(__m128d in){ return (__m128d)_mm_alignr_epi64((__m128i)in,(__m128i)in,n); };
|
2016-04-19 22:24:18 +01:00
|
|
|
|
|
|
|
};
|
2015-05-20 09:22:40 +01:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Some Template specialization
|
2015-09-25 16:55:04 +01:00
|
|
|
|
2015-05-27 16:07:17 +01:00
|
|
|
|
2015-05-20 09:22:40 +01:00
|
|
|
//Complex float Reduce
|
|
|
|
template<>
|
|
|
|
inline Grid::ComplexF Reduce<Grid::ComplexF, __m128>::operator()(__m128 in){
|
2015-05-27 16:07:17 +01:00
|
|
|
__m128 v1; // two complex
|
2015-09-25 16:55:04 +01:00
|
|
|
v1= Optimization::Permute::Permute0(in);
|
2015-05-27 16:07:17 +01:00
|
|
|
v1= _mm_add_ps(v1,in);
|
|
|
|
u128f conv; conv.v=v1;
|
|
|
|
return Grid::ComplexF(conv.f[0],conv.f[1]);
|
2015-05-20 09:22:40 +01:00
|
|
|
}
|
|
|
|
//Real float Reduce
|
|
|
|
template<>
|
|
|
|
inline Grid::RealF Reduce<Grid::RealF, __m128>::operator()(__m128 in){
|
2015-05-27 16:07:17 +01:00
|
|
|
__m128 v1,v2; // quad single
|
2015-09-25 16:55:04 +01:00
|
|
|
v1= Optimization::Permute::Permute0(in);
|
2015-05-27 16:07:17 +01:00
|
|
|
v1= _mm_add_ps(v1,in);
|
2015-09-25 16:55:04 +01:00
|
|
|
v2= Optimization::Permute::Permute1(v1);
|
2015-05-27 16:07:17 +01:00
|
|
|
v1 = _mm_add_ps(v1,v2);
|
|
|
|
u128f conv; conv.v=v1;
|
|
|
|
return conv.f[0];
|
2015-05-20 09:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Complex double Reduce
|
|
|
|
template<>
|
|
|
|
inline Grid::ComplexD Reduce<Grid::ComplexD, __m128d>::operator()(__m128d in){
|
2015-05-27 16:07:17 +01:00
|
|
|
u128d conv; conv.v = in;
|
|
|
|
return Grid::ComplexD(conv.f[0],conv.f[1]);
|
2015-05-20 09:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Real double Reduce
|
|
|
|
template<>
|
|
|
|
inline Grid::RealD Reduce<Grid::RealD, __m128d>::operator()(__m128d in){
|
2015-05-27 16:07:17 +01:00
|
|
|
__m128d v1;
|
2015-09-25 16:55:04 +01:00
|
|
|
v1 = Optimization::Permute::Permute0(in);
|
2015-05-27 16:07:17 +01:00
|
|
|
v1 = _mm_add_pd(v1,in);
|
|
|
|
u128d conv; conv.v = v1;
|
|
|
|
return conv.f[0];
|
2015-05-20 09:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Integer Reduce
|
|
|
|
template<>
|
|
|
|
inline Integer Reduce<Integer, __m128i>::operator()(__m128i in){
|
|
|
|
// FIXME unimplemented
|
|
|
|
printf("Reduce : Missing integer implementation -> FIX\n");
|
|
|
|
assert(0);
|
|
|
|
}
|
2015-05-19 09:21:17 +01:00
|
|
|
}
|
|
|
|
|
2016-09-26 09:42:22 +01:00
|
|
|
|
|
|
|
|
2015-05-20 09:22:40 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
2015-05-19 09:21:17 +01:00
|
|
|
// Here assign types
|
2015-05-25 13:47:12 +01:00
|
|
|
|
2017-04-12 19:32:37 +01:00
|
|
|
typedef __m128i SIMD_Htype; // Single precision type
|
|
|
|
typedef __m128 SIMD_Ftype; // Single precision type
|
2015-05-19 09:21:17 +01:00
|
|
|
typedef __m128d SIMD_Dtype; // Double precision type
|
|
|
|
typedef __m128i SIMD_Itype; // Integer type
|
|
|
|
|
2015-06-09 07:46:21 +01:00
|
|
|
// prefetch utilities
|
|
|
|
inline void v_prefetch0(int size, const char *ptr){};
|
|
|
|
inline void prefetch_HINT_T0(const char *ptr){
|
|
|
|
_mm_prefetch(ptr,_MM_HINT_T0);
|
|
|
|
}
|
2015-05-27 04:11:44 +01:00
|
|
|
|
2015-05-20 09:22:40 +01:00
|
|
|
// Function name aliases
|
|
|
|
typedef Optimization::Vsplat VsplatSIMD;
|
|
|
|
typedef Optimization::Vstore VstoreSIMD;
|
|
|
|
typedef Optimization::Vset VsetSIMD;
|
|
|
|
typedef Optimization::Vstream VstreamSIMD;
|
|
|
|
template <typename S, typename T> using ReduceSIMD = Optimization::Reduce<S,T>;
|
|
|
|
|
2015-05-27 04:11:44 +01:00
|
|
|
|
|
|
|
|
2015-05-19 09:21:17 +01:00
|
|
|
|
|
|
|
// Arithmetic operations
|
|
|
|
typedef Optimization::Sum SumSIMD;
|
|
|
|
typedef Optimization::Sub SubSIMD;
|
2016-09-26 09:42:22 +01:00
|
|
|
typedef Optimization::Div DivSIMD;
|
2015-05-19 09:21:17 +01:00
|
|
|
typedef Optimization::Mult MultSIMD;
|
|
|
|
typedef Optimization::MultComplex MultComplexSIMD;
|
2016-12-08 16:43:28 +00:00
|
|
|
typedef Optimization::MultRealPart MultRealPartSIMD;
|
|
|
|
typedef Optimization::MaddRealPart MaddRealPartSIMD;
|
2015-05-20 09:22:40 +01:00
|
|
|
typedef Optimization::Conj ConjSIMD;
|
|
|
|
typedef Optimization::TimesMinusI TimesMinusISIMD;
|
|
|
|
typedef Optimization::TimesI TimesISIMD;
|
2015-05-19 09:21:17 +01:00
|
|
|
|
|
|
|
}
|