Remove unused config.h defines
[alexxy/gromacs.git] / src / gromacs / legacyheaders / gmx_x86_sse4_1.h
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  *
3  *
4  * This file is part of GROMACS.
5  * Copyright (c) 2012-
6  *
7  * Written by the Gromacs development team under coordination of
8  * David van der Spoel, Berk Hess, and Erik Lindahl.
9  *
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.
14  *
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
17  *
18  * And Hey:
19  * Gnomes, ROck Monsters And Chili Sauce
20  */
21 #ifndef _gmx_x86_sse4_1_h_
22 #define _gmx_x86_sse4_1_h_
23
24 #include <smmintrin.h>
25
26 #include <stdio.h>
27
28 #include "types/simple.h"
29
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.
33  */
34
35
36 #define gmx_mm_extract_epi32(x, imm) _mm_extract_epi32((x), (imm))
37
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); \
42 }
43
44 #define _GMX_MM_BLEND(b3, b2, b1, b0) (((b3) << 3) | ((b2) << 2) | ((b1) << 1) | ((b0)))
45
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)
60 {
61     return *(__m128 *) &a;
62 }
63 static __m128i gmx_mm_castps_si128(__m128 a)
64 {
65     return *(__m128i *) &a;
66 }
67 static __m128  gmx_mm_castps_ps128(__m128 a)
68 {
69     return *(__m128 *) &a;
70 }
71 static __m128d gmx_mm_castsi128_pd(__m128i a)
72 {
73     return *(__m128d *) &a;
74 }
75 static __m128i gmx_mm_castpd_si128(__m128d a)
76 {
77     return *(__m128i *) &a;
78 }
79 #endif
80
81
82 static void
83 gmx_mm_printxmm_ps(const char *s, __m128 xmm)
84 {
85     float f[4];
86
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]);
89 }
90
91
92 static void
93 gmx_mm_printxmmsum_ps(const char *s, __m128 xmm)
94 {
95     float f[4];
96
97     _mm_storeu_ps(f, xmm);
98     printf("%s (sum): %15.10g\n", s, f[0]+f[1]+f[2]+f[3]);
99 }
100
101
102 static void
103 gmx_mm_printxmm_pd(const char *s, __m128d xmm)
104 {
105     double f[2];
106
107     _mm_storeu_pd(f, xmm);
108     printf("%s: %30.20e %30.20e\n", s, f[0], f[1]);
109 }
110
111 static void
112 gmx_mm_printxmmsum_pd(const char *s, __m128d xmm)
113 {
114     double f[2];
115
116     _mm_storeu_pd(f, xmm);
117     printf("%s (sum): %15.10g\n", s, f[0]+f[1]);
118 }
119
120
121 static void
122 gmx_mm_printxmm_epi32(const char *s, __m128i xmmi)
123 {
124     int i[4];
125
126     _mm_storeu_si128((__m128i *)i, xmmi);
127     printf("%10s: %2d %2d %2d %2d\n", s, i[0], i[1], i[2], i[3]);
128 }
129
130
131
132 static int gmx_mm_check_and_reset_overflow(void)
133 {
134     int MXCSR;
135     int sse_overflow;
136
137     MXCSR = _mm_getcsr();
138     /* The overflow flag is bit 3 in the register */
139     if (MXCSR & 0x0008)
140     {
141         sse_overflow = 1;
142         /* Set the overflow flag to zero */
143         MXCSR = MXCSR & 0xFFF7;
144         _mm_setcsr(MXCSR);
145     }
146     else
147     {
148         sse_overflow = 0;
149     }
150
151     return sse_overflow;
152 }
153
154
155 #endif /* _gmx_x86_sse4_1_h_ */