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