Introduce gmxpre.h for truly global definitions
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRFCut_VdwNone_GeomP1P1_avx_128_fma_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS avx_128_fma_double kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_double
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            None
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_double
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70      * just 0 for non-waters.
71      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB;
77     int              j_coord_offsetA,j_coord_offsetB;
78     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
79     real             rcutoff_scalar;
80     real             *shiftvec,*fshift,*x,*f;
81     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82     int              vdwioffset0;
83     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwjidx0A,vdwjidx0B;
85     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
88     real             *charge;
89     __m128d          dummy_mask,cutoff_mask;
90     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
91     __m128d          one     = _mm_set1_pd(1.0);
92     __m128d          two     = _mm_set1_pd(2.0);
93     x                = xx[0];
94     f                = ff[0];
95
96     nri              = nlist->nri;
97     iinr             = nlist->iinr;
98     jindex           = nlist->jindex;
99     jjnr             = nlist->jjnr;
100     shiftidx         = nlist->shift;
101     gid              = nlist->gid;
102     shiftvec         = fr->shift_vec[0];
103     fshift           = fr->fshift[0];
104     facel            = _mm_set1_pd(fr->epsfac);
105     charge           = mdatoms->chargeA;
106     krf              = _mm_set1_pd(fr->ic->k_rf);
107     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
108     crf              = _mm_set1_pd(fr->ic->c_rf);
109
110     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
111     rcutoff_scalar   = fr->rcoulomb;
112     rcutoff          = _mm_set1_pd(rcutoff_scalar);
113     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
114
115     /* Avoid stupid compiler warnings */
116     jnrA = jnrB = 0;
117     j_coord_offsetA = 0;
118     j_coord_offsetB = 0;
119
120     outeriter        = 0;
121     inneriter        = 0;
122
123     /* Start outer loop over neighborlists */
124     for(iidx=0; iidx<nri; iidx++)
125     {
126         /* Load shift vector for this list */
127         i_shift_offset   = DIM*shiftidx[iidx];
128
129         /* Load limits for loop over neighbors */
130         j_index_start    = jindex[iidx];
131         j_index_end      = jindex[iidx+1];
132
133         /* Get outer coordinate index */
134         inr              = iinr[iidx];
135         i_coord_offset   = DIM*inr;
136
137         /* Load i particle coords and add shift vector */
138         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
139
140         fix0             = _mm_setzero_pd();
141         fiy0             = _mm_setzero_pd();
142         fiz0             = _mm_setzero_pd();
143
144         /* Load parameters for i particles */
145         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
146
147         /* Reset potential sums */
148         velecsum         = _mm_setzero_pd();
149
150         /* Start inner kernel loop */
151         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
152         {
153
154             /* Get j neighbor index, and coordinate index */
155             jnrA             = jjnr[jidx];
156             jnrB             = jjnr[jidx+1];
157             j_coord_offsetA  = DIM*jnrA;
158             j_coord_offsetB  = DIM*jnrB;
159
160             /* load j atom coordinates */
161             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
162                                               &jx0,&jy0,&jz0);
163
164             /* Calculate displacement vector */
165             dx00             = _mm_sub_pd(ix0,jx0);
166             dy00             = _mm_sub_pd(iy0,jy0);
167             dz00             = _mm_sub_pd(iz0,jz0);
168
169             /* Calculate squared distance and things based on it */
170             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
171
172             rinv00           = gmx_mm_invsqrt_pd(rsq00);
173
174             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
175
176             /* Load parameters for j particles */
177             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
178
179             /**************************
180              * CALCULATE INTERACTIONS *
181              **************************/
182
183             if (gmx_mm_any_lt(rsq00,rcutoff2))
184             {
185
186             /* Compute parameters for interactions between i and j atoms */
187             qq00             = _mm_mul_pd(iq0,jq0);
188
189             /* REACTION-FIELD ELECTROSTATICS */
190             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
191             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
192
193             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
194
195             /* Update potential sum for this i atom from the interaction with this j atom. */
196             velec            = _mm_and_pd(velec,cutoff_mask);
197             velecsum         = _mm_add_pd(velecsum,velec);
198
199             fscal            = felec;
200
201             fscal            = _mm_and_pd(fscal,cutoff_mask);
202
203             /* Update vectorial force */
204             fix0             = _mm_macc_pd(dx00,fscal,fix0);
205             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
206             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
207             
208             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
209                                                    _mm_mul_pd(dx00,fscal),
210                                                    _mm_mul_pd(dy00,fscal),
211                                                    _mm_mul_pd(dz00,fscal));
212
213             }
214
215             /* Inner loop uses 39 flops */
216         }
217
218         if(jidx<j_index_end)
219         {
220
221             jnrA             = jjnr[jidx];
222             j_coord_offsetA  = DIM*jnrA;
223
224             /* load j atom coordinates */
225             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
226                                               &jx0,&jy0,&jz0);
227
228             /* Calculate displacement vector */
229             dx00             = _mm_sub_pd(ix0,jx0);
230             dy00             = _mm_sub_pd(iy0,jy0);
231             dz00             = _mm_sub_pd(iz0,jz0);
232
233             /* Calculate squared distance and things based on it */
234             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
235
236             rinv00           = gmx_mm_invsqrt_pd(rsq00);
237
238             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
239
240             /* Load parameters for j particles */
241             jq0              = _mm_load_sd(charge+jnrA+0);
242
243             /**************************
244              * CALCULATE INTERACTIONS *
245              **************************/
246
247             if (gmx_mm_any_lt(rsq00,rcutoff2))
248             {
249
250             /* Compute parameters for interactions between i and j atoms */
251             qq00             = _mm_mul_pd(iq0,jq0);
252
253             /* REACTION-FIELD ELECTROSTATICS */
254             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
255             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
256
257             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
258
259             /* Update potential sum for this i atom from the interaction with this j atom. */
260             velec            = _mm_and_pd(velec,cutoff_mask);
261             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
262             velecsum         = _mm_add_pd(velecsum,velec);
263
264             fscal            = felec;
265
266             fscal            = _mm_and_pd(fscal,cutoff_mask);
267
268             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
269
270             /* Update vectorial force */
271             fix0             = _mm_macc_pd(dx00,fscal,fix0);
272             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
273             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
274             
275             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
276                                                    _mm_mul_pd(dx00,fscal),
277                                                    _mm_mul_pd(dy00,fscal),
278                                                    _mm_mul_pd(dz00,fscal));
279
280             }
281
282             /* Inner loop uses 39 flops */
283         }
284
285         /* End of innermost loop */
286
287         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
288                                               f+i_coord_offset,fshift+i_shift_offset);
289
290         ggid                        = gid[iidx];
291         /* Update potential energies */
292         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
293
294         /* Increment number of inner iterations */
295         inneriter                  += j_index_end - j_index_start;
296
297         /* Outer loop uses 8 flops */
298     }
299
300     /* Increment number of outer iterations */
301     outeriter        += nri;
302
303     /* Update outer/inner flops */
304
305     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*39);
306 }
307 /*
308  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
309  * Electrostatics interaction: ReactionField
310  * VdW interaction:            None
311  * Geometry:                   Particle-Particle
312  * Calculate force/pot:        Force
313  */
314 void
315 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
316                     (t_nblist                    * gmx_restrict       nlist,
317                      rvec                        * gmx_restrict          xx,
318                      rvec                        * gmx_restrict          ff,
319                      t_forcerec                  * gmx_restrict          fr,
320                      t_mdatoms                   * gmx_restrict     mdatoms,
321                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
322                      t_nrnb                      * gmx_restrict        nrnb)
323 {
324     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
325      * just 0 for non-waters.
326      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
327      * jnr indices corresponding to data put in the four positions in the SIMD register.
328      */
329     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
330     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
331     int              jnrA,jnrB;
332     int              j_coord_offsetA,j_coord_offsetB;
333     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
334     real             rcutoff_scalar;
335     real             *shiftvec,*fshift,*x,*f;
336     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
337     int              vdwioffset0;
338     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
339     int              vdwjidx0A,vdwjidx0B;
340     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
341     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
342     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
343     real             *charge;
344     __m128d          dummy_mask,cutoff_mask;
345     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
346     __m128d          one     = _mm_set1_pd(1.0);
347     __m128d          two     = _mm_set1_pd(2.0);
348     x                = xx[0];
349     f                = ff[0];
350
351     nri              = nlist->nri;
352     iinr             = nlist->iinr;
353     jindex           = nlist->jindex;
354     jjnr             = nlist->jjnr;
355     shiftidx         = nlist->shift;
356     gid              = nlist->gid;
357     shiftvec         = fr->shift_vec[0];
358     fshift           = fr->fshift[0];
359     facel            = _mm_set1_pd(fr->epsfac);
360     charge           = mdatoms->chargeA;
361     krf              = _mm_set1_pd(fr->ic->k_rf);
362     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
363     crf              = _mm_set1_pd(fr->ic->c_rf);
364
365     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
366     rcutoff_scalar   = fr->rcoulomb;
367     rcutoff          = _mm_set1_pd(rcutoff_scalar);
368     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
369
370     /* Avoid stupid compiler warnings */
371     jnrA = jnrB = 0;
372     j_coord_offsetA = 0;
373     j_coord_offsetB = 0;
374
375     outeriter        = 0;
376     inneriter        = 0;
377
378     /* Start outer loop over neighborlists */
379     for(iidx=0; iidx<nri; iidx++)
380     {
381         /* Load shift vector for this list */
382         i_shift_offset   = DIM*shiftidx[iidx];
383
384         /* Load limits for loop over neighbors */
385         j_index_start    = jindex[iidx];
386         j_index_end      = jindex[iidx+1];
387
388         /* Get outer coordinate index */
389         inr              = iinr[iidx];
390         i_coord_offset   = DIM*inr;
391
392         /* Load i particle coords and add shift vector */
393         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
394
395         fix0             = _mm_setzero_pd();
396         fiy0             = _mm_setzero_pd();
397         fiz0             = _mm_setzero_pd();
398
399         /* Load parameters for i particles */
400         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
401
402         /* Start inner kernel loop */
403         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
404         {
405
406             /* Get j neighbor index, and coordinate index */
407             jnrA             = jjnr[jidx];
408             jnrB             = jjnr[jidx+1];
409             j_coord_offsetA  = DIM*jnrA;
410             j_coord_offsetB  = DIM*jnrB;
411
412             /* load j atom coordinates */
413             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
414                                               &jx0,&jy0,&jz0);
415
416             /* Calculate displacement vector */
417             dx00             = _mm_sub_pd(ix0,jx0);
418             dy00             = _mm_sub_pd(iy0,jy0);
419             dz00             = _mm_sub_pd(iz0,jz0);
420
421             /* Calculate squared distance and things based on it */
422             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
423
424             rinv00           = gmx_mm_invsqrt_pd(rsq00);
425
426             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
427
428             /* Load parameters for j particles */
429             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
430
431             /**************************
432              * CALCULATE INTERACTIONS *
433              **************************/
434
435             if (gmx_mm_any_lt(rsq00,rcutoff2))
436             {
437
438             /* Compute parameters for interactions between i and j atoms */
439             qq00             = _mm_mul_pd(iq0,jq0);
440
441             /* REACTION-FIELD ELECTROSTATICS */
442             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
443
444             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
445
446             fscal            = felec;
447
448             fscal            = _mm_and_pd(fscal,cutoff_mask);
449
450             /* Update vectorial force */
451             fix0             = _mm_macc_pd(dx00,fscal,fix0);
452             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
453             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
454             
455             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
456                                                    _mm_mul_pd(dx00,fscal),
457                                                    _mm_mul_pd(dy00,fscal),
458                                                    _mm_mul_pd(dz00,fscal));
459
460             }
461
462             /* Inner loop uses 33 flops */
463         }
464
465         if(jidx<j_index_end)
466         {
467
468             jnrA             = jjnr[jidx];
469             j_coord_offsetA  = DIM*jnrA;
470
471             /* load j atom coordinates */
472             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
473                                               &jx0,&jy0,&jz0);
474
475             /* Calculate displacement vector */
476             dx00             = _mm_sub_pd(ix0,jx0);
477             dy00             = _mm_sub_pd(iy0,jy0);
478             dz00             = _mm_sub_pd(iz0,jz0);
479
480             /* Calculate squared distance and things based on it */
481             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
482
483             rinv00           = gmx_mm_invsqrt_pd(rsq00);
484
485             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
486
487             /* Load parameters for j particles */
488             jq0              = _mm_load_sd(charge+jnrA+0);
489
490             /**************************
491              * CALCULATE INTERACTIONS *
492              **************************/
493
494             if (gmx_mm_any_lt(rsq00,rcutoff2))
495             {
496
497             /* Compute parameters for interactions between i and j atoms */
498             qq00             = _mm_mul_pd(iq0,jq0);
499
500             /* REACTION-FIELD ELECTROSTATICS */
501             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
502
503             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
504
505             fscal            = felec;
506
507             fscal            = _mm_and_pd(fscal,cutoff_mask);
508
509             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
510
511             /* Update vectorial force */
512             fix0             = _mm_macc_pd(dx00,fscal,fix0);
513             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
514             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
515             
516             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
517                                                    _mm_mul_pd(dx00,fscal),
518                                                    _mm_mul_pd(dy00,fscal),
519                                                    _mm_mul_pd(dz00,fscal));
520
521             }
522
523             /* Inner loop uses 33 flops */
524         }
525
526         /* End of innermost loop */
527
528         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
529                                               f+i_coord_offset,fshift+i_shift_offset);
530
531         /* Increment number of inner iterations */
532         inneriter                  += j_index_end - j_index_start;
533
534         /* Outer loop uses 7 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_F,outeriter*7 + inneriter*33);
543 }