Fixed LJ-14 error in free energy
[gromacs.git] / include / gmx_x86_avx_256.h
blob90317a5328085370c7d4b634955eedaa1bbd8ada
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_256_h_
22 #define _gmx_x86_avx_256_h_
25 #include <immintrin.h>
26 #ifdef HAVE_X86INTRIN_H
27 #include <x86intrin.h> /* FMA */
28 #endif
31 #include <stdio.h>
33 #include "types/simple.h"
36 #define gmx_mm_extract_epi32(x, imm) _mm_cvtsi128_si32(_mm_srli_si128((x), 4 * (imm)))
38 #define _GMX_MM_PERMUTE(fp3,fp2,fp1,fp0) (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | ((fp0)))
39 #define _GMX_MM_PERMUTE256D(fp3,fp2,fp1,fp0) (((fp3) << 3) | ((fp2) << 2) | ((fp1) << 1) | ((fp0)))
40 #define _GMX_MM_PERMUTE128D(fp1,fp0) (((fp1) << 1) | ((fp0)))
43 #define GMX_MM_TRANSPOSE2_PD(row0, row1) { \
44 __m128d __gmx_t1 = row0; \
45 row0 = _mm_unpacklo_pd(row0,row1); \
46 row1 = _mm_unpackhi_pd(__gmx_t1,row1); \
50 #if (defined (_MSC_VER) || defined(__INTEL_COMPILER))
51 # define gmx_mm_castsi128_ps(a) _mm_castsi128_ps(a)
52 # define gmx_mm_castps_si128(a) _mm_castps_si128(a)
53 # define gmx_mm_castps_ps128(a) (a)
54 # define gmx_mm_castsi128_pd(a) _mm_castsi128_pd(a)
55 # define gmx_mm_castpd_si128(a) _mm_castpd_si128(a)
56 #elif defined(__GNUC__)
57 # define gmx_mm_castsi128_ps(a) ((__m128)(a))
58 # define gmx_mm_castps_si128(a) ((__m128i)(a))
59 # define gmx_mm_castps_ps128(a) ((__m128)(a))
60 # define gmx_mm_castsi128_pd(a) ((__m128d)(a))
61 # define gmx_mm_castpd_si128(a) ((__m128i)(a))
62 #else
63 static __m128 gmx_mm_castsi128_ps(__m128i a)
65 return *(__m128 *) &a;
67 static __m128i gmx_mm_castps_si128(__m128 a)
69 return *(__m128i *) &a;
71 static __m128 gmx_mm_castps_ps128(__m128 a)
73 return *(__m128 *) &a;
75 static __m128d gmx_mm_castsi128_pd(__m128i a)
77 return *(__m128d *) &a;
79 static __m128i gmx_mm_castpd_si128(__m128d a)
81 return *(__m128i *) &a;
83 #endif
87 static void
88 gmx_mm_printxmm_ps(const char *s,__m128 xmm)
90 float f[4];
92 _mm_storeu_ps(f,xmm);
93 printf("%s: %15.10e %15.10e %15.10e %15.10e\n",s,f[0],f[1],f[2],f[3]);
97 static void
98 gmx_mm_printxmmsum_ps(const char *s,__m128 xmm)
100 float f[4];
102 _mm_storeu_ps(f,xmm);
103 printf("%s (sum): %15.10g\n",s,f[0]+f[1]+f[2]+f[3]);
107 static void
108 gmx_mm_printxmm_pd(const char *s,__m128d xmm)
110 double f[2];
112 _mm_storeu_pd(f,xmm);
113 printf("%s: %30.20e %30.20e\n",s,f[0],f[1]);
116 static void
117 gmx_mm_printxmmsum_pd(const char *s,__m128d xmm)
119 double f[2];
121 _mm_storeu_pd(f,xmm);
122 printf("%s (sum): %15.10g\n",s,f[0]+f[1]);
126 static void
127 gmx_mm_printxmm_epi32(const char *s,__m128i xmmi)
129 int i[4];
131 _mm_storeu_si128((__m128i *)i,xmmi);
132 printf("%10s: %2d %2d %2d %2d\n",s,i[0],i[1],i[2],i[3]);
135 static void
136 gmx_mm256_printymm_ps(const char *s,__m256 ymm)
138 float f[8];
140 _mm256_storeu_ps(f,ymm);
141 printf("%s: %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f %12.7f\n",s,f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7]);
144 static void
145 gmx_mm256_printymmsum_ps(const char *s,__m256 ymm)
147 float f[8];
149 _mm256_storeu_ps(f,ymm);
150 printf("%s (sum): %15.10g\n",s,f[0]+f[1]+f[2]+f[3]+f[4]+f[5]+f[6]+f[7]);
154 static void
155 gmx_mm256_printymm_pd(const char *s,__m256d ymm)
157 double f[4];
159 _mm256_storeu_pd(f,ymm);
160 printf("%s: %16.12f %16.12f %16.12f %16.12f\n",s,f[0],f[1],f[2],f[3]);
163 static void
164 gmx_mm256_printymmsum_pd(const char *s,__m256d ymm)
166 double f[4];
168 _mm256_storeu_pd(f,ymm);
169 printf("%s (sum): %15.10g\n",s,f[0]+f[1]+f[2]+f[3]);
174 static void
175 gmx_mm256_printymm_epi32(const char *s,__m256i ymmi)
177 int i[8];
179 _mm256_storeu_si256((__m256i *)i,ymmi);
180 printf("%10s: %2d %2d %2d %2d %2d %2d %2d %2d\n",s,i[0],i[1],i[2],i[3],i[4],i[5],i[6],i[7]);
185 static int gmx_mm_check_and_reset_overflow(void)
187 int MXCSR;
188 int sse_overflow;
190 MXCSR = _mm_getcsr();
191 /* The overflow flag is bit 3 in the register */
192 if (MXCSR & 0x0008)
194 sse_overflow = 1;
195 /* Set the overflow flag to zero */
196 MXCSR = MXCSR & 0xFFF7;
197 _mm_setcsr(MXCSR);
199 else
201 sse_overflow = 0;
204 return sse_overflow;
209 #endif /* _gmx_x86_avx_256_h_ */