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