Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecCoul_VdwLJ_GeomW4P1_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_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_double
51  * Electrostatics interaction: Coulomb
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_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              vdwioffset3;
86     __m128d          ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
87     int              vdwjidx0A,vdwjidx0B;
88     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
91     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
92     __m128d          dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
93     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
94     real             *charge;
95     int              nvdwtype;
96     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97     int              *vdwtype;
98     real             *vdwparam;
99     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
100     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
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     /* Setup water-specific parameters */
123     inr              = nlist->iinr[0];
124     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
125     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
126     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
127     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
128
129     /* Avoid stupid compiler warnings */
130     jnrA = jnrB = 0;
131     j_coord_offsetA = 0;
132     j_coord_offsetB = 0;
133
134     outeriter        = 0;
135     inneriter        = 0;
136
137     /* Start outer loop over neighborlists */
138     for(iidx=0; iidx<nri; iidx++)
139     {
140         /* Load shift vector for this list */
141         i_shift_offset   = DIM*shiftidx[iidx];
142
143         /* Load limits for loop over neighbors */
144         j_index_start    = jindex[iidx];
145         j_index_end      = jindex[iidx+1];
146
147         /* Get outer coordinate index */
148         inr              = iinr[iidx];
149         i_coord_offset   = DIM*inr;
150
151         /* Load i particle coords and add shift vector */
152         gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
153                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
154
155         fix0             = _mm_setzero_pd();
156         fiy0             = _mm_setzero_pd();
157         fiz0             = _mm_setzero_pd();
158         fix1             = _mm_setzero_pd();
159         fiy1             = _mm_setzero_pd();
160         fiz1             = _mm_setzero_pd();
161         fix2             = _mm_setzero_pd();
162         fiy2             = _mm_setzero_pd();
163         fiz2             = _mm_setzero_pd();
164         fix3             = _mm_setzero_pd();
165         fiy3             = _mm_setzero_pd();
166         fiz3             = _mm_setzero_pd();
167
168         /* Reset potential sums */
169         velecsum         = _mm_setzero_pd();
170         vvdwsum          = _mm_setzero_pd();
171
172         /* Start inner kernel loop */
173         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
174         {
175
176             /* Get j neighbor index, and coordinate index */
177             jnrA             = jjnr[jidx];
178             jnrB             = jjnr[jidx+1];
179             j_coord_offsetA  = DIM*jnrA;
180             j_coord_offsetB  = DIM*jnrB;
181
182             /* load j atom coordinates */
183             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
184                                               &jx0,&jy0,&jz0);
185
186             /* Calculate displacement vector */
187             dx00             = _mm_sub_pd(ix0,jx0);
188             dy00             = _mm_sub_pd(iy0,jy0);
189             dz00             = _mm_sub_pd(iz0,jz0);
190             dx10             = _mm_sub_pd(ix1,jx0);
191             dy10             = _mm_sub_pd(iy1,jy0);
192             dz10             = _mm_sub_pd(iz1,jz0);
193             dx20             = _mm_sub_pd(ix2,jx0);
194             dy20             = _mm_sub_pd(iy2,jy0);
195             dz20             = _mm_sub_pd(iz2,jz0);
196             dx30             = _mm_sub_pd(ix3,jx0);
197             dy30             = _mm_sub_pd(iy3,jy0);
198             dz30             = _mm_sub_pd(iz3,jz0);
199
200             /* Calculate squared distance and things based on it */
201             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
202             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
203             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
204             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
205
206             rinv10           = avx128fma_invsqrt_d(rsq10);
207             rinv20           = avx128fma_invsqrt_d(rsq20);
208             rinv30           = avx128fma_invsqrt_d(rsq30);
209
210             rinvsq00         = avx128fma_inv_d(rsq00);
211             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
212             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
213             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
214
215             /* Load parameters for j particles */
216             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
217             vdwjidx0A        = 2*vdwtype[jnrA+0];
218             vdwjidx0B        = 2*vdwtype[jnrB+0];
219
220             fjx0             = _mm_setzero_pd();
221             fjy0             = _mm_setzero_pd();
222             fjz0             = _mm_setzero_pd();
223
224             /**************************
225              * CALCULATE INTERACTIONS *
226              **************************/
227
228             /* Compute parameters for interactions between i and j atoms */
229             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
230                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
231
232             /* LENNARD-JONES DISPERSION/REPULSION */
233
234             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
235             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
236             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
237             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
238             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
239
240             /* Update potential sum for this i atom from the interaction with this j atom. */
241             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
242
243             fscal            = fvdw;
244
245             /* Update vectorial force */
246             fix0             = _mm_macc_pd(dx00,fscal,fix0);
247             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
248             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
249             
250             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
251             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
252             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
253
254             /**************************
255              * CALCULATE INTERACTIONS *
256              **************************/
257
258             /* Compute parameters for interactions between i and j atoms */
259             qq10             = _mm_mul_pd(iq1,jq0);
260
261             /* COULOMB ELECTROSTATICS */
262             velec            = _mm_mul_pd(qq10,rinv10);
263             felec            = _mm_mul_pd(velec,rinvsq10);
264
265             /* Update potential sum for this i atom from the interaction with this j atom. */
266             velecsum         = _mm_add_pd(velecsum,velec);
267
268             fscal            = felec;
269
270             /* Update vectorial force */
271             fix1             = _mm_macc_pd(dx10,fscal,fix1);
272             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
273             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
274             
275             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
276             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
277             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
278
279             /**************************
280              * CALCULATE INTERACTIONS *
281              **************************/
282
283             /* Compute parameters for interactions between i and j atoms */
284             qq20             = _mm_mul_pd(iq2,jq0);
285
286             /* COULOMB ELECTROSTATICS */
287             velec            = _mm_mul_pd(qq20,rinv20);
288             felec            = _mm_mul_pd(velec,rinvsq20);
289
290             /* Update potential sum for this i atom from the interaction with this j atom. */
291             velecsum         = _mm_add_pd(velecsum,velec);
292
293             fscal            = felec;
294
295             /* Update vectorial force */
296             fix2             = _mm_macc_pd(dx20,fscal,fix2);
297             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
298             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
299             
300             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
301             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
302             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
303
304             /**************************
305              * CALCULATE INTERACTIONS *
306              **************************/
307
308             /* Compute parameters for interactions between i and j atoms */
309             qq30             = _mm_mul_pd(iq3,jq0);
310
311             /* COULOMB ELECTROSTATICS */
312             velec            = _mm_mul_pd(qq30,rinv30);
313             felec            = _mm_mul_pd(velec,rinvsq30);
314
315             /* Update potential sum for this i atom from the interaction with this j atom. */
316             velecsum         = _mm_add_pd(velecsum,velec);
317
318             fscal            = felec;
319
320             /* Update vectorial force */
321             fix3             = _mm_macc_pd(dx30,fscal,fix3);
322             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
323             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
324             
325             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
326             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
327             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
328
329             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
330
331             /* Inner loop uses 131 flops */
332         }
333
334         if(jidx<j_index_end)
335         {
336
337             jnrA             = jjnr[jidx];
338             j_coord_offsetA  = DIM*jnrA;
339
340             /* load j atom coordinates */
341             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
342                                               &jx0,&jy0,&jz0);
343
344             /* Calculate displacement vector */
345             dx00             = _mm_sub_pd(ix0,jx0);
346             dy00             = _mm_sub_pd(iy0,jy0);
347             dz00             = _mm_sub_pd(iz0,jz0);
348             dx10             = _mm_sub_pd(ix1,jx0);
349             dy10             = _mm_sub_pd(iy1,jy0);
350             dz10             = _mm_sub_pd(iz1,jz0);
351             dx20             = _mm_sub_pd(ix2,jx0);
352             dy20             = _mm_sub_pd(iy2,jy0);
353             dz20             = _mm_sub_pd(iz2,jz0);
354             dx30             = _mm_sub_pd(ix3,jx0);
355             dy30             = _mm_sub_pd(iy3,jy0);
356             dz30             = _mm_sub_pd(iz3,jz0);
357
358             /* Calculate squared distance and things based on it */
359             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
360             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
361             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
362             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
363
364             rinv10           = avx128fma_invsqrt_d(rsq10);
365             rinv20           = avx128fma_invsqrt_d(rsq20);
366             rinv30           = avx128fma_invsqrt_d(rsq30);
367
368             rinvsq00         = avx128fma_inv_d(rsq00);
369             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
370             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
371             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
372
373             /* Load parameters for j particles */
374             jq0              = _mm_load_sd(charge+jnrA+0);
375             vdwjidx0A        = 2*vdwtype[jnrA+0];
376
377             fjx0             = _mm_setzero_pd();
378             fjy0             = _mm_setzero_pd();
379             fjz0             = _mm_setzero_pd();
380
381             /**************************
382              * CALCULATE INTERACTIONS *
383              **************************/
384
385             /* Compute parameters for interactions between i and j atoms */
386             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
387
388             /* LENNARD-JONES DISPERSION/REPULSION */
389
390             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
391             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
392             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
393             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
394             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
395
396             /* Update potential sum for this i atom from the interaction with this j atom. */
397             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
398             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
399
400             fscal            = fvdw;
401
402             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
403
404             /* Update vectorial force */
405             fix0             = _mm_macc_pd(dx00,fscal,fix0);
406             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
407             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
408             
409             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
410             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
411             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
412
413             /**************************
414              * CALCULATE INTERACTIONS *
415              **************************/
416
417             /* Compute parameters for interactions between i and j atoms */
418             qq10             = _mm_mul_pd(iq1,jq0);
419
420             /* COULOMB ELECTROSTATICS */
421             velec            = _mm_mul_pd(qq10,rinv10);
422             felec            = _mm_mul_pd(velec,rinvsq10);
423
424             /* Update potential sum for this i atom from the interaction with this j atom. */
425             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
426             velecsum         = _mm_add_pd(velecsum,velec);
427
428             fscal            = felec;
429
430             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
431
432             /* Update vectorial force */
433             fix1             = _mm_macc_pd(dx10,fscal,fix1);
434             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
435             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
436             
437             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
438             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
439             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
440
441             /**************************
442              * CALCULATE INTERACTIONS *
443              **************************/
444
445             /* Compute parameters for interactions between i and j atoms */
446             qq20             = _mm_mul_pd(iq2,jq0);
447
448             /* COULOMB ELECTROSTATICS */
449             velec            = _mm_mul_pd(qq20,rinv20);
450             felec            = _mm_mul_pd(velec,rinvsq20);
451
452             /* Update potential sum for this i atom from the interaction with this j atom. */
453             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
454             velecsum         = _mm_add_pd(velecsum,velec);
455
456             fscal            = felec;
457
458             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
459
460             /* Update vectorial force */
461             fix2             = _mm_macc_pd(dx20,fscal,fix2);
462             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
463             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
464             
465             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
466             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
467             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
468
469             /**************************
470              * CALCULATE INTERACTIONS *
471              **************************/
472
473             /* Compute parameters for interactions between i and j atoms */
474             qq30             = _mm_mul_pd(iq3,jq0);
475
476             /* COULOMB ELECTROSTATICS */
477             velec            = _mm_mul_pd(qq30,rinv30);
478             felec            = _mm_mul_pd(velec,rinvsq30);
479
480             /* Update potential sum for this i atom from the interaction with this j atom. */
481             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
482             velecsum         = _mm_add_pd(velecsum,velec);
483
484             fscal            = felec;
485
486             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
487
488             /* Update vectorial force */
489             fix3             = _mm_macc_pd(dx30,fscal,fix3);
490             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
491             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
492             
493             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
494             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
495             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
496
497             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
498
499             /* Inner loop uses 131 flops */
500         }
501
502         /* End of innermost loop */
503
504         gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
505                                               f+i_coord_offset,fshift+i_shift_offset);
506
507         ggid                        = gid[iidx];
508         /* Update potential energies */
509         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
510         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
511
512         /* Increment number of inner iterations */
513         inneriter                  += j_index_end - j_index_start;
514
515         /* Outer loop uses 26 flops */
516     }
517
518     /* Increment number of outer iterations */
519     outeriter        += nri;
520
521     /* Update outer/inner flops */
522
523     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*131);
524 }
525 /*
526  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_double
527  * Electrostatics interaction: Coulomb
528  * VdW interaction:            LennardJones
529  * Geometry:                   Water4-Particle
530  * Calculate force/pot:        Force
531  */
532 void
533 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_double
534                     (t_nblist                    * gmx_restrict       nlist,
535                      rvec                        * gmx_restrict          xx,
536                      rvec                        * gmx_restrict          ff,
537                      struct t_forcerec           * gmx_restrict          fr,
538                      t_mdatoms                   * gmx_restrict     mdatoms,
539                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
540                      t_nrnb                      * gmx_restrict        nrnb)
541 {
542     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
543      * just 0 for non-waters.
544      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
545      * jnr indices corresponding to data put in the four positions in the SIMD register.
546      */
547     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
548     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
549     int              jnrA,jnrB;
550     int              j_coord_offsetA,j_coord_offsetB;
551     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
552     real             rcutoff_scalar;
553     real             *shiftvec,*fshift,*x,*f;
554     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
555     int              vdwioffset0;
556     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
557     int              vdwioffset1;
558     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
559     int              vdwioffset2;
560     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
561     int              vdwioffset3;
562     __m128d          ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
563     int              vdwjidx0A,vdwjidx0B;
564     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
565     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
566     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
567     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
568     __m128d          dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
569     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
570     real             *charge;
571     int              nvdwtype;
572     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
573     int              *vdwtype;
574     real             *vdwparam;
575     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
576     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
577     __m128d          dummy_mask,cutoff_mask;
578     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
579     __m128d          one     = _mm_set1_pd(1.0);
580     __m128d          two     = _mm_set1_pd(2.0);
581     x                = xx[0];
582     f                = ff[0];
583
584     nri              = nlist->nri;
585     iinr             = nlist->iinr;
586     jindex           = nlist->jindex;
587     jjnr             = nlist->jjnr;
588     shiftidx         = nlist->shift;
589     gid              = nlist->gid;
590     shiftvec         = fr->shift_vec[0];
591     fshift           = fr->fshift[0];
592     facel            = _mm_set1_pd(fr->ic->epsfac);
593     charge           = mdatoms->chargeA;
594     nvdwtype         = fr->ntype;
595     vdwparam         = fr->nbfp;
596     vdwtype          = mdatoms->typeA;
597
598     /* Setup water-specific parameters */
599     inr              = nlist->iinr[0];
600     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
601     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
602     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
603     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
604
605     /* Avoid stupid compiler warnings */
606     jnrA = jnrB = 0;
607     j_coord_offsetA = 0;
608     j_coord_offsetB = 0;
609
610     outeriter        = 0;
611     inneriter        = 0;
612
613     /* Start outer loop over neighborlists */
614     for(iidx=0; iidx<nri; iidx++)
615     {
616         /* Load shift vector for this list */
617         i_shift_offset   = DIM*shiftidx[iidx];
618
619         /* Load limits for loop over neighbors */
620         j_index_start    = jindex[iidx];
621         j_index_end      = jindex[iidx+1];
622
623         /* Get outer coordinate index */
624         inr              = iinr[iidx];
625         i_coord_offset   = DIM*inr;
626
627         /* Load i particle coords and add shift vector */
628         gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
629                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
630
631         fix0             = _mm_setzero_pd();
632         fiy0             = _mm_setzero_pd();
633         fiz0             = _mm_setzero_pd();
634         fix1             = _mm_setzero_pd();
635         fiy1             = _mm_setzero_pd();
636         fiz1             = _mm_setzero_pd();
637         fix2             = _mm_setzero_pd();
638         fiy2             = _mm_setzero_pd();
639         fiz2             = _mm_setzero_pd();
640         fix3             = _mm_setzero_pd();
641         fiy3             = _mm_setzero_pd();
642         fiz3             = _mm_setzero_pd();
643
644         /* Start inner kernel loop */
645         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
646         {
647
648             /* Get j neighbor index, and coordinate index */
649             jnrA             = jjnr[jidx];
650             jnrB             = jjnr[jidx+1];
651             j_coord_offsetA  = DIM*jnrA;
652             j_coord_offsetB  = DIM*jnrB;
653
654             /* load j atom coordinates */
655             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
656                                               &jx0,&jy0,&jz0);
657
658             /* Calculate displacement vector */
659             dx00             = _mm_sub_pd(ix0,jx0);
660             dy00             = _mm_sub_pd(iy0,jy0);
661             dz00             = _mm_sub_pd(iz0,jz0);
662             dx10             = _mm_sub_pd(ix1,jx0);
663             dy10             = _mm_sub_pd(iy1,jy0);
664             dz10             = _mm_sub_pd(iz1,jz0);
665             dx20             = _mm_sub_pd(ix2,jx0);
666             dy20             = _mm_sub_pd(iy2,jy0);
667             dz20             = _mm_sub_pd(iz2,jz0);
668             dx30             = _mm_sub_pd(ix3,jx0);
669             dy30             = _mm_sub_pd(iy3,jy0);
670             dz30             = _mm_sub_pd(iz3,jz0);
671
672             /* Calculate squared distance and things based on it */
673             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
674             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
675             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
676             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
677
678             rinv10           = avx128fma_invsqrt_d(rsq10);
679             rinv20           = avx128fma_invsqrt_d(rsq20);
680             rinv30           = avx128fma_invsqrt_d(rsq30);
681
682             rinvsq00         = avx128fma_inv_d(rsq00);
683             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
684             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
685             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
686
687             /* Load parameters for j particles */
688             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
689             vdwjidx0A        = 2*vdwtype[jnrA+0];
690             vdwjidx0B        = 2*vdwtype[jnrB+0];
691
692             fjx0             = _mm_setzero_pd();
693             fjy0             = _mm_setzero_pd();
694             fjz0             = _mm_setzero_pd();
695
696             /**************************
697              * CALCULATE INTERACTIONS *
698              **************************/
699
700             /* Compute parameters for interactions between i and j atoms */
701             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
702                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
703
704             /* LENNARD-JONES DISPERSION/REPULSION */
705
706             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
707             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
708
709             fscal            = fvdw;
710
711             /* Update vectorial force */
712             fix0             = _mm_macc_pd(dx00,fscal,fix0);
713             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
714             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
715             
716             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
717             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
718             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
719
720             /**************************
721              * CALCULATE INTERACTIONS *
722              **************************/
723
724             /* Compute parameters for interactions between i and j atoms */
725             qq10             = _mm_mul_pd(iq1,jq0);
726
727             /* COULOMB ELECTROSTATICS */
728             velec            = _mm_mul_pd(qq10,rinv10);
729             felec            = _mm_mul_pd(velec,rinvsq10);
730
731             fscal            = felec;
732
733             /* Update vectorial force */
734             fix1             = _mm_macc_pd(dx10,fscal,fix1);
735             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
736             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
737             
738             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
739             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
740             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
741
742             /**************************
743              * CALCULATE INTERACTIONS *
744              **************************/
745
746             /* Compute parameters for interactions between i and j atoms */
747             qq20             = _mm_mul_pd(iq2,jq0);
748
749             /* COULOMB ELECTROSTATICS */
750             velec            = _mm_mul_pd(qq20,rinv20);
751             felec            = _mm_mul_pd(velec,rinvsq20);
752
753             fscal            = felec;
754
755             /* Update vectorial force */
756             fix2             = _mm_macc_pd(dx20,fscal,fix2);
757             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
758             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
759             
760             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
761             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
762             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
763
764             /**************************
765              * CALCULATE INTERACTIONS *
766              **************************/
767
768             /* Compute parameters for interactions between i and j atoms */
769             qq30             = _mm_mul_pd(iq3,jq0);
770
771             /* COULOMB ELECTROSTATICS */
772             velec            = _mm_mul_pd(qq30,rinv30);
773             felec            = _mm_mul_pd(velec,rinvsq30);
774
775             fscal            = felec;
776
777             /* Update vectorial force */
778             fix3             = _mm_macc_pd(dx30,fscal,fix3);
779             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
780             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
781             
782             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
783             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
784             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
785
786             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
787
788             /* Inner loop uses 123 flops */
789         }
790
791         if(jidx<j_index_end)
792         {
793
794             jnrA             = jjnr[jidx];
795             j_coord_offsetA  = DIM*jnrA;
796
797             /* load j atom coordinates */
798             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
799                                               &jx0,&jy0,&jz0);
800
801             /* Calculate displacement vector */
802             dx00             = _mm_sub_pd(ix0,jx0);
803             dy00             = _mm_sub_pd(iy0,jy0);
804             dz00             = _mm_sub_pd(iz0,jz0);
805             dx10             = _mm_sub_pd(ix1,jx0);
806             dy10             = _mm_sub_pd(iy1,jy0);
807             dz10             = _mm_sub_pd(iz1,jz0);
808             dx20             = _mm_sub_pd(ix2,jx0);
809             dy20             = _mm_sub_pd(iy2,jy0);
810             dz20             = _mm_sub_pd(iz2,jz0);
811             dx30             = _mm_sub_pd(ix3,jx0);
812             dy30             = _mm_sub_pd(iy3,jy0);
813             dz30             = _mm_sub_pd(iz3,jz0);
814
815             /* Calculate squared distance and things based on it */
816             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
817             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
818             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
819             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
820
821             rinv10           = avx128fma_invsqrt_d(rsq10);
822             rinv20           = avx128fma_invsqrt_d(rsq20);
823             rinv30           = avx128fma_invsqrt_d(rsq30);
824
825             rinvsq00         = avx128fma_inv_d(rsq00);
826             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
827             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
828             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
829
830             /* Load parameters for j particles */
831             jq0              = _mm_load_sd(charge+jnrA+0);
832             vdwjidx0A        = 2*vdwtype[jnrA+0];
833
834             fjx0             = _mm_setzero_pd();
835             fjy0             = _mm_setzero_pd();
836             fjz0             = _mm_setzero_pd();
837
838             /**************************
839              * CALCULATE INTERACTIONS *
840              **************************/
841
842             /* Compute parameters for interactions between i and j atoms */
843             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
844
845             /* LENNARD-JONES DISPERSION/REPULSION */
846
847             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
848             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
849
850             fscal            = fvdw;
851
852             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
853
854             /* Update vectorial force */
855             fix0             = _mm_macc_pd(dx00,fscal,fix0);
856             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
857             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
858             
859             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
860             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
861             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
862
863             /**************************
864              * CALCULATE INTERACTIONS *
865              **************************/
866
867             /* Compute parameters for interactions between i and j atoms */
868             qq10             = _mm_mul_pd(iq1,jq0);
869
870             /* COULOMB ELECTROSTATICS */
871             velec            = _mm_mul_pd(qq10,rinv10);
872             felec            = _mm_mul_pd(velec,rinvsq10);
873
874             fscal            = felec;
875
876             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
877
878             /* Update vectorial force */
879             fix1             = _mm_macc_pd(dx10,fscal,fix1);
880             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
881             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
882             
883             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
884             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
885             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
886
887             /**************************
888              * CALCULATE INTERACTIONS *
889              **************************/
890
891             /* Compute parameters for interactions between i and j atoms */
892             qq20             = _mm_mul_pd(iq2,jq0);
893
894             /* COULOMB ELECTROSTATICS */
895             velec            = _mm_mul_pd(qq20,rinv20);
896             felec            = _mm_mul_pd(velec,rinvsq20);
897
898             fscal            = felec;
899
900             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
901
902             /* Update vectorial force */
903             fix2             = _mm_macc_pd(dx20,fscal,fix2);
904             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
905             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
906             
907             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
908             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
909             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
910
911             /**************************
912              * CALCULATE INTERACTIONS *
913              **************************/
914
915             /* Compute parameters for interactions between i and j atoms */
916             qq30             = _mm_mul_pd(iq3,jq0);
917
918             /* COULOMB ELECTROSTATICS */
919             velec            = _mm_mul_pd(qq30,rinv30);
920             felec            = _mm_mul_pd(velec,rinvsq30);
921
922             fscal            = felec;
923
924             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
925
926             /* Update vectorial force */
927             fix3             = _mm_macc_pd(dx30,fscal,fix3);
928             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
929             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
930             
931             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
932             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
933             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
934
935             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
936
937             /* Inner loop uses 123 flops */
938         }
939
940         /* End of innermost loop */
941
942         gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
943                                               f+i_coord_offset,fshift+i_shift_offset);
944
945         /* Increment number of inner iterations */
946         inneriter                  += j_index_end - j_index_start;
947
948         /* Outer loop uses 24 flops */
949     }
950
951     /* Increment number of outer iterations */
952     outeriter        += nri;
953
954     /* Update outer/inner flops */
955
956     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*123);
957 }