Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_avx_128_fma_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*
36  * Note: this file was generated by the GROMACS avx_128_fma_double kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_VF_avx_128_fma_double
52  * Electrostatics interaction: ReactionField
53  * VdW interaction:            LennardJones
54  * Geometry:                   Water3-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_VF_avx_128_fma_double
59                     (t_nblist                    * gmx_restrict       nlist,
60                      rvec                        * gmx_restrict          xx,
61                      rvec                        * gmx_restrict          ff,
62                      t_forcerec                  * gmx_restrict          fr,
63                      t_mdatoms                   * gmx_restrict     mdatoms,
64                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65                      t_nrnb                      * gmx_restrict        nrnb)
66 {
67     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68      * just 0 for non-waters.
69      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70      * jnr indices corresponding to data put in the four positions in the SIMD register.
71      */
72     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
73     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74     int              jnrA,jnrB;
75     int              j_coord_offsetA,j_coord_offsetB;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80     int              vdwioffset0;
81     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82     int              vdwioffset1;
83     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
84     int              vdwioffset2;
85     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86     int              vdwjidx0A,vdwjidx0B;
87     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
88     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
90     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
91     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
92     real             *charge;
93     int              nvdwtype;
94     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
95     int              *vdwtype;
96     real             *vdwparam;
97     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
98     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
99     __m128d          dummy_mask,cutoff_mask;
100     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
101     __m128d          one     = _mm_set1_pd(1.0);
102     __m128d          two     = _mm_set1_pd(2.0);
103     x                = xx[0];
104     f                = ff[0];
105
106     nri              = nlist->nri;
107     iinr             = nlist->iinr;
108     jindex           = nlist->jindex;
109     jjnr             = nlist->jjnr;
110     shiftidx         = nlist->shift;
111     gid              = nlist->gid;
112     shiftvec         = fr->shift_vec[0];
113     fshift           = fr->fshift[0];
114     facel            = _mm_set1_pd(fr->epsfac);
115     charge           = mdatoms->chargeA;
116     krf              = _mm_set1_pd(fr->ic->k_rf);
117     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
118     crf              = _mm_set1_pd(fr->ic->c_rf);
119     nvdwtype         = fr->ntype;
120     vdwparam         = fr->nbfp;
121     vdwtype          = mdatoms->typeA;
122
123     /* Setup water-specific parameters */
124     inr              = nlist->iinr[0];
125     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
126     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
127     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
128     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
129
130     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
131     rcutoff_scalar   = fr->rcoulomb;
132     rcutoff          = _mm_set1_pd(rcutoff_scalar);
133     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
134
135     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
136     rvdw             = _mm_set1_pd(fr->rvdw);
137
138     /* Avoid stupid compiler warnings */
139     jnrA = jnrB = 0;
140     j_coord_offsetA = 0;
141     j_coord_offsetB = 0;
142
143     outeriter        = 0;
144     inneriter        = 0;
145
146     /* Start outer loop over neighborlists */
147     for(iidx=0; iidx<nri; iidx++)
148     {
149         /* Load shift vector for this list */
150         i_shift_offset   = DIM*shiftidx[iidx];
151
152         /* Load limits for loop over neighbors */
153         j_index_start    = jindex[iidx];
154         j_index_end      = jindex[iidx+1];
155
156         /* Get outer coordinate index */
157         inr              = iinr[iidx];
158         i_coord_offset   = DIM*inr;
159
160         /* Load i particle coords and add shift vector */
161         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
162                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
163
164         fix0             = _mm_setzero_pd();
165         fiy0             = _mm_setzero_pd();
166         fiz0             = _mm_setzero_pd();
167         fix1             = _mm_setzero_pd();
168         fiy1             = _mm_setzero_pd();
169         fiz1             = _mm_setzero_pd();
170         fix2             = _mm_setzero_pd();
171         fiy2             = _mm_setzero_pd();
172         fiz2             = _mm_setzero_pd();
173
174         /* Reset potential sums */
175         velecsum         = _mm_setzero_pd();
176         vvdwsum          = _mm_setzero_pd();
177
178         /* Start inner kernel loop */
179         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
180         {
181
182             /* Get j neighbor index, and coordinate index */
183             jnrA             = jjnr[jidx];
184             jnrB             = jjnr[jidx+1];
185             j_coord_offsetA  = DIM*jnrA;
186             j_coord_offsetB  = DIM*jnrB;
187
188             /* load j atom coordinates */
189             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
190                                               &jx0,&jy0,&jz0);
191
192             /* Calculate displacement vector */
193             dx00             = _mm_sub_pd(ix0,jx0);
194             dy00             = _mm_sub_pd(iy0,jy0);
195             dz00             = _mm_sub_pd(iz0,jz0);
196             dx10             = _mm_sub_pd(ix1,jx0);
197             dy10             = _mm_sub_pd(iy1,jy0);
198             dz10             = _mm_sub_pd(iz1,jz0);
199             dx20             = _mm_sub_pd(ix2,jx0);
200             dy20             = _mm_sub_pd(iy2,jy0);
201             dz20             = _mm_sub_pd(iz2,jz0);
202
203             /* Calculate squared distance and things based on it */
204             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
205             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
206             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
207
208             rinv00           = gmx_mm_invsqrt_pd(rsq00);
209             rinv10           = gmx_mm_invsqrt_pd(rsq10);
210             rinv20           = gmx_mm_invsqrt_pd(rsq20);
211
212             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
213             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
214             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
215
216             /* Load parameters for j particles */
217             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
218             vdwjidx0A        = 2*vdwtype[jnrA+0];
219             vdwjidx0B        = 2*vdwtype[jnrB+0];
220
221             fjx0             = _mm_setzero_pd();
222             fjy0             = _mm_setzero_pd();
223             fjz0             = _mm_setzero_pd();
224
225             /**************************
226              * CALCULATE INTERACTIONS *
227              **************************/
228
229             if (gmx_mm_any_lt(rsq00,rcutoff2))
230             {
231
232             /* Compute parameters for interactions between i and j atoms */
233             qq00             = _mm_mul_pd(iq0,jq0);
234             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
235                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
236
237             /* REACTION-FIELD ELECTROSTATICS */
238             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
239             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
240
241             /* LENNARD-JONES DISPERSION/REPULSION */
242
243             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
244             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
245             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
246             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
247                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
248             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
249
250             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
251
252             /* Update potential sum for this i atom from the interaction with this j atom. */
253             velec            = _mm_and_pd(velec,cutoff_mask);
254             velecsum         = _mm_add_pd(velecsum,velec);
255             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
256             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
257
258             fscal            = _mm_add_pd(felec,fvdw);
259
260             fscal            = _mm_and_pd(fscal,cutoff_mask);
261
262             /* Update vectorial force */
263             fix0             = _mm_macc_pd(dx00,fscal,fix0);
264             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
265             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
266             
267             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
268             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
269             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
270
271             }
272
273             /**************************
274              * CALCULATE INTERACTIONS *
275              **************************/
276
277             if (gmx_mm_any_lt(rsq10,rcutoff2))
278             {
279
280             /* Compute parameters for interactions between i and j atoms */
281             qq10             = _mm_mul_pd(iq1,jq0);
282
283             /* REACTION-FIELD ELECTROSTATICS */
284             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
285             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
286
287             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
288
289             /* Update potential sum for this i atom from the interaction with this j atom. */
290             velec            = _mm_and_pd(velec,cutoff_mask);
291             velecsum         = _mm_add_pd(velecsum,velec);
292
293             fscal            = felec;
294
295             fscal            = _mm_and_pd(fscal,cutoff_mask);
296
297             /* Update vectorial force */
298             fix1             = _mm_macc_pd(dx10,fscal,fix1);
299             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
300             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
301             
302             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
303             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
304             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
305
306             }
307
308             /**************************
309              * CALCULATE INTERACTIONS *
310              **************************/
311
312             if (gmx_mm_any_lt(rsq20,rcutoff2))
313             {
314
315             /* Compute parameters for interactions between i and j atoms */
316             qq20             = _mm_mul_pd(iq2,jq0);
317
318             /* REACTION-FIELD ELECTROSTATICS */
319             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
320             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
321
322             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
323
324             /* Update potential sum for this i atom from the interaction with this j atom. */
325             velec            = _mm_and_pd(velec,cutoff_mask);
326             velecsum         = _mm_add_pd(velecsum,velec);
327
328             fscal            = felec;
329
330             fscal            = _mm_and_pd(fscal,cutoff_mask);
331
332             /* Update vectorial force */
333             fix2             = _mm_macc_pd(dx20,fscal,fix2);
334             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
335             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
336             
337             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
338             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
339             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
340
341             }
342
343             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
344
345             /* Inner loop uses 138 flops */
346         }
347
348         if(jidx<j_index_end)
349         {
350
351             jnrA             = jjnr[jidx];
352             j_coord_offsetA  = DIM*jnrA;
353
354             /* load j atom coordinates */
355             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
356                                               &jx0,&jy0,&jz0);
357
358             /* Calculate displacement vector */
359             dx00             = _mm_sub_pd(ix0,jx0);
360             dy00             = _mm_sub_pd(iy0,jy0);
361             dz00             = _mm_sub_pd(iz0,jz0);
362             dx10             = _mm_sub_pd(ix1,jx0);
363             dy10             = _mm_sub_pd(iy1,jy0);
364             dz10             = _mm_sub_pd(iz1,jz0);
365             dx20             = _mm_sub_pd(ix2,jx0);
366             dy20             = _mm_sub_pd(iy2,jy0);
367             dz20             = _mm_sub_pd(iz2,jz0);
368
369             /* Calculate squared distance and things based on it */
370             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
371             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
372             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
373
374             rinv00           = gmx_mm_invsqrt_pd(rsq00);
375             rinv10           = gmx_mm_invsqrt_pd(rsq10);
376             rinv20           = gmx_mm_invsqrt_pd(rsq20);
377
378             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
379             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
380             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
381
382             /* Load parameters for j particles */
383             jq0              = _mm_load_sd(charge+jnrA+0);
384             vdwjidx0A        = 2*vdwtype[jnrA+0];
385
386             fjx0             = _mm_setzero_pd();
387             fjy0             = _mm_setzero_pd();
388             fjz0             = _mm_setzero_pd();
389
390             /**************************
391              * CALCULATE INTERACTIONS *
392              **************************/
393
394             if (gmx_mm_any_lt(rsq00,rcutoff2))
395             {
396
397             /* Compute parameters for interactions between i and j atoms */
398             qq00             = _mm_mul_pd(iq0,jq0);
399             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
400
401             /* REACTION-FIELD ELECTROSTATICS */
402             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
403             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
404
405             /* LENNARD-JONES DISPERSION/REPULSION */
406
407             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
408             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
409             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
410             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
411                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
412             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
413
414             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
415
416             /* Update potential sum for this i atom from the interaction with this j atom. */
417             velec            = _mm_and_pd(velec,cutoff_mask);
418             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
419             velecsum         = _mm_add_pd(velecsum,velec);
420             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
421             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
422             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
423
424             fscal            = _mm_add_pd(felec,fvdw);
425
426             fscal            = _mm_and_pd(fscal,cutoff_mask);
427
428             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
429
430             /* Update vectorial force */
431             fix0             = _mm_macc_pd(dx00,fscal,fix0);
432             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
433             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
434             
435             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
436             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
437             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
438
439             }
440
441             /**************************
442              * CALCULATE INTERACTIONS *
443              **************************/
444
445             if (gmx_mm_any_lt(rsq10,rcutoff2))
446             {
447
448             /* Compute parameters for interactions between i and j atoms */
449             qq10             = _mm_mul_pd(iq1,jq0);
450
451             /* REACTION-FIELD ELECTROSTATICS */
452             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
453             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
454
455             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
456
457             /* Update potential sum for this i atom from the interaction with this j atom. */
458             velec            = _mm_and_pd(velec,cutoff_mask);
459             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
460             velecsum         = _mm_add_pd(velecsum,velec);
461
462             fscal            = felec;
463
464             fscal            = _mm_and_pd(fscal,cutoff_mask);
465
466             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
467
468             /* Update vectorial force */
469             fix1             = _mm_macc_pd(dx10,fscal,fix1);
470             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
471             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
472             
473             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
474             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
475             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
476
477             }
478
479             /**************************
480              * CALCULATE INTERACTIONS *
481              **************************/
482
483             if (gmx_mm_any_lt(rsq20,rcutoff2))
484             {
485
486             /* Compute parameters for interactions between i and j atoms */
487             qq20             = _mm_mul_pd(iq2,jq0);
488
489             /* REACTION-FIELD ELECTROSTATICS */
490             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
491             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
492
493             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
494
495             /* Update potential sum for this i atom from the interaction with this j atom. */
496             velec            = _mm_and_pd(velec,cutoff_mask);
497             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
498             velecsum         = _mm_add_pd(velecsum,velec);
499
500             fscal            = felec;
501
502             fscal            = _mm_and_pd(fscal,cutoff_mask);
503
504             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
505
506             /* Update vectorial force */
507             fix2             = _mm_macc_pd(dx20,fscal,fix2);
508             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
509             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
510             
511             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
512             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
513             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
514
515             }
516
517             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
518
519             /* Inner loop uses 138 flops */
520         }
521
522         /* End of innermost loop */
523
524         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
525                                               f+i_coord_offset,fshift+i_shift_offset);
526
527         ggid                        = gid[iidx];
528         /* Update potential energies */
529         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
530         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
531
532         /* Increment number of inner iterations */
533         inneriter                  += j_index_end - j_index_start;
534
535         /* Outer loop uses 20 flops */
536     }
537
538     /* Increment number of outer iterations */
539     outeriter        += nri;
540
541     /* Update outer/inner flops */
542
543     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*138);
544 }
545 /*
546  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
547  * Electrostatics interaction: ReactionField
548  * VdW interaction:            LennardJones
549  * Geometry:                   Water3-Particle
550  * Calculate force/pot:        Force
551  */
552 void
553 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
554                     (t_nblist                    * gmx_restrict       nlist,
555                      rvec                        * gmx_restrict          xx,
556                      rvec                        * gmx_restrict          ff,
557                      t_forcerec                  * gmx_restrict          fr,
558                      t_mdatoms                   * gmx_restrict     mdatoms,
559                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
560                      t_nrnb                      * gmx_restrict        nrnb)
561 {
562     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
563      * just 0 for non-waters.
564      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
565      * jnr indices corresponding to data put in the four positions in the SIMD register.
566      */
567     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
568     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
569     int              jnrA,jnrB;
570     int              j_coord_offsetA,j_coord_offsetB;
571     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
572     real             rcutoff_scalar;
573     real             *shiftvec,*fshift,*x,*f;
574     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
575     int              vdwioffset0;
576     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
577     int              vdwioffset1;
578     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
579     int              vdwioffset2;
580     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
581     int              vdwjidx0A,vdwjidx0B;
582     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
583     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
584     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
585     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
586     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
587     real             *charge;
588     int              nvdwtype;
589     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
590     int              *vdwtype;
591     real             *vdwparam;
592     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
593     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
594     __m128d          dummy_mask,cutoff_mask;
595     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
596     __m128d          one     = _mm_set1_pd(1.0);
597     __m128d          two     = _mm_set1_pd(2.0);
598     x                = xx[0];
599     f                = ff[0];
600
601     nri              = nlist->nri;
602     iinr             = nlist->iinr;
603     jindex           = nlist->jindex;
604     jjnr             = nlist->jjnr;
605     shiftidx         = nlist->shift;
606     gid              = nlist->gid;
607     shiftvec         = fr->shift_vec[0];
608     fshift           = fr->fshift[0];
609     facel            = _mm_set1_pd(fr->epsfac);
610     charge           = mdatoms->chargeA;
611     krf              = _mm_set1_pd(fr->ic->k_rf);
612     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
613     crf              = _mm_set1_pd(fr->ic->c_rf);
614     nvdwtype         = fr->ntype;
615     vdwparam         = fr->nbfp;
616     vdwtype          = mdatoms->typeA;
617
618     /* Setup water-specific parameters */
619     inr              = nlist->iinr[0];
620     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
621     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
622     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
623     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
624
625     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
626     rcutoff_scalar   = fr->rcoulomb;
627     rcutoff          = _mm_set1_pd(rcutoff_scalar);
628     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
629
630     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
631     rvdw             = _mm_set1_pd(fr->rvdw);
632
633     /* Avoid stupid compiler warnings */
634     jnrA = jnrB = 0;
635     j_coord_offsetA = 0;
636     j_coord_offsetB = 0;
637
638     outeriter        = 0;
639     inneriter        = 0;
640
641     /* Start outer loop over neighborlists */
642     for(iidx=0; iidx<nri; iidx++)
643     {
644         /* Load shift vector for this list */
645         i_shift_offset   = DIM*shiftidx[iidx];
646
647         /* Load limits for loop over neighbors */
648         j_index_start    = jindex[iidx];
649         j_index_end      = jindex[iidx+1];
650
651         /* Get outer coordinate index */
652         inr              = iinr[iidx];
653         i_coord_offset   = DIM*inr;
654
655         /* Load i particle coords and add shift vector */
656         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
657                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
658
659         fix0             = _mm_setzero_pd();
660         fiy0             = _mm_setzero_pd();
661         fiz0             = _mm_setzero_pd();
662         fix1             = _mm_setzero_pd();
663         fiy1             = _mm_setzero_pd();
664         fiz1             = _mm_setzero_pd();
665         fix2             = _mm_setzero_pd();
666         fiy2             = _mm_setzero_pd();
667         fiz2             = _mm_setzero_pd();
668
669         /* Start inner kernel loop */
670         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
671         {
672
673             /* Get j neighbor index, and coordinate index */
674             jnrA             = jjnr[jidx];
675             jnrB             = jjnr[jidx+1];
676             j_coord_offsetA  = DIM*jnrA;
677             j_coord_offsetB  = DIM*jnrB;
678
679             /* load j atom coordinates */
680             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
681                                               &jx0,&jy0,&jz0);
682
683             /* Calculate displacement vector */
684             dx00             = _mm_sub_pd(ix0,jx0);
685             dy00             = _mm_sub_pd(iy0,jy0);
686             dz00             = _mm_sub_pd(iz0,jz0);
687             dx10             = _mm_sub_pd(ix1,jx0);
688             dy10             = _mm_sub_pd(iy1,jy0);
689             dz10             = _mm_sub_pd(iz1,jz0);
690             dx20             = _mm_sub_pd(ix2,jx0);
691             dy20             = _mm_sub_pd(iy2,jy0);
692             dz20             = _mm_sub_pd(iz2,jz0);
693
694             /* Calculate squared distance and things based on it */
695             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
696             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
697             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
698
699             rinv00           = gmx_mm_invsqrt_pd(rsq00);
700             rinv10           = gmx_mm_invsqrt_pd(rsq10);
701             rinv20           = gmx_mm_invsqrt_pd(rsq20);
702
703             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
704             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
705             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
706
707             /* Load parameters for j particles */
708             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
709             vdwjidx0A        = 2*vdwtype[jnrA+0];
710             vdwjidx0B        = 2*vdwtype[jnrB+0];
711
712             fjx0             = _mm_setzero_pd();
713             fjy0             = _mm_setzero_pd();
714             fjz0             = _mm_setzero_pd();
715
716             /**************************
717              * CALCULATE INTERACTIONS *
718              **************************/
719
720             if (gmx_mm_any_lt(rsq00,rcutoff2))
721             {
722
723             /* Compute parameters for interactions between i and j atoms */
724             qq00             = _mm_mul_pd(iq0,jq0);
725             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
726                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
727
728             /* REACTION-FIELD ELECTROSTATICS */
729             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
730
731             /* LENNARD-JONES DISPERSION/REPULSION */
732
733             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
734             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
735
736             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
737
738             fscal            = _mm_add_pd(felec,fvdw);
739
740             fscal            = _mm_and_pd(fscal,cutoff_mask);
741
742             /* Update vectorial force */
743             fix0             = _mm_macc_pd(dx00,fscal,fix0);
744             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
745             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
746             
747             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
748             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
749             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
750
751             }
752
753             /**************************
754              * CALCULATE INTERACTIONS *
755              **************************/
756
757             if (gmx_mm_any_lt(rsq10,rcutoff2))
758             {
759
760             /* Compute parameters for interactions between i and j atoms */
761             qq10             = _mm_mul_pd(iq1,jq0);
762
763             /* REACTION-FIELD ELECTROSTATICS */
764             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
765
766             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
767
768             fscal            = felec;
769
770             fscal            = _mm_and_pd(fscal,cutoff_mask);
771
772             /* Update vectorial force */
773             fix1             = _mm_macc_pd(dx10,fscal,fix1);
774             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
775             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
776             
777             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
778             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
779             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
780
781             }
782
783             /**************************
784              * CALCULATE INTERACTIONS *
785              **************************/
786
787             if (gmx_mm_any_lt(rsq20,rcutoff2))
788             {
789
790             /* Compute parameters for interactions between i and j atoms */
791             qq20             = _mm_mul_pd(iq2,jq0);
792
793             /* REACTION-FIELD ELECTROSTATICS */
794             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
795
796             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
797
798             fscal            = felec;
799
800             fscal            = _mm_and_pd(fscal,cutoff_mask);
801
802             /* Update vectorial force */
803             fix2             = _mm_macc_pd(dx20,fscal,fix2);
804             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
805             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
806             
807             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
808             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
809             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
810
811             }
812
813             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
814
815             /* Inner loop uses 109 flops */
816         }
817
818         if(jidx<j_index_end)
819         {
820
821             jnrA             = jjnr[jidx];
822             j_coord_offsetA  = DIM*jnrA;
823
824             /* load j atom coordinates */
825             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
826                                               &jx0,&jy0,&jz0);
827
828             /* Calculate displacement vector */
829             dx00             = _mm_sub_pd(ix0,jx0);
830             dy00             = _mm_sub_pd(iy0,jy0);
831             dz00             = _mm_sub_pd(iz0,jz0);
832             dx10             = _mm_sub_pd(ix1,jx0);
833             dy10             = _mm_sub_pd(iy1,jy0);
834             dz10             = _mm_sub_pd(iz1,jz0);
835             dx20             = _mm_sub_pd(ix2,jx0);
836             dy20             = _mm_sub_pd(iy2,jy0);
837             dz20             = _mm_sub_pd(iz2,jz0);
838
839             /* Calculate squared distance and things based on it */
840             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
841             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
842             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
843
844             rinv00           = gmx_mm_invsqrt_pd(rsq00);
845             rinv10           = gmx_mm_invsqrt_pd(rsq10);
846             rinv20           = gmx_mm_invsqrt_pd(rsq20);
847
848             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
849             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
850             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
851
852             /* Load parameters for j particles */
853             jq0              = _mm_load_sd(charge+jnrA+0);
854             vdwjidx0A        = 2*vdwtype[jnrA+0];
855
856             fjx0             = _mm_setzero_pd();
857             fjy0             = _mm_setzero_pd();
858             fjz0             = _mm_setzero_pd();
859
860             /**************************
861              * CALCULATE INTERACTIONS *
862              **************************/
863
864             if (gmx_mm_any_lt(rsq00,rcutoff2))
865             {
866
867             /* Compute parameters for interactions between i and j atoms */
868             qq00             = _mm_mul_pd(iq0,jq0);
869             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
870
871             /* REACTION-FIELD ELECTROSTATICS */
872             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
873
874             /* LENNARD-JONES DISPERSION/REPULSION */
875
876             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
877             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
878
879             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
880
881             fscal            = _mm_add_pd(felec,fvdw);
882
883             fscal            = _mm_and_pd(fscal,cutoff_mask);
884
885             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
886
887             /* Update vectorial force */
888             fix0             = _mm_macc_pd(dx00,fscal,fix0);
889             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
890             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
891             
892             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
893             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
894             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
895
896             }
897
898             /**************************
899              * CALCULATE INTERACTIONS *
900              **************************/
901
902             if (gmx_mm_any_lt(rsq10,rcutoff2))
903             {
904
905             /* Compute parameters for interactions between i and j atoms */
906             qq10             = _mm_mul_pd(iq1,jq0);
907
908             /* REACTION-FIELD ELECTROSTATICS */
909             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
910
911             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
912
913             fscal            = felec;
914
915             fscal            = _mm_and_pd(fscal,cutoff_mask);
916
917             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
918
919             /* Update vectorial force */
920             fix1             = _mm_macc_pd(dx10,fscal,fix1);
921             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
922             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
923             
924             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
925             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
926             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
927
928             }
929
930             /**************************
931              * CALCULATE INTERACTIONS *
932              **************************/
933
934             if (gmx_mm_any_lt(rsq20,rcutoff2))
935             {
936
937             /* Compute parameters for interactions between i and j atoms */
938             qq20             = _mm_mul_pd(iq2,jq0);
939
940             /* REACTION-FIELD ELECTROSTATICS */
941             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
942
943             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
944
945             fscal            = felec;
946
947             fscal            = _mm_and_pd(fscal,cutoff_mask);
948
949             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
950
951             /* Update vectorial force */
952             fix2             = _mm_macc_pd(dx20,fscal,fix2);
953             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
954             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
955             
956             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
957             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
958             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
959
960             }
961
962             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
963
964             /* Inner loop uses 109 flops */
965         }
966
967         /* End of innermost loop */
968
969         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
970                                               f+i_coord_offset,fshift+i_shift_offset);
971
972         /* Increment number of inner iterations */
973         inneriter                  += j_index_end - j_index_start;
974
975         /* Outer loop uses 18 flops */
976     }
977
978     /* Increment number of outer iterations */
979     outeriter        += nri;
980
981     /* Update outer/inner flops */
982
983     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*109);
984 }