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