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