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