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