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