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