Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_double / nb_kernel_ElecRFCut_VdwCSTab_GeomP1P1_sse2_double.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_double kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_sse2_double.h"
50 #include "kernelutil_x86_sse2_double.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwCSTab_GeomP1P1_VF_sse2_double
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            CubicSplineTable
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwCSTab_GeomP1P1_VF_sse2_double
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_unused * 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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
77     int              j_coord_offsetA,j_coord_offsetB;
78     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
79     real             rcutoff_scalar;
80     real             *shiftvec,*fshift,*x,*f;
81     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82     int              vdwioffset0;
83     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwjidx0A,vdwjidx0B;
85     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
88     real             *charge;
89     int              nvdwtype;
90     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
91     int              *vdwtype;
92     real             *vdwparam;
93     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
94     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
95     __m128i          vfitab;
96     __m128i          ifour       = _mm_set1_epi32(4);
97     __m128d          rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
98     real             *vftab;
99     __m128d          dummy_mask,cutoff_mask;
100     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
101     __m128d          one     = _mm_set1_pd(1.0);
102     __m128d          two     = _mm_set1_pd(2.0);
103     x                = xx[0];
104     f                = ff[0];
105
106     nri              = nlist->nri;
107     iinr             = nlist->iinr;
108     jindex           = nlist->jindex;
109     jjnr             = nlist->jjnr;
110     shiftidx         = nlist->shift;
111     gid              = nlist->gid;
112     shiftvec         = fr->shift_vec[0];
113     fshift           = fr->fshift[0];
114     facel            = _mm_set1_pd(fr->epsfac);
115     charge           = mdatoms->chargeA;
116     krf              = _mm_set1_pd(fr->ic->k_rf);
117     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
118     crf              = _mm_set1_pd(fr->ic->c_rf);
119     nvdwtype         = fr->ntype;
120     vdwparam         = fr->nbfp;
121     vdwtype          = mdatoms->typeA;
122
123     vftab            = kernel_data->table_vdw->data;
124     vftabscale       = _mm_set1_pd(kernel_data->table_vdw->scale);
125
126     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
127     rcutoff_scalar   = fr->rcoulomb;
128     rcutoff          = _mm_set1_pd(rcutoff_scalar);
129     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
130
131     /* Avoid stupid compiler warnings */
132     jnrA = jnrB = 0;
133     j_coord_offsetA = 0;
134     j_coord_offsetB = 0;
135
136     outeriter        = 0;
137     inneriter        = 0;
138
139     /* Start outer loop over neighborlists */
140     for(iidx=0; iidx<nri; iidx++)
141     {
142         /* Load shift vector for this list */
143         i_shift_offset   = DIM*shiftidx[iidx];
144
145         /* Load limits for loop over neighbors */
146         j_index_start    = jindex[iidx];
147         j_index_end      = jindex[iidx+1];
148
149         /* Get outer coordinate index */
150         inr              = iinr[iidx];
151         i_coord_offset   = DIM*inr;
152
153         /* Load i particle coords and add shift vector */
154         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
155
156         fix0             = _mm_setzero_pd();
157         fiy0             = _mm_setzero_pd();
158         fiz0             = _mm_setzero_pd();
159
160         /* Load parameters for i particles */
161         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
162         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
163
164         /* Reset potential sums */
165         velecsum         = _mm_setzero_pd();
166         vvdwsum          = _mm_setzero_pd();
167
168         /* Start inner kernel loop */
169         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
170         {
171
172             /* Get j neighbor index, and coordinate index */
173             jnrA             = jjnr[jidx];
174             jnrB             = jjnr[jidx+1];
175             j_coord_offsetA  = DIM*jnrA;
176             j_coord_offsetB  = DIM*jnrB;
177
178             /* load j atom coordinates */
179             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
180                                               &jx0,&jy0,&jz0);
181
182             /* Calculate displacement vector */
183             dx00             = _mm_sub_pd(ix0,jx0);
184             dy00             = _mm_sub_pd(iy0,jy0);
185             dz00             = _mm_sub_pd(iz0,jz0);
186
187             /* Calculate squared distance and things based on it */
188             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
189
190             rinv00           = gmx_mm_invsqrt_pd(rsq00);
191
192             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
193
194             /* Load parameters for j particles */
195             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
196             vdwjidx0A        = 2*vdwtype[jnrA+0];
197             vdwjidx0B        = 2*vdwtype[jnrB+0];
198
199             /**************************
200              * CALCULATE INTERACTIONS *
201              **************************/
202
203             if (gmx_mm_any_lt(rsq00,rcutoff2))
204             {
205
206             r00              = _mm_mul_pd(rsq00,rinv00);
207
208             /* Compute parameters for interactions between i and j atoms */
209             qq00             = _mm_mul_pd(iq0,jq0);
210             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
211                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
212
213             /* Calculate table index by multiplying r with table scale and truncate to integer */
214             rt               = _mm_mul_pd(r00,vftabscale);
215             vfitab           = _mm_cvttpd_epi32(rt);
216             vfeps            = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
217             vfitab           = _mm_slli_epi32(vfitab,3);
218
219             /* REACTION-FIELD ELECTROSTATICS */
220             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
221             felec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
222
223             /* CUBIC SPLINE TABLE DISPERSION */
224             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
225             F                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
226             GMX_MM_TRANSPOSE2_PD(Y,F);
227             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
228             H                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
229             GMX_MM_TRANSPOSE2_PD(G,H);
230             Heps             = _mm_mul_pd(vfeps,H);
231             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
232             VV               = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
233             vvdw6            = _mm_mul_pd(c6_00,VV);
234             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
235             fvdw6            = _mm_mul_pd(c6_00,FF);
236
237             /* CUBIC SPLINE TABLE REPULSION */
238             vfitab           = _mm_add_epi32(vfitab,ifour);
239             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
240             F                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
241             GMX_MM_TRANSPOSE2_PD(Y,F);
242             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
243             H                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
244             GMX_MM_TRANSPOSE2_PD(G,H);
245             Heps             = _mm_mul_pd(vfeps,H);
246             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
247             VV               = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
248             vvdw12           = _mm_mul_pd(c12_00,VV);
249             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
250             fvdw12           = _mm_mul_pd(c12_00,FF);
251             vvdw             = _mm_add_pd(vvdw12,vvdw6);
252             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
253
254             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
255
256             /* Update potential sum for this i atom from the interaction with this j atom. */
257             velec            = _mm_and_pd(velec,cutoff_mask);
258             velecsum         = _mm_add_pd(velecsum,velec);
259             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
260             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
261
262             fscal            = _mm_add_pd(felec,fvdw);
263
264             fscal            = _mm_and_pd(fscal,cutoff_mask);
265
266             /* Calculate temporary vectorial force */
267             tx               = _mm_mul_pd(fscal,dx00);
268             ty               = _mm_mul_pd(fscal,dy00);
269             tz               = _mm_mul_pd(fscal,dz00);
270
271             /* Update vectorial force */
272             fix0             = _mm_add_pd(fix0,tx);
273             fiy0             = _mm_add_pd(fiy0,ty);
274             fiz0             = _mm_add_pd(fiz0,tz);
275
276             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
277
278             }
279
280             /* Inner loop uses 72 flops */
281         }
282
283         if(jidx<j_index_end)
284         {
285
286             jnrA             = jjnr[jidx];
287             j_coord_offsetA  = DIM*jnrA;
288
289             /* load j atom coordinates */
290             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
291                                               &jx0,&jy0,&jz0);
292
293             /* Calculate displacement vector */
294             dx00             = _mm_sub_pd(ix0,jx0);
295             dy00             = _mm_sub_pd(iy0,jy0);
296             dz00             = _mm_sub_pd(iz0,jz0);
297
298             /* Calculate squared distance and things based on it */
299             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
300
301             rinv00           = gmx_mm_invsqrt_pd(rsq00);
302
303             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
304
305             /* Load parameters for j particles */
306             jq0              = _mm_load_sd(charge+jnrA+0);
307             vdwjidx0A        = 2*vdwtype[jnrA+0];
308
309             /**************************
310              * CALCULATE INTERACTIONS *
311              **************************/
312
313             if (gmx_mm_any_lt(rsq00,rcutoff2))
314             {
315
316             r00              = _mm_mul_pd(rsq00,rinv00);
317
318             /* Compute parameters for interactions between i and j atoms */
319             qq00             = _mm_mul_pd(iq0,jq0);
320             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
321
322             /* Calculate table index by multiplying r with table scale and truncate to integer */
323             rt               = _mm_mul_pd(r00,vftabscale);
324             vfitab           = _mm_cvttpd_epi32(rt);
325             vfeps            = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
326             vfitab           = _mm_slli_epi32(vfitab,3);
327
328             /* REACTION-FIELD ELECTROSTATICS */
329             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
330             felec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
331
332             /* CUBIC SPLINE TABLE DISPERSION */
333             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
334             F                = _mm_setzero_pd();
335             GMX_MM_TRANSPOSE2_PD(Y,F);
336             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
337             H                = _mm_setzero_pd();
338             GMX_MM_TRANSPOSE2_PD(G,H);
339             Heps             = _mm_mul_pd(vfeps,H);
340             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
341             VV               = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
342             vvdw6            = _mm_mul_pd(c6_00,VV);
343             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
344             fvdw6            = _mm_mul_pd(c6_00,FF);
345
346             /* CUBIC SPLINE TABLE REPULSION */
347             vfitab           = _mm_add_epi32(vfitab,ifour);
348             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
349             F                = _mm_setzero_pd();
350             GMX_MM_TRANSPOSE2_PD(Y,F);
351             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
352             H                = _mm_setzero_pd();
353             GMX_MM_TRANSPOSE2_PD(G,H);
354             Heps             = _mm_mul_pd(vfeps,H);
355             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
356             VV               = _mm_add_pd(Y,_mm_mul_pd(vfeps,Fp));
357             vvdw12           = _mm_mul_pd(c12_00,VV);
358             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
359             fvdw12           = _mm_mul_pd(c12_00,FF);
360             vvdw             = _mm_add_pd(vvdw12,vvdw6);
361             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
362
363             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
364
365             /* Update potential sum for this i atom from the interaction with this j atom. */
366             velec            = _mm_and_pd(velec,cutoff_mask);
367             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
368             velecsum         = _mm_add_pd(velecsum,velec);
369             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
370             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
371             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
372
373             fscal            = _mm_add_pd(felec,fvdw);
374
375             fscal            = _mm_and_pd(fscal,cutoff_mask);
376
377             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
378
379             /* Calculate temporary vectorial force */
380             tx               = _mm_mul_pd(fscal,dx00);
381             ty               = _mm_mul_pd(fscal,dy00);
382             tz               = _mm_mul_pd(fscal,dz00);
383
384             /* Update vectorial force */
385             fix0             = _mm_add_pd(fix0,tx);
386             fiy0             = _mm_add_pd(fiy0,ty);
387             fiz0             = _mm_add_pd(fiz0,tz);
388
389             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
390
391             }
392
393             /* Inner loop uses 72 flops */
394         }
395
396         /* End of innermost loop */
397
398         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
399                                               f+i_coord_offset,fshift+i_shift_offset);
400
401         ggid                        = gid[iidx];
402         /* Update potential energies */
403         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
404         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
405
406         /* Increment number of inner iterations */
407         inneriter                  += j_index_end - j_index_start;
408
409         /* Outer loop uses 9 flops */
410     }
411
412     /* Increment number of outer iterations */
413     outeriter        += nri;
414
415     /* Update outer/inner flops */
416
417     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*72);
418 }
419 /*
420  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwCSTab_GeomP1P1_F_sse2_double
421  * Electrostatics interaction: ReactionField
422  * VdW interaction:            CubicSplineTable
423  * Geometry:                   Particle-Particle
424  * Calculate force/pot:        Force
425  */
426 void
427 nb_kernel_ElecRFCut_VdwCSTab_GeomP1P1_F_sse2_double
428                     (t_nblist                    * gmx_restrict       nlist,
429                      rvec                        * gmx_restrict          xx,
430                      rvec                        * gmx_restrict          ff,
431                      t_forcerec                  * gmx_restrict          fr,
432                      t_mdatoms                   * gmx_restrict     mdatoms,
433                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
434                      t_nrnb                      * gmx_restrict        nrnb)
435 {
436     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
437      * just 0 for non-waters.
438      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
439      * jnr indices corresponding to data put in the four positions in the SIMD register.
440      */
441     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
442     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
443     int              jnrA,jnrB;
444     int              j_coord_offsetA,j_coord_offsetB;
445     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
446     real             rcutoff_scalar;
447     real             *shiftvec,*fshift,*x,*f;
448     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
449     int              vdwioffset0;
450     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
451     int              vdwjidx0A,vdwjidx0B;
452     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
453     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
454     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
455     real             *charge;
456     int              nvdwtype;
457     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
458     int              *vdwtype;
459     real             *vdwparam;
460     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
461     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
462     __m128i          vfitab;
463     __m128i          ifour       = _mm_set1_epi32(4);
464     __m128d          rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
465     real             *vftab;
466     __m128d          dummy_mask,cutoff_mask;
467     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
468     __m128d          one     = _mm_set1_pd(1.0);
469     __m128d          two     = _mm_set1_pd(2.0);
470     x                = xx[0];
471     f                = ff[0];
472
473     nri              = nlist->nri;
474     iinr             = nlist->iinr;
475     jindex           = nlist->jindex;
476     jjnr             = nlist->jjnr;
477     shiftidx         = nlist->shift;
478     gid              = nlist->gid;
479     shiftvec         = fr->shift_vec[0];
480     fshift           = fr->fshift[0];
481     facel            = _mm_set1_pd(fr->epsfac);
482     charge           = mdatoms->chargeA;
483     krf              = _mm_set1_pd(fr->ic->k_rf);
484     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
485     crf              = _mm_set1_pd(fr->ic->c_rf);
486     nvdwtype         = fr->ntype;
487     vdwparam         = fr->nbfp;
488     vdwtype          = mdatoms->typeA;
489
490     vftab            = kernel_data->table_vdw->data;
491     vftabscale       = _mm_set1_pd(kernel_data->table_vdw->scale);
492
493     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
494     rcutoff_scalar   = fr->rcoulomb;
495     rcutoff          = _mm_set1_pd(rcutoff_scalar);
496     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
497
498     /* Avoid stupid compiler warnings */
499     jnrA = jnrB = 0;
500     j_coord_offsetA = 0;
501     j_coord_offsetB = 0;
502
503     outeriter        = 0;
504     inneriter        = 0;
505
506     /* Start outer loop over neighborlists */
507     for(iidx=0; iidx<nri; iidx++)
508     {
509         /* Load shift vector for this list */
510         i_shift_offset   = DIM*shiftidx[iidx];
511
512         /* Load limits for loop over neighbors */
513         j_index_start    = jindex[iidx];
514         j_index_end      = jindex[iidx+1];
515
516         /* Get outer coordinate index */
517         inr              = iinr[iidx];
518         i_coord_offset   = DIM*inr;
519
520         /* Load i particle coords and add shift vector */
521         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
522
523         fix0             = _mm_setzero_pd();
524         fiy0             = _mm_setzero_pd();
525         fiz0             = _mm_setzero_pd();
526
527         /* Load parameters for i particles */
528         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
529         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
530
531         /* Start inner kernel loop */
532         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
533         {
534
535             /* Get j neighbor index, and coordinate index */
536             jnrA             = jjnr[jidx];
537             jnrB             = jjnr[jidx+1];
538             j_coord_offsetA  = DIM*jnrA;
539             j_coord_offsetB  = DIM*jnrB;
540
541             /* load j atom coordinates */
542             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
543                                               &jx0,&jy0,&jz0);
544
545             /* Calculate displacement vector */
546             dx00             = _mm_sub_pd(ix0,jx0);
547             dy00             = _mm_sub_pd(iy0,jy0);
548             dz00             = _mm_sub_pd(iz0,jz0);
549
550             /* Calculate squared distance and things based on it */
551             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
552
553             rinv00           = gmx_mm_invsqrt_pd(rsq00);
554
555             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
556
557             /* Load parameters for j particles */
558             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
559             vdwjidx0A        = 2*vdwtype[jnrA+0];
560             vdwjidx0B        = 2*vdwtype[jnrB+0];
561
562             /**************************
563              * CALCULATE INTERACTIONS *
564              **************************/
565
566             if (gmx_mm_any_lt(rsq00,rcutoff2))
567             {
568
569             r00              = _mm_mul_pd(rsq00,rinv00);
570
571             /* Compute parameters for interactions between i and j atoms */
572             qq00             = _mm_mul_pd(iq0,jq0);
573             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
574                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
575
576             /* Calculate table index by multiplying r with table scale and truncate to integer */
577             rt               = _mm_mul_pd(r00,vftabscale);
578             vfitab           = _mm_cvttpd_epi32(rt);
579             vfeps            = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
580             vfitab           = _mm_slli_epi32(vfitab,3);
581
582             /* REACTION-FIELD ELECTROSTATICS */
583             felec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
584
585             /* CUBIC SPLINE TABLE DISPERSION */
586             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
587             F                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
588             GMX_MM_TRANSPOSE2_PD(Y,F);
589             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
590             H                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
591             GMX_MM_TRANSPOSE2_PD(G,H);
592             Heps             = _mm_mul_pd(vfeps,H);
593             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
594             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
595             fvdw6            = _mm_mul_pd(c6_00,FF);
596
597             /* CUBIC SPLINE TABLE REPULSION */
598             vfitab           = _mm_add_epi32(vfitab,ifour);
599             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
600             F                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) );
601             GMX_MM_TRANSPOSE2_PD(Y,F);
602             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
603             H                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,1) +2);
604             GMX_MM_TRANSPOSE2_PD(G,H);
605             Heps             = _mm_mul_pd(vfeps,H);
606             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
607             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
608             fvdw12           = _mm_mul_pd(c12_00,FF);
609             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
610
611             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
612
613             fscal            = _mm_add_pd(felec,fvdw);
614
615             fscal            = _mm_and_pd(fscal,cutoff_mask);
616
617             /* Calculate temporary vectorial force */
618             tx               = _mm_mul_pd(fscal,dx00);
619             ty               = _mm_mul_pd(fscal,dy00);
620             tz               = _mm_mul_pd(fscal,dz00);
621
622             /* Update vectorial force */
623             fix0             = _mm_add_pd(fix0,tx);
624             fiy0             = _mm_add_pd(fiy0,ty);
625             fiz0             = _mm_add_pd(fiz0,tz);
626
627             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
628
629             }
630
631             /* Inner loop uses 57 flops */
632         }
633
634         if(jidx<j_index_end)
635         {
636
637             jnrA             = jjnr[jidx];
638             j_coord_offsetA  = DIM*jnrA;
639
640             /* load j atom coordinates */
641             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
642                                               &jx0,&jy0,&jz0);
643
644             /* Calculate displacement vector */
645             dx00             = _mm_sub_pd(ix0,jx0);
646             dy00             = _mm_sub_pd(iy0,jy0);
647             dz00             = _mm_sub_pd(iz0,jz0);
648
649             /* Calculate squared distance and things based on it */
650             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
651
652             rinv00           = gmx_mm_invsqrt_pd(rsq00);
653
654             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
655
656             /* Load parameters for j particles */
657             jq0              = _mm_load_sd(charge+jnrA+0);
658             vdwjidx0A        = 2*vdwtype[jnrA+0];
659
660             /**************************
661              * CALCULATE INTERACTIONS *
662              **************************/
663
664             if (gmx_mm_any_lt(rsq00,rcutoff2))
665             {
666
667             r00              = _mm_mul_pd(rsq00,rinv00);
668
669             /* Compute parameters for interactions between i and j atoms */
670             qq00             = _mm_mul_pd(iq0,jq0);
671             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
672
673             /* Calculate table index by multiplying r with table scale and truncate to integer */
674             rt               = _mm_mul_pd(r00,vftabscale);
675             vfitab           = _mm_cvttpd_epi32(rt);
676             vfeps            = _mm_sub_pd(rt,_mm_cvtepi32_pd(vfitab));
677             vfitab           = _mm_slli_epi32(vfitab,3);
678
679             /* REACTION-FIELD ELECTROSTATICS */
680             felec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
681
682             /* CUBIC SPLINE TABLE DISPERSION */
683             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
684             F                = _mm_setzero_pd();
685             GMX_MM_TRANSPOSE2_PD(Y,F);
686             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
687             H                = _mm_setzero_pd();
688             GMX_MM_TRANSPOSE2_PD(G,H);
689             Heps             = _mm_mul_pd(vfeps,H);
690             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
691             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
692             fvdw6            = _mm_mul_pd(c6_00,FF);
693
694             /* CUBIC SPLINE TABLE REPULSION */
695             vfitab           = _mm_add_epi32(vfitab,ifour);
696             Y                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) );
697             F                = _mm_setzero_pd();
698             GMX_MM_TRANSPOSE2_PD(Y,F);
699             G                = _mm_load_pd( vftab + gmx_mm_extract_epi32(vfitab,0) +2);
700             H                = _mm_setzero_pd();
701             GMX_MM_TRANSPOSE2_PD(G,H);
702             Heps             = _mm_mul_pd(vfeps,H);
703             Fp               = _mm_add_pd(F,_mm_mul_pd(vfeps,_mm_add_pd(G,Heps)));
704             FF               = _mm_add_pd(Fp,_mm_mul_pd(vfeps,_mm_add_pd(G,_mm_add_pd(Heps,Heps))));
705             fvdw12           = _mm_mul_pd(c12_00,FF);
706             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
707
708             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
709
710             fscal            = _mm_add_pd(felec,fvdw);
711
712             fscal            = _mm_and_pd(fscal,cutoff_mask);
713
714             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
715
716             /* Calculate temporary vectorial force */
717             tx               = _mm_mul_pd(fscal,dx00);
718             ty               = _mm_mul_pd(fscal,dy00);
719             tz               = _mm_mul_pd(fscal,dz00);
720
721             /* Update vectorial force */
722             fix0             = _mm_add_pd(fix0,tx);
723             fiy0             = _mm_add_pd(fiy0,ty);
724             fiz0             = _mm_add_pd(fiz0,tz);
725
726             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
727
728             }
729
730             /* Inner loop uses 57 flops */
731         }
732
733         /* End of innermost loop */
734
735         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
736                                               f+i_coord_offset,fshift+i_shift_offset);
737
738         /* Increment number of inner iterations */
739         inneriter                  += j_index_end - j_index_start;
740
741         /* Outer loop uses 7 flops */
742     }
743
744     /* Increment number of outer iterations */
745     outeriter        += nri;
746
747     /* Update outer/inner flops */
748
749     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*57);
750 }