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