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