Merge "Clean up some variable naming for eigensolving" into release-4-6
[gromacs.git] / include / gmx_x86_sse2.h
blob80f0a7e54e71370ec79e6b8b49661eb2c86d8f2e
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_sse2_h_
22 #define _gmx_x86_sse2_h_
24 #include <emmintrin.h>
26 #include <stdio.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))
58 #else
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;
79 #endif
82 static void
83 gmx_mm_printxmm_ps(const char *s,__m128 xmm)
85 float f[4];
87 _mm_storeu_ps(f,xmm);
88 printf("%s: %15.10e %15.10e %15.10e %15.10e\n",s,f[0],f[1],f[2],f[3]);
92 static void
93 gmx_mm_printxmmsum_ps(const char *s,__m128 xmm)
95 float f[4];
97 _mm_storeu_ps(f,xmm);
98 printf("%s (sum): %15.10g\n",s,f[0]+f[1]+f[2]+f[3]);
102 static void
103 gmx_mm_printxmm_pd(const char *s,__m128d xmm)
105 double f[2];
107 _mm_storeu_pd(f,xmm);
108 printf("%s: %30.20e %30.20e\n",s,f[0],f[1]);
111 static void
112 gmx_mm_printxmmsum_pd(const char *s,__m128d xmm)
114 double f[2];
116 _mm_storeu_pd(f,xmm);
117 printf("%s (sum): %15.10g\n",s,f[0]+f[1]);
121 static void
122 gmx_mm_printxmm_epi32(const char *s,__m128i xmmi)
124 int i[4];
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)
134 int MXCSR;
135 int sse_overflow;
137 MXCSR = _mm_getcsr();
138 /* The overflow flag is bit 3 in the register */
139 if (MXCSR & 0x0008)
141 sse_overflow = 1;
142 /* Set the overflow flag to zero */
143 MXCSR = MXCSR & 0xFFF7;
144 _mm_setcsr(MXCSR);
146 else
148 sse_overflow = 0;
151 return sse_overflow;
155 #endif /* _gmx_x86_sse2_h_ */