added Verlet scheme and NxN non-bonded functionality
[gromacs.git] / include / gmx_x86_avx_128_fma.h
blob821924db56f1df9765f91c57502cb1f7b1d9f429
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
3 *
4 * This file is part of GROMACS.
5 * Copyright (c) 2012-
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
18 * And Hey:
19 * Gnomes, ROck Monsters And Chili Sauce
21 #ifndef _gmx_x86_avx_128_fma_h_
22 #define _gmx_x86_avx_128_fma_h_
25 #include <immintrin.h>
26 #ifdef HAVE_X86INTRIN_H
27 #include <x86intrin.h> /* FMA */
28 #endif
30 #include <stdio.h>
32 #include "types/simple.h"
35 #define gmx_mm_extract_epi32(x, imm) _mm_cvtsi128_si32(_mm_srli_si128((x), 4 * (imm)))
38 #define _GMX_MM_PERMUTE128D(fp1,fp0) (((fp1) << 1) | ((fp0)))
41 #define GMX_MM_TRANSPOSE2_PD(row0, row1) { \
42 __m128d __gmx_t1 = row0; \
43 row0 = _mm_unpacklo_pd(row0,row1); \
44 row1 = _mm_unpackhi_pd(__gmx_t1,row1); \
48 #if (defined (_MSC_VER) || defined(__INTEL_COMPILER))
49 # define gmx_mm_castsi128_ps(a) _mm_castsi128_ps(a)
50 # define gmx_mm_castps_si128(a) _mm_castps_si128(a)
51 # define gmx_mm_castps_ps128(a) (a)
52 # define gmx_mm_castsi128_pd(a) _mm_castsi128_pd(a)
53 # define gmx_mm_castpd_si128(a) _mm_castpd_si128(a)
54 #elif defined(__GNUC__)
55 # define gmx_mm_castsi128_ps(a) ((__m128)(a))
56 # define gmx_mm_castps_si128(a) ((__m128i)(a))
57 # define gmx_mm_castps_ps128(a) ((__m128)(a))
58 # define gmx_mm_castsi128_pd(a) ((__m128d)(a))
59 # define gmx_mm_castpd_si128(a) ((__m128i)(a))
60 #else
61 static __m128 gmx_mm_castsi128_ps(__m128i a)
63 return *(__m128 *) &a;
65 static __m128i gmx_mm_castps_si128(__m128 a)
67 return *(__m128i *) &a;
69 static __m128 gmx_mm_castps_ps128(__m128 a)
71 return *(__m128 *) &a;
73 static __m128d gmx_mm_castsi128_pd(__m128i a)
75 return *(__m128d *) &a;
77 static __m128i gmx_mm_castpd_si128(__m128d a)
79 return *(__m128i *) &a;
81 #endif
83 #ifndef _MSC_VER
84 /* The warning directive is not supported by MSVC, and that compiler
85 * does not support overriding built-in functions anyway...
87 #if !defined(HAVE_X86INTRIN_H) || !defined(__FMA4__)
88 #warning Emulating FMA instructions - this is probably not what you want!
89 /* Wrapper routines so we can do test builds on non-FMA hardware */
90 static __m128
91 _mm_macc_ps(__m128 a, __m128 b, __m128 c)
94 return _mm_add_ps(c,_mm_mul_ps(a,b));
97 static __m128
98 _mm_nmacc_ps(__m128 a, __m128 b, __m128 c)
101 return _mm_sub_ps(c,_mm_mul_ps(a,b));
104 static __m128d
105 _mm_macc_pd(__m128d a, __m128d b, __m128d c)
108 return _mm_add_pd(c,_mm_mul_pd(a,b));
111 static __m128d
112 _mm_nmacc_pd(__m128d a, __m128d b, __m128d c)
115 return _mm_sub_pd(c,_mm_mul_pd(a,b));
117 #endif /* FMA4 support */
119 #endif /* _MSC_VER */
121 static void
122 gmx_mm_printxmm_ps(const char *s,__m128 xmm)
124 float f[4];
126 _mm_storeu_ps(f,xmm);
127 printf("%s: %15.10e %15.10e %15.10e %15.10e\n",s,f[0],f[1],f[2],f[3]);
131 static void
132 gmx_mm_printxmmsum_ps(const char *s,__m128 xmm)
134 float f[4];
136 _mm_storeu_ps(f,xmm);
137 printf("%s (sum): %15.10g\n",s,f[0]+f[1]+f[2]+f[3]);
141 static void
142 gmx_mm_printxmm_pd(const char *s,__m128d xmm)
144 double f[2];
146 _mm_storeu_pd(f,xmm);
147 printf("%s: %30.20e %30.20e\n",s,f[0],f[1]);
150 static void
151 gmx_mm_printxmmsum_pd(const char *s,__m128d xmm)
153 double f[2];
155 _mm_storeu_pd(f,xmm);
156 printf("%s (sum): %15.10g\n",s,f[0]+f[1]);
160 static void
161 gmx_mm_printxmm_epi32(const char *s,__m128i xmmi)
163 int i[4];
165 _mm_storeu_si128((__m128i *)i,xmmi);
166 printf("%10s: %2d %2d %2d %2d\n",s,i[0],i[1],i[2],i[3]);
171 static int gmx_mm_check_and_reset_overflow(void)
173 int MXCSR;
174 int sse_overflow;
176 MXCSR = _mm_getcsr();
177 /* The overflow flag is bit 3 in the register */
178 if (MXCSR & 0x0008)
180 sse_overflow = 1;
181 /* Set the overflow flag to zero */
182 MXCSR = MXCSR & 0xFFF7;
183 _mm_setcsr(MXCSR);
185 else
187 sse_overflow = 0;
190 return sse_overflow;
195 #endif /* _gmx_x86_avx_128_fma_h_ */