Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRFCut_VdwNone_GeomW4P1_avx_128_fma_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 avx_128_fma_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_avx_128_fma_double.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_avx_128_fma_double
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            None
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_avx_128_fma_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              vdwioffset1;
80     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
81     int              vdwioffset2;
82     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
83     int              vdwioffset3;
84     __m128d          ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
85     int              vdwjidx0A,vdwjidx0B;
86     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
88     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
89     __m128d          dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
90     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
91     real             *charge;
92     __m128d          dummy_mask,cutoff_mask;
93     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
94     __m128d          one     = _mm_set1_pd(1.0);
95     __m128d          two     = _mm_set1_pd(2.0);
96     x                = xx[0];
97     f                = ff[0];
98
99     nri              = nlist->nri;
100     iinr             = nlist->iinr;
101     jindex           = nlist->jindex;
102     jjnr             = nlist->jjnr;
103     shiftidx         = nlist->shift;
104     gid              = nlist->gid;
105     shiftvec         = fr->shift_vec[0];
106     fshift           = fr->fshift[0];
107     facel            = _mm_set1_pd(fr->ic->epsfac);
108     charge           = mdatoms->chargeA;
109     krf              = _mm_set1_pd(fr->ic->k_rf);
110     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
111     crf              = _mm_set1_pd(fr->ic->c_rf);
112
113     /* Setup water-specific parameters */
114     inr              = nlist->iinr[0];
115     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
116     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
117     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
118
119     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
120     rcutoff_scalar   = fr->ic->rcoulomb;
121     rcutoff          = _mm_set1_pd(rcutoff_scalar);
122     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
123
124     /* Avoid stupid compiler warnings */
125     jnrA = jnrB = 0;
126     j_coord_offsetA = 0;
127     j_coord_offsetB = 0;
128
129     outeriter        = 0;
130     inneriter        = 0;
131
132     /* Start outer loop over neighborlists */
133     for(iidx=0; iidx<nri; iidx++)
134     {
135         /* Load shift vector for this list */
136         i_shift_offset   = DIM*shiftidx[iidx];
137
138         /* Load limits for loop over neighbors */
139         j_index_start    = jindex[iidx];
140         j_index_end      = jindex[iidx+1];
141
142         /* Get outer coordinate index */
143         inr              = iinr[iidx];
144         i_coord_offset   = DIM*inr;
145
146         /* Load i particle coords and add shift vector */
147         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
148                                                  &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
149
150         fix1             = _mm_setzero_pd();
151         fiy1             = _mm_setzero_pd();
152         fiz1             = _mm_setzero_pd();
153         fix2             = _mm_setzero_pd();
154         fiy2             = _mm_setzero_pd();
155         fiz2             = _mm_setzero_pd();
156         fix3             = _mm_setzero_pd();
157         fiy3             = _mm_setzero_pd();
158         fiz3             = _mm_setzero_pd();
159
160         /* Reset potential sums */
161         velecsum         = _mm_setzero_pd();
162
163         /* Start inner kernel loop */
164         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
165         {
166
167             /* Get j neighbor index, and coordinate index */
168             jnrA             = jjnr[jidx];
169             jnrB             = jjnr[jidx+1];
170             j_coord_offsetA  = DIM*jnrA;
171             j_coord_offsetB  = DIM*jnrB;
172
173             /* load j atom coordinates */
174             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
175                                               &jx0,&jy0,&jz0);
176
177             /* Calculate displacement vector */
178             dx10             = _mm_sub_pd(ix1,jx0);
179             dy10             = _mm_sub_pd(iy1,jy0);
180             dz10             = _mm_sub_pd(iz1,jz0);
181             dx20             = _mm_sub_pd(ix2,jx0);
182             dy20             = _mm_sub_pd(iy2,jy0);
183             dz20             = _mm_sub_pd(iz2,jz0);
184             dx30             = _mm_sub_pd(ix3,jx0);
185             dy30             = _mm_sub_pd(iy3,jy0);
186             dz30             = _mm_sub_pd(iz3,jz0);
187
188             /* Calculate squared distance and things based on it */
189             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
190             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
191             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
192
193             rinv10           = avx128fma_invsqrt_d(rsq10);
194             rinv20           = avx128fma_invsqrt_d(rsq20);
195             rinv30           = avx128fma_invsqrt_d(rsq30);
196
197             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
198             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
199             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
200
201             /* Load parameters for j particles */
202             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
203
204             fjx0             = _mm_setzero_pd();
205             fjy0             = _mm_setzero_pd();
206             fjz0             = _mm_setzero_pd();
207
208             /**************************
209              * CALCULATE INTERACTIONS *
210              **************************/
211
212             if (gmx_mm_any_lt(rsq10,rcutoff2))
213             {
214
215             /* Compute parameters for interactions between i and j atoms */
216             qq10             = _mm_mul_pd(iq1,jq0);
217
218             /* REACTION-FIELD ELECTROSTATICS */
219             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
220             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
221
222             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
223
224             /* Update potential sum for this i atom from the interaction with this j atom. */
225             velec            = _mm_and_pd(velec,cutoff_mask);
226             velecsum         = _mm_add_pd(velecsum,velec);
227
228             fscal            = felec;
229
230             fscal            = _mm_and_pd(fscal,cutoff_mask);
231
232             /* Update vectorial force */
233             fix1             = _mm_macc_pd(dx10,fscal,fix1);
234             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
235             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
236             
237             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
238             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
239             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
240
241             }
242
243             /**************************
244              * CALCULATE INTERACTIONS *
245              **************************/
246
247             if (gmx_mm_any_lt(rsq20,rcutoff2))
248             {
249
250             /* Compute parameters for interactions between i and j atoms */
251             qq20             = _mm_mul_pd(iq2,jq0);
252
253             /* REACTION-FIELD ELECTROSTATICS */
254             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
255             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
256
257             cutoff_mask      = _mm_cmplt_pd(rsq20,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             velecsum         = _mm_add_pd(velecsum,velec);
262
263             fscal            = felec;
264
265             fscal            = _mm_and_pd(fscal,cutoff_mask);
266
267             /* Update vectorial force */
268             fix2             = _mm_macc_pd(dx20,fscal,fix2);
269             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
270             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
271             
272             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
273             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
274             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
275
276             }
277
278             /**************************
279              * CALCULATE INTERACTIONS *
280              **************************/
281
282             if (gmx_mm_any_lt(rsq30,rcutoff2))
283             {
284
285             /* Compute parameters for interactions between i and j atoms */
286             qq30             = _mm_mul_pd(iq3,jq0);
287
288             /* REACTION-FIELD ELECTROSTATICS */
289             velec            = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
290             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
291
292             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
293
294             /* Update potential sum for this i atom from the interaction with this j atom. */
295             velec            = _mm_and_pd(velec,cutoff_mask);
296             velecsum         = _mm_add_pd(velecsum,velec);
297
298             fscal            = felec;
299
300             fscal            = _mm_and_pd(fscal,cutoff_mask);
301
302             /* Update vectorial force */
303             fix3             = _mm_macc_pd(dx30,fscal,fix3);
304             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
305             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
306             
307             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
308             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
309             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
310
311             }
312
313             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
314
315             /* Inner loop uses 120 flops */
316         }
317
318         if(jidx<j_index_end)
319         {
320
321             jnrA             = jjnr[jidx];
322             j_coord_offsetA  = DIM*jnrA;
323
324             /* load j atom coordinates */
325             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
326                                               &jx0,&jy0,&jz0);
327
328             /* Calculate displacement vector */
329             dx10             = _mm_sub_pd(ix1,jx0);
330             dy10             = _mm_sub_pd(iy1,jy0);
331             dz10             = _mm_sub_pd(iz1,jz0);
332             dx20             = _mm_sub_pd(ix2,jx0);
333             dy20             = _mm_sub_pd(iy2,jy0);
334             dz20             = _mm_sub_pd(iz2,jz0);
335             dx30             = _mm_sub_pd(ix3,jx0);
336             dy30             = _mm_sub_pd(iy3,jy0);
337             dz30             = _mm_sub_pd(iz3,jz0);
338
339             /* Calculate squared distance and things based on it */
340             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
341             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
342             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
343
344             rinv10           = avx128fma_invsqrt_d(rsq10);
345             rinv20           = avx128fma_invsqrt_d(rsq20);
346             rinv30           = avx128fma_invsqrt_d(rsq30);
347
348             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
349             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
350             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
351
352             /* Load parameters for j particles */
353             jq0              = _mm_load_sd(charge+jnrA+0);
354
355             fjx0             = _mm_setzero_pd();
356             fjy0             = _mm_setzero_pd();
357             fjz0             = _mm_setzero_pd();
358
359             /**************************
360              * CALCULATE INTERACTIONS *
361              **************************/
362
363             if (gmx_mm_any_lt(rsq10,rcutoff2))
364             {
365
366             /* Compute parameters for interactions between i and j atoms */
367             qq10             = _mm_mul_pd(iq1,jq0);
368
369             /* REACTION-FIELD ELECTROSTATICS */
370             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
371             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
372
373             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
374
375             /* Update potential sum for this i atom from the interaction with this j atom. */
376             velec            = _mm_and_pd(velec,cutoff_mask);
377             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
378             velecsum         = _mm_add_pd(velecsum,velec);
379
380             fscal            = felec;
381
382             fscal            = _mm_and_pd(fscal,cutoff_mask);
383
384             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
385
386             /* Update vectorial force */
387             fix1             = _mm_macc_pd(dx10,fscal,fix1);
388             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
389             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
390             
391             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
392             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
393             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
394
395             }
396
397             /**************************
398              * CALCULATE INTERACTIONS *
399              **************************/
400
401             if (gmx_mm_any_lt(rsq20,rcutoff2))
402             {
403
404             /* Compute parameters for interactions between i and j atoms */
405             qq20             = _mm_mul_pd(iq2,jq0);
406
407             /* REACTION-FIELD ELECTROSTATICS */
408             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
409             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
410
411             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
412
413             /* Update potential sum for this i atom from the interaction with this j atom. */
414             velec            = _mm_and_pd(velec,cutoff_mask);
415             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
416             velecsum         = _mm_add_pd(velecsum,velec);
417
418             fscal            = felec;
419
420             fscal            = _mm_and_pd(fscal,cutoff_mask);
421
422             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
423
424             /* Update vectorial force */
425             fix2             = _mm_macc_pd(dx20,fscal,fix2);
426             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
427             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
428             
429             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
430             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
431             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
432
433             }
434
435             /**************************
436              * CALCULATE INTERACTIONS *
437              **************************/
438
439             if (gmx_mm_any_lt(rsq30,rcutoff2))
440             {
441
442             /* Compute parameters for interactions between i and j atoms */
443             qq30             = _mm_mul_pd(iq3,jq0);
444
445             /* REACTION-FIELD ELECTROSTATICS */
446             velec            = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
447             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
448
449             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
450
451             /* Update potential sum for this i atom from the interaction with this j atom. */
452             velec            = _mm_and_pd(velec,cutoff_mask);
453             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
454             velecsum         = _mm_add_pd(velecsum,velec);
455
456             fscal            = felec;
457
458             fscal            = _mm_and_pd(fscal,cutoff_mask);
459
460             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
461
462             /* Update vectorial force */
463             fix3             = _mm_macc_pd(dx30,fscal,fix3);
464             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
465             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
466             
467             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
468             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
469             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
470
471             }
472
473             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
474
475             /* Inner loop uses 120 flops */
476         }
477
478         /* End of innermost loop */
479
480         gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
481                                               f+i_coord_offset+DIM,fshift+i_shift_offset);
482
483         ggid                        = gid[iidx];
484         /* Update potential energies */
485         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
486
487         /* Increment number of inner iterations */
488         inneriter                  += j_index_end - j_index_start;
489
490         /* Outer loop uses 19 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_W4_VF,outeriter*19 + inneriter*120);
499 }
500 /*
501  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_avx_128_fma_double
502  * Electrostatics interaction: ReactionField
503  * VdW interaction:            None
504  * Geometry:                   Water4-Particle
505  * Calculate force/pot:        Force
506  */
507 void
508 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_avx_128_fma_double
509                     (t_nblist                    * gmx_restrict       nlist,
510                      rvec                        * gmx_restrict          xx,
511                      rvec                        * gmx_restrict          ff,
512                      struct t_forcerec           * gmx_restrict          fr,
513                      t_mdatoms                   * gmx_restrict     mdatoms,
514                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
515                      t_nrnb                      * gmx_restrict        nrnb)
516 {
517     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
518      * just 0 for non-waters.
519      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
520      * jnr indices corresponding to data put in the four positions in the SIMD register.
521      */
522     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
523     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
524     int              jnrA,jnrB;
525     int              j_coord_offsetA,j_coord_offsetB;
526     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
527     real             rcutoff_scalar;
528     real             *shiftvec,*fshift,*x,*f;
529     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
530     int              vdwioffset1;
531     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
532     int              vdwioffset2;
533     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
534     int              vdwioffset3;
535     __m128d          ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
536     int              vdwjidx0A,vdwjidx0B;
537     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
538     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
539     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
540     __m128d          dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
541     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
542     real             *charge;
543     __m128d          dummy_mask,cutoff_mask;
544     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
545     __m128d          one     = _mm_set1_pd(1.0);
546     __m128d          two     = _mm_set1_pd(2.0);
547     x                = xx[0];
548     f                = ff[0];
549
550     nri              = nlist->nri;
551     iinr             = nlist->iinr;
552     jindex           = nlist->jindex;
553     jjnr             = nlist->jjnr;
554     shiftidx         = nlist->shift;
555     gid              = nlist->gid;
556     shiftvec         = fr->shift_vec[0];
557     fshift           = fr->fshift[0];
558     facel            = _mm_set1_pd(fr->ic->epsfac);
559     charge           = mdatoms->chargeA;
560     krf              = _mm_set1_pd(fr->ic->k_rf);
561     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
562     crf              = _mm_set1_pd(fr->ic->c_rf);
563
564     /* Setup water-specific parameters */
565     inr              = nlist->iinr[0];
566     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
567     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
568     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
569
570     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
571     rcutoff_scalar   = fr->ic->rcoulomb;
572     rcutoff          = _mm_set1_pd(rcutoff_scalar);
573     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
574
575     /* Avoid stupid compiler warnings */
576     jnrA = jnrB = 0;
577     j_coord_offsetA = 0;
578     j_coord_offsetB = 0;
579
580     outeriter        = 0;
581     inneriter        = 0;
582
583     /* Start outer loop over neighborlists */
584     for(iidx=0; iidx<nri; iidx++)
585     {
586         /* Load shift vector for this list */
587         i_shift_offset   = DIM*shiftidx[iidx];
588
589         /* Load limits for loop over neighbors */
590         j_index_start    = jindex[iidx];
591         j_index_end      = jindex[iidx+1];
592
593         /* Get outer coordinate index */
594         inr              = iinr[iidx];
595         i_coord_offset   = DIM*inr;
596
597         /* Load i particle coords and add shift vector */
598         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
599                                                  &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
600
601         fix1             = _mm_setzero_pd();
602         fiy1             = _mm_setzero_pd();
603         fiz1             = _mm_setzero_pd();
604         fix2             = _mm_setzero_pd();
605         fiy2             = _mm_setzero_pd();
606         fiz2             = _mm_setzero_pd();
607         fix3             = _mm_setzero_pd();
608         fiy3             = _mm_setzero_pd();
609         fiz3             = _mm_setzero_pd();
610
611         /* Start inner kernel loop */
612         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
613         {
614
615             /* Get j neighbor index, and coordinate index */
616             jnrA             = jjnr[jidx];
617             jnrB             = jjnr[jidx+1];
618             j_coord_offsetA  = DIM*jnrA;
619             j_coord_offsetB  = DIM*jnrB;
620
621             /* load j atom coordinates */
622             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
623                                               &jx0,&jy0,&jz0);
624
625             /* Calculate displacement vector */
626             dx10             = _mm_sub_pd(ix1,jx0);
627             dy10             = _mm_sub_pd(iy1,jy0);
628             dz10             = _mm_sub_pd(iz1,jz0);
629             dx20             = _mm_sub_pd(ix2,jx0);
630             dy20             = _mm_sub_pd(iy2,jy0);
631             dz20             = _mm_sub_pd(iz2,jz0);
632             dx30             = _mm_sub_pd(ix3,jx0);
633             dy30             = _mm_sub_pd(iy3,jy0);
634             dz30             = _mm_sub_pd(iz3,jz0);
635
636             /* Calculate squared distance and things based on it */
637             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
638             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
639             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
640
641             rinv10           = avx128fma_invsqrt_d(rsq10);
642             rinv20           = avx128fma_invsqrt_d(rsq20);
643             rinv30           = avx128fma_invsqrt_d(rsq30);
644
645             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
646             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
647             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
648
649             /* Load parameters for j particles */
650             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
651
652             fjx0             = _mm_setzero_pd();
653             fjy0             = _mm_setzero_pd();
654             fjz0             = _mm_setzero_pd();
655
656             /**************************
657              * CALCULATE INTERACTIONS *
658              **************************/
659
660             if (gmx_mm_any_lt(rsq10,rcutoff2))
661             {
662
663             /* Compute parameters for interactions between i and j atoms */
664             qq10             = _mm_mul_pd(iq1,jq0);
665
666             /* REACTION-FIELD ELECTROSTATICS */
667             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
668
669             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
670
671             fscal            = felec;
672
673             fscal            = _mm_and_pd(fscal,cutoff_mask);
674
675             /* Update vectorial force */
676             fix1             = _mm_macc_pd(dx10,fscal,fix1);
677             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
678             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
679             
680             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
681             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
682             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
683
684             }
685
686             /**************************
687              * CALCULATE INTERACTIONS *
688              **************************/
689
690             if (gmx_mm_any_lt(rsq20,rcutoff2))
691             {
692
693             /* Compute parameters for interactions between i and j atoms */
694             qq20             = _mm_mul_pd(iq2,jq0);
695
696             /* REACTION-FIELD ELECTROSTATICS */
697             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
698
699             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
700
701             fscal            = felec;
702
703             fscal            = _mm_and_pd(fscal,cutoff_mask);
704
705             /* Update vectorial force */
706             fix2             = _mm_macc_pd(dx20,fscal,fix2);
707             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
708             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
709             
710             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
711             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
712             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
713
714             }
715
716             /**************************
717              * CALCULATE INTERACTIONS *
718              **************************/
719
720             if (gmx_mm_any_lt(rsq30,rcutoff2))
721             {
722
723             /* Compute parameters for interactions between i and j atoms */
724             qq30             = _mm_mul_pd(iq3,jq0);
725
726             /* REACTION-FIELD ELECTROSTATICS */
727             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
728
729             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
730
731             fscal            = felec;
732
733             fscal            = _mm_and_pd(fscal,cutoff_mask);
734
735             /* Update vectorial force */
736             fix3             = _mm_macc_pd(dx30,fscal,fix3);
737             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
738             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
739             
740             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
741             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
742             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
743
744             }
745
746             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
747
748             /* Inner loop uses 102 flops */
749         }
750
751         if(jidx<j_index_end)
752         {
753
754             jnrA             = jjnr[jidx];
755             j_coord_offsetA  = DIM*jnrA;
756
757             /* load j atom coordinates */
758             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
759                                               &jx0,&jy0,&jz0);
760
761             /* Calculate displacement vector */
762             dx10             = _mm_sub_pd(ix1,jx0);
763             dy10             = _mm_sub_pd(iy1,jy0);
764             dz10             = _mm_sub_pd(iz1,jz0);
765             dx20             = _mm_sub_pd(ix2,jx0);
766             dy20             = _mm_sub_pd(iy2,jy0);
767             dz20             = _mm_sub_pd(iz2,jz0);
768             dx30             = _mm_sub_pd(ix3,jx0);
769             dy30             = _mm_sub_pd(iy3,jy0);
770             dz30             = _mm_sub_pd(iz3,jz0);
771
772             /* Calculate squared distance and things based on it */
773             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
774             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
775             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
776
777             rinv10           = avx128fma_invsqrt_d(rsq10);
778             rinv20           = avx128fma_invsqrt_d(rsq20);
779             rinv30           = avx128fma_invsqrt_d(rsq30);
780
781             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
782             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
783             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
784
785             /* Load parameters for j particles */
786             jq0              = _mm_load_sd(charge+jnrA+0);
787
788             fjx0             = _mm_setzero_pd();
789             fjy0             = _mm_setzero_pd();
790             fjz0             = _mm_setzero_pd();
791
792             /**************************
793              * CALCULATE INTERACTIONS *
794              **************************/
795
796             if (gmx_mm_any_lt(rsq10,rcutoff2))
797             {
798
799             /* Compute parameters for interactions between i and j atoms */
800             qq10             = _mm_mul_pd(iq1,jq0);
801
802             /* REACTION-FIELD ELECTROSTATICS */
803             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
804
805             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
806
807             fscal            = felec;
808
809             fscal            = _mm_and_pd(fscal,cutoff_mask);
810
811             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
812
813             /* Update vectorial force */
814             fix1             = _mm_macc_pd(dx10,fscal,fix1);
815             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
816             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
817             
818             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
819             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
820             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
821
822             }
823
824             /**************************
825              * CALCULATE INTERACTIONS *
826              **************************/
827
828             if (gmx_mm_any_lt(rsq20,rcutoff2))
829             {
830
831             /* Compute parameters for interactions between i and j atoms */
832             qq20             = _mm_mul_pd(iq2,jq0);
833
834             /* REACTION-FIELD ELECTROSTATICS */
835             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
836
837             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
838
839             fscal            = felec;
840
841             fscal            = _mm_and_pd(fscal,cutoff_mask);
842
843             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
844
845             /* Update vectorial force */
846             fix2             = _mm_macc_pd(dx20,fscal,fix2);
847             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
848             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
849             
850             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
851             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
852             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
853
854             }
855
856             /**************************
857              * CALCULATE INTERACTIONS *
858              **************************/
859
860             if (gmx_mm_any_lt(rsq30,rcutoff2))
861             {
862
863             /* Compute parameters for interactions between i and j atoms */
864             qq30             = _mm_mul_pd(iq3,jq0);
865
866             /* REACTION-FIELD ELECTROSTATICS */
867             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
868
869             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
870
871             fscal            = felec;
872
873             fscal            = _mm_and_pd(fscal,cutoff_mask);
874
875             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
876
877             /* Update vectorial force */
878             fix3             = _mm_macc_pd(dx30,fscal,fix3);
879             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
880             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
881             
882             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
883             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
884             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
885
886             }
887
888             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
889
890             /* Inner loop uses 102 flops */
891         }
892
893         /* End of innermost loop */
894
895         gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
896                                               f+i_coord_offset+DIM,fshift+i_shift_offset);
897
898         /* Increment number of inner iterations */
899         inneriter                  += j_index_end - j_index_start;
900
901         /* Outer loop uses 18 flops */
902     }
903
904     /* Increment number of outer iterations */
905     outeriter        += nri;
906
907     /* Update outer/inner flops */
908
909     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*102);
910 }