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