89a4500d197a4daf64e5615ba05a8b0786329eeb
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_avx_128_fma_single.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_single kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
46
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_VF_avx_128_fma_single
52  * Electrostatics interaction: Ewald
53  * VdW interaction:            LennardJones
54  * Geometry:                   Water3-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_VF_avx_128_fma_single
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,C,D refer to j loop unrolling done with AVX_128, e.g. for the four 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,jnrC,jnrD;
75     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
78     real             rcutoff_scalar;
79     real             *shiftvec,*fshift,*x,*f;
80     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81     real             scratch[4*DIM];
82     __m128           fscal,rcutoff,rcutoff2,jidxall;
83     int              vdwioffset0;
84     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85     int              vdwioffset1;
86     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87     int              vdwioffset2;
88     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
94     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
95     real             *charge;
96     int              nvdwtype;
97     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
98     int              *vdwtype;
99     real             *vdwparam;
100     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
101     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
102     __m128i          ewitab;
103     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
104     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
105     real             *ewtab;
106     __m128           dummy_mask,cutoff_mask;
107     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
108     __m128           one     = _mm_set1_ps(1.0);
109     __m128           two     = _mm_set1_ps(2.0);
110     x                = xx[0];
111     f                = ff[0];
112
113     nri              = nlist->nri;
114     iinr             = nlist->iinr;
115     jindex           = nlist->jindex;
116     jjnr             = nlist->jjnr;
117     shiftidx         = nlist->shift;
118     gid              = nlist->gid;
119     shiftvec         = fr->shift_vec[0];
120     fshift           = fr->fshift[0];
121     facel            = _mm_set1_ps(fr->epsfac);
122     charge           = mdatoms->chargeA;
123     nvdwtype         = fr->ntype;
124     vdwparam         = fr->nbfp;
125     vdwtype          = mdatoms->typeA;
126
127     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
128     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
129     beta2            = _mm_mul_ps(beta,beta);
130     beta3            = _mm_mul_ps(beta,beta2);
131     ewtab            = fr->ic->tabq_coul_FDV0;
132     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
133     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
134
135     /* Setup water-specific parameters */
136     inr              = nlist->iinr[0];
137     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
138     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
139     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
140     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
141
142     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
143     rcutoff_scalar   = fr->rcoulomb;
144     rcutoff          = _mm_set1_ps(rcutoff_scalar);
145     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
146
147     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
148     rvdw             = _mm_set1_ps(fr->rvdw);
149
150     /* Avoid stupid compiler warnings */
151     jnrA = jnrB = jnrC = jnrD = 0;
152     j_coord_offsetA = 0;
153     j_coord_offsetB = 0;
154     j_coord_offsetC = 0;
155     j_coord_offsetD = 0;
156
157     outeriter        = 0;
158     inneriter        = 0;
159
160     for(iidx=0;iidx<4*DIM;iidx++)
161     {
162         scratch[iidx] = 0.0;
163     }
164
165     /* Start outer loop over neighborlists */
166     for(iidx=0; iidx<nri; iidx++)
167     {
168         /* Load shift vector for this list */
169         i_shift_offset   = DIM*shiftidx[iidx];
170
171         /* Load limits for loop over neighbors */
172         j_index_start    = jindex[iidx];
173         j_index_end      = jindex[iidx+1];
174
175         /* Get outer coordinate index */
176         inr              = iinr[iidx];
177         i_coord_offset   = DIM*inr;
178
179         /* Load i particle coords and add shift vector */
180         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
181                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
182
183         fix0             = _mm_setzero_ps();
184         fiy0             = _mm_setzero_ps();
185         fiz0             = _mm_setzero_ps();
186         fix1             = _mm_setzero_ps();
187         fiy1             = _mm_setzero_ps();
188         fiz1             = _mm_setzero_ps();
189         fix2             = _mm_setzero_ps();
190         fiy2             = _mm_setzero_ps();
191         fiz2             = _mm_setzero_ps();
192
193         /* Reset potential sums */
194         velecsum         = _mm_setzero_ps();
195         vvdwsum          = _mm_setzero_ps();
196
197         /* Start inner kernel loop */
198         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
199         {
200
201             /* Get j neighbor index, and coordinate index */
202             jnrA             = jjnr[jidx];
203             jnrB             = jjnr[jidx+1];
204             jnrC             = jjnr[jidx+2];
205             jnrD             = jjnr[jidx+3];
206             j_coord_offsetA  = DIM*jnrA;
207             j_coord_offsetB  = DIM*jnrB;
208             j_coord_offsetC  = DIM*jnrC;
209             j_coord_offsetD  = DIM*jnrD;
210
211             /* load j atom coordinates */
212             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
213                                               x+j_coord_offsetC,x+j_coord_offsetD,
214                                               &jx0,&jy0,&jz0);
215
216             /* Calculate displacement vector */
217             dx00             = _mm_sub_ps(ix0,jx0);
218             dy00             = _mm_sub_ps(iy0,jy0);
219             dz00             = _mm_sub_ps(iz0,jz0);
220             dx10             = _mm_sub_ps(ix1,jx0);
221             dy10             = _mm_sub_ps(iy1,jy0);
222             dz10             = _mm_sub_ps(iz1,jz0);
223             dx20             = _mm_sub_ps(ix2,jx0);
224             dy20             = _mm_sub_ps(iy2,jy0);
225             dz20             = _mm_sub_ps(iz2,jz0);
226
227             /* Calculate squared distance and things based on it */
228             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
229             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
230             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
231
232             rinv00           = gmx_mm_invsqrt_ps(rsq00);
233             rinv10           = gmx_mm_invsqrt_ps(rsq10);
234             rinv20           = gmx_mm_invsqrt_ps(rsq20);
235
236             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
237             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
238             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
239
240             /* Load parameters for j particles */
241             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
242                                                               charge+jnrC+0,charge+jnrD+0);
243             vdwjidx0A        = 2*vdwtype[jnrA+0];
244             vdwjidx0B        = 2*vdwtype[jnrB+0];
245             vdwjidx0C        = 2*vdwtype[jnrC+0];
246             vdwjidx0D        = 2*vdwtype[jnrD+0];
247
248             fjx0             = _mm_setzero_ps();
249             fjy0             = _mm_setzero_ps();
250             fjz0             = _mm_setzero_ps();
251
252             /**************************
253              * CALCULATE INTERACTIONS *
254              **************************/
255
256             if (gmx_mm_any_lt(rsq00,rcutoff2))
257             {
258
259             r00              = _mm_mul_ps(rsq00,rinv00);
260
261             /* Compute parameters for interactions between i and j atoms */
262             qq00             = _mm_mul_ps(iq0,jq0);
263             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
264                                          vdwparam+vdwioffset0+vdwjidx0B,
265                                          vdwparam+vdwioffset0+vdwjidx0C,
266                                          vdwparam+vdwioffset0+vdwjidx0D,
267                                          &c6_00,&c12_00);
268
269             /* EWALD ELECTROSTATICS */
270
271             /* Analytical PME correction */
272             zeta2            = _mm_mul_ps(beta2,rsq00);
273             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
274             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
275             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
276             felec            = _mm_mul_ps(qq00,felec);
277             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
278             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
279             velec            = _mm_mul_ps(qq00,velec);
280
281             /* LENNARD-JONES DISPERSION/REPULSION */
282
283             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
284             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
285             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
286             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
287                                           _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
288             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
289
290             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
291
292             /* Update potential sum for this i atom from the interaction with this j atom. */
293             velec            = _mm_and_ps(velec,cutoff_mask);
294             velecsum         = _mm_add_ps(velecsum,velec);
295             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
296             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
297
298             fscal            = _mm_add_ps(felec,fvdw);
299
300             fscal            = _mm_and_ps(fscal,cutoff_mask);
301
302              /* Update vectorial force */
303             fix0             = _mm_macc_ps(dx00,fscal,fix0);
304             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
305             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
306
307             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
308             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
309             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
310
311             }
312
313             /**************************
314              * CALCULATE INTERACTIONS *
315              **************************/
316
317             if (gmx_mm_any_lt(rsq10,rcutoff2))
318             {
319
320             r10              = _mm_mul_ps(rsq10,rinv10);
321
322             /* Compute parameters for interactions between i and j atoms */
323             qq10             = _mm_mul_ps(iq1,jq0);
324
325             /* EWALD ELECTROSTATICS */
326
327             /* Analytical PME correction */
328             zeta2            = _mm_mul_ps(beta2,rsq10);
329             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
330             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
331             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
332             felec            = _mm_mul_ps(qq10,felec);
333             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
334             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
335             velec            = _mm_mul_ps(qq10,velec);
336
337             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
338
339             /* Update potential sum for this i atom from the interaction with this j atom. */
340             velec            = _mm_and_ps(velec,cutoff_mask);
341             velecsum         = _mm_add_ps(velecsum,velec);
342
343             fscal            = felec;
344
345             fscal            = _mm_and_ps(fscal,cutoff_mask);
346
347              /* Update vectorial force */
348             fix1             = _mm_macc_ps(dx10,fscal,fix1);
349             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
350             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
351
352             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
353             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
354             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
355
356             }
357
358             /**************************
359              * CALCULATE INTERACTIONS *
360              **************************/
361
362             if (gmx_mm_any_lt(rsq20,rcutoff2))
363             {
364
365             r20              = _mm_mul_ps(rsq20,rinv20);
366
367             /* Compute parameters for interactions between i and j atoms */
368             qq20             = _mm_mul_ps(iq2,jq0);
369
370             /* EWALD ELECTROSTATICS */
371
372             /* Analytical PME correction */
373             zeta2            = _mm_mul_ps(beta2,rsq20);
374             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
375             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
376             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
377             felec            = _mm_mul_ps(qq20,felec);
378             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
379             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
380             velec            = _mm_mul_ps(qq20,velec);
381
382             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
383
384             /* Update potential sum for this i atom from the interaction with this j atom. */
385             velec            = _mm_and_ps(velec,cutoff_mask);
386             velecsum         = _mm_add_ps(velecsum,velec);
387
388             fscal            = felec;
389
390             fscal            = _mm_and_ps(fscal,cutoff_mask);
391
392              /* Update vectorial force */
393             fix2             = _mm_macc_ps(dx20,fscal,fix2);
394             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
395             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
396
397             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
398             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
399             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
400
401             }
402
403             fjptrA             = f+j_coord_offsetA;
404             fjptrB             = f+j_coord_offsetB;
405             fjptrC             = f+j_coord_offsetC;
406             fjptrD             = f+j_coord_offsetD;
407
408             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
409
410             /* Inner loop uses 117 flops */
411         }
412
413         if(jidx<j_index_end)
414         {
415
416             /* Get j neighbor index, and coordinate index */
417             jnrlistA         = jjnr[jidx];
418             jnrlistB         = jjnr[jidx+1];
419             jnrlistC         = jjnr[jidx+2];
420             jnrlistD         = jjnr[jidx+3];
421             /* Sign of each element will be negative for non-real atoms.
422              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
423              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
424              */
425             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
426             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
427             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
428             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
429             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
430             j_coord_offsetA  = DIM*jnrA;
431             j_coord_offsetB  = DIM*jnrB;
432             j_coord_offsetC  = DIM*jnrC;
433             j_coord_offsetD  = DIM*jnrD;
434
435             /* load j atom coordinates */
436             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
437                                               x+j_coord_offsetC,x+j_coord_offsetD,
438                                               &jx0,&jy0,&jz0);
439
440             /* Calculate displacement vector */
441             dx00             = _mm_sub_ps(ix0,jx0);
442             dy00             = _mm_sub_ps(iy0,jy0);
443             dz00             = _mm_sub_ps(iz0,jz0);
444             dx10             = _mm_sub_ps(ix1,jx0);
445             dy10             = _mm_sub_ps(iy1,jy0);
446             dz10             = _mm_sub_ps(iz1,jz0);
447             dx20             = _mm_sub_ps(ix2,jx0);
448             dy20             = _mm_sub_ps(iy2,jy0);
449             dz20             = _mm_sub_ps(iz2,jz0);
450
451             /* Calculate squared distance and things based on it */
452             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
453             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
454             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
455
456             rinv00           = gmx_mm_invsqrt_ps(rsq00);
457             rinv10           = gmx_mm_invsqrt_ps(rsq10);
458             rinv20           = gmx_mm_invsqrt_ps(rsq20);
459
460             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
461             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
462             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
463
464             /* Load parameters for j particles */
465             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
466                                                               charge+jnrC+0,charge+jnrD+0);
467             vdwjidx0A        = 2*vdwtype[jnrA+0];
468             vdwjidx0B        = 2*vdwtype[jnrB+0];
469             vdwjidx0C        = 2*vdwtype[jnrC+0];
470             vdwjidx0D        = 2*vdwtype[jnrD+0];
471
472             fjx0             = _mm_setzero_ps();
473             fjy0             = _mm_setzero_ps();
474             fjz0             = _mm_setzero_ps();
475
476             /**************************
477              * CALCULATE INTERACTIONS *
478              **************************/
479
480             if (gmx_mm_any_lt(rsq00,rcutoff2))
481             {
482
483             r00              = _mm_mul_ps(rsq00,rinv00);
484             r00              = _mm_andnot_ps(dummy_mask,r00);
485
486             /* Compute parameters for interactions between i and j atoms */
487             qq00             = _mm_mul_ps(iq0,jq0);
488             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
489                                          vdwparam+vdwioffset0+vdwjidx0B,
490                                          vdwparam+vdwioffset0+vdwjidx0C,
491                                          vdwparam+vdwioffset0+vdwjidx0D,
492                                          &c6_00,&c12_00);
493
494             /* EWALD ELECTROSTATICS */
495
496             /* Analytical PME correction */
497             zeta2            = _mm_mul_ps(beta2,rsq00);
498             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
499             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
500             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
501             felec            = _mm_mul_ps(qq00,felec);
502             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
503             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
504             velec            = _mm_mul_ps(qq00,velec);
505
506             /* LENNARD-JONES DISPERSION/REPULSION */
507
508             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
509             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
510             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
511             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
512                                           _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
513             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
514
515             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
516
517             /* Update potential sum for this i atom from the interaction with this j atom. */
518             velec            = _mm_and_ps(velec,cutoff_mask);
519             velec            = _mm_andnot_ps(dummy_mask,velec);
520             velecsum         = _mm_add_ps(velecsum,velec);
521             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
522             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
523             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
524
525             fscal            = _mm_add_ps(felec,fvdw);
526
527             fscal            = _mm_and_ps(fscal,cutoff_mask);
528
529             fscal            = _mm_andnot_ps(dummy_mask,fscal);
530
531              /* Update vectorial force */
532             fix0             = _mm_macc_ps(dx00,fscal,fix0);
533             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
534             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
535
536             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
537             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
538             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
539
540             }
541
542             /**************************
543              * CALCULATE INTERACTIONS *
544              **************************/
545
546             if (gmx_mm_any_lt(rsq10,rcutoff2))
547             {
548
549             r10              = _mm_mul_ps(rsq10,rinv10);
550             r10              = _mm_andnot_ps(dummy_mask,r10);
551
552             /* Compute parameters for interactions between i and j atoms */
553             qq10             = _mm_mul_ps(iq1,jq0);
554
555             /* EWALD ELECTROSTATICS */
556
557             /* Analytical PME correction */
558             zeta2            = _mm_mul_ps(beta2,rsq10);
559             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
560             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
561             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
562             felec            = _mm_mul_ps(qq10,felec);
563             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
564             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv10,sh_ewald));
565             velec            = _mm_mul_ps(qq10,velec);
566
567             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
568
569             /* Update potential sum for this i atom from the interaction with this j atom. */
570             velec            = _mm_and_ps(velec,cutoff_mask);
571             velec            = _mm_andnot_ps(dummy_mask,velec);
572             velecsum         = _mm_add_ps(velecsum,velec);
573
574             fscal            = felec;
575
576             fscal            = _mm_and_ps(fscal,cutoff_mask);
577
578             fscal            = _mm_andnot_ps(dummy_mask,fscal);
579
580              /* Update vectorial force */
581             fix1             = _mm_macc_ps(dx10,fscal,fix1);
582             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
583             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
584
585             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
586             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
587             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
588
589             }
590
591             /**************************
592              * CALCULATE INTERACTIONS *
593              **************************/
594
595             if (gmx_mm_any_lt(rsq20,rcutoff2))
596             {
597
598             r20              = _mm_mul_ps(rsq20,rinv20);
599             r20              = _mm_andnot_ps(dummy_mask,r20);
600
601             /* Compute parameters for interactions between i and j atoms */
602             qq20             = _mm_mul_ps(iq2,jq0);
603
604             /* EWALD ELECTROSTATICS */
605
606             /* Analytical PME correction */
607             zeta2            = _mm_mul_ps(beta2,rsq20);
608             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
609             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
610             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
611             felec            = _mm_mul_ps(qq20,felec);
612             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
613             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv20,sh_ewald));
614             velec            = _mm_mul_ps(qq20,velec);
615
616             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
617
618             /* Update potential sum for this i atom from the interaction with this j atom. */
619             velec            = _mm_and_ps(velec,cutoff_mask);
620             velec            = _mm_andnot_ps(dummy_mask,velec);
621             velecsum         = _mm_add_ps(velecsum,velec);
622
623             fscal            = felec;
624
625             fscal            = _mm_and_ps(fscal,cutoff_mask);
626
627             fscal            = _mm_andnot_ps(dummy_mask,fscal);
628
629              /* Update vectorial force */
630             fix2             = _mm_macc_ps(dx20,fscal,fix2);
631             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
632             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
633
634             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
635             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
636             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
637
638             }
639
640             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
641             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
642             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
643             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
644
645             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
646
647             /* Inner loop uses 120 flops */
648         }
649
650         /* End of innermost loop */
651
652         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
653                                               f+i_coord_offset,fshift+i_shift_offset);
654
655         ggid                        = gid[iidx];
656         /* Update potential energies */
657         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
658         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
659
660         /* Increment number of inner iterations */
661         inneriter                  += j_index_end - j_index_start;
662
663         /* Outer loop uses 20 flops */
664     }
665
666     /* Increment number of outer iterations */
667     outeriter        += nri;
668
669     /* Update outer/inner flops */
670
671     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*120);
672 }
673 /*
674  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_avx_128_fma_single
675  * Electrostatics interaction: Ewald
676  * VdW interaction:            LennardJones
677  * Geometry:                   Water3-Particle
678  * Calculate force/pot:        Force
679  */
680 void
681 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_avx_128_fma_single
682                     (t_nblist                    * gmx_restrict       nlist,
683                      rvec                        * gmx_restrict          xx,
684                      rvec                        * gmx_restrict          ff,
685                      t_forcerec                  * gmx_restrict          fr,
686                      t_mdatoms                   * gmx_restrict     mdatoms,
687                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
688                      t_nrnb                      * gmx_restrict        nrnb)
689 {
690     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
691      * just 0 for non-waters.
692      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
693      * jnr indices corresponding to data put in the four positions in the SIMD register.
694      */
695     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
696     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
697     int              jnrA,jnrB,jnrC,jnrD;
698     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
699     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
700     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
701     real             rcutoff_scalar;
702     real             *shiftvec,*fshift,*x,*f;
703     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
704     real             scratch[4*DIM];
705     __m128           fscal,rcutoff,rcutoff2,jidxall;
706     int              vdwioffset0;
707     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
708     int              vdwioffset1;
709     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
710     int              vdwioffset2;
711     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
712     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
713     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
714     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
715     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
716     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
717     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
718     real             *charge;
719     int              nvdwtype;
720     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
721     int              *vdwtype;
722     real             *vdwparam;
723     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
724     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
725     __m128i          ewitab;
726     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
727     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
728     real             *ewtab;
729     __m128           dummy_mask,cutoff_mask;
730     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
731     __m128           one     = _mm_set1_ps(1.0);
732     __m128           two     = _mm_set1_ps(2.0);
733     x                = xx[0];
734     f                = ff[0];
735
736     nri              = nlist->nri;
737     iinr             = nlist->iinr;
738     jindex           = nlist->jindex;
739     jjnr             = nlist->jjnr;
740     shiftidx         = nlist->shift;
741     gid              = nlist->gid;
742     shiftvec         = fr->shift_vec[0];
743     fshift           = fr->fshift[0];
744     facel            = _mm_set1_ps(fr->epsfac);
745     charge           = mdatoms->chargeA;
746     nvdwtype         = fr->ntype;
747     vdwparam         = fr->nbfp;
748     vdwtype          = mdatoms->typeA;
749
750     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
751     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
752     beta2            = _mm_mul_ps(beta,beta);
753     beta3            = _mm_mul_ps(beta,beta2);
754     ewtab            = fr->ic->tabq_coul_F;
755     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
756     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
757
758     /* Setup water-specific parameters */
759     inr              = nlist->iinr[0];
760     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
761     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
762     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
763     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
764
765     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
766     rcutoff_scalar   = fr->rcoulomb;
767     rcutoff          = _mm_set1_ps(rcutoff_scalar);
768     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
769
770     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
771     rvdw             = _mm_set1_ps(fr->rvdw);
772
773     /* Avoid stupid compiler warnings */
774     jnrA = jnrB = jnrC = jnrD = 0;
775     j_coord_offsetA = 0;
776     j_coord_offsetB = 0;
777     j_coord_offsetC = 0;
778     j_coord_offsetD = 0;
779
780     outeriter        = 0;
781     inneriter        = 0;
782
783     for(iidx=0;iidx<4*DIM;iidx++)
784     {
785         scratch[iidx] = 0.0;
786     }
787
788     /* Start outer loop over neighborlists */
789     for(iidx=0; iidx<nri; iidx++)
790     {
791         /* Load shift vector for this list */
792         i_shift_offset   = DIM*shiftidx[iidx];
793
794         /* Load limits for loop over neighbors */
795         j_index_start    = jindex[iidx];
796         j_index_end      = jindex[iidx+1];
797
798         /* Get outer coordinate index */
799         inr              = iinr[iidx];
800         i_coord_offset   = DIM*inr;
801
802         /* Load i particle coords and add shift vector */
803         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
804                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
805
806         fix0             = _mm_setzero_ps();
807         fiy0             = _mm_setzero_ps();
808         fiz0             = _mm_setzero_ps();
809         fix1             = _mm_setzero_ps();
810         fiy1             = _mm_setzero_ps();
811         fiz1             = _mm_setzero_ps();
812         fix2             = _mm_setzero_ps();
813         fiy2             = _mm_setzero_ps();
814         fiz2             = _mm_setzero_ps();
815
816         /* Start inner kernel loop */
817         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
818         {
819
820             /* Get j neighbor index, and coordinate index */
821             jnrA             = jjnr[jidx];
822             jnrB             = jjnr[jidx+1];
823             jnrC             = jjnr[jidx+2];
824             jnrD             = jjnr[jidx+3];
825             j_coord_offsetA  = DIM*jnrA;
826             j_coord_offsetB  = DIM*jnrB;
827             j_coord_offsetC  = DIM*jnrC;
828             j_coord_offsetD  = DIM*jnrD;
829
830             /* load j atom coordinates */
831             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
832                                               x+j_coord_offsetC,x+j_coord_offsetD,
833                                               &jx0,&jy0,&jz0);
834
835             /* Calculate displacement vector */
836             dx00             = _mm_sub_ps(ix0,jx0);
837             dy00             = _mm_sub_ps(iy0,jy0);
838             dz00             = _mm_sub_ps(iz0,jz0);
839             dx10             = _mm_sub_ps(ix1,jx0);
840             dy10             = _mm_sub_ps(iy1,jy0);
841             dz10             = _mm_sub_ps(iz1,jz0);
842             dx20             = _mm_sub_ps(ix2,jx0);
843             dy20             = _mm_sub_ps(iy2,jy0);
844             dz20             = _mm_sub_ps(iz2,jz0);
845
846             /* Calculate squared distance and things based on it */
847             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
848             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
849             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
850
851             rinv00           = gmx_mm_invsqrt_ps(rsq00);
852             rinv10           = gmx_mm_invsqrt_ps(rsq10);
853             rinv20           = gmx_mm_invsqrt_ps(rsq20);
854
855             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
856             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
857             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
858
859             /* Load parameters for j particles */
860             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
861                                                               charge+jnrC+0,charge+jnrD+0);
862             vdwjidx0A        = 2*vdwtype[jnrA+0];
863             vdwjidx0B        = 2*vdwtype[jnrB+0];
864             vdwjidx0C        = 2*vdwtype[jnrC+0];
865             vdwjidx0D        = 2*vdwtype[jnrD+0];
866
867             fjx0             = _mm_setzero_ps();
868             fjy0             = _mm_setzero_ps();
869             fjz0             = _mm_setzero_ps();
870
871             /**************************
872              * CALCULATE INTERACTIONS *
873              **************************/
874
875             if (gmx_mm_any_lt(rsq00,rcutoff2))
876             {
877
878             r00              = _mm_mul_ps(rsq00,rinv00);
879
880             /* Compute parameters for interactions between i and j atoms */
881             qq00             = _mm_mul_ps(iq0,jq0);
882             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
883                                          vdwparam+vdwioffset0+vdwjidx0B,
884                                          vdwparam+vdwioffset0+vdwjidx0C,
885                                          vdwparam+vdwioffset0+vdwjidx0D,
886                                          &c6_00,&c12_00);
887
888             /* EWALD ELECTROSTATICS */
889
890             /* Analytical PME correction */
891             zeta2            = _mm_mul_ps(beta2,rsq00);
892             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
893             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
894             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
895             felec            = _mm_mul_ps(qq00,felec);
896
897             /* LENNARD-JONES DISPERSION/REPULSION */
898
899             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
900             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
901
902             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
903
904             fscal            = _mm_add_ps(felec,fvdw);
905
906             fscal            = _mm_and_ps(fscal,cutoff_mask);
907
908              /* Update vectorial force */
909             fix0             = _mm_macc_ps(dx00,fscal,fix0);
910             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
911             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
912
913             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
914             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
915             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
916
917             }
918
919             /**************************
920              * CALCULATE INTERACTIONS *
921              **************************/
922
923             if (gmx_mm_any_lt(rsq10,rcutoff2))
924             {
925
926             r10              = _mm_mul_ps(rsq10,rinv10);
927
928             /* Compute parameters for interactions between i and j atoms */
929             qq10             = _mm_mul_ps(iq1,jq0);
930
931             /* EWALD ELECTROSTATICS */
932
933             /* Analytical PME correction */
934             zeta2            = _mm_mul_ps(beta2,rsq10);
935             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
936             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
937             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
938             felec            = _mm_mul_ps(qq10,felec);
939
940             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
941
942             fscal            = felec;
943
944             fscal            = _mm_and_ps(fscal,cutoff_mask);
945
946              /* Update vectorial force */
947             fix1             = _mm_macc_ps(dx10,fscal,fix1);
948             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
949             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
950
951             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
952             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
953             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
954
955             }
956
957             /**************************
958              * CALCULATE INTERACTIONS *
959              **************************/
960
961             if (gmx_mm_any_lt(rsq20,rcutoff2))
962             {
963
964             r20              = _mm_mul_ps(rsq20,rinv20);
965
966             /* Compute parameters for interactions between i and j atoms */
967             qq20             = _mm_mul_ps(iq2,jq0);
968
969             /* EWALD ELECTROSTATICS */
970
971             /* Analytical PME correction */
972             zeta2            = _mm_mul_ps(beta2,rsq20);
973             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
974             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
975             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
976             felec            = _mm_mul_ps(qq20,felec);
977
978             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
979
980             fscal            = felec;
981
982             fscal            = _mm_and_ps(fscal,cutoff_mask);
983
984              /* Update vectorial force */
985             fix2             = _mm_macc_ps(dx20,fscal,fix2);
986             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
987             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
988
989             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
990             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
991             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
992
993             }
994
995             fjptrA             = f+j_coord_offsetA;
996             fjptrB             = f+j_coord_offsetB;
997             fjptrC             = f+j_coord_offsetC;
998             fjptrD             = f+j_coord_offsetD;
999
1000             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1001
1002             /* Inner loop uses 100 flops */
1003         }
1004
1005         if(jidx<j_index_end)
1006         {
1007
1008             /* Get j neighbor index, and coordinate index */
1009             jnrlistA         = jjnr[jidx];
1010             jnrlistB         = jjnr[jidx+1];
1011             jnrlistC         = jjnr[jidx+2];
1012             jnrlistD         = jjnr[jidx+3];
1013             /* Sign of each element will be negative for non-real atoms.
1014              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1015              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1016              */
1017             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1018             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1019             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1020             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1021             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1022             j_coord_offsetA  = DIM*jnrA;
1023             j_coord_offsetB  = DIM*jnrB;
1024             j_coord_offsetC  = DIM*jnrC;
1025             j_coord_offsetD  = DIM*jnrD;
1026
1027             /* load j atom coordinates */
1028             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1029                                               x+j_coord_offsetC,x+j_coord_offsetD,
1030                                               &jx0,&jy0,&jz0);
1031
1032             /* Calculate displacement vector */
1033             dx00             = _mm_sub_ps(ix0,jx0);
1034             dy00             = _mm_sub_ps(iy0,jy0);
1035             dz00             = _mm_sub_ps(iz0,jz0);
1036             dx10             = _mm_sub_ps(ix1,jx0);
1037             dy10             = _mm_sub_ps(iy1,jy0);
1038             dz10             = _mm_sub_ps(iz1,jz0);
1039             dx20             = _mm_sub_ps(ix2,jx0);
1040             dy20             = _mm_sub_ps(iy2,jy0);
1041             dz20             = _mm_sub_ps(iz2,jz0);
1042
1043             /* Calculate squared distance and things based on it */
1044             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1045             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1046             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1047
1048             rinv00           = gmx_mm_invsqrt_ps(rsq00);
1049             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1050             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1051
1052             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1053             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1054             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1055
1056             /* Load parameters for j particles */
1057             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1058                                                               charge+jnrC+0,charge+jnrD+0);
1059             vdwjidx0A        = 2*vdwtype[jnrA+0];
1060             vdwjidx0B        = 2*vdwtype[jnrB+0];
1061             vdwjidx0C        = 2*vdwtype[jnrC+0];
1062             vdwjidx0D        = 2*vdwtype[jnrD+0];
1063
1064             fjx0             = _mm_setzero_ps();
1065             fjy0             = _mm_setzero_ps();
1066             fjz0             = _mm_setzero_ps();
1067
1068             /**************************
1069              * CALCULATE INTERACTIONS *
1070              **************************/
1071
1072             if (gmx_mm_any_lt(rsq00,rcutoff2))
1073             {
1074
1075             r00              = _mm_mul_ps(rsq00,rinv00);
1076             r00              = _mm_andnot_ps(dummy_mask,r00);
1077
1078             /* Compute parameters for interactions between i and j atoms */
1079             qq00             = _mm_mul_ps(iq0,jq0);
1080             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1081                                          vdwparam+vdwioffset0+vdwjidx0B,
1082                                          vdwparam+vdwioffset0+vdwjidx0C,
1083                                          vdwparam+vdwioffset0+vdwjidx0D,
1084                                          &c6_00,&c12_00);
1085
1086             /* EWALD ELECTROSTATICS */
1087
1088             /* Analytical PME correction */
1089             zeta2            = _mm_mul_ps(beta2,rsq00);
1090             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
1091             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1092             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1093             felec            = _mm_mul_ps(qq00,felec);
1094
1095             /* LENNARD-JONES DISPERSION/REPULSION */
1096
1097             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1098             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1099
1100             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1101
1102             fscal            = _mm_add_ps(felec,fvdw);
1103
1104             fscal            = _mm_and_ps(fscal,cutoff_mask);
1105
1106             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1107
1108              /* Update vectorial force */
1109             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1110             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1111             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1112
1113             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1114             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1115             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1116
1117             }
1118
1119             /**************************
1120              * CALCULATE INTERACTIONS *
1121              **************************/
1122
1123             if (gmx_mm_any_lt(rsq10,rcutoff2))
1124             {
1125
1126             r10              = _mm_mul_ps(rsq10,rinv10);
1127             r10              = _mm_andnot_ps(dummy_mask,r10);
1128
1129             /* Compute parameters for interactions between i and j atoms */
1130             qq10             = _mm_mul_ps(iq1,jq0);
1131
1132             /* EWALD ELECTROSTATICS */
1133
1134             /* Analytical PME correction */
1135             zeta2            = _mm_mul_ps(beta2,rsq10);
1136             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
1137             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1138             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1139             felec            = _mm_mul_ps(qq10,felec);
1140
1141             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1142
1143             fscal            = felec;
1144
1145             fscal            = _mm_and_ps(fscal,cutoff_mask);
1146
1147             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1148
1149              /* Update vectorial force */
1150             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1151             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1152             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1153
1154             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1155             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1156             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1157
1158             }
1159
1160             /**************************
1161              * CALCULATE INTERACTIONS *
1162              **************************/
1163
1164             if (gmx_mm_any_lt(rsq20,rcutoff2))
1165             {
1166
1167             r20              = _mm_mul_ps(rsq20,rinv20);
1168             r20              = _mm_andnot_ps(dummy_mask,r20);
1169
1170             /* Compute parameters for interactions between i and j atoms */
1171             qq20             = _mm_mul_ps(iq2,jq0);
1172
1173             /* EWALD ELECTROSTATICS */
1174
1175             /* Analytical PME correction */
1176             zeta2            = _mm_mul_ps(beta2,rsq20);
1177             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1178             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1179             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1180             felec            = _mm_mul_ps(qq20,felec);
1181
1182             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1183
1184             fscal            = felec;
1185
1186             fscal            = _mm_and_ps(fscal,cutoff_mask);
1187
1188             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1189
1190              /* Update vectorial force */
1191             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1192             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1193             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1194
1195             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1196             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1197             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1198
1199             }
1200
1201             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1202             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1203             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1204             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1205
1206             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1207
1208             /* Inner loop uses 103 flops */
1209         }
1210
1211         /* End of innermost loop */
1212
1213         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1214                                               f+i_coord_offset,fshift+i_shift_offset);
1215
1216         /* Increment number of inner iterations */
1217         inneriter                  += j_index_end - j_index_start;
1218
1219         /* Outer loop uses 18 flops */
1220     }
1221
1222     /* Increment number of outer iterations */
1223     outeriter        += nri;
1224
1225     /* Update outer/inner flops */
1226
1227     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*103);
1228 }