Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse4_1_single / nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_sse4_1_single.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2017, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS sse4_1_single kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
46
47 #include "kernelutil_x86_sse4_1_single.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_sse4_1_single
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_sse4_1_single
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      struct t_forcerec           * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
67      * just 0 for non-waters.
68      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69      * jnr indices corresponding to data put in the four positions in the SIMD register.
70      */
71     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
72     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73     int              jnrA,jnrB,jnrC,jnrD;
74     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
80     real             scratch[4*DIM];
81     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82     int              vdwioffset0;
83     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwioffset1;
85     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
86     int              vdwioffset2;
87     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88     int              vdwioffset3;
89     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
97     real             *charge;
98     int              nvdwtype;
99     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
100     int              *vdwtype;
101     real             *vdwparam;
102     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
103     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
104     __m128i          ewitab;
105     __m128           ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
106     real             *ewtab;
107     __m128           dummy_mask,cutoff_mask;
108     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
109     __m128           one     = _mm_set1_ps(1.0);
110     __m128           two     = _mm_set1_ps(2.0);
111     x                = xx[0];
112     f                = ff[0];
113
114     nri              = nlist->nri;
115     iinr             = nlist->iinr;
116     jindex           = nlist->jindex;
117     jjnr             = nlist->jjnr;
118     shiftidx         = nlist->shift;
119     gid              = nlist->gid;
120     shiftvec         = fr->shift_vec[0];
121     fshift           = fr->fshift[0];
122     facel            = _mm_set1_ps(fr->ic->epsfac);
123     charge           = mdatoms->chargeA;
124     nvdwtype         = fr->ntype;
125     vdwparam         = fr->nbfp;
126     vdwtype          = mdatoms->typeA;
127
128     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
129     ewtab            = fr->ic->tabq_coul_FDV0;
130     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
131     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
132
133     /* Setup water-specific parameters */
134     inr              = nlist->iinr[0];
135     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
136     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
137     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
138     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
139
140     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
141     rcutoff_scalar   = fr->ic->rcoulomb;
142     rcutoff          = _mm_set1_ps(rcutoff_scalar);
143     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
144
145     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
146     rvdw             = _mm_set1_ps(fr->ic->rvdw);
147
148     /* Avoid stupid compiler warnings */
149     jnrA = jnrB = jnrC = jnrD = 0;
150     j_coord_offsetA = 0;
151     j_coord_offsetB = 0;
152     j_coord_offsetC = 0;
153     j_coord_offsetD = 0;
154
155     outeriter        = 0;
156     inneriter        = 0;
157
158     for(iidx=0;iidx<4*DIM;iidx++)
159     {
160         scratch[iidx] = 0.0;
161     }
162
163     /* Start outer loop over neighborlists */
164     for(iidx=0; iidx<nri; iidx++)
165     {
166         /* Load shift vector for this list */
167         i_shift_offset   = DIM*shiftidx[iidx];
168
169         /* Load limits for loop over neighbors */
170         j_index_start    = jindex[iidx];
171         j_index_end      = jindex[iidx+1];
172
173         /* Get outer coordinate index */
174         inr              = iinr[iidx];
175         i_coord_offset   = DIM*inr;
176
177         /* Load i particle coords and add shift vector */
178         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
179                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
180
181         fix0             = _mm_setzero_ps();
182         fiy0             = _mm_setzero_ps();
183         fiz0             = _mm_setzero_ps();
184         fix1             = _mm_setzero_ps();
185         fiy1             = _mm_setzero_ps();
186         fiz1             = _mm_setzero_ps();
187         fix2             = _mm_setzero_ps();
188         fiy2             = _mm_setzero_ps();
189         fiz2             = _mm_setzero_ps();
190         fix3             = _mm_setzero_ps();
191         fiy3             = _mm_setzero_ps();
192         fiz3             = _mm_setzero_ps();
193
194         /* Reset potential sums */
195         velecsum         = _mm_setzero_ps();
196         vvdwsum          = _mm_setzero_ps();
197
198         /* Start inner kernel loop */
199         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
200         {
201
202             /* Get j neighbor index, and coordinate index */
203             jnrA             = jjnr[jidx];
204             jnrB             = jjnr[jidx+1];
205             jnrC             = jjnr[jidx+2];
206             jnrD             = jjnr[jidx+3];
207             j_coord_offsetA  = DIM*jnrA;
208             j_coord_offsetB  = DIM*jnrB;
209             j_coord_offsetC  = DIM*jnrC;
210             j_coord_offsetD  = DIM*jnrD;
211
212             /* load j atom coordinates */
213             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
214                                               x+j_coord_offsetC,x+j_coord_offsetD,
215                                               &jx0,&jy0,&jz0);
216
217             /* Calculate displacement vector */
218             dx00             = _mm_sub_ps(ix0,jx0);
219             dy00             = _mm_sub_ps(iy0,jy0);
220             dz00             = _mm_sub_ps(iz0,jz0);
221             dx10             = _mm_sub_ps(ix1,jx0);
222             dy10             = _mm_sub_ps(iy1,jy0);
223             dz10             = _mm_sub_ps(iz1,jz0);
224             dx20             = _mm_sub_ps(ix2,jx0);
225             dy20             = _mm_sub_ps(iy2,jy0);
226             dz20             = _mm_sub_ps(iz2,jz0);
227             dx30             = _mm_sub_ps(ix3,jx0);
228             dy30             = _mm_sub_ps(iy3,jy0);
229             dz30             = _mm_sub_ps(iz3,jz0);
230
231             /* Calculate squared distance and things based on it */
232             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
233             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
234             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
235             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
236
237             rinv10           = sse41_invsqrt_f(rsq10);
238             rinv20           = sse41_invsqrt_f(rsq20);
239             rinv30           = sse41_invsqrt_f(rsq30);
240
241             rinvsq00         = sse41_inv_f(rsq00);
242             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
243             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
244             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
245
246             /* Load parameters for j particles */
247             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
248                                                               charge+jnrC+0,charge+jnrD+0);
249             vdwjidx0A        = 2*vdwtype[jnrA+0];
250             vdwjidx0B        = 2*vdwtype[jnrB+0];
251             vdwjidx0C        = 2*vdwtype[jnrC+0];
252             vdwjidx0D        = 2*vdwtype[jnrD+0];
253
254             fjx0             = _mm_setzero_ps();
255             fjy0             = _mm_setzero_ps();
256             fjz0             = _mm_setzero_ps();
257
258             /**************************
259              * CALCULATE INTERACTIONS *
260              **************************/
261
262             if (gmx_mm_any_lt(rsq00,rcutoff2))
263             {
264
265             /* Compute parameters for interactions between i and j atoms */
266             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
267                                          vdwparam+vdwioffset0+vdwjidx0B,
268                                          vdwparam+vdwioffset0+vdwjidx0C,
269                                          vdwparam+vdwioffset0+vdwjidx0D,
270                                          &c6_00,&c12_00);
271
272             /* LENNARD-JONES DISPERSION/REPULSION */
273
274             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
275             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
276             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
277             vvdw             = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
278                                           _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
279             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
280
281             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
282
283             /* Update potential sum for this i atom from the interaction with this j atom. */
284             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
285             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
286
287             fscal            = fvdw;
288
289             fscal            = _mm_and_ps(fscal,cutoff_mask);
290
291             /* Calculate temporary vectorial force */
292             tx               = _mm_mul_ps(fscal,dx00);
293             ty               = _mm_mul_ps(fscal,dy00);
294             tz               = _mm_mul_ps(fscal,dz00);
295
296             /* Update vectorial force */
297             fix0             = _mm_add_ps(fix0,tx);
298             fiy0             = _mm_add_ps(fiy0,ty);
299             fiz0             = _mm_add_ps(fiz0,tz);
300
301             fjx0             = _mm_add_ps(fjx0,tx);
302             fjy0             = _mm_add_ps(fjy0,ty);
303             fjz0             = _mm_add_ps(fjz0,tz);
304
305             }
306
307             /**************************
308              * CALCULATE INTERACTIONS *
309              **************************/
310
311             if (gmx_mm_any_lt(rsq10,rcutoff2))
312             {
313
314             r10              = _mm_mul_ps(rsq10,rinv10);
315
316             /* Compute parameters for interactions between i and j atoms */
317             qq10             = _mm_mul_ps(iq1,jq0);
318
319             /* EWALD ELECTROSTATICS */
320
321             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
322             ewrt             = _mm_mul_ps(r10,ewtabscale);
323             ewitab           = _mm_cvttps_epi32(ewrt);
324             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
325             ewitab           = _mm_slli_epi32(ewitab,2);
326             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
327             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
328             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
329             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
330             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
331             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
332             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
333             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_sub_ps(rinv10,sh_ewald),velec));
334             felec            = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
335
336             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
337
338             /* Update potential sum for this i atom from the interaction with this j atom. */
339             velec            = _mm_and_ps(velec,cutoff_mask);
340             velecsum         = _mm_add_ps(velecsum,velec);
341
342             fscal            = felec;
343
344             fscal            = _mm_and_ps(fscal,cutoff_mask);
345
346             /* Calculate temporary vectorial force */
347             tx               = _mm_mul_ps(fscal,dx10);
348             ty               = _mm_mul_ps(fscal,dy10);
349             tz               = _mm_mul_ps(fscal,dz10);
350
351             /* Update vectorial force */
352             fix1             = _mm_add_ps(fix1,tx);
353             fiy1             = _mm_add_ps(fiy1,ty);
354             fiz1             = _mm_add_ps(fiz1,tz);
355
356             fjx0             = _mm_add_ps(fjx0,tx);
357             fjy0             = _mm_add_ps(fjy0,ty);
358             fjz0             = _mm_add_ps(fjz0,tz);
359
360             }
361
362             /**************************
363              * CALCULATE INTERACTIONS *
364              **************************/
365
366             if (gmx_mm_any_lt(rsq20,rcutoff2))
367             {
368
369             r20              = _mm_mul_ps(rsq20,rinv20);
370
371             /* Compute parameters for interactions between i and j atoms */
372             qq20             = _mm_mul_ps(iq2,jq0);
373
374             /* EWALD ELECTROSTATICS */
375
376             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
377             ewrt             = _mm_mul_ps(r20,ewtabscale);
378             ewitab           = _mm_cvttps_epi32(ewrt);
379             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
380             ewitab           = _mm_slli_epi32(ewitab,2);
381             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
382             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
383             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
384             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
385             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
386             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
387             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
388             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_sub_ps(rinv20,sh_ewald),velec));
389             felec            = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
390
391             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
392
393             /* Update potential sum for this i atom from the interaction with this j atom. */
394             velec            = _mm_and_ps(velec,cutoff_mask);
395             velecsum         = _mm_add_ps(velecsum,velec);
396
397             fscal            = felec;
398
399             fscal            = _mm_and_ps(fscal,cutoff_mask);
400
401             /* Calculate temporary vectorial force */
402             tx               = _mm_mul_ps(fscal,dx20);
403             ty               = _mm_mul_ps(fscal,dy20);
404             tz               = _mm_mul_ps(fscal,dz20);
405
406             /* Update vectorial force */
407             fix2             = _mm_add_ps(fix2,tx);
408             fiy2             = _mm_add_ps(fiy2,ty);
409             fiz2             = _mm_add_ps(fiz2,tz);
410
411             fjx0             = _mm_add_ps(fjx0,tx);
412             fjy0             = _mm_add_ps(fjy0,ty);
413             fjz0             = _mm_add_ps(fjz0,tz);
414
415             }
416
417             /**************************
418              * CALCULATE INTERACTIONS *
419              **************************/
420
421             if (gmx_mm_any_lt(rsq30,rcutoff2))
422             {
423
424             r30              = _mm_mul_ps(rsq30,rinv30);
425
426             /* Compute parameters for interactions between i and j atoms */
427             qq30             = _mm_mul_ps(iq3,jq0);
428
429             /* EWALD ELECTROSTATICS */
430
431             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
432             ewrt             = _mm_mul_ps(r30,ewtabscale);
433             ewitab           = _mm_cvttps_epi32(ewrt);
434             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
435             ewitab           = _mm_slli_epi32(ewitab,2);
436             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
437             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
438             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
439             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
440             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
441             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
442             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
443             velec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_sub_ps(rinv30,sh_ewald),velec));
444             felec            = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
445
446             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
447
448             /* Update potential sum for this i atom from the interaction with this j atom. */
449             velec            = _mm_and_ps(velec,cutoff_mask);
450             velecsum         = _mm_add_ps(velecsum,velec);
451
452             fscal            = felec;
453
454             fscal            = _mm_and_ps(fscal,cutoff_mask);
455
456             /* Calculate temporary vectorial force */
457             tx               = _mm_mul_ps(fscal,dx30);
458             ty               = _mm_mul_ps(fscal,dy30);
459             tz               = _mm_mul_ps(fscal,dz30);
460
461             /* Update vectorial force */
462             fix3             = _mm_add_ps(fix3,tx);
463             fiy3             = _mm_add_ps(fiy3,ty);
464             fiz3             = _mm_add_ps(fiz3,tz);
465
466             fjx0             = _mm_add_ps(fjx0,tx);
467             fjy0             = _mm_add_ps(fjy0,ty);
468             fjz0             = _mm_add_ps(fjz0,tz);
469
470             }
471
472             fjptrA             = f+j_coord_offsetA;
473             fjptrB             = f+j_coord_offsetB;
474             fjptrC             = f+j_coord_offsetC;
475             fjptrD             = f+j_coord_offsetD;
476
477             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
478
479             /* Inner loop uses 179 flops */
480         }
481
482         if(jidx<j_index_end)
483         {
484
485             /* Get j neighbor index, and coordinate index */
486             jnrlistA         = jjnr[jidx];
487             jnrlistB         = jjnr[jidx+1];
488             jnrlistC         = jjnr[jidx+2];
489             jnrlistD         = jjnr[jidx+3];
490             /* Sign of each element will be negative for non-real atoms.
491              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
492              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
493              */
494             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
495             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
496             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
497             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
498             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
499             j_coord_offsetA  = DIM*jnrA;
500             j_coord_offsetB  = DIM*jnrB;
501             j_coord_offsetC  = DIM*jnrC;
502             j_coord_offsetD  = DIM*jnrD;
503
504             /* load j atom coordinates */
505             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
506                                               x+j_coord_offsetC,x+j_coord_offsetD,
507                                               &jx0,&jy0,&jz0);
508
509             /* Calculate displacement vector */
510             dx00             = _mm_sub_ps(ix0,jx0);
511             dy00             = _mm_sub_ps(iy0,jy0);
512             dz00             = _mm_sub_ps(iz0,jz0);
513             dx10             = _mm_sub_ps(ix1,jx0);
514             dy10             = _mm_sub_ps(iy1,jy0);
515             dz10             = _mm_sub_ps(iz1,jz0);
516             dx20             = _mm_sub_ps(ix2,jx0);
517             dy20             = _mm_sub_ps(iy2,jy0);
518             dz20             = _mm_sub_ps(iz2,jz0);
519             dx30             = _mm_sub_ps(ix3,jx0);
520             dy30             = _mm_sub_ps(iy3,jy0);
521             dz30             = _mm_sub_ps(iz3,jz0);
522
523             /* Calculate squared distance and things based on it */
524             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
525             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
526             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
527             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
528
529             rinv10           = sse41_invsqrt_f(rsq10);
530             rinv20           = sse41_invsqrt_f(rsq20);
531             rinv30           = sse41_invsqrt_f(rsq30);
532
533             rinvsq00         = sse41_inv_f(rsq00);
534             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
535             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
536             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
537
538             /* Load parameters for j particles */
539             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
540                                                               charge+jnrC+0,charge+jnrD+0);
541             vdwjidx0A        = 2*vdwtype[jnrA+0];
542             vdwjidx0B        = 2*vdwtype[jnrB+0];
543             vdwjidx0C        = 2*vdwtype[jnrC+0];
544             vdwjidx0D        = 2*vdwtype[jnrD+0];
545
546             fjx0             = _mm_setzero_ps();
547             fjy0             = _mm_setzero_ps();
548             fjz0             = _mm_setzero_ps();
549
550             /**************************
551              * CALCULATE INTERACTIONS *
552              **************************/
553
554             if (gmx_mm_any_lt(rsq00,rcutoff2))
555             {
556
557             /* Compute parameters for interactions between i and j atoms */
558             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
559                                          vdwparam+vdwioffset0+vdwjidx0B,
560                                          vdwparam+vdwioffset0+vdwjidx0C,
561                                          vdwparam+vdwioffset0+vdwjidx0D,
562                                          &c6_00,&c12_00);
563
564             /* LENNARD-JONES DISPERSION/REPULSION */
565
566             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
567             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
568             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
569             vvdw             = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
570                                           _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
571             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
572
573             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
574
575             /* Update potential sum for this i atom from the interaction with this j atom. */
576             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
577             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
578             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
579
580             fscal            = fvdw;
581
582             fscal            = _mm_and_ps(fscal,cutoff_mask);
583
584             fscal            = _mm_andnot_ps(dummy_mask,fscal);
585
586             /* Calculate temporary vectorial force */
587             tx               = _mm_mul_ps(fscal,dx00);
588             ty               = _mm_mul_ps(fscal,dy00);
589             tz               = _mm_mul_ps(fscal,dz00);
590
591             /* Update vectorial force */
592             fix0             = _mm_add_ps(fix0,tx);
593             fiy0             = _mm_add_ps(fiy0,ty);
594             fiz0             = _mm_add_ps(fiz0,tz);
595
596             fjx0             = _mm_add_ps(fjx0,tx);
597             fjy0             = _mm_add_ps(fjy0,ty);
598             fjz0             = _mm_add_ps(fjz0,tz);
599
600             }
601
602             /**************************
603              * CALCULATE INTERACTIONS *
604              **************************/
605
606             if (gmx_mm_any_lt(rsq10,rcutoff2))
607             {
608
609             r10              = _mm_mul_ps(rsq10,rinv10);
610             r10              = _mm_andnot_ps(dummy_mask,r10);
611
612             /* Compute parameters for interactions between i and j atoms */
613             qq10             = _mm_mul_ps(iq1,jq0);
614
615             /* EWALD ELECTROSTATICS */
616
617             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
618             ewrt             = _mm_mul_ps(r10,ewtabscale);
619             ewitab           = _mm_cvttps_epi32(ewrt);
620             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
621             ewitab           = _mm_slli_epi32(ewitab,2);
622             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
623             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
624             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
625             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
626             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
627             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
628             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
629             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_sub_ps(rinv10,sh_ewald),velec));
630             felec            = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
631
632             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
633
634             /* Update potential sum for this i atom from the interaction with this j atom. */
635             velec            = _mm_and_ps(velec,cutoff_mask);
636             velec            = _mm_andnot_ps(dummy_mask,velec);
637             velecsum         = _mm_add_ps(velecsum,velec);
638
639             fscal            = felec;
640
641             fscal            = _mm_and_ps(fscal,cutoff_mask);
642
643             fscal            = _mm_andnot_ps(dummy_mask,fscal);
644
645             /* Calculate temporary vectorial force */
646             tx               = _mm_mul_ps(fscal,dx10);
647             ty               = _mm_mul_ps(fscal,dy10);
648             tz               = _mm_mul_ps(fscal,dz10);
649
650             /* Update vectorial force */
651             fix1             = _mm_add_ps(fix1,tx);
652             fiy1             = _mm_add_ps(fiy1,ty);
653             fiz1             = _mm_add_ps(fiz1,tz);
654
655             fjx0             = _mm_add_ps(fjx0,tx);
656             fjy0             = _mm_add_ps(fjy0,ty);
657             fjz0             = _mm_add_ps(fjz0,tz);
658
659             }
660
661             /**************************
662              * CALCULATE INTERACTIONS *
663              **************************/
664
665             if (gmx_mm_any_lt(rsq20,rcutoff2))
666             {
667
668             r20              = _mm_mul_ps(rsq20,rinv20);
669             r20              = _mm_andnot_ps(dummy_mask,r20);
670
671             /* Compute parameters for interactions between i and j atoms */
672             qq20             = _mm_mul_ps(iq2,jq0);
673
674             /* EWALD ELECTROSTATICS */
675
676             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
677             ewrt             = _mm_mul_ps(r20,ewtabscale);
678             ewitab           = _mm_cvttps_epi32(ewrt);
679             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
680             ewitab           = _mm_slli_epi32(ewitab,2);
681             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
682             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
683             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
684             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
685             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
686             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
687             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
688             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_sub_ps(rinv20,sh_ewald),velec));
689             felec            = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
690
691             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
692
693             /* Update potential sum for this i atom from the interaction with this j atom. */
694             velec            = _mm_and_ps(velec,cutoff_mask);
695             velec            = _mm_andnot_ps(dummy_mask,velec);
696             velecsum         = _mm_add_ps(velecsum,velec);
697
698             fscal            = felec;
699
700             fscal            = _mm_and_ps(fscal,cutoff_mask);
701
702             fscal            = _mm_andnot_ps(dummy_mask,fscal);
703
704             /* Calculate temporary vectorial force */
705             tx               = _mm_mul_ps(fscal,dx20);
706             ty               = _mm_mul_ps(fscal,dy20);
707             tz               = _mm_mul_ps(fscal,dz20);
708
709             /* Update vectorial force */
710             fix2             = _mm_add_ps(fix2,tx);
711             fiy2             = _mm_add_ps(fiy2,ty);
712             fiz2             = _mm_add_ps(fiz2,tz);
713
714             fjx0             = _mm_add_ps(fjx0,tx);
715             fjy0             = _mm_add_ps(fjy0,ty);
716             fjz0             = _mm_add_ps(fjz0,tz);
717
718             }
719
720             /**************************
721              * CALCULATE INTERACTIONS *
722              **************************/
723
724             if (gmx_mm_any_lt(rsq30,rcutoff2))
725             {
726
727             r30              = _mm_mul_ps(rsq30,rinv30);
728             r30              = _mm_andnot_ps(dummy_mask,r30);
729
730             /* Compute parameters for interactions between i and j atoms */
731             qq30             = _mm_mul_ps(iq3,jq0);
732
733             /* EWALD ELECTROSTATICS */
734
735             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
736             ewrt             = _mm_mul_ps(r30,ewtabscale);
737             ewitab           = _mm_cvttps_epi32(ewrt);
738             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
739             ewitab           = _mm_slli_epi32(ewitab,2);
740             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
741             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
742             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
743             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
744             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
745             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
746             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
747             velec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_sub_ps(rinv30,sh_ewald),velec));
748             felec            = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
749
750             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
751
752             /* Update potential sum for this i atom from the interaction with this j atom. */
753             velec            = _mm_and_ps(velec,cutoff_mask);
754             velec            = _mm_andnot_ps(dummy_mask,velec);
755             velecsum         = _mm_add_ps(velecsum,velec);
756
757             fscal            = felec;
758
759             fscal            = _mm_and_ps(fscal,cutoff_mask);
760
761             fscal            = _mm_andnot_ps(dummy_mask,fscal);
762
763             /* Calculate temporary vectorial force */
764             tx               = _mm_mul_ps(fscal,dx30);
765             ty               = _mm_mul_ps(fscal,dy30);
766             tz               = _mm_mul_ps(fscal,dz30);
767
768             /* Update vectorial force */
769             fix3             = _mm_add_ps(fix3,tx);
770             fiy3             = _mm_add_ps(fiy3,ty);
771             fiz3             = _mm_add_ps(fiz3,tz);
772
773             fjx0             = _mm_add_ps(fjx0,tx);
774             fjy0             = _mm_add_ps(fjy0,ty);
775             fjz0             = _mm_add_ps(fjz0,tz);
776
777             }
778
779             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
780             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
781             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
782             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
783
784             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
785
786             /* Inner loop uses 182 flops */
787         }
788
789         /* End of innermost loop */
790
791         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
792                                               f+i_coord_offset,fshift+i_shift_offset);
793
794         ggid                        = gid[iidx];
795         /* Update potential energies */
796         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
797         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
798
799         /* Increment number of inner iterations */
800         inneriter                  += j_index_end - j_index_start;
801
802         /* Outer loop uses 26 flops */
803     }
804
805     /* Increment number of outer iterations */
806     outeriter        += nri;
807
808     /* Update outer/inner flops */
809
810     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*182);
811 }
812 /*
813  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse4_1_single
814  * Electrostatics interaction: Ewald
815  * VdW interaction:            LennardJones
816  * Geometry:                   Water4-Particle
817  * Calculate force/pot:        Force
818  */
819 void
820 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse4_1_single
821                     (t_nblist                    * gmx_restrict       nlist,
822                      rvec                        * gmx_restrict          xx,
823                      rvec                        * gmx_restrict          ff,
824                      struct t_forcerec           * gmx_restrict          fr,
825                      t_mdatoms                   * gmx_restrict     mdatoms,
826                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
827                      t_nrnb                      * gmx_restrict        nrnb)
828 {
829     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
830      * just 0 for non-waters.
831      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
832      * jnr indices corresponding to data put in the four positions in the SIMD register.
833      */
834     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
835     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
836     int              jnrA,jnrB,jnrC,jnrD;
837     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
838     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
839     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
840     real             rcutoff_scalar;
841     real             *shiftvec,*fshift,*x,*f;
842     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
843     real             scratch[4*DIM];
844     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
845     int              vdwioffset0;
846     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
847     int              vdwioffset1;
848     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
849     int              vdwioffset2;
850     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
851     int              vdwioffset3;
852     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
853     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
854     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
855     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
856     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
857     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
858     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
859     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
860     real             *charge;
861     int              nvdwtype;
862     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
863     int              *vdwtype;
864     real             *vdwparam;
865     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
866     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
867     __m128i          ewitab;
868     __m128           ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
869     real             *ewtab;
870     __m128           dummy_mask,cutoff_mask;
871     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
872     __m128           one     = _mm_set1_ps(1.0);
873     __m128           two     = _mm_set1_ps(2.0);
874     x                = xx[0];
875     f                = ff[0];
876
877     nri              = nlist->nri;
878     iinr             = nlist->iinr;
879     jindex           = nlist->jindex;
880     jjnr             = nlist->jjnr;
881     shiftidx         = nlist->shift;
882     gid              = nlist->gid;
883     shiftvec         = fr->shift_vec[0];
884     fshift           = fr->fshift[0];
885     facel            = _mm_set1_ps(fr->ic->epsfac);
886     charge           = mdatoms->chargeA;
887     nvdwtype         = fr->ntype;
888     vdwparam         = fr->nbfp;
889     vdwtype          = mdatoms->typeA;
890
891     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
892     ewtab            = fr->ic->tabq_coul_F;
893     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
894     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
895
896     /* Setup water-specific parameters */
897     inr              = nlist->iinr[0];
898     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
899     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
900     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
901     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
902
903     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
904     rcutoff_scalar   = fr->ic->rcoulomb;
905     rcutoff          = _mm_set1_ps(rcutoff_scalar);
906     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
907
908     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
909     rvdw             = _mm_set1_ps(fr->ic->rvdw);
910
911     /* Avoid stupid compiler warnings */
912     jnrA = jnrB = jnrC = jnrD = 0;
913     j_coord_offsetA = 0;
914     j_coord_offsetB = 0;
915     j_coord_offsetC = 0;
916     j_coord_offsetD = 0;
917
918     outeriter        = 0;
919     inneriter        = 0;
920
921     for(iidx=0;iidx<4*DIM;iidx++)
922     {
923         scratch[iidx] = 0.0;
924     }
925
926     /* Start outer loop over neighborlists */
927     for(iidx=0; iidx<nri; iidx++)
928     {
929         /* Load shift vector for this list */
930         i_shift_offset   = DIM*shiftidx[iidx];
931
932         /* Load limits for loop over neighbors */
933         j_index_start    = jindex[iidx];
934         j_index_end      = jindex[iidx+1];
935
936         /* Get outer coordinate index */
937         inr              = iinr[iidx];
938         i_coord_offset   = DIM*inr;
939
940         /* Load i particle coords and add shift vector */
941         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
942                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
943
944         fix0             = _mm_setzero_ps();
945         fiy0             = _mm_setzero_ps();
946         fiz0             = _mm_setzero_ps();
947         fix1             = _mm_setzero_ps();
948         fiy1             = _mm_setzero_ps();
949         fiz1             = _mm_setzero_ps();
950         fix2             = _mm_setzero_ps();
951         fiy2             = _mm_setzero_ps();
952         fiz2             = _mm_setzero_ps();
953         fix3             = _mm_setzero_ps();
954         fiy3             = _mm_setzero_ps();
955         fiz3             = _mm_setzero_ps();
956
957         /* Start inner kernel loop */
958         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
959         {
960
961             /* Get j neighbor index, and coordinate index */
962             jnrA             = jjnr[jidx];
963             jnrB             = jjnr[jidx+1];
964             jnrC             = jjnr[jidx+2];
965             jnrD             = jjnr[jidx+3];
966             j_coord_offsetA  = DIM*jnrA;
967             j_coord_offsetB  = DIM*jnrB;
968             j_coord_offsetC  = DIM*jnrC;
969             j_coord_offsetD  = DIM*jnrD;
970
971             /* load j atom coordinates */
972             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
973                                               x+j_coord_offsetC,x+j_coord_offsetD,
974                                               &jx0,&jy0,&jz0);
975
976             /* Calculate displacement vector */
977             dx00             = _mm_sub_ps(ix0,jx0);
978             dy00             = _mm_sub_ps(iy0,jy0);
979             dz00             = _mm_sub_ps(iz0,jz0);
980             dx10             = _mm_sub_ps(ix1,jx0);
981             dy10             = _mm_sub_ps(iy1,jy0);
982             dz10             = _mm_sub_ps(iz1,jz0);
983             dx20             = _mm_sub_ps(ix2,jx0);
984             dy20             = _mm_sub_ps(iy2,jy0);
985             dz20             = _mm_sub_ps(iz2,jz0);
986             dx30             = _mm_sub_ps(ix3,jx0);
987             dy30             = _mm_sub_ps(iy3,jy0);
988             dz30             = _mm_sub_ps(iz3,jz0);
989
990             /* Calculate squared distance and things based on it */
991             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
992             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
993             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
994             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
995
996             rinv10           = sse41_invsqrt_f(rsq10);
997             rinv20           = sse41_invsqrt_f(rsq20);
998             rinv30           = sse41_invsqrt_f(rsq30);
999
1000             rinvsq00         = sse41_inv_f(rsq00);
1001             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1002             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1003             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
1004
1005             /* Load parameters for j particles */
1006             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1007                                                               charge+jnrC+0,charge+jnrD+0);
1008             vdwjidx0A        = 2*vdwtype[jnrA+0];
1009             vdwjidx0B        = 2*vdwtype[jnrB+0];
1010             vdwjidx0C        = 2*vdwtype[jnrC+0];
1011             vdwjidx0D        = 2*vdwtype[jnrD+0];
1012
1013             fjx0             = _mm_setzero_ps();
1014             fjy0             = _mm_setzero_ps();
1015             fjz0             = _mm_setzero_ps();
1016
1017             /**************************
1018              * CALCULATE INTERACTIONS *
1019              **************************/
1020
1021             if (gmx_mm_any_lt(rsq00,rcutoff2))
1022             {
1023
1024             /* Compute parameters for interactions between i and j atoms */
1025             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1026                                          vdwparam+vdwioffset0+vdwjidx0B,
1027                                          vdwparam+vdwioffset0+vdwjidx0C,
1028                                          vdwparam+vdwioffset0+vdwjidx0D,
1029                                          &c6_00,&c12_00);
1030
1031             /* LENNARD-JONES DISPERSION/REPULSION */
1032
1033             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1034             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1035
1036             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1037
1038             fscal            = fvdw;
1039
1040             fscal            = _mm_and_ps(fscal,cutoff_mask);
1041
1042             /* Calculate temporary vectorial force */
1043             tx               = _mm_mul_ps(fscal,dx00);
1044             ty               = _mm_mul_ps(fscal,dy00);
1045             tz               = _mm_mul_ps(fscal,dz00);
1046
1047             /* Update vectorial force */
1048             fix0             = _mm_add_ps(fix0,tx);
1049             fiy0             = _mm_add_ps(fiy0,ty);
1050             fiz0             = _mm_add_ps(fiz0,tz);
1051
1052             fjx0             = _mm_add_ps(fjx0,tx);
1053             fjy0             = _mm_add_ps(fjy0,ty);
1054             fjz0             = _mm_add_ps(fjz0,tz);
1055
1056             }
1057
1058             /**************************
1059              * CALCULATE INTERACTIONS *
1060              **************************/
1061
1062             if (gmx_mm_any_lt(rsq10,rcutoff2))
1063             {
1064
1065             r10              = _mm_mul_ps(rsq10,rinv10);
1066
1067             /* Compute parameters for interactions between i and j atoms */
1068             qq10             = _mm_mul_ps(iq1,jq0);
1069
1070             /* EWALD ELECTROSTATICS */
1071
1072             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1073             ewrt             = _mm_mul_ps(r10,ewtabscale);
1074             ewitab           = _mm_cvttps_epi32(ewrt);
1075             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1076             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1077                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1078                                          &ewtabF,&ewtabFn);
1079             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1080             felec            = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
1081
1082             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1083
1084             fscal            = felec;
1085
1086             fscal            = _mm_and_ps(fscal,cutoff_mask);
1087
1088             /* Calculate temporary vectorial force */
1089             tx               = _mm_mul_ps(fscal,dx10);
1090             ty               = _mm_mul_ps(fscal,dy10);
1091             tz               = _mm_mul_ps(fscal,dz10);
1092
1093             /* Update vectorial force */
1094             fix1             = _mm_add_ps(fix1,tx);
1095             fiy1             = _mm_add_ps(fiy1,ty);
1096             fiz1             = _mm_add_ps(fiz1,tz);
1097
1098             fjx0             = _mm_add_ps(fjx0,tx);
1099             fjy0             = _mm_add_ps(fjy0,ty);
1100             fjz0             = _mm_add_ps(fjz0,tz);
1101
1102             }
1103
1104             /**************************
1105              * CALCULATE INTERACTIONS *
1106              **************************/
1107
1108             if (gmx_mm_any_lt(rsq20,rcutoff2))
1109             {
1110
1111             r20              = _mm_mul_ps(rsq20,rinv20);
1112
1113             /* Compute parameters for interactions between i and j atoms */
1114             qq20             = _mm_mul_ps(iq2,jq0);
1115
1116             /* EWALD ELECTROSTATICS */
1117
1118             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1119             ewrt             = _mm_mul_ps(r20,ewtabscale);
1120             ewitab           = _mm_cvttps_epi32(ewrt);
1121             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1122             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1123                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1124                                          &ewtabF,&ewtabFn);
1125             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1126             felec            = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
1127
1128             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1129
1130             fscal            = felec;
1131
1132             fscal            = _mm_and_ps(fscal,cutoff_mask);
1133
1134             /* Calculate temporary vectorial force */
1135             tx               = _mm_mul_ps(fscal,dx20);
1136             ty               = _mm_mul_ps(fscal,dy20);
1137             tz               = _mm_mul_ps(fscal,dz20);
1138
1139             /* Update vectorial force */
1140             fix2             = _mm_add_ps(fix2,tx);
1141             fiy2             = _mm_add_ps(fiy2,ty);
1142             fiz2             = _mm_add_ps(fiz2,tz);
1143
1144             fjx0             = _mm_add_ps(fjx0,tx);
1145             fjy0             = _mm_add_ps(fjy0,ty);
1146             fjz0             = _mm_add_ps(fjz0,tz);
1147
1148             }
1149
1150             /**************************
1151              * CALCULATE INTERACTIONS *
1152              **************************/
1153
1154             if (gmx_mm_any_lt(rsq30,rcutoff2))
1155             {
1156
1157             r30              = _mm_mul_ps(rsq30,rinv30);
1158
1159             /* Compute parameters for interactions between i and j atoms */
1160             qq30             = _mm_mul_ps(iq3,jq0);
1161
1162             /* EWALD ELECTROSTATICS */
1163
1164             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1165             ewrt             = _mm_mul_ps(r30,ewtabscale);
1166             ewitab           = _mm_cvttps_epi32(ewrt);
1167             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1168             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1169                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1170                                          &ewtabF,&ewtabFn);
1171             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1172             felec            = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
1173
1174             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
1175
1176             fscal            = felec;
1177
1178             fscal            = _mm_and_ps(fscal,cutoff_mask);
1179
1180             /* Calculate temporary vectorial force */
1181             tx               = _mm_mul_ps(fscal,dx30);
1182             ty               = _mm_mul_ps(fscal,dy30);
1183             tz               = _mm_mul_ps(fscal,dz30);
1184
1185             /* Update vectorial force */
1186             fix3             = _mm_add_ps(fix3,tx);
1187             fiy3             = _mm_add_ps(fiy3,ty);
1188             fiz3             = _mm_add_ps(fiz3,tz);
1189
1190             fjx0             = _mm_add_ps(fjx0,tx);
1191             fjy0             = _mm_add_ps(fjy0,ty);
1192             fjz0             = _mm_add_ps(fjz0,tz);
1193
1194             }
1195
1196             fjptrA             = f+j_coord_offsetA;
1197             fjptrB             = f+j_coord_offsetB;
1198             fjptrC             = f+j_coord_offsetC;
1199             fjptrD             = f+j_coord_offsetD;
1200
1201             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1202
1203             /* Inner loop uses 147 flops */
1204         }
1205
1206         if(jidx<j_index_end)
1207         {
1208
1209             /* Get j neighbor index, and coordinate index */
1210             jnrlistA         = jjnr[jidx];
1211             jnrlistB         = jjnr[jidx+1];
1212             jnrlistC         = jjnr[jidx+2];
1213             jnrlistD         = jjnr[jidx+3];
1214             /* Sign of each element will be negative for non-real atoms.
1215              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1216              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1217              */
1218             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1219             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1220             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1221             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1222             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1223             j_coord_offsetA  = DIM*jnrA;
1224             j_coord_offsetB  = DIM*jnrB;
1225             j_coord_offsetC  = DIM*jnrC;
1226             j_coord_offsetD  = DIM*jnrD;
1227
1228             /* load j atom coordinates */
1229             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1230                                               x+j_coord_offsetC,x+j_coord_offsetD,
1231                                               &jx0,&jy0,&jz0);
1232
1233             /* Calculate displacement vector */
1234             dx00             = _mm_sub_ps(ix0,jx0);
1235             dy00             = _mm_sub_ps(iy0,jy0);
1236             dz00             = _mm_sub_ps(iz0,jz0);
1237             dx10             = _mm_sub_ps(ix1,jx0);
1238             dy10             = _mm_sub_ps(iy1,jy0);
1239             dz10             = _mm_sub_ps(iz1,jz0);
1240             dx20             = _mm_sub_ps(ix2,jx0);
1241             dy20             = _mm_sub_ps(iy2,jy0);
1242             dz20             = _mm_sub_ps(iz2,jz0);
1243             dx30             = _mm_sub_ps(ix3,jx0);
1244             dy30             = _mm_sub_ps(iy3,jy0);
1245             dz30             = _mm_sub_ps(iz3,jz0);
1246
1247             /* Calculate squared distance and things based on it */
1248             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1249             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1250             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1251             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1252
1253             rinv10           = sse41_invsqrt_f(rsq10);
1254             rinv20           = sse41_invsqrt_f(rsq20);
1255             rinv30           = sse41_invsqrt_f(rsq30);
1256
1257             rinvsq00         = sse41_inv_f(rsq00);
1258             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1259             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1260             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
1261
1262             /* Load parameters for j particles */
1263             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1264                                                               charge+jnrC+0,charge+jnrD+0);
1265             vdwjidx0A        = 2*vdwtype[jnrA+0];
1266             vdwjidx0B        = 2*vdwtype[jnrB+0];
1267             vdwjidx0C        = 2*vdwtype[jnrC+0];
1268             vdwjidx0D        = 2*vdwtype[jnrD+0];
1269
1270             fjx0             = _mm_setzero_ps();
1271             fjy0             = _mm_setzero_ps();
1272             fjz0             = _mm_setzero_ps();
1273
1274             /**************************
1275              * CALCULATE INTERACTIONS *
1276              **************************/
1277
1278             if (gmx_mm_any_lt(rsq00,rcutoff2))
1279             {
1280
1281             /* Compute parameters for interactions between i and j atoms */
1282             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1283                                          vdwparam+vdwioffset0+vdwjidx0B,
1284                                          vdwparam+vdwioffset0+vdwjidx0C,
1285                                          vdwparam+vdwioffset0+vdwjidx0D,
1286                                          &c6_00,&c12_00);
1287
1288             /* LENNARD-JONES DISPERSION/REPULSION */
1289
1290             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1291             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1292
1293             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1294
1295             fscal            = fvdw;
1296
1297             fscal            = _mm_and_ps(fscal,cutoff_mask);
1298
1299             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1300
1301             /* Calculate temporary vectorial force */
1302             tx               = _mm_mul_ps(fscal,dx00);
1303             ty               = _mm_mul_ps(fscal,dy00);
1304             tz               = _mm_mul_ps(fscal,dz00);
1305
1306             /* Update vectorial force */
1307             fix0             = _mm_add_ps(fix0,tx);
1308             fiy0             = _mm_add_ps(fiy0,ty);
1309             fiz0             = _mm_add_ps(fiz0,tz);
1310
1311             fjx0             = _mm_add_ps(fjx0,tx);
1312             fjy0             = _mm_add_ps(fjy0,ty);
1313             fjz0             = _mm_add_ps(fjz0,tz);
1314
1315             }
1316
1317             /**************************
1318              * CALCULATE INTERACTIONS *
1319              **************************/
1320
1321             if (gmx_mm_any_lt(rsq10,rcutoff2))
1322             {
1323
1324             r10              = _mm_mul_ps(rsq10,rinv10);
1325             r10              = _mm_andnot_ps(dummy_mask,r10);
1326
1327             /* Compute parameters for interactions between i and j atoms */
1328             qq10             = _mm_mul_ps(iq1,jq0);
1329
1330             /* EWALD ELECTROSTATICS */
1331
1332             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1333             ewrt             = _mm_mul_ps(r10,ewtabscale);
1334             ewitab           = _mm_cvttps_epi32(ewrt);
1335             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1336             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1337                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1338                                          &ewtabF,&ewtabFn);
1339             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1340             felec            = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
1341
1342             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1343
1344             fscal            = felec;
1345
1346             fscal            = _mm_and_ps(fscal,cutoff_mask);
1347
1348             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1349
1350             /* Calculate temporary vectorial force */
1351             tx               = _mm_mul_ps(fscal,dx10);
1352             ty               = _mm_mul_ps(fscal,dy10);
1353             tz               = _mm_mul_ps(fscal,dz10);
1354
1355             /* Update vectorial force */
1356             fix1             = _mm_add_ps(fix1,tx);
1357             fiy1             = _mm_add_ps(fiy1,ty);
1358             fiz1             = _mm_add_ps(fiz1,tz);
1359
1360             fjx0             = _mm_add_ps(fjx0,tx);
1361             fjy0             = _mm_add_ps(fjy0,ty);
1362             fjz0             = _mm_add_ps(fjz0,tz);
1363
1364             }
1365
1366             /**************************
1367              * CALCULATE INTERACTIONS *
1368              **************************/
1369
1370             if (gmx_mm_any_lt(rsq20,rcutoff2))
1371             {
1372
1373             r20              = _mm_mul_ps(rsq20,rinv20);
1374             r20              = _mm_andnot_ps(dummy_mask,r20);
1375
1376             /* Compute parameters for interactions between i and j atoms */
1377             qq20             = _mm_mul_ps(iq2,jq0);
1378
1379             /* EWALD ELECTROSTATICS */
1380
1381             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1382             ewrt             = _mm_mul_ps(r20,ewtabscale);
1383             ewitab           = _mm_cvttps_epi32(ewrt);
1384             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1385             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1386                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1387                                          &ewtabF,&ewtabFn);
1388             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1389             felec            = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
1390
1391             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1392
1393             fscal            = felec;
1394
1395             fscal            = _mm_and_ps(fscal,cutoff_mask);
1396
1397             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1398
1399             /* Calculate temporary vectorial force */
1400             tx               = _mm_mul_ps(fscal,dx20);
1401             ty               = _mm_mul_ps(fscal,dy20);
1402             tz               = _mm_mul_ps(fscal,dz20);
1403
1404             /* Update vectorial force */
1405             fix2             = _mm_add_ps(fix2,tx);
1406             fiy2             = _mm_add_ps(fiy2,ty);
1407             fiz2             = _mm_add_ps(fiz2,tz);
1408
1409             fjx0             = _mm_add_ps(fjx0,tx);
1410             fjy0             = _mm_add_ps(fjy0,ty);
1411             fjz0             = _mm_add_ps(fjz0,tz);
1412
1413             }
1414
1415             /**************************
1416              * CALCULATE INTERACTIONS *
1417              **************************/
1418
1419             if (gmx_mm_any_lt(rsq30,rcutoff2))
1420             {
1421
1422             r30              = _mm_mul_ps(rsq30,rinv30);
1423             r30              = _mm_andnot_ps(dummy_mask,r30);
1424
1425             /* Compute parameters for interactions between i and j atoms */
1426             qq30             = _mm_mul_ps(iq3,jq0);
1427
1428             /* EWALD ELECTROSTATICS */
1429
1430             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1431             ewrt             = _mm_mul_ps(r30,ewtabscale);
1432             ewitab           = _mm_cvttps_epi32(ewrt);
1433             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1434             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1435                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1436                                          &ewtabF,&ewtabFn);
1437             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1438             felec            = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
1439
1440             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
1441
1442             fscal            = felec;
1443
1444             fscal            = _mm_and_ps(fscal,cutoff_mask);
1445
1446             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1447
1448             /* Calculate temporary vectorial force */
1449             tx               = _mm_mul_ps(fscal,dx30);
1450             ty               = _mm_mul_ps(fscal,dy30);
1451             tz               = _mm_mul_ps(fscal,dz30);
1452
1453             /* Update vectorial force */
1454             fix3             = _mm_add_ps(fix3,tx);
1455             fiy3             = _mm_add_ps(fiy3,ty);
1456             fiz3             = _mm_add_ps(fiz3,tz);
1457
1458             fjx0             = _mm_add_ps(fjx0,tx);
1459             fjy0             = _mm_add_ps(fjy0,ty);
1460             fjz0             = _mm_add_ps(fjz0,tz);
1461
1462             }
1463
1464             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1465             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1466             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1467             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1468
1469             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1470
1471             /* Inner loop uses 150 flops */
1472         }
1473
1474         /* End of innermost loop */
1475
1476         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1477                                               f+i_coord_offset,fshift+i_shift_offset);
1478
1479         /* Increment number of inner iterations */
1480         inneriter                  += j_index_end - j_index_start;
1481
1482         /* Outer loop uses 24 flops */
1483     }
1484
1485     /* Increment number of outer iterations */
1486     outeriter        += nri;
1487
1488     /* Update outer/inner flops */
1489
1490     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*150);
1491 }