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