1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This file is part of GROMACS.
7 * Written by the Gromacs development team under coordination of
8 * David van der Spoel, Berk Hess, and Erik Lindahl.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * To help us fund GROMACS development, we humbly ask that you cite
16 * the research papers on the package. Check out http://www.gromacs.org
19 * Gnomes, ROck Monsters And Chili Sauce
21 #ifndef _gmx_x86_sse2_h_
22 #define _gmx_x86_sse2_h_
24 #include <emmintrin.h>
28 #include "types/simple.h"
32 /* Create some basic definitions that are not 100% SSE2 standard and thus not
33 * available on all compilers. These should be fairly self-evident by comparing
34 * with an arbitrary emmintrin.h.
37 #define gmx_mm_extract_epi32(x, imm) _mm_cvtsi128_si32(_mm_srli_si128((x), 4 * (imm)))
39 #define GMX_MM_TRANSPOSE2_PD(row0, row1) { \
40 __m128d __gmx_t1 = row0; \
41 row0 = _mm_unpacklo_pd(row0,row1); \
42 row1 = _mm_unpackhi_pd(__gmx_t1,row1); \
46 #if (defined (_MSC_VER) || defined(__INTEL_COMPILER))
47 # define gmx_mm_castsi128_ps(a) _mm_castsi128_ps(a)
48 # define gmx_mm_castps_si128(a) _mm_castps_si128(a)
49 # define gmx_mm_castps_ps128(a) (a)
50 # define gmx_mm_castsi128_pd(a) _mm_castsi128_pd(a)
51 # define gmx_mm_castpd_si128(a) _mm_castpd_si128(a)
52 #elif defined(__GNUC__)
53 # define gmx_mm_castsi128_ps(a) ((__m128)(a))
54 # define gmx_mm_castps_si128(a) ((__m128i)(a))
55 # define gmx_mm_castps_ps128(a) ((__m128)(a))
56 # define gmx_mm_castsi128_pd(a) ((__m128d)(a))
57 # define gmx_mm_castpd_si128(a) ((__m128i)(a))
59 static __m128
gmx_mm_castsi128_ps(__m128i a
)
61 return *(__m128
*) &a
;
63 static __m128i
gmx_mm_castps_si128(__m128 a
)
65 return *(__m128i
*) &a
;
67 static __m128
gmx_mm_castps_ps128(__m128 a
)
69 return *(__m128
*) &a
;
71 static __m128d
gmx_mm_castsi128_pd(__m128i a
)
73 return *(__m128d
*) &a
;
75 static __m128i
gmx_mm_castpd_si128(__m128d a
)
77 return *(__m128i
*) &a
;
83 gmx_mm_printxmm_ps(const char *s
,__m128 xmm
)
88 printf("%s: %15.10e %15.10e %15.10e %15.10e\n",s
,f
[0],f
[1],f
[2],f
[3]);
93 gmx_mm_printxmmsum_ps(const char *s
,__m128 xmm
)
98 printf("%s (sum): %15.10g\n",s
,f
[0]+f
[1]+f
[2]+f
[3]);
103 gmx_mm_printxmm_pd(const char *s
,__m128d xmm
)
107 _mm_storeu_pd(f
,xmm
);
108 printf("%s: %30.20e %30.20e\n",s
,f
[0],f
[1]);
112 gmx_mm_printxmmsum_pd(const char *s
,__m128d xmm
)
116 _mm_storeu_pd(f
,xmm
);
117 printf("%s (sum): %15.10g\n",s
,f
[0]+f
[1]);
122 gmx_mm_printxmm_epi32(const char *s
,__m128i xmmi
)
126 _mm_storeu_si128((__m128i
*)i
,xmmi
);
127 printf("%10s: %2d %2d %2d %2d\n",s
,i
[0],i
[1],i
[2],i
[3]);
132 static int gmx_mm_check_and_reset_overflow(void)
137 MXCSR
= _mm_getcsr();
138 /* The overflow flag is bit 3 in the register */
142 /* Set the overflow flag to zero */
143 MXCSR
= MXCSR
& 0xFFF7;
155 #endif /* _gmx_x86_sse2_h_ */