8c8f333175fff4a336c48bc3509e90a54437bcf8
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_single / nb_kernel_ElecCoul_VdwLJ_GeomW4P1_sse2_single.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS sse2_single kernel generator.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "vec.h"
47 #include "nrnb.h"
48
49 #include "gmx_math_x86_sse2_single.h"
50 #include "kernelutil_x86_sse2_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_sse2_single
54  * Electrostatics interaction: Coulomb
55  * VdW interaction:            LennardJones
56  * Geometry:                   Water4-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_sse2_single
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
70      * just 0 for non-waters.
71      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB,jnrC,jnrD;
77     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
80     real             rcutoff_scalar;
81     real             *shiftvec,*fshift,*x,*f;
82     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
83     real             scratch[4*DIM];
84     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
85     int              vdwioffset0;
86     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87     int              vdwioffset1;
88     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
89     int              vdwioffset2;
90     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
91     int              vdwioffset3;
92     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
100     real             *charge;
101     int              nvdwtype;
102     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103     int              *vdwtype;
104     real             *vdwparam;
105     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
106     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
107     __m128           dummy_mask,cutoff_mask;
108     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
109     __m128           one     = _mm_set1_ps(1.0);
110     __m128           two     = _mm_set1_ps(2.0);
111     x                = xx[0];
112     f                = ff[0];
113
114     nri              = nlist->nri;
115     iinr             = nlist->iinr;
116     jindex           = nlist->jindex;
117     jjnr             = nlist->jjnr;
118     shiftidx         = nlist->shift;
119     gid              = nlist->gid;
120     shiftvec         = fr->shift_vec[0];
121     fshift           = fr->fshift[0];
122     facel            = _mm_set1_ps(fr->epsfac);
123     charge           = mdatoms->chargeA;
124     nvdwtype         = fr->ntype;
125     vdwparam         = fr->nbfp;
126     vdwtype          = mdatoms->typeA;
127
128     /* Setup water-specific parameters */
129     inr              = nlist->iinr[0];
130     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
131     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
132     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
133     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
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             /* Compute parameters for interactions between i and j atoms */
250             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
251                                          vdwparam+vdwioffset0+vdwjidx0B,
252                                          vdwparam+vdwioffset0+vdwjidx0C,
253                                          vdwparam+vdwioffset0+vdwjidx0D,
254                                          &c6_00,&c12_00);
255
256             /* LENNARD-JONES DISPERSION/REPULSION */
257
258             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
259             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
260             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
261             vvdw             = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
262             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
263
264             /* Update potential sum for this i atom from the interaction with this j atom. */
265             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
266
267             fscal            = fvdw;
268
269             /* Calculate temporary vectorial force */
270             tx               = _mm_mul_ps(fscal,dx00);
271             ty               = _mm_mul_ps(fscal,dy00);
272             tz               = _mm_mul_ps(fscal,dz00);
273
274             /* Update vectorial force */
275             fix0             = _mm_add_ps(fix0,tx);
276             fiy0             = _mm_add_ps(fiy0,ty);
277             fiz0             = _mm_add_ps(fiz0,tz);
278
279             fjx0             = _mm_add_ps(fjx0,tx);
280             fjy0             = _mm_add_ps(fjy0,ty);
281             fjz0             = _mm_add_ps(fjz0,tz);
282             
283             /**************************
284              * CALCULATE INTERACTIONS *
285              **************************/
286
287             /* Compute parameters for interactions between i and j atoms */
288             qq10             = _mm_mul_ps(iq1,jq0);
289
290             /* COULOMB ELECTROSTATICS */
291             velec            = _mm_mul_ps(qq10,rinv10);
292             felec            = _mm_mul_ps(velec,rinvsq10);
293
294             /* Update potential sum for this i atom from the interaction with this j atom. */
295             velecsum         = _mm_add_ps(velecsum,velec);
296
297             fscal            = felec;
298
299             /* Calculate temporary vectorial force */
300             tx               = _mm_mul_ps(fscal,dx10);
301             ty               = _mm_mul_ps(fscal,dy10);
302             tz               = _mm_mul_ps(fscal,dz10);
303
304             /* Update vectorial force */
305             fix1             = _mm_add_ps(fix1,tx);
306             fiy1             = _mm_add_ps(fiy1,ty);
307             fiz1             = _mm_add_ps(fiz1,tz);
308
309             fjx0             = _mm_add_ps(fjx0,tx);
310             fjy0             = _mm_add_ps(fjy0,ty);
311             fjz0             = _mm_add_ps(fjz0,tz);
312             
313             /**************************
314              * CALCULATE INTERACTIONS *
315              **************************/
316
317             /* Compute parameters for interactions between i and j atoms */
318             qq20             = _mm_mul_ps(iq2,jq0);
319
320             /* COULOMB ELECTROSTATICS */
321             velec            = _mm_mul_ps(qq20,rinv20);
322             felec            = _mm_mul_ps(velec,rinvsq20);
323
324             /* Update potential sum for this i atom from the interaction with this j atom. */
325             velecsum         = _mm_add_ps(velecsum,velec);
326
327             fscal            = felec;
328
329             /* Calculate temporary vectorial force */
330             tx               = _mm_mul_ps(fscal,dx20);
331             ty               = _mm_mul_ps(fscal,dy20);
332             tz               = _mm_mul_ps(fscal,dz20);
333
334             /* Update vectorial force */
335             fix2             = _mm_add_ps(fix2,tx);
336             fiy2             = _mm_add_ps(fiy2,ty);
337             fiz2             = _mm_add_ps(fiz2,tz);
338
339             fjx0             = _mm_add_ps(fjx0,tx);
340             fjy0             = _mm_add_ps(fjy0,ty);
341             fjz0             = _mm_add_ps(fjz0,tz);
342             
343             /**************************
344              * CALCULATE INTERACTIONS *
345              **************************/
346
347             /* Compute parameters for interactions between i and j atoms */
348             qq30             = _mm_mul_ps(iq3,jq0);
349
350             /* COULOMB ELECTROSTATICS */
351             velec            = _mm_mul_ps(qq30,rinv30);
352             felec            = _mm_mul_ps(velec,rinvsq30);
353
354             /* Update potential sum for this i atom from the interaction with this j atom. */
355             velecsum         = _mm_add_ps(velecsum,velec);
356
357             fscal            = felec;
358
359             /* Calculate temporary vectorial force */
360             tx               = _mm_mul_ps(fscal,dx30);
361             ty               = _mm_mul_ps(fscal,dy30);
362             tz               = _mm_mul_ps(fscal,dz30);
363
364             /* Update vectorial force */
365             fix3             = _mm_add_ps(fix3,tx);
366             fiy3             = _mm_add_ps(fiy3,ty);
367             fiz3             = _mm_add_ps(fiz3,tz);
368
369             fjx0             = _mm_add_ps(fjx0,tx);
370             fjy0             = _mm_add_ps(fjy0,ty);
371             fjz0             = _mm_add_ps(fjz0,tz);
372             
373             fjptrA             = f+j_coord_offsetA;
374             fjptrB             = f+j_coord_offsetB;
375             fjptrC             = f+j_coord_offsetC;
376             fjptrD             = f+j_coord_offsetD;
377
378             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
379
380             /* Inner loop uses 116 flops */
381         }
382
383         if(jidx<j_index_end)
384         {
385
386             /* Get j neighbor index, and coordinate index */
387             jnrlistA         = jjnr[jidx];
388             jnrlistB         = jjnr[jidx+1];
389             jnrlistC         = jjnr[jidx+2];
390             jnrlistD         = jjnr[jidx+3];
391             /* Sign of each element will be negative for non-real atoms.
392              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
393              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
394              */
395             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
396             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
397             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
398             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
399             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
400             j_coord_offsetA  = DIM*jnrA;
401             j_coord_offsetB  = DIM*jnrB;
402             j_coord_offsetC  = DIM*jnrC;
403             j_coord_offsetD  = DIM*jnrD;
404
405             /* load j atom coordinates */
406             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
407                                               x+j_coord_offsetC,x+j_coord_offsetD,
408                                               &jx0,&jy0,&jz0);
409
410             /* Calculate displacement vector */
411             dx00             = _mm_sub_ps(ix0,jx0);
412             dy00             = _mm_sub_ps(iy0,jy0);
413             dz00             = _mm_sub_ps(iz0,jz0);
414             dx10             = _mm_sub_ps(ix1,jx0);
415             dy10             = _mm_sub_ps(iy1,jy0);
416             dz10             = _mm_sub_ps(iz1,jz0);
417             dx20             = _mm_sub_ps(ix2,jx0);
418             dy20             = _mm_sub_ps(iy2,jy0);
419             dz20             = _mm_sub_ps(iz2,jz0);
420             dx30             = _mm_sub_ps(ix3,jx0);
421             dy30             = _mm_sub_ps(iy3,jy0);
422             dz30             = _mm_sub_ps(iz3,jz0);
423
424             /* Calculate squared distance and things based on it */
425             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
426             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
427             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
428             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
429
430             rinv10           = gmx_mm_invsqrt_ps(rsq10);
431             rinv20           = gmx_mm_invsqrt_ps(rsq20);
432             rinv30           = gmx_mm_invsqrt_ps(rsq30);
433
434             rinvsq00         = gmx_mm_inv_ps(rsq00);
435             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
436             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
437             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
438
439             /* Load parameters for j particles */
440             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
441                                                               charge+jnrC+0,charge+jnrD+0);
442             vdwjidx0A        = 2*vdwtype[jnrA+0];
443             vdwjidx0B        = 2*vdwtype[jnrB+0];
444             vdwjidx0C        = 2*vdwtype[jnrC+0];
445             vdwjidx0D        = 2*vdwtype[jnrD+0];
446
447             fjx0             = _mm_setzero_ps();
448             fjy0             = _mm_setzero_ps();
449             fjz0             = _mm_setzero_ps();
450
451             /**************************
452              * CALCULATE INTERACTIONS *
453              **************************/
454
455             /* Compute parameters for interactions between i and j atoms */
456             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
457                                          vdwparam+vdwioffset0+vdwjidx0B,
458                                          vdwparam+vdwioffset0+vdwjidx0C,
459                                          vdwparam+vdwioffset0+vdwjidx0D,
460                                          &c6_00,&c12_00);
461
462             /* LENNARD-JONES DISPERSION/REPULSION */
463
464             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
465             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
466             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
467             vvdw             = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
468             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
469
470             /* Update potential sum for this i atom from the interaction with this j atom. */
471             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
472             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
473
474             fscal            = fvdw;
475
476             fscal            = _mm_andnot_ps(dummy_mask,fscal);
477
478             /* Calculate temporary vectorial force */
479             tx               = _mm_mul_ps(fscal,dx00);
480             ty               = _mm_mul_ps(fscal,dy00);
481             tz               = _mm_mul_ps(fscal,dz00);
482
483             /* Update vectorial force */
484             fix0             = _mm_add_ps(fix0,tx);
485             fiy0             = _mm_add_ps(fiy0,ty);
486             fiz0             = _mm_add_ps(fiz0,tz);
487
488             fjx0             = _mm_add_ps(fjx0,tx);
489             fjy0             = _mm_add_ps(fjy0,ty);
490             fjz0             = _mm_add_ps(fjz0,tz);
491             
492             /**************************
493              * CALCULATE INTERACTIONS *
494              **************************/
495
496             /* Compute parameters for interactions between i and j atoms */
497             qq10             = _mm_mul_ps(iq1,jq0);
498
499             /* COULOMB ELECTROSTATICS */
500             velec            = _mm_mul_ps(qq10,rinv10);
501             felec            = _mm_mul_ps(velec,rinvsq10);
502
503             /* Update potential sum for this i atom from the interaction with this j atom. */
504             velec            = _mm_andnot_ps(dummy_mask,velec);
505             velecsum         = _mm_add_ps(velecsum,velec);
506
507             fscal            = felec;
508
509             fscal            = _mm_andnot_ps(dummy_mask,fscal);
510
511             /* Calculate temporary vectorial force */
512             tx               = _mm_mul_ps(fscal,dx10);
513             ty               = _mm_mul_ps(fscal,dy10);
514             tz               = _mm_mul_ps(fscal,dz10);
515
516             /* Update vectorial force */
517             fix1             = _mm_add_ps(fix1,tx);
518             fiy1             = _mm_add_ps(fiy1,ty);
519             fiz1             = _mm_add_ps(fiz1,tz);
520
521             fjx0             = _mm_add_ps(fjx0,tx);
522             fjy0             = _mm_add_ps(fjy0,ty);
523             fjz0             = _mm_add_ps(fjz0,tz);
524             
525             /**************************
526              * CALCULATE INTERACTIONS *
527              **************************/
528
529             /* Compute parameters for interactions between i and j atoms */
530             qq20             = _mm_mul_ps(iq2,jq0);
531
532             /* COULOMB ELECTROSTATICS */
533             velec            = _mm_mul_ps(qq20,rinv20);
534             felec            = _mm_mul_ps(velec,rinvsq20);
535
536             /* Update potential sum for this i atom from the interaction with this j atom. */
537             velec            = _mm_andnot_ps(dummy_mask,velec);
538             velecsum         = _mm_add_ps(velecsum,velec);
539
540             fscal            = felec;
541
542             fscal            = _mm_andnot_ps(dummy_mask,fscal);
543
544             /* Calculate temporary vectorial force */
545             tx               = _mm_mul_ps(fscal,dx20);
546             ty               = _mm_mul_ps(fscal,dy20);
547             tz               = _mm_mul_ps(fscal,dz20);
548
549             /* Update vectorial force */
550             fix2             = _mm_add_ps(fix2,tx);
551             fiy2             = _mm_add_ps(fiy2,ty);
552             fiz2             = _mm_add_ps(fiz2,tz);
553
554             fjx0             = _mm_add_ps(fjx0,tx);
555             fjy0             = _mm_add_ps(fjy0,ty);
556             fjz0             = _mm_add_ps(fjz0,tz);
557             
558             /**************************
559              * CALCULATE INTERACTIONS *
560              **************************/
561
562             /* Compute parameters for interactions between i and j atoms */
563             qq30             = _mm_mul_ps(iq3,jq0);
564
565             /* COULOMB ELECTROSTATICS */
566             velec            = _mm_mul_ps(qq30,rinv30);
567             felec            = _mm_mul_ps(velec,rinvsq30);
568
569             /* Update potential sum for this i atom from the interaction with this j atom. */
570             velec            = _mm_andnot_ps(dummy_mask,velec);
571             velecsum         = _mm_add_ps(velecsum,velec);
572
573             fscal            = felec;
574
575             fscal            = _mm_andnot_ps(dummy_mask,fscal);
576
577             /* Calculate temporary vectorial force */
578             tx               = _mm_mul_ps(fscal,dx30);
579             ty               = _mm_mul_ps(fscal,dy30);
580             tz               = _mm_mul_ps(fscal,dz30);
581
582             /* Update vectorial force */
583             fix3             = _mm_add_ps(fix3,tx);
584             fiy3             = _mm_add_ps(fiy3,ty);
585             fiz3             = _mm_add_ps(fiz3,tz);
586
587             fjx0             = _mm_add_ps(fjx0,tx);
588             fjy0             = _mm_add_ps(fjy0,ty);
589             fjz0             = _mm_add_ps(fjz0,tz);
590             
591             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
592             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
593             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
594             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
595
596             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
597
598             /* Inner loop uses 116 flops */
599         }
600
601         /* End of innermost loop */
602
603         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
604                                               f+i_coord_offset,fshift+i_shift_offset);
605
606         ggid                        = gid[iidx];
607         /* Update potential energies */
608         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
609         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
610
611         /* Increment number of inner iterations */
612         inneriter                  += j_index_end - j_index_start;
613
614         /* Outer loop uses 26 flops */
615     }
616
617     /* Increment number of outer iterations */
618     outeriter        += nri;
619
620     /* Update outer/inner flops */
621
622     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*116);
623 }
624 /*
625  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_sse2_single
626  * Electrostatics interaction: Coulomb
627  * VdW interaction:            LennardJones
628  * Geometry:                   Water4-Particle
629  * Calculate force/pot:        Force
630  */
631 void
632 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_sse2_single
633                     (t_nblist                    * gmx_restrict       nlist,
634                      rvec                        * gmx_restrict          xx,
635                      rvec                        * gmx_restrict          ff,
636                      t_forcerec                  * gmx_restrict          fr,
637                      t_mdatoms                   * gmx_restrict     mdatoms,
638                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
639                      t_nrnb                      * gmx_restrict        nrnb)
640 {
641     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
642      * just 0 for non-waters.
643      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
644      * jnr indices corresponding to data put in the four positions in the SIMD register.
645      */
646     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
647     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
648     int              jnrA,jnrB,jnrC,jnrD;
649     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
650     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
651     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
652     real             rcutoff_scalar;
653     real             *shiftvec,*fshift,*x,*f;
654     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
655     real             scratch[4*DIM];
656     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
657     int              vdwioffset0;
658     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
659     int              vdwioffset1;
660     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
661     int              vdwioffset2;
662     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
663     int              vdwioffset3;
664     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
665     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
666     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
667     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
668     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
669     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
670     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
671     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
672     real             *charge;
673     int              nvdwtype;
674     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
675     int              *vdwtype;
676     real             *vdwparam;
677     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
678     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
679     __m128           dummy_mask,cutoff_mask;
680     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
681     __m128           one     = _mm_set1_ps(1.0);
682     __m128           two     = _mm_set1_ps(2.0);
683     x                = xx[0];
684     f                = ff[0];
685
686     nri              = nlist->nri;
687     iinr             = nlist->iinr;
688     jindex           = nlist->jindex;
689     jjnr             = nlist->jjnr;
690     shiftidx         = nlist->shift;
691     gid              = nlist->gid;
692     shiftvec         = fr->shift_vec[0];
693     fshift           = fr->fshift[0];
694     facel            = _mm_set1_ps(fr->epsfac);
695     charge           = mdatoms->chargeA;
696     nvdwtype         = fr->ntype;
697     vdwparam         = fr->nbfp;
698     vdwtype          = mdatoms->typeA;
699
700     /* Setup water-specific parameters */
701     inr              = nlist->iinr[0];
702     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
703     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
704     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
705     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
706
707     /* Avoid stupid compiler warnings */
708     jnrA = jnrB = jnrC = jnrD = 0;
709     j_coord_offsetA = 0;
710     j_coord_offsetB = 0;
711     j_coord_offsetC = 0;
712     j_coord_offsetD = 0;
713
714     outeriter        = 0;
715     inneriter        = 0;
716
717     for(iidx=0;iidx<4*DIM;iidx++)
718     {
719         scratch[iidx] = 0.0;
720     }  
721
722     /* Start outer loop over neighborlists */
723     for(iidx=0; iidx<nri; iidx++)
724     {
725         /* Load shift vector for this list */
726         i_shift_offset   = DIM*shiftidx[iidx];
727
728         /* Load limits for loop over neighbors */
729         j_index_start    = jindex[iidx];
730         j_index_end      = jindex[iidx+1];
731
732         /* Get outer coordinate index */
733         inr              = iinr[iidx];
734         i_coord_offset   = DIM*inr;
735
736         /* Load i particle coords and add shift vector */
737         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
738                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
739         
740         fix0             = _mm_setzero_ps();
741         fiy0             = _mm_setzero_ps();
742         fiz0             = _mm_setzero_ps();
743         fix1             = _mm_setzero_ps();
744         fiy1             = _mm_setzero_ps();
745         fiz1             = _mm_setzero_ps();
746         fix2             = _mm_setzero_ps();
747         fiy2             = _mm_setzero_ps();
748         fiz2             = _mm_setzero_ps();
749         fix3             = _mm_setzero_ps();
750         fiy3             = _mm_setzero_ps();
751         fiz3             = _mm_setzero_ps();
752
753         /* Start inner kernel loop */
754         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
755         {
756
757             /* Get j neighbor index, and coordinate index */
758             jnrA             = jjnr[jidx];
759             jnrB             = jjnr[jidx+1];
760             jnrC             = jjnr[jidx+2];
761             jnrD             = jjnr[jidx+3];
762             j_coord_offsetA  = DIM*jnrA;
763             j_coord_offsetB  = DIM*jnrB;
764             j_coord_offsetC  = DIM*jnrC;
765             j_coord_offsetD  = DIM*jnrD;
766
767             /* load j atom coordinates */
768             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
769                                               x+j_coord_offsetC,x+j_coord_offsetD,
770                                               &jx0,&jy0,&jz0);
771
772             /* Calculate displacement vector */
773             dx00             = _mm_sub_ps(ix0,jx0);
774             dy00             = _mm_sub_ps(iy0,jy0);
775             dz00             = _mm_sub_ps(iz0,jz0);
776             dx10             = _mm_sub_ps(ix1,jx0);
777             dy10             = _mm_sub_ps(iy1,jy0);
778             dz10             = _mm_sub_ps(iz1,jz0);
779             dx20             = _mm_sub_ps(ix2,jx0);
780             dy20             = _mm_sub_ps(iy2,jy0);
781             dz20             = _mm_sub_ps(iz2,jz0);
782             dx30             = _mm_sub_ps(ix3,jx0);
783             dy30             = _mm_sub_ps(iy3,jy0);
784             dz30             = _mm_sub_ps(iz3,jz0);
785
786             /* Calculate squared distance and things based on it */
787             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
788             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
789             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
790             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
791
792             rinv10           = gmx_mm_invsqrt_ps(rsq10);
793             rinv20           = gmx_mm_invsqrt_ps(rsq20);
794             rinv30           = gmx_mm_invsqrt_ps(rsq30);
795
796             rinvsq00         = gmx_mm_inv_ps(rsq00);
797             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
798             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
799             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
800
801             /* Load parameters for j particles */
802             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
803                                                               charge+jnrC+0,charge+jnrD+0);
804             vdwjidx0A        = 2*vdwtype[jnrA+0];
805             vdwjidx0B        = 2*vdwtype[jnrB+0];
806             vdwjidx0C        = 2*vdwtype[jnrC+0];
807             vdwjidx0D        = 2*vdwtype[jnrD+0];
808
809             fjx0             = _mm_setzero_ps();
810             fjy0             = _mm_setzero_ps();
811             fjz0             = _mm_setzero_ps();
812
813             /**************************
814              * CALCULATE INTERACTIONS *
815              **************************/
816
817             /* Compute parameters for interactions between i and j atoms */
818             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
819                                          vdwparam+vdwioffset0+vdwjidx0B,
820                                          vdwparam+vdwioffset0+vdwjidx0C,
821                                          vdwparam+vdwioffset0+vdwjidx0D,
822                                          &c6_00,&c12_00);
823
824             /* LENNARD-JONES DISPERSION/REPULSION */
825
826             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
827             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
828
829             fscal            = fvdw;
830
831             /* Calculate temporary vectorial force */
832             tx               = _mm_mul_ps(fscal,dx00);
833             ty               = _mm_mul_ps(fscal,dy00);
834             tz               = _mm_mul_ps(fscal,dz00);
835
836             /* Update vectorial force */
837             fix0             = _mm_add_ps(fix0,tx);
838             fiy0             = _mm_add_ps(fiy0,ty);
839             fiz0             = _mm_add_ps(fiz0,tz);
840
841             fjx0             = _mm_add_ps(fjx0,tx);
842             fjy0             = _mm_add_ps(fjy0,ty);
843             fjz0             = _mm_add_ps(fjz0,tz);
844             
845             /**************************
846              * CALCULATE INTERACTIONS *
847              **************************/
848
849             /* Compute parameters for interactions between i and j atoms */
850             qq10             = _mm_mul_ps(iq1,jq0);
851
852             /* COULOMB ELECTROSTATICS */
853             velec            = _mm_mul_ps(qq10,rinv10);
854             felec            = _mm_mul_ps(velec,rinvsq10);
855
856             fscal            = felec;
857
858             /* Calculate temporary vectorial force */
859             tx               = _mm_mul_ps(fscal,dx10);
860             ty               = _mm_mul_ps(fscal,dy10);
861             tz               = _mm_mul_ps(fscal,dz10);
862
863             /* Update vectorial force */
864             fix1             = _mm_add_ps(fix1,tx);
865             fiy1             = _mm_add_ps(fiy1,ty);
866             fiz1             = _mm_add_ps(fiz1,tz);
867
868             fjx0             = _mm_add_ps(fjx0,tx);
869             fjy0             = _mm_add_ps(fjy0,ty);
870             fjz0             = _mm_add_ps(fjz0,tz);
871             
872             /**************************
873              * CALCULATE INTERACTIONS *
874              **************************/
875
876             /* Compute parameters for interactions between i and j atoms */
877             qq20             = _mm_mul_ps(iq2,jq0);
878
879             /* COULOMB ELECTROSTATICS */
880             velec            = _mm_mul_ps(qq20,rinv20);
881             felec            = _mm_mul_ps(velec,rinvsq20);
882
883             fscal            = felec;
884
885             /* Calculate temporary vectorial force */
886             tx               = _mm_mul_ps(fscal,dx20);
887             ty               = _mm_mul_ps(fscal,dy20);
888             tz               = _mm_mul_ps(fscal,dz20);
889
890             /* Update vectorial force */
891             fix2             = _mm_add_ps(fix2,tx);
892             fiy2             = _mm_add_ps(fiy2,ty);
893             fiz2             = _mm_add_ps(fiz2,tz);
894
895             fjx0             = _mm_add_ps(fjx0,tx);
896             fjy0             = _mm_add_ps(fjy0,ty);
897             fjz0             = _mm_add_ps(fjz0,tz);
898             
899             /**************************
900              * CALCULATE INTERACTIONS *
901              **************************/
902
903             /* Compute parameters for interactions between i and j atoms */
904             qq30             = _mm_mul_ps(iq3,jq0);
905
906             /* COULOMB ELECTROSTATICS */
907             velec            = _mm_mul_ps(qq30,rinv30);
908             felec            = _mm_mul_ps(velec,rinvsq30);
909
910             fscal            = felec;
911
912             /* Calculate temporary vectorial force */
913             tx               = _mm_mul_ps(fscal,dx30);
914             ty               = _mm_mul_ps(fscal,dy30);
915             tz               = _mm_mul_ps(fscal,dz30);
916
917             /* Update vectorial force */
918             fix3             = _mm_add_ps(fix3,tx);
919             fiy3             = _mm_add_ps(fiy3,ty);
920             fiz3             = _mm_add_ps(fiz3,tz);
921
922             fjx0             = _mm_add_ps(fjx0,tx);
923             fjy0             = _mm_add_ps(fjy0,ty);
924             fjz0             = _mm_add_ps(fjz0,tz);
925             
926             fjptrA             = f+j_coord_offsetA;
927             fjptrB             = f+j_coord_offsetB;
928             fjptrC             = f+j_coord_offsetC;
929             fjptrD             = f+j_coord_offsetD;
930
931             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
932
933             /* Inner loop uses 108 flops */
934         }
935
936         if(jidx<j_index_end)
937         {
938
939             /* Get j neighbor index, and coordinate index */
940             jnrlistA         = jjnr[jidx];
941             jnrlistB         = jjnr[jidx+1];
942             jnrlistC         = jjnr[jidx+2];
943             jnrlistD         = jjnr[jidx+3];
944             /* Sign of each element will be negative for non-real atoms.
945              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
946              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
947              */
948             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
949             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
950             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
951             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
952             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
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             /* Compute parameters for interactions between i and j atoms */
1009             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1010                                          vdwparam+vdwioffset0+vdwjidx0B,
1011                                          vdwparam+vdwioffset0+vdwjidx0C,
1012                                          vdwparam+vdwioffset0+vdwjidx0D,
1013                                          &c6_00,&c12_00);
1014
1015             /* LENNARD-JONES DISPERSION/REPULSION */
1016
1017             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1018             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1019
1020             fscal            = fvdw;
1021
1022             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1023
1024             /* Calculate temporary vectorial force */
1025             tx               = _mm_mul_ps(fscal,dx00);
1026             ty               = _mm_mul_ps(fscal,dy00);
1027             tz               = _mm_mul_ps(fscal,dz00);
1028
1029             /* Update vectorial force */
1030             fix0             = _mm_add_ps(fix0,tx);
1031             fiy0             = _mm_add_ps(fiy0,ty);
1032             fiz0             = _mm_add_ps(fiz0,tz);
1033
1034             fjx0             = _mm_add_ps(fjx0,tx);
1035             fjy0             = _mm_add_ps(fjy0,ty);
1036             fjz0             = _mm_add_ps(fjz0,tz);
1037             
1038             /**************************
1039              * CALCULATE INTERACTIONS *
1040              **************************/
1041
1042             /* Compute parameters for interactions between i and j atoms */
1043             qq10             = _mm_mul_ps(iq1,jq0);
1044
1045             /* COULOMB ELECTROSTATICS */
1046             velec            = _mm_mul_ps(qq10,rinv10);
1047             felec            = _mm_mul_ps(velec,rinvsq10);
1048
1049             fscal            = felec;
1050
1051             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1052
1053             /* Calculate temporary vectorial force */
1054             tx               = _mm_mul_ps(fscal,dx10);
1055             ty               = _mm_mul_ps(fscal,dy10);
1056             tz               = _mm_mul_ps(fscal,dz10);
1057
1058             /* Update vectorial force */
1059             fix1             = _mm_add_ps(fix1,tx);
1060             fiy1             = _mm_add_ps(fiy1,ty);
1061             fiz1             = _mm_add_ps(fiz1,tz);
1062
1063             fjx0             = _mm_add_ps(fjx0,tx);
1064             fjy0             = _mm_add_ps(fjy0,ty);
1065             fjz0             = _mm_add_ps(fjz0,tz);
1066             
1067             /**************************
1068              * CALCULATE INTERACTIONS *
1069              **************************/
1070
1071             /* Compute parameters for interactions between i and j atoms */
1072             qq20             = _mm_mul_ps(iq2,jq0);
1073
1074             /* COULOMB ELECTROSTATICS */
1075             velec            = _mm_mul_ps(qq20,rinv20);
1076             felec            = _mm_mul_ps(velec,rinvsq20);
1077
1078             fscal            = felec;
1079
1080             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1081
1082             /* Calculate temporary vectorial force */
1083             tx               = _mm_mul_ps(fscal,dx20);
1084             ty               = _mm_mul_ps(fscal,dy20);
1085             tz               = _mm_mul_ps(fscal,dz20);
1086
1087             /* Update vectorial force */
1088             fix2             = _mm_add_ps(fix2,tx);
1089             fiy2             = _mm_add_ps(fiy2,ty);
1090             fiz2             = _mm_add_ps(fiz2,tz);
1091
1092             fjx0             = _mm_add_ps(fjx0,tx);
1093             fjy0             = _mm_add_ps(fjy0,ty);
1094             fjz0             = _mm_add_ps(fjz0,tz);
1095             
1096             /**************************
1097              * CALCULATE INTERACTIONS *
1098              **************************/
1099
1100             /* Compute parameters for interactions between i and j atoms */
1101             qq30             = _mm_mul_ps(iq3,jq0);
1102
1103             /* COULOMB ELECTROSTATICS */
1104             velec            = _mm_mul_ps(qq30,rinv30);
1105             felec            = _mm_mul_ps(velec,rinvsq30);
1106
1107             fscal            = felec;
1108
1109             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1110
1111             /* Calculate temporary vectorial force */
1112             tx               = _mm_mul_ps(fscal,dx30);
1113             ty               = _mm_mul_ps(fscal,dy30);
1114             tz               = _mm_mul_ps(fscal,dz30);
1115
1116             /* Update vectorial force */
1117             fix3             = _mm_add_ps(fix3,tx);
1118             fiy3             = _mm_add_ps(fiy3,ty);
1119             fiz3             = _mm_add_ps(fiz3,tz);
1120
1121             fjx0             = _mm_add_ps(fjx0,tx);
1122             fjy0             = _mm_add_ps(fjy0,ty);
1123             fjz0             = _mm_add_ps(fjz0,tz);
1124             
1125             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1126             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1127             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1128             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1129
1130             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1131
1132             /* Inner loop uses 108 flops */
1133         }
1134
1135         /* End of innermost loop */
1136
1137         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1138                                               f+i_coord_offset,fshift+i_shift_offset);
1139
1140         /* Increment number of inner iterations */
1141         inneriter                  += j_index_end - j_index_start;
1142
1143         /* Outer loop uses 24 flops */
1144     }
1145
1146     /* Increment number of outer iterations */
1147     outeriter        += nri;
1148
1149     /* Update outer/inner flops */
1150
1151     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*108);
1152 }