Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_sse4_1_single / nb_kernel_ElecGB_VdwCSTab_GeomP1P1_sse4_1_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 sse4_1_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_sse4_1_single.h"
50 #include "kernelutil_x86_sse4_1_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_sse4_1_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_sse4_1_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_round_ps(rt, _MM_FROUND_FLOOR));
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_round_ps(rt, _MM_FROUND_FLOOR));
253             gbitab           = _mm_slli_epi32(gbitab,2);
254             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
255             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
256             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
257             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
258             _MM_TRANSPOSE4_PS(Y,F,G,H);
259             Heps             = _mm_mul_ps(gbeps,H);
260             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
261             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
262             vgb              = _mm_mul_ps(gbqqfactor,VV);
263
264             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
265             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
266             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
267             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
268             fjptrA           = dvda+jnrA;
269             fjptrB           = dvda+jnrB;
270             fjptrC           = dvda+jnrC;
271             fjptrD           = dvda+jnrD;
272             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
273             velec            = _mm_mul_ps(qq00,rinv00);
274             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
275
276             /* CUBIC SPLINE TABLE DISPERSION */
277             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
278             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
279             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
280             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
281             _MM_TRANSPOSE4_PS(Y,F,G,H);
282             Heps             = _mm_mul_ps(vfeps,H);
283             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
284             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
285             vvdw6            = _mm_mul_ps(c6_00,VV);
286             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
287             fvdw6            = _mm_mul_ps(c6_00,FF);
288
289             /* CUBIC SPLINE TABLE REPULSION */
290             vfitab           = _mm_add_epi32(vfitab,ifour);
291             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
292             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
293             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
294             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
295             _MM_TRANSPOSE4_PS(Y,F,G,H);
296             Heps             = _mm_mul_ps(vfeps,H);
297             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
298             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
299             vvdw12           = _mm_mul_ps(c12_00,VV);
300             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
301             fvdw12           = _mm_mul_ps(c12_00,FF);
302             vvdw             = _mm_add_ps(vvdw12,vvdw6);
303             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
304
305             /* Update potential sum for this i atom from the interaction with this j atom. */
306             velecsum         = _mm_add_ps(velecsum,velec);
307             vgbsum           = _mm_add_ps(vgbsum,vgb);
308             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
309
310             fscal            = _mm_add_ps(felec,fvdw);
311
312             /* Calculate temporary vectorial force */
313             tx               = _mm_mul_ps(fscal,dx00);
314             ty               = _mm_mul_ps(fscal,dy00);
315             tz               = _mm_mul_ps(fscal,dz00);
316
317             /* Update vectorial force */
318             fix0             = _mm_add_ps(fix0,tx);
319             fiy0             = _mm_add_ps(fiy0,ty);
320             fiz0             = _mm_add_ps(fiz0,tz);
321
322             fjptrA             = f+j_coord_offsetA;
323             fjptrB             = f+j_coord_offsetB;
324             fjptrC             = f+j_coord_offsetC;
325             fjptrD             = f+j_coord_offsetD;
326             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
327
328             /* Inner loop uses 92 flops */
329         }
330
331         if(jidx<j_index_end)
332         {
333
334             /* Get j neighbor index, and coordinate index */
335             jnrlistA         = jjnr[jidx];
336             jnrlistB         = jjnr[jidx+1];
337             jnrlistC         = jjnr[jidx+2];
338             jnrlistD         = jjnr[jidx+3];
339             /* Sign of each element will be negative for non-real atoms.
340              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
341              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
342              */
343             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
344             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
345             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
346             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
347             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
348             j_coord_offsetA  = DIM*jnrA;
349             j_coord_offsetB  = DIM*jnrB;
350             j_coord_offsetC  = DIM*jnrC;
351             j_coord_offsetD  = DIM*jnrD;
352
353             /* load j atom coordinates */
354             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
355                                               x+j_coord_offsetC,x+j_coord_offsetD,
356                                               &jx0,&jy0,&jz0);
357
358             /* Calculate displacement vector */
359             dx00             = _mm_sub_ps(ix0,jx0);
360             dy00             = _mm_sub_ps(iy0,jy0);
361             dz00             = _mm_sub_ps(iz0,jz0);
362
363             /* Calculate squared distance and things based on it */
364             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
365
366             rinv00           = gmx_mm_invsqrt_ps(rsq00);
367
368             /* Load parameters for j particles */
369             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
370                                                               charge+jnrC+0,charge+jnrD+0);
371             isaj0            = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
372                                                               invsqrta+jnrC+0,invsqrta+jnrD+0);
373             vdwjidx0A        = 2*vdwtype[jnrA+0];
374             vdwjidx0B        = 2*vdwtype[jnrB+0];
375             vdwjidx0C        = 2*vdwtype[jnrC+0];
376             vdwjidx0D        = 2*vdwtype[jnrD+0];
377
378             /**************************
379              * CALCULATE INTERACTIONS *
380              **************************/
381
382             r00              = _mm_mul_ps(rsq00,rinv00);
383             r00              = _mm_andnot_ps(dummy_mask,r00);
384
385             /* Compute parameters for interactions between i and j atoms */
386             qq00             = _mm_mul_ps(iq0,jq0);
387             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
388                                          vdwparam+vdwioffset0+vdwjidx0B,
389                                          vdwparam+vdwioffset0+vdwjidx0C,
390                                          vdwparam+vdwioffset0+vdwjidx0D,
391                                          &c6_00,&c12_00);
392
393             /* Calculate table index by multiplying r with table scale and truncate to integer */
394             rt               = _mm_mul_ps(r00,vftabscale);
395             vfitab           = _mm_cvttps_epi32(rt);
396             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
397             vfitab           = _mm_slli_epi32(vfitab,3);
398
399             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
400             isaprod          = _mm_mul_ps(isai0,isaj0);
401             gbqqfactor       = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
402             gbscale          = _mm_mul_ps(isaprod,gbtabscale);
403
404             /* Calculate generalized born table index - this is a separate table from the normal one,
405              * but we use the same procedure by multiplying r with scale and truncating to integer.
406              */
407             rt               = _mm_mul_ps(r00,gbscale);
408             gbitab           = _mm_cvttps_epi32(rt);
409             gbeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
410             gbitab           = _mm_slli_epi32(gbitab,2);
411             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
412             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
413             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
414             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
415             _MM_TRANSPOSE4_PS(Y,F,G,H);
416             Heps             = _mm_mul_ps(gbeps,H);
417             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
418             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
419             vgb              = _mm_mul_ps(gbqqfactor,VV);
420
421             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
422             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
423             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
424             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
425             /* 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. */
426             fjptrA             = (jnrlistA>=0) ? dvda+jnrA : scratch;
427             fjptrB             = (jnrlistB>=0) ? dvda+jnrB : scratch;
428             fjptrC             = (jnrlistC>=0) ? dvda+jnrC : scratch;
429             fjptrD             = (jnrlistD>=0) ? dvda+jnrD : scratch;
430             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
431             velec            = _mm_mul_ps(qq00,rinv00);
432             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
433
434             /* CUBIC SPLINE TABLE DISPERSION */
435             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
436             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
437             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
438             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
439             _MM_TRANSPOSE4_PS(Y,F,G,H);
440             Heps             = _mm_mul_ps(vfeps,H);
441             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
442             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
443             vvdw6            = _mm_mul_ps(c6_00,VV);
444             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
445             fvdw6            = _mm_mul_ps(c6_00,FF);
446
447             /* CUBIC SPLINE TABLE REPULSION */
448             vfitab           = _mm_add_epi32(vfitab,ifour);
449             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
450             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
451             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
452             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
453             _MM_TRANSPOSE4_PS(Y,F,G,H);
454             Heps             = _mm_mul_ps(vfeps,H);
455             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
456             VV               = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
457             vvdw12           = _mm_mul_ps(c12_00,VV);
458             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
459             fvdw12           = _mm_mul_ps(c12_00,FF);
460             vvdw             = _mm_add_ps(vvdw12,vvdw6);
461             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
462
463             /* Update potential sum for this i atom from the interaction with this j atom. */
464             velec            = _mm_andnot_ps(dummy_mask,velec);
465             velecsum         = _mm_add_ps(velecsum,velec);
466             vgb              = _mm_andnot_ps(dummy_mask,vgb);
467             vgbsum           = _mm_add_ps(vgbsum,vgb);
468             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
469             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
470
471             fscal            = _mm_add_ps(felec,fvdw);
472
473             fscal            = _mm_andnot_ps(dummy_mask,fscal);
474
475             /* Calculate temporary vectorial force */
476             tx               = _mm_mul_ps(fscal,dx00);
477             ty               = _mm_mul_ps(fscal,dy00);
478             tz               = _mm_mul_ps(fscal,dz00);
479
480             /* Update vectorial force */
481             fix0             = _mm_add_ps(fix0,tx);
482             fiy0             = _mm_add_ps(fiy0,ty);
483             fiz0             = _mm_add_ps(fiz0,tz);
484
485             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
486             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
487             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
488             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
489             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
490
491             /* Inner loop uses 93 flops */
492         }
493
494         /* End of innermost loop */
495
496         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
497                                               f+i_coord_offset,fshift+i_shift_offset);
498
499         ggid                        = gid[iidx];
500         /* Update potential energies */
501         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
502         gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
503         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
504         dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
505         gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
506
507         /* Increment number of inner iterations */
508         inneriter                  += j_index_end - j_index_start;
509
510         /* Outer loop uses 10 flops */
511     }
512
513     /* Increment number of outer iterations */
514     outeriter        += nri;
515
516     /* Update outer/inner flops */
517
518     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*93);
519 }
520 /*
521  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_sse4_1_single
522  * Electrostatics interaction: GeneralizedBorn
523  * VdW interaction:            CubicSplineTable
524  * Geometry:                   Particle-Particle
525  * Calculate force/pot:        Force
526  */
527 void
528 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_sse4_1_single
529                     (t_nblist * gmx_restrict                nlist,
530                      rvec * gmx_restrict                    xx,
531                      rvec * gmx_restrict                    ff,
532                      t_forcerec * gmx_restrict              fr,
533                      t_mdatoms * gmx_restrict               mdatoms,
534                      nb_kernel_data_t * gmx_restrict        kernel_data,
535                      t_nrnb * gmx_restrict                  nrnb)
536 {
537     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
538      * just 0 for non-waters.
539      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
540      * jnr indices corresponding to data put in the four positions in the SIMD register.
541      */
542     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
543     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
544     int              jnrA,jnrB,jnrC,jnrD;
545     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
546     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
547     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
548     real             rcutoff_scalar;
549     real             *shiftvec,*fshift,*x,*f;
550     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
551     real             scratch[4*DIM];
552     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
553     int              vdwioffset0;
554     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
555     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
556     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
557     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
558     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
559     real             *charge;
560     __m128i          gbitab;
561     __m128           vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,dvdatmp;
562     __m128           minushalf = _mm_set1_ps(-0.5);
563     real             *invsqrta,*dvda,*gbtab;
564     int              nvdwtype;
565     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
566     int              *vdwtype;
567     real             *vdwparam;
568     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
569     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
570     __m128i          vfitab;
571     __m128i          ifour       = _mm_set1_epi32(4);
572     __m128           rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
573     real             *vftab;
574     __m128           dummy_mask,cutoff_mask;
575     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
576     __m128           one     = _mm_set1_ps(1.0);
577     __m128           two     = _mm_set1_ps(2.0);
578     x                = xx[0];
579     f                = ff[0];
580
581     nri              = nlist->nri;
582     iinr             = nlist->iinr;
583     jindex           = nlist->jindex;
584     jjnr             = nlist->jjnr;
585     shiftidx         = nlist->shift;
586     gid              = nlist->gid;
587     shiftvec         = fr->shift_vec[0];
588     fshift           = fr->fshift[0];
589     facel            = _mm_set1_ps(fr->epsfac);
590     charge           = mdatoms->chargeA;
591     nvdwtype         = fr->ntype;
592     vdwparam         = fr->nbfp;
593     vdwtype          = mdatoms->typeA;
594
595     vftab            = kernel_data->table_vdw->data;
596     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
597
598     invsqrta         = fr->invsqrta;
599     dvda             = fr->dvda;
600     gbtabscale       = _mm_set1_ps(fr->gbtab.scale);
601     gbtab            = fr->gbtab.data;
602     gbinvepsdiff     = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
603
604     /* Avoid stupid compiler warnings */
605     jnrA = jnrB = jnrC = jnrD = 0;
606     j_coord_offsetA = 0;
607     j_coord_offsetB = 0;
608     j_coord_offsetC = 0;
609     j_coord_offsetD = 0;
610
611     outeriter        = 0;
612     inneriter        = 0;
613
614     for(iidx=0;iidx<4*DIM;iidx++)
615     {
616         scratch[iidx] = 0.0;
617     }
618
619     /* Start outer loop over neighborlists */
620     for(iidx=0; iidx<nri; iidx++)
621     {
622         /* Load shift vector for this list */
623         i_shift_offset   = DIM*shiftidx[iidx];
624
625         /* Load limits for loop over neighbors */
626         j_index_start    = jindex[iidx];
627         j_index_end      = jindex[iidx+1];
628
629         /* Get outer coordinate index */
630         inr              = iinr[iidx];
631         i_coord_offset   = DIM*inr;
632
633         /* Load i particle coords and add shift vector */
634         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
635
636         fix0             = _mm_setzero_ps();
637         fiy0             = _mm_setzero_ps();
638         fiz0             = _mm_setzero_ps();
639
640         /* Load parameters for i particles */
641         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
642         isai0            = _mm_load1_ps(invsqrta+inr+0);
643         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
644
645         dvdasum          = _mm_setzero_ps();
646
647         /* Start inner kernel loop */
648         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
649         {
650
651             /* Get j neighbor index, and coordinate index */
652             jnrA             = jjnr[jidx];
653             jnrB             = jjnr[jidx+1];
654             jnrC             = jjnr[jidx+2];
655             jnrD             = jjnr[jidx+3];
656             j_coord_offsetA  = DIM*jnrA;
657             j_coord_offsetB  = DIM*jnrB;
658             j_coord_offsetC  = DIM*jnrC;
659             j_coord_offsetD  = DIM*jnrD;
660
661             /* load j atom coordinates */
662             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
663                                               x+j_coord_offsetC,x+j_coord_offsetD,
664                                               &jx0,&jy0,&jz0);
665
666             /* Calculate displacement vector */
667             dx00             = _mm_sub_ps(ix0,jx0);
668             dy00             = _mm_sub_ps(iy0,jy0);
669             dz00             = _mm_sub_ps(iz0,jz0);
670
671             /* Calculate squared distance and things based on it */
672             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
673
674             rinv00           = gmx_mm_invsqrt_ps(rsq00);
675
676             /* Load parameters for j particles */
677             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
678                                                               charge+jnrC+0,charge+jnrD+0);
679             isaj0            = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
680                                                               invsqrta+jnrC+0,invsqrta+jnrD+0);
681             vdwjidx0A        = 2*vdwtype[jnrA+0];
682             vdwjidx0B        = 2*vdwtype[jnrB+0];
683             vdwjidx0C        = 2*vdwtype[jnrC+0];
684             vdwjidx0D        = 2*vdwtype[jnrD+0];
685
686             /**************************
687              * CALCULATE INTERACTIONS *
688              **************************/
689
690             r00              = _mm_mul_ps(rsq00,rinv00);
691
692             /* Compute parameters for interactions between i and j atoms */
693             qq00             = _mm_mul_ps(iq0,jq0);
694             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
695                                          vdwparam+vdwioffset0+vdwjidx0B,
696                                          vdwparam+vdwioffset0+vdwjidx0C,
697                                          vdwparam+vdwioffset0+vdwjidx0D,
698                                          &c6_00,&c12_00);
699
700             /* Calculate table index by multiplying r with table scale and truncate to integer */
701             rt               = _mm_mul_ps(r00,vftabscale);
702             vfitab           = _mm_cvttps_epi32(rt);
703             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
704             vfitab           = _mm_slli_epi32(vfitab,3);
705
706             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
707             isaprod          = _mm_mul_ps(isai0,isaj0);
708             gbqqfactor       = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
709             gbscale          = _mm_mul_ps(isaprod,gbtabscale);
710
711             /* Calculate generalized born table index - this is a separate table from the normal one,
712              * but we use the same procedure by multiplying r with scale and truncating to integer.
713              */
714             rt               = _mm_mul_ps(r00,gbscale);
715             gbitab           = _mm_cvttps_epi32(rt);
716             gbeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
717             gbitab           = _mm_slli_epi32(gbitab,2);
718             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
719             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
720             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
721             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
722             _MM_TRANSPOSE4_PS(Y,F,G,H);
723             Heps             = _mm_mul_ps(gbeps,H);
724             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
725             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
726             vgb              = _mm_mul_ps(gbqqfactor,VV);
727
728             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
729             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
730             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
731             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
732             fjptrA           = dvda+jnrA;
733             fjptrB           = dvda+jnrB;
734             fjptrC           = dvda+jnrC;
735             fjptrD           = dvda+jnrD;
736             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
737             velec            = _mm_mul_ps(qq00,rinv00);
738             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
739
740             /* CUBIC SPLINE TABLE DISPERSION */
741             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
742             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
743             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
744             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
745             _MM_TRANSPOSE4_PS(Y,F,G,H);
746             Heps             = _mm_mul_ps(vfeps,H);
747             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
748             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
749             fvdw6            = _mm_mul_ps(c6_00,FF);
750
751             /* CUBIC SPLINE TABLE REPULSION */
752             vfitab           = _mm_add_epi32(vfitab,ifour);
753             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
754             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
755             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
756             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
757             _MM_TRANSPOSE4_PS(Y,F,G,H);
758             Heps             = _mm_mul_ps(vfeps,H);
759             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
760             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
761             fvdw12           = _mm_mul_ps(c12_00,FF);
762             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
763
764             fscal            = _mm_add_ps(felec,fvdw);
765
766             /* Calculate temporary vectorial force */
767             tx               = _mm_mul_ps(fscal,dx00);
768             ty               = _mm_mul_ps(fscal,dy00);
769             tz               = _mm_mul_ps(fscal,dz00);
770
771             /* Update vectorial force */
772             fix0             = _mm_add_ps(fix0,tx);
773             fiy0             = _mm_add_ps(fiy0,ty);
774             fiz0             = _mm_add_ps(fiz0,tz);
775
776             fjptrA             = f+j_coord_offsetA;
777             fjptrB             = f+j_coord_offsetB;
778             fjptrC             = f+j_coord_offsetC;
779             fjptrD             = f+j_coord_offsetD;
780             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
781
782             /* Inner loop uses 82 flops */
783         }
784
785         if(jidx<j_index_end)
786         {
787
788             /* Get j neighbor index, and coordinate index */
789             jnrlistA         = jjnr[jidx];
790             jnrlistB         = jjnr[jidx+1];
791             jnrlistC         = jjnr[jidx+2];
792             jnrlistD         = jjnr[jidx+3];
793             /* Sign of each element will be negative for non-real atoms.
794              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
795              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
796              */
797             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
798             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
799             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
800             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
801             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
802             j_coord_offsetA  = DIM*jnrA;
803             j_coord_offsetB  = DIM*jnrB;
804             j_coord_offsetC  = DIM*jnrC;
805             j_coord_offsetD  = DIM*jnrD;
806
807             /* load j atom coordinates */
808             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
809                                               x+j_coord_offsetC,x+j_coord_offsetD,
810                                               &jx0,&jy0,&jz0);
811
812             /* Calculate displacement vector */
813             dx00             = _mm_sub_ps(ix0,jx0);
814             dy00             = _mm_sub_ps(iy0,jy0);
815             dz00             = _mm_sub_ps(iz0,jz0);
816
817             /* Calculate squared distance and things based on it */
818             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
819
820             rinv00           = gmx_mm_invsqrt_ps(rsq00);
821
822             /* Load parameters for j particles */
823             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
824                                                               charge+jnrC+0,charge+jnrD+0);
825             isaj0            = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
826                                                               invsqrta+jnrC+0,invsqrta+jnrD+0);
827             vdwjidx0A        = 2*vdwtype[jnrA+0];
828             vdwjidx0B        = 2*vdwtype[jnrB+0];
829             vdwjidx0C        = 2*vdwtype[jnrC+0];
830             vdwjidx0D        = 2*vdwtype[jnrD+0];
831
832             /**************************
833              * CALCULATE INTERACTIONS *
834              **************************/
835
836             r00              = _mm_mul_ps(rsq00,rinv00);
837             r00              = _mm_andnot_ps(dummy_mask,r00);
838
839             /* Compute parameters for interactions between i and j atoms */
840             qq00             = _mm_mul_ps(iq0,jq0);
841             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
842                                          vdwparam+vdwioffset0+vdwjidx0B,
843                                          vdwparam+vdwioffset0+vdwjidx0C,
844                                          vdwparam+vdwioffset0+vdwjidx0D,
845                                          &c6_00,&c12_00);
846
847             /* Calculate table index by multiplying r with table scale and truncate to integer */
848             rt               = _mm_mul_ps(r00,vftabscale);
849             vfitab           = _mm_cvttps_epi32(rt);
850             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
851             vfitab           = _mm_slli_epi32(vfitab,3);
852
853             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
854             isaprod          = _mm_mul_ps(isai0,isaj0);
855             gbqqfactor       = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
856             gbscale          = _mm_mul_ps(isaprod,gbtabscale);
857
858             /* Calculate generalized born table index - this is a separate table from the normal one,
859              * but we use the same procedure by multiplying r with scale and truncating to integer.
860              */
861             rt               = _mm_mul_ps(r00,gbscale);
862             gbitab           = _mm_cvttps_epi32(rt);
863             gbeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
864             gbitab           = _mm_slli_epi32(gbitab,2);
865             Y                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
866             F                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
867             G                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
868             H                = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
869             _MM_TRANSPOSE4_PS(Y,F,G,H);
870             Heps             = _mm_mul_ps(gbeps,H);
871             Fp               = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
872             VV               = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
873             vgb              = _mm_mul_ps(gbqqfactor,VV);
874
875             FF               = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
876             fgb              = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
877             dvdatmp          = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
878             dvdasum          = _mm_add_ps(dvdasum,dvdatmp);
879             /* 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. */
880             fjptrA             = (jnrlistA>=0) ? dvda+jnrA : scratch;
881             fjptrB             = (jnrlistB>=0) ? dvda+jnrB : scratch;
882             fjptrC             = (jnrlistC>=0) ? dvda+jnrC : scratch;
883             fjptrD             = (jnrlistD>=0) ? dvda+jnrD : scratch;
884             gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
885             velec            = _mm_mul_ps(qq00,rinv00);
886             felec            = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
887
888             /* CUBIC SPLINE TABLE DISPERSION */
889             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
890             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
891             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
892             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
893             _MM_TRANSPOSE4_PS(Y,F,G,H);
894             Heps             = _mm_mul_ps(vfeps,H);
895             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
896             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
897             fvdw6            = _mm_mul_ps(c6_00,FF);
898
899             /* CUBIC SPLINE TABLE REPULSION */
900             vfitab           = _mm_add_epi32(vfitab,ifour);
901             Y                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
902             F                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
903             G                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
904             H                = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
905             _MM_TRANSPOSE4_PS(Y,F,G,H);
906             Heps             = _mm_mul_ps(vfeps,H);
907             Fp               = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
908             FF               = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
909             fvdw12           = _mm_mul_ps(c12_00,FF);
910             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
911
912             fscal            = _mm_add_ps(felec,fvdw);
913
914             fscal            = _mm_andnot_ps(dummy_mask,fscal);
915
916             /* Calculate temporary vectorial force */
917             tx               = _mm_mul_ps(fscal,dx00);
918             ty               = _mm_mul_ps(fscal,dy00);
919             tz               = _mm_mul_ps(fscal,dz00);
920
921             /* Update vectorial force */
922             fix0             = _mm_add_ps(fix0,tx);
923             fiy0             = _mm_add_ps(fiy0,ty);
924             fiz0             = _mm_add_ps(fiz0,tz);
925
926             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
927             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
928             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
929             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
930             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
931
932             /* Inner loop uses 83 flops */
933         }
934
935         /* End of innermost loop */
936
937         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
938                                               f+i_coord_offset,fshift+i_shift_offset);
939
940         dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
941         gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
942
943         /* Increment number of inner iterations */
944         inneriter                  += j_index_end - j_index_start;
945
946         /* Outer loop uses 7 flops */
947     }
948
949     /* Increment number of outer iterations */
950     outeriter        += nri;
951
952     /* Update outer/inner flops */
953
954     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*83);
955 }