Remove no-inline-max-size and suppress remark
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEw_VdwCSTab_GeomW4P1_avx_128_fma_single.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, 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 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "vec.h"
47 #include "nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwCSTab_GeomW4P1_VF_avx_128_fma_single
54  * Electrostatics interaction: Ewald
55  * VdW interaction:            CubicSplineTable
56  * Geometry:                   Water4-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecEw_VdwCSTab_GeomW4P1_VF_avx_128_fma_single
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70      * just 0 for non-waters.
71      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB,jnrC,jnrD;
77     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
80     real             rcutoff_scalar;
81     real             *shiftvec,*fshift,*x,*f;
82     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
83     real             scratch[4*DIM];
84     __m128           fscal,rcutoff,rcutoff2,jidxall;
85     int              vdwioffset0;
86     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87     int              vdwioffset1;
88     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
89     int              vdwioffset2;
90     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
91     int              vdwioffset3;
92     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
100     real             *charge;
101     int              nvdwtype;
102     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103     int              *vdwtype;
104     real             *vdwparam;
105     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
106     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
107     __m128i          vfitab;
108     __m128i          ifour       = _mm_set1_epi32(4);
109     __m128           rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
110     real             *vftab;
111     __m128i          ewitab;
112     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
113     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
114     real             *ewtab;
115     __m128           dummy_mask,cutoff_mask;
116     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
117     __m128           one     = _mm_set1_ps(1.0);
118     __m128           two     = _mm_set1_ps(2.0);
119     x                = xx[0];
120     f                = ff[0];
121
122     nri              = nlist->nri;
123     iinr             = nlist->iinr;
124     jindex           = nlist->jindex;
125     jjnr             = nlist->jjnr;
126     shiftidx         = nlist->shift;
127     gid              = nlist->gid;
128     shiftvec         = fr->shift_vec[0];
129     fshift           = fr->fshift[0];
130     facel            = _mm_set1_ps(fr->epsfac);
131     charge           = mdatoms->chargeA;
132     nvdwtype         = fr->ntype;
133     vdwparam         = fr->nbfp;
134     vdwtype          = mdatoms->typeA;
135
136     vftab            = kernel_data->table_vdw->data;
137     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
138
139     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
140     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
141     beta2            = _mm_mul_ps(beta,beta);
142     beta3            = _mm_mul_ps(beta,beta2);
143     ewtab            = fr->ic->tabq_coul_FDV0;
144     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
145     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
146
147     /* Setup water-specific parameters */
148     inr              = nlist->iinr[0];
149     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
150     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
151     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
152     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
153
154     /* Avoid stupid compiler warnings */
155     jnrA = jnrB = jnrC = jnrD = 0;
156     j_coord_offsetA = 0;
157     j_coord_offsetB = 0;
158     j_coord_offsetC = 0;
159     j_coord_offsetD = 0;
160
161     outeriter        = 0;
162     inneriter        = 0;
163
164     for(iidx=0;iidx<4*DIM;iidx++)
165     {
166         scratch[iidx] = 0.0;
167     }
168
169     /* Start outer loop over neighborlists */
170     for(iidx=0; iidx<nri; iidx++)
171     {
172         /* Load shift vector for this list */
173         i_shift_offset   = DIM*shiftidx[iidx];
174
175         /* Load limits for loop over neighbors */
176         j_index_start    = jindex[iidx];
177         j_index_end      = jindex[iidx+1];
178
179         /* Get outer coordinate index */
180         inr              = iinr[iidx];
181         i_coord_offset   = DIM*inr;
182
183         /* Load i particle coords and add shift vector */
184         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
185                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
186
187         fix0             = _mm_setzero_ps();
188         fiy0             = _mm_setzero_ps();
189         fiz0             = _mm_setzero_ps();
190         fix1             = _mm_setzero_ps();
191         fiy1             = _mm_setzero_ps();
192         fiz1             = _mm_setzero_ps();
193         fix2             = _mm_setzero_ps();
194         fiy2             = _mm_setzero_ps();
195         fiz2             = _mm_setzero_ps();
196         fix3             = _mm_setzero_ps();
197         fiy3             = _mm_setzero_ps();
198         fiz3             = _mm_setzero_ps();
199
200         /* Reset potential sums */
201         velecsum         = _mm_setzero_ps();
202         vvdwsum          = _mm_setzero_ps();
203
204         /* Start inner kernel loop */
205         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
206         {
207
208             /* Get j neighbor index, and coordinate index */
209             jnrA             = jjnr[jidx];
210             jnrB             = jjnr[jidx+1];
211             jnrC             = jjnr[jidx+2];
212             jnrD             = jjnr[jidx+3];
213             j_coord_offsetA  = DIM*jnrA;
214             j_coord_offsetB  = DIM*jnrB;
215             j_coord_offsetC  = DIM*jnrC;
216             j_coord_offsetD  = DIM*jnrD;
217
218             /* load j atom coordinates */
219             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
220                                               x+j_coord_offsetC,x+j_coord_offsetD,
221                                               &jx0,&jy0,&jz0);
222
223             /* Calculate displacement vector */
224             dx00             = _mm_sub_ps(ix0,jx0);
225             dy00             = _mm_sub_ps(iy0,jy0);
226             dz00             = _mm_sub_ps(iz0,jz0);
227             dx10             = _mm_sub_ps(ix1,jx0);
228             dy10             = _mm_sub_ps(iy1,jy0);
229             dz10             = _mm_sub_ps(iz1,jz0);
230             dx20             = _mm_sub_ps(ix2,jx0);
231             dy20             = _mm_sub_ps(iy2,jy0);
232             dz20             = _mm_sub_ps(iz2,jz0);
233             dx30             = _mm_sub_ps(ix3,jx0);
234             dy30             = _mm_sub_ps(iy3,jy0);
235             dz30             = _mm_sub_ps(iz3,jz0);
236
237             /* Calculate squared distance and things based on it */
238             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
239             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
240             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
241             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
242
243             rinv00           = gmx_mm_invsqrt_ps(rsq00);
244             rinv10           = gmx_mm_invsqrt_ps(rsq10);
245             rinv20           = gmx_mm_invsqrt_ps(rsq20);
246             rinv30           = gmx_mm_invsqrt_ps(rsq30);
247
248             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
249             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
250             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
251
252             /* Load parameters for j particles */
253             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
254                                                               charge+jnrC+0,charge+jnrD+0);
255             vdwjidx0A        = 2*vdwtype[jnrA+0];
256             vdwjidx0B        = 2*vdwtype[jnrB+0];
257             vdwjidx0C        = 2*vdwtype[jnrC+0];
258             vdwjidx0D        = 2*vdwtype[jnrD+0];
259
260             fjx0             = _mm_setzero_ps();
261             fjy0             = _mm_setzero_ps();
262             fjz0             = _mm_setzero_ps();
263
264             /**************************
265              * CALCULATE INTERACTIONS *
266              **************************/
267
268             r00              = _mm_mul_ps(rsq00,rinv00);
269
270             /* Compute parameters for interactions between i and j atoms */
271             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
272                                          vdwparam+vdwioffset0+vdwjidx0B,
273                                          vdwparam+vdwioffset0+vdwjidx0C,
274                                          vdwparam+vdwioffset0+vdwjidx0D,
275                                          &c6_00,&c12_00);
276
277             /* Calculate table index by multiplying r with table scale and truncate to integer */
278             rt               = _mm_mul_ps(r00,vftabscale);
279             vfitab           = _mm_cvttps_epi32(rt);
280 #ifdef __XOP__
281             vfeps            = _mm_frcz_ps(rt);
282 #else
283             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
284 #endif
285             twovfeps         = _mm_add_ps(vfeps,vfeps);
286             vfitab           = _mm_slli_epi32(vfitab,3);
287
288             /* CUBIC SPLINE TABLE DISPERSION */
289             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
290             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
291             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
292             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
293             _MM_TRANSPOSE4_PS(Y,F,G,H);
294             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
295             VV               = _mm_macc_ps(vfeps,Fp,Y);
296             vvdw6            = _mm_mul_ps(c6_00,VV);
297             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
298             fvdw6            = _mm_mul_ps(c6_00,FF);
299
300             /* CUBIC SPLINE TABLE REPULSION */
301             vfitab           = _mm_add_epi32(vfitab,ifour);
302             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
303             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
304             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
305             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
306             _MM_TRANSPOSE4_PS(Y,F,G,H);
307             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
308             VV               = _mm_macc_ps(vfeps,Fp,Y);
309             vvdw12           = _mm_mul_ps(c12_00,VV);
310             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
311             fvdw12           = _mm_mul_ps(c12_00,FF);
312             vvdw             = _mm_add_ps(vvdw12,vvdw6);
313             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
314
315             /* Update potential sum for this i atom from the interaction with this j atom. */
316             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
317
318             fscal            = fvdw;
319
320              /* Update vectorial force */
321             fix0             = _mm_macc_ps(dx00,fscal,fix0);
322             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
323             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
324
325             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
326             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
327             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
328
329             /**************************
330              * CALCULATE INTERACTIONS *
331              **************************/
332
333             r10              = _mm_mul_ps(rsq10,rinv10);
334
335             /* Compute parameters for interactions between i and j atoms */
336             qq10             = _mm_mul_ps(iq1,jq0);
337
338             /* EWALD ELECTROSTATICS */
339
340             /* Analytical PME correction */
341             zeta2            = _mm_mul_ps(beta2,rsq10);
342             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
343             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
344             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
345             felec            = _mm_mul_ps(qq10,felec);
346             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
347             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv10);
348             velec            = _mm_mul_ps(qq10,velec);
349
350             /* Update potential sum for this i atom from the interaction with this j atom. */
351             velecsum         = _mm_add_ps(velecsum,velec);
352
353             fscal            = felec;
354
355              /* Update vectorial force */
356             fix1             = _mm_macc_ps(dx10,fscal,fix1);
357             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
358             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
359
360             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
361             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
362             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
363
364             /**************************
365              * CALCULATE INTERACTIONS *
366              **************************/
367
368             r20              = _mm_mul_ps(rsq20,rinv20);
369
370             /* Compute parameters for interactions between i and j atoms */
371             qq20             = _mm_mul_ps(iq2,jq0);
372
373             /* EWALD ELECTROSTATICS */
374
375             /* Analytical PME correction */
376             zeta2            = _mm_mul_ps(beta2,rsq20);
377             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
378             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
379             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
380             felec            = _mm_mul_ps(qq20,felec);
381             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
382             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv20);
383             velec            = _mm_mul_ps(qq20,velec);
384
385             /* Update potential sum for this i atom from the interaction with this j atom. */
386             velecsum         = _mm_add_ps(velecsum,velec);
387
388             fscal            = felec;
389
390              /* Update vectorial force */
391             fix2             = _mm_macc_ps(dx20,fscal,fix2);
392             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
393             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
394
395             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
396             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
397             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
398
399             /**************************
400              * CALCULATE INTERACTIONS *
401              **************************/
402
403             r30              = _mm_mul_ps(rsq30,rinv30);
404
405             /* Compute parameters for interactions between i and j atoms */
406             qq30             = _mm_mul_ps(iq3,jq0);
407
408             /* EWALD ELECTROSTATICS */
409
410             /* Analytical PME correction */
411             zeta2            = _mm_mul_ps(beta2,rsq30);
412             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
413             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
414             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
415             felec            = _mm_mul_ps(qq30,felec);
416             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
417             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv30);
418             velec            = _mm_mul_ps(qq30,velec);
419
420             /* Update potential sum for this i atom from the interaction with this j atom. */
421             velecsum         = _mm_add_ps(velecsum,velec);
422
423             fscal            = felec;
424
425              /* Update vectorial force */
426             fix3             = _mm_macc_ps(dx30,fscal,fix3);
427             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
428             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
429
430             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
431             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
432             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
433
434             fjptrA             = f+j_coord_offsetA;
435             fjptrB             = f+j_coord_offsetB;
436             fjptrC             = f+j_coord_offsetC;
437             fjptrD             = f+j_coord_offsetD;
438
439             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
440
441             /* Inner loop uses 146 flops */
442         }
443
444         if(jidx<j_index_end)
445         {
446
447             /* Get j neighbor index, and coordinate index */
448             jnrlistA         = jjnr[jidx];
449             jnrlistB         = jjnr[jidx+1];
450             jnrlistC         = jjnr[jidx+2];
451             jnrlistD         = jjnr[jidx+3];
452             /* Sign of each element will be negative for non-real atoms.
453              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
454              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
455              */
456             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
457             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
458             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
459             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
460             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
461             j_coord_offsetA  = DIM*jnrA;
462             j_coord_offsetB  = DIM*jnrB;
463             j_coord_offsetC  = DIM*jnrC;
464             j_coord_offsetD  = DIM*jnrD;
465
466             /* load j atom coordinates */
467             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
468                                               x+j_coord_offsetC,x+j_coord_offsetD,
469                                               &jx0,&jy0,&jz0);
470
471             /* Calculate displacement vector */
472             dx00             = _mm_sub_ps(ix0,jx0);
473             dy00             = _mm_sub_ps(iy0,jy0);
474             dz00             = _mm_sub_ps(iz0,jz0);
475             dx10             = _mm_sub_ps(ix1,jx0);
476             dy10             = _mm_sub_ps(iy1,jy0);
477             dz10             = _mm_sub_ps(iz1,jz0);
478             dx20             = _mm_sub_ps(ix2,jx0);
479             dy20             = _mm_sub_ps(iy2,jy0);
480             dz20             = _mm_sub_ps(iz2,jz0);
481             dx30             = _mm_sub_ps(ix3,jx0);
482             dy30             = _mm_sub_ps(iy3,jy0);
483             dz30             = _mm_sub_ps(iz3,jz0);
484
485             /* Calculate squared distance and things based on it */
486             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
487             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
488             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
489             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
490
491             rinv00           = gmx_mm_invsqrt_ps(rsq00);
492             rinv10           = gmx_mm_invsqrt_ps(rsq10);
493             rinv20           = gmx_mm_invsqrt_ps(rsq20);
494             rinv30           = gmx_mm_invsqrt_ps(rsq30);
495
496             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
497             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
498             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
499
500             /* Load parameters for j particles */
501             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
502                                                               charge+jnrC+0,charge+jnrD+0);
503             vdwjidx0A        = 2*vdwtype[jnrA+0];
504             vdwjidx0B        = 2*vdwtype[jnrB+0];
505             vdwjidx0C        = 2*vdwtype[jnrC+0];
506             vdwjidx0D        = 2*vdwtype[jnrD+0];
507
508             fjx0             = _mm_setzero_ps();
509             fjy0             = _mm_setzero_ps();
510             fjz0             = _mm_setzero_ps();
511
512             /**************************
513              * CALCULATE INTERACTIONS *
514              **************************/
515
516             r00              = _mm_mul_ps(rsq00,rinv00);
517             r00              = _mm_andnot_ps(dummy_mask,r00);
518
519             /* Compute parameters for interactions between i and j atoms */
520             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
521                                          vdwparam+vdwioffset0+vdwjidx0B,
522                                          vdwparam+vdwioffset0+vdwjidx0C,
523                                          vdwparam+vdwioffset0+vdwjidx0D,
524                                          &c6_00,&c12_00);
525
526             /* Calculate table index by multiplying r with table scale and truncate to integer */
527             rt               = _mm_mul_ps(r00,vftabscale);
528             vfitab           = _mm_cvttps_epi32(rt);
529 #ifdef __XOP__
530             vfeps            = _mm_frcz_ps(rt);
531 #else
532             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
533 #endif
534             twovfeps         = _mm_add_ps(vfeps,vfeps);
535             vfitab           = _mm_slli_epi32(vfitab,3);
536
537             /* CUBIC SPLINE TABLE DISPERSION */
538             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
539             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
540             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
541             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
542             _MM_TRANSPOSE4_PS(Y,F,G,H);
543             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
544             VV               = _mm_macc_ps(vfeps,Fp,Y);
545             vvdw6            = _mm_mul_ps(c6_00,VV);
546             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
547             fvdw6            = _mm_mul_ps(c6_00,FF);
548
549             /* CUBIC SPLINE TABLE REPULSION */
550             vfitab           = _mm_add_epi32(vfitab,ifour);
551             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
552             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
553             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
554             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
555             _MM_TRANSPOSE4_PS(Y,F,G,H);
556             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
557             VV               = _mm_macc_ps(vfeps,Fp,Y);
558             vvdw12           = _mm_mul_ps(c12_00,VV);
559             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
560             fvdw12           = _mm_mul_ps(c12_00,FF);
561             vvdw             = _mm_add_ps(vvdw12,vvdw6);
562             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
563
564             /* Update potential sum for this i atom from the interaction with this j atom. */
565             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
566             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
567
568             fscal            = fvdw;
569
570             fscal            = _mm_andnot_ps(dummy_mask,fscal);
571
572              /* Update vectorial force */
573             fix0             = _mm_macc_ps(dx00,fscal,fix0);
574             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
575             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
576
577             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
578             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
579             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
580
581             /**************************
582              * CALCULATE INTERACTIONS *
583              **************************/
584
585             r10              = _mm_mul_ps(rsq10,rinv10);
586             r10              = _mm_andnot_ps(dummy_mask,r10);
587
588             /* Compute parameters for interactions between i and j atoms */
589             qq10             = _mm_mul_ps(iq1,jq0);
590
591             /* EWALD ELECTROSTATICS */
592
593             /* Analytical PME correction */
594             zeta2            = _mm_mul_ps(beta2,rsq10);
595             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
596             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
597             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
598             felec            = _mm_mul_ps(qq10,felec);
599             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
600             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv10);
601             velec            = _mm_mul_ps(qq10,velec);
602
603             /* Update potential sum for this i atom from the interaction with this j atom. */
604             velec            = _mm_andnot_ps(dummy_mask,velec);
605             velecsum         = _mm_add_ps(velecsum,velec);
606
607             fscal            = felec;
608
609             fscal            = _mm_andnot_ps(dummy_mask,fscal);
610
611              /* Update vectorial force */
612             fix1             = _mm_macc_ps(dx10,fscal,fix1);
613             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
614             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
615
616             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
617             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
618             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
619
620             /**************************
621              * CALCULATE INTERACTIONS *
622              **************************/
623
624             r20              = _mm_mul_ps(rsq20,rinv20);
625             r20              = _mm_andnot_ps(dummy_mask,r20);
626
627             /* Compute parameters for interactions between i and j atoms */
628             qq20             = _mm_mul_ps(iq2,jq0);
629
630             /* EWALD ELECTROSTATICS */
631
632             /* Analytical PME correction */
633             zeta2            = _mm_mul_ps(beta2,rsq20);
634             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
635             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
636             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
637             felec            = _mm_mul_ps(qq20,felec);
638             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
639             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv20);
640             velec            = _mm_mul_ps(qq20,velec);
641
642             /* Update potential sum for this i atom from the interaction with this j atom. */
643             velec            = _mm_andnot_ps(dummy_mask,velec);
644             velecsum         = _mm_add_ps(velecsum,velec);
645
646             fscal            = felec;
647
648             fscal            = _mm_andnot_ps(dummy_mask,fscal);
649
650              /* Update vectorial force */
651             fix2             = _mm_macc_ps(dx20,fscal,fix2);
652             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
653             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
654
655             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
656             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
657             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
658
659             /**************************
660              * CALCULATE INTERACTIONS *
661              **************************/
662
663             r30              = _mm_mul_ps(rsq30,rinv30);
664             r30              = _mm_andnot_ps(dummy_mask,r30);
665
666             /* Compute parameters for interactions between i and j atoms */
667             qq30             = _mm_mul_ps(iq3,jq0);
668
669             /* EWALD ELECTROSTATICS */
670
671             /* Analytical PME correction */
672             zeta2            = _mm_mul_ps(beta2,rsq30);
673             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
674             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
675             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
676             felec            = _mm_mul_ps(qq30,felec);
677             pmecorrV         = gmx_mm_pmecorrV_ps(zeta2);
678             velec            = _mm_nmacc_ps(pmecorrV,beta,rinv30);
679             velec            = _mm_mul_ps(qq30,velec);
680
681             /* Update potential sum for this i atom from the interaction with this j atom. */
682             velec            = _mm_andnot_ps(dummy_mask,velec);
683             velecsum         = _mm_add_ps(velecsum,velec);
684
685             fscal            = felec;
686
687             fscal            = _mm_andnot_ps(dummy_mask,fscal);
688
689              /* Update vectorial force */
690             fix3             = _mm_macc_ps(dx30,fscal,fix3);
691             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
692             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
693
694             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
695             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
696             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
697
698             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
699             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
700             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
701             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
702
703             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
704
705             /* Inner loop uses 150 flops */
706         }
707
708         /* End of innermost loop */
709
710         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
711                                               f+i_coord_offset,fshift+i_shift_offset);
712
713         ggid                        = gid[iidx];
714         /* Update potential energies */
715         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
716         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
717
718         /* Increment number of inner iterations */
719         inneriter                  += j_index_end - j_index_start;
720
721         /* Outer loop uses 26 flops */
722     }
723
724     /* Increment number of outer iterations */
725     outeriter        += nri;
726
727     /* Update outer/inner flops */
728
729     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*150);
730 }
731 /*
732  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwCSTab_GeomW4P1_F_avx_128_fma_single
733  * Electrostatics interaction: Ewald
734  * VdW interaction:            CubicSplineTable
735  * Geometry:                   Water4-Particle
736  * Calculate force/pot:        Force
737  */
738 void
739 nb_kernel_ElecEw_VdwCSTab_GeomW4P1_F_avx_128_fma_single
740                     (t_nblist                    * gmx_restrict       nlist,
741                      rvec                        * gmx_restrict          xx,
742                      rvec                        * gmx_restrict          ff,
743                      t_forcerec                  * gmx_restrict          fr,
744                      t_mdatoms                   * gmx_restrict     mdatoms,
745                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
746                      t_nrnb                      * gmx_restrict        nrnb)
747 {
748     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
749      * just 0 for non-waters.
750      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
751      * jnr indices corresponding to data put in the four positions in the SIMD register.
752      */
753     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
754     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
755     int              jnrA,jnrB,jnrC,jnrD;
756     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
757     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
758     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
759     real             rcutoff_scalar;
760     real             *shiftvec,*fshift,*x,*f;
761     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
762     real             scratch[4*DIM];
763     __m128           fscal,rcutoff,rcutoff2,jidxall;
764     int              vdwioffset0;
765     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
766     int              vdwioffset1;
767     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
768     int              vdwioffset2;
769     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
770     int              vdwioffset3;
771     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
772     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
773     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
774     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
775     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
776     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
777     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
778     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
779     real             *charge;
780     int              nvdwtype;
781     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
782     int              *vdwtype;
783     real             *vdwparam;
784     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
785     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
786     __m128i          vfitab;
787     __m128i          ifour       = _mm_set1_epi32(4);
788     __m128           rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
789     real             *vftab;
790     __m128i          ewitab;
791     __m128           ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
792     __m128           beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
793     real             *ewtab;
794     __m128           dummy_mask,cutoff_mask;
795     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
796     __m128           one     = _mm_set1_ps(1.0);
797     __m128           two     = _mm_set1_ps(2.0);
798     x                = xx[0];
799     f                = ff[0];
800
801     nri              = nlist->nri;
802     iinr             = nlist->iinr;
803     jindex           = nlist->jindex;
804     jjnr             = nlist->jjnr;
805     shiftidx         = nlist->shift;
806     gid              = nlist->gid;
807     shiftvec         = fr->shift_vec[0];
808     fshift           = fr->fshift[0];
809     facel            = _mm_set1_ps(fr->epsfac);
810     charge           = mdatoms->chargeA;
811     nvdwtype         = fr->ntype;
812     vdwparam         = fr->nbfp;
813     vdwtype          = mdatoms->typeA;
814
815     vftab            = kernel_data->table_vdw->data;
816     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
817
818     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
819     beta             = _mm_set1_ps(fr->ic->ewaldcoeff_q);
820     beta2            = _mm_mul_ps(beta,beta);
821     beta3            = _mm_mul_ps(beta,beta2);
822     ewtab            = fr->ic->tabq_coul_F;
823     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
824     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
825
826     /* Setup water-specific parameters */
827     inr              = nlist->iinr[0];
828     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
829     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
830     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
831     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
832
833     /* Avoid stupid compiler warnings */
834     jnrA = jnrB = jnrC = jnrD = 0;
835     j_coord_offsetA = 0;
836     j_coord_offsetB = 0;
837     j_coord_offsetC = 0;
838     j_coord_offsetD = 0;
839
840     outeriter        = 0;
841     inneriter        = 0;
842
843     for(iidx=0;iidx<4*DIM;iidx++)
844     {
845         scratch[iidx] = 0.0;
846     }
847
848     /* Start outer loop over neighborlists */
849     for(iidx=0; iidx<nri; iidx++)
850     {
851         /* Load shift vector for this list */
852         i_shift_offset   = DIM*shiftidx[iidx];
853
854         /* Load limits for loop over neighbors */
855         j_index_start    = jindex[iidx];
856         j_index_end      = jindex[iidx+1];
857
858         /* Get outer coordinate index */
859         inr              = iinr[iidx];
860         i_coord_offset   = DIM*inr;
861
862         /* Load i particle coords and add shift vector */
863         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
864                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
865
866         fix0             = _mm_setzero_ps();
867         fiy0             = _mm_setzero_ps();
868         fiz0             = _mm_setzero_ps();
869         fix1             = _mm_setzero_ps();
870         fiy1             = _mm_setzero_ps();
871         fiz1             = _mm_setzero_ps();
872         fix2             = _mm_setzero_ps();
873         fiy2             = _mm_setzero_ps();
874         fiz2             = _mm_setzero_ps();
875         fix3             = _mm_setzero_ps();
876         fiy3             = _mm_setzero_ps();
877         fiz3             = _mm_setzero_ps();
878
879         /* Start inner kernel loop */
880         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
881         {
882
883             /* Get j neighbor index, and coordinate index */
884             jnrA             = jjnr[jidx];
885             jnrB             = jjnr[jidx+1];
886             jnrC             = jjnr[jidx+2];
887             jnrD             = jjnr[jidx+3];
888             j_coord_offsetA  = DIM*jnrA;
889             j_coord_offsetB  = DIM*jnrB;
890             j_coord_offsetC  = DIM*jnrC;
891             j_coord_offsetD  = DIM*jnrD;
892
893             /* load j atom coordinates */
894             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
895                                               x+j_coord_offsetC,x+j_coord_offsetD,
896                                               &jx0,&jy0,&jz0);
897
898             /* Calculate displacement vector */
899             dx00             = _mm_sub_ps(ix0,jx0);
900             dy00             = _mm_sub_ps(iy0,jy0);
901             dz00             = _mm_sub_ps(iz0,jz0);
902             dx10             = _mm_sub_ps(ix1,jx0);
903             dy10             = _mm_sub_ps(iy1,jy0);
904             dz10             = _mm_sub_ps(iz1,jz0);
905             dx20             = _mm_sub_ps(ix2,jx0);
906             dy20             = _mm_sub_ps(iy2,jy0);
907             dz20             = _mm_sub_ps(iz2,jz0);
908             dx30             = _mm_sub_ps(ix3,jx0);
909             dy30             = _mm_sub_ps(iy3,jy0);
910             dz30             = _mm_sub_ps(iz3,jz0);
911
912             /* Calculate squared distance and things based on it */
913             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
914             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
915             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
916             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
917
918             rinv00           = gmx_mm_invsqrt_ps(rsq00);
919             rinv10           = gmx_mm_invsqrt_ps(rsq10);
920             rinv20           = gmx_mm_invsqrt_ps(rsq20);
921             rinv30           = gmx_mm_invsqrt_ps(rsq30);
922
923             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
924             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
925             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
926
927             /* Load parameters for j particles */
928             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
929                                                               charge+jnrC+0,charge+jnrD+0);
930             vdwjidx0A        = 2*vdwtype[jnrA+0];
931             vdwjidx0B        = 2*vdwtype[jnrB+0];
932             vdwjidx0C        = 2*vdwtype[jnrC+0];
933             vdwjidx0D        = 2*vdwtype[jnrD+0];
934
935             fjx0             = _mm_setzero_ps();
936             fjy0             = _mm_setzero_ps();
937             fjz0             = _mm_setzero_ps();
938
939             /**************************
940              * CALCULATE INTERACTIONS *
941              **************************/
942
943             r00              = _mm_mul_ps(rsq00,rinv00);
944
945             /* Compute parameters for interactions between i and j atoms */
946             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
947                                          vdwparam+vdwioffset0+vdwjidx0B,
948                                          vdwparam+vdwioffset0+vdwjidx0C,
949                                          vdwparam+vdwioffset0+vdwjidx0D,
950                                          &c6_00,&c12_00);
951
952             /* Calculate table index by multiplying r with table scale and truncate to integer */
953             rt               = _mm_mul_ps(r00,vftabscale);
954             vfitab           = _mm_cvttps_epi32(rt);
955 #ifdef __XOP__
956             vfeps            = _mm_frcz_ps(rt);
957 #else
958             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
959 #endif
960             twovfeps         = _mm_add_ps(vfeps,vfeps);
961             vfitab           = _mm_slli_epi32(vfitab,3);
962
963             /* CUBIC SPLINE TABLE DISPERSION */
964             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
965             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
966             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
967             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
968             _MM_TRANSPOSE4_PS(Y,F,G,H);
969             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
970             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
971             fvdw6            = _mm_mul_ps(c6_00,FF);
972
973             /* CUBIC SPLINE TABLE REPULSION */
974             vfitab           = _mm_add_epi32(vfitab,ifour);
975             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
976             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
977             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
978             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
979             _MM_TRANSPOSE4_PS(Y,F,G,H);
980             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
981             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
982             fvdw12           = _mm_mul_ps(c12_00,FF);
983             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
984
985             fscal            = fvdw;
986
987              /* Update vectorial force */
988             fix0             = _mm_macc_ps(dx00,fscal,fix0);
989             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
990             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
991
992             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
993             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
994             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
995
996             /**************************
997              * CALCULATE INTERACTIONS *
998              **************************/
999
1000             r10              = _mm_mul_ps(rsq10,rinv10);
1001
1002             /* Compute parameters for interactions between i and j atoms */
1003             qq10             = _mm_mul_ps(iq1,jq0);
1004
1005             /* EWALD ELECTROSTATICS */
1006
1007             /* Analytical PME correction */
1008             zeta2            = _mm_mul_ps(beta2,rsq10);
1009             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
1010             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1011             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1012             felec            = _mm_mul_ps(qq10,felec);
1013
1014             fscal            = felec;
1015
1016              /* Update vectorial force */
1017             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1018             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1019             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1020
1021             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1022             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1023             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1024
1025             /**************************
1026              * CALCULATE INTERACTIONS *
1027              **************************/
1028
1029             r20              = _mm_mul_ps(rsq20,rinv20);
1030
1031             /* Compute parameters for interactions between i and j atoms */
1032             qq20             = _mm_mul_ps(iq2,jq0);
1033
1034             /* EWALD ELECTROSTATICS */
1035
1036             /* Analytical PME correction */
1037             zeta2            = _mm_mul_ps(beta2,rsq20);
1038             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1039             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1040             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1041             felec            = _mm_mul_ps(qq20,felec);
1042
1043             fscal            = felec;
1044
1045              /* Update vectorial force */
1046             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1047             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1048             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1049
1050             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1051             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1052             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1053
1054             /**************************
1055              * CALCULATE INTERACTIONS *
1056              **************************/
1057
1058             r30              = _mm_mul_ps(rsq30,rinv30);
1059
1060             /* Compute parameters for interactions between i and j atoms */
1061             qq30             = _mm_mul_ps(iq3,jq0);
1062
1063             /* EWALD ELECTROSTATICS */
1064
1065             /* Analytical PME correction */
1066             zeta2            = _mm_mul_ps(beta2,rsq30);
1067             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
1068             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1069             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1070             felec            = _mm_mul_ps(qq30,felec);
1071
1072             fscal            = felec;
1073
1074              /* Update vectorial force */
1075             fix3             = _mm_macc_ps(dx30,fscal,fix3);
1076             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
1077             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
1078
1079             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
1080             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
1081             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
1082
1083             fjptrA             = f+j_coord_offsetA;
1084             fjptrB             = f+j_coord_offsetB;
1085             fjptrC             = f+j_coord_offsetC;
1086             fjptrD             = f+j_coord_offsetD;
1087
1088             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1089
1090             /* Inner loop uses 135 flops */
1091         }
1092
1093         if(jidx<j_index_end)
1094         {
1095
1096             /* Get j neighbor index, and coordinate index */
1097             jnrlistA         = jjnr[jidx];
1098             jnrlistB         = jjnr[jidx+1];
1099             jnrlistC         = jjnr[jidx+2];
1100             jnrlistD         = jjnr[jidx+3];
1101             /* Sign of each element will be negative for non-real atoms.
1102              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1103              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1104              */
1105             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1106             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1107             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1108             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1109             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1110             j_coord_offsetA  = DIM*jnrA;
1111             j_coord_offsetB  = DIM*jnrB;
1112             j_coord_offsetC  = DIM*jnrC;
1113             j_coord_offsetD  = DIM*jnrD;
1114
1115             /* load j atom coordinates */
1116             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1117                                               x+j_coord_offsetC,x+j_coord_offsetD,
1118                                               &jx0,&jy0,&jz0);
1119
1120             /* Calculate displacement vector */
1121             dx00             = _mm_sub_ps(ix0,jx0);
1122             dy00             = _mm_sub_ps(iy0,jy0);
1123             dz00             = _mm_sub_ps(iz0,jz0);
1124             dx10             = _mm_sub_ps(ix1,jx0);
1125             dy10             = _mm_sub_ps(iy1,jy0);
1126             dz10             = _mm_sub_ps(iz1,jz0);
1127             dx20             = _mm_sub_ps(ix2,jx0);
1128             dy20             = _mm_sub_ps(iy2,jy0);
1129             dz20             = _mm_sub_ps(iz2,jz0);
1130             dx30             = _mm_sub_ps(ix3,jx0);
1131             dy30             = _mm_sub_ps(iy3,jy0);
1132             dz30             = _mm_sub_ps(iz3,jz0);
1133
1134             /* Calculate squared distance and things based on it */
1135             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1136             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1137             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1138             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1139
1140             rinv00           = gmx_mm_invsqrt_ps(rsq00);
1141             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1142             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1143             rinv30           = gmx_mm_invsqrt_ps(rsq30);
1144
1145             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1146             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1147             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
1148
1149             /* Load parameters for j particles */
1150             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1151                                                               charge+jnrC+0,charge+jnrD+0);
1152             vdwjidx0A        = 2*vdwtype[jnrA+0];
1153             vdwjidx0B        = 2*vdwtype[jnrB+0];
1154             vdwjidx0C        = 2*vdwtype[jnrC+0];
1155             vdwjidx0D        = 2*vdwtype[jnrD+0];
1156
1157             fjx0             = _mm_setzero_ps();
1158             fjy0             = _mm_setzero_ps();
1159             fjz0             = _mm_setzero_ps();
1160
1161             /**************************
1162              * CALCULATE INTERACTIONS *
1163              **************************/
1164
1165             r00              = _mm_mul_ps(rsq00,rinv00);
1166             r00              = _mm_andnot_ps(dummy_mask,r00);
1167
1168             /* Compute parameters for interactions between i and j atoms */
1169             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1170                                          vdwparam+vdwioffset0+vdwjidx0B,
1171                                          vdwparam+vdwioffset0+vdwjidx0C,
1172                                          vdwparam+vdwioffset0+vdwjidx0D,
1173                                          &c6_00,&c12_00);
1174
1175             /* Calculate table index by multiplying r with table scale and truncate to integer */
1176             rt               = _mm_mul_ps(r00,vftabscale);
1177             vfitab           = _mm_cvttps_epi32(rt);
1178 #ifdef __XOP__
1179             vfeps            = _mm_frcz_ps(rt);
1180 #else
1181             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1182 #endif
1183             twovfeps         = _mm_add_ps(vfeps,vfeps);
1184             vfitab           = _mm_slli_epi32(vfitab,3);
1185
1186             /* CUBIC SPLINE TABLE DISPERSION */
1187             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1188             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1189             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1190             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1191             _MM_TRANSPOSE4_PS(Y,F,G,H);
1192             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1193             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1194             fvdw6            = _mm_mul_ps(c6_00,FF);
1195
1196             /* CUBIC SPLINE TABLE REPULSION */
1197             vfitab           = _mm_add_epi32(vfitab,ifour);
1198             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1199             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1200             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1201             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1202             _MM_TRANSPOSE4_PS(Y,F,G,H);
1203             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1204             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1205             fvdw12           = _mm_mul_ps(c12_00,FF);
1206             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1207
1208             fscal            = fvdw;
1209
1210             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1211
1212              /* Update vectorial force */
1213             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1214             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1215             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1216
1217             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1218             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1219             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1220
1221             /**************************
1222              * CALCULATE INTERACTIONS *
1223              **************************/
1224
1225             r10              = _mm_mul_ps(rsq10,rinv10);
1226             r10              = _mm_andnot_ps(dummy_mask,r10);
1227
1228             /* Compute parameters for interactions between i and j atoms */
1229             qq10             = _mm_mul_ps(iq1,jq0);
1230
1231             /* EWALD ELECTROSTATICS */
1232
1233             /* Analytical PME correction */
1234             zeta2            = _mm_mul_ps(beta2,rsq10);
1235             rinv3            = _mm_mul_ps(rinvsq10,rinv10);
1236             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1237             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1238             felec            = _mm_mul_ps(qq10,felec);
1239
1240             fscal            = felec;
1241
1242             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1243
1244              /* Update vectorial force */
1245             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1246             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1247             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1248
1249             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1250             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1251             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1252
1253             /**************************
1254              * CALCULATE INTERACTIONS *
1255              **************************/
1256
1257             r20              = _mm_mul_ps(rsq20,rinv20);
1258             r20              = _mm_andnot_ps(dummy_mask,r20);
1259
1260             /* Compute parameters for interactions between i and j atoms */
1261             qq20             = _mm_mul_ps(iq2,jq0);
1262
1263             /* EWALD ELECTROSTATICS */
1264
1265             /* Analytical PME correction */
1266             zeta2            = _mm_mul_ps(beta2,rsq20);
1267             rinv3            = _mm_mul_ps(rinvsq20,rinv20);
1268             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1269             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1270             felec            = _mm_mul_ps(qq20,felec);
1271
1272             fscal            = felec;
1273
1274             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1275
1276              /* Update vectorial force */
1277             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1278             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1279             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1280
1281             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1282             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1283             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1284
1285             /**************************
1286              * CALCULATE INTERACTIONS *
1287              **************************/
1288
1289             r30              = _mm_mul_ps(rsq30,rinv30);
1290             r30              = _mm_andnot_ps(dummy_mask,r30);
1291
1292             /* Compute parameters for interactions between i and j atoms */
1293             qq30             = _mm_mul_ps(iq3,jq0);
1294
1295             /* EWALD ELECTROSTATICS */
1296
1297             /* Analytical PME correction */
1298             zeta2            = _mm_mul_ps(beta2,rsq30);
1299             rinv3            = _mm_mul_ps(rinvsq30,rinv30);
1300             pmecorrF         = gmx_mm_pmecorrF_ps(zeta2);
1301             felec            = _mm_macc_ps(pmecorrF,beta3,rinv3);
1302             felec            = _mm_mul_ps(qq30,felec);
1303
1304             fscal            = felec;
1305
1306             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1307
1308              /* Update vectorial force */
1309             fix3             = _mm_macc_ps(dx30,fscal,fix3);
1310             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
1311             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
1312
1313             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
1314             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
1315             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
1316
1317             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1318             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1319             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1320             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1321
1322             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1323
1324             /* Inner loop uses 139 flops */
1325         }
1326
1327         /* End of innermost loop */
1328
1329         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1330                                               f+i_coord_offset,fshift+i_shift_offset);
1331
1332         /* Increment number of inner iterations */
1333         inneriter                  += j_index_end - j_index_start;
1334
1335         /* Outer loop uses 24 flops */
1336     }
1337
1338     /* Increment number of outer iterations */
1339     outeriter        += nri;
1340
1341     /* Update outer/inner flops */
1342
1343     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*139);
1344 }