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_VdwLJ_GeomP1P1_VF_avx_128_fma_single
38 * Electrostatics interaction: GeneralizedBorn
39 * VdW interaction: LennardJones
40 * Geometry: Particle-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecGB_VdwLJ_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 invsqrta = fr->invsqrta;
113 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
114 gbtab = fr->gbtab.data;
115 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
117 /* Avoid stupid compiler warnings */
118 jnrA = jnrB = jnrC = jnrD = 0;
127 for(iidx=0;iidx<4*DIM;iidx++)
132 /* Start outer loop over neighborlists */
133 for(iidx=0; iidx<nri; iidx++)
135 /* Load shift vector for this list */
136 i_shift_offset = DIM*shiftidx[iidx];
138 /* Load limits for loop over neighbors */
139 j_index_start = jindex[iidx];
140 j_index_end = jindex[iidx+1];
142 /* Get outer coordinate index */
144 i_coord_offset = DIM*inr;
146 /* Load i particle coords and add shift vector */
147 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
149 fix0 = _mm_setzero_ps();
150 fiy0 = _mm_setzero_ps();
151 fiz0 = _mm_setzero_ps();
153 /* Load parameters for i particles */
154 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
155 isai0 = _mm_load1_ps(invsqrta+inr+0);
156 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
158 /* Reset potential sums */
159 velecsum = _mm_setzero_ps();
160 vgbsum = _mm_setzero_ps();
161 vvdwsum = _mm_setzero_ps();
162 dvdasum = _mm_setzero_ps();
164 /* Start inner kernel loop */
165 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
168 /* Get j neighbor index, and coordinate index */
173 j_coord_offsetA = DIM*jnrA;
174 j_coord_offsetB = DIM*jnrB;
175 j_coord_offsetC = DIM*jnrC;
176 j_coord_offsetD = DIM*jnrD;
178 /* load j atom coordinates */
179 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
180 x+j_coord_offsetC,x+j_coord_offsetD,
183 /* Calculate displacement vector */
184 dx00 = _mm_sub_ps(ix0,jx0);
185 dy00 = _mm_sub_ps(iy0,jy0);
186 dz00 = _mm_sub_ps(iz0,jz0);
188 /* Calculate squared distance and things based on it */
189 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
191 rinv00 = gmx_mm_invsqrt_ps(rsq00);
193 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
195 /* Load parameters for j particles */
196 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
197 charge+jnrC+0,charge+jnrD+0);
198 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
199 invsqrta+jnrC+0,invsqrta+jnrD+0);
200 vdwjidx0A = 2*vdwtype[jnrA+0];
201 vdwjidx0B = 2*vdwtype[jnrB+0];
202 vdwjidx0C = 2*vdwtype[jnrC+0];
203 vdwjidx0D = 2*vdwtype[jnrD+0];
205 /**************************
206 * CALCULATE INTERACTIONS *
207 **************************/
209 r00 = _mm_mul_ps(rsq00,rinv00);
211 /* Compute parameters for interactions between i and j atoms */
212 qq00 = _mm_mul_ps(iq0,jq0);
213 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
214 vdwparam+vdwioffset0+vdwjidx0B,
215 vdwparam+vdwioffset0+vdwjidx0C,
216 vdwparam+vdwioffset0+vdwjidx0D,
219 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
220 isaprod = _mm_mul_ps(isai0,isaj0);
221 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
222 gbscale = _mm_mul_ps(isaprod,gbtabscale);
224 /* Calculate generalized born table index - this is a separate table from the normal one,
225 * but we use the same procedure by multiplying r with scale and truncating to integer.
227 rt = _mm_mul_ps(r00,gbscale);
228 gbitab = _mm_cvttps_epi32(rt);
230 gbeps = _mm_frcz_ps(rt);
232 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
234 gbitab = _mm_slli_epi32(gbitab,2);
236 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
237 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
238 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
239 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
240 _MM_TRANSPOSE4_PS(Y,F,G,H);
241 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
242 VV = _mm_macc_ps(gbeps,Fp,Y);
243 vgb = _mm_mul_ps(gbqqfactor,VV);
245 twogbeps = _mm_add_ps(gbeps,gbeps);
246 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
247 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
248 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
249 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
254 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
255 velec = _mm_mul_ps(qq00,rinv00);
256 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
258 /* LENNARD-JONES DISPERSION/REPULSION */
260 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
261 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
262 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
263 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
264 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
266 /* Update potential sum for this i atom from the interaction with this j atom. */
267 velecsum = _mm_add_ps(velecsum,velec);
268 vgbsum = _mm_add_ps(vgbsum,vgb);
269 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
271 fscal = _mm_add_ps(felec,fvdw);
273 /* Update vectorial force */
274 fix0 = _mm_macc_ps(dx00,fscal,fix0);
275 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
276 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
278 fjptrA = f+j_coord_offsetA;
279 fjptrB = f+j_coord_offsetB;
280 fjptrC = f+j_coord_offsetC;
281 fjptrD = f+j_coord_offsetD;
282 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
283 _mm_mul_ps(dx00,fscal),
284 _mm_mul_ps(dy00,fscal),
285 _mm_mul_ps(dz00,fscal));
287 /* Inner loop uses 74 flops */
293 /* Get j neighbor index, and coordinate index */
294 jnrlistA = jjnr[jidx];
295 jnrlistB = jjnr[jidx+1];
296 jnrlistC = jjnr[jidx+2];
297 jnrlistD = jjnr[jidx+3];
298 /* Sign of each element will be negative for non-real atoms.
299 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
300 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
302 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
303 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
304 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
305 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
306 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
307 j_coord_offsetA = DIM*jnrA;
308 j_coord_offsetB = DIM*jnrB;
309 j_coord_offsetC = DIM*jnrC;
310 j_coord_offsetD = DIM*jnrD;
312 /* load j atom coordinates */
313 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
314 x+j_coord_offsetC,x+j_coord_offsetD,
317 /* Calculate displacement vector */
318 dx00 = _mm_sub_ps(ix0,jx0);
319 dy00 = _mm_sub_ps(iy0,jy0);
320 dz00 = _mm_sub_ps(iz0,jz0);
322 /* Calculate squared distance and things based on it */
323 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
325 rinv00 = gmx_mm_invsqrt_ps(rsq00);
327 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
329 /* Load parameters for j particles */
330 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
331 charge+jnrC+0,charge+jnrD+0);
332 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
333 invsqrta+jnrC+0,invsqrta+jnrD+0);
334 vdwjidx0A = 2*vdwtype[jnrA+0];
335 vdwjidx0B = 2*vdwtype[jnrB+0];
336 vdwjidx0C = 2*vdwtype[jnrC+0];
337 vdwjidx0D = 2*vdwtype[jnrD+0];
339 /**************************
340 * CALCULATE INTERACTIONS *
341 **************************/
343 r00 = _mm_mul_ps(rsq00,rinv00);
344 r00 = _mm_andnot_ps(dummy_mask,r00);
346 /* Compute parameters for interactions between i and j atoms */
347 qq00 = _mm_mul_ps(iq0,jq0);
348 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
349 vdwparam+vdwioffset0+vdwjidx0B,
350 vdwparam+vdwioffset0+vdwjidx0C,
351 vdwparam+vdwioffset0+vdwjidx0D,
354 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
355 isaprod = _mm_mul_ps(isai0,isaj0);
356 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
357 gbscale = _mm_mul_ps(isaprod,gbtabscale);
359 /* Calculate generalized born table index - this is a separate table from the normal one,
360 * but we use the same procedure by multiplying r with scale and truncating to integer.
362 rt = _mm_mul_ps(r00,gbscale);
363 gbitab = _mm_cvttps_epi32(rt);
365 gbeps = _mm_frcz_ps(rt);
367 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
369 gbitab = _mm_slli_epi32(gbitab,2);
371 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
372 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
373 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
374 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
375 _MM_TRANSPOSE4_PS(Y,F,G,H);
376 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
377 VV = _mm_macc_ps(gbeps,Fp,Y);
378 vgb = _mm_mul_ps(gbqqfactor,VV);
380 twogbeps = _mm_add_ps(gbeps,gbeps);
381 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
382 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
383 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
384 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
385 /* 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. */
386 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
387 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
388 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
389 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
390 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
391 velec = _mm_mul_ps(qq00,rinv00);
392 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
394 /* LENNARD-JONES DISPERSION/REPULSION */
396 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
397 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
398 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
399 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
400 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
402 /* Update potential sum for this i atom from the interaction with this j atom. */
403 velec = _mm_andnot_ps(dummy_mask,velec);
404 velecsum = _mm_add_ps(velecsum,velec);
405 vgb = _mm_andnot_ps(dummy_mask,vgb);
406 vgbsum = _mm_add_ps(vgbsum,vgb);
407 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
408 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
410 fscal = _mm_add_ps(felec,fvdw);
412 fscal = _mm_andnot_ps(dummy_mask,fscal);
414 /* Update vectorial force */
415 fix0 = _mm_macc_ps(dx00,fscal,fix0);
416 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
417 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
419 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
420 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
421 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
422 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
423 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
424 _mm_mul_ps(dx00,fscal),
425 _mm_mul_ps(dy00,fscal),
426 _mm_mul_ps(dz00,fscal));
428 /* Inner loop uses 75 flops */
431 /* End of innermost loop */
433 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
434 f+i_coord_offset,fshift+i_shift_offset);
437 /* Update potential energies */
438 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
439 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
440 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
441 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
442 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
444 /* Increment number of inner iterations */
445 inneriter += j_index_end - j_index_start;
447 /* Outer loop uses 10 flops */
450 /* Increment number of outer iterations */
453 /* Update outer/inner flops */
455 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*75);
458 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_single
459 * Electrostatics interaction: GeneralizedBorn
460 * VdW interaction: LennardJones
461 * Geometry: Particle-Particle
462 * Calculate force/pot: Force
465 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_single
466 (t_nblist * gmx_restrict nlist,
467 rvec * gmx_restrict xx,
468 rvec * gmx_restrict ff,
469 t_forcerec * gmx_restrict fr,
470 t_mdatoms * gmx_restrict mdatoms,
471 nb_kernel_data_t * gmx_restrict kernel_data,
472 t_nrnb * gmx_restrict nrnb)
474 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
475 * just 0 for non-waters.
476 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
477 * jnr indices corresponding to data put in the four positions in the SIMD register.
479 int i_shift_offset,i_coord_offset,outeriter,inneriter;
480 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
481 int jnrA,jnrB,jnrC,jnrD;
482 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
483 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
484 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
486 real *shiftvec,*fshift,*x,*f;
487 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
489 __m128 fscal,rcutoff,rcutoff2,jidxall;
491 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
492 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
493 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
494 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
495 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
498 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
499 __m128 minushalf = _mm_set1_ps(-0.5);
500 real *invsqrta,*dvda,*gbtab;
502 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
505 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
506 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
508 __m128i ifour = _mm_set1_epi32(4);
509 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
511 __m128 dummy_mask,cutoff_mask;
512 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
513 __m128 one = _mm_set1_ps(1.0);
514 __m128 two = _mm_set1_ps(2.0);
520 jindex = nlist->jindex;
522 shiftidx = nlist->shift;
524 shiftvec = fr->shift_vec[0];
525 fshift = fr->fshift[0];
526 facel = _mm_set1_ps(fr->epsfac);
527 charge = mdatoms->chargeA;
528 nvdwtype = fr->ntype;
530 vdwtype = mdatoms->typeA;
532 invsqrta = fr->invsqrta;
534 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
535 gbtab = fr->gbtab.data;
536 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
538 /* Avoid stupid compiler warnings */
539 jnrA = jnrB = jnrC = jnrD = 0;
548 for(iidx=0;iidx<4*DIM;iidx++)
553 /* Start outer loop over neighborlists */
554 for(iidx=0; iidx<nri; iidx++)
556 /* Load shift vector for this list */
557 i_shift_offset = DIM*shiftidx[iidx];
559 /* Load limits for loop over neighbors */
560 j_index_start = jindex[iidx];
561 j_index_end = jindex[iidx+1];
563 /* Get outer coordinate index */
565 i_coord_offset = DIM*inr;
567 /* Load i particle coords and add shift vector */
568 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
570 fix0 = _mm_setzero_ps();
571 fiy0 = _mm_setzero_ps();
572 fiz0 = _mm_setzero_ps();
574 /* Load parameters for i particles */
575 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
576 isai0 = _mm_load1_ps(invsqrta+inr+0);
577 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
579 dvdasum = _mm_setzero_ps();
581 /* Start inner kernel loop */
582 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
585 /* Get j neighbor index, and coordinate index */
590 j_coord_offsetA = DIM*jnrA;
591 j_coord_offsetB = DIM*jnrB;
592 j_coord_offsetC = DIM*jnrC;
593 j_coord_offsetD = DIM*jnrD;
595 /* load j atom coordinates */
596 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
597 x+j_coord_offsetC,x+j_coord_offsetD,
600 /* Calculate displacement vector */
601 dx00 = _mm_sub_ps(ix0,jx0);
602 dy00 = _mm_sub_ps(iy0,jy0);
603 dz00 = _mm_sub_ps(iz0,jz0);
605 /* Calculate squared distance and things based on it */
606 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
608 rinv00 = gmx_mm_invsqrt_ps(rsq00);
610 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
612 /* Load parameters for j particles */
613 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
614 charge+jnrC+0,charge+jnrD+0);
615 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
616 invsqrta+jnrC+0,invsqrta+jnrD+0);
617 vdwjidx0A = 2*vdwtype[jnrA+0];
618 vdwjidx0B = 2*vdwtype[jnrB+0];
619 vdwjidx0C = 2*vdwtype[jnrC+0];
620 vdwjidx0D = 2*vdwtype[jnrD+0];
622 /**************************
623 * CALCULATE INTERACTIONS *
624 **************************/
626 r00 = _mm_mul_ps(rsq00,rinv00);
628 /* Compute parameters for interactions between i and j atoms */
629 qq00 = _mm_mul_ps(iq0,jq0);
630 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
631 vdwparam+vdwioffset0+vdwjidx0B,
632 vdwparam+vdwioffset0+vdwjidx0C,
633 vdwparam+vdwioffset0+vdwjidx0D,
636 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
637 isaprod = _mm_mul_ps(isai0,isaj0);
638 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
639 gbscale = _mm_mul_ps(isaprod,gbtabscale);
641 /* Calculate generalized born table index - this is a separate table from the normal one,
642 * but we use the same procedure by multiplying r with scale and truncating to integer.
644 rt = _mm_mul_ps(r00,gbscale);
645 gbitab = _mm_cvttps_epi32(rt);
647 gbeps = _mm_frcz_ps(rt);
649 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
651 gbitab = _mm_slli_epi32(gbitab,2);
653 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
654 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
655 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
656 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
657 _MM_TRANSPOSE4_PS(Y,F,G,H);
658 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
659 VV = _mm_macc_ps(gbeps,Fp,Y);
660 vgb = _mm_mul_ps(gbqqfactor,VV);
662 twogbeps = _mm_add_ps(gbeps,gbeps);
663 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
664 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
665 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
666 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
671 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
672 velec = _mm_mul_ps(qq00,rinv00);
673 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
675 /* LENNARD-JONES DISPERSION/REPULSION */
677 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
678 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
680 fscal = _mm_add_ps(felec,fvdw);
682 /* Update vectorial force */
683 fix0 = _mm_macc_ps(dx00,fscal,fix0);
684 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
685 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
687 fjptrA = f+j_coord_offsetA;
688 fjptrB = f+j_coord_offsetB;
689 fjptrC = f+j_coord_offsetC;
690 fjptrD = f+j_coord_offsetD;
691 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
692 _mm_mul_ps(dx00,fscal),
693 _mm_mul_ps(dy00,fscal),
694 _mm_mul_ps(dz00,fscal));
696 /* Inner loop uses 67 flops */
702 /* Get j neighbor index, and coordinate index */
703 jnrlistA = jjnr[jidx];
704 jnrlistB = jjnr[jidx+1];
705 jnrlistC = jjnr[jidx+2];
706 jnrlistD = jjnr[jidx+3];
707 /* Sign of each element will be negative for non-real atoms.
708 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
709 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
711 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
712 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
713 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
714 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
715 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
716 j_coord_offsetA = DIM*jnrA;
717 j_coord_offsetB = DIM*jnrB;
718 j_coord_offsetC = DIM*jnrC;
719 j_coord_offsetD = DIM*jnrD;
721 /* load j atom coordinates */
722 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
723 x+j_coord_offsetC,x+j_coord_offsetD,
726 /* Calculate displacement vector */
727 dx00 = _mm_sub_ps(ix0,jx0);
728 dy00 = _mm_sub_ps(iy0,jy0);
729 dz00 = _mm_sub_ps(iz0,jz0);
731 /* Calculate squared distance and things based on it */
732 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
734 rinv00 = gmx_mm_invsqrt_ps(rsq00);
736 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
738 /* Load parameters for j particles */
739 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
740 charge+jnrC+0,charge+jnrD+0);
741 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
742 invsqrta+jnrC+0,invsqrta+jnrD+0);
743 vdwjidx0A = 2*vdwtype[jnrA+0];
744 vdwjidx0B = 2*vdwtype[jnrB+0];
745 vdwjidx0C = 2*vdwtype[jnrC+0];
746 vdwjidx0D = 2*vdwtype[jnrD+0];
748 /**************************
749 * CALCULATE INTERACTIONS *
750 **************************/
752 r00 = _mm_mul_ps(rsq00,rinv00);
753 r00 = _mm_andnot_ps(dummy_mask,r00);
755 /* Compute parameters for interactions between i and j atoms */
756 qq00 = _mm_mul_ps(iq0,jq0);
757 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
758 vdwparam+vdwioffset0+vdwjidx0B,
759 vdwparam+vdwioffset0+vdwjidx0C,
760 vdwparam+vdwioffset0+vdwjidx0D,
763 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
764 isaprod = _mm_mul_ps(isai0,isaj0);
765 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
766 gbscale = _mm_mul_ps(isaprod,gbtabscale);
768 /* Calculate generalized born table index - this is a separate table from the normal one,
769 * but we use the same procedure by multiplying r with scale and truncating to integer.
771 rt = _mm_mul_ps(r00,gbscale);
772 gbitab = _mm_cvttps_epi32(rt);
774 gbeps = _mm_frcz_ps(rt);
776 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
778 gbitab = _mm_slli_epi32(gbitab,2);
780 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
781 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
782 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
783 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
784 _MM_TRANSPOSE4_PS(Y,F,G,H);
785 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
786 VV = _mm_macc_ps(gbeps,Fp,Y);
787 vgb = _mm_mul_ps(gbqqfactor,VV);
789 twogbeps = _mm_add_ps(gbeps,gbeps);
790 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
791 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
792 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
793 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
794 /* 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. */
795 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
796 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
797 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
798 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
799 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
800 velec = _mm_mul_ps(qq00,rinv00);
801 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
803 /* LENNARD-JONES DISPERSION/REPULSION */
805 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
806 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
808 fscal = _mm_add_ps(felec,fvdw);
810 fscal = _mm_andnot_ps(dummy_mask,fscal);
812 /* Update vectorial force */
813 fix0 = _mm_macc_ps(dx00,fscal,fix0);
814 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
815 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
817 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
818 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
819 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
820 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
821 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
822 _mm_mul_ps(dx00,fscal),
823 _mm_mul_ps(dy00,fscal),
824 _mm_mul_ps(dz00,fscal));
826 /* Inner loop uses 68 flops */
829 /* End of innermost loop */
831 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
832 f+i_coord_offset,fshift+i_shift_offset);
834 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
835 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
837 /* Increment number of inner iterations */
838 inneriter += j_index_end - j_index_start;
840 /* Outer loop uses 7 flops */
843 /* Increment number of outer iterations */
846 /* Update outer/inner flops */
848 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*68);