Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRF_VdwLJ_GeomW3P1_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 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/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_ElecRF_VdwLJ_GeomW3P1_VF_avx_128_fma_double
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            LennardJones
56  * Geometry:                   Water3-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRF_VdwLJ_GeomW3P1_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              vdwjidx0A,vdwjidx0B;
89     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
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->epsfac);
117     charge           = mdatoms->chargeA;
118     krf              = _mm_set1_pd(fr->ic->k_rf);
119     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
120     crf              = _mm_set1_pd(fr->ic->c_rf);
121     nvdwtype         = fr->ntype;
122     vdwparam         = fr->nbfp;
123     vdwtype          = mdatoms->typeA;
124
125     /* Setup water-specific parameters */
126     inr              = nlist->iinr[0];
127     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
128     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
129     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
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_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
156                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
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
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
197             /* Calculate squared distance and things based on it */
198             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
199             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
200             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
201
202             rinv00           = gmx_mm_invsqrt_pd(rsq00);
203             rinv10           = gmx_mm_invsqrt_pd(rsq10);
204             rinv20           = gmx_mm_invsqrt_pd(rsq20);
205
206             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
207             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
208             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
209
210             /* Load parameters for j particles */
211             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
212             vdwjidx0A        = 2*vdwtype[jnrA+0];
213             vdwjidx0B        = 2*vdwtype[jnrB+0];
214
215             fjx0             = _mm_setzero_pd();
216             fjy0             = _mm_setzero_pd();
217             fjz0             = _mm_setzero_pd();
218
219             /**************************
220              * CALCULATE INTERACTIONS *
221              **************************/
222
223             /* Compute parameters for interactions between i and j atoms */
224             qq00             = _mm_mul_pd(iq0,jq0);
225             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
226                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
227
228             /* REACTION-FIELD ELECTROSTATICS */
229             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
230             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
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             velecsum         = _mm_add_pd(velecsum,velec);
242             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
243
244             fscal            = _mm_add_pd(felec,fvdw);
245
246             /* Update vectorial force */
247             fix0             = _mm_macc_pd(dx00,fscal,fix0);
248             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
249             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
250             
251             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
252             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
253             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
254
255             /**************************
256              * CALCULATE INTERACTIONS *
257              **************************/
258
259             /* Compute parameters for interactions between i and j atoms */
260             qq10             = _mm_mul_pd(iq1,jq0);
261
262             /* REACTION-FIELD ELECTROSTATICS */
263             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
264             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
265
266             /* Update potential sum for this i atom from the interaction with this j atom. */
267             velecsum         = _mm_add_pd(velecsum,velec);
268
269             fscal            = felec;
270
271             /* Update vectorial force */
272             fix1             = _mm_macc_pd(dx10,fscal,fix1);
273             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
274             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
275             
276             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
277             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
278             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
279
280             /**************************
281              * CALCULATE INTERACTIONS *
282              **************************/
283
284             /* Compute parameters for interactions between i and j atoms */
285             qq20             = _mm_mul_pd(iq2,jq0);
286
287             /* REACTION-FIELD ELECTROSTATICS */
288             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
289             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
290
291             /* Update potential sum for this i atom from the interaction with this j atom. */
292             velecsum         = _mm_add_pd(velecsum,velec);
293
294             fscal            = felec;
295
296             /* Update vectorial force */
297             fix2             = _mm_macc_pd(dx20,fscal,fix2);
298             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
299             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
300             
301             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
302             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
303             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
304
305             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
306
307             /* Inner loop uses 120 flops */
308         }
309
310         if(jidx<j_index_end)
311         {
312
313             jnrA             = jjnr[jidx];
314             j_coord_offsetA  = DIM*jnrA;
315
316             /* load j atom coordinates */
317             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
318                                               &jx0,&jy0,&jz0);
319
320             /* Calculate displacement vector */
321             dx00             = _mm_sub_pd(ix0,jx0);
322             dy00             = _mm_sub_pd(iy0,jy0);
323             dz00             = _mm_sub_pd(iz0,jz0);
324             dx10             = _mm_sub_pd(ix1,jx0);
325             dy10             = _mm_sub_pd(iy1,jy0);
326             dz10             = _mm_sub_pd(iz1,jz0);
327             dx20             = _mm_sub_pd(ix2,jx0);
328             dy20             = _mm_sub_pd(iy2,jy0);
329             dz20             = _mm_sub_pd(iz2,jz0);
330
331             /* Calculate squared distance and things based on it */
332             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
333             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
334             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
335
336             rinv00           = gmx_mm_invsqrt_pd(rsq00);
337             rinv10           = gmx_mm_invsqrt_pd(rsq10);
338             rinv20           = gmx_mm_invsqrt_pd(rsq20);
339
340             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
341             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
342             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
343
344             /* Load parameters for j particles */
345             jq0              = _mm_load_sd(charge+jnrA+0);
346             vdwjidx0A        = 2*vdwtype[jnrA+0];
347
348             fjx0             = _mm_setzero_pd();
349             fjy0             = _mm_setzero_pd();
350             fjz0             = _mm_setzero_pd();
351
352             /**************************
353              * CALCULATE INTERACTIONS *
354              **************************/
355
356             /* Compute parameters for interactions between i and j atoms */
357             qq00             = _mm_mul_pd(iq0,jq0);
358             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
359
360             /* REACTION-FIELD ELECTROSTATICS */
361             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
362             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
363
364             /* LENNARD-JONES DISPERSION/REPULSION */
365
366             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
367             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
368             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
369             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
370             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
371
372             /* Update potential sum for this i atom from the interaction with this j atom. */
373             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
374             velecsum         = _mm_add_pd(velecsum,velec);
375             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
376             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
377
378             fscal            = _mm_add_pd(felec,fvdw);
379
380             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
381
382             /* Update vectorial force */
383             fix0             = _mm_macc_pd(dx00,fscal,fix0);
384             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
385             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
386             
387             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
388             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
389             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
390
391             /**************************
392              * CALCULATE INTERACTIONS *
393              **************************/
394
395             /* Compute parameters for interactions between i and j atoms */
396             qq10             = _mm_mul_pd(iq1,jq0);
397
398             /* REACTION-FIELD ELECTROSTATICS */
399             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
400             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
401
402             /* Update potential sum for this i atom from the interaction with this j atom. */
403             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
404             velecsum         = _mm_add_pd(velecsum,velec);
405
406             fscal            = felec;
407
408             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
409
410             /* Update vectorial force */
411             fix1             = _mm_macc_pd(dx10,fscal,fix1);
412             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
413             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
414             
415             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
416             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
417             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
418
419             /**************************
420              * CALCULATE INTERACTIONS *
421              **************************/
422
423             /* Compute parameters for interactions between i and j atoms */
424             qq20             = _mm_mul_pd(iq2,jq0);
425
426             /* REACTION-FIELD ELECTROSTATICS */
427             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
428             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
429
430             /* Update potential sum for this i atom from the interaction with this j atom. */
431             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
432             velecsum         = _mm_add_pd(velecsum,velec);
433
434             fscal            = felec;
435
436             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
437
438             /* Update vectorial force */
439             fix2             = _mm_macc_pd(dx20,fscal,fix2);
440             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
441             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
442             
443             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
444             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
445             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
446
447             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
448
449             /* Inner loop uses 120 flops */
450         }
451
452         /* End of innermost loop */
453
454         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
455                                               f+i_coord_offset,fshift+i_shift_offset);
456
457         ggid                        = gid[iidx];
458         /* Update potential energies */
459         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
460         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
461
462         /* Increment number of inner iterations */
463         inneriter                  += j_index_end - j_index_start;
464
465         /* Outer loop uses 20 flops */
466     }
467
468     /* Increment number of outer iterations */
469     outeriter        += nri;
470
471     /* Update outer/inner flops */
472
473     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*120);
474 }
475 /*
476  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_double
477  * Electrostatics interaction: ReactionField
478  * VdW interaction:            LennardJones
479  * Geometry:                   Water3-Particle
480  * Calculate force/pot:        Force
481  */
482 void
483 nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_double
484                     (t_nblist                    * gmx_restrict       nlist,
485                      rvec                        * gmx_restrict          xx,
486                      rvec                        * gmx_restrict          ff,
487                      t_forcerec                  * gmx_restrict          fr,
488                      t_mdatoms                   * gmx_restrict     mdatoms,
489                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
490                      t_nrnb                      * gmx_restrict        nrnb)
491 {
492     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
493      * just 0 for non-waters.
494      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
495      * jnr indices corresponding to data put in the four positions in the SIMD register.
496      */
497     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
498     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
499     int              jnrA,jnrB;
500     int              j_coord_offsetA,j_coord_offsetB;
501     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
502     real             rcutoff_scalar;
503     real             *shiftvec,*fshift,*x,*f;
504     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
505     int              vdwioffset0;
506     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
507     int              vdwioffset1;
508     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
509     int              vdwioffset2;
510     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
511     int              vdwjidx0A,vdwjidx0B;
512     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
513     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
514     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
515     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
516     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
517     real             *charge;
518     int              nvdwtype;
519     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
520     int              *vdwtype;
521     real             *vdwparam;
522     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
523     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
524     __m128d          dummy_mask,cutoff_mask;
525     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
526     __m128d          one     = _mm_set1_pd(1.0);
527     __m128d          two     = _mm_set1_pd(2.0);
528     x                = xx[0];
529     f                = ff[0];
530
531     nri              = nlist->nri;
532     iinr             = nlist->iinr;
533     jindex           = nlist->jindex;
534     jjnr             = nlist->jjnr;
535     shiftidx         = nlist->shift;
536     gid              = nlist->gid;
537     shiftvec         = fr->shift_vec[0];
538     fshift           = fr->fshift[0];
539     facel            = _mm_set1_pd(fr->epsfac);
540     charge           = mdatoms->chargeA;
541     krf              = _mm_set1_pd(fr->ic->k_rf);
542     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
543     crf              = _mm_set1_pd(fr->ic->c_rf);
544     nvdwtype         = fr->ntype;
545     vdwparam         = fr->nbfp;
546     vdwtype          = mdatoms->typeA;
547
548     /* Setup water-specific parameters */
549     inr              = nlist->iinr[0];
550     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
551     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
552     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
553     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
554
555     /* Avoid stupid compiler warnings */
556     jnrA = jnrB = 0;
557     j_coord_offsetA = 0;
558     j_coord_offsetB = 0;
559
560     outeriter        = 0;
561     inneriter        = 0;
562
563     /* Start outer loop over neighborlists */
564     for(iidx=0; iidx<nri; iidx++)
565     {
566         /* Load shift vector for this list */
567         i_shift_offset   = DIM*shiftidx[iidx];
568
569         /* Load limits for loop over neighbors */
570         j_index_start    = jindex[iidx];
571         j_index_end      = jindex[iidx+1];
572
573         /* Get outer coordinate index */
574         inr              = iinr[iidx];
575         i_coord_offset   = DIM*inr;
576
577         /* Load i particle coords and add shift vector */
578         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
579                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
580
581         fix0             = _mm_setzero_pd();
582         fiy0             = _mm_setzero_pd();
583         fiz0             = _mm_setzero_pd();
584         fix1             = _mm_setzero_pd();
585         fiy1             = _mm_setzero_pd();
586         fiz1             = _mm_setzero_pd();
587         fix2             = _mm_setzero_pd();
588         fiy2             = _mm_setzero_pd();
589         fiz2             = _mm_setzero_pd();
590
591         /* Start inner kernel loop */
592         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
593         {
594
595             /* Get j neighbor index, and coordinate index */
596             jnrA             = jjnr[jidx];
597             jnrB             = jjnr[jidx+1];
598             j_coord_offsetA  = DIM*jnrA;
599             j_coord_offsetB  = DIM*jnrB;
600
601             /* load j atom coordinates */
602             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
603                                               &jx0,&jy0,&jz0);
604
605             /* Calculate displacement vector */
606             dx00             = _mm_sub_pd(ix0,jx0);
607             dy00             = _mm_sub_pd(iy0,jy0);
608             dz00             = _mm_sub_pd(iz0,jz0);
609             dx10             = _mm_sub_pd(ix1,jx0);
610             dy10             = _mm_sub_pd(iy1,jy0);
611             dz10             = _mm_sub_pd(iz1,jz0);
612             dx20             = _mm_sub_pd(ix2,jx0);
613             dy20             = _mm_sub_pd(iy2,jy0);
614             dz20             = _mm_sub_pd(iz2,jz0);
615
616             /* Calculate squared distance and things based on it */
617             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
618             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
619             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
620
621             rinv00           = gmx_mm_invsqrt_pd(rsq00);
622             rinv10           = gmx_mm_invsqrt_pd(rsq10);
623             rinv20           = gmx_mm_invsqrt_pd(rsq20);
624
625             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
626             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
627             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
628
629             /* Load parameters for j particles */
630             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
631             vdwjidx0A        = 2*vdwtype[jnrA+0];
632             vdwjidx0B        = 2*vdwtype[jnrB+0];
633
634             fjx0             = _mm_setzero_pd();
635             fjy0             = _mm_setzero_pd();
636             fjz0             = _mm_setzero_pd();
637
638             /**************************
639              * CALCULATE INTERACTIONS *
640              **************************/
641
642             /* Compute parameters for interactions between i and j atoms */
643             qq00             = _mm_mul_pd(iq0,jq0);
644             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
645                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
646
647             /* REACTION-FIELD ELECTROSTATICS */
648             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
649
650             /* LENNARD-JONES DISPERSION/REPULSION */
651
652             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
653             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
654
655             fscal            = _mm_add_pd(felec,fvdw);
656
657             /* Update vectorial force */
658             fix0             = _mm_macc_pd(dx00,fscal,fix0);
659             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
660             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
661             
662             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
663             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
664             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
665
666             /**************************
667              * CALCULATE INTERACTIONS *
668              **************************/
669
670             /* Compute parameters for interactions between i and j atoms */
671             qq10             = _mm_mul_pd(iq1,jq0);
672
673             /* REACTION-FIELD ELECTROSTATICS */
674             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
675
676             fscal            = felec;
677
678             /* Update vectorial force */
679             fix1             = _mm_macc_pd(dx10,fscal,fix1);
680             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
681             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
682             
683             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
684             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
685             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
686
687             /**************************
688              * CALCULATE INTERACTIONS *
689              **************************/
690
691             /* Compute parameters for interactions between i and j atoms */
692             qq20             = _mm_mul_pd(iq2,jq0);
693
694             /* REACTION-FIELD ELECTROSTATICS */
695             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
696
697             fscal            = felec;
698
699             /* Update vectorial force */
700             fix2             = _mm_macc_pd(dx20,fscal,fix2);
701             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
702             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
703             
704             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
705             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
706             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
707
708             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
709
710             /* Inner loop uses 100 flops */
711         }
712
713         if(jidx<j_index_end)
714         {
715
716             jnrA             = jjnr[jidx];
717             j_coord_offsetA  = DIM*jnrA;
718
719             /* load j atom coordinates */
720             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
721                                               &jx0,&jy0,&jz0);
722
723             /* Calculate displacement vector */
724             dx00             = _mm_sub_pd(ix0,jx0);
725             dy00             = _mm_sub_pd(iy0,jy0);
726             dz00             = _mm_sub_pd(iz0,jz0);
727             dx10             = _mm_sub_pd(ix1,jx0);
728             dy10             = _mm_sub_pd(iy1,jy0);
729             dz10             = _mm_sub_pd(iz1,jz0);
730             dx20             = _mm_sub_pd(ix2,jx0);
731             dy20             = _mm_sub_pd(iy2,jy0);
732             dz20             = _mm_sub_pd(iz2,jz0);
733
734             /* Calculate squared distance and things based on it */
735             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
736             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
737             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
738
739             rinv00           = gmx_mm_invsqrt_pd(rsq00);
740             rinv10           = gmx_mm_invsqrt_pd(rsq10);
741             rinv20           = gmx_mm_invsqrt_pd(rsq20);
742
743             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
744             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
745             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
746
747             /* Load parameters for j particles */
748             jq0              = _mm_load_sd(charge+jnrA+0);
749             vdwjidx0A        = 2*vdwtype[jnrA+0];
750
751             fjx0             = _mm_setzero_pd();
752             fjy0             = _mm_setzero_pd();
753             fjz0             = _mm_setzero_pd();
754
755             /**************************
756              * CALCULATE INTERACTIONS *
757              **************************/
758
759             /* Compute parameters for interactions between i and j atoms */
760             qq00             = _mm_mul_pd(iq0,jq0);
761             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
762
763             /* REACTION-FIELD ELECTROSTATICS */
764             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
765
766             /* LENNARD-JONES DISPERSION/REPULSION */
767
768             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
769             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
770
771             fscal            = _mm_add_pd(felec,fvdw);
772
773             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
774
775             /* Update vectorial force */
776             fix0             = _mm_macc_pd(dx00,fscal,fix0);
777             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
778             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
779             
780             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
781             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
782             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
783
784             /**************************
785              * CALCULATE INTERACTIONS *
786              **************************/
787
788             /* Compute parameters for interactions between i and j atoms */
789             qq10             = _mm_mul_pd(iq1,jq0);
790
791             /* REACTION-FIELD ELECTROSTATICS */
792             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
793
794             fscal            = felec;
795
796             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
797
798             /* Update vectorial force */
799             fix1             = _mm_macc_pd(dx10,fscal,fix1);
800             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
801             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
802             
803             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
804             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
805             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
806
807             /**************************
808              * CALCULATE INTERACTIONS *
809              **************************/
810
811             /* Compute parameters for interactions between i and j atoms */
812             qq20             = _mm_mul_pd(iq2,jq0);
813
814             /* REACTION-FIELD ELECTROSTATICS */
815             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
816
817             fscal            = felec;
818
819             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
820
821             /* Update vectorial force */
822             fix2             = _mm_macc_pd(dx20,fscal,fix2);
823             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
824             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
825             
826             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
827             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
828             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
829
830             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
831
832             /* Inner loop uses 100 flops */
833         }
834
835         /* End of innermost loop */
836
837         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
838                                               f+i_coord_offset,fshift+i_shift_offset);
839
840         /* Increment number of inner iterations */
841         inneriter                  += j_index_end - j_index_start;
842
843         /* Outer loop uses 18 flops */
844     }
845
846     /* Increment number of outer iterations */
847     outeriter        += nri;
848
849     /* Update outer/inner flops */
850
851     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*100);
852 }