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