Compile nonbonded kernels as C++
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRFCut_VdwNone_GeomW4W4_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_VdwNone_GeomW4W4_VF_avx_128_fma_single
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            None
53  * Geometry:                   Water4-Water4
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRFCut_VdwNone_GeomW4W4_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              vdwioffset1;
83     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
84     int              vdwioffset2;
85     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86     int              vdwioffset3;
87     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
89     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
90     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
91     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
92     int              vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
93     __m128           jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
94     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
95     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
96     __m128           dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
97     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
98     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
99     __m128           dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
100     __m128           dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
101     __m128           dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
102     __m128           dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
103     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
104     real             *charge;
105     __m128           dummy_mask,cutoff_mask;
106     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107     __m128           one     = _mm_set1_ps(1.0);
108     __m128           two     = _mm_set1_ps(2.0);
109     x                = xx[0];
110     f                = ff[0];
111
112     nri              = nlist->nri;
113     iinr             = nlist->iinr;
114     jindex           = nlist->jindex;
115     jjnr             = nlist->jjnr;
116     shiftidx         = nlist->shift;
117     gid              = nlist->gid;
118     shiftvec         = fr->shift_vec[0];
119     fshift           = fr->fshift[0];
120     facel            = _mm_set1_ps(fr->ic->epsfac);
121     charge           = mdatoms->chargeA;
122     krf              = _mm_set1_ps(fr->ic->k_rf);
123     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
124     crf              = _mm_set1_ps(fr->ic->c_rf);
125
126     /* Setup water-specific parameters */
127     inr              = nlist->iinr[0];
128     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
129     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
130     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
131
132     jq1              = _mm_set1_ps(charge[inr+1]);
133     jq2              = _mm_set1_ps(charge[inr+2]);
134     jq3              = _mm_set1_ps(charge[inr+3]);
135     qq11             = _mm_mul_ps(iq1,jq1);
136     qq12             = _mm_mul_ps(iq1,jq2);
137     qq13             = _mm_mul_ps(iq1,jq3);
138     qq21             = _mm_mul_ps(iq2,jq1);
139     qq22             = _mm_mul_ps(iq2,jq2);
140     qq23             = _mm_mul_ps(iq2,jq3);
141     qq31             = _mm_mul_ps(iq3,jq1);
142     qq32             = _mm_mul_ps(iq3,jq2);
143     qq33             = _mm_mul_ps(iq3,jq3);
144
145     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
146     rcutoff_scalar   = fr->ic->rcoulomb;
147     rcutoff          = _mm_set1_ps(rcutoff_scalar);
148     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
149
150     /* Avoid stupid compiler warnings */
151     jnrA = jnrB = jnrC = jnrD = 0;
152     j_coord_offsetA = 0;
153     j_coord_offsetB = 0;
154     j_coord_offsetC = 0;
155     j_coord_offsetD = 0;
156
157     outeriter        = 0;
158     inneriter        = 0;
159
160     for(iidx=0;iidx<4*DIM;iidx++)
161     {
162         scratch[iidx] = 0.0;
163     }
164
165     /* Start outer loop over neighborlists */
166     for(iidx=0; iidx<nri; iidx++)
167     {
168         /* Load shift vector for this list */
169         i_shift_offset   = DIM*shiftidx[iidx];
170
171         /* Load limits for loop over neighbors */
172         j_index_start    = jindex[iidx];
173         j_index_end      = jindex[iidx+1];
174
175         /* Get outer coordinate index */
176         inr              = iinr[iidx];
177         i_coord_offset   = DIM*inr;
178
179         /* Load i particle coords and add shift vector */
180         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
181                                                  &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
182
183         fix1             = _mm_setzero_ps();
184         fiy1             = _mm_setzero_ps();
185         fiz1             = _mm_setzero_ps();
186         fix2             = _mm_setzero_ps();
187         fiy2             = _mm_setzero_ps();
188         fiz2             = _mm_setzero_ps();
189         fix3             = _mm_setzero_ps();
190         fiy3             = _mm_setzero_ps();
191         fiz3             = _mm_setzero_ps();
192
193         /* Reset potential sums */
194         velecsum         = _mm_setzero_ps();
195
196         /* Start inner kernel loop */
197         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
198         {
199
200             /* Get j neighbor index, and coordinate index */
201             jnrA             = jjnr[jidx];
202             jnrB             = jjnr[jidx+1];
203             jnrC             = jjnr[jidx+2];
204             jnrD             = jjnr[jidx+3];
205             j_coord_offsetA  = DIM*jnrA;
206             j_coord_offsetB  = DIM*jnrB;
207             j_coord_offsetC  = DIM*jnrC;
208             j_coord_offsetD  = DIM*jnrD;
209
210             /* load j atom coordinates */
211             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
212                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
213                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
214
215             /* Calculate displacement vector */
216             dx11             = _mm_sub_ps(ix1,jx1);
217             dy11             = _mm_sub_ps(iy1,jy1);
218             dz11             = _mm_sub_ps(iz1,jz1);
219             dx12             = _mm_sub_ps(ix1,jx2);
220             dy12             = _mm_sub_ps(iy1,jy2);
221             dz12             = _mm_sub_ps(iz1,jz2);
222             dx13             = _mm_sub_ps(ix1,jx3);
223             dy13             = _mm_sub_ps(iy1,jy3);
224             dz13             = _mm_sub_ps(iz1,jz3);
225             dx21             = _mm_sub_ps(ix2,jx1);
226             dy21             = _mm_sub_ps(iy2,jy1);
227             dz21             = _mm_sub_ps(iz2,jz1);
228             dx22             = _mm_sub_ps(ix2,jx2);
229             dy22             = _mm_sub_ps(iy2,jy2);
230             dz22             = _mm_sub_ps(iz2,jz2);
231             dx23             = _mm_sub_ps(ix2,jx3);
232             dy23             = _mm_sub_ps(iy2,jy3);
233             dz23             = _mm_sub_ps(iz2,jz3);
234             dx31             = _mm_sub_ps(ix3,jx1);
235             dy31             = _mm_sub_ps(iy3,jy1);
236             dz31             = _mm_sub_ps(iz3,jz1);
237             dx32             = _mm_sub_ps(ix3,jx2);
238             dy32             = _mm_sub_ps(iy3,jy2);
239             dz32             = _mm_sub_ps(iz3,jz2);
240             dx33             = _mm_sub_ps(ix3,jx3);
241             dy33             = _mm_sub_ps(iy3,jy3);
242             dz33             = _mm_sub_ps(iz3,jz3);
243
244             /* Calculate squared distance and things based on it */
245             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
246             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
247             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
248             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
249             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
250             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
251             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
252             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
253             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
254
255             rinv11           = avx128fma_invsqrt_f(rsq11);
256             rinv12           = avx128fma_invsqrt_f(rsq12);
257             rinv13           = avx128fma_invsqrt_f(rsq13);
258             rinv21           = avx128fma_invsqrt_f(rsq21);
259             rinv22           = avx128fma_invsqrt_f(rsq22);
260             rinv23           = avx128fma_invsqrt_f(rsq23);
261             rinv31           = avx128fma_invsqrt_f(rsq31);
262             rinv32           = avx128fma_invsqrt_f(rsq32);
263             rinv33           = avx128fma_invsqrt_f(rsq33);
264
265             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
266             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
267             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
268             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
269             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
270             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
271             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
272             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
273             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
274
275             fjx1             = _mm_setzero_ps();
276             fjy1             = _mm_setzero_ps();
277             fjz1             = _mm_setzero_ps();
278             fjx2             = _mm_setzero_ps();
279             fjy2             = _mm_setzero_ps();
280             fjz2             = _mm_setzero_ps();
281             fjx3             = _mm_setzero_ps();
282             fjy3             = _mm_setzero_ps();
283             fjz3             = _mm_setzero_ps();
284
285             /**************************
286              * CALCULATE INTERACTIONS *
287              **************************/
288
289             if (gmx_mm_any_lt(rsq11,rcutoff2))
290             {
291
292             /* REACTION-FIELD ELECTROSTATICS */
293             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
294             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
295
296             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
297
298             /* Update potential sum for this i atom from the interaction with this j atom. */
299             velec            = _mm_and_ps(velec,cutoff_mask);
300             velecsum         = _mm_add_ps(velecsum,velec);
301
302             fscal            = felec;
303
304             fscal            = _mm_and_ps(fscal,cutoff_mask);
305
306              /* Update vectorial force */
307             fix1             = _mm_macc_ps(dx11,fscal,fix1);
308             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
309             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
310
311             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
312             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
313             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
314
315             }
316
317             /**************************
318              * CALCULATE INTERACTIONS *
319              **************************/
320
321             if (gmx_mm_any_lt(rsq12,rcutoff2))
322             {
323
324             /* REACTION-FIELD ELECTROSTATICS */
325             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
326             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
327
328             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
329
330             /* Update potential sum for this i atom from the interaction with this j atom. */
331             velec            = _mm_and_ps(velec,cutoff_mask);
332             velecsum         = _mm_add_ps(velecsum,velec);
333
334             fscal            = felec;
335
336             fscal            = _mm_and_ps(fscal,cutoff_mask);
337
338              /* Update vectorial force */
339             fix1             = _mm_macc_ps(dx12,fscal,fix1);
340             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
341             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
342
343             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
344             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
345             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
346
347             }
348
349             /**************************
350              * CALCULATE INTERACTIONS *
351              **************************/
352
353             if (gmx_mm_any_lt(rsq13,rcutoff2))
354             {
355
356             /* REACTION-FIELD ELECTROSTATICS */
357             velec            = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
358             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
359
360             cutoff_mask      = _mm_cmplt_ps(rsq13,rcutoff2);
361
362             /* Update potential sum for this i atom from the interaction with this j atom. */
363             velec            = _mm_and_ps(velec,cutoff_mask);
364             velecsum         = _mm_add_ps(velecsum,velec);
365
366             fscal            = felec;
367
368             fscal            = _mm_and_ps(fscal,cutoff_mask);
369
370              /* Update vectorial force */
371             fix1             = _mm_macc_ps(dx13,fscal,fix1);
372             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
373             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
374
375             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
376             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
377             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
378
379             }
380
381             /**************************
382              * CALCULATE INTERACTIONS *
383              **************************/
384
385             if (gmx_mm_any_lt(rsq21,rcutoff2))
386             {
387
388             /* REACTION-FIELD ELECTROSTATICS */
389             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
390             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
391
392             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
393
394             /* Update potential sum for this i atom from the interaction with this j atom. */
395             velec            = _mm_and_ps(velec,cutoff_mask);
396             velecsum         = _mm_add_ps(velecsum,velec);
397
398             fscal            = felec;
399
400             fscal            = _mm_and_ps(fscal,cutoff_mask);
401
402              /* Update vectorial force */
403             fix2             = _mm_macc_ps(dx21,fscal,fix2);
404             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
405             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
406
407             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
408             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
409             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
410
411             }
412
413             /**************************
414              * CALCULATE INTERACTIONS *
415              **************************/
416
417             if (gmx_mm_any_lt(rsq22,rcutoff2))
418             {
419
420             /* REACTION-FIELD ELECTROSTATICS */
421             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
422             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
423
424             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
425
426             /* Update potential sum for this i atom from the interaction with this j atom. */
427             velec            = _mm_and_ps(velec,cutoff_mask);
428             velecsum         = _mm_add_ps(velecsum,velec);
429
430             fscal            = felec;
431
432             fscal            = _mm_and_ps(fscal,cutoff_mask);
433
434              /* Update vectorial force */
435             fix2             = _mm_macc_ps(dx22,fscal,fix2);
436             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
437             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
438
439             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
440             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
441             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
442
443             }
444
445             /**************************
446              * CALCULATE INTERACTIONS *
447              **************************/
448
449             if (gmx_mm_any_lt(rsq23,rcutoff2))
450             {
451
452             /* REACTION-FIELD ELECTROSTATICS */
453             velec            = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
454             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
455
456             cutoff_mask      = _mm_cmplt_ps(rsq23,rcutoff2);
457
458             /* Update potential sum for this i atom from the interaction with this j atom. */
459             velec            = _mm_and_ps(velec,cutoff_mask);
460             velecsum         = _mm_add_ps(velecsum,velec);
461
462             fscal            = felec;
463
464             fscal            = _mm_and_ps(fscal,cutoff_mask);
465
466              /* Update vectorial force */
467             fix2             = _mm_macc_ps(dx23,fscal,fix2);
468             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
469             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
470
471             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
472             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
473             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
474
475             }
476
477             /**************************
478              * CALCULATE INTERACTIONS *
479              **************************/
480
481             if (gmx_mm_any_lt(rsq31,rcutoff2))
482             {
483
484             /* REACTION-FIELD ELECTROSTATICS */
485             velec            = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
486             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
487
488             cutoff_mask      = _mm_cmplt_ps(rsq31,rcutoff2);
489
490             /* Update potential sum for this i atom from the interaction with this j atom. */
491             velec            = _mm_and_ps(velec,cutoff_mask);
492             velecsum         = _mm_add_ps(velecsum,velec);
493
494             fscal            = felec;
495
496             fscal            = _mm_and_ps(fscal,cutoff_mask);
497
498              /* Update vectorial force */
499             fix3             = _mm_macc_ps(dx31,fscal,fix3);
500             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
501             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
502
503             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
504             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
505             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
506
507             }
508
509             /**************************
510              * CALCULATE INTERACTIONS *
511              **************************/
512
513             if (gmx_mm_any_lt(rsq32,rcutoff2))
514             {
515
516             /* REACTION-FIELD ELECTROSTATICS */
517             velec            = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
518             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
519
520             cutoff_mask      = _mm_cmplt_ps(rsq32,rcutoff2);
521
522             /* Update potential sum for this i atom from the interaction with this j atom. */
523             velec            = _mm_and_ps(velec,cutoff_mask);
524             velecsum         = _mm_add_ps(velecsum,velec);
525
526             fscal            = felec;
527
528             fscal            = _mm_and_ps(fscal,cutoff_mask);
529
530              /* Update vectorial force */
531             fix3             = _mm_macc_ps(dx32,fscal,fix3);
532             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
533             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
534
535             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
536             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
537             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
538
539             }
540
541             /**************************
542              * CALCULATE INTERACTIONS *
543              **************************/
544
545             if (gmx_mm_any_lt(rsq33,rcutoff2))
546             {
547
548             /* REACTION-FIELD ELECTROSTATICS */
549             velec            = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
550             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
551
552             cutoff_mask      = _mm_cmplt_ps(rsq33,rcutoff2);
553
554             /* Update potential sum for this i atom from the interaction with this j atom. */
555             velec            = _mm_and_ps(velec,cutoff_mask);
556             velecsum         = _mm_add_ps(velecsum,velec);
557
558             fscal            = felec;
559
560             fscal            = _mm_and_ps(fscal,cutoff_mask);
561
562              /* Update vectorial force */
563             fix3             = _mm_macc_ps(dx33,fscal,fix3);
564             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
565             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
566
567             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
568             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
569             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
570
571             }
572
573             fjptrA             = f+j_coord_offsetA;
574             fjptrB             = f+j_coord_offsetB;
575             fjptrC             = f+j_coord_offsetC;
576             fjptrD             = f+j_coord_offsetD;
577
578             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
579                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
580
581             /* Inner loop uses 351 flops */
582         }
583
584         if(jidx<j_index_end)
585         {
586
587             /* Get j neighbor index, and coordinate index */
588             jnrlistA         = jjnr[jidx];
589             jnrlistB         = jjnr[jidx+1];
590             jnrlistC         = jjnr[jidx+2];
591             jnrlistD         = jjnr[jidx+3];
592             /* Sign of each element will be negative for non-real atoms.
593              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
594              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
595              */
596             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
597             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
598             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
599             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
600             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
601             j_coord_offsetA  = DIM*jnrA;
602             j_coord_offsetB  = DIM*jnrB;
603             j_coord_offsetC  = DIM*jnrC;
604             j_coord_offsetD  = DIM*jnrD;
605
606             /* load j atom coordinates */
607             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
608                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
609                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
610
611             /* Calculate displacement vector */
612             dx11             = _mm_sub_ps(ix1,jx1);
613             dy11             = _mm_sub_ps(iy1,jy1);
614             dz11             = _mm_sub_ps(iz1,jz1);
615             dx12             = _mm_sub_ps(ix1,jx2);
616             dy12             = _mm_sub_ps(iy1,jy2);
617             dz12             = _mm_sub_ps(iz1,jz2);
618             dx13             = _mm_sub_ps(ix1,jx3);
619             dy13             = _mm_sub_ps(iy1,jy3);
620             dz13             = _mm_sub_ps(iz1,jz3);
621             dx21             = _mm_sub_ps(ix2,jx1);
622             dy21             = _mm_sub_ps(iy2,jy1);
623             dz21             = _mm_sub_ps(iz2,jz1);
624             dx22             = _mm_sub_ps(ix2,jx2);
625             dy22             = _mm_sub_ps(iy2,jy2);
626             dz22             = _mm_sub_ps(iz2,jz2);
627             dx23             = _mm_sub_ps(ix2,jx3);
628             dy23             = _mm_sub_ps(iy2,jy3);
629             dz23             = _mm_sub_ps(iz2,jz3);
630             dx31             = _mm_sub_ps(ix3,jx1);
631             dy31             = _mm_sub_ps(iy3,jy1);
632             dz31             = _mm_sub_ps(iz3,jz1);
633             dx32             = _mm_sub_ps(ix3,jx2);
634             dy32             = _mm_sub_ps(iy3,jy2);
635             dz32             = _mm_sub_ps(iz3,jz2);
636             dx33             = _mm_sub_ps(ix3,jx3);
637             dy33             = _mm_sub_ps(iy3,jy3);
638             dz33             = _mm_sub_ps(iz3,jz3);
639
640             /* Calculate squared distance and things based on it */
641             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
642             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
643             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
644             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
645             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
646             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
647             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
648             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
649             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
650
651             rinv11           = avx128fma_invsqrt_f(rsq11);
652             rinv12           = avx128fma_invsqrt_f(rsq12);
653             rinv13           = avx128fma_invsqrt_f(rsq13);
654             rinv21           = avx128fma_invsqrt_f(rsq21);
655             rinv22           = avx128fma_invsqrt_f(rsq22);
656             rinv23           = avx128fma_invsqrt_f(rsq23);
657             rinv31           = avx128fma_invsqrt_f(rsq31);
658             rinv32           = avx128fma_invsqrt_f(rsq32);
659             rinv33           = avx128fma_invsqrt_f(rsq33);
660
661             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
662             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
663             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
664             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
665             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
666             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
667             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
668             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
669             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
670
671             fjx1             = _mm_setzero_ps();
672             fjy1             = _mm_setzero_ps();
673             fjz1             = _mm_setzero_ps();
674             fjx2             = _mm_setzero_ps();
675             fjy2             = _mm_setzero_ps();
676             fjz2             = _mm_setzero_ps();
677             fjx3             = _mm_setzero_ps();
678             fjy3             = _mm_setzero_ps();
679             fjz3             = _mm_setzero_ps();
680
681             /**************************
682              * CALCULATE INTERACTIONS *
683              **************************/
684
685             if (gmx_mm_any_lt(rsq11,rcutoff2))
686             {
687
688             /* REACTION-FIELD ELECTROSTATICS */
689             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
690             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
691
692             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
693
694             /* Update potential sum for this i atom from the interaction with this j atom. */
695             velec            = _mm_and_ps(velec,cutoff_mask);
696             velec            = _mm_andnot_ps(dummy_mask,velec);
697             velecsum         = _mm_add_ps(velecsum,velec);
698
699             fscal            = felec;
700
701             fscal            = _mm_and_ps(fscal,cutoff_mask);
702
703             fscal            = _mm_andnot_ps(dummy_mask,fscal);
704
705              /* Update vectorial force */
706             fix1             = _mm_macc_ps(dx11,fscal,fix1);
707             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
708             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
709
710             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
711             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
712             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
713
714             }
715
716             /**************************
717              * CALCULATE INTERACTIONS *
718              **************************/
719
720             if (gmx_mm_any_lt(rsq12,rcutoff2))
721             {
722
723             /* REACTION-FIELD ELECTROSTATICS */
724             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
725             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
726
727             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
728
729             /* Update potential sum for this i atom from the interaction with this j atom. */
730             velec            = _mm_and_ps(velec,cutoff_mask);
731             velec            = _mm_andnot_ps(dummy_mask,velec);
732             velecsum         = _mm_add_ps(velecsum,velec);
733
734             fscal            = felec;
735
736             fscal            = _mm_and_ps(fscal,cutoff_mask);
737
738             fscal            = _mm_andnot_ps(dummy_mask,fscal);
739
740              /* Update vectorial force */
741             fix1             = _mm_macc_ps(dx12,fscal,fix1);
742             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
743             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
744
745             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
746             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
747             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
748
749             }
750
751             /**************************
752              * CALCULATE INTERACTIONS *
753              **************************/
754
755             if (gmx_mm_any_lt(rsq13,rcutoff2))
756             {
757
758             /* REACTION-FIELD ELECTROSTATICS */
759             velec            = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
760             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
761
762             cutoff_mask      = _mm_cmplt_ps(rsq13,rcutoff2);
763
764             /* Update potential sum for this i atom from the interaction with this j atom. */
765             velec            = _mm_and_ps(velec,cutoff_mask);
766             velec            = _mm_andnot_ps(dummy_mask,velec);
767             velecsum         = _mm_add_ps(velecsum,velec);
768
769             fscal            = felec;
770
771             fscal            = _mm_and_ps(fscal,cutoff_mask);
772
773             fscal            = _mm_andnot_ps(dummy_mask,fscal);
774
775              /* Update vectorial force */
776             fix1             = _mm_macc_ps(dx13,fscal,fix1);
777             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
778             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
779
780             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
781             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
782             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
783
784             }
785
786             /**************************
787              * CALCULATE INTERACTIONS *
788              **************************/
789
790             if (gmx_mm_any_lt(rsq21,rcutoff2))
791             {
792
793             /* REACTION-FIELD ELECTROSTATICS */
794             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
795             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
796
797             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
798
799             /* Update potential sum for this i atom from the interaction with this j atom. */
800             velec            = _mm_and_ps(velec,cutoff_mask);
801             velec            = _mm_andnot_ps(dummy_mask,velec);
802             velecsum         = _mm_add_ps(velecsum,velec);
803
804             fscal            = felec;
805
806             fscal            = _mm_and_ps(fscal,cutoff_mask);
807
808             fscal            = _mm_andnot_ps(dummy_mask,fscal);
809
810              /* Update vectorial force */
811             fix2             = _mm_macc_ps(dx21,fscal,fix2);
812             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
813             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
814
815             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
816             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
817             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
818
819             }
820
821             /**************************
822              * CALCULATE INTERACTIONS *
823              **************************/
824
825             if (gmx_mm_any_lt(rsq22,rcutoff2))
826             {
827
828             /* REACTION-FIELD ELECTROSTATICS */
829             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
830             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
831
832             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
833
834             /* Update potential sum for this i atom from the interaction with this j atom. */
835             velec            = _mm_and_ps(velec,cutoff_mask);
836             velec            = _mm_andnot_ps(dummy_mask,velec);
837             velecsum         = _mm_add_ps(velecsum,velec);
838
839             fscal            = felec;
840
841             fscal            = _mm_and_ps(fscal,cutoff_mask);
842
843             fscal            = _mm_andnot_ps(dummy_mask,fscal);
844
845              /* Update vectorial force */
846             fix2             = _mm_macc_ps(dx22,fscal,fix2);
847             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
848             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
849
850             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
851             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
852             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
853
854             }
855
856             /**************************
857              * CALCULATE INTERACTIONS *
858              **************************/
859
860             if (gmx_mm_any_lt(rsq23,rcutoff2))
861             {
862
863             /* REACTION-FIELD ELECTROSTATICS */
864             velec            = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
865             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
866
867             cutoff_mask      = _mm_cmplt_ps(rsq23,rcutoff2);
868
869             /* Update potential sum for this i atom from the interaction with this j atom. */
870             velec            = _mm_and_ps(velec,cutoff_mask);
871             velec            = _mm_andnot_ps(dummy_mask,velec);
872             velecsum         = _mm_add_ps(velecsum,velec);
873
874             fscal            = felec;
875
876             fscal            = _mm_and_ps(fscal,cutoff_mask);
877
878             fscal            = _mm_andnot_ps(dummy_mask,fscal);
879
880              /* Update vectorial force */
881             fix2             = _mm_macc_ps(dx23,fscal,fix2);
882             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
883             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
884
885             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
886             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
887             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
888
889             }
890
891             /**************************
892              * CALCULATE INTERACTIONS *
893              **************************/
894
895             if (gmx_mm_any_lt(rsq31,rcutoff2))
896             {
897
898             /* REACTION-FIELD ELECTROSTATICS */
899             velec            = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
900             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
901
902             cutoff_mask      = _mm_cmplt_ps(rsq31,rcutoff2);
903
904             /* Update potential sum for this i atom from the interaction with this j atom. */
905             velec            = _mm_and_ps(velec,cutoff_mask);
906             velec            = _mm_andnot_ps(dummy_mask,velec);
907             velecsum         = _mm_add_ps(velecsum,velec);
908
909             fscal            = felec;
910
911             fscal            = _mm_and_ps(fscal,cutoff_mask);
912
913             fscal            = _mm_andnot_ps(dummy_mask,fscal);
914
915              /* Update vectorial force */
916             fix3             = _mm_macc_ps(dx31,fscal,fix3);
917             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
918             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
919
920             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
921             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
922             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
923
924             }
925
926             /**************************
927              * CALCULATE INTERACTIONS *
928              **************************/
929
930             if (gmx_mm_any_lt(rsq32,rcutoff2))
931             {
932
933             /* REACTION-FIELD ELECTROSTATICS */
934             velec            = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
935             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
936
937             cutoff_mask      = _mm_cmplt_ps(rsq32,rcutoff2);
938
939             /* Update potential sum for this i atom from the interaction with this j atom. */
940             velec            = _mm_and_ps(velec,cutoff_mask);
941             velec            = _mm_andnot_ps(dummy_mask,velec);
942             velecsum         = _mm_add_ps(velecsum,velec);
943
944             fscal            = felec;
945
946             fscal            = _mm_and_ps(fscal,cutoff_mask);
947
948             fscal            = _mm_andnot_ps(dummy_mask,fscal);
949
950              /* Update vectorial force */
951             fix3             = _mm_macc_ps(dx32,fscal,fix3);
952             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
953             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
954
955             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
956             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
957             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
958
959             }
960
961             /**************************
962              * CALCULATE INTERACTIONS *
963              **************************/
964
965             if (gmx_mm_any_lt(rsq33,rcutoff2))
966             {
967
968             /* REACTION-FIELD ELECTROSTATICS */
969             velec            = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
970             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
971
972             cutoff_mask      = _mm_cmplt_ps(rsq33,rcutoff2);
973
974             /* Update potential sum for this i atom from the interaction with this j atom. */
975             velec            = _mm_and_ps(velec,cutoff_mask);
976             velec            = _mm_andnot_ps(dummy_mask,velec);
977             velecsum         = _mm_add_ps(velecsum,velec);
978
979             fscal            = felec;
980
981             fscal            = _mm_and_ps(fscal,cutoff_mask);
982
983             fscal            = _mm_andnot_ps(dummy_mask,fscal);
984
985              /* Update vectorial force */
986             fix3             = _mm_macc_ps(dx33,fscal,fix3);
987             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
988             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
989
990             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
991             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
992             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
993
994             }
995
996             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
997             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
998             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
999             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1000
1001             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1002                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1003
1004             /* Inner loop uses 351 flops */
1005         }
1006
1007         /* End of innermost loop */
1008
1009         gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1010                                               f+i_coord_offset+DIM,fshift+i_shift_offset);
1011
1012         ggid                        = gid[iidx];
1013         /* Update potential energies */
1014         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1015
1016         /* Increment number of inner iterations */
1017         inneriter                  += j_index_end - j_index_start;
1018
1019         /* Outer loop uses 19 flops */
1020     }
1021
1022     /* Increment number of outer iterations */
1023     outeriter        += nri;
1024
1025     /* Update outer/inner flops */
1026
1027     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4W4_VF,outeriter*19 + inneriter*351);
1028 }
1029 /*
1030  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW4W4_F_avx_128_fma_single
1031  * Electrostatics interaction: ReactionField
1032  * VdW interaction:            None
1033  * Geometry:                   Water4-Water4
1034  * Calculate force/pot:        Force
1035  */
1036 void
1037 nb_kernel_ElecRFCut_VdwNone_GeomW4W4_F_avx_128_fma_single
1038                     (t_nblist                    * gmx_restrict       nlist,
1039                      rvec                        * gmx_restrict          xx,
1040                      rvec                        * gmx_restrict          ff,
1041                      struct t_forcerec           * gmx_restrict          fr,
1042                      t_mdatoms                   * gmx_restrict     mdatoms,
1043                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1044                      t_nrnb                      * gmx_restrict        nrnb)
1045 {
1046     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1047      * just 0 for non-waters.
1048      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1049      * jnr indices corresponding to data put in the four positions in the SIMD register.
1050      */
1051     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
1052     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1053     int              jnrA,jnrB,jnrC,jnrD;
1054     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1055     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1056     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
1057     real             rcutoff_scalar;
1058     real             *shiftvec,*fshift,*x,*f;
1059     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1060     real             scratch[4*DIM];
1061     __m128           fscal,rcutoff,rcutoff2,jidxall;
1062     int              vdwioffset1;
1063     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1064     int              vdwioffset2;
1065     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1066     int              vdwioffset3;
1067     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1068     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1069     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1070     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1071     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1072     int              vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
1073     __m128           jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1074     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1075     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1076     __m128           dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1077     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1078     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1079     __m128           dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1080     __m128           dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1081     __m128           dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1082     __m128           dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1083     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
1084     real             *charge;
1085     __m128           dummy_mask,cutoff_mask;
1086     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1087     __m128           one     = _mm_set1_ps(1.0);
1088     __m128           two     = _mm_set1_ps(2.0);
1089     x                = xx[0];
1090     f                = ff[0];
1091
1092     nri              = nlist->nri;
1093     iinr             = nlist->iinr;
1094     jindex           = nlist->jindex;
1095     jjnr             = nlist->jjnr;
1096     shiftidx         = nlist->shift;
1097     gid              = nlist->gid;
1098     shiftvec         = fr->shift_vec[0];
1099     fshift           = fr->fshift[0];
1100     facel            = _mm_set1_ps(fr->ic->epsfac);
1101     charge           = mdatoms->chargeA;
1102     krf              = _mm_set1_ps(fr->ic->k_rf);
1103     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
1104     crf              = _mm_set1_ps(fr->ic->c_rf);
1105
1106     /* Setup water-specific parameters */
1107     inr              = nlist->iinr[0];
1108     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1109     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1110     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
1111
1112     jq1              = _mm_set1_ps(charge[inr+1]);
1113     jq2              = _mm_set1_ps(charge[inr+2]);
1114     jq3              = _mm_set1_ps(charge[inr+3]);
1115     qq11             = _mm_mul_ps(iq1,jq1);
1116     qq12             = _mm_mul_ps(iq1,jq2);
1117     qq13             = _mm_mul_ps(iq1,jq3);
1118     qq21             = _mm_mul_ps(iq2,jq1);
1119     qq22             = _mm_mul_ps(iq2,jq2);
1120     qq23             = _mm_mul_ps(iq2,jq3);
1121     qq31             = _mm_mul_ps(iq3,jq1);
1122     qq32             = _mm_mul_ps(iq3,jq2);
1123     qq33             = _mm_mul_ps(iq3,jq3);
1124
1125     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1126     rcutoff_scalar   = fr->ic->rcoulomb;
1127     rcutoff          = _mm_set1_ps(rcutoff_scalar);
1128     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
1129
1130     /* Avoid stupid compiler warnings */
1131     jnrA = jnrB = jnrC = jnrD = 0;
1132     j_coord_offsetA = 0;
1133     j_coord_offsetB = 0;
1134     j_coord_offsetC = 0;
1135     j_coord_offsetD = 0;
1136
1137     outeriter        = 0;
1138     inneriter        = 0;
1139
1140     for(iidx=0;iidx<4*DIM;iidx++)
1141     {
1142         scratch[iidx] = 0.0;
1143     }
1144
1145     /* Start outer loop over neighborlists */
1146     for(iidx=0; iidx<nri; iidx++)
1147     {
1148         /* Load shift vector for this list */
1149         i_shift_offset   = DIM*shiftidx[iidx];
1150
1151         /* Load limits for loop over neighbors */
1152         j_index_start    = jindex[iidx];
1153         j_index_end      = jindex[iidx+1];
1154
1155         /* Get outer coordinate index */
1156         inr              = iinr[iidx];
1157         i_coord_offset   = DIM*inr;
1158
1159         /* Load i particle coords and add shift vector */
1160         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
1161                                                  &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1162
1163         fix1             = _mm_setzero_ps();
1164         fiy1             = _mm_setzero_ps();
1165         fiz1             = _mm_setzero_ps();
1166         fix2             = _mm_setzero_ps();
1167         fiy2             = _mm_setzero_ps();
1168         fiz2             = _mm_setzero_ps();
1169         fix3             = _mm_setzero_ps();
1170         fiy3             = _mm_setzero_ps();
1171         fiz3             = _mm_setzero_ps();
1172
1173         /* Start inner kernel loop */
1174         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1175         {
1176
1177             /* Get j neighbor index, and coordinate index */
1178             jnrA             = jjnr[jidx];
1179             jnrB             = jjnr[jidx+1];
1180             jnrC             = jjnr[jidx+2];
1181             jnrD             = jjnr[jidx+3];
1182             j_coord_offsetA  = DIM*jnrA;
1183             j_coord_offsetB  = DIM*jnrB;
1184             j_coord_offsetC  = DIM*jnrC;
1185             j_coord_offsetD  = DIM*jnrD;
1186
1187             /* load j atom coordinates */
1188             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
1189                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
1190                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
1191
1192             /* Calculate displacement vector */
1193             dx11             = _mm_sub_ps(ix1,jx1);
1194             dy11             = _mm_sub_ps(iy1,jy1);
1195             dz11             = _mm_sub_ps(iz1,jz1);
1196             dx12             = _mm_sub_ps(ix1,jx2);
1197             dy12             = _mm_sub_ps(iy1,jy2);
1198             dz12             = _mm_sub_ps(iz1,jz2);
1199             dx13             = _mm_sub_ps(ix1,jx3);
1200             dy13             = _mm_sub_ps(iy1,jy3);
1201             dz13             = _mm_sub_ps(iz1,jz3);
1202             dx21             = _mm_sub_ps(ix2,jx1);
1203             dy21             = _mm_sub_ps(iy2,jy1);
1204             dz21             = _mm_sub_ps(iz2,jz1);
1205             dx22             = _mm_sub_ps(ix2,jx2);
1206             dy22             = _mm_sub_ps(iy2,jy2);
1207             dz22             = _mm_sub_ps(iz2,jz2);
1208             dx23             = _mm_sub_ps(ix2,jx3);
1209             dy23             = _mm_sub_ps(iy2,jy3);
1210             dz23             = _mm_sub_ps(iz2,jz3);
1211             dx31             = _mm_sub_ps(ix3,jx1);
1212             dy31             = _mm_sub_ps(iy3,jy1);
1213             dz31             = _mm_sub_ps(iz3,jz1);
1214             dx32             = _mm_sub_ps(ix3,jx2);
1215             dy32             = _mm_sub_ps(iy3,jy2);
1216             dz32             = _mm_sub_ps(iz3,jz2);
1217             dx33             = _mm_sub_ps(ix3,jx3);
1218             dy33             = _mm_sub_ps(iy3,jy3);
1219             dz33             = _mm_sub_ps(iz3,jz3);
1220
1221             /* Calculate squared distance and things based on it */
1222             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1223             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1224             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1225             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1226             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1227             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1228             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1229             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1230             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1231
1232             rinv11           = avx128fma_invsqrt_f(rsq11);
1233             rinv12           = avx128fma_invsqrt_f(rsq12);
1234             rinv13           = avx128fma_invsqrt_f(rsq13);
1235             rinv21           = avx128fma_invsqrt_f(rsq21);
1236             rinv22           = avx128fma_invsqrt_f(rsq22);
1237             rinv23           = avx128fma_invsqrt_f(rsq23);
1238             rinv31           = avx128fma_invsqrt_f(rsq31);
1239             rinv32           = avx128fma_invsqrt_f(rsq32);
1240             rinv33           = avx128fma_invsqrt_f(rsq33);
1241
1242             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1243             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1244             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
1245             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1246             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1247             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
1248             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
1249             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
1250             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
1251
1252             fjx1             = _mm_setzero_ps();
1253             fjy1             = _mm_setzero_ps();
1254             fjz1             = _mm_setzero_ps();
1255             fjx2             = _mm_setzero_ps();
1256             fjy2             = _mm_setzero_ps();
1257             fjz2             = _mm_setzero_ps();
1258             fjx3             = _mm_setzero_ps();
1259             fjy3             = _mm_setzero_ps();
1260             fjz3             = _mm_setzero_ps();
1261
1262             /**************************
1263              * CALCULATE INTERACTIONS *
1264              **************************/
1265
1266             if (gmx_mm_any_lt(rsq11,rcutoff2))
1267             {
1268
1269             /* REACTION-FIELD ELECTROSTATICS */
1270             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1271
1272             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
1273
1274             fscal            = felec;
1275
1276             fscal            = _mm_and_ps(fscal,cutoff_mask);
1277
1278              /* Update vectorial force */
1279             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1280             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1281             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1282
1283             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1284             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1285             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1286
1287             }
1288
1289             /**************************
1290              * CALCULATE INTERACTIONS *
1291              **************************/
1292
1293             if (gmx_mm_any_lt(rsq12,rcutoff2))
1294             {
1295
1296             /* REACTION-FIELD ELECTROSTATICS */
1297             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1298
1299             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
1300
1301             fscal            = felec;
1302
1303             fscal            = _mm_and_ps(fscal,cutoff_mask);
1304
1305              /* Update vectorial force */
1306             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1307             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1308             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1309
1310             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1311             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1312             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1313
1314             }
1315
1316             /**************************
1317              * CALCULATE INTERACTIONS *
1318              **************************/
1319
1320             if (gmx_mm_any_lt(rsq13,rcutoff2))
1321             {
1322
1323             /* REACTION-FIELD ELECTROSTATICS */
1324             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1325
1326             cutoff_mask      = _mm_cmplt_ps(rsq13,rcutoff2);
1327
1328             fscal            = felec;
1329
1330             fscal            = _mm_and_ps(fscal,cutoff_mask);
1331
1332              /* Update vectorial force */
1333             fix1             = _mm_macc_ps(dx13,fscal,fix1);
1334             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
1335             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
1336
1337             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
1338             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
1339             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
1340
1341             }
1342
1343             /**************************
1344              * CALCULATE INTERACTIONS *
1345              **************************/
1346
1347             if (gmx_mm_any_lt(rsq21,rcutoff2))
1348             {
1349
1350             /* REACTION-FIELD ELECTROSTATICS */
1351             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1352
1353             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
1354
1355             fscal            = felec;
1356
1357             fscal            = _mm_and_ps(fscal,cutoff_mask);
1358
1359              /* Update vectorial force */
1360             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1361             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1362             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1363
1364             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1365             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1366             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1367
1368             }
1369
1370             /**************************
1371              * CALCULATE INTERACTIONS *
1372              **************************/
1373
1374             if (gmx_mm_any_lt(rsq22,rcutoff2))
1375             {
1376
1377             /* REACTION-FIELD ELECTROSTATICS */
1378             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1379
1380             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
1381
1382             fscal            = felec;
1383
1384             fscal            = _mm_and_ps(fscal,cutoff_mask);
1385
1386              /* Update vectorial force */
1387             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1388             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1389             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1390
1391             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1392             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1393             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1394
1395             }
1396
1397             /**************************
1398              * CALCULATE INTERACTIONS *
1399              **************************/
1400
1401             if (gmx_mm_any_lt(rsq23,rcutoff2))
1402             {
1403
1404             /* REACTION-FIELD ELECTROSTATICS */
1405             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1406
1407             cutoff_mask      = _mm_cmplt_ps(rsq23,rcutoff2);
1408
1409             fscal            = felec;
1410
1411             fscal            = _mm_and_ps(fscal,cutoff_mask);
1412
1413              /* Update vectorial force */
1414             fix2             = _mm_macc_ps(dx23,fscal,fix2);
1415             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
1416             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
1417
1418             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
1419             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
1420             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
1421
1422             }
1423
1424             /**************************
1425              * CALCULATE INTERACTIONS *
1426              **************************/
1427
1428             if (gmx_mm_any_lt(rsq31,rcutoff2))
1429             {
1430
1431             /* REACTION-FIELD ELECTROSTATICS */
1432             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1433
1434             cutoff_mask      = _mm_cmplt_ps(rsq31,rcutoff2);
1435
1436             fscal            = felec;
1437
1438             fscal            = _mm_and_ps(fscal,cutoff_mask);
1439
1440              /* Update vectorial force */
1441             fix3             = _mm_macc_ps(dx31,fscal,fix3);
1442             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
1443             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
1444
1445             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
1446             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
1447             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
1448
1449             }
1450
1451             /**************************
1452              * CALCULATE INTERACTIONS *
1453              **************************/
1454
1455             if (gmx_mm_any_lt(rsq32,rcutoff2))
1456             {
1457
1458             /* REACTION-FIELD ELECTROSTATICS */
1459             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1460
1461             cutoff_mask      = _mm_cmplt_ps(rsq32,rcutoff2);
1462
1463             fscal            = felec;
1464
1465             fscal            = _mm_and_ps(fscal,cutoff_mask);
1466
1467              /* Update vectorial force */
1468             fix3             = _mm_macc_ps(dx32,fscal,fix3);
1469             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
1470             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
1471
1472             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
1473             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
1474             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
1475
1476             }
1477
1478             /**************************
1479              * CALCULATE INTERACTIONS *
1480              **************************/
1481
1482             if (gmx_mm_any_lt(rsq33,rcutoff2))
1483             {
1484
1485             /* REACTION-FIELD ELECTROSTATICS */
1486             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1487
1488             cutoff_mask      = _mm_cmplt_ps(rsq33,rcutoff2);
1489
1490             fscal            = felec;
1491
1492             fscal            = _mm_and_ps(fscal,cutoff_mask);
1493
1494              /* Update vectorial force */
1495             fix3             = _mm_macc_ps(dx33,fscal,fix3);
1496             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
1497             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
1498
1499             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
1500             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
1501             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
1502
1503             }
1504
1505             fjptrA             = f+j_coord_offsetA;
1506             fjptrB             = f+j_coord_offsetB;
1507             fjptrC             = f+j_coord_offsetC;
1508             fjptrD             = f+j_coord_offsetD;
1509
1510             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1511                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1512
1513             /* Inner loop uses 297 flops */
1514         }
1515
1516         if(jidx<j_index_end)
1517         {
1518
1519             /* Get j neighbor index, and coordinate index */
1520             jnrlistA         = jjnr[jidx];
1521             jnrlistB         = jjnr[jidx+1];
1522             jnrlistC         = jjnr[jidx+2];
1523             jnrlistD         = jjnr[jidx+3];
1524             /* Sign of each element will be negative for non-real atoms.
1525              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1526              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1527              */
1528             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1529             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1530             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1531             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1532             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1533             j_coord_offsetA  = DIM*jnrA;
1534             j_coord_offsetB  = DIM*jnrB;
1535             j_coord_offsetC  = DIM*jnrC;
1536             j_coord_offsetD  = DIM*jnrD;
1537
1538             /* load j atom coordinates */
1539             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
1540                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
1541                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
1542
1543             /* Calculate displacement vector */
1544             dx11             = _mm_sub_ps(ix1,jx1);
1545             dy11             = _mm_sub_ps(iy1,jy1);
1546             dz11             = _mm_sub_ps(iz1,jz1);
1547             dx12             = _mm_sub_ps(ix1,jx2);
1548             dy12             = _mm_sub_ps(iy1,jy2);
1549             dz12             = _mm_sub_ps(iz1,jz2);
1550             dx13             = _mm_sub_ps(ix1,jx3);
1551             dy13             = _mm_sub_ps(iy1,jy3);
1552             dz13             = _mm_sub_ps(iz1,jz3);
1553             dx21             = _mm_sub_ps(ix2,jx1);
1554             dy21             = _mm_sub_ps(iy2,jy1);
1555             dz21             = _mm_sub_ps(iz2,jz1);
1556             dx22             = _mm_sub_ps(ix2,jx2);
1557             dy22             = _mm_sub_ps(iy2,jy2);
1558             dz22             = _mm_sub_ps(iz2,jz2);
1559             dx23             = _mm_sub_ps(ix2,jx3);
1560             dy23             = _mm_sub_ps(iy2,jy3);
1561             dz23             = _mm_sub_ps(iz2,jz3);
1562             dx31             = _mm_sub_ps(ix3,jx1);
1563             dy31             = _mm_sub_ps(iy3,jy1);
1564             dz31             = _mm_sub_ps(iz3,jz1);
1565             dx32             = _mm_sub_ps(ix3,jx2);
1566             dy32             = _mm_sub_ps(iy3,jy2);
1567             dz32             = _mm_sub_ps(iz3,jz2);
1568             dx33             = _mm_sub_ps(ix3,jx3);
1569             dy33             = _mm_sub_ps(iy3,jy3);
1570             dz33             = _mm_sub_ps(iz3,jz3);
1571
1572             /* Calculate squared distance and things based on it */
1573             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1574             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1575             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1576             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1577             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1578             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1579             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1580             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1581             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1582
1583             rinv11           = avx128fma_invsqrt_f(rsq11);
1584             rinv12           = avx128fma_invsqrt_f(rsq12);
1585             rinv13           = avx128fma_invsqrt_f(rsq13);
1586             rinv21           = avx128fma_invsqrt_f(rsq21);
1587             rinv22           = avx128fma_invsqrt_f(rsq22);
1588             rinv23           = avx128fma_invsqrt_f(rsq23);
1589             rinv31           = avx128fma_invsqrt_f(rsq31);
1590             rinv32           = avx128fma_invsqrt_f(rsq32);
1591             rinv33           = avx128fma_invsqrt_f(rsq33);
1592
1593             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1594             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1595             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
1596             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1597             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1598             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
1599             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
1600             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
1601             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
1602
1603             fjx1             = _mm_setzero_ps();
1604             fjy1             = _mm_setzero_ps();
1605             fjz1             = _mm_setzero_ps();
1606             fjx2             = _mm_setzero_ps();
1607             fjy2             = _mm_setzero_ps();
1608             fjz2             = _mm_setzero_ps();
1609             fjx3             = _mm_setzero_ps();
1610             fjy3             = _mm_setzero_ps();
1611             fjz3             = _mm_setzero_ps();
1612
1613             /**************************
1614              * CALCULATE INTERACTIONS *
1615              **************************/
1616
1617             if (gmx_mm_any_lt(rsq11,rcutoff2))
1618             {
1619
1620             /* REACTION-FIELD ELECTROSTATICS */
1621             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1622
1623             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
1624
1625             fscal            = felec;
1626
1627             fscal            = _mm_and_ps(fscal,cutoff_mask);
1628
1629             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1630
1631              /* Update vectorial force */
1632             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1633             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1634             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1635
1636             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1637             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1638             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1639
1640             }
1641
1642             /**************************
1643              * CALCULATE INTERACTIONS *
1644              **************************/
1645
1646             if (gmx_mm_any_lt(rsq12,rcutoff2))
1647             {
1648
1649             /* REACTION-FIELD ELECTROSTATICS */
1650             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1651
1652             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
1653
1654             fscal            = felec;
1655
1656             fscal            = _mm_and_ps(fscal,cutoff_mask);
1657
1658             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1659
1660              /* Update vectorial force */
1661             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1662             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1663             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1664
1665             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1666             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1667             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1668
1669             }
1670
1671             /**************************
1672              * CALCULATE INTERACTIONS *
1673              **************************/
1674
1675             if (gmx_mm_any_lt(rsq13,rcutoff2))
1676             {
1677
1678             /* REACTION-FIELD ELECTROSTATICS */
1679             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1680
1681             cutoff_mask      = _mm_cmplt_ps(rsq13,rcutoff2);
1682
1683             fscal            = felec;
1684
1685             fscal            = _mm_and_ps(fscal,cutoff_mask);
1686
1687             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1688
1689              /* Update vectorial force */
1690             fix1             = _mm_macc_ps(dx13,fscal,fix1);
1691             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
1692             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
1693
1694             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
1695             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
1696             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
1697
1698             }
1699
1700             /**************************
1701              * CALCULATE INTERACTIONS *
1702              **************************/
1703
1704             if (gmx_mm_any_lt(rsq21,rcutoff2))
1705             {
1706
1707             /* REACTION-FIELD ELECTROSTATICS */
1708             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1709
1710             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
1711
1712             fscal            = felec;
1713
1714             fscal            = _mm_and_ps(fscal,cutoff_mask);
1715
1716             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1717
1718              /* Update vectorial force */
1719             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1720             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1721             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1722
1723             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1724             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1725             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1726
1727             }
1728
1729             /**************************
1730              * CALCULATE INTERACTIONS *
1731              **************************/
1732
1733             if (gmx_mm_any_lt(rsq22,rcutoff2))
1734             {
1735
1736             /* REACTION-FIELD ELECTROSTATICS */
1737             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1738
1739             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
1740
1741             fscal            = felec;
1742
1743             fscal            = _mm_and_ps(fscal,cutoff_mask);
1744
1745             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1746
1747              /* Update vectorial force */
1748             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1749             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1750             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1751
1752             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1753             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1754             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1755
1756             }
1757
1758             /**************************
1759              * CALCULATE INTERACTIONS *
1760              **************************/
1761
1762             if (gmx_mm_any_lt(rsq23,rcutoff2))
1763             {
1764
1765             /* REACTION-FIELD ELECTROSTATICS */
1766             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1767
1768             cutoff_mask      = _mm_cmplt_ps(rsq23,rcutoff2);
1769
1770             fscal            = felec;
1771
1772             fscal            = _mm_and_ps(fscal,cutoff_mask);
1773
1774             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1775
1776              /* Update vectorial force */
1777             fix2             = _mm_macc_ps(dx23,fscal,fix2);
1778             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
1779             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
1780
1781             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
1782             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
1783             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
1784
1785             }
1786
1787             /**************************
1788              * CALCULATE INTERACTIONS *
1789              **************************/
1790
1791             if (gmx_mm_any_lt(rsq31,rcutoff2))
1792             {
1793
1794             /* REACTION-FIELD ELECTROSTATICS */
1795             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1796
1797             cutoff_mask      = _mm_cmplt_ps(rsq31,rcutoff2);
1798
1799             fscal            = felec;
1800
1801             fscal            = _mm_and_ps(fscal,cutoff_mask);
1802
1803             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1804
1805              /* Update vectorial force */
1806             fix3             = _mm_macc_ps(dx31,fscal,fix3);
1807             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
1808             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
1809
1810             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
1811             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
1812             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
1813
1814             }
1815
1816             /**************************
1817              * CALCULATE INTERACTIONS *
1818              **************************/
1819
1820             if (gmx_mm_any_lt(rsq32,rcutoff2))
1821             {
1822
1823             /* REACTION-FIELD ELECTROSTATICS */
1824             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1825
1826             cutoff_mask      = _mm_cmplt_ps(rsq32,rcutoff2);
1827
1828             fscal            = felec;
1829
1830             fscal            = _mm_and_ps(fscal,cutoff_mask);
1831
1832             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1833
1834              /* Update vectorial force */
1835             fix3             = _mm_macc_ps(dx32,fscal,fix3);
1836             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
1837             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
1838
1839             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
1840             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
1841             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
1842
1843             }
1844
1845             /**************************
1846              * CALCULATE INTERACTIONS *
1847              **************************/
1848
1849             if (gmx_mm_any_lt(rsq33,rcutoff2))
1850             {
1851
1852             /* REACTION-FIELD ELECTROSTATICS */
1853             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1854
1855             cutoff_mask      = _mm_cmplt_ps(rsq33,rcutoff2);
1856
1857             fscal            = felec;
1858
1859             fscal            = _mm_and_ps(fscal,cutoff_mask);
1860
1861             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1862
1863              /* Update vectorial force */
1864             fix3             = _mm_macc_ps(dx33,fscal,fix3);
1865             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
1866             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
1867
1868             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
1869             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
1870             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
1871
1872             }
1873
1874             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1875             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1876             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1877             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1878
1879             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1880                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1881
1882             /* Inner loop uses 297 flops */
1883         }
1884
1885         /* End of innermost loop */
1886
1887         gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1888                                               f+i_coord_offset+DIM,fshift+i_shift_offset);
1889
1890         /* Increment number of inner iterations */
1891         inneriter                  += j_index_end - j_index_start;
1892
1893         /* Outer loop uses 18 flops */
1894     }
1895
1896     /* Increment number of outer iterations */
1897     outeriter        += nri;
1898
1899     /* Update outer/inner flops */
1900
1901     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4W4_F,outeriter*18 + inneriter*297);
1902 }