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