Compile nonbonded kernels as C++
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEwSh_VdwNone_GeomP1P1_avx_128_fma_single.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2017,2018, 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_ElecEwSh_VdwNone_GeomP1P1_VF_avx_128_fma_single
51  * Electrostatics interaction: Ewald
52  * VdW interaction:            None
53  * Geometry:                   Particle-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_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              vdwioffset0;
83     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
85     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
88     real             *charge;
89     __m128i          ewitab;
90     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
91     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
92     real             *ewtab;
93     __m128           dummy_mask,cutoff_mask;
94     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
95     __m128           one     = _mm_set1_ps(1.0);
96     __m128           two     = _mm_set1_ps(2.0);
97     x                = xx[0];
98     f                = ff[0];
99
100     nri              = nlist->nri;
101     iinr             = nlist->iinr;
102     jindex           = nlist->jindex;
103     jjnr             = nlist->jjnr;
104     shiftidx         = nlist->shift;
105     gid              = nlist->gid;
106     shiftvec         = fr->shift_vec[0];
107     fshift           = fr->fshift[0];
108     facel            = _mm_set1_ps(fr->ic->epsfac);
109     charge           = mdatoms->chargeA;
110
111     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
112     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
113     beta2            = _mm_mul_ps(beta,beta);
114     beta3            = _mm_mul_ps(beta,beta2);
115     ewtab            = fr->ic->tabq_coul_FDV0;
116     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
117     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
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_ps(rcutoff_scalar);
122     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
123
124     /* Avoid stupid compiler warnings */
125     jnrA = jnrB = jnrC = jnrD = 0;
126     j_coord_offsetA = 0;
127     j_coord_offsetB = 0;
128     j_coord_offsetC = 0;
129     j_coord_offsetD = 0;
130
131     outeriter        = 0;
132     inneriter        = 0;
133
134     for(iidx=0;iidx<4*DIM;iidx++)
135     {
136         scratch[iidx] = 0.0;
137     }
138
139     /* Start outer loop over neighborlists */
140     for(iidx=0; iidx<nri; iidx++)
141     {
142         /* Load shift vector for this list */
143         i_shift_offset   = DIM*shiftidx[iidx];
144
145         /* Load limits for loop over neighbors */
146         j_index_start    = jindex[iidx];
147         j_index_end      = jindex[iidx+1];
148
149         /* Get outer coordinate index */
150         inr              = iinr[iidx];
151         i_coord_offset   = DIM*inr;
152
153         /* Load i particle coords and add shift vector */
154         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
155
156         fix0             = _mm_setzero_ps();
157         fiy0             = _mm_setzero_ps();
158         fiz0             = _mm_setzero_ps();
159
160         /* Load parameters for i particles */
161         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
162
163         /* Reset potential sums */
164         velecsum         = _mm_setzero_ps();
165
166         /* Start inner kernel loop */
167         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
168         {
169
170             /* Get j neighbor index, and coordinate index */
171             jnrA             = jjnr[jidx];
172             jnrB             = jjnr[jidx+1];
173             jnrC             = jjnr[jidx+2];
174             jnrD             = jjnr[jidx+3];
175             j_coord_offsetA  = DIM*jnrA;
176             j_coord_offsetB  = DIM*jnrB;
177             j_coord_offsetC  = DIM*jnrC;
178             j_coord_offsetD  = DIM*jnrD;
179
180             /* load j atom coordinates */
181             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
182                                               x+j_coord_offsetC,x+j_coord_offsetD,
183                                               &jx0,&jy0,&jz0);
184
185             /* Calculate displacement vector */
186             dx00             = _mm_sub_ps(ix0,jx0);
187             dy00             = _mm_sub_ps(iy0,jy0);
188             dz00             = _mm_sub_ps(iz0,jz0);
189
190             /* Calculate squared distance and things based on it */
191             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
192
193             rinv00           = avx128fma_invsqrt_f(rsq00);
194
195             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
196
197             /* Load parameters for j particles */
198             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
199                                                               charge+jnrC+0,charge+jnrD+0);
200
201             /**************************
202              * CALCULATE INTERACTIONS *
203              **************************/
204
205             if (gmx_mm_any_lt(rsq00,rcutoff2))
206             {
207
208             r00              = _mm_mul_ps(rsq00,rinv00);
209
210             /* Compute parameters for interactions between i and j atoms */
211             qq00             = _mm_mul_ps(iq0,jq0);
212
213             /* EWALD ELECTROSTATICS */
214
215             /* Analytical PME correction */
216             zeta2            = _mm_mul_ps(beta2,rsq00);
217             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
218             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
219             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
220             felec            = _mm_mul_ps(qq00,felec);
221             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
222             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
223             velec            = _mm_mul_ps(qq00,velec);
224
225             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
226
227             /* Update potential sum for this i atom from the interaction with this j atom. */
228             velec            = _mm_and_ps(velec,cutoff_mask);
229             velecsum         = _mm_add_ps(velecsum,velec);
230
231             fscal            = felec;
232
233             fscal            = _mm_and_ps(fscal,cutoff_mask);
234
235              /* Update vectorial force */
236             fix0             = _mm_macc_ps(dx00,fscal,fix0);
237             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
238             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
239
240             fjptrA             = f+j_coord_offsetA;
241             fjptrB             = f+j_coord_offsetB;
242             fjptrC             = f+j_coord_offsetC;
243             fjptrD             = f+j_coord_offsetD;
244             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
245                                                    _mm_mul_ps(dx00,fscal),
246                                                    _mm_mul_ps(dy00,fscal),
247                                                    _mm_mul_ps(dz00,fscal));
248
249             }
250
251             /* Inner loop uses 33 flops */
252         }
253
254         if(jidx<j_index_end)
255         {
256
257             /* Get j neighbor index, and coordinate index */
258             jnrlistA         = jjnr[jidx];
259             jnrlistB         = jjnr[jidx+1];
260             jnrlistC         = jjnr[jidx+2];
261             jnrlistD         = jjnr[jidx+3];
262             /* Sign of each element will be negative for non-real atoms.
263              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
264              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
265              */
266             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
267             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
268             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
269             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
270             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
271             j_coord_offsetA  = DIM*jnrA;
272             j_coord_offsetB  = DIM*jnrB;
273             j_coord_offsetC  = DIM*jnrC;
274             j_coord_offsetD  = DIM*jnrD;
275
276             /* load j atom coordinates */
277             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
278                                               x+j_coord_offsetC,x+j_coord_offsetD,
279                                               &jx0,&jy0,&jz0);
280
281             /* Calculate displacement vector */
282             dx00             = _mm_sub_ps(ix0,jx0);
283             dy00             = _mm_sub_ps(iy0,jy0);
284             dz00             = _mm_sub_ps(iz0,jz0);
285
286             /* Calculate squared distance and things based on it */
287             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
288
289             rinv00           = avx128fma_invsqrt_f(rsq00);
290
291             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
292
293             /* Load parameters for j particles */
294             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
295                                                               charge+jnrC+0,charge+jnrD+0);
296
297             /**************************
298              * CALCULATE INTERACTIONS *
299              **************************/
300
301             if (gmx_mm_any_lt(rsq00,rcutoff2))
302             {
303
304             r00              = _mm_mul_ps(rsq00,rinv00);
305             r00              = _mm_andnot_ps(dummy_mask,r00);
306
307             /* Compute parameters for interactions between i and j atoms */
308             qq00             = _mm_mul_ps(iq0,jq0);
309
310             /* EWALD ELECTROSTATICS */
311
312             /* Analytical PME correction */
313             zeta2            = _mm_mul_ps(beta2,rsq00);
314             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
315             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
316             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
317             felec            = _mm_mul_ps(qq00,felec);
318             pmecorrV         = avx128fma_pmecorrV_f(zeta2);
319             velec            = _mm_nmacc_ps(pmecorrV,beta,_mm_sub_ps(rinv00,sh_ewald));
320             velec            = _mm_mul_ps(qq00,velec);
321
322             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
323
324             /* Update potential sum for this i atom from the interaction with this j atom. */
325             velec            = _mm_and_ps(velec,cutoff_mask);
326             velec            = _mm_andnot_ps(dummy_mask,velec);
327             velecsum         = _mm_add_ps(velecsum,velec);
328
329             fscal            = felec;
330
331             fscal            = _mm_and_ps(fscal,cutoff_mask);
332
333             fscal            = _mm_andnot_ps(dummy_mask,fscal);
334
335              /* Update vectorial force */
336             fix0             = _mm_macc_ps(dx00,fscal,fix0);
337             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
338             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
339
340             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
341             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
342             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
343             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
344             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
345                                                    _mm_mul_ps(dx00,fscal),
346                                                    _mm_mul_ps(dy00,fscal),
347                                                    _mm_mul_ps(dz00,fscal));
348
349             }
350
351             /* Inner loop uses 34 flops */
352         }
353
354         /* End of innermost loop */
355
356         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
357                                               f+i_coord_offset,fshift+i_shift_offset);
358
359         ggid                        = gid[iidx];
360         /* Update potential energies */
361         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
362
363         /* Increment number of inner iterations */
364         inneriter                  += j_index_end - j_index_start;
365
366         /* Outer loop uses 8 flops */
367     }
368
369     /* Increment number of outer iterations */
370     outeriter        += nri;
371
372     /* Update outer/inner flops */
373
374     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*34);
375 }
376 /*
377  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_avx_128_fma_single
378  * Electrostatics interaction: Ewald
379  * VdW interaction:            None
380  * Geometry:                   Particle-Particle
381  * Calculate force/pot:        Force
382  */
383 void
384 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_avx_128_fma_single
385                     (t_nblist                    * gmx_restrict       nlist,
386                      rvec                        * gmx_restrict          xx,
387                      rvec                        * gmx_restrict          ff,
388                      struct t_forcerec           * gmx_restrict          fr,
389                      t_mdatoms                   * gmx_restrict     mdatoms,
390                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
391                      t_nrnb                      * gmx_restrict        nrnb)
392 {
393     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
394      * just 0 for non-waters.
395      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
396      * jnr indices corresponding to data put in the four positions in the SIMD register.
397      */
398     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
399     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
400     int              jnrA,jnrB,jnrC,jnrD;
401     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
402     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
403     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
404     real             rcutoff_scalar;
405     real             *shiftvec,*fshift,*x,*f;
406     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
407     real             scratch[4*DIM];
408     __m128           fscal,rcutoff,rcutoff2,jidxall;
409     int              vdwioffset0;
410     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
411     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
412     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
413     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
414     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
415     real             *charge;
416     __m128i          ewitab;
417     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
418     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
419     real             *ewtab;
420     __m128           dummy_mask,cutoff_mask;
421     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
422     __m128           one     = _mm_set1_ps(1.0);
423     __m128           two     = _mm_set1_ps(2.0);
424     x                = xx[0];
425     f                = ff[0];
426
427     nri              = nlist->nri;
428     iinr             = nlist->iinr;
429     jindex           = nlist->jindex;
430     jjnr             = nlist->jjnr;
431     shiftidx         = nlist->shift;
432     gid              = nlist->gid;
433     shiftvec         = fr->shift_vec[0];
434     fshift           = fr->fshift[0];
435     facel            = _mm_set1_ps(fr->ic->epsfac);
436     charge           = mdatoms->chargeA;
437
438     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
439     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
440     beta2            = _mm_mul_ps(beta,beta);
441     beta3            = _mm_mul_ps(beta,beta2);
442     ewtab            = fr->ic->tabq_coul_F;
443     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
444     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
445
446     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
447     rcutoff_scalar   = fr->ic->rcoulomb;
448     rcutoff          = _mm_set1_ps(rcutoff_scalar);
449     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
450
451     /* Avoid stupid compiler warnings */
452     jnrA = jnrB = jnrC = jnrD = 0;
453     j_coord_offsetA = 0;
454     j_coord_offsetB = 0;
455     j_coord_offsetC = 0;
456     j_coord_offsetD = 0;
457
458     outeriter        = 0;
459     inneriter        = 0;
460
461     for(iidx=0;iidx<4*DIM;iidx++)
462     {
463         scratch[iidx] = 0.0;
464     }
465
466     /* Start outer loop over neighborlists */
467     for(iidx=0; iidx<nri; iidx++)
468     {
469         /* Load shift vector for this list */
470         i_shift_offset   = DIM*shiftidx[iidx];
471
472         /* Load limits for loop over neighbors */
473         j_index_start    = jindex[iidx];
474         j_index_end      = jindex[iidx+1];
475
476         /* Get outer coordinate index */
477         inr              = iinr[iidx];
478         i_coord_offset   = DIM*inr;
479
480         /* Load i particle coords and add shift vector */
481         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
482
483         fix0             = _mm_setzero_ps();
484         fiy0             = _mm_setzero_ps();
485         fiz0             = _mm_setzero_ps();
486
487         /* Load parameters for i particles */
488         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
489
490         /* Start inner kernel loop */
491         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
492         {
493
494             /* Get j neighbor index, and coordinate index */
495             jnrA             = jjnr[jidx];
496             jnrB             = jjnr[jidx+1];
497             jnrC             = jjnr[jidx+2];
498             jnrD             = jjnr[jidx+3];
499             j_coord_offsetA  = DIM*jnrA;
500             j_coord_offsetB  = DIM*jnrB;
501             j_coord_offsetC  = DIM*jnrC;
502             j_coord_offsetD  = DIM*jnrD;
503
504             /* load j atom coordinates */
505             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
506                                               x+j_coord_offsetC,x+j_coord_offsetD,
507                                               &jx0,&jy0,&jz0);
508
509             /* Calculate displacement vector */
510             dx00             = _mm_sub_ps(ix0,jx0);
511             dy00             = _mm_sub_ps(iy0,jy0);
512             dz00             = _mm_sub_ps(iz0,jz0);
513
514             /* Calculate squared distance and things based on it */
515             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
516
517             rinv00           = avx128fma_invsqrt_f(rsq00);
518
519             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
520
521             /* Load parameters for j particles */
522             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
523                                                               charge+jnrC+0,charge+jnrD+0);
524
525             /**************************
526              * CALCULATE INTERACTIONS *
527              **************************/
528
529             if (gmx_mm_any_lt(rsq00,rcutoff2))
530             {
531
532             r00              = _mm_mul_ps(rsq00,rinv00);
533
534             /* Compute parameters for interactions between i and j atoms */
535             qq00             = _mm_mul_ps(iq0,jq0);
536
537             /* EWALD ELECTROSTATICS */
538
539             /* Analytical PME correction */
540             zeta2            = _mm_mul_ps(beta2,rsq00);
541             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
542             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
543             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
544             felec            = _mm_mul_ps(qq00,felec);
545
546             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
547
548             fscal            = felec;
549
550             fscal            = _mm_and_ps(fscal,cutoff_mask);
551
552              /* Update vectorial force */
553             fix0             = _mm_macc_ps(dx00,fscal,fix0);
554             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
555             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
556
557             fjptrA             = f+j_coord_offsetA;
558             fjptrB             = f+j_coord_offsetB;
559             fjptrC             = f+j_coord_offsetC;
560             fjptrD             = f+j_coord_offsetD;
561             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
562                                                    _mm_mul_ps(dx00,fscal),
563                                                    _mm_mul_ps(dy00,fscal),
564                                                    _mm_mul_ps(dz00,fscal));
565
566             }
567
568             /* Inner loop uses 31 flops */
569         }
570
571         if(jidx<j_index_end)
572         {
573
574             /* Get j neighbor index, and coordinate index */
575             jnrlistA         = jjnr[jidx];
576             jnrlistB         = jjnr[jidx+1];
577             jnrlistC         = jjnr[jidx+2];
578             jnrlistD         = jjnr[jidx+3];
579             /* Sign of each element will be negative for non-real atoms.
580              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
581              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
582              */
583             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
584             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
585             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
586             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
587             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
588             j_coord_offsetA  = DIM*jnrA;
589             j_coord_offsetB  = DIM*jnrB;
590             j_coord_offsetC  = DIM*jnrC;
591             j_coord_offsetD  = DIM*jnrD;
592
593             /* load j atom coordinates */
594             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
595                                               x+j_coord_offsetC,x+j_coord_offsetD,
596                                               &jx0,&jy0,&jz0);
597
598             /* Calculate displacement vector */
599             dx00             = _mm_sub_ps(ix0,jx0);
600             dy00             = _mm_sub_ps(iy0,jy0);
601             dz00             = _mm_sub_ps(iz0,jz0);
602
603             /* Calculate squared distance and things based on it */
604             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
605
606             rinv00           = avx128fma_invsqrt_f(rsq00);
607
608             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
609
610             /* Load parameters for j particles */
611             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
612                                                               charge+jnrC+0,charge+jnrD+0);
613
614             /**************************
615              * CALCULATE INTERACTIONS *
616              **************************/
617
618             if (gmx_mm_any_lt(rsq00,rcutoff2))
619             {
620
621             r00              = _mm_mul_ps(rsq00,rinv00);
622             r00              = _mm_andnot_ps(dummy_mask,r00);
623
624             /* Compute parameters for interactions between i and j atoms */
625             qq00             = _mm_mul_ps(iq0,jq0);
626
627             /* EWALD ELECTROSTATICS */
628
629             /* Analytical PME correction */
630             zeta2            = _mm_mul_ps(beta2,rsq00);
631             rinv3            = _mm_mul_ps(rinvsq00,rinv00);
632             pmecorrF         = avx128fma_pmecorrF_f(zeta2);
633             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
634             felec            = _mm_mul_ps(qq00,felec);
635
636             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
637
638             fscal            = felec;
639
640             fscal            = _mm_and_ps(fscal,cutoff_mask);
641
642             fscal            = _mm_andnot_ps(dummy_mask,fscal);
643
644              /* Update vectorial force */
645             fix0             = _mm_macc_ps(dx00,fscal,fix0);
646             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
647             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
648
649             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
650             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
651             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
652             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
653             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
654                                                    _mm_mul_ps(dx00,fscal),
655                                                    _mm_mul_ps(dy00,fscal),
656                                                    _mm_mul_ps(dz00,fscal));
657
658             }
659
660             /* Inner loop uses 32 flops */
661         }
662
663         /* End of innermost loop */
664
665         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
666                                               f+i_coord_offset,fshift+i_shift_offset);
667
668         /* Increment number of inner iterations */
669         inneriter                  += j_index_end - j_index_start;
670
671         /* Outer loop uses 7 flops */
672     }
673
674     /* Increment number of outer iterations */
675     outeriter        += nri;
676
677     /* Update outer/inner flops */
678
679     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*32);
680 }