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