Remove no-inline-max-size and suppress remark
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecCoul_VdwCSTab_GeomW3W3_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_ElecCoul_VdwCSTab_GeomW3W3_VF_avx_128_fma_single
54  * Electrostatics interaction: Coulomb
55  * VdW interaction:            CubicSplineTable
56  * Geometry:                   Water3-Water3
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecCoul_VdwCSTab_GeomW3W3_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              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
94     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
95     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
96     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
97     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
98     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
99     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
100     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
101     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
102     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
103     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
104     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
105     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
106     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
107     real             *charge;
108     int              nvdwtype;
109     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
110     int              *vdwtype;
111     real             *vdwparam;
112     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
113     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
114     __m128i          vfitab;
115     __m128i          ifour       = _mm_set1_epi32(4);
116     __m128           rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
117     real             *vftab;
118     __m128           dummy_mask,cutoff_mask;
119     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
120     __m128           one     = _mm_set1_ps(1.0);
121     __m128           two     = _mm_set1_ps(2.0);
122     x                = xx[0];
123     f                = ff[0];
124
125     nri              = nlist->nri;
126     iinr             = nlist->iinr;
127     jindex           = nlist->jindex;
128     jjnr             = nlist->jjnr;
129     shiftidx         = nlist->shift;
130     gid              = nlist->gid;
131     shiftvec         = fr->shift_vec[0];
132     fshift           = fr->fshift[0];
133     facel            = _mm_set1_ps(fr->epsfac);
134     charge           = mdatoms->chargeA;
135     nvdwtype         = fr->ntype;
136     vdwparam         = fr->nbfp;
137     vdwtype          = mdatoms->typeA;
138
139     vftab            = kernel_data->table_vdw->data;
140     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
141
142     /* Setup water-specific parameters */
143     inr              = nlist->iinr[0];
144     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
145     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
146     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
147     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
148
149     jq0              = _mm_set1_ps(charge[inr+0]);
150     jq1              = _mm_set1_ps(charge[inr+1]);
151     jq2              = _mm_set1_ps(charge[inr+2]);
152     vdwjidx0A        = 2*vdwtype[inr+0];
153     qq00             = _mm_mul_ps(iq0,jq0);
154     c6_00            = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
155     c12_00           = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
156     qq01             = _mm_mul_ps(iq0,jq1);
157     qq02             = _mm_mul_ps(iq0,jq2);
158     qq10             = _mm_mul_ps(iq1,jq0);
159     qq11             = _mm_mul_ps(iq1,jq1);
160     qq12             = _mm_mul_ps(iq1,jq2);
161     qq20             = _mm_mul_ps(iq2,jq0);
162     qq21             = _mm_mul_ps(iq2,jq1);
163     qq22             = _mm_mul_ps(iq2,jq2);
164
165     /* Avoid stupid compiler warnings */
166     jnrA = jnrB = jnrC = jnrD = 0;
167     j_coord_offsetA = 0;
168     j_coord_offsetB = 0;
169     j_coord_offsetC = 0;
170     j_coord_offsetD = 0;
171
172     outeriter        = 0;
173     inneriter        = 0;
174
175     for(iidx=0;iidx<4*DIM;iidx++)
176     {
177         scratch[iidx] = 0.0;
178     }
179
180     /* Start outer loop over neighborlists */
181     for(iidx=0; iidx<nri; iidx++)
182     {
183         /* Load shift vector for this list */
184         i_shift_offset   = DIM*shiftidx[iidx];
185
186         /* Load limits for loop over neighbors */
187         j_index_start    = jindex[iidx];
188         j_index_end      = jindex[iidx+1];
189
190         /* Get outer coordinate index */
191         inr              = iinr[iidx];
192         i_coord_offset   = DIM*inr;
193
194         /* Load i particle coords and add shift vector */
195         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
196                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
197
198         fix0             = _mm_setzero_ps();
199         fiy0             = _mm_setzero_ps();
200         fiz0             = _mm_setzero_ps();
201         fix1             = _mm_setzero_ps();
202         fiy1             = _mm_setzero_ps();
203         fiz1             = _mm_setzero_ps();
204         fix2             = _mm_setzero_ps();
205         fiy2             = _mm_setzero_ps();
206         fiz2             = _mm_setzero_ps();
207
208         /* Reset potential sums */
209         velecsum         = _mm_setzero_ps();
210         vvdwsum          = _mm_setzero_ps();
211
212         /* Start inner kernel loop */
213         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
214         {
215
216             /* Get j neighbor index, and coordinate index */
217             jnrA             = jjnr[jidx];
218             jnrB             = jjnr[jidx+1];
219             jnrC             = jjnr[jidx+2];
220             jnrD             = jjnr[jidx+3];
221             j_coord_offsetA  = DIM*jnrA;
222             j_coord_offsetB  = DIM*jnrB;
223             j_coord_offsetC  = DIM*jnrC;
224             j_coord_offsetD  = DIM*jnrD;
225
226             /* load j atom coordinates */
227             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
228                                               x+j_coord_offsetC,x+j_coord_offsetD,
229                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
230
231             /* Calculate displacement vector */
232             dx00             = _mm_sub_ps(ix0,jx0);
233             dy00             = _mm_sub_ps(iy0,jy0);
234             dz00             = _mm_sub_ps(iz0,jz0);
235             dx01             = _mm_sub_ps(ix0,jx1);
236             dy01             = _mm_sub_ps(iy0,jy1);
237             dz01             = _mm_sub_ps(iz0,jz1);
238             dx02             = _mm_sub_ps(ix0,jx2);
239             dy02             = _mm_sub_ps(iy0,jy2);
240             dz02             = _mm_sub_ps(iz0,jz2);
241             dx10             = _mm_sub_ps(ix1,jx0);
242             dy10             = _mm_sub_ps(iy1,jy0);
243             dz10             = _mm_sub_ps(iz1,jz0);
244             dx11             = _mm_sub_ps(ix1,jx1);
245             dy11             = _mm_sub_ps(iy1,jy1);
246             dz11             = _mm_sub_ps(iz1,jz1);
247             dx12             = _mm_sub_ps(ix1,jx2);
248             dy12             = _mm_sub_ps(iy1,jy2);
249             dz12             = _mm_sub_ps(iz1,jz2);
250             dx20             = _mm_sub_ps(ix2,jx0);
251             dy20             = _mm_sub_ps(iy2,jy0);
252             dz20             = _mm_sub_ps(iz2,jz0);
253             dx21             = _mm_sub_ps(ix2,jx1);
254             dy21             = _mm_sub_ps(iy2,jy1);
255             dz21             = _mm_sub_ps(iz2,jz1);
256             dx22             = _mm_sub_ps(ix2,jx2);
257             dy22             = _mm_sub_ps(iy2,jy2);
258             dz22             = _mm_sub_ps(iz2,jz2);
259
260             /* Calculate squared distance and things based on it */
261             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
262             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
263             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
264             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
265             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
266             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
267             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
268             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
269             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
270
271             rinv00           = gmx_mm_invsqrt_ps(rsq00);
272             rinv01           = gmx_mm_invsqrt_ps(rsq01);
273             rinv02           = gmx_mm_invsqrt_ps(rsq02);
274             rinv10           = gmx_mm_invsqrt_ps(rsq10);
275             rinv11           = gmx_mm_invsqrt_ps(rsq11);
276             rinv12           = gmx_mm_invsqrt_ps(rsq12);
277             rinv20           = gmx_mm_invsqrt_ps(rsq20);
278             rinv21           = gmx_mm_invsqrt_ps(rsq21);
279             rinv22           = gmx_mm_invsqrt_ps(rsq22);
280
281             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
282             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
283             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
284             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
285             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
286             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
287             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
288             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
289             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
290
291             fjx0             = _mm_setzero_ps();
292             fjy0             = _mm_setzero_ps();
293             fjz0             = _mm_setzero_ps();
294             fjx1             = _mm_setzero_ps();
295             fjy1             = _mm_setzero_ps();
296             fjz1             = _mm_setzero_ps();
297             fjx2             = _mm_setzero_ps();
298             fjy2             = _mm_setzero_ps();
299             fjz2             = _mm_setzero_ps();
300
301             /**************************
302              * CALCULATE INTERACTIONS *
303              **************************/
304
305             r00              = _mm_mul_ps(rsq00,rinv00);
306
307             /* Calculate table index by multiplying r with table scale and truncate to integer */
308             rt               = _mm_mul_ps(r00,vftabscale);
309             vfitab           = _mm_cvttps_epi32(rt);
310 #ifdef __XOP__
311             vfeps            = _mm_frcz_ps(rt);
312 #else
313             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
314 #endif
315             twovfeps         = _mm_add_ps(vfeps,vfeps);
316             vfitab           = _mm_slli_epi32(vfitab,3);
317
318             /* COULOMB ELECTROSTATICS */
319             velec            = _mm_mul_ps(qq00,rinv00);
320             felec            = _mm_mul_ps(velec,rinvsq00);
321
322             /* CUBIC SPLINE TABLE DISPERSION */
323             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
324             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
325             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
326             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
327             _MM_TRANSPOSE4_PS(Y,F,G,H);
328             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
329             VV               = _mm_macc_ps(vfeps,Fp,Y);
330             vvdw6            = _mm_mul_ps(c6_00,VV);
331             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
332             fvdw6            = _mm_mul_ps(c6_00,FF);
333
334             /* CUBIC SPLINE TABLE REPULSION */
335             vfitab           = _mm_add_epi32(vfitab,ifour);
336             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
337             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
338             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
339             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
340             _MM_TRANSPOSE4_PS(Y,F,G,H);
341             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
342             VV               = _mm_macc_ps(vfeps,Fp,Y);
343             vvdw12           = _mm_mul_ps(c12_00,VV);
344             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
345             fvdw12           = _mm_mul_ps(c12_00,FF);
346             vvdw             = _mm_add_ps(vvdw12,vvdw6);
347             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
348
349             /* Update potential sum for this i atom from the interaction with this j atom. */
350             velecsum         = _mm_add_ps(velecsum,velec);
351             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
352
353             fscal            = _mm_add_ps(felec,fvdw);
354
355              /* Update vectorial force */
356             fix0             = _mm_macc_ps(dx00,fscal,fix0);
357             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
358             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
359
360             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
361             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
362             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
363
364             /**************************
365              * CALCULATE INTERACTIONS *
366              **************************/
367
368             /* COULOMB ELECTROSTATICS */
369             velec            = _mm_mul_ps(qq01,rinv01);
370             felec            = _mm_mul_ps(velec,rinvsq01);
371
372             /* Update potential sum for this i atom from the interaction with this j atom. */
373             velecsum         = _mm_add_ps(velecsum,velec);
374
375             fscal            = felec;
376
377              /* Update vectorial force */
378             fix0             = _mm_macc_ps(dx01,fscal,fix0);
379             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
380             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
381
382             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
383             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
384             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
385
386             /**************************
387              * CALCULATE INTERACTIONS *
388              **************************/
389
390             /* COULOMB ELECTROSTATICS */
391             velec            = _mm_mul_ps(qq02,rinv02);
392             felec            = _mm_mul_ps(velec,rinvsq02);
393
394             /* Update potential sum for this i atom from the interaction with this j atom. */
395             velecsum         = _mm_add_ps(velecsum,velec);
396
397             fscal            = felec;
398
399              /* Update vectorial force */
400             fix0             = _mm_macc_ps(dx02,fscal,fix0);
401             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
402             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
403
404             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
405             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
406             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
407
408             /**************************
409              * CALCULATE INTERACTIONS *
410              **************************/
411
412             /* COULOMB ELECTROSTATICS */
413             velec            = _mm_mul_ps(qq10,rinv10);
414             felec            = _mm_mul_ps(velec,rinvsq10);
415
416             /* Update potential sum for this i atom from the interaction with this j atom. */
417             velecsum         = _mm_add_ps(velecsum,velec);
418
419             fscal            = felec;
420
421              /* Update vectorial force */
422             fix1             = _mm_macc_ps(dx10,fscal,fix1);
423             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
424             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
425
426             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
427             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
428             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
429
430             /**************************
431              * CALCULATE INTERACTIONS *
432              **************************/
433
434             /* COULOMB ELECTROSTATICS */
435             velec            = _mm_mul_ps(qq11,rinv11);
436             felec            = _mm_mul_ps(velec,rinvsq11);
437
438             /* Update potential sum for this i atom from the interaction with this j atom. */
439             velecsum         = _mm_add_ps(velecsum,velec);
440
441             fscal            = felec;
442
443              /* Update vectorial force */
444             fix1             = _mm_macc_ps(dx11,fscal,fix1);
445             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
446             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
447
448             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
449             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
450             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
451
452             /**************************
453              * CALCULATE INTERACTIONS *
454              **************************/
455
456             /* COULOMB ELECTROSTATICS */
457             velec            = _mm_mul_ps(qq12,rinv12);
458             felec            = _mm_mul_ps(velec,rinvsq12);
459
460             /* Update potential sum for this i atom from the interaction with this j atom. */
461             velecsum         = _mm_add_ps(velecsum,velec);
462
463             fscal            = felec;
464
465              /* Update vectorial force */
466             fix1             = _mm_macc_ps(dx12,fscal,fix1);
467             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
468             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
469
470             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
471             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
472             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
473
474             /**************************
475              * CALCULATE INTERACTIONS *
476              **************************/
477
478             /* COULOMB ELECTROSTATICS */
479             velec            = _mm_mul_ps(qq20,rinv20);
480             felec            = _mm_mul_ps(velec,rinvsq20);
481
482             /* Update potential sum for this i atom from the interaction with this j atom. */
483             velecsum         = _mm_add_ps(velecsum,velec);
484
485             fscal            = felec;
486
487              /* Update vectorial force */
488             fix2             = _mm_macc_ps(dx20,fscal,fix2);
489             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
490             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
491
492             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
493             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
494             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
495
496             /**************************
497              * CALCULATE INTERACTIONS *
498              **************************/
499
500             /* COULOMB ELECTROSTATICS */
501             velec            = _mm_mul_ps(qq21,rinv21);
502             felec            = _mm_mul_ps(velec,rinvsq21);
503
504             /* Update potential sum for this i atom from the interaction with this j atom. */
505             velecsum         = _mm_add_ps(velecsum,velec);
506
507             fscal            = felec;
508
509              /* Update vectorial force */
510             fix2             = _mm_macc_ps(dx21,fscal,fix2);
511             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
512             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
513
514             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
515             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
516             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
517
518             /**************************
519              * CALCULATE INTERACTIONS *
520              **************************/
521
522             /* COULOMB ELECTROSTATICS */
523             velec            = _mm_mul_ps(qq22,rinv22);
524             felec            = _mm_mul_ps(velec,rinvsq22);
525
526             /* Update potential sum for this i atom from the interaction with this j atom. */
527             velecsum         = _mm_add_ps(velecsum,velec);
528
529             fscal            = felec;
530
531              /* Update vectorial force */
532             fix2             = _mm_macc_ps(dx22,fscal,fix2);
533             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
534             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
535
536             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
537             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
538             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
539
540             fjptrA             = f+j_coord_offsetA;
541             fjptrB             = f+j_coord_offsetB;
542             fjptrC             = f+j_coord_offsetC;
543             fjptrD             = f+j_coord_offsetD;
544
545             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
546                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
547
548             /* Inner loop uses 314 flops */
549         }
550
551         if(jidx<j_index_end)
552         {
553
554             /* Get j neighbor index, and coordinate index */
555             jnrlistA         = jjnr[jidx];
556             jnrlistB         = jjnr[jidx+1];
557             jnrlistC         = jjnr[jidx+2];
558             jnrlistD         = jjnr[jidx+3];
559             /* Sign of each element will be negative for non-real atoms.
560              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
561              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
562              */
563             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
564             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
565             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
566             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
567             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
568             j_coord_offsetA  = DIM*jnrA;
569             j_coord_offsetB  = DIM*jnrB;
570             j_coord_offsetC  = DIM*jnrC;
571             j_coord_offsetD  = DIM*jnrD;
572
573             /* load j atom coordinates */
574             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
575                                               x+j_coord_offsetC,x+j_coord_offsetD,
576                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
577
578             /* Calculate displacement vector */
579             dx00             = _mm_sub_ps(ix0,jx0);
580             dy00             = _mm_sub_ps(iy0,jy0);
581             dz00             = _mm_sub_ps(iz0,jz0);
582             dx01             = _mm_sub_ps(ix0,jx1);
583             dy01             = _mm_sub_ps(iy0,jy1);
584             dz01             = _mm_sub_ps(iz0,jz1);
585             dx02             = _mm_sub_ps(ix0,jx2);
586             dy02             = _mm_sub_ps(iy0,jy2);
587             dz02             = _mm_sub_ps(iz0,jz2);
588             dx10             = _mm_sub_ps(ix1,jx0);
589             dy10             = _mm_sub_ps(iy1,jy0);
590             dz10             = _mm_sub_ps(iz1,jz0);
591             dx11             = _mm_sub_ps(ix1,jx1);
592             dy11             = _mm_sub_ps(iy1,jy1);
593             dz11             = _mm_sub_ps(iz1,jz1);
594             dx12             = _mm_sub_ps(ix1,jx2);
595             dy12             = _mm_sub_ps(iy1,jy2);
596             dz12             = _mm_sub_ps(iz1,jz2);
597             dx20             = _mm_sub_ps(ix2,jx0);
598             dy20             = _mm_sub_ps(iy2,jy0);
599             dz20             = _mm_sub_ps(iz2,jz0);
600             dx21             = _mm_sub_ps(ix2,jx1);
601             dy21             = _mm_sub_ps(iy2,jy1);
602             dz21             = _mm_sub_ps(iz2,jz1);
603             dx22             = _mm_sub_ps(ix2,jx2);
604             dy22             = _mm_sub_ps(iy2,jy2);
605             dz22             = _mm_sub_ps(iz2,jz2);
606
607             /* Calculate squared distance and things based on it */
608             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
609             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
610             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
611             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
612             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
613             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
614             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
615             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
616             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
617
618             rinv00           = gmx_mm_invsqrt_ps(rsq00);
619             rinv01           = gmx_mm_invsqrt_ps(rsq01);
620             rinv02           = gmx_mm_invsqrt_ps(rsq02);
621             rinv10           = gmx_mm_invsqrt_ps(rsq10);
622             rinv11           = gmx_mm_invsqrt_ps(rsq11);
623             rinv12           = gmx_mm_invsqrt_ps(rsq12);
624             rinv20           = gmx_mm_invsqrt_ps(rsq20);
625             rinv21           = gmx_mm_invsqrt_ps(rsq21);
626             rinv22           = gmx_mm_invsqrt_ps(rsq22);
627
628             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
629             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
630             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
631             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
632             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
633             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
634             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
635             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
636             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
637
638             fjx0             = _mm_setzero_ps();
639             fjy0             = _mm_setzero_ps();
640             fjz0             = _mm_setzero_ps();
641             fjx1             = _mm_setzero_ps();
642             fjy1             = _mm_setzero_ps();
643             fjz1             = _mm_setzero_ps();
644             fjx2             = _mm_setzero_ps();
645             fjy2             = _mm_setzero_ps();
646             fjz2             = _mm_setzero_ps();
647
648             /**************************
649              * CALCULATE INTERACTIONS *
650              **************************/
651
652             r00              = _mm_mul_ps(rsq00,rinv00);
653             r00              = _mm_andnot_ps(dummy_mask,r00);
654
655             /* Calculate table index by multiplying r with table scale and truncate to integer */
656             rt               = _mm_mul_ps(r00,vftabscale);
657             vfitab           = _mm_cvttps_epi32(rt);
658 #ifdef __XOP__
659             vfeps            = _mm_frcz_ps(rt);
660 #else
661             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
662 #endif
663             twovfeps         = _mm_add_ps(vfeps,vfeps);
664             vfitab           = _mm_slli_epi32(vfitab,3);
665
666             /* COULOMB ELECTROSTATICS */
667             velec            = _mm_mul_ps(qq00,rinv00);
668             felec            = _mm_mul_ps(velec,rinvsq00);
669
670             /* CUBIC SPLINE TABLE DISPERSION */
671             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
672             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
673             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
674             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
675             _MM_TRANSPOSE4_PS(Y,F,G,H);
676             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
677             VV               = _mm_macc_ps(vfeps,Fp,Y);
678             vvdw6            = _mm_mul_ps(c6_00,VV);
679             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
680             fvdw6            = _mm_mul_ps(c6_00,FF);
681
682             /* CUBIC SPLINE TABLE REPULSION */
683             vfitab           = _mm_add_epi32(vfitab,ifour);
684             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
685             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
686             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
687             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
688             _MM_TRANSPOSE4_PS(Y,F,G,H);
689             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
690             VV               = _mm_macc_ps(vfeps,Fp,Y);
691             vvdw12           = _mm_mul_ps(c12_00,VV);
692             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
693             fvdw12           = _mm_mul_ps(c12_00,FF);
694             vvdw             = _mm_add_ps(vvdw12,vvdw6);
695             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
696
697             /* Update potential sum for this i atom from the interaction with this j atom. */
698             velec            = _mm_andnot_ps(dummy_mask,velec);
699             velecsum         = _mm_add_ps(velecsum,velec);
700             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
701             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
702
703             fscal            = _mm_add_ps(felec,fvdw);
704
705             fscal            = _mm_andnot_ps(dummy_mask,fscal);
706
707              /* Update vectorial force */
708             fix0             = _mm_macc_ps(dx00,fscal,fix0);
709             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
710             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
711
712             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
713             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
714             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
715
716             /**************************
717              * CALCULATE INTERACTIONS *
718              **************************/
719
720             /* COULOMB ELECTROSTATICS */
721             velec            = _mm_mul_ps(qq01,rinv01);
722             felec            = _mm_mul_ps(velec,rinvsq01);
723
724             /* Update potential sum for this i atom from the interaction with this j atom. */
725             velec            = _mm_andnot_ps(dummy_mask,velec);
726             velecsum         = _mm_add_ps(velecsum,velec);
727
728             fscal            = felec;
729
730             fscal            = _mm_andnot_ps(dummy_mask,fscal);
731
732              /* Update vectorial force */
733             fix0             = _mm_macc_ps(dx01,fscal,fix0);
734             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
735             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
736
737             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
738             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
739             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
740
741             /**************************
742              * CALCULATE INTERACTIONS *
743              **************************/
744
745             /* COULOMB ELECTROSTATICS */
746             velec            = _mm_mul_ps(qq02,rinv02);
747             felec            = _mm_mul_ps(velec,rinvsq02);
748
749             /* Update potential sum for this i atom from the interaction with this j atom. */
750             velec            = _mm_andnot_ps(dummy_mask,velec);
751             velecsum         = _mm_add_ps(velecsum,velec);
752
753             fscal            = felec;
754
755             fscal            = _mm_andnot_ps(dummy_mask,fscal);
756
757              /* Update vectorial force */
758             fix0             = _mm_macc_ps(dx02,fscal,fix0);
759             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
760             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
761
762             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
763             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
764             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
765
766             /**************************
767              * CALCULATE INTERACTIONS *
768              **************************/
769
770             /* COULOMB ELECTROSTATICS */
771             velec            = _mm_mul_ps(qq10,rinv10);
772             felec            = _mm_mul_ps(velec,rinvsq10);
773
774             /* Update potential sum for this i atom from the interaction with this j atom. */
775             velec            = _mm_andnot_ps(dummy_mask,velec);
776             velecsum         = _mm_add_ps(velecsum,velec);
777
778             fscal            = felec;
779
780             fscal            = _mm_andnot_ps(dummy_mask,fscal);
781
782              /* Update vectorial force */
783             fix1             = _mm_macc_ps(dx10,fscal,fix1);
784             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
785             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
786
787             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
788             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
789             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
790
791             /**************************
792              * CALCULATE INTERACTIONS *
793              **************************/
794
795             /* COULOMB ELECTROSTATICS */
796             velec            = _mm_mul_ps(qq11,rinv11);
797             felec            = _mm_mul_ps(velec,rinvsq11);
798
799             /* Update potential sum for this i atom from the interaction with this j atom. */
800             velec            = _mm_andnot_ps(dummy_mask,velec);
801             velecsum         = _mm_add_ps(velecsum,velec);
802
803             fscal            = felec;
804
805             fscal            = _mm_andnot_ps(dummy_mask,fscal);
806
807              /* Update vectorial force */
808             fix1             = _mm_macc_ps(dx11,fscal,fix1);
809             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
810             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
811
812             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
813             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
814             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
815
816             /**************************
817              * CALCULATE INTERACTIONS *
818              **************************/
819
820             /* COULOMB ELECTROSTATICS */
821             velec            = _mm_mul_ps(qq12,rinv12);
822             felec            = _mm_mul_ps(velec,rinvsq12);
823
824             /* Update potential sum for this i atom from the interaction with this j atom. */
825             velec            = _mm_andnot_ps(dummy_mask,velec);
826             velecsum         = _mm_add_ps(velecsum,velec);
827
828             fscal            = felec;
829
830             fscal            = _mm_andnot_ps(dummy_mask,fscal);
831
832              /* Update vectorial force */
833             fix1             = _mm_macc_ps(dx12,fscal,fix1);
834             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
835             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
836
837             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
838             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
839             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
840
841             /**************************
842              * CALCULATE INTERACTIONS *
843              **************************/
844
845             /* COULOMB ELECTROSTATICS */
846             velec            = _mm_mul_ps(qq20,rinv20);
847             felec            = _mm_mul_ps(velec,rinvsq20);
848
849             /* Update potential sum for this i atom from the interaction with this j atom. */
850             velec            = _mm_andnot_ps(dummy_mask,velec);
851             velecsum         = _mm_add_ps(velecsum,velec);
852
853             fscal            = felec;
854
855             fscal            = _mm_andnot_ps(dummy_mask,fscal);
856
857              /* Update vectorial force */
858             fix2             = _mm_macc_ps(dx20,fscal,fix2);
859             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
860             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
861
862             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
863             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
864             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
865
866             /**************************
867              * CALCULATE INTERACTIONS *
868              **************************/
869
870             /* COULOMB ELECTROSTATICS */
871             velec            = _mm_mul_ps(qq21,rinv21);
872             felec            = _mm_mul_ps(velec,rinvsq21);
873
874             /* Update potential sum for this i atom from the interaction with this j atom. */
875             velec            = _mm_andnot_ps(dummy_mask,velec);
876             velecsum         = _mm_add_ps(velecsum,velec);
877
878             fscal            = felec;
879
880             fscal            = _mm_andnot_ps(dummy_mask,fscal);
881
882              /* Update vectorial force */
883             fix2             = _mm_macc_ps(dx21,fscal,fix2);
884             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
885             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
886
887             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
888             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
889             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
890
891             /**************************
892              * CALCULATE INTERACTIONS *
893              **************************/
894
895             /* COULOMB ELECTROSTATICS */
896             velec            = _mm_mul_ps(qq22,rinv22);
897             felec            = _mm_mul_ps(velec,rinvsq22);
898
899             /* Update potential sum for this i atom from the interaction with this j atom. */
900             velec            = _mm_andnot_ps(dummy_mask,velec);
901             velecsum         = _mm_add_ps(velecsum,velec);
902
903             fscal            = felec;
904
905             fscal            = _mm_andnot_ps(dummy_mask,fscal);
906
907              /* Update vectorial force */
908             fix2             = _mm_macc_ps(dx22,fscal,fix2);
909             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
910             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
911
912             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
913             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
914             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
915
916             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
917             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
918             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
919             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
920
921             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
922                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
923
924             /* Inner loop uses 315 flops */
925         }
926
927         /* End of innermost loop */
928
929         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
930                                               f+i_coord_offset,fshift+i_shift_offset);
931
932         ggid                        = gid[iidx];
933         /* Update potential energies */
934         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
935         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
936
937         /* Increment number of inner iterations */
938         inneriter                  += j_index_end - j_index_start;
939
940         /* Outer loop uses 20 flops */
941     }
942
943     /* Increment number of outer iterations */
944     outeriter        += nri;
945
946     /* Update outer/inner flops */
947
948     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*315);
949 }
950 /*
951  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwCSTab_GeomW3W3_F_avx_128_fma_single
952  * Electrostatics interaction: Coulomb
953  * VdW interaction:            CubicSplineTable
954  * Geometry:                   Water3-Water3
955  * Calculate force/pot:        Force
956  */
957 void
958 nb_kernel_ElecCoul_VdwCSTab_GeomW3W3_F_avx_128_fma_single
959                     (t_nblist                    * gmx_restrict       nlist,
960                      rvec                        * gmx_restrict          xx,
961                      rvec                        * gmx_restrict          ff,
962                      t_forcerec                  * gmx_restrict          fr,
963                      t_mdatoms                   * gmx_restrict     mdatoms,
964                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
965                      t_nrnb                      * gmx_restrict        nrnb)
966 {
967     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
968      * just 0 for non-waters.
969      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
970      * jnr indices corresponding to data put in the four positions in the SIMD register.
971      */
972     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
973     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
974     int              jnrA,jnrB,jnrC,jnrD;
975     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
976     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
977     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
978     real             rcutoff_scalar;
979     real             *shiftvec,*fshift,*x,*f;
980     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
981     real             scratch[4*DIM];
982     __m128           fscal,rcutoff,rcutoff2,jidxall;
983     int              vdwioffset0;
984     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
985     int              vdwioffset1;
986     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
987     int              vdwioffset2;
988     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
989     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
990     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
991     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
992     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
993     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
994     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
995     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
996     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
997     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
998     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
999     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1000     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1001     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1002     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1003     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1004     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
1005     real             *charge;
1006     int              nvdwtype;
1007     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1008     int              *vdwtype;
1009     real             *vdwparam;
1010     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
1011     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
1012     __m128i          vfitab;
1013     __m128i          ifour       = _mm_set1_epi32(4);
1014     __m128           rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
1015     real             *vftab;
1016     __m128           dummy_mask,cutoff_mask;
1017     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1018     __m128           one     = _mm_set1_ps(1.0);
1019     __m128           two     = _mm_set1_ps(2.0);
1020     x                = xx[0];
1021     f                = ff[0];
1022
1023     nri              = nlist->nri;
1024     iinr             = nlist->iinr;
1025     jindex           = nlist->jindex;
1026     jjnr             = nlist->jjnr;
1027     shiftidx         = nlist->shift;
1028     gid              = nlist->gid;
1029     shiftvec         = fr->shift_vec[0];
1030     fshift           = fr->fshift[0];
1031     facel            = _mm_set1_ps(fr->epsfac);
1032     charge           = mdatoms->chargeA;
1033     nvdwtype         = fr->ntype;
1034     vdwparam         = fr->nbfp;
1035     vdwtype          = mdatoms->typeA;
1036
1037     vftab            = kernel_data->table_vdw->data;
1038     vftabscale       = _mm_set1_ps(kernel_data->table_vdw->scale);
1039
1040     /* Setup water-specific parameters */
1041     inr              = nlist->iinr[0];
1042     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1043     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1044     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1045     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
1046
1047     jq0              = _mm_set1_ps(charge[inr+0]);
1048     jq1              = _mm_set1_ps(charge[inr+1]);
1049     jq2              = _mm_set1_ps(charge[inr+2]);
1050     vdwjidx0A        = 2*vdwtype[inr+0];
1051     qq00             = _mm_mul_ps(iq0,jq0);
1052     c6_00            = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1053     c12_00           = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1054     qq01             = _mm_mul_ps(iq0,jq1);
1055     qq02             = _mm_mul_ps(iq0,jq2);
1056     qq10             = _mm_mul_ps(iq1,jq0);
1057     qq11             = _mm_mul_ps(iq1,jq1);
1058     qq12             = _mm_mul_ps(iq1,jq2);
1059     qq20             = _mm_mul_ps(iq2,jq0);
1060     qq21             = _mm_mul_ps(iq2,jq1);
1061     qq22             = _mm_mul_ps(iq2,jq2);
1062
1063     /* Avoid stupid compiler warnings */
1064     jnrA = jnrB = jnrC = jnrD = 0;
1065     j_coord_offsetA = 0;
1066     j_coord_offsetB = 0;
1067     j_coord_offsetC = 0;
1068     j_coord_offsetD = 0;
1069
1070     outeriter        = 0;
1071     inneriter        = 0;
1072
1073     for(iidx=0;iidx<4*DIM;iidx++)
1074     {
1075         scratch[iidx] = 0.0;
1076     }
1077
1078     /* Start outer loop over neighborlists */
1079     for(iidx=0; iidx<nri; iidx++)
1080     {
1081         /* Load shift vector for this list */
1082         i_shift_offset   = DIM*shiftidx[iidx];
1083
1084         /* Load limits for loop over neighbors */
1085         j_index_start    = jindex[iidx];
1086         j_index_end      = jindex[iidx+1];
1087
1088         /* Get outer coordinate index */
1089         inr              = iinr[iidx];
1090         i_coord_offset   = DIM*inr;
1091
1092         /* Load i particle coords and add shift vector */
1093         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1094                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1095
1096         fix0             = _mm_setzero_ps();
1097         fiy0             = _mm_setzero_ps();
1098         fiz0             = _mm_setzero_ps();
1099         fix1             = _mm_setzero_ps();
1100         fiy1             = _mm_setzero_ps();
1101         fiz1             = _mm_setzero_ps();
1102         fix2             = _mm_setzero_ps();
1103         fiy2             = _mm_setzero_ps();
1104         fiz2             = _mm_setzero_ps();
1105
1106         /* Start inner kernel loop */
1107         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1108         {
1109
1110             /* Get j neighbor index, and coordinate index */
1111             jnrA             = jjnr[jidx];
1112             jnrB             = jjnr[jidx+1];
1113             jnrC             = jjnr[jidx+2];
1114             jnrD             = jjnr[jidx+3];
1115             j_coord_offsetA  = DIM*jnrA;
1116             j_coord_offsetB  = DIM*jnrB;
1117             j_coord_offsetC  = DIM*jnrC;
1118             j_coord_offsetD  = DIM*jnrD;
1119
1120             /* load j atom coordinates */
1121             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1122                                               x+j_coord_offsetC,x+j_coord_offsetD,
1123                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1124
1125             /* Calculate displacement vector */
1126             dx00             = _mm_sub_ps(ix0,jx0);
1127             dy00             = _mm_sub_ps(iy0,jy0);
1128             dz00             = _mm_sub_ps(iz0,jz0);
1129             dx01             = _mm_sub_ps(ix0,jx1);
1130             dy01             = _mm_sub_ps(iy0,jy1);
1131             dz01             = _mm_sub_ps(iz0,jz1);
1132             dx02             = _mm_sub_ps(ix0,jx2);
1133             dy02             = _mm_sub_ps(iy0,jy2);
1134             dz02             = _mm_sub_ps(iz0,jz2);
1135             dx10             = _mm_sub_ps(ix1,jx0);
1136             dy10             = _mm_sub_ps(iy1,jy0);
1137             dz10             = _mm_sub_ps(iz1,jz0);
1138             dx11             = _mm_sub_ps(ix1,jx1);
1139             dy11             = _mm_sub_ps(iy1,jy1);
1140             dz11             = _mm_sub_ps(iz1,jz1);
1141             dx12             = _mm_sub_ps(ix1,jx2);
1142             dy12             = _mm_sub_ps(iy1,jy2);
1143             dz12             = _mm_sub_ps(iz1,jz2);
1144             dx20             = _mm_sub_ps(ix2,jx0);
1145             dy20             = _mm_sub_ps(iy2,jy0);
1146             dz20             = _mm_sub_ps(iz2,jz0);
1147             dx21             = _mm_sub_ps(ix2,jx1);
1148             dy21             = _mm_sub_ps(iy2,jy1);
1149             dz21             = _mm_sub_ps(iz2,jz1);
1150             dx22             = _mm_sub_ps(ix2,jx2);
1151             dy22             = _mm_sub_ps(iy2,jy2);
1152             dz22             = _mm_sub_ps(iz2,jz2);
1153
1154             /* Calculate squared distance and things based on it */
1155             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1156             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1157             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1158             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1159             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1160             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1161             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1162             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1163             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1164
1165             rinv00           = gmx_mm_invsqrt_ps(rsq00);
1166             rinv01           = gmx_mm_invsqrt_ps(rsq01);
1167             rinv02           = gmx_mm_invsqrt_ps(rsq02);
1168             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1169             rinv11           = gmx_mm_invsqrt_ps(rsq11);
1170             rinv12           = gmx_mm_invsqrt_ps(rsq12);
1171             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1172             rinv21           = gmx_mm_invsqrt_ps(rsq21);
1173             rinv22           = gmx_mm_invsqrt_ps(rsq22);
1174
1175             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1176             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1177             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1178             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1179             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1180             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1181             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1182             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1183             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1184
1185             fjx0             = _mm_setzero_ps();
1186             fjy0             = _mm_setzero_ps();
1187             fjz0             = _mm_setzero_ps();
1188             fjx1             = _mm_setzero_ps();
1189             fjy1             = _mm_setzero_ps();
1190             fjz1             = _mm_setzero_ps();
1191             fjx2             = _mm_setzero_ps();
1192             fjy2             = _mm_setzero_ps();
1193             fjz2             = _mm_setzero_ps();
1194
1195             /**************************
1196              * CALCULATE INTERACTIONS *
1197              **************************/
1198
1199             r00              = _mm_mul_ps(rsq00,rinv00);
1200
1201             /* Calculate table index by multiplying r with table scale and truncate to integer */
1202             rt               = _mm_mul_ps(r00,vftabscale);
1203             vfitab           = _mm_cvttps_epi32(rt);
1204 #ifdef __XOP__
1205             vfeps            = _mm_frcz_ps(rt);
1206 #else
1207             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1208 #endif
1209             twovfeps         = _mm_add_ps(vfeps,vfeps);
1210             vfitab           = _mm_slli_epi32(vfitab,3);
1211
1212             /* COULOMB ELECTROSTATICS */
1213             velec            = _mm_mul_ps(qq00,rinv00);
1214             felec            = _mm_mul_ps(velec,rinvsq00);
1215
1216             /* CUBIC SPLINE TABLE DISPERSION */
1217             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1218             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1219             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1220             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1221             _MM_TRANSPOSE4_PS(Y,F,G,H);
1222             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1223             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1224             fvdw6            = _mm_mul_ps(c6_00,FF);
1225
1226             /* CUBIC SPLINE TABLE REPULSION */
1227             vfitab           = _mm_add_epi32(vfitab,ifour);
1228             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1229             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1230             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1231             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1232             _MM_TRANSPOSE4_PS(Y,F,G,H);
1233             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1234             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1235             fvdw12           = _mm_mul_ps(c12_00,FF);
1236             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1237
1238             fscal            = _mm_add_ps(felec,fvdw);
1239
1240              /* Update vectorial force */
1241             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1242             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1243             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1244
1245             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1246             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1247             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1248
1249             /**************************
1250              * CALCULATE INTERACTIONS *
1251              **************************/
1252
1253             /* COULOMB ELECTROSTATICS */
1254             velec            = _mm_mul_ps(qq01,rinv01);
1255             felec            = _mm_mul_ps(velec,rinvsq01);
1256
1257             fscal            = felec;
1258
1259              /* Update vectorial force */
1260             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1261             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1262             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1263
1264             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1265             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1266             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1267
1268             /**************************
1269              * CALCULATE INTERACTIONS *
1270              **************************/
1271
1272             /* COULOMB ELECTROSTATICS */
1273             velec            = _mm_mul_ps(qq02,rinv02);
1274             felec            = _mm_mul_ps(velec,rinvsq02);
1275
1276             fscal            = felec;
1277
1278              /* Update vectorial force */
1279             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1280             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1281             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1282
1283             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
1284             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
1285             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
1286
1287             /**************************
1288              * CALCULATE INTERACTIONS *
1289              **************************/
1290
1291             /* COULOMB ELECTROSTATICS */
1292             velec            = _mm_mul_ps(qq10,rinv10);
1293             felec            = _mm_mul_ps(velec,rinvsq10);
1294
1295             fscal            = felec;
1296
1297              /* Update vectorial force */
1298             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1299             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1300             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1301
1302             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1303             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1304             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1305
1306             /**************************
1307              * CALCULATE INTERACTIONS *
1308              **************************/
1309
1310             /* COULOMB ELECTROSTATICS */
1311             velec            = _mm_mul_ps(qq11,rinv11);
1312             felec            = _mm_mul_ps(velec,rinvsq11);
1313
1314             fscal            = felec;
1315
1316              /* Update vectorial force */
1317             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1318             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1319             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1320
1321             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1322             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1323             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1324
1325             /**************************
1326              * CALCULATE INTERACTIONS *
1327              **************************/
1328
1329             /* COULOMB ELECTROSTATICS */
1330             velec            = _mm_mul_ps(qq12,rinv12);
1331             felec            = _mm_mul_ps(velec,rinvsq12);
1332
1333             fscal            = felec;
1334
1335              /* Update vectorial force */
1336             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1337             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1338             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1339
1340             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1341             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1342             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1343
1344             /**************************
1345              * CALCULATE INTERACTIONS *
1346              **************************/
1347
1348             /* COULOMB ELECTROSTATICS */
1349             velec            = _mm_mul_ps(qq20,rinv20);
1350             felec            = _mm_mul_ps(velec,rinvsq20);
1351
1352             fscal            = felec;
1353
1354              /* Update vectorial force */
1355             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1356             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1357             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1358
1359             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1360             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1361             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1362
1363             /**************************
1364              * CALCULATE INTERACTIONS *
1365              **************************/
1366
1367             /* COULOMB ELECTROSTATICS */
1368             velec            = _mm_mul_ps(qq21,rinv21);
1369             felec            = _mm_mul_ps(velec,rinvsq21);
1370
1371             fscal            = felec;
1372
1373              /* Update vectorial force */
1374             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1375             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1376             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1377
1378             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1379             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1380             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1381
1382             /**************************
1383              * CALCULATE INTERACTIONS *
1384              **************************/
1385
1386             /* COULOMB ELECTROSTATICS */
1387             velec            = _mm_mul_ps(qq22,rinv22);
1388             felec            = _mm_mul_ps(velec,rinvsq22);
1389
1390             fscal            = felec;
1391
1392              /* Update vectorial force */
1393             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1394             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1395             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1396
1397             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1398             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1399             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1400
1401             fjptrA             = f+j_coord_offsetA;
1402             fjptrB             = f+j_coord_offsetB;
1403             fjptrC             = f+j_coord_offsetC;
1404             fjptrD             = f+j_coord_offsetD;
1405
1406             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1407                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1408
1409             /* Inner loop uses 297 flops */
1410         }
1411
1412         if(jidx<j_index_end)
1413         {
1414
1415             /* Get j neighbor index, and coordinate index */
1416             jnrlistA         = jjnr[jidx];
1417             jnrlistB         = jjnr[jidx+1];
1418             jnrlistC         = jjnr[jidx+2];
1419             jnrlistD         = jjnr[jidx+3];
1420             /* Sign of each element will be negative for non-real atoms.
1421              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1422              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1423              */
1424             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1425             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1426             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1427             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1428             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1429             j_coord_offsetA  = DIM*jnrA;
1430             j_coord_offsetB  = DIM*jnrB;
1431             j_coord_offsetC  = DIM*jnrC;
1432             j_coord_offsetD  = DIM*jnrD;
1433
1434             /* load j atom coordinates */
1435             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1436                                               x+j_coord_offsetC,x+j_coord_offsetD,
1437                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1438
1439             /* Calculate displacement vector */
1440             dx00             = _mm_sub_ps(ix0,jx0);
1441             dy00             = _mm_sub_ps(iy0,jy0);
1442             dz00             = _mm_sub_ps(iz0,jz0);
1443             dx01             = _mm_sub_ps(ix0,jx1);
1444             dy01             = _mm_sub_ps(iy0,jy1);
1445             dz01             = _mm_sub_ps(iz0,jz1);
1446             dx02             = _mm_sub_ps(ix0,jx2);
1447             dy02             = _mm_sub_ps(iy0,jy2);
1448             dz02             = _mm_sub_ps(iz0,jz2);
1449             dx10             = _mm_sub_ps(ix1,jx0);
1450             dy10             = _mm_sub_ps(iy1,jy0);
1451             dz10             = _mm_sub_ps(iz1,jz0);
1452             dx11             = _mm_sub_ps(ix1,jx1);
1453             dy11             = _mm_sub_ps(iy1,jy1);
1454             dz11             = _mm_sub_ps(iz1,jz1);
1455             dx12             = _mm_sub_ps(ix1,jx2);
1456             dy12             = _mm_sub_ps(iy1,jy2);
1457             dz12             = _mm_sub_ps(iz1,jz2);
1458             dx20             = _mm_sub_ps(ix2,jx0);
1459             dy20             = _mm_sub_ps(iy2,jy0);
1460             dz20             = _mm_sub_ps(iz2,jz0);
1461             dx21             = _mm_sub_ps(ix2,jx1);
1462             dy21             = _mm_sub_ps(iy2,jy1);
1463             dz21             = _mm_sub_ps(iz2,jz1);
1464             dx22             = _mm_sub_ps(ix2,jx2);
1465             dy22             = _mm_sub_ps(iy2,jy2);
1466             dz22             = _mm_sub_ps(iz2,jz2);
1467
1468             /* Calculate squared distance and things based on it */
1469             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1470             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1471             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1472             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1473             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1474             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1475             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1476             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1477             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1478
1479             rinv00           = gmx_mm_invsqrt_ps(rsq00);
1480             rinv01           = gmx_mm_invsqrt_ps(rsq01);
1481             rinv02           = gmx_mm_invsqrt_ps(rsq02);
1482             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1483             rinv11           = gmx_mm_invsqrt_ps(rsq11);
1484             rinv12           = gmx_mm_invsqrt_ps(rsq12);
1485             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1486             rinv21           = gmx_mm_invsqrt_ps(rsq21);
1487             rinv22           = gmx_mm_invsqrt_ps(rsq22);
1488
1489             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1490             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1491             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1492             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1493             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1494             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1495             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1496             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1497             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1498
1499             fjx0             = _mm_setzero_ps();
1500             fjy0             = _mm_setzero_ps();
1501             fjz0             = _mm_setzero_ps();
1502             fjx1             = _mm_setzero_ps();
1503             fjy1             = _mm_setzero_ps();
1504             fjz1             = _mm_setzero_ps();
1505             fjx2             = _mm_setzero_ps();
1506             fjy2             = _mm_setzero_ps();
1507             fjz2             = _mm_setzero_ps();
1508
1509             /**************************
1510              * CALCULATE INTERACTIONS *
1511              **************************/
1512
1513             r00              = _mm_mul_ps(rsq00,rinv00);
1514             r00              = _mm_andnot_ps(dummy_mask,r00);
1515
1516             /* Calculate table index by multiplying r with table scale and truncate to integer */
1517             rt               = _mm_mul_ps(r00,vftabscale);
1518             vfitab           = _mm_cvttps_epi32(rt);
1519 #ifdef __XOP__
1520             vfeps            = _mm_frcz_ps(rt);
1521 #else
1522             vfeps            = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1523 #endif
1524             twovfeps         = _mm_add_ps(vfeps,vfeps);
1525             vfitab           = _mm_slli_epi32(vfitab,3);
1526
1527             /* COULOMB ELECTROSTATICS */
1528             velec            = _mm_mul_ps(qq00,rinv00);
1529             felec            = _mm_mul_ps(velec,rinvsq00);
1530
1531             /* CUBIC SPLINE TABLE DISPERSION */
1532             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1533             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1534             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1535             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1536             _MM_TRANSPOSE4_PS(Y,F,G,H);
1537             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1538             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1539             fvdw6            = _mm_mul_ps(c6_00,FF);
1540
1541             /* CUBIC SPLINE TABLE REPULSION */
1542             vfitab           = _mm_add_epi32(vfitab,ifour);
1543             Y                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1544             F                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1545             G                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1546             H                = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1547             _MM_TRANSPOSE4_PS(Y,F,G,H);
1548             Fp               = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1549             FF               = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1550             fvdw12           = _mm_mul_ps(c12_00,FF);
1551             fvdw             = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1552
1553             fscal            = _mm_add_ps(felec,fvdw);
1554
1555             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1556
1557              /* Update vectorial force */
1558             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1559             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1560             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1561
1562             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1563             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1564             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1565
1566             /**************************
1567              * CALCULATE INTERACTIONS *
1568              **************************/
1569
1570             /* COULOMB ELECTROSTATICS */
1571             velec            = _mm_mul_ps(qq01,rinv01);
1572             felec            = _mm_mul_ps(velec,rinvsq01);
1573
1574             fscal            = felec;
1575
1576             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1577
1578              /* Update vectorial force */
1579             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1580             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1581             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1582
1583             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1584             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1585             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1586
1587             /**************************
1588              * CALCULATE INTERACTIONS *
1589              **************************/
1590
1591             /* COULOMB ELECTROSTATICS */
1592             velec            = _mm_mul_ps(qq02,rinv02);
1593             felec            = _mm_mul_ps(velec,rinvsq02);
1594
1595             fscal            = felec;
1596
1597             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1598
1599              /* Update vectorial force */
1600             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1601             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1602             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1603
1604             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
1605             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
1606             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
1607
1608             /**************************
1609              * CALCULATE INTERACTIONS *
1610              **************************/
1611
1612             /* COULOMB ELECTROSTATICS */
1613             velec            = _mm_mul_ps(qq10,rinv10);
1614             felec            = _mm_mul_ps(velec,rinvsq10);
1615
1616             fscal            = felec;
1617
1618             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1619
1620              /* Update vectorial force */
1621             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1622             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1623             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1624
1625             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1626             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1627             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1628
1629             /**************************
1630              * CALCULATE INTERACTIONS *
1631              **************************/
1632
1633             /* COULOMB ELECTROSTATICS */
1634             velec            = _mm_mul_ps(qq11,rinv11);
1635             felec            = _mm_mul_ps(velec,rinvsq11);
1636
1637             fscal            = felec;
1638
1639             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1640
1641              /* Update vectorial force */
1642             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1643             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1644             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1645
1646             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1647             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1648             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1649
1650             /**************************
1651              * CALCULATE INTERACTIONS *
1652              **************************/
1653
1654             /* COULOMB ELECTROSTATICS */
1655             velec            = _mm_mul_ps(qq12,rinv12);
1656             felec            = _mm_mul_ps(velec,rinvsq12);
1657
1658             fscal            = felec;
1659
1660             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1661
1662              /* Update vectorial force */
1663             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1664             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1665             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1666
1667             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1668             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1669             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1670
1671             /**************************
1672              * CALCULATE INTERACTIONS *
1673              **************************/
1674
1675             /* COULOMB ELECTROSTATICS */
1676             velec            = _mm_mul_ps(qq20,rinv20);
1677             felec            = _mm_mul_ps(velec,rinvsq20);
1678
1679             fscal            = felec;
1680
1681             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1682
1683              /* Update vectorial force */
1684             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1685             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1686             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1687
1688             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1689             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1690             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1691
1692             /**************************
1693              * CALCULATE INTERACTIONS *
1694              **************************/
1695
1696             /* COULOMB ELECTROSTATICS */
1697             velec            = _mm_mul_ps(qq21,rinv21);
1698             felec            = _mm_mul_ps(velec,rinvsq21);
1699
1700             fscal            = felec;
1701
1702             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1703
1704              /* Update vectorial force */
1705             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1706             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1707             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1708
1709             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1710             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1711             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1712
1713             /**************************
1714              * CALCULATE INTERACTIONS *
1715              **************************/
1716
1717             /* COULOMB ELECTROSTATICS */
1718             velec            = _mm_mul_ps(qq22,rinv22);
1719             felec            = _mm_mul_ps(velec,rinvsq22);
1720
1721             fscal            = felec;
1722
1723             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1724
1725              /* Update vectorial force */
1726             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1727             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1728             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1729
1730             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1731             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1732             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1733
1734             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1735             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1736             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1737             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1738
1739             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1740                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1741
1742             /* Inner loop uses 298 flops */
1743         }
1744
1745         /* End of innermost loop */
1746
1747         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1748                                               f+i_coord_offset,fshift+i_shift_offset);
1749
1750         /* Increment number of inner iterations */
1751         inneriter                  += j_index_end - j_index_start;
1752
1753         /* Outer loop uses 18 flops */
1754     }
1755
1756     /* Increment number of outer iterations */
1757     outeriter        += nri;
1758
1759     /* Update outer/inner flops */
1760
1761     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*298);
1762 }