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