Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecNone_VdwLJ_GeomP1P1_avx_128_fma_double.c
1 /*
2  * Note: this file was generated by the Gromacs avx_128_fma_double kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
10  * Gromacs is a library for molecular simulation and trajectory analysis,
11  * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12  * a full list of developers and information, check out http://www.gromacs.org
13  *
14  * This program is free software; you can redistribute it and/or modify it under
15  * the terms of the GNU Lesser General Public License as published by the Free
16  * Software Foundation; either version 2 of the License, or (at your option) any
17  * later version.
18  *
19  * To help fund GROMACS development, we humbly ask that you cite
20  * the papers people have written on it - you can find them on the website.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 #include "gmx_math_x86_avx_128_fma_double.h"
34 #include "kernelutil_x86_avx_128_fma_double.h"
35
36 /*
37  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_avx_128_fma_double
38  * Electrostatics interaction: None
39  * VdW interaction:            LennardJones
40  * Geometry:                   Particle-Particle
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_avx_128_fma_double
45                     (t_nblist * gmx_restrict                nlist,
46                      rvec * gmx_restrict                    xx,
47                      rvec * gmx_restrict                    ff,
48                      t_forcerec * gmx_restrict              fr,
49                      t_mdatoms * gmx_restrict               mdatoms,
50                      nb_kernel_data_t * gmx_restrict        kernel_data,
51                      t_nrnb * gmx_restrict                  nrnb)
52 {
53     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54      * just 0 for non-waters.
55      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
56      * jnr indices corresponding to data put in the four positions in the SIMD register.
57      */
58     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
59     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60     int              jnrA,jnrB;
61     int              j_coord_offsetA,j_coord_offsetB;
62     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
63     real             rcutoff_scalar;
64     real             *shiftvec,*fshift,*x,*f;
65     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
66     int              vdwioffset0;
67     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
68     int              vdwjidx0A,vdwjidx0B;
69     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
70     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
71     int              nvdwtype;
72     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
73     int              *vdwtype;
74     real             *vdwparam;
75     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
76     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
77     __m128d          dummy_mask,cutoff_mask;
78     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
79     __m128d          one     = _mm_set1_pd(1.0);
80     __m128d          two     = _mm_set1_pd(2.0);
81     x                = xx[0];
82     f                = ff[0];
83
84     nri              = nlist->nri;
85     iinr             = nlist->iinr;
86     jindex           = nlist->jindex;
87     jjnr             = nlist->jjnr;
88     shiftidx         = nlist->shift;
89     gid              = nlist->gid;
90     shiftvec         = fr->shift_vec[0];
91     fshift           = fr->fshift[0];
92     nvdwtype         = fr->ntype;
93     vdwparam         = fr->nbfp;
94     vdwtype          = mdatoms->typeA;
95
96     /* Avoid stupid compiler warnings */
97     jnrA = jnrB = 0;
98     j_coord_offsetA = 0;
99     j_coord_offsetB = 0;
100
101     outeriter        = 0;
102     inneriter        = 0;
103
104     /* Start outer loop over neighborlists */
105     for(iidx=0; iidx<nri; iidx++)
106     {
107         /* Load shift vector for this list */
108         i_shift_offset   = DIM*shiftidx[iidx];
109
110         /* Load limits for loop over neighbors */
111         j_index_start    = jindex[iidx];
112         j_index_end      = jindex[iidx+1];
113
114         /* Get outer coordinate index */
115         inr              = iinr[iidx];
116         i_coord_offset   = DIM*inr;
117
118         /* Load i particle coords and add shift vector */
119         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
120
121         fix0             = _mm_setzero_pd();
122         fiy0             = _mm_setzero_pd();
123         fiz0             = _mm_setzero_pd();
124
125         /* Load parameters for i particles */
126         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
127
128         /* Reset potential sums */
129         vvdwsum          = _mm_setzero_pd();
130
131         /* Start inner kernel loop */
132         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
133         {
134
135             /* Get j neighbor index, and coordinate index */
136             jnrA             = jjnr[jidx];
137             jnrB             = jjnr[jidx+1];
138             j_coord_offsetA  = DIM*jnrA;
139             j_coord_offsetB  = DIM*jnrB;
140
141             /* load j atom coordinates */
142             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
143                                               &jx0,&jy0,&jz0);
144
145             /* Calculate displacement vector */
146             dx00             = _mm_sub_pd(ix0,jx0);
147             dy00             = _mm_sub_pd(iy0,jy0);
148             dz00             = _mm_sub_pd(iz0,jz0);
149
150             /* Calculate squared distance and things based on it */
151             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
152
153             rinvsq00         = gmx_mm_inv_pd(rsq00);
154
155             /* Load parameters for j particles */
156             vdwjidx0A        = 2*vdwtype[jnrA+0];
157             vdwjidx0B        = 2*vdwtype[jnrB+0];
158
159             /**************************
160              * CALCULATE INTERACTIONS *
161              **************************/
162
163             /* Compute parameters for interactions between i and j atoms */
164             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
165                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
166
167             /* LENNARD-JONES DISPERSION/REPULSION */
168
169             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
170             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
171             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
172             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
173             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
174
175             /* Update potential sum for this i atom from the interaction with this j atom. */
176             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
177
178             fscal            = fvdw;
179
180             /* Update vectorial force */
181             fix0             = _mm_macc_pd(dx00,fscal,fix0);
182             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
183             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
184             
185             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
186                                                    _mm_mul_pd(dx00,fscal),
187                                                    _mm_mul_pd(dy00,fscal),
188                                                    _mm_mul_pd(dz00,fscal));
189
190             /* Inner loop uses 35 flops */
191         }
192
193         if(jidx<j_index_end)
194         {
195
196             jnrA             = jjnr[jidx];
197             j_coord_offsetA  = DIM*jnrA;
198
199             /* load j atom coordinates */
200             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
201                                               &jx0,&jy0,&jz0);
202
203             /* Calculate displacement vector */
204             dx00             = _mm_sub_pd(ix0,jx0);
205             dy00             = _mm_sub_pd(iy0,jy0);
206             dz00             = _mm_sub_pd(iz0,jz0);
207
208             /* Calculate squared distance and things based on it */
209             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
210
211             rinvsq00         = gmx_mm_inv_pd(rsq00);
212
213             /* Load parameters for j particles */
214             vdwjidx0A        = 2*vdwtype[jnrA+0];
215
216             /**************************
217              * CALCULATE INTERACTIONS *
218              **************************/
219
220             /* Compute parameters for interactions between i and j atoms */
221             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
222
223             /* LENNARD-JONES DISPERSION/REPULSION */
224
225             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
226             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
227             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
228             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
229             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
230
231             /* Update potential sum for this i atom from the interaction with this j atom. */
232             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
233             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
234
235             fscal            = fvdw;
236
237             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
238
239             /* Update vectorial force */
240             fix0             = _mm_macc_pd(dx00,fscal,fix0);
241             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
242             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
243             
244             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
245                                                    _mm_mul_pd(dx00,fscal),
246                                                    _mm_mul_pd(dy00,fscal),
247                                                    _mm_mul_pd(dz00,fscal));
248
249             /* Inner loop uses 35 flops */
250         }
251
252         /* End of innermost loop */
253
254         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
255                                               f+i_coord_offset,fshift+i_shift_offset);
256
257         ggid                        = gid[iidx];
258         /* Update potential energies */
259         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
260
261         /* Increment number of inner iterations */
262         inneriter                  += j_index_end - j_index_start;
263
264         /* Outer loop uses 7 flops */
265     }
266
267     /* Increment number of outer iterations */
268     outeriter        += nri;
269
270     /* Update outer/inner flops */
271
272     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*35);
273 }
274 /*
275  * Gromacs nonbonded kernel:   nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_avx_128_fma_double
276  * Electrostatics interaction: None
277  * VdW interaction:            LennardJones
278  * Geometry:                   Particle-Particle
279  * Calculate force/pot:        Force
280  */
281 void
282 nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_avx_128_fma_double
283                     (t_nblist * gmx_restrict                nlist,
284                      rvec * gmx_restrict                    xx,
285                      rvec * gmx_restrict                    ff,
286                      t_forcerec * gmx_restrict              fr,
287                      t_mdatoms * gmx_restrict               mdatoms,
288                      nb_kernel_data_t * gmx_restrict        kernel_data,
289                      t_nrnb * gmx_restrict                  nrnb)
290 {
291     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
292      * just 0 for non-waters.
293      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
294      * jnr indices corresponding to data put in the four positions in the SIMD register.
295      */
296     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
297     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
298     int              jnrA,jnrB;
299     int              j_coord_offsetA,j_coord_offsetB;
300     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
301     real             rcutoff_scalar;
302     real             *shiftvec,*fshift,*x,*f;
303     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
304     int              vdwioffset0;
305     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
306     int              vdwjidx0A,vdwjidx0B;
307     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
308     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
309     int              nvdwtype;
310     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
311     int              *vdwtype;
312     real             *vdwparam;
313     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
314     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
315     __m128d          dummy_mask,cutoff_mask;
316     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
317     __m128d          one     = _mm_set1_pd(1.0);
318     __m128d          two     = _mm_set1_pd(2.0);
319     x                = xx[0];
320     f                = ff[0];
321
322     nri              = nlist->nri;
323     iinr             = nlist->iinr;
324     jindex           = nlist->jindex;
325     jjnr             = nlist->jjnr;
326     shiftidx         = nlist->shift;
327     gid              = nlist->gid;
328     shiftvec         = fr->shift_vec[0];
329     fshift           = fr->fshift[0];
330     nvdwtype         = fr->ntype;
331     vdwparam         = fr->nbfp;
332     vdwtype          = mdatoms->typeA;
333
334     /* Avoid stupid compiler warnings */
335     jnrA = jnrB = 0;
336     j_coord_offsetA = 0;
337     j_coord_offsetB = 0;
338
339     outeriter        = 0;
340     inneriter        = 0;
341
342     /* Start outer loop over neighborlists */
343     for(iidx=0; iidx<nri; iidx++)
344     {
345         /* Load shift vector for this list */
346         i_shift_offset   = DIM*shiftidx[iidx];
347
348         /* Load limits for loop over neighbors */
349         j_index_start    = jindex[iidx];
350         j_index_end      = jindex[iidx+1];
351
352         /* Get outer coordinate index */
353         inr              = iinr[iidx];
354         i_coord_offset   = DIM*inr;
355
356         /* Load i particle coords and add shift vector */
357         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
358
359         fix0             = _mm_setzero_pd();
360         fiy0             = _mm_setzero_pd();
361         fiz0             = _mm_setzero_pd();
362
363         /* Load parameters for i particles */
364         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
365
366         /* Start inner kernel loop */
367         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
368         {
369
370             /* Get j neighbor index, and coordinate index */
371             jnrA             = jjnr[jidx];
372             jnrB             = jjnr[jidx+1];
373             j_coord_offsetA  = DIM*jnrA;
374             j_coord_offsetB  = DIM*jnrB;
375
376             /* load j atom coordinates */
377             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
378                                               &jx0,&jy0,&jz0);
379
380             /* Calculate displacement vector */
381             dx00             = _mm_sub_pd(ix0,jx0);
382             dy00             = _mm_sub_pd(iy0,jy0);
383             dz00             = _mm_sub_pd(iz0,jz0);
384
385             /* Calculate squared distance and things based on it */
386             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
387
388             rinvsq00         = gmx_mm_inv_pd(rsq00);
389
390             /* Load parameters for j particles */
391             vdwjidx0A        = 2*vdwtype[jnrA+0];
392             vdwjidx0B        = 2*vdwtype[jnrB+0];
393
394             /**************************
395              * CALCULATE INTERACTIONS *
396              **************************/
397
398             /* Compute parameters for interactions between i and j atoms */
399             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
400                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
401
402             /* LENNARD-JONES DISPERSION/REPULSION */
403
404             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
405             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
406
407             fscal            = fvdw;
408
409             /* Update vectorial force */
410             fix0             = _mm_macc_pd(dx00,fscal,fix0);
411             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
412             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
413             
414             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,
415                                                    _mm_mul_pd(dx00,fscal),
416                                                    _mm_mul_pd(dy00,fscal),
417                                                    _mm_mul_pd(dz00,fscal));
418
419             /* Inner loop uses 30 flops */
420         }
421
422         if(jidx<j_index_end)
423         {
424
425             jnrA             = jjnr[jidx];
426             j_coord_offsetA  = DIM*jnrA;
427
428             /* load j atom coordinates */
429             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
430                                               &jx0,&jy0,&jz0);
431
432             /* Calculate displacement vector */
433             dx00             = _mm_sub_pd(ix0,jx0);
434             dy00             = _mm_sub_pd(iy0,jy0);
435             dz00             = _mm_sub_pd(iz0,jz0);
436
437             /* Calculate squared distance and things based on it */
438             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
439
440             rinvsq00         = gmx_mm_inv_pd(rsq00);
441
442             /* Load parameters for j particles */
443             vdwjidx0A        = 2*vdwtype[jnrA+0];
444
445             /**************************
446              * CALCULATE INTERACTIONS *
447              **************************/
448
449             /* Compute parameters for interactions between i and j atoms */
450             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
451
452             /* LENNARD-JONES DISPERSION/REPULSION */
453
454             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
455             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
456
457             fscal            = fvdw;
458
459             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
460
461             /* Update vectorial force */
462             fix0             = _mm_macc_pd(dx00,fscal,fix0);
463             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
464             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
465             
466             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,
467                                                    _mm_mul_pd(dx00,fscal),
468                                                    _mm_mul_pd(dy00,fscal),
469                                                    _mm_mul_pd(dz00,fscal));
470
471             /* Inner loop uses 30 flops */
472         }
473
474         /* End of innermost loop */
475
476         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
477                                               f+i_coord_offset,fshift+i_shift_offset);
478
479         /* Increment number of inner iterations */
480         inneriter                  += j_index_end - j_index_start;
481
482         /* Outer loop uses 6 flops */
483     }
484
485     /* Increment number of outer iterations */
486     outeriter        += nri;
487
488     /* Update outer/inner flops */
489
490     inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*30);
491 }