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