Split SIMD implementations into 4 files
[gromacs.git] / src / gromacs / simd / impl_ibm_vsx / impl_ibm_vsx_simd4_float.h
blobf7750233dc2d64961c056bf2f990fd8a03dc25c4
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,2015, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 #ifndef GMX_SIMD_IMPLEMENTATION_IBM_VSX_SIMD4_FLOAT_H
37 #define GMX_SIMD_IMPLEMENTATION_IBM_VSX_SIMD4_FLOAT_H
39 #include <math.h>
41 #include <altivec.h>
43 #include "impl_ibm_vsx_common.h"
44 #include "impl_ibm_vsx_simd_float.h"
46 /* IBM VSX SIMD instruction wrappers. Power7 and later.
48 * While this instruction set is similar to VMX, there are quite a few differences
49 * that make it easier to understand if we start from scratch rather than by
50 * including the VMX implementation and changing lots of things.
54 /* Make sure we do not screw up c++ - undefine vector/bool, and rely on __vector,
55 * which is present both on gcc and xlc.
57 #undef vector
59 /* g++ is also unhappy with the clash of vector bool and the C++ reserved 'bool',
60 * which is solved by undefining bool and reyling on __bool. However, that does
61 * not work with xlc, which requires us to use bool. Solve the conflict by
62 * defining a new vsx_bool.
64 #if defined(__GNUC__) && !defined(__ibmxl__) && !defined(__xlC__)
65 # define vsx_bool __bool
66 # undef bool
67 #else
68 # define vsx_bool bool
69 #endif
72 /* Single precision VSX is 4 elements wide, use for SIMD4 */
73 #define gmx_simd4_float_t gmx_simd_float_t
74 #define gmx_simd4_load_f gmx_simd_load_f
75 #define gmx_simd4_load1_f gmx_simd_load1_f
76 #define gmx_simd4_set1_f gmx_simd_set1_f
77 #define gmx_simd4_store_f gmx_simd_store_f
78 #define gmx_simd4_loadu_f gmx_simd_loadu_f
79 #define gmx_simd4_storeu_f gmx_simd_storeu_f
80 #define gmx_simd4_setzero_f gmx_simd_setzero_f
81 #define gmx_simd4_add_f gmx_simd_add_f
82 #define gmx_simd4_sub_f gmx_simd_sub_f
83 #define gmx_simd4_mul_f gmx_simd_mul_f
84 #define gmx_simd4_fmadd_f gmx_simd_fmadd_f
85 #define gmx_simd4_fmsub_f gmx_simd_fmsub_f
86 #define gmx_simd4_fnmadd_f gmx_simd_fnmadd_f
87 #define gmx_simd4_fnmsub_f gmx_simd_fnmsub_f
88 #define gmx_simd4_and_f gmx_simd_and_f
89 #define gmx_simd4_andnot_f gmx_simd_andnot_f
90 #define gmx_simd4_or_f gmx_simd_or_f
91 #define gmx_simd4_xor_f gmx_simd_xor_f
92 #define gmx_simd4_rsqrt_f gmx_simd_rsqrt_f
93 #define gmx_simd4_rcp_f gmx_simd_rcp_f
94 #define gmx_simd4_fabs_f gmx_simd_fabs_f
95 #define gmx_simd4_fneg_f gmx_simd_fneg_f
96 #define gmx_simd4_max_f gmx_simd_max_f
97 #define gmx_simd4_min_f gmx_simd_min_f
98 #define gmx_simd4_round_f gmx_simd_round_f
99 #define gmx_simd4_trunc_f gmx_simd_trunc_f
100 #define gmx_simd4_fraction_f gmx_simd_fraction_f
101 #define gmx_simd4_get_exponent_f gmx_simd_get_exponent_f
102 #define gmx_simd4_get_mantissa_f gmx_simd_get_mantissa_f
103 #define gmx_simd4_set_exponent_f gmx_simd_set_exponent_f
104 #define gmx_simd4_dotproduct3_f gmx_simd4_dotproduct3_f_ibm_vsx
105 #define gmx_simd4_fint32_t gmx_simd_fint32_t
106 #define gmx_simd4_load_fi gmx_simd_load_fi
107 #define gmx_simd4_load1_fi gmx_simd_load1_fi
108 #define gmx_simd4_set1_fi gmx_simd_set1_fi
109 #define gmx_simd4_store_fi gmx_simd_store_fi
110 #define gmx_simd4_loadu_fi gmx_simd_loadu_fi
111 #define gmx_simd4_storeu_fi gmx_simd_storeu_fi
112 #define gmx_simd4_setzero_fi gmx_simd_setzero_fi
113 #define gmx_simd4_cvt_f2i gmx_simd_cvt_f2i
114 #define gmx_simd4_cvtt_f2i gmx_simd_cvtt_f2i
115 #define gmx_simd4_cvt_i2f gmx_simd_cvt_i2f
116 #define gmx_simd4_fbool_t gmx_simd_fbool_t
117 #define gmx_simd4_cmpeq_f gmx_simd_cmpeq_f
118 #define gmx_simd4_cmplt_f gmx_simd_cmplt_f
119 #define gmx_simd4_cmple_f gmx_simd_cmple_f
120 #define gmx_simd4_and_fb gmx_simd_and_fb
121 #define gmx_simd4_or_fb gmx_simd_or_fb
122 #define gmx_simd4_anytrue_fb gmx_simd_anytrue_fb
123 #define gmx_simd4_blendzero_f gmx_simd_blendzero_f
124 #define gmx_simd4_blendnotzero_f gmx_simd_blendnotzero_f
125 #define gmx_simd4_blendv_f gmx_simd_blendv_f
126 #define gmx_simd4_reduce_f gmx_simd_reduce_f
128 static gmx_inline float
129 gmx_simd4_dotproduct3_f_ibm_vsx(gmx_simd4_float_t a, gmx_simd4_float_t b)
131 gmx_simd4_float_t c = gmx_simd_mul_f(a, b);
132 const __vector unsigned char perm1 = { 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7 };
133 const __vector unsigned char perm2 = { 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3 };
134 __vector float sum;
135 sum = vec_add(c, vec_perm(c, c, (__vector unsigned char)perm1));
136 sum = vec_add(sum, vec_perm(c, c, (__vector unsigned char)perm2));
137 return vec_extract(sum, 0);
140 #endif /* GMX_SIMD_IMPLEMENTATION_IBM_VSX_SIMD4_FLOAT_H */