Use full path for legacyheaders
[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 "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_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_double
52  * Electrostatics interaction: ReactionField
53  * VdW interaction:            None
54  * Geometry:                   Particle-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
75     int              j_coord_offsetA,j_coord_offsetB;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80     int              vdwioffset0;
81     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82     int              vdwjidx0A,vdwjidx0B;
83     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
85     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
86     real             *charge;
87     __m128d          dummy_mask,cutoff_mask;
88     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
89     __m128d          one     = _mm_set1_pd(1.0);
90     __m128d          two     = _mm_set1_pd(2.0);
91     x                = xx[0];
92     f                = ff[0];
93
94     nri              = nlist->nri;
95     iinr             = nlist->iinr;
96     jindex           = nlist->jindex;
97     jjnr             = nlist->jjnr;
98     shiftidx         = nlist->shift;
99     gid              = nlist->gid;
100     shiftvec         = fr->shift_vec[0];
101     fshift           = fr->fshift[0];
102     facel            = _mm_set1_pd(fr->epsfac);
103     charge           = mdatoms->chargeA;
104     krf              = _mm_set1_pd(fr->ic->k_rf);
105     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
106     crf              = _mm_set1_pd(fr->ic->c_rf);
107
108     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
109     rcutoff_scalar   = fr->rcoulomb;
110     rcutoff          = _mm_set1_pd(rcutoff_scalar);
111     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
112
113     /* Avoid stupid compiler warnings */
114     jnrA = jnrB = 0;
115     j_coord_offsetA = 0;
116     j_coord_offsetB = 0;
117
118     outeriter        = 0;
119     inneriter        = 0;
120
121     /* Start outer loop over neighborlists */
122     for(iidx=0; iidx<nri; iidx++)
123     {
124         /* Load shift vector for this list */
125         i_shift_offset   = DIM*shiftidx[iidx];
126
127         /* Load limits for loop over neighbors */
128         j_index_start    = jindex[iidx];
129         j_index_end      = jindex[iidx+1];
130
131         /* Get outer coordinate index */
132         inr              = iinr[iidx];
133         i_coord_offset   = DIM*inr;
134
135         /* Load i particle coords and add shift vector */
136         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
137
138         fix0             = _mm_setzero_pd();
139         fiy0             = _mm_setzero_pd();
140         fiz0             = _mm_setzero_pd();
141
142         /* Load parameters for i particles */
143         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
144
145         /* Reset potential sums */
146         velecsum         = _mm_setzero_pd();
147
148         /* Start inner kernel loop */
149         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
150         {
151
152             /* Get j neighbor index, and coordinate index */
153             jnrA             = jjnr[jidx];
154             jnrB             = jjnr[jidx+1];
155             j_coord_offsetA  = DIM*jnrA;
156             j_coord_offsetB  = DIM*jnrB;
157
158             /* load j atom coordinates */
159             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
160                                               &jx0,&jy0,&jz0);
161
162             /* Calculate displacement vector */
163             dx00             = _mm_sub_pd(ix0,jx0);
164             dy00             = _mm_sub_pd(iy0,jy0);
165             dz00             = _mm_sub_pd(iz0,jz0);
166
167             /* Calculate squared distance and things based on it */
168             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
169
170             rinv00           = gmx_mm_invsqrt_pd(rsq00);
171
172             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
173
174             /* Load parameters for j particles */
175             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
176
177             /**************************
178              * CALCULATE INTERACTIONS *
179              **************************/
180
181             if (gmx_mm_any_lt(rsq00,rcutoff2))
182             {
183
184             /* Compute parameters for interactions between i and j atoms */
185             qq00             = _mm_mul_pd(iq0,jq0);
186
187             /* REACTION-FIELD ELECTROSTATICS */
188             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
189             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
190
191             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
192
193             /* Update potential sum for this i atom from the interaction with this j atom. */
194             velec            = _mm_and_pd(velec,cutoff_mask);
195             velecsum         = _mm_add_pd(velecsum,velec);
196
197             fscal            = felec;
198
199             fscal            = _mm_and_pd(fscal,cutoff_mask);
200
201             /* Update vectorial force */
202             fix0             = _mm_macc_pd(dx00,fscal,fix0);
203             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
204             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
205             
206             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
207                                                    _mm_mul_pd(dx00,fscal),
208                                                    _mm_mul_pd(dy00,fscal),
209                                                    _mm_mul_pd(dz00,fscal));
210
211             }
212
213             /* Inner loop uses 39 flops */
214         }
215
216         if(jidx<j_index_end)
217         {
218
219             jnrA             = jjnr[jidx];
220             j_coord_offsetA  = DIM*jnrA;
221
222             /* load j atom coordinates */
223             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
224                                               &jx0,&jy0,&jz0);
225
226             /* Calculate displacement vector */
227             dx00             = _mm_sub_pd(ix0,jx0);
228             dy00             = _mm_sub_pd(iy0,jy0);
229             dz00             = _mm_sub_pd(iz0,jz0);
230
231             /* Calculate squared distance and things based on it */
232             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
233
234             rinv00           = gmx_mm_invsqrt_pd(rsq00);
235
236             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
237
238             /* Load parameters for j particles */
239             jq0              = _mm_load_sd(charge+jnrA+0);
240
241             /**************************
242              * CALCULATE INTERACTIONS *
243              **************************/
244
245             if (gmx_mm_any_lt(rsq00,rcutoff2))
246             {
247
248             /* Compute parameters for interactions between i and j atoms */
249             qq00             = _mm_mul_pd(iq0,jq0);
250
251             /* REACTION-FIELD ELECTROSTATICS */
252             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
253             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
254
255             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
256
257             /* Update potential sum for this i atom from the interaction with this j atom. */
258             velec            = _mm_and_pd(velec,cutoff_mask);
259             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
260             velecsum         = _mm_add_pd(velecsum,velec);
261
262             fscal            = felec;
263
264             fscal            = _mm_and_pd(fscal,cutoff_mask);
265
266             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
267
268             /* Update vectorial force */
269             fix0             = _mm_macc_pd(dx00,fscal,fix0);
270             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
271             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
272             
273             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
274                                                    _mm_mul_pd(dx00,fscal),
275                                                    _mm_mul_pd(dy00,fscal),
276                                                    _mm_mul_pd(dz00,fscal));
277
278             }
279
280             /* Inner loop uses 39 flops */
281         }
282
283         /* End of innermost loop */
284
285         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
286                                               f+i_coord_offset,fshift+i_shift_offset);
287
288         ggid                        = gid[iidx];
289         /* Update potential energies */
290         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
291
292         /* Increment number of inner iterations */
293         inneriter                  += j_index_end - j_index_start;
294
295         /* Outer loop uses 8 flops */
296     }
297
298     /* Increment number of outer iterations */
299     outeriter        += nri;
300
301     /* Update outer/inner flops */
302
303     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*39);
304 }
305 /*
306  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
307  * Electrostatics interaction: ReactionField
308  * VdW interaction:            None
309  * Geometry:                   Particle-Particle
310  * Calculate force/pot:        Force
311  */
312 void
313 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_double
314                     (t_nblist                    * gmx_restrict       nlist,
315                      rvec                        * gmx_restrict          xx,
316                      rvec                        * gmx_restrict          ff,
317                      t_forcerec                  * gmx_restrict          fr,
318                      t_mdatoms                   * gmx_restrict     mdatoms,
319                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
320                      t_nrnb                      * gmx_restrict        nrnb)
321 {
322     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
323      * just 0 for non-waters.
324      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
325      * jnr indices corresponding to data put in the four positions in the SIMD register.
326      */
327     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
328     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
329     int              jnrA,jnrB;
330     int              j_coord_offsetA,j_coord_offsetB;
331     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
332     real             rcutoff_scalar;
333     real             *shiftvec,*fshift,*x,*f;
334     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
335     int              vdwioffset0;
336     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
337     int              vdwjidx0A,vdwjidx0B;
338     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
339     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
340     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
341     real             *charge;
342     __m128d          dummy_mask,cutoff_mask;
343     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
344     __m128d          one     = _mm_set1_pd(1.0);
345     __m128d          two     = _mm_set1_pd(2.0);
346     x                = xx[0];
347     f                = ff[0];
348
349     nri              = nlist->nri;
350     iinr             = nlist->iinr;
351     jindex           = nlist->jindex;
352     jjnr             = nlist->jjnr;
353     shiftidx         = nlist->shift;
354     gid              = nlist->gid;
355     shiftvec         = fr->shift_vec[0];
356     fshift           = fr->fshift[0];
357     facel            = _mm_set1_pd(fr->epsfac);
358     charge           = mdatoms->chargeA;
359     krf              = _mm_set1_pd(fr->ic->k_rf);
360     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
361     crf              = _mm_set1_pd(fr->ic->c_rf);
362
363     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
364     rcutoff_scalar   = fr->rcoulomb;
365     rcutoff          = _mm_set1_pd(rcutoff_scalar);
366     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
367
368     /* Avoid stupid compiler warnings */
369     jnrA = jnrB = 0;
370     j_coord_offsetA = 0;
371     j_coord_offsetB = 0;
372
373     outeriter        = 0;
374     inneriter        = 0;
375
376     /* Start outer loop over neighborlists */
377     for(iidx=0; iidx<nri; iidx++)
378     {
379         /* Load shift vector for this list */
380         i_shift_offset   = DIM*shiftidx[iidx];
381
382         /* Load limits for loop over neighbors */
383         j_index_start    = jindex[iidx];
384         j_index_end      = jindex[iidx+1];
385
386         /* Get outer coordinate index */
387         inr              = iinr[iidx];
388         i_coord_offset   = DIM*inr;
389
390         /* Load i particle coords and add shift vector */
391         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
392
393         fix0             = _mm_setzero_pd();
394         fiy0             = _mm_setzero_pd();
395         fiz0             = _mm_setzero_pd();
396
397         /* Load parameters for i particles */
398         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
399
400         /* Start inner kernel loop */
401         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
402         {
403
404             /* Get j neighbor index, and coordinate index */
405             jnrA             = jjnr[jidx];
406             jnrB             = jjnr[jidx+1];
407             j_coord_offsetA  = DIM*jnrA;
408             j_coord_offsetB  = DIM*jnrB;
409
410             /* load j atom coordinates */
411             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
412                                               &jx0,&jy0,&jz0);
413
414             /* Calculate displacement vector */
415             dx00             = _mm_sub_pd(ix0,jx0);
416             dy00             = _mm_sub_pd(iy0,jy0);
417             dz00             = _mm_sub_pd(iz0,jz0);
418
419             /* Calculate squared distance and things based on it */
420             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
421
422             rinv00           = gmx_mm_invsqrt_pd(rsq00);
423
424             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
425
426             /* Load parameters for j particles */
427             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
428
429             /**************************
430              * CALCULATE INTERACTIONS *
431              **************************/
432
433             if (gmx_mm_any_lt(rsq00,rcutoff2))
434             {
435
436             /* Compute parameters for interactions between i and j atoms */
437             qq00             = _mm_mul_pd(iq0,jq0);
438
439             /* REACTION-FIELD ELECTROSTATICS */
440             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
441
442             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
443
444             fscal            = felec;
445
446             fscal            = _mm_and_pd(fscal,cutoff_mask);
447
448             /* Update vectorial force */
449             fix0             = _mm_macc_pd(dx00,fscal,fix0);
450             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
451             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
452             
453             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
454                                                    _mm_mul_pd(dx00,fscal),
455                                                    _mm_mul_pd(dy00,fscal),
456                                                    _mm_mul_pd(dz00,fscal));
457
458             }
459
460             /* Inner loop uses 33 flops */
461         }
462
463         if(jidx<j_index_end)
464         {
465
466             jnrA             = jjnr[jidx];
467             j_coord_offsetA  = DIM*jnrA;
468
469             /* load j atom coordinates */
470             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
471                                               &jx0,&jy0,&jz0);
472
473             /* Calculate displacement vector */
474             dx00             = _mm_sub_pd(ix0,jx0);
475             dy00             = _mm_sub_pd(iy0,jy0);
476             dz00             = _mm_sub_pd(iz0,jz0);
477
478             /* Calculate squared distance and things based on it */
479             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
480
481             rinv00           = gmx_mm_invsqrt_pd(rsq00);
482
483             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
484
485             /* Load parameters for j particles */
486             jq0              = _mm_load_sd(charge+jnrA+0);
487
488             /**************************
489              * CALCULATE INTERACTIONS *
490              **************************/
491
492             if (gmx_mm_any_lt(rsq00,rcutoff2))
493             {
494
495             /* Compute parameters for interactions between i and j atoms */
496             qq00             = _mm_mul_pd(iq0,jq0);
497
498             /* REACTION-FIELD ELECTROSTATICS */
499             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
500
501             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
502
503             fscal            = felec;
504
505             fscal            = _mm_and_pd(fscal,cutoff_mask);
506
507             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
508
509             /* Update vectorial force */
510             fix0             = _mm_macc_pd(dx00,fscal,fix0);
511             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
512             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
513             
514             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
515                                                    _mm_mul_pd(dx00,fscal),
516                                                    _mm_mul_pd(dy00,fscal),
517                                                    _mm_mul_pd(dz00,fscal));
518
519             }
520
521             /* Inner loop uses 33 flops */
522         }
523
524         /* End of innermost loop */
525
526         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
527                                               f+i_coord_offset,fshift+i_shift_offset);
528
529         /* Increment number of inner iterations */
530         inneriter                  += j_index_end - j_index_start;
531
532         /* Outer loop uses 7 flops */
533     }
534
535     /* Increment number of outer iterations */
536     outeriter        += nri;
537
538     /* Update outer/inner flops */
539
540     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*33);
541 }