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