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