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