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