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