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