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