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