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