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