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