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