Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_sse2_single / nb_kernel_ElecGB_VdwCSTab_GeomP1P1_sse2_single.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012, by the GROMACS development team, led by
5  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6  * others, as listed in the AUTHORS file in the top-level source
7  * directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS sse2_single kernel generator.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "vec.h"
47 #include "nrnb.h"
48
49 #include "gmx_math_x86_sse2_single.h"
50 #include "kernelutil_x86_sse2_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_sse2_single
54  * Electrostatics interaction: GeneralizedBorn
55  * VdW interaction:            CubicSplineTable
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_sse2_single
61                     (t_nblist * gmx_restrict                nlist,
62                      rvec * gmx_restrict                    xx,
63                      rvec * gmx_restrict                    ff,
64                      t_forcerec * gmx_restrict              fr,
65                      t_mdatoms * gmx_restrict               mdatoms,
66                      nb_kernel_data_t * gmx_restrict        kernel_data,
67                      t_nrnb * gmx_restrict                  nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
70      * just 0 for non-waters.
71      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB,jnrC,jnrD;
77     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
80     real             rcutoff_scalar;
81     real             *shiftvec,*fshift,*x,*f;
82     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
83     real             scratch[4*DIM];
84     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
85     int              vdwioffset0;
86     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
91     real             *charge;
92     __m128i          gbitab;
93     __m128           vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,dvdatmp;
94     __m128           minushalf = _mm_set1_ps(-0.5);
95     real             *invsqrta,*dvda,*gbtab;
96     int              nvdwtype;
97     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
98     int              *vdwtype;
99     real             *vdwparam;
100     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
101     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
102     __m128i          vfitab;
103     __m128i          ifour       = _mm_set1_epi32(4);
104     __m128           rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
105     real             *vftab;
106     __m128           dummy_mask,cutoff_mask;
107     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
108     __m128           one     = _mm_set1_ps(1.0);
109     __m128           two     = _mm_set1_ps(2.0);
110     x                = xx[0];
111     f                = ff[0];
112
113     nri              = nlist->nri;
114     iinr             = nlist->iinr;
115     jindex           = nlist->jindex;
116     jjnr             = nlist->jjnr;
117     shiftidx         = nlist->shift;
118     gid              = nlist->gid;
119     shiftvec         = fr->shift_vec[0];
120     fshift           = fr->fshift[0];
121     facel            = _mm_set1_ps(fr->epsfac);
122     charge           = mdatoms->chargeA;
123     nvdwtype         = fr->ntype;
124     vdwparam         = fr->nbfp;
125     vdwtype          = mdatoms->typeA;
126
127     vftab            = kernel_data->table_vdw->data;
128     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
129
130     invsqrta         = fr->invsqrta;
131     dvda             = fr->dvda;
132     gbtabscale       = _mm_set1_ps(fr->gbtab.scale);
133     gbtab            = fr->gbtab.data;
134     gbinvepsdiff     = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
135
136     /* Avoid stupid compiler warnings */
137     jnrA = jnrB = jnrC = jnrD = 0;
138     j_coord_offsetA = 0;
139     j_coord_offsetB = 0;
140     j_coord_offsetC = 0;
141     j_coord_offsetD = 0;
142
143     outeriter        = 0;
144     inneriter        = 0;
145
146     for(iidx=0;iidx<4*DIM;iidx++)
147     {
148         scratch[iidx] = 0.0;
149     }  
150
151     /* Start outer loop over neighborlists */
152     for(iidx=0; iidx<nri; iidx++)
153     {
154         /* Load shift vector for this list */
155         i_shift_offset   = DIM*shiftidx[iidx];
156
157         /* Load limits for loop over neighbors */
158         j_index_start    = jindex[iidx];
159         j_index_end      = jindex[iidx+1];
160
161         /* Get outer coordinate index */
162         inr              = iinr[iidx];
163         i_coord_offset   = DIM*inr;
164
165         /* Load i particle coords and add shift vector */
166         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
167         
168         fix0             = _mm_setzero_ps();
169         fiy0             = _mm_setzero_ps();
170         fiz0             = _mm_setzero_ps();
171
172         /* Load parameters for i particles */
173         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
174         isai0            = _mm_load1_ps(invsqrta+inr+0);
175         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
176
177         /* Reset potential sums */
178         velecsum         = _mm_setzero_ps();
179         vgbsum           = _mm_setzero_ps();
180         vvdwsum          = _mm_setzero_ps();
181         dvdasum          = _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
207             /* Calculate squared distance and things based on it */
208             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
209
210             rinv00           = gmx_mm_invsqrt_ps(rsq00);
211
212             /* Load parameters for j particles */
213             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
214                                                               charge+jnrC+0,charge+jnrD+0);
215             isaj0            = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
216                                                               invsqrta+jnrC+0,invsqrta+jnrD+0);
217             vdwjidx0A        = 2*vdwtype[jnrA+0];
218             vdwjidx0B        = 2*vdwtype[jnrB+0];
219             vdwjidx0C        = 2*vdwtype[jnrC+0];
220             vdwjidx0D        = 2*vdwtype[jnrD+0];
221
222             /**************************
223              * CALCULATE INTERACTIONS *
224              **************************/
225
226             r00              = _mm_mul_ps(rsq00,rinv00);
227
228             /* Compute parameters for interactions between i and j atoms */
229             qq00             = _mm_mul_ps(iq0,jq0);
230             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
231                                          vdwparam+vdwioffset0+vdwjidx0B,
232                                          vdwparam+vdwioffset0+vdwjidx0C,
233                                          vdwparam+vdwioffset0+vdwjidx0D,
234                                          &c6_00,&c12_00);
235
236             /* Calculate table index by multiplying r with table scale and truncate to integer */
237             rt               = _mm_mul_ps(r00,vftabscale);
238             vfitab           = _mm_cvttps_epi32(rt);
239             vfeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
240             vfitab           = _mm_slli_epi32(vfitab,3);
241
242             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
243             isaprod          = _mm_mul_ps(isai0,isaj0);
244             gbqqfactor       = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
245             gbscale          = _mm_mul_ps(isaprod,gbtabscale);
246
247             /* Calculate generalized born table index - this is a separate table from the normal one,
248              * but we use the same procedure by multiplying r with scale and truncating to integer.
249              */
250             rt               = _mm_mul_ps(r00,gbscale);
251             gbitab           = _mm_cvttps_epi32(rt);
252             gbeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
253             gbitab           = _mm_slli_epi32(gbitab,2);
254
255             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
256             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
257             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
258             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
259             _MM_TRANSPOSE4_PS(Y,F,G,H);
260             Heps             = _mm_mul_ps(gbeps,H);
261             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
262             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
263             vgb              = _mm_mul_ps(gbqqfactor,VV);
264
265             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
266             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
267             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
268             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
269             fjptrA           = dvda+jnrA;
270             fjptrB           = dvda+jnrB;
271             fjptrC           = dvda+jnrC;
272             fjptrD           = dvda+jnrD;
273             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
274             velec            = _mm_mul_ps(qq00,rinv00);
275             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
276
277             /* CUBIC SPLINE TABLE DISPERSION */
278             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
279             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
280             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
281             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
282             _MM_TRANSPOSE4_PS(Y,F,G,H);
283             Heps             = _mm_mul_ps(vfeps,H);
284             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
285             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
286             vvdw6            = _mm_mul_ps(c6_00,VV);
287             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
288             fvdw6            = _mm_mul_ps(c6_00,FF);
289
290             /* CUBIC SPLINE TABLE REPULSION */
291             vfitab           = _mm_add_epi32(vfitab,ifour);
292             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
293             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
294             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
295             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
296             _MM_TRANSPOSE4_PS(Y,F,G,H);
297             Heps             = _mm_mul_ps(vfeps,H);
298             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
299             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
300             vvdw12           = _mm_mul_ps(c12_00,VV);
301             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
302             fvdw12           = _mm_mul_ps(c12_00,FF);
303             vvdw             = _mm_add_ps(vvdw12,vvdw6);
304             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
305
306             /* Update potential sum for this i atom from the interaction with this j atom. */
307             velecsum         = _mm_add_ps(velecsum,velec);
308             vgbsum           = _mm_add_ps(vgbsum,vgb);
309             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
310
311             fscal            = _mm_add_ps(felec,fvdw);
312
313             /* Calculate temporary vectorial force */
314             tx               = _mm_mul_ps(fscal,dx00);
315             ty               = _mm_mul_ps(fscal,dy00);
316             tz               = _mm_mul_ps(fscal,dz00);
317
318             /* Update vectorial force */
319             fix0             = _mm_add_ps(fix0,tx);
320             fiy0             = _mm_add_ps(fiy0,ty);
321             fiz0             = _mm_add_ps(fiz0,tz);
322
323             fjptrA             = f+j_coord_offsetA;
324             fjptrB             = f+j_coord_offsetB;
325             fjptrC             = f+j_coord_offsetC;
326             fjptrD             = f+j_coord_offsetD;
327             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
328             
329             /* Inner loop uses 92 flops */
330         }
331
332         if(jidx<j_index_end)
333         {
334
335             /* Get j neighbor index, and coordinate index */
336             jnrlistA         = jjnr[jidx];
337             jnrlistB         = jjnr[jidx+1];
338             jnrlistC         = jjnr[jidx+2];
339             jnrlistD         = jjnr[jidx+3];
340             /* Sign of each element will be negative for non-real atoms.
341              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
342              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
343              */
344             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
345             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
346             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
347             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
348             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
349             j_coord_offsetA  = DIM*jnrA;
350             j_coord_offsetB  = DIM*jnrB;
351             j_coord_offsetC  = DIM*jnrC;
352             j_coord_offsetD  = DIM*jnrD;
353
354             /* load j atom coordinates */
355             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
356                                               x+j_coord_offsetC,x+j_coord_offsetD,
357                                               &jx0,&jy0,&jz0);
358
359             /* Calculate displacement vector */
360             dx00             = _mm_sub_ps(ix0,jx0);
361             dy00             = _mm_sub_ps(iy0,jy0);
362             dz00             = _mm_sub_ps(iz0,jz0);
363
364             /* Calculate squared distance and things based on it */
365             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
366
367             rinv00           = gmx_mm_invsqrt_ps(rsq00);
368
369             /* Load parameters for j particles */
370             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
371                                                               charge+jnrC+0,charge+jnrD+0);
372             isaj0            = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
373                                                               invsqrta+jnrC+0,invsqrta+jnrD+0);
374             vdwjidx0A        = 2*vdwtype[jnrA+0];
375             vdwjidx0B        = 2*vdwtype[jnrB+0];
376             vdwjidx0C        = 2*vdwtype[jnrC+0];
377             vdwjidx0D        = 2*vdwtype[jnrD+0];
378
379             /**************************
380              * CALCULATE INTERACTIONS *
381              **************************/
382
383             r00              = _mm_mul_ps(rsq00,rinv00);
384             r00              = _mm_andnot_ps(dummy_mask,r00);
385
386             /* Compute parameters for interactions between i and j atoms */
387             qq00             = _mm_mul_ps(iq0,jq0);
388             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
389                                          vdwparam+vdwioffset0+vdwjidx0B,
390                                          vdwparam+vdwioffset0+vdwjidx0C,
391                                          vdwparam+vdwioffset0+vdwjidx0D,
392                                          &c6_00,&c12_00);
393
394             /* Calculate table index by multiplying r with table scale and truncate to integer */
395             rt               = _mm_mul_ps(r00,vftabscale);
396             vfitab           = _mm_cvttps_epi32(rt);
397             vfeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
398             vfitab           = _mm_slli_epi32(vfitab,3);
399
400             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
401             isaprod          = _mm_mul_ps(isai0,isaj0);
402             gbqqfactor       = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
403             gbscale          = _mm_mul_ps(isaprod,gbtabscale);
404
405             /* Calculate generalized born table index - this is a separate table from the normal one,
406              * but we use the same procedure by multiplying r with scale and truncating to integer.
407              */
408             rt               = _mm_mul_ps(r00,gbscale);
409             gbitab           = _mm_cvttps_epi32(rt);
410             gbeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
411             gbitab           = _mm_slli_epi32(gbitab,2);
412
413             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
414             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
415             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
416             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
417             _MM_TRANSPOSE4_PS(Y,F,G,H);
418             Heps             = _mm_mul_ps(gbeps,H);
419             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
420             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
421             vgb              = _mm_mul_ps(gbqqfactor,VV);
422
423             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
424             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
425             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
426             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
427             /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
428             fjptrA             = (jnrlistA>=0) ? dvda+jnrA : scratch;
429             fjptrB             = (jnrlistB>=0) ? dvda+jnrB : scratch;
430             fjptrC             = (jnrlistC>=0) ? dvda+jnrC : scratch;
431             fjptrD             = (jnrlistD>=0) ? dvda+jnrD : scratch;
432             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
433             velec            = _mm_mul_ps(qq00,rinv00);
434             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
435
436             /* CUBIC SPLINE TABLE DISPERSION */
437             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
438             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
439             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
440             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
441             _MM_TRANSPOSE4_PS(Y,F,G,H);
442             Heps             = _mm_mul_ps(vfeps,H);
443             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
444             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
445             vvdw6            = _mm_mul_ps(c6_00,VV);
446             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
447             fvdw6            = _mm_mul_ps(c6_00,FF);
448
449             /* CUBIC SPLINE TABLE REPULSION */
450             vfitab           = _mm_add_epi32(vfitab,ifour);
451             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
452             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
453             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
454             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
455             _MM_TRANSPOSE4_PS(Y,F,G,H);
456             Heps             = _mm_mul_ps(vfeps,H);
457             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
458             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
459             vvdw12           = _mm_mul_ps(c12_00,VV);
460             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
461             fvdw12           = _mm_mul_ps(c12_00,FF);
462             vvdw             = _mm_add_ps(vvdw12,vvdw6);
463             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
464
465             /* Update potential sum for this i atom from the interaction with this j atom. */
466             velec            = _mm_andnot_ps(dummy_mask,velec);
467             velecsum         = _mm_add_ps(velecsum,velec);
468             vgb              = _mm_andnot_ps(dummy_mask,vgb);
469             vgbsum           = _mm_add_ps(vgbsum,vgb);
470             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
471             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
472
473             fscal            = _mm_add_ps(felec,fvdw);
474
475             fscal            = _mm_andnot_ps(dummy_mask,fscal);
476
477             /* Calculate temporary vectorial force */
478             tx               = _mm_mul_ps(fscal,dx00);
479             ty               = _mm_mul_ps(fscal,dy00);
480             tz               = _mm_mul_ps(fscal,dz00);
481
482             /* Update vectorial force */
483             fix0             = _mm_add_ps(fix0,tx);
484             fiy0             = _mm_add_ps(fiy0,ty);
485             fiz0             = _mm_add_ps(fiz0,tz);
486
487             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
488             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
489             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
490             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
491             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
492             
493             /* Inner loop uses 93 flops */
494         }
495
496         /* End of innermost loop */
497
498         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
499                                               f+i_coord_offset,fshift+i_shift_offset);
500
501         ggid                        = gid[iidx];
502         /* Update potential energies */
503         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
504         gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
505         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
506         dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
507         gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
508
509         /* Increment number of inner iterations */
510         inneriter                  += j_index_end - j_index_start;
511
512         /* Outer loop uses 10 flops */
513     }
514
515     /* Increment number of outer iterations */
516     outeriter        += nri;
517
518     /* Update outer/inner flops */
519
520     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*93);
521 }
522 /*
523  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_sse2_single
524  * Electrostatics interaction: GeneralizedBorn
525  * VdW interaction:            CubicSplineTable
526  * Geometry:                   Particle-Particle
527  * Calculate force/pot:        Force
528  */
529 void
530 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_sse2_single
531                     (t_nblist * gmx_restrict                nlist,
532                      rvec * gmx_restrict                    xx,
533                      rvec * gmx_restrict                    ff,
534                      t_forcerec * gmx_restrict              fr,
535                      t_mdatoms * gmx_restrict               mdatoms,
536                      nb_kernel_data_t * gmx_restrict        kernel_data,
537                      t_nrnb * gmx_restrict                  nrnb)
538 {
539     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
540      * just 0 for non-waters.
541      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
542      * jnr indices corresponding to data put in the four positions in the SIMD register.
543      */
544     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
545     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
546     int              jnrA,jnrB,jnrC,jnrD;
547     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
548     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
549     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
550     real             rcutoff_scalar;
551     real             *shiftvec,*fshift,*x,*f;
552     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
553     real             scratch[4*DIM];
554     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
555     int              vdwioffset0;
556     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
557     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
558     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
559     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
560     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
561     real             *charge;
562     __m128i          gbitab;
563     __m128           vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,dvdatmp;
564     __m128           minushalf = _mm_set1_ps(-0.5);
565     real             *invsqrta,*dvda,*gbtab;
566     int              nvdwtype;
567     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
568     int              *vdwtype;
569     real             *vdwparam;
570     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
571     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
572     __m128i          vfitab;
573     __m128i          ifour       = _mm_set1_epi32(4);
574     __m128           rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
575     real             *vftab;
576     __m128           dummy_mask,cutoff_mask;
577     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
578     __m128           one     = _mm_set1_ps(1.0);
579     __m128           two     = _mm_set1_ps(2.0);
580     x                = xx[0];
581     f                = ff[0];
582
583     nri              = nlist->nri;
584     iinr             = nlist->iinr;
585     jindex           = nlist->jindex;
586     jjnr             = nlist->jjnr;
587     shiftidx         = nlist->shift;
588     gid              = nlist->gid;
589     shiftvec         = fr->shift_vec[0];
590     fshift           = fr->fshift[0];
591     facel            = _mm_set1_ps(fr->epsfac);
592     charge           = mdatoms->chargeA;
593     nvdwtype         = fr->ntype;
594     vdwparam         = fr->nbfp;
595     vdwtype          = mdatoms->typeA;
596
597     vftab            = kernel_data->table_vdw->data;
598     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
599
600     invsqrta         = fr->invsqrta;
601     dvda             = fr->dvda;
602     gbtabscale       = _mm_set1_ps(fr->gbtab.scale);
603     gbtab            = fr->gbtab.data;
604     gbinvepsdiff     = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
605
606     /* Avoid stupid compiler warnings */
607     jnrA = jnrB = jnrC = jnrD = 0;
608     j_coord_offsetA = 0;
609     j_coord_offsetB = 0;
610     j_coord_offsetC = 0;
611     j_coord_offsetD = 0;
612
613     outeriter        = 0;
614     inneriter        = 0;
615
616     for(iidx=0;iidx<4*DIM;iidx++)
617     {
618         scratch[iidx] = 0.0;
619     }  
620
621     /* Start outer loop over neighborlists */
622     for(iidx=0; iidx<nri; iidx++)
623     {
624         /* Load shift vector for this list */
625         i_shift_offset   = DIM*shiftidx[iidx];
626
627         /* Load limits for loop over neighbors */
628         j_index_start    = jindex[iidx];
629         j_index_end      = jindex[iidx+1];
630
631         /* Get outer coordinate index */
632         inr              = iinr[iidx];
633         i_coord_offset   = DIM*inr;
634
635         /* Load i particle coords and add shift vector */
636         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
637         
638         fix0             = _mm_setzero_ps();
639         fiy0             = _mm_setzero_ps();
640         fiz0             = _mm_setzero_ps();
641
642         /* Load parameters for i particles */
643         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
644         isai0            = _mm_load1_ps(invsqrta+inr+0);
645         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
646
647         dvdasum          = _mm_setzero_ps();
648
649         /* Start inner kernel loop */
650         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
651         {
652
653             /* Get j neighbor index, and coordinate index */
654             jnrA             = jjnr[jidx];
655             jnrB             = jjnr[jidx+1];
656             jnrC             = jjnr[jidx+2];
657             jnrD             = jjnr[jidx+3];
658             j_coord_offsetA  = DIM*jnrA;
659             j_coord_offsetB  = DIM*jnrB;
660             j_coord_offsetC  = DIM*jnrC;
661             j_coord_offsetD  = DIM*jnrD;
662
663             /* load j atom coordinates */
664             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
665                                               x+j_coord_offsetC,x+j_coord_offsetD,
666                                               &jx0,&jy0,&jz0);
667
668             /* Calculate displacement vector */
669             dx00             = _mm_sub_ps(ix0,jx0);
670             dy00             = _mm_sub_ps(iy0,jy0);
671             dz00             = _mm_sub_ps(iz0,jz0);
672
673             /* Calculate squared distance and things based on it */
674             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
675
676             rinv00           = gmx_mm_invsqrt_ps(rsq00);
677
678             /* Load parameters for j particles */
679             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
680                                                               charge+jnrC+0,charge+jnrD+0);
681             isaj0            = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
682                                                               invsqrta+jnrC+0,invsqrta+jnrD+0);
683             vdwjidx0A        = 2*vdwtype[jnrA+0];
684             vdwjidx0B        = 2*vdwtype[jnrB+0];
685             vdwjidx0C        = 2*vdwtype[jnrC+0];
686             vdwjidx0D        = 2*vdwtype[jnrD+0];
687
688             /**************************
689              * CALCULATE INTERACTIONS *
690              **************************/
691
692             r00              = _mm_mul_ps(rsq00,rinv00);
693
694             /* Compute parameters for interactions between i and j atoms */
695             qq00             = _mm_mul_ps(iq0,jq0);
696             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
697                                          vdwparam+vdwioffset0+vdwjidx0B,
698                                          vdwparam+vdwioffset0+vdwjidx0C,
699                                          vdwparam+vdwioffset0+vdwjidx0D,
700                                          &c6_00,&c12_00);
701
702             /* Calculate table index by multiplying r with table scale and truncate to integer */
703             rt               = _mm_mul_ps(r00,vftabscale);
704             vfitab           = _mm_cvttps_epi32(rt);
705             vfeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
706             vfitab           = _mm_slli_epi32(vfitab,3);
707
708             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
709             isaprod          = _mm_mul_ps(isai0,isaj0);
710             gbqqfactor       = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
711             gbscale          = _mm_mul_ps(isaprod,gbtabscale);
712
713             /* Calculate generalized born table index - this is a separate table from the normal one,
714              * but we use the same procedure by multiplying r with scale and truncating to integer.
715              */
716             rt               = _mm_mul_ps(r00,gbscale);
717             gbitab           = _mm_cvttps_epi32(rt);
718             gbeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
719             gbitab           = _mm_slli_epi32(gbitab,2);
720
721             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
722             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
723             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
724             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
725             _MM_TRANSPOSE4_PS(Y,F,G,H);
726             Heps             = _mm_mul_ps(gbeps,H);
727             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
728             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
729             vgb              = _mm_mul_ps(gbqqfactor,VV);
730
731             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
732             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
733             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
734             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
735             fjptrA           = dvda+jnrA;
736             fjptrB           = dvda+jnrB;
737             fjptrC           = dvda+jnrC;
738             fjptrD           = dvda+jnrD;
739             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
740             velec            = _mm_mul_ps(qq00,rinv00);
741             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
742
743             /* CUBIC SPLINE TABLE DISPERSION */
744             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
745             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
746             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
747             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
748             _MM_TRANSPOSE4_PS(Y,F,G,H);
749             Heps             = _mm_mul_ps(vfeps,H);
750             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
751             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
752             fvdw6            = _mm_mul_ps(c6_00,FF);
753
754             /* CUBIC SPLINE TABLE REPULSION */
755             vfitab           = _mm_add_epi32(vfitab,ifour);
756             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
757             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
758             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
759             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
760             _MM_TRANSPOSE4_PS(Y,F,G,H);
761             Heps             = _mm_mul_ps(vfeps,H);
762             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
763             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
764             fvdw12           = _mm_mul_ps(c12_00,FF);
765             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
766
767             fscal            = _mm_add_ps(felec,fvdw);
768
769             /* Calculate temporary vectorial force */
770             tx               = _mm_mul_ps(fscal,dx00);
771             ty               = _mm_mul_ps(fscal,dy00);
772             tz               = _mm_mul_ps(fscal,dz00);
773
774             /* Update vectorial force */
775             fix0             = _mm_add_ps(fix0,tx);
776             fiy0             = _mm_add_ps(fiy0,ty);
777             fiz0             = _mm_add_ps(fiz0,tz);
778
779             fjptrA             = f+j_coord_offsetA;
780             fjptrB             = f+j_coord_offsetB;
781             fjptrC             = f+j_coord_offsetC;
782             fjptrD             = f+j_coord_offsetD;
783             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
784             
785             /* Inner loop uses 82 flops */
786         }
787
788         if(jidx<j_index_end)
789         {
790
791             /* Get j neighbor index, and coordinate index */
792             jnrlistA         = jjnr[jidx];
793             jnrlistB         = jjnr[jidx+1];
794             jnrlistC         = jjnr[jidx+2];
795             jnrlistD         = jjnr[jidx+3];
796             /* Sign of each element will be negative for non-real atoms.
797              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
798              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
799              */
800             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
801             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
802             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
803             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
804             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
805             j_coord_offsetA  = DIM*jnrA;
806             j_coord_offsetB  = DIM*jnrB;
807             j_coord_offsetC  = DIM*jnrC;
808             j_coord_offsetD  = DIM*jnrD;
809
810             /* load j atom coordinates */
811             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
812                                               x+j_coord_offsetC,x+j_coord_offsetD,
813                                               &jx0,&jy0,&jz0);
814
815             /* Calculate displacement vector */
816             dx00             = _mm_sub_ps(ix0,jx0);
817             dy00             = _mm_sub_ps(iy0,jy0);
818             dz00             = _mm_sub_ps(iz0,jz0);
819
820             /* Calculate squared distance and things based on it */
821             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
822
823             rinv00           = gmx_mm_invsqrt_ps(rsq00);
824
825             /* Load parameters for j particles */
826             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
827                                                               charge+jnrC+0,charge+jnrD+0);
828             isaj0            = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
829                                                               invsqrta+jnrC+0,invsqrta+jnrD+0);
830             vdwjidx0A        = 2*vdwtype[jnrA+0];
831             vdwjidx0B        = 2*vdwtype[jnrB+0];
832             vdwjidx0C        = 2*vdwtype[jnrC+0];
833             vdwjidx0D        = 2*vdwtype[jnrD+0];
834
835             /**************************
836              * CALCULATE INTERACTIONS *
837              **************************/
838
839             r00              = _mm_mul_ps(rsq00,rinv00);
840             r00              = _mm_andnot_ps(dummy_mask,r00);
841
842             /* Compute parameters for interactions between i and j atoms */
843             qq00             = _mm_mul_ps(iq0,jq0);
844             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
845                                          vdwparam+vdwioffset0+vdwjidx0B,
846                                          vdwparam+vdwioffset0+vdwjidx0C,
847                                          vdwparam+vdwioffset0+vdwjidx0D,
848                                          &c6_00,&c12_00);
849
850             /* Calculate table index by multiplying r with table scale and truncate to integer */
851             rt               = _mm_mul_ps(r00,vftabscale);
852             vfitab           = _mm_cvttps_epi32(rt);
853             vfeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
854             vfitab           = _mm_slli_epi32(vfitab,3);
855
856             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
857             isaprod          = _mm_mul_ps(isai0,isaj0);
858             gbqqfactor       = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
859             gbscale          = _mm_mul_ps(isaprod,gbtabscale);
860
861             /* Calculate generalized born table index - this is a separate table from the normal one,
862              * but we use the same procedure by multiplying r with scale and truncating to integer.
863              */
864             rt               = _mm_mul_ps(r00,gbscale);
865             gbitab           = _mm_cvttps_epi32(rt);
866             gbeps            = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
867             gbitab           = _mm_slli_epi32(gbitab,2);
868
869             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
870             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
871             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
872             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
873             _MM_TRANSPOSE4_PS(Y,F,G,H);
874             Heps             = _mm_mul_ps(gbeps,H);
875             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
876             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
877             vgb              = _mm_mul_ps(gbqqfactor,VV);
878
879             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
880             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
881             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
882             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
883             /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
884             fjptrA             = (jnrlistA>=0) ? dvda+jnrA : scratch;
885             fjptrB             = (jnrlistB>=0) ? dvda+jnrB : scratch;
886             fjptrC             = (jnrlistC>=0) ? dvda+jnrC : scratch;
887             fjptrD             = (jnrlistD>=0) ? dvda+jnrD : scratch;
888             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
889             velec            = _mm_mul_ps(qq00,rinv00);
890             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
891
892             /* CUBIC SPLINE TABLE DISPERSION */
893             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
894             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
895             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
896             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
897             _MM_TRANSPOSE4_PS(Y,F,G,H);
898             Heps             = _mm_mul_ps(vfeps,H);
899             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
900             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
901             fvdw6            = _mm_mul_ps(c6_00,FF);
902
903             /* CUBIC SPLINE TABLE REPULSION */
904             vfitab           = _mm_add_epi32(vfitab,ifour);
905             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
906             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
907             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
908             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
909             _MM_TRANSPOSE4_PS(Y,F,G,H);
910             Heps             = _mm_mul_ps(vfeps,H);
911             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
912             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
913             fvdw12           = _mm_mul_ps(c12_00,FF);
914             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
915
916             fscal            = _mm_add_ps(felec,fvdw);
917
918             fscal            = _mm_andnot_ps(dummy_mask,fscal);
919
920             /* Calculate temporary vectorial force */
921             tx               = _mm_mul_ps(fscal,dx00);
922             ty               = _mm_mul_ps(fscal,dy00);
923             tz               = _mm_mul_ps(fscal,dz00);
924
925             /* Update vectorial force */
926             fix0             = _mm_add_ps(fix0,tx);
927             fiy0             = _mm_add_ps(fiy0,ty);
928             fiz0             = _mm_add_ps(fiz0,tz);
929
930             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
931             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
932             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
933             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
934             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
935             
936             /* Inner loop uses 83 flops */
937         }
938
939         /* End of innermost loop */
940
941         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
942                                               f+i_coord_offset,fshift+i_shift_offset);
943
944         dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
945         gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
946
947         /* Increment number of inner iterations */
948         inneriter                  += j_index_end - j_index_start;
949
950         /* Outer loop uses 7 flops */
951     }
952
953     /* Increment number of outer iterations */
954     outeriter        += nri;
955
956     /* Update outer/inner flops */
957
958     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*83);
959 }