Compile nonbonded kernels as C++
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_avx_128_fma_double.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2017,2018, 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_ElecEwSh_VdwLJSh_GeomW3P1_VF_avx_128_fma_double
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water3-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_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              vdwioffset1;
82     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
83     int              vdwioffset2;
84     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
85     int              vdwjidx0A,vdwjidx0B;
86     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
89     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
90     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
91     real             *charge;
92     int              nvdwtype;
93     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
94     int              *vdwtype;
95     real             *vdwparam;
96     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
97     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
98     __m128i          ewitab;
99     __m128d          ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
100     real             *ewtab;
101     __m128d          dummy_mask,cutoff_mask;
102     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
103     __m128d          one     = _mm_set1_pd(1.0);
104     __m128d          two     = _mm_set1_pd(2.0);
105     x                = xx[0];
106     f                = ff[0];
107
108     nri              = nlist->nri;
109     iinr             = nlist->iinr;
110     jindex           = nlist->jindex;
111     jjnr             = nlist->jjnr;
112     shiftidx         = nlist->shift;
113     gid              = nlist->gid;
114     shiftvec         = fr->shift_vec[0];
115     fshift           = fr->fshift[0];
116     facel            = _mm_set1_pd(fr->ic->epsfac);
117     charge           = mdatoms->chargeA;
118     nvdwtype         = fr->ntype;
119     vdwparam         = fr->nbfp;
120     vdwtype          = mdatoms->typeA;
121
122     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
123     ewtab            = fr->ic->tabq_coul_FDV0;
124     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
125     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
126
127     /* Setup water-specific parameters */
128     inr              = nlist->iinr[0];
129     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
130     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
131     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
132     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
133
134     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
135     rcutoff_scalar   = fr->ic->rcoulomb;
136     rcutoff          = _mm_set1_pd(rcutoff_scalar);
137     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
138
139     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
140     rvdw             = _mm_set1_pd(fr->ic->rvdw);
141
142     /* Avoid stupid compiler warnings */
143     jnrA = jnrB = 0;
144     j_coord_offsetA = 0;
145     j_coord_offsetB = 0;
146
147     outeriter        = 0;
148     inneriter        = 0;
149
150     /* Start outer loop over neighborlists */
151     for(iidx=0; iidx<nri; iidx++)
152     {
153         /* Load shift vector for this list */
154         i_shift_offset   = DIM*shiftidx[iidx];
155
156         /* Load limits for loop over neighbors */
157         j_index_start    = jindex[iidx];
158         j_index_end      = jindex[iidx+1];
159
160         /* Get outer coordinate index */
161         inr              = iinr[iidx];
162         i_coord_offset   = DIM*inr;
163
164         /* Load i particle coords and add shift vector */
165         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
166                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
167
168         fix0             = _mm_setzero_pd();
169         fiy0             = _mm_setzero_pd();
170         fiz0             = _mm_setzero_pd();
171         fix1             = _mm_setzero_pd();
172         fiy1             = _mm_setzero_pd();
173         fiz1             = _mm_setzero_pd();
174         fix2             = _mm_setzero_pd();
175         fiy2             = _mm_setzero_pd();
176         fiz2             = _mm_setzero_pd();
177
178         /* Reset potential sums */
179         velecsum         = _mm_setzero_pd();
180         vvdwsum          = _mm_setzero_pd();
181
182         /* Start inner kernel loop */
183         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
184         {
185
186             /* Get j neighbor index, and coordinate index */
187             jnrA             = jjnr[jidx];
188             jnrB             = jjnr[jidx+1];
189             j_coord_offsetA  = DIM*jnrA;
190             j_coord_offsetB  = DIM*jnrB;
191
192             /* load j atom coordinates */
193             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
194                                               &jx0,&jy0,&jz0);
195
196             /* Calculate displacement vector */
197             dx00             = _mm_sub_pd(ix0,jx0);
198             dy00             = _mm_sub_pd(iy0,jy0);
199             dz00             = _mm_sub_pd(iz0,jz0);
200             dx10             = _mm_sub_pd(ix1,jx0);
201             dy10             = _mm_sub_pd(iy1,jy0);
202             dz10             = _mm_sub_pd(iz1,jz0);
203             dx20             = _mm_sub_pd(ix2,jx0);
204             dy20             = _mm_sub_pd(iy2,jy0);
205             dz20             = _mm_sub_pd(iz2,jz0);
206
207             /* Calculate squared distance and things based on it */
208             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
209             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
210             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
211
212             rinv00           = avx128fma_invsqrt_d(rsq00);
213             rinv10           = avx128fma_invsqrt_d(rsq10);
214             rinv20           = avx128fma_invsqrt_d(rsq20);
215
216             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
217             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
218             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
219
220             /* Load parameters for j particles */
221             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
222             vdwjidx0A        = 2*vdwtype[jnrA+0];
223             vdwjidx0B        = 2*vdwtype[jnrB+0];
224
225             fjx0             = _mm_setzero_pd();
226             fjy0             = _mm_setzero_pd();
227             fjz0             = _mm_setzero_pd();
228
229             /**************************
230              * CALCULATE INTERACTIONS *
231              **************************/
232
233             if (gmx_mm_any_lt(rsq00,rcutoff2))
234             {
235
236             r00              = _mm_mul_pd(rsq00,rinv00);
237
238             /* Compute parameters for interactions between i and j atoms */
239             qq00             = _mm_mul_pd(iq0,jq0);
240             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
241                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
242
243             /* EWALD ELECTROSTATICS */
244
245             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
246             ewrt             = _mm_mul_pd(r00,ewtabscale);
247             ewitab           = _mm_cvttpd_epi32(ewrt);
248 #ifdef __XOP__
249             eweps            = _mm_frcz_pd(ewrt);
250 #else
251             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
252 #endif
253             twoeweps         = _mm_add_pd(eweps,eweps);
254             ewitab           = _mm_slli_epi32(ewitab,2);
255             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
256             ewtabD           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
257             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
258             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
259             ewtabFn          = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
260             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
261             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
262             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
263             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
264             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
265
266             /* LENNARD-JONES DISPERSION/REPULSION */
267
268             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
269             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
270             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
271             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
272                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
273             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
274
275             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
276
277             /* Update potential sum for this i atom from the interaction with this j atom. */
278             velec            = _mm_and_pd(velec,cutoff_mask);
279             velecsum         = _mm_add_pd(velecsum,velec);
280             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
281             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
282
283             fscal            = _mm_add_pd(felec,fvdw);
284
285             fscal            = _mm_and_pd(fscal,cutoff_mask);
286
287             /* Update vectorial force */
288             fix0             = _mm_macc_pd(dx00,fscal,fix0);
289             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
290             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
291             
292             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
293             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
294             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
295
296             }
297
298             /**************************
299              * CALCULATE INTERACTIONS *
300              **************************/
301
302             if (gmx_mm_any_lt(rsq10,rcutoff2))
303             {
304
305             r10              = _mm_mul_pd(rsq10,rinv10);
306
307             /* Compute parameters for interactions between i and j atoms */
308             qq10             = _mm_mul_pd(iq1,jq0);
309
310             /* EWALD ELECTROSTATICS */
311
312             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
313             ewrt             = _mm_mul_pd(r10,ewtabscale);
314             ewitab           = _mm_cvttpd_epi32(ewrt);
315 #ifdef __XOP__
316             eweps            = _mm_frcz_pd(ewrt);
317 #else
318             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
319 #endif
320             twoeweps         = _mm_add_pd(eweps,eweps);
321             ewitab           = _mm_slli_epi32(ewitab,2);
322             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
323             ewtabD           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
324             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
325             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
326             ewtabFn          = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
327             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
328             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
329             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
330             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
331             felec            = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
332
333             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
334
335             /* Update potential sum for this i atom from the interaction with this j atom. */
336             velec            = _mm_and_pd(velec,cutoff_mask);
337             velecsum         = _mm_add_pd(velecsum,velec);
338
339             fscal            = felec;
340
341             fscal            = _mm_and_pd(fscal,cutoff_mask);
342
343             /* Update vectorial force */
344             fix1             = _mm_macc_pd(dx10,fscal,fix1);
345             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
346             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
347             
348             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
349             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
350             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
351
352             }
353
354             /**************************
355              * CALCULATE INTERACTIONS *
356              **************************/
357
358             if (gmx_mm_any_lt(rsq20,rcutoff2))
359             {
360
361             r20              = _mm_mul_pd(rsq20,rinv20);
362
363             /* Compute parameters for interactions between i and j atoms */
364             qq20             = _mm_mul_pd(iq2,jq0);
365
366             /* EWALD ELECTROSTATICS */
367
368             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
369             ewrt             = _mm_mul_pd(r20,ewtabscale);
370             ewitab           = _mm_cvttpd_epi32(ewrt);
371 #ifdef __XOP__
372             eweps            = _mm_frcz_pd(ewrt);
373 #else
374             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
375 #endif
376             twoeweps         = _mm_add_pd(eweps,eweps);
377             ewitab           = _mm_slli_epi32(ewitab,2);
378             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
379             ewtabD           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
380             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
381             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
382             ewtabFn          = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,1) +2);
383             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
384             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
385             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
386             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
387             felec            = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
388
389             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
390
391             /* Update potential sum for this i atom from the interaction with this j atom. */
392             velec            = _mm_and_pd(velec,cutoff_mask);
393             velecsum         = _mm_add_pd(velecsum,velec);
394
395             fscal            = felec;
396
397             fscal            = _mm_and_pd(fscal,cutoff_mask);
398
399             /* Update vectorial force */
400             fix2             = _mm_macc_pd(dx20,fscal,fix2);
401             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
402             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
403             
404             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
405             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
406             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
407
408             }
409
410             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
411
412             /* Inner loop uses 168 flops */
413         }
414
415         if(jidx<j_index_end)
416         {
417
418             jnrA             = jjnr[jidx];
419             j_coord_offsetA  = DIM*jnrA;
420
421             /* load j atom coordinates */
422             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
423                                               &jx0,&jy0,&jz0);
424
425             /* Calculate displacement vector */
426             dx00             = _mm_sub_pd(ix0,jx0);
427             dy00             = _mm_sub_pd(iy0,jy0);
428             dz00             = _mm_sub_pd(iz0,jz0);
429             dx10             = _mm_sub_pd(ix1,jx0);
430             dy10             = _mm_sub_pd(iy1,jy0);
431             dz10             = _mm_sub_pd(iz1,jz0);
432             dx20             = _mm_sub_pd(ix2,jx0);
433             dy20             = _mm_sub_pd(iy2,jy0);
434             dz20             = _mm_sub_pd(iz2,jz0);
435
436             /* Calculate squared distance and things based on it */
437             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
438             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
439             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
440
441             rinv00           = avx128fma_invsqrt_d(rsq00);
442             rinv10           = avx128fma_invsqrt_d(rsq10);
443             rinv20           = avx128fma_invsqrt_d(rsq20);
444
445             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
446             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
447             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
448
449             /* Load parameters for j particles */
450             jq0              = _mm_load_sd(charge+jnrA+0);
451             vdwjidx0A        = 2*vdwtype[jnrA+0];
452
453             fjx0             = _mm_setzero_pd();
454             fjy0             = _mm_setzero_pd();
455             fjz0             = _mm_setzero_pd();
456
457             /**************************
458              * CALCULATE INTERACTIONS *
459              **************************/
460
461             if (gmx_mm_any_lt(rsq00,rcutoff2))
462             {
463
464             r00              = _mm_mul_pd(rsq00,rinv00);
465
466             /* Compute parameters for interactions between i and j atoms */
467             qq00             = _mm_mul_pd(iq0,jq0);
468             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
469
470             /* EWALD ELECTROSTATICS */
471
472             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
473             ewrt             = _mm_mul_pd(r00,ewtabscale);
474             ewitab           = _mm_cvttpd_epi32(ewrt);
475 #ifdef __XOP__
476             eweps            = _mm_frcz_pd(ewrt);
477 #else
478             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
479 #endif
480             twoeweps         = _mm_add_pd(eweps,eweps);
481             ewitab           = _mm_slli_epi32(ewitab,2);
482             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
483             ewtabD           = _mm_setzero_pd();
484             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
485             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
486             ewtabFn          = _mm_setzero_pd();
487             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
488             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
489             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
490             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_sub_pd(rinv00,sh_ewald),velec));
491             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
492
493             /* LENNARD-JONES DISPERSION/REPULSION */
494
495             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
496             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
497             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
498             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
499                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
500             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
501
502             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
503
504             /* Update potential sum for this i atom from the interaction with this j atom. */
505             velec            = _mm_and_pd(velec,cutoff_mask);
506             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
507             velecsum         = _mm_add_pd(velecsum,velec);
508             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
509             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
510             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
511
512             fscal            = _mm_add_pd(felec,fvdw);
513
514             fscal            = _mm_and_pd(fscal,cutoff_mask);
515
516             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
517
518             /* Update vectorial force */
519             fix0             = _mm_macc_pd(dx00,fscal,fix0);
520             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
521             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
522             
523             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
524             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
525             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
526
527             }
528
529             /**************************
530              * CALCULATE INTERACTIONS *
531              **************************/
532
533             if (gmx_mm_any_lt(rsq10,rcutoff2))
534             {
535
536             r10              = _mm_mul_pd(rsq10,rinv10);
537
538             /* Compute parameters for interactions between i and j atoms */
539             qq10             = _mm_mul_pd(iq1,jq0);
540
541             /* EWALD ELECTROSTATICS */
542
543             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
544             ewrt             = _mm_mul_pd(r10,ewtabscale);
545             ewitab           = _mm_cvttpd_epi32(ewrt);
546 #ifdef __XOP__
547             eweps            = _mm_frcz_pd(ewrt);
548 #else
549             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
550 #endif
551             twoeweps         = _mm_add_pd(eweps,eweps);
552             ewitab           = _mm_slli_epi32(ewitab,2);
553             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
554             ewtabD           = _mm_setzero_pd();
555             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
556             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
557             ewtabFn          = _mm_setzero_pd();
558             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
559             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
560             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
561             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
562             felec            = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
563
564             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
565
566             /* Update potential sum for this i atom from the interaction with this j atom. */
567             velec            = _mm_and_pd(velec,cutoff_mask);
568             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
569             velecsum         = _mm_add_pd(velecsum,velec);
570
571             fscal            = felec;
572
573             fscal            = _mm_and_pd(fscal,cutoff_mask);
574
575             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
576
577             /* Update vectorial force */
578             fix1             = _mm_macc_pd(dx10,fscal,fix1);
579             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
580             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
581             
582             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
583             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
584             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
585
586             }
587
588             /**************************
589              * CALCULATE INTERACTIONS *
590              **************************/
591
592             if (gmx_mm_any_lt(rsq20,rcutoff2))
593             {
594
595             r20              = _mm_mul_pd(rsq20,rinv20);
596
597             /* Compute parameters for interactions between i and j atoms */
598             qq20             = _mm_mul_pd(iq2,jq0);
599
600             /* EWALD ELECTROSTATICS */
601
602             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
603             ewrt             = _mm_mul_pd(r20,ewtabscale);
604             ewitab           = _mm_cvttpd_epi32(ewrt);
605 #ifdef __XOP__
606             eweps            = _mm_frcz_pd(ewrt);
607 #else
608             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
609 #endif
610             twoeweps         = _mm_add_pd(eweps,eweps);
611             ewitab           = _mm_slli_epi32(ewitab,2);
612             ewtabF           = _mm_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
613             ewtabD           = _mm_setzero_pd();
614             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
615             ewtabV           = _mm_load_sd( ewtab + _mm_extract_epi32(ewitab,0) +2);
616             ewtabFn          = _mm_setzero_pd();
617             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
618             felec            = _mm_macc_pd(eweps,ewtabD,ewtabF);
619             velec            = _mm_nmacc_pd(_mm_mul_pd(ewtabhalfspace,eweps) ,_mm_add_pd(ewtabF,felec), ewtabV);
620             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
621             felec            = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
622
623             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
624
625             /* Update potential sum for this i atom from the interaction with this j atom. */
626             velec            = _mm_and_pd(velec,cutoff_mask);
627             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
628             velecsum         = _mm_add_pd(velecsum,velec);
629
630             fscal            = felec;
631
632             fscal            = _mm_and_pd(fscal,cutoff_mask);
633
634             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
635
636             /* Update vectorial force */
637             fix2             = _mm_macc_pd(dx20,fscal,fix2);
638             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
639             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
640             
641             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
642             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
643             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
644
645             }
646
647             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
648
649             /* Inner loop uses 168 flops */
650         }
651
652         /* End of innermost loop */
653
654         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
655                                               f+i_coord_offset,fshift+i_shift_offset);
656
657         ggid                        = gid[iidx];
658         /* Update potential energies */
659         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
660         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
661
662         /* Increment number of inner iterations */
663         inneriter                  += j_index_end - j_index_start;
664
665         /* Outer loop uses 20 flops */
666     }
667
668     /* Increment number of outer iterations */
669     outeriter        += nri;
670
671     /* Update outer/inner flops */
672
673     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*168);
674 }
675 /*
676  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_avx_128_fma_double
677  * Electrostatics interaction: Ewald
678  * VdW interaction:            LennardJones
679  * Geometry:                   Water3-Particle
680  * Calculate force/pot:        Force
681  */
682 void
683 nb_kernel_ElecEwSh_VdwLJSh_GeomW3P1_F_avx_128_fma_double
684                     (t_nblist                    * gmx_restrict       nlist,
685                      rvec                        * gmx_restrict          xx,
686                      rvec                        * gmx_restrict          ff,
687                      struct t_forcerec           * gmx_restrict          fr,
688                      t_mdatoms                   * gmx_restrict     mdatoms,
689                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
690                      t_nrnb                      * gmx_restrict        nrnb)
691 {
692     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
693      * just 0 for non-waters.
694      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
695      * jnr indices corresponding to data put in the four positions in the SIMD register.
696      */
697     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
698     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
699     int              jnrA,jnrB;
700     int              j_coord_offsetA,j_coord_offsetB;
701     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
702     real             rcutoff_scalar;
703     real             *shiftvec,*fshift,*x,*f;
704     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
705     int              vdwioffset0;
706     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
707     int              vdwioffset1;
708     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
709     int              vdwioffset2;
710     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
711     int              vdwjidx0A,vdwjidx0B;
712     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
713     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
714     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
715     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
716     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
717     real             *charge;
718     int              nvdwtype;
719     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
720     int              *vdwtype;
721     real             *vdwparam;
722     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
723     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
724     __m128i          ewitab;
725     __m128d          ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
726     real             *ewtab;
727     __m128d          dummy_mask,cutoff_mask;
728     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
729     __m128d          one     = _mm_set1_pd(1.0);
730     __m128d          two     = _mm_set1_pd(2.0);
731     x                = xx[0];
732     f                = ff[0];
733
734     nri              = nlist->nri;
735     iinr             = nlist->iinr;
736     jindex           = nlist->jindex;
737     jjnr             = nlist->jjnr;
738     shiftidx         = nlist->shift;
739     gid              = nlist->gid;
740     shiftvec         = fr->shift_vec[0];
741     fshift           = fr->fshift[0];
742     facel            = _mm_set1_pd(fr->ic->epsfac);
743     charge           = mdatoms->chargeA;
744     nvdwtype         = fr->ntype;
745     vdwparam         = fr->nbfp;
746     vdwtype          = mdatoms->typeA;
747
748     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
749     ewtab            = fr->ic->tabq_coul_F;
750     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
751     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
752
753     /* Setup water-specific parameters */
754     inr              = nlist->iinr[0];
755     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
756     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
757     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
758     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
759
760     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
761     rcutoff_scalar   = fr->ic->rcoulomb;
762     rcutoff          = _mm_set1_pd(rcutoff_scalar);
763     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
764
765     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
766     rvdw             = _mm_set1_pd(fr->ic->rvdw);
767
768     /* Avoid stupid compiler warnings */
769     jnrA = jnrB = 0;
770     j_coord_offsetA = 0;
771     j_coord_offsetB = 0;
772
773     outeriter        = 0;
774     inneriter        = 0;
775
776     /* Start outer loop over neighborlists */
777     for(iidx=0; iidx<nri; iidx++)
778     {
779         /* Load shift vector for this list */
780         i_shift_offset   = DIM*shiftidx[iidx];
781
782         /* Load limits for loop over neighbors */
783         j_index_start    = jindex[iidx];
784         j_index_end      = jindex[iidx+1];
785
786         /* Get outer coordinate index */
787         inr              = iinr[iidx];
788         i_coord_offset   = DIM*inr;
789
790         /* Load i particle coords and add shift vector */
791         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
792                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
793
794         fix0             = _mm_setzero_pd();
795         fiy0             = _mm_setzero_pd();
796         fiz0             = _mm_setzero_pd();
797         fix1             = _mm_setzero_pd();
798         fiy1             = _mm_setzero_pd();
799         fiz1             = _mm_setzero_pd();
800         fix2             = _mm_setzero_pd();
801         fiy2             = _mm_setzero_pd();
802         fiz2             = _mm_setzero_pd();
803
804         /* Start inner kernel loop */
805         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
806         {
807
808             /* Get j neighbor index, and coordinate index */
809             jnrA             = jjnr[jidx];
810             jnrB             = jjnr[jidx+1];
811             j_coord_offsetA  = DIM*jnrA;
812             j_coord_offsetB  = DIM*jnrB;
813
814             /* load j atom coordinates */
815             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
816                                               &jx0,&jy0,&jz0);
817
818             /* Calculate displacement vector */
819             dx00             = _mm_sub_pd(ix0,jx0);
820             dy00             = _mm_sub_pd(iy0,jy0);
821             dz00             = _mm_sub_pd(iz0,jz0);
822             dx10             = _mm_sub_pd(ix1,jx0);
823             dy10             = _mm_sub_pd(iy1,jy0);
824             dz10             = _mm_sub_pd(iz1,jz0);
825             dx20             = _mm_sub_pd(ix2,jx0);
826             dy20             = _mm_sub_pd(iy2,jy0);
827             dz20             = _mm_sub_pd(iz2,jz0);
828
829             /* Calculate squared distance and things based on it */
830             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
831             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
832             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
833
834             rinv00           = avx128fma_invsqrt_d(rsq00);
835             rinv10           = avx128fma_invsqrt_d(rsq10);
836             rinv20           = avx128fma_invsqrt_d(rsq20);
837
838             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
839             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
840             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
841
842             /* Load parameters for j particles */
843             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
844             vdwjidx0A        = 2*vdwtype[jnrA+0];
845             vdwjidx0B        = 2*vdwtype[jnrB+0];
846
847             fjx0             = _mm_setzero_pd();
848             fjy0             = _mm_setzero_pd();
849             fjz0             = _mm_setzero_pd();
850
851             /**************************
852              * CALCULATE INTERACTIONS *
853              **************************/
854
855             if (gmx_mm_any_lt(rsq00,rcutoff2))
856             {
857
858             r00              = _mm_mul_pd(rsq00,rinv00);
859
860             /* Compute parameters for interactions between i and j atoms */
861             qq00             = _mm_mul_pd(iq0,jq0);
862             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
863                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
864
865             /* EWALD ELECTROSTATICS */
866
867             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
868             ewrt             = _mm_mul_pd(r00,ewtabscale);
869             ewitab           = _mm_cvttpd_epi32(ewrt);
870 #ifdef __XOP__
871             eweps            = _mm_frcz_pd(ewrt);
872 #else
873             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
874 #endif
875             twoeweps         = _mm_add_pd(eweps,eweps);
876             gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
877                                          &ewtabF,&ewtabFn);
878             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
879             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
880
881             /* LENNARD-JONES DISPERSION/REPULSION */
882
883             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
884             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
885
886             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
887
888             fscal            = _mm_add_pd(felec,fvdw);
889
890             fscal            = _mm_and_pd(fscal,cutoff_mask);
891
892             /* Update vectorial force */
893             fix0             = _mm_macc_pd(dx00,fscal,fix0);
894             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
895             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
896             
897             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
898             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
899             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
900
901             }
902
903             /**************************
904              * CALCULATE INTERACTIONS *
905              **************************/
906
907             if (gmx_mm_any_lt(rsq10,rcutoff2))
908             {
909
910             r10              = _mm_mul_pd(rsq10,rinv10);
911
912             /* Compute parameters for interactions between i and j atoms */
913             qq10             = _mm_mul_pd(iq1,jq0);
914
915             /* EWALD ELECTROSTATICS */
916
917             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
918             ewrt             = _mm_mul_pd(r10,ewtabscale);
919             ewitab           = _mm_cvttpd_epi32(ewrt);
920 #ifdef __XOP__
921             eweps            = _mm_frcz_pd(ewrt);
922 #else
923             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
924 #endif
925             twoeweps         = _mm_add_pd(eweps,eweps);
926             gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
927                                          &ewtabF,&ewtabFn);
928             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
929             felec            = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
930
931             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
932
933             fscal            = felec;
934
935             fscal            = _mm_and_pd(fscal,cutoff_mask);
936
937             /* Update vectorial force */
938             fix1             = _mm_macc_pd(dx10,fscal,fix1);
939             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
940             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
941             
942             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
943             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
944             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
945
946             }
947
948             /**************************
949              * CALCULATE INTERACTIONS *
950              **************************/
951
952             if (gmx_mm_any_lt(rsq20,rcutoff2))
953             {
954
955             r20              = _mm_mul_pd(rsq20,rinv20);
956
957             /* Compute parameters for interactions between i and j atoms */
958             qq20             = _mm_mul_pd(iq2,jq0);
959
960             /* EWALD ELECTROSTATICS */
961
962             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
963             ewrt             = _mm_mul_pd(r20,ewtabscale);
964             ewitab           = _mm_cvttpd_epi32(ewrt);
965 #ifdef __XOP__
966             eweps            = _mm_frcz_pd(ewrt);
967 #else
968             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
969 #endif
970             twoeweps         = _mm_add_pd(eweps,eweps);
971             gmx_mm_load_2pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),ewtab+_mm_extract_epi32(ewitab,1),
972                                          &ewtabF,&ewtabFn);
973             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
974             felec            = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
975
976             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
977
978             fscal            = felec;
979
980             fscal            = _mm_and_pd(fscal,cutoff_mask);
981
982             /* Update vectorial force */
983             fix2             = _mm_macc_pd(dx20,fscal,fix2);
984             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
985             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
986             
987             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
988             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
989             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
990
991             }
992
993             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
994
995             /* Inner loop uses 136 flops */
996         }
997
998         if(jidx<j_index_end)
999         {
1000
1001             jnrA             = jjnr[jidx];
1002             j_coord_offsetA  = DIM*jnrA;
1003
1004             /* load j atom coordinates */
1005             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
1006                                               &jx0,&jy0,&jz0);
1007
1008             /* Calculate displacement vector */
1009             dx00             = _mm_sub_pd(ix0,jx0);
1010             dy00             = _mm_sub_pd(iy0,jy0);
1011             dz00             = _mm_sub_pd(iz0,jz0);
1012             dx10             = _mm_sub_pd(ix1,jx0);
1013             dy10             = _mm_sub_pd(iy1,jy0);
1014             dz10             = _mm_sub_pd(iz1,jz0);
1015             dx20             = _mm_sub_pd(ix2,jx0);
1016             dy20             = _mm_sub_pd(iy2,jy0);
1017             dz20             = _mm_sub_pd(iz2,jz0);
1018
1019             /* Calculate squared distance and things based on it */
1020             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1021             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
1022             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
1023
1024             rinv00           = avx128fma_invsqrt_d(rsq00);
1025             rinv10           = avx128fma_invsqrt_d(rsq10);
1026             rinv20           = avx128fma_invsqrt_d(rsq20);
1027
1028             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
1029             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
1030             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
1031
1032             /* Load parameters for j particles */
1033             jq0              = _mm_load_sd(charge+jnrA+0);
1034             vdwjidx0A        = 2*vdwtype[jnrA+0];
1035
1036             fjx0             = _mm_setzero_pd();
1037             fjy0             = _mm_setzero_pd();
1038             fjz0             = _mm_setzero_pd();
1039
1040             /**************************
1041              * CALCULATE INTERACTIONS *
1042              **************************/
1043
1044             if (gmx_mm_any_lt(rsq00,rcutoff2))
1045             {
1046
1047             r00              = _mm_mul_pd(rsq00,rinv00);
1048
1049             /* Compute parameters for interactions between i and j atoms */
1050             qq00             = _mm_mul_pd(iq0,jq0);
1051             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
1052
1053             /* EWALD ELECTROSTATICS */
1054
1055             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1056             ewrt             = _mm_mul_pd(r00,ewtabscale);
1057             ewitab           = _mm_cvttpd_epi32(ewrt);
1058 #ifdef __XOP__
1059             eweps            = _mm_frcz_pd(ewrt);
1060 #else
1061             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1062 #endif
1063             twoeweps         = _mm_add_pd(eweps,eweps);
1064             gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1065             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1066             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
1067
1068             /* LENNARD-JONES DISPERSION/REPULSION */
1069
1070             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
1071             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
1072
1073             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
1074
1075             fscal            = _mm_add_pd(felec,fvdw);
1076
1077             fscal            = _mm_and_pd(fscal,cutoff_mask);
1078
1079             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1080
1081             /* Update vectorial force */
1082             fix0             = _mm_macc_pd(dx00,fscal,fix0);
1083             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
1084             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
1085             
1086             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
1087             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
1088             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
1089
1090             }
1091
1092             /**************************
1093              * CALCULATE INTERACTIONS *
1094              **************************/
1095
1096             if (gmx_mm_any_lt(rsq10,rcutoff2))
1097             {
1098
1099             r10              = _mm_mul_pd(rsq10,rinv10);
1100
1101             /* Compute parameters for interactions between i and j atoms */
1102             qq10             = _mm_mul_pd(iq1,jq0);
1103
1104             /* EWALD ELECTROSTATICS */
1105
1106             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1107             ewrt             = _mm_mul_pd(r10,ewtabscale);
1108             ewitab           = _mm_cvttpd_epi32(ewrt);
1109 #ifdef __XOP__
1110             eweps            = _mm_frcz_pd(ewrt);
1111 #else
1112             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1113 #endif
1114             twoeweps         = _mm_add_pd(eweps,eweps);
1115             gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1116             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1117             felec            = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
1118
1119             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
1120
1121             fscal            = felec;
1122
1123             fscal            = _mm_and_pd(fscal,cutoff_mask);
1124
1125             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1126
1127             /* Update vectorial force */
1128             fix1             = _mm_macc_pd(dx10,fscal,fix1);
1129             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
1130             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
1131             
1132             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
1133             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
1134             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
1135
1136             }
1137
1138             /**************************
1139              * CALCULATE INTERACTIONS *
1140              **************************/
1141
1142             if (gmx_mm_any_lt(rsq20,rcutoff2))
1143             {
1144
1145             r20              = _mm_mul_pd(rsq20,rinv20);
1146
1147             /* Compute parameters for interactions between i and j atoms */
1148             qq20             = _mm_mul_pd(iq2,jq0);
1149
1150             /* EWALD ELECTROSTATICS */
1151
1152             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1153             ewrt             = _mm_mul_pd(r20,ewtabscale);
1154             ewitab           = _mm_cvttpd_epi32(ewrt);
1155 #ifdef __XOP__
1156             eweps            = _mm_frcz_pd(ewrt);
1157 #else
1158             eweps            = _mm_sub_pd(ewrt,_mm_round_pd(ewrt, _MM_FROUND_FLOOR));
1159 #endif
1160             twoeweps         = _mm_add_pd(eweps,eweps);
1161             gmx_mm_load_1pair_swizzle_pd(ewtab+_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1162             felec            = _mm_macc_pd(eweps,ewtabFn,_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF));
1163             felec            = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
1164
1165             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
1166
1167             fscal            = felec;
1168
1169             fscal            = _mm_and_pd(fscal,cutoff_mask);
1170
1171             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1172
1173             /* Update vectorial force */
1174             fix2             = _mm_macc_pd(dx20,fscal,fix2);
1175             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
1176             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
1177             
1178             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
1179             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
1180             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
1181
1182             }
1183
1184             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1185
1186             /* Inner loop uses 136 flops */
1187         }
1188
1189         /* End of innermost loop */
1190
1191         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1192                                               f+i_coord_offset,fshift+i_shift_offset);
1193
1194         /* Increment number of inner iterations */
1195         inneriter                  += j_index_end - j_index_start;
1196
1197         /* Outer loop uses 18 flops */
1198     }
1199
1200     /* Increment number of outer iterations */
1201     outeriter        += nri;
1202
1203     /* Update outer/inner flops */
1204
1205     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*136);
1206 }