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