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