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