2 * Note: this file was generated by the Gromacs avx_128_fma_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
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
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
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.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwCSTab_GeomP1P1_VF_avx_128_fma_single
38 * Electrostatics interaction: GeneralizedBorn
39 * VdW interaction: CubicSplineTable
40 * Geometry: Particle-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_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)
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.
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;
65 real *shiftvec,*fshift,*x,*f;
66 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
68 __m128 fscal,rcutoff,rcutoff2,jidxall;
70 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
71 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
72 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
73 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
74 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
77 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
78 __m128 minushalf = _mm_set1_ps(-0.5);
79 real *invsqrta,*dvda,*gbtab;
81 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
84 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
85 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
87 __m128i ifour = _mm_set1_epi32(4);
88 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
90 __m128 dummy_mask,cutoff_mask;
91 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
92 __m128 one = _mm_set1_ps(1.0);
93 __m128 two = _mm_set1_ps(2.0);
99 jindex = nlist->jindex;
101 shiftidx = nlist->shift;
103 shiftvec = fr->shift_vec[0];
104 fshift = fr->fshift[0];
105 facel = _mm_set1_ps(fr->epsfac);
106 charge = mdatoms->chargeA;
107 nvdwtype = fr->ntype;
109 vdwtype = mdatoms->typeA;
111 vftab = kernel_data->table_vdw->data;
112 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
114 invsqrta = fr->invsqrta;
116 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
117 gbtab = fr->gbtab.data;
118 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
120 /* Avoid stupid compiler warnings */
121 jnrA = jnrB = jnrC = jnrD = 0;
130 for(iidx=0;iidx<4*DIM;iidx++)
135 /* Start outer loop over neighborlists */
136 for(iidx=0; iidx<nri; iidx++)
138 /* Load shift vector for this list */
139 i_shift_offset = DIM*shiftidx[iidx];
141 /* Load limits for loop over neighbors */
142 j_index_start = jindex[iidx];
143 j_index_end = jindex[iidx+1];
145 /* Get outer coordinate index */
147 i_coord_offset = DIM*inr;
149 /* Load i particle coords and add shift vector */
150 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
152 fix0 = _mm_setzero_ps();
153 fiy0 = _mm_setzero_ps();
154 fiz0 = _mm_setzero_ps();
156 /* Load parameters for i particles */
157 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
158 isai0 = _mm_load1_ps(invsqrta+inr+0);
159 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
161 /* Reset potential sums */
162 velecsum = _mm_setzero_ps();
163 vgbsum = _mm_setzero_ps();
164 vvdwsum = _mm_setzero_ps();
165 dvdasum = _mm_setzero_ps();
167 /* Start inner kernel loop */
168 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
171 /* Get j neighbor index, and coordinate index */
176 j_coord_offsetA = DIM*jnrA;
177 j_coord_offsetB = DIM*jnrB;
178 j_coord_offsetC = DIM*jnrC;
179 j_coord_offsetD = DIM*jnrD;
181 /* load j atom coordinates */
182 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
183 x+j_coord_offsetC,x+j_coord_offsetD,
186 /* Calculate displacement vector */
187 dx00 = _mm_sub_ps(ix0,jx0);
188 dy00 = _mm_sub_ps(iy0,jy0);
189 dz00 = _mm_sub_ps(iz0,jz0);
191 /* Calculate squared distance and things based on it */
192 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
194 rinv00 = gmx_mm_invsqrt_ps(rsq00);
196 /* Load parameters for j particles */
197 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
198 charge+jnrC+0,charge+jnrD+0);
199 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
200 invsqrta+jnrC+0,invsqrta+jnrD+0);
201 vdwjidx0A = 2*vdwtype[jnrA+0];
202 vdwjidx0B = 2*vdwtype[jnrB+0];
203 vdwjidx0C = 2*vdwtype[jnrC+0];
204 vdwjidx0D = 2*vdwtype[jnrD+0];
206 /**************************
207 * CALCULATE INTERACTIONS *
208 **************************/
210 r00 = _mm_mul_ps(rsq00,rinv00);
212 /* Compute parameters for interactions between i and j atoms */
213 qq00 = _mm_mul_ps(iq0,jq0);
214 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
215 vdwparam+vdwioffset0+vdwjidx0B,
216 vdwparam+vdwioffset0+vdwjidx0C,
217 vdwparam+vdwioffset0+vdwjidx0D,
220 /* Calculate table index by multiplying r with table scale and truncate to integer */
221 rt = _mm_mul_ps(r00,vftabscale);
222 vfitab = _mm_cvttps_epi32(rt);
224 vfeps = _mm_frcz_ps(rt);
226 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
228 twovfeps = _mm_add_ps(vfeps,vfeps);
229 vfitab = _mm_slli_epi32(vfitab,3);
231 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
232 isaprod = _mm_mul_ps(isai0,isaj0);
233 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
234 gbscale = _mm_mul_ps(isaprod,gbtabscale);
236 /* Calculate generalized born table index - this is a separate table from the normal one,
237 * but we use the same procedure by multiplying r with scale and truncating to integer.
239 rt = _mm_mul_ps(r00,gbscale);
240 gbitab = _mm_cvttps_epi32(rt);
242 gbeps = _mm_frcz_ps(rt);
244 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
246 gbitab = _mm_slli_epi32(gbitab,2);
248 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
249 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
250 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
251 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
252 _MM_TRANSPOSE4_PS(Y,F,G,H);
253 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
254 VV = _mm_macc_ps(gbeps,Fp,Y);
255 vgb = _mm_mul_ps(gbqqfactor,VV);
257 twogbeps = _mm_add_ps(gbeps,gbeps);
258 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
259 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
260 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
261 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
266 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
267 velec = _mm_mul_ps(qq00,rinv00);
268 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
270 /* CUBIC SPLINE TABLE DISPERSION */
271 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
272 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
273 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
274 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
275 _MM_TRANSPOSE4_PS(Y,F,G,H);
276 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
277 VV = _mm_macc_ps(vfeps,Fp,Y);
278 vvdw6 = _mm_mul_ps(c6_00,VV);
279 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
280 fvdw6 = _mm_mul_ps(c6_00,FF);
282 /* CUBIC SPLINE TABLE REPULSION */
283 vfitab = _mm_add_epi32(vfitab,ifour);
284 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
285 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
286 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
287 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
288 _MM_TRANSPOSE4_PS(Y,F,G,H);
289 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
290 VV = _mm_macc_ps(vfeps,Fp,Y);
291 vvdw12 = _mm_mul_ps(c12_00,VV);
292 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
293 fvdw12 = _mm_mul_ps(c12_00,FF);
294 vvdw = _mm_add_ps(vvdw12,vvdw6);
295 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
297 /* Update potential sum for this i atom from the interaction with this j atom. */
298 velecsum = _mm_add_ps(velecsum,velec);
299 vgbsum = _mm_add_ps(vgbsum,vgb);
300 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
302 fscal = _mm_add_ps(felec,fvdw);
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);
309 fjptrA = f+j_coord_offsetA;
310 fjptrB = f+j_coord_offsetB;
311 fjptrC = f+j_coord_offsetC;
312 fjptrD = f+j_coord_offsetD;
313 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
314 _mm_mul_ps(dx00,fscal),
315 _mm_mul_ps(dy00,fscal),
316 _mm_mul_ps(dz00,fscal));
318 /* Inner loop uses 95 flops */
324 /* Get j neighbor index, and coordinate index */
325 jnrlistA = jjnr[jidx];
326 jnrlistB = jjnr[jidx+1];
327 jnrlistC = jjnr[jidx+2];
328 jnrlistD = jjnr[jidx+3];
329 /* Sign of each element will be negative for non-real atoms.
330 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
331 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
333 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
334 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
335 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
336 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
337 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
338 j_coord_offsetA = DIM*jnrA;
339 j_coord_offsetB = DIM*jnrB;
340 j_coord_offsetC = DIM*jnrC;
341 j_coord_offsetD = DIM*jnrD;
343 /* load j atom coordinates */
344 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
345 x+j_coord_offsetC,x+j_coord_offsetD,
348 /* Calculate displacement vector */
349 dx00 = _mm_sub_ps(ix0,jx0);
350 dy00 = _mm_sub_ps(iy0,jy0);
351 dz00 = _mm_sub_ps(iz0,jz0);
353 /* Calculate squared distance and things based on it */
354 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
356 rinv00 = gmx_mm_invsqrt_ps(rsq00);
358 /* Load parameters for j particles */
359 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
360 charge+jnrC+0,charge+jnrD+0);
361 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
362 invsqrta+jnrC+0,invsqrta+jnrD+0);
363 vdwjidx0A = 2*vdwtype[jnrA+0];
364 vdwjidx0B = 2*vdwtype[jnrB+0];
365 vdwjidx0C = 2*vdwtype[jnrC+0];
366 vdwjidx0D = 2*vdwtype[jnrD+0];
368 /**************************
369 * CALCULATE INTERACTIONS *
370 **************************/
372 r00 = _mm_mul_ps(rsq00,rinv00);
373 r00 = _mm_andnot_ps(dummy_mask,r00);
375 /* Compute parameters for interactions between i and j atoms */
376 qq00 = _mm_mul_ps(iq0,jq0);
377 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
378 vdwparam+vdwioffset0+vdwjidx0B,
379 vdwparam+vdwioffset0+vdwjidx0C,
380 vdwparam+vdwioffset0+vdwjidx0D,
383 /* Calculate table index by multiplying r with table scale and truncate to integer */
384 rt = _mm_mul_ps(r00,vftabscale);
385 vfitab = _mm_cvttps_epi32(rt);
387 vfeps = _mm_frcz_ps(rt);
389 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
391 twovfeps = _mm_add_ps(vfeps,vfeps);
392 vfitab = _mm_slli_epi32(vfitab,3);
394 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
395 isaprod = _mm_mul_ps(isai0,isaj0);
396 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
397 gbscale = _mm_mul_ps(isaprod,gbtabscale);
399 /* Calculate generalized born table index - this is a separate table from the normal one,
400 * but we use the same procedure by multiplying r with scale and truncating to integer.
402 rt = _mm_mul_ps(r00,gbscale);
403 gbitab = _mm_cvttps_epi32(rt);
405 gbeps = _mm_frcz_ps(rt);
407 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
409 gbitab = _mm_slli_epi32(gbitab,2);
411 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
412 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
413 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
414 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
415 _MM_TRANSPOSE4_PS(Y,F,G,H);
416 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
417 VV = _mm_macc_ps(gbeps,Fp,Y);
418 vgb = _mm_mul_ps(gbqqfactor,VV);
420 twogbeps = _mm_add_ps(gbeps,gbeps);
421 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
422 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
423 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
424 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
425 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
426 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
427 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
428 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
429 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
430 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
431 velec = _mm_mul_ps(qq00,rinv00);
432 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
434 /* CUBIC SPLINE TABLE DISPERSION */
435 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
436 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
437 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
438 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
439 _MM_TRANSPOSE4_PS(Y,F,G,H);
440 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
441 VV = _mm_macc_ps(vfeps,Fp,Y);
442 vvdw6 = _mm_mul_ps(c6_00,VV);
443 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
444 fvdw6 = _mm_mul_ps(c6_00,FF);
446 /* CUBIC SPLINE TABLE REPULSION */
447 vfitab = _mm_add_epi32(vfitab,ifour);
448 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
449 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
450 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
451 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
452 _MM_TRANSPOSE4_PS(Y,F,G,H);
453 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
454 VV = _mm_macc_ps(vfeps,Fp,Y);
455 vvdw12 = _mm_mul_ps(c12_00,VV);
456 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
457 fvdw12 = _mm_mul_ps(c12_00,FF);
458 vvdw = _mm_add_ps(vvdw12,vvdw6);
459 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
461 /* Update potential sum for this i atom from the interaction with this j atom. */
462 velec = _mm_andnot_ps(dummy_mask,velec);
463 velecsum = _mm_add_ps(velecsum,velec);
464 vgb = _mm_andnot_ps(dummy_mask,vgb);
465 vgbsum = _mm_add_ps(vgbsum,vgb);
466 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
467 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
469 fscal = _mm_add_ps(felec,fvdw);
471 fscal = _mm_andnot_ps(dummy_mask,fscal);
473 /* Update vectorial force */
474 fix0 = _mm_macc_ps(dx00,fscal,fix0);
475 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
476 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
478 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
479 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
480 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
481 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
482 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
483 _mm_mul_ps(dx00,fscal),
484 _mm_mul_ps(dy00,fscal),
485 _mm_mul_ps(dz00,fscal));
487 /* Inner loop uses 96 flops */
490 /* End of innermost loop */
492 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
493 f+i_coord_offset,fshift+i_shift_offset);
496 /* Update potential energies */
497 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
498 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
499 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
500 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
501 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
503 /* Increment number of inner iterations */
504 inneriter += j_index_end - j_index_start;
506 /* Outer loop uses 10 flops */
509 /* Increment number of outer iterations */
512 /* Update outer/inner flops */
514 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*96);
517 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_single
518 * Electrostatics interaction: GeneralizedBorn
519 * VdW interaction: CubicSplineTable
520 * Geometry: Particle-Particle
521 * Calculate force/pot: Force
524 nb_kernel_ElecGB_VdwCSTab_GeomP1P1_F_avx_128_fma_single
525 (t_nblist * gmx_restrict nlist,
526 rvec * gmx_restrict xx,
527 rvec * gmx_restrict ff,
528 t_forcerec * gmx_restrict fr,
529 t_mdatoms * gmx_restrict mdatoms,
530 nb_kernel_data_t * gmx_restrict kernel_data,
531 t_nrnb * gmx_restrict nrnb)
533 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
534 * just 0 for non-waters.
535 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
536 * jnr indices corresponding to data put in the four positions in the SIMD register.
538 int i_shift_offset,i_coord_offset,outeriter,inneriter;
539 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
540 int jnrA,jnrB,jnrC,jnrD;
541 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
542 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
543 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
545 real *shiftvec,*fshift,*x,*f;
546 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
548 __m128 fscal,rcutoff,rcutoff2,jidxall;
550 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
551 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
552 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
553 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
554 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
557 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
558 __m128 minushalf = _mm_set1_ps(-0.5);
559 real *invsqrta,*dvda,*gbtab;
561 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
564 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
565 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
567 __m128i ifour = _mm_set1_epi32(4);
568 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
570 __m128 dummy_mask,cutoff_mask;
571 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
572 __m128 one = _mm_set1_ps(1.0);
573 __m128 two = _mm_set1_ps(2.0);
579 jindex = nlist->jindex;
581 shiftidx = nlist->shift;
583 shiftvec = fr->shift_vec[0];
584 fshift = fr->fshift[0];
585 facel = _mm_set1_ps(fr->epsfac);
586 charge = mdatoms->chargeA;
587 nvdwtype = fr->ntype;
589 vdwtype = mdatoms->typeA;
591 vftab = kernel_data->table_vdw->data;
592 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
594 invsqrta = fr->invsqrta;
596 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
597 gbtab = fr->gbtab.data;
598 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
600 /* Avoid stupid compiler warnings */
601 jnrA = jnrB = jnrC = jnrD = 0;
610 for(iidx=0;iidx<4*DIM;iidx++)
615 /* Start outer loop over neighborlists */
616 for(iidx=0; iidx<nri; iidx++)
618 /* Load shift vector for this list */
619 i_shift_offset = DIM*shiftidx[iidx];
621 /* Load limits for loop over neighbors */
622 j_index_start = jindex[iidx];
623 j_index_end = jindex[iidx+1];
625 /* Get outer coordinate index */
627 i_coord_offset = DIM*inr;
629 /* Load i particle coords and add shift vector */
630 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
632 fix0 = _mm_setzero_ps();
633 fiy0 = _mm_setzero_ps();
634 fiz0 = _mm_setzero_ps();
636 /* Load parameters for i particles */
637 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
638 isai0 = _mm_load1_ps(invsqrta+inr+0);
639 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
641 dvdasum = _mm_setzero_ps();
643 /* Start inner kernel loop */
644 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
647 /* Get j neighbor index, and coordinate index */
652 j_coord_offsetA = DIM*jnrA;
653 j_coord_offsetB = DIM*jnrB;
654 j_coord_offsetC = DIM*jnrC;
655 j_coord_offsetD = DIM*jnrD;
657 /* load j atom coordinates */
658 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
659 x+j_coord_offsetC,x+j_coord_offsetD,
662 /* Calculate displacement vector */
663 dx00 = _mm_sub_ps(ix0,jx0);
664 dy00 = _mm_sub_ps(iy0,jy0);
665 dz00 = _mm_sub_ps(iz0,jz0);
667 /* Calculate squared distance and things based on it */
668 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
670 rinv00 = gmx_mm_invsqrt_ps(rsq00);
672 /* Load parameters for j particles */
673 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
674 charge+jnrC+0,charge+jnrD+0);
675 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
676 invsqrta+jnrC+0,invsqrta+jnrD+0);
677 vdwjidx0A = 2*vdwtype[jnrA+0];
678 vdwjidx0B = 2*vdwtype[jnrB+0];
679 vdwjidx0C = 2*vdwtype[jnrC+0];
680 vdwjidx0D = 2*vdwtype[jnrD+0];
682 /**************************
683 * CALCULATE INTERACTIONS *
684 **************************/
686 r00 = _mm_mul_ps(rsq00,rinv00);
688 /* Compute parameters for interactions between i and j atoms */
689 qq00 = _mm_mul_ps(iq0,jq0);
690 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
691 vdwparam+vdwioffset0+vdwjidx0B,
692 vdwparam+vdwioffset0+vdwjidx0C,
693 vdwparam+vdwioffset0+vdwjidx0D,
696 /* Calculate table index by multiplying r with table scale and truncate to integer */
697 rt = _mm_mul_ps(r00,vftabscale);
698 vfitab = _mm_cvttps_epi32(rt);
700 vfeps = _mm_frcz_ps(rt);
702 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
704 twovfeps = _mm_add_ps(vfeps,vfeps);
705 vfitab = _mm_slli_epi32(vfitab,3);
707 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
708 isaprod = _mm_mul_ps(isai0,isaj0);
709 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
710 gbscale = _mm_mul_ps(isaprod,gbtabscale);
712 /* Calculate generalized born table index - this is a separate table from the normal one,
713 * but we use the same procedure by multiplying r with scale and truncating to integer.
715 rt = _mm_mul_ps(r00,gbscale);
716 gbitab = _mm_cvttps_epi32(rt);
718 gbeps = _mm_frcz_ps(rt);
720 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
722 gbitab = _mm_slli_epi32(gbitab,2);
724 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
725 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
726 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
727 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
728 _MM_TRANSPOSE4_PS(Y,F,G,H);
729 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
730 VV = _mm_macc_ps(gbeps,Fp,Y);
731 vgb = _mm_mul_ps(gbqqfactor,VV);
733 twogbeps = _mm_add_ps(gbeps,gbeps);
734 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
735 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
736 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
737 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
742 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
743 velec = _mm_mul_ps(qq00,rinv00);
744 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
746 /* CUBIC SPLINE TABLE DISPERSION */
747 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
748 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
749 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
750 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
751 _MM_TRANSPOSE4_PS(Y,F,G,H);
752 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
753 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
754 fvdw6 = _mm_mul_ps(c6_00,FF);
756 /* CUBIC SPLINE TABLE REPULSION */
757 vfitab = _mm_add_epi32(vfitab,ifour);
758 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
759 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
760 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
761 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
762 _MM_TRANSPOSE4_PS(Y,F,G,H);
763 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
764 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
765 fvdw12 = _mm_mul_ps(c12_00,FF);
766 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
768 fscal = _mm_add_ps(felec,fvdw);
770 /* Update vectorial force */
771 fix0 = _mm_macc_ps(dx00,fscal,fix0);
772 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
773 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
775 fjptrA = f+j_coord_offsetA;
776 fjptrB = f+j_coord_offsetB;
777 fjptrC = f+j_coord_offsetC;
778 fjptrD = f+j_coord_offsetD;
779 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
780 _mm_mul_ps(dx00,fscal),
781 _mm_mul_ps(dy00,fscal),
782 _mm_mul_ps(dz00,fscal));
784 /* Inner loop uses 85 flops */
790 /* Get j neighbor index, and coordinate index */
791 jnrlistA = jjnr[jidx];
792 jnrlistB = jjnr[jidx+1];
793 jnrlistC = jjnr[jidx+2];
794 jnrlistD = jjnr[jidx+3];
795 /* Sign of each element will be negative for non-real atoms.
796 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
797 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
799 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
800 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
801 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
802 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
803 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
804 j_coord_offsetA = DIM*jnrA;
805 j_coord_offsetB = DIM*jnrB;
806 j_coord_offsetC = DIM*jnrC;
807 j_coord_offsetD = DIM*jnrD;
809 /* load j atom coordinates */
810 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
811 x+j_coord_offsetC,x+j_coord_offsetD,
814 /* Calculate displacement vector */
815 dx00 = _mm_sub_ps(ix0,jx0);
816 dy00 = _mm_sub_ps(iy0,jy0);
817 dz00 = _mm_sub_ps(iz0,jz0);
819 /* Calculate squared distance and things based on it */
820 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
822 rinv00 = gmx_mm_invsqrt_ps(rsq00);
824 /* Load parameters for j particles */
825 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
826 charge+jnrC+0,charge+jnrD+0);
827 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
828 invsqrta+jnrC+0,invsqrta+jnrD+0);
829 vdwjidx0A = 2*vdwtype[jnrA+0];
830 vdwjidx0B = 2*vdwtype[jnrB+0];
831 vdwjidx0C = 2*vdwtype[jnrC+0];
832 vdwjidx0D = 2*vdwtype[jnrD+0];
834 /**************************
835 * CALCULATE INTERACTIONS *
836 **************************/
838 r00 = _mm_mul_ps(rsq00,rinv00);
839 r00 = _mm_andnot_ps(dummy_mask,r00);
841 /* Compute parameters for interactions between i and j atoms */
842 qq00 = _mm_mul_ps(iq0,jq0);
843 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
844 vdwparam+vdwioffset0+vdwjidx0B,
845 vdwparam+vdwioffset0+vdwjidx0C,
846 vdwparam+vdwioffset0+vdwjidx0D,
849 /* Calculate table index by multiplying r with table scale and truncate to integer */
850 rt = _mm_mul_ps(r00,vftabscale);
851 vfitab = _mm_cvttps_epi32(rt);
853 vfeps = _mm_frcz_ps(rt);
855 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
857 twovfeps = _mm_add_ps(vfeps,vfeps);
858 vfitab = _mm_slli_epi32(vfitab,3);
860 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
861 isaprod = _mm_mul_ps(isai0,isaj0);
862 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
863 gbscale = _mm_mul_ps(isaprod,gbtabscale);
865 /* Calculate generalized born table index - this is a separate table from the normal one,
866 * but we use the same procedure by multiplying r with scale and truncating to integer.
868 rt = _mm_mul_ps(r00,gbscale);
869 gbitab = _mm_cvttps_epi32(rt);
871 gbeps = _mm_frcz_ps(rt);
873 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
875 gbitab = _mm_slli_epi32(gbitab,2);
877 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
878 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
879 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
880 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
881 _MM_TRANSPOSE4_PS(Y,F,G,H);
882 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
883 VV = _mm_macc_ps(gbeps,Fp,Y);
884 vgb = _mm_mul_ps(gbqqfactor,VV);
886 twogbeps = _mm_add_ps(gbeps,gbeps);
887 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
888 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
889 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
890 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
891 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
892 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
893 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
894 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
895 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
896 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
897 velec = _mm_mul_ps(qq00,rinv00);
898 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
900 /* CUBIC SPLINE TABLE DISPERSION */
901 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
902 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
903 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
904 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
905 _MM_TRANSPOSE4_PS(Y,F,G,H);
906 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
907 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
908 fvdw6 = _mm_mul_ps(c6_00,FF);
910 /* CUBIC SPLINE TABLE REPULSION */
911 vfitab = _mm_add_epi32(vfitab,ifour);
912 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
913 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
914 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
915 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
916 _MM_TRANSPOSE4_PS(Y,F,G,H);
917 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
918 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
919 fvdw12 = _mm_mul_ps(c12_00,FF);
920 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
922 fscal = _mm_add_ps(felec,fvdw);
924 fscal = _mm_andnot_ps(dummy_mask,fscal);
926 /* Update vectorial force */
927 fix0 = _mm_macc_ps(dx00,fscal,fix0);
928 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
929 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
931 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
932 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
933 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
934 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
935 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
936 _mm_mul_ps(dx00,fscal),
937 _mm_mul_ps(dy00,fscal),
938 _mm_mul_ps(dz00,fscal));
940 /* Inner loop uses 86 flops */
943 /* End of innermost loop */
945 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
946 f+i_coord_offset,fshift+i_shift_offset);
948 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
949 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
951 /* Increment number of inner iterations */
952 inneriter += j_index_end - j_index_start;
954 /* Outer loop uses 7 flops */
957 /* Increment number of outer iterations */
960 /* Update outer/inner flops */
962 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*86);