added Verlet scheme and NxN non-bonded functionality
[gromacs.git] / include / gmx_x86_sse4_1.h
blob75e61e1bd9e24b7b0a76997b3a91fff78c2aa7b5
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_sse4_1_h_
22 #define _gmx_x86_sse4_1_h_
24 #include <smmintrin.h>
26 #include <stdio.h>
28 #include "types/simple.h"
30 /* Create some basic definitions that are not 100% SSE2 standard and thus not
31 * available on all compilers. These should be fairly self-evident by comparing
32 * with an arbitrary emmintrin.h.
36 #define gmx_mm_extract_epi32(x, imm) _mm_cvtsi128_si32(_mm_srli_si128((x), 4 * (imm)))
38 #define GMX_MM_TRANSPOSE2_PD(row0, row1) { \
39 __m128d __gmx_t1 = row0; \
40 row0 = _mm_unpacklo_pd(row0,row1); \
41 row1 = _mm_unpackhi_pd(__gmx_t1,row1); \
45 #if (defined (_MSC_VER) || defined(__INTEL_COMPILER))
46 # define gmx_mm_castsi128_ps(a) _mm_castsi128_ps(a)
47 # define gmx_mm_castps_si128(a) _mm_castps_si128(a)
48 # define gmx_mm_castps_ps128(a) (a)
49 # define gmx_mm_castsi128_pd(a) _mm_castsi128_pd(a)
50 # define gmx_mm_castpd_si128(a) _mm_castpd_si128(a)
51 #elif defined(__GNUC__)
52 # define gmx_mm_castsi128_ps(a) ((__m128)(a))
53 # define gmx_mm_castps_si128(a) ((__m128i)(a))
54 # define gmx_mm_castps_ps128(a) ((__m128)(a))
55 # define gmx_mm_castsi128_pd(a) ((__m128d)(a))
56 # define gmx_mm_castpd_si128(a) ((__m128i)(a))
57 #else
58 static __m128 gmx_mm_castsi128_ps(__m128i a)
60 return *(__m128 *) &a;
62 static __m128i gmx_mm_castps_si128(__m128 a)
64 return *(__m128i *) &a;
66 static __m128 gmx_mm_castps_ps128(__m128 a)
68 return *(__m128 *) &a;
70 static __m128d gmx_mm_castsi128_pd(__m128i a)
72 return *(__m128d *) &a;
74 static __m128i gmx_mm_castpd_si128(__m128d a)
76 return *(__m128i *) &a;
78 #endif
81 static void
82 gmx_mm_printxmm_ps(const char *s,__m128 xmm)
84 float f[4];
86 _mm_storeu_ps(f,xmm);
87 printf("%s: %15.10e %15.10e %15.10e %15.10e\n",s,f[0],f[1],f[2],f[3]);
91 static void
92 gmx_mm_printxmmsum_ps(const char *s,__m128 xmm)
94 float f[4];
96 _mm_storeu_ps(f,xmm);
97 printf("%s (sum): %15.10g\n",s,f[0]+f[1]+f[2]+f[3]);
101 static void
102 gmx_mm_printxmm_pd(const char *s,__m128d xmm)
104 double f[2];
106 _mm_storeu_pd(f,xmm);
107 printf("%s: %30.20e %30.20e\n",s,f[0],f[1]);
110 static void
111 gmx_mm_printxmmsum_pd(const char *s,__m128d xmm)
113 double f[2];
115 _mm_storeu_pd(f,xmm);
116 printf("%s (sum): %15.10g\n",s,f[0]+f[1]);
120 static void
121 gmx_mm_printxmm_epi32(const char *s,__m128i xmmi)
123 int i[4];
125 _mm_storeu_si128((__m128i *)i,xmmi);
126 printf("%10s: %2d %2d %2d %2d\n",s,i[0],i[1],i[2],i[3]);
131 static int gmx_mm_check_and_reset_overflow(void)
133 int MXCSR;
134 int sse_overflow;
136 MXCSR = _mm_getcsr();
137 /* The overflow flag is bit 3 in the register */
138 if (MXCSR & 0x0008)
140 sse_overflow = 1;
141 /* Set the overflow flag to zero */
142 MXCSR = MXCSR & 0xFFF7;
143 _mm_setcsr(MXCSR);
145 else
147 sse_overflow = 0;
150 return sse_overflow;
154 #endif /* _gmx_x86_sse4_1_h_ */