Remove topology support for implicit solvation
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecGB_VdwCSTab_GeomP1P1_avx_128_fma_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2017, 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 avx_128_fma_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/gmxlib/nrnb.h"
46
47 #include "kernelutil_x86_avx_128_fma_double.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_avx_128_fma_double
51  * Electrostatics interaction: GeneralizedBorn
52  * VdW interaction:            CubicSplineTable
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_avx_128_fma_double
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      struct t_forcerec           * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67      * just 0 for non-waters.
68      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
69      * jnr indices corresponding to data put in the four positions in the SIMD register.
70      */
71     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
72     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73     int              jnrA,jnrB;
74     int              j_coord_offsetA,j_coord_offsetB;
75     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
76     real             rcutoff_scalar;
77     real             *shiftvec,*fshift,*x,*f;
78     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
79     int              vdwioffset0;
80     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81     int              vdwjidx0A,vdwjidx0B;
82     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
83     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
84     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
85     real             *charge;
86     __m128i          gbitab;
87     __m128d          vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
88     __m128d          minushalf = _mm_set1_pd(-0.5);
89     real             *invsqrta,*dvda,*gbtab;
90     int              nvdwtype;
91     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
92     int              *vdwtype;
93     real             *vdwparam;
94     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
95     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
96     __m128i          vfitab;
97     __m128i          ifour       = _mm_set1_epi32(4);
98     __m128d          rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
99     real             *vftab;
100     __m128d          dummy_mask,cutoff_mask;
101     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
102     __m128d          one     = _mm_set1_pd(1.0);
103     __m128d          two     = _mm_set1_pd(2.0);
104     x                = xx[0];
105     f                = ff[0];
106
107     nri              = nlist->nri;
108     iinr             = nlist->iinr;
109     jindex           = nlist->jindex;
110     jjnr             = nlist->jjnr;
111     shiftidx         = nlist->shift;
112     gid              = nlist->gid;
113     shiftvec         = fr->shift_vec[0];
114     fshift           = fr->fshift[0];
115     facel            = _mm_set1_pd(fr->ic->epsfac);
116     charge           = mdatoms->chargeA;
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     invsqrta         = fr->invsqrta;
125     dvda             = fr->dvda;
126     gbtabscale       = _mm_set1_pd(fr->gbtab->scale);
127     gbtab            = fr->gbtab->data;
128     gbinvepsdiff     = _mm_set1_pd((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
129
130     /* Avoid stupid compiler warnings */
131     jnrA = jnrB = 0;
132     j_coord_offsetA = 0;
133     j_coord_offsetB = 0;
134
135     outeriter        = 0;
136     inneriter        = 0;
137
138     /* Start outer loop over neighborlists */
139     for(iidx=0; iidx<nri; iidx++)
140     {
141         /* Load shift vector for this list */
142         i_shift_offset   = DIM*shiftidx[iidx];
143
144         /* Load limits for loop over neighbors */
145         j_index_start    = jindex[iidx];
146         j_index_end      = jindex[iidx+1];
147
148         /* Get outer coordinate index */
149         inr              = iinr[iidx];
150         i_coord_offset   = DIM*inr;
151
152         /* Load i particle coords and add shift vector */
153         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
154
155         fix0             = _mm_setzero_pd();
156         fiy0             = _mm_setzero_pd();
157         fiz0             = _mm_setzero_pd();
158
159         /* Load parameters for i particles */
160         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
161         isai0            = _mm_load1_pd(invsqrta+inr+0);
162         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
163
164         /* Reset potential sums */
165         velecsum         = _mm_setzero_pd();
166         vgbsum           = _mm_setzero_pd();
167         vvdwsum          = _mm_setzero_pd();
168         dvdasum          = _mm_setzero_pd();
169
170         /* Start inner kernel loop */
171         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
172         {
173
174             /* Get j neighbor index, and coordinate index */
175             jnrA             = jjnr[jidx];
176             jnrB             = jjnr[jidx+1];
177             j_coord_offsetA  = DIM*jnrA;
178             j_coord_offsetB  = DIM*jnrB;
179
180             /* load j atom coordinates */
181             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
182                                               &jx0,&jy0,&jz0);
183
184             /* Calculate displacement vector */
185             dx00             = _mm_sub_pd(ix0,jx0);
186             dy00             = _mm_sub_pd(iy0,jy0);
187             dz00             = _mm_sub_pd(iz0,jz0);
188
189             /* Calculate squared distance and things based on it */
190             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
191
192             rinv00           = avx128fma_invsqrt_d(rsq00);
193
194             /* Load parameters for j particles */
195             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
196             isaj0            = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
197             vdwjidx0A        = 2*vdwtype[jnrA+0];
198             vdwjidx0B        = 2*vdwtype[jnrB+0];
199
200             /**************************
201              * CALCULATE INTERACTIONS *
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 #ifdef __XOP__
215             vfeps            = _mm_frcz_pd(rt);
216 #else
217             vfeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
218 #endif
219             twovfeps         = _mm_add_pd(vfeps,vfeps);
220             vfitab           = _mm_slli_epi32(vfitab,3);
221
222             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
223             isaprod          = _mm_mul_pd(isai0,isaj0);
224             gbqqfactor       = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
225             gbscale          = _mm_mul_pd(isaprod,gbtabscale);
226
227             /* Calculate generalized born table index - this is a separate table from the normal one,
228              * but we use the same procedure by multiplying r with scale and truncating to integer.
229              */
230             rt               = _mm_mul_pd(r00,gbscale);
231             gbitab           = _mm_cvttpd_epi32(rt);
232 #ifdef __XOP__
233             gbeps            = _mm_frcz_pd(rt);
234 #else
235             gbeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
236 #endif
237             gbitab           = _mm_slli_epi32(gbitab,2);
238
239             Y                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
240             F                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
241             GMX_MM_TRANSPOSE2_PD(Y,F);
242             G                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
243             H                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
244             GMX_MM_TRANSPOSE2_PD(G,H);
245             Fp               = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
246             VV               = _mm_macc_pd(gbeps,Fp,Y);
247             vgb              = _mm_mul_pd(gbqqfactor,VV);
248
249             twogbeps         = _mm_add_pd(gbeps,gbeps);
250             FF               = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
251             fgb              = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
252             dvdatmp          = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
253             dvdasum          = _mm_add_pd(dvdasum,dvdatmp);
254             gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
255             velec            = _mm_mul_pd(qq00,rinv00);
256             felec            = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
257
258             /* CUBIC SPLINE TABLE DISPERSION */
259             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
260             F                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
261             GMX_MM_TRANSPOSE2_PD(Y,F);
262             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
263             H                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
264             GMX_MM_TRANSPOSE2_PD(G,H);
265             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
266             VV               = _mm_macc_pd(vfeps,Fp,Y);
267             vvdw6            = _mm_mul_pd(c6_00,VV);
268             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
269             fvdw6            = _mm_mul_pd(c6_00,FF);
270
271             /* CUBIC SPLINE TABLE REPULSION */
272             vfitab           = _mm_add_epi32(vfitab,ifour);
273             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
274             F                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
275             GMX_MM_TRANSPOSE2_PD(Y,F);
276             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
277             H                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
278             GMX_MM_TRANSPOSE2_PD(G,H);
279             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
280             VV               = _mm_macc_pd(vfeps,Fp,Y);
281             vvdw12           = _mm_mul_pd(c12_00,VV);
282             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
283             fvdw12           = _mm_mul_pd(c12_00,FF);
284             vvdw             = _mm_add_pd(vvdw12,vvdw6);
285             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
286
287             /* Update potential sum for this i atom from the interaction with this j atom. */
288             velecsum         = _mm_add_pd(velecsum,velec);
289             vgbsum           = _mm_add_pd(vgbsum,vgb);
290             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
291
292             fscal            = _mm_add_pd(felec,fvdw);
293
294             /* Update vectorial force */
295             fix0             = _mm_macc_pd(dx00,fscal,fix0);
296             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
297             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
298             
299             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
300                                                    _mm_mul_pd(dx00,fscal),
301                                                    _mm_mul_pd(dy00,fscal),
302                                                    _mm_mul_pd(dz00,fscal));
303
304             /* Inner loop uses 95 flops */
305         }
306
307         if(jidx<j_index_end)
308         {
309
310             jnrA             = jjnr[jidx];
311             j_coord_offsetA  = DIM*jnrA;
312
313             /* load j atom coordinates */
314             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
315                                               &jx0,&jy0,&jz0);
316
317             /* Calculate displacement vector */
318             dx00             = _mm_sub_pd(ix0,jx0);
319             dy00             = _mm_sub_pd(iy0,jy0);
320             dz00             = _mm_sub_pd(iz0,jz0);
321
322             /* Calculate squared distance and things based on it */
323             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
324
325             rinv00           = avx128fma_invsqrt_d(rsq00);
326
327             /* Load parameters for j particles */
328             jq0              = _mm_load_sd(charge+jnrA+0);
329             isaj0            = _mm_load_sd(invsqrta+jnrA+0);
330             vdwjidx0A        = 2*vdwtype[jnrA+0];
331
332             /**************************
333              * CALCULATE INTERACTIONS *
334              **************************/
335
336             r00              = _mm_mul_pd(rsq00,rinv00);
337
338             /* Compute parameters for interactions between i and j atoms */
339             qq00             = _mm_mul_pd(iq0,jq0);
340             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
341
342             /* Calculate table index by multiplying r with table scale and truncate to integer */
343             rt               = _mm_mul_pd(r00,vftabscale);
344             vfitab           = _mm_cvttpd_epi32(rt);
345 #ifdef __XOP__
346             vfeps            = _mm_frcz_pd(rt);
347 #else
348             vfeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
349 #endif
350             twovfeps         = _mm_add_pd(vfeps,vfeps);
351             vfitab           = _mm_slli_epi32(vfitab,3);
352
353             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
354             isaprod          = _mm_mul_pd(isai0,isaj0);
355             gbqqfactor       = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
356             gbscale          = _mm_mul_pd(isaprod,gbtabscale);
357
358             /* Calculate generalized born table index - this is a separate table from the normal one,
359              * but we use the same procedure by multiplying r with scale and truncating to integer.
360              */
361             rt               = _mm_mul_pd(r00,gbscale);
362             gbitab           = _mm_cvttpd_epi32(rt);
363 #ifdef __XOP__
364             gbeps            = _mm_frcz_pd(rt);
365 #else
366             gbeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
367 #endif
368             gbitab           = _mm_slli_epi32(gbitab,2);
369
370             Y                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
371             F                = _mm_setzero_pd();
372             GMX_MM_TRANSPOSE2_PD(Y,F);
373             G                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
374             H                = _mm_setzero_pd();
375             GMX_MM_TRANSPOSE2_PD(G,H);
376             Fp               = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
377             VV               = _mm_macc_pd(gbeps,Fp,Y);
378             vgb              = _mm_mul_pd(gbqqfactor,VV);
379
380             twogbeps         = _mm_add_pd(gbeps,gbeps);
381             FF               = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
382             fgb              = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
383             dvdatmp          = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
384             dvdatmp          = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
385             dvdasum          = _mm_add_pd(dvdasum,dvdatmp);
386             gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
387             velec            = _mm_mul_pd(qq00,rinv00);
388             felec            = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
389
390             /* CUBIC SPLINE TABLE DISPERSION */
391             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
392             F                = _mm_setzero_pd();
393             GMX_MM_TRANSPOSE2_PD(Y,F);
394             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
395             H                = _mm_setzero_pd();
396             GMX_MM_TRANSPOSE2_PD(G,H);
397             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
398             VV               = _mm_macc_pd(vfeps,Fp,Y);
399             vvdw6            = _mm_mul_pd(c6_00,VV);
400             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
401             fvdw6            = _mm_mul_pd(c6_00,FF);
402
403             /* CUBIC SPLINE TABLE REPULSION */
404             vfitab           = _mm_add_epi32(vfitab,ifour);
405             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
406             F                = _mm_setzero_pd();
407             GMX_MM_TRANSPOSE2_PD(Y,F);
408             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
409             H                = _mm_setzero_pd();
410             GMX_MM_TRANSPOSE2_PD(G,H);
411             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
412             VV               = _mm_macc_pd(vfeps,Fp,Y);
413             vvdw12           = _mm_mul_pd(c12_00,VV);
414             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
415             fvdw12           = _mm_mul_pd(c12_00,FF);
416             vvdw             = _mm_add_pd(vvdw12,vvdw6);
417             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
418
419             /* Update potential sum for this i atom from the interaction with this j atom. */
420             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
421             velecsum         = _mm_add_pd(velecsum,velec);
422             vgb              = _mm_unpacklo_pd(vgb,_mm_setzero_pd());
423             vgbsum           = _mm_add_pd(vgbsum,vgb);
424             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
425             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
426
427             fscal            = _mm_add_pd(felec,fvdw);
428
429             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
430
431             /* Update vectorial force */
432             fix0             = _mm_macc_pd(dx00,fscal,fix0);
433             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
434             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
435             
436             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
437                                                    _mm_mul_pd(dx00,fscal),
438                                                    _mm_mul_pd(dy00,fscal),
439                                                    _mm_mul_pd(dz00,fscal));
440
441             /* Inner loop uses 95 flops */
442         }
443
444         /* End of innermost loop */
445
446         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
447                                               f+i_coord_offset,fshift+i_shift_offset);
448
449         ggid                        = gid[iidx];
450         /* Update potential energies */
451         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
452         gmx_mm_update_1pot_pd(vgbsum,kernel_data->energygrp_polarization+ggid);
453         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
454         dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
455         gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
456
457         /* Increment number of inner iterations */
458         inneriter                  += j_index_end - j_index_start;
459
460         /* Outer loop uses 10 flops */
461     }
462
463     /* Increment number of outer iterations */
464     outeriter        += nri;
465
466     /* Update outer/inner flops */
467
468     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*95);
469 }
470 /*
471  * Gromacs nonbonded kernel:   nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_double
472  * Electrostatics interaction: GeneralizedBorn
473  * VdW interaction:            CubicSplineTable
474  * Geometry:                   Particle-Particle
475  * Calculate force/pot:        Force
476  */
477 void
478 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_double
479                     (t_nblist                    * gmx_restrict       nlist,
480                      rvec                        * gmx_restrict          xx,
481                      rvec                        * gmx_restrict          ff,
482                      struct t_forcerec           * gmx_restrict          fr,
483                      t_mdatoms                   * gmx_restrict     mdatoms,
484                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
485                      t_nrnb                      * gmx_restrict        nrnb)
486 {
487     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
488      * just 0 for non-waters.
489      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
490      * jnr indices corresponding to data put in the four positions in the SIMD register.
491      */
492     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
493     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
494     int              jnrA,jnrB;
495     int              j_coord_offsetA,j_coord_offsetB;
496     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
497     real             rcutoff_scalar;
498     real             *shiftvec,*fshift,*x,*f;
499     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
500     int              vdwioffset0;
501     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
502     int              vdwjidx0A,vdwjidx0B;
503     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
504     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
505     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
506     real             *charge;
507     __m128i          gbitab;
508     __m128d          vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,dvdaj,gbeps,twogbeps,dvdatmp;
509     __m128d          minushalf = _mm_set1_pd(-0.5);
510     real             *invsqrta,*dvda,*gbtab;
511     int              nvdwtype;
512     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
513     int              *vdwtype;
514     real             *vdwparam;
515     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
516     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
517     __m128i          vfitab;
518     __m128i          ifour       = _mm_set1_epi32(4);
519     __m128d          rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
520     real             *vftab;
521     __m128d          dummy_mask,cutoff_mask;
522     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
523     __m128d          one     = _mm_set1_pd(1.0);
524     __m128d          two     = _mm_set1_pd(2.0);
525     x                = xx[0];
526     f                = ff[0];
527
528     nri              = nlist->nri;
529     iinr             = nlist->iinr;
530     jindex           = nlist->jindex;
531     jjnr             = nlist->jjnr;
532     shiftidx         = nlist->shift;
533     gid              = nlist->gid;
534     shiftvec         = fr->shift_vec[0];
535     fshift           = fr->fshift[0];
536     facel            = _mm_set1_pd(fr->ic->epsfac);
537     charge           = mdatoms->chargeA;
538     nvdwtype         = fr->ntype;
539     vdwparam         = fr->nbfp;
540     vdwtype          = mdatoms->typeA;
541
542     vftab            = kernel_data->table_vdw->data;
543     vftabscale       = _mm_set1_pd(kernel_data->table_vdw->scale);
544
545     invsqrta         = fr->invsqrta;
546     dvda             = fr->dvda;
547     gbtabscale       = _mm_set1_pd(fr->gbtab->scale);
548     gbtab            = fr->gbtab->data;
549     gbinvepsdiff     = _mm_set1_pd((1.0/fr->ic->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
550
551     /* Avoid stupid compiler warnings */
552     jnrA = jnrB = 0;
553     j_coord_offsetA = 0;
554     j_coord_offsetB = 0;
555
556     outeriter        = 0;
557     inneriter        = 0;
558
559     /* Start outer loop over neighborlists */
560     for(iidx=0; iidx<nri; iidx++)
561     {
562         /* Load shift vector for this list */
563         i_shift_offset   = DIM*shiftidx[iidx];
564
565         /* Load limits for loop over neighbors */
566         j_index_start    = jindex[iidx];
567         j_index_end      = jindex[iidx+1];
568
569         /* Get outer coordinate index */
570         inr              = iinr[iidx];
571         i_coord_offset   = DIM*inr;
572
573         /* Load i particle coords and add shift vector */
574         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
575
576         fix0             = _mm_setzero_pd();
577         fiy0             = _mm_setzero_pd();
578         fiz0             = _mm_setzero_pd();
579
580         /* Load parameters for i particles */
581         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
582         isai0            = _mm_load1_pd(invsqrta+inr+0);
583         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
584
585         dvdasum          = _mm_setzero_pd();
586
587         /* Start inner kernel loop */
588         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
589         {
590
591             /* Get j neighbor index, and coordinate index */
592             jnrA             = jjnr[jidx];
593             jnrB             = jjnr[jidx+1];
594             j_coord_offsetA  = DIM*jnrA;
595             j_coord_offsetB  = DIM*jnrB;
596
597             /* load j atom coordinates */
598             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
599                                               &jx0,&jy0,&jz0);
600
601             /* Calculate displacement vector */
602             dx00             = _mm_sub_pd(ix0,jx0);
603             dy00             = _mm_sub_pd(iy0,jy0);
604             dz00             = _mm_sub_pd(iz0,jz0);
605
606             /* Calculate squared distance and things based on it */
607             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
608
609             rinv00           = avx128fma_invsqrt_d(rsq00);
610
611             /* Load parameters for j particles */
612             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
613             isaj0            = gmx_mm_load_2real_swizzle_pd(invsqrta+jnrA+0,invsqrta+jnrB+0);
614             vdwjidx0A        = 2*vdwtype[jnrA+0];
615             vdwjidx0B        = 2*vdwtype[jnrB+0];
616
617             /**************************
618              * CALCULATE INTERACTIONS *
619              **************************/
620
621             r00              = _mm_mul_pd(rsq00,rinv00);
622
623             /* Compute parameters for interactions between i and j atoms */
624             qq00             = _mm_mul_pd(iq0,jq0);
625             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
626                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
627
628             /* Calculate table index by multiplying r with table scale and truncate to integer */
629             rt               = _mm_mul_pd(r00,vftabscale);
630             vfitab           = _mm_cvttpd_epi32(rt);
631 #ifdef __XOP__
632             vfeps            = _mm_frcz_pd(rt);
633 #else
634             vfeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
635 #endif
636             twovfeps         = _mm_add_pd(vfeps,vfeps);
637             vfitab           = _mm_slli_epi32(vfitab,3);
638
639             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
640             isaprod          = _mm_mul_pd(isai0,isaj0);
641             gbqqfactor       = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
642             gbscale          = _mm_mul_pd(isaprod,gbtabscale);
643
644             /* Calculate generalized born table index - this is a separate table from the normal one,
645              * but we use the same procedure by multiplying r with scale and truncating to integer.
646              */
647             rt               = _mm_mul_pd(r00,gbscale);
648             gbitab           = _mm_cvttpd_epi32(rt);
649 #ifdef __XOP__
650             gbeps            = _mm_frcz_pd(rt);
651 #else
652             gbeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
653 #endif
654             gbitab           = _mm_slli_epi32(gbitab,2);
655
656             Y                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
657             F                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) );
658             GMX_MM_TRANSPOSE2_PD(Y,F);
659             G                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
660             H                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,1) +2);
661             GMX_MM_TRANSPOSE2_PD(G,H);
662             Fp               = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
663             VV               = _mm_macc_pd(gbeps,Fp,Y);
664             vgb              = _mm_mul_pd(gbqqfactor,VV);
665
666             twogbeps         = _mm_add_pd(gbeps,gbeps);
667             FF               = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
668             fgb              = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
669             dvdatmp          = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
670             dvdasum          = _mm_add_pd(dvdasum,dvdatmp);
671             gmx_mm_increment_2real_swizzle_pd(dvda+jnrA,dvda+jnrB,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
672             velec            = _mm_mul_pd(qq00,rinv00);
673             felec            = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
674
675             /* CUBIC SPLINE TABLE DISPERSION */
676             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
677             F                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
678             GMX_MM_TRANSPOSE2_PD(Y,F);
679             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
680             H                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
681             GMX_MM_TRANSPOSE2_PD(G,H);
682             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
683             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
684             fvdw6            = _mm_mul_pd(c6_00,FF);
685
686             /* CUBIC SPLINE TABLE REPULSION */
687             vfitab           = _mm_add_epi32(vfitab,ifour);
688             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
689             F                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
690             GMX_MM_TRANSPOSE2_PD(Y,F);
691             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
692             H                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
693             GMX_MM_TRANSPOSE2_PD(G,H);
694             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
695             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
696             fvdw12           = _mm_mul_pd(c12_00,FF);
697             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
698
699             fscal            = _mm_add_pd(felec,fvdw);
700
701             /* Update vectorial force */
702             fix0             = _mm_macc_pd(dx00,fscal,fix0);
703             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
704             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
705             
706             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
707                                                    _mm_mul_pd(dx00,fscal),
708                                                    _mm_mul_pd(dy00,fscal),
709                                                    _mm_mul_pd(dz00,fscal));
710
711             /* Inner loop uses 85 flops */
712         }
713
714         if(jidx<j_index_end)
715         {
716
717             jnrA             = jjnr[jidx];
718             j_coord_offsetA  = DIM*jnrA;
719
720             /* load j atom coordinates */
721             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
722                                               &jx0,&jy0,&jz0);
723
724             /* Calculate displacement vector */
725             dx00             = _mm_sub_pd(ix0,jx0);
726             dy00             = _mm_sub_pd(iy0,jy0);
727             dz00             = _mm_sub_pd(iz0,jz0);
728
729             /* Calculate squared distance and things based on it */
730             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
731
732             rinv00           = avx128fma_invsqrt_d(rsq00);
733
734             /* Load parameters for j particles */
735             jq0              = _mm_load_sd(charge+jnrA+0);
736             isaj0            = _mm_load_sd(invsqrta+jnrA+0);
737             vdwjidx0A        = 2*vdwtype[jnrA+0];
738
739             /**************************
740              * CALCULATE INTERACTIONS *
741              **************************/
742
743             r00              = _mm_mul_pd(rsq00,rinv00);
744
745             /* Compute parameters for interactions between i and j atoms */
746             qq00             = _mm_mul_pd(iq0,jq0);
747             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
748
749             /* Calculate table index by multiplying r with table scale and truncate to integer */
750             rt               = _mm_mul_pd(r00,vftabscale);
751             vfitab           = _mm_cvttpd_epi32(rt);
752 #ifdef __XOP__
753             vfeps            = _mm_frcz_pd(rt);
754 #else
755             vfeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
756 #endif
757             twovfeps         = _mm_add_pd(vfeps,vfeps);
758             vfitab           = _mm_slli_epi32(vfitab,3);
759
760             /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
761             isaprod          = _mm_mul_pd(isai0,isaj0);
762             gbqqfactor       = _mm_xor_pd(signbit,_mm_mul_pd(qq00,_mm_mul_pd(isaprod,gbinvepsdiff)));
763             gbscale          = _mm_mul_pd(isaprod,gbtabscale);
764
765             /* Calculate generalized born table index - this is a separate table from the normal one,
766              * but we use the same procedure by multiplying r with scale and truncating to integer.
767              */
768             rt               = _mm_mul_pd(r00,gbscale);
769             gbitab           = _mm_cvttpd_epi32(rt);
770 #ifdef __XOP__
771             gbeps            = _mm_frcz_pd(rt);
772 #else
773             gbeps            = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
774 #endif
775             gbitab           = _mm_slli_epi32(gbitab,2);
776
777             Y                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) );
778             F                = _mm_setzero_pd();
779             GMX_MM_TRANSPOSE2_PD(Y,F);
780             G                = _mm_load_pd( gbtab + _mm_extract_epi32(gbitab,0) +2);
781             H                = _mm_setzero_pd();
782             GMX_MM_TRANSPOSE2_PD(G,H);
783             Fp               = _mm_macc_pd(gbeps,_mm_macc_pd(gbeps,H,G),F);
784             VV               = _mm_macc_pd(gbeps,Fp,Y);
785             vgb              = _mm_mul_pd(gbqqfactor,VV);
786
787             twogbeps         = _mm_add_pd(gbeps,gbeps);
788             FF               = _mm_macc_pd(_mm_macc_pd(twogbeps,H,G),gbeps,Fp);
789             fgb              = _mm_mul_pd(gbqqfactor,_mm_mul_pd(FF,gbscale));
790             dvdatmp          = _mm_mul_pd(minushalf,_mm_macc_pd(fgb,r00,vgb));
791             dvdatmp          = _mm_unpacklo_pd(dvdatmp,_mm_setzero_pd());
792             dvdasum          = _mm_add_pd(dvdasum,dvdatmp);
793             gmx_mm_increment_1real_pd(dvda+jnrA,_mm_mul_pd(dvdatmp,_mm_mul_pd(isaj0,isaj0)));
794             velec            = _mm_mul_pd(qq00,rinv00);
795             felec            = _mm_mul_pd(_mm_msub_pd(velec,rinv00,fgb),rinv00);
796
797             /* CUBIC SPLINE TABLE DISPERSION */
798             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
799             F                = _mm_setzero_pd();
800             GMX_MM_TRANSPOSE2_PD(Y,F);
801             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
802             H                = _mm_setzero_pd();
803             GMX_MM_TRANSPOSE2_PD(G,H);
804             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
805             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
806             fvdw6            = _mm_mul_pd(c6_00,FF);
807
808             /* CUBIC SPLINE TABLE REPULSION */
809             vfitab           = _mm_add_epi32(vfitab,ifour);
810             Y                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
811             F                = _mm_setzero_pd();
812             GMX_MM_TRANSPOSE2_PD(Y,F);
813             G                = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
814             H                = _mm_setzero_pd();
815             GMX_MM_TRANSPOSE2_PD(G,H);
816             Fp               = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
817             FF               = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
818             fvdw12           = _mm_mul_pd(c12_00,FF);
819             fvdw             = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
820
821             fscal            = _mm_add_pd(felec,fvdw);
822
823             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
824
825             /* Update vectorial force */
826             fix0             = _mm_macc_pd(dx00,fscal,fix0);
827             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
828             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
829             
830             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
831                                                    _mm_mul_pd(dx00,fscal),
832                                                    _mm_mul_pd(dy00,fscal),
833                                                    _mm_mul_pd(dz00,fscal));
834
835             /* Inner loop uses 85 flops */
836         }
837
838         /* End of innermost loop */
839
840         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
841                                               f+i_coord_offset,fshift+i_shift_offset);
842
843         dvdasum = _mm_mul_pd(dvdasum, _mm_mul_pd(isai0,isai0));
844         gmx_mm_update_1pot_pd(dvdasum,dvda+inr);
845
846         /* Increment number of inner iterations */
847         inneriter                  += j_index_end - j_index_start;
848
849         /* Outer loop uses 7 flops */
850     }
851
852     /* Increment number of outer iterations */
853     outeriter        += nri;
854
855     /* Update outer/inner flops */
856
857     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*85);
858 }