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