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