2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_VF_avx_128_fma_single
54 * Electrostatics interaction: CubicSplineTable
55 * VdW interaction: CubicSplineTable
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
93 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
96 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
97 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
99 __m128i ifour = _mm_set1_epi32(4);
100 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
102 __m128 dummy_mask,cutoff_mask;
103 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
104 __m128 one = _mm_set1_ps(1.0);
105 __m128 two = _mm_set1_ps(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm_set1_ps(fr->epsfac);
118 charge = mdatoms->chargeA;
119 nvdwtype = fr->ntype;
121 vdwtype = mdatoms->typeA;
123 vftab = kernel_data->table_elec_vdw->data;
124 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
126 /* Avoid stupid compiler warnings */
127 jnrA = jnrB = jnrC = jnrD = 0;
136 for(iidx=0;iidx<4*DIM;iidx++)
141 /* Start outer loop over neighborlists */
142 for(iidx=0; iidx<nri; iidx++)
144 /* Load shift vector for this list */
145 i_shift_offset = DIM*shiftidx[iidx];
147 /* Load limits for loop over neighbors */
148 j_index_start = jindex[iidx];
149 j_index_end = jindex[iidx+1];
151 /* Get outer coordinate index */
153 i_coord_offset = DIM*inr;
155 /* Load i particle coords and add shift vector */
156 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
158 fix0 = _mm_setzero_ps();
159 fiy0 = _mm_setzero_ps();
160 fiz0 = _mm_setzero_ps();
162 /* Load parameters for i particles */
163 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
164 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
166 /* Reset potential sums */
167 velecsum = _mm_setzero_ps();
168 vvdwsum = _mm_setzero_ps();
170 /* Start inner kernel loop */
171 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
174 /* Get j neighbor index, and coordinate index */
179 j_coord_offsetA = DIM*jnrA;
180 j_coord_offsetB = DIM*jnrB;
181 j_coord_offsetC = DIM*jnrC;
182 j_coord_offsetD = DIM*jnrD;
184 /* load j atom coordinates */
185 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
186 x+j_coord_offsetC,x+j_coord_offsetD,
189 /* Calculate displacement vector */
190 dx00 = _mm_sub_ps(ix0,jx0);
191 dy00 = _mm_sub_ps(iy0,jy0);
192 dz00 = _mm_sub_ps(iz0,jz0);
194 /* Calculate squared distance and things based on it */
195 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
197 rinv00 = gmx_mm_invsqrt_ps(rsq00);
199 /* Load parameters for j particles */
200 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
201 charge+jnrC+0,charge+jnrD+0);
202 vdwjidx0A = 2*vdwtype[jnrA+0];
203 vdwjidx0B = 2*vdwtype[jnrB+0];
204 vdwjidx0C = 2*vdwtype[jnrC+0];
205 vdwjidx0D = 2*vdwtype[jnrD+0];
207 /**************************
208 * CALCULATE INTERACTIONS *
209 **************************/
211 r00 = _mm_mul_ps(rsq00,rinv00);
213 /* Compute parameters for interactions between i and j atoms */
214 qq00 = _mm_mul_ps(iq0,jq0);
215 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
216 vdwparam+vdwioffset0+vdwjidx0B,
217 vdwparam+vdwioffset0+vdwjidx0C,
218 vdwparam+vdwioffset0+vdwjidx0D,
221 /* Calculate table index by multiplying r with table scale and truncate to integer */
222 rt = _mm_mul_ps(r00,vftabscale);
223 vfitab = _mm_cvttps_epi32(rt);
225 vfeps = _mm_frcz_ps(rt);
227 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
229 twovfeps = _mm_add_ps(vfeps,vfeps);
230 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
232 /* CUBIC SPLINE TABLE ELECTROSTATICS */
233 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
234 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
235 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
236 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
237 _MM_TRANSPOSE4_PS(Y,F,G,H);
238 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
239 VV = _mm_macc_ps(vfeps,Fp,Y);
240 velec = _mm_mul_ps(qq00,VV);
241 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
242 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
244 /* CUBIC SPLINE TABLE DISPERSION */
245 vfitab = _mm_add_epi32(vfitab,ifour);
246 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
247 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
248 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
249 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
250 _MM_TRANSPOSE4_PS(Y,F,G,H);
251 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
252 VV = _mm_macc_ps(vfeps,Fp,Y);
253 vvdw6 = _mm_mul_ps(c6_00,VV);
254 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
255 fvdw6 = _mm_mul_ps(c6_00,FF);
257 /* CUBIC SPLINE TABLE REPULSION */
258 vfitab = _mm_add_epi32(vfitab,ifour);
259 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
260 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
261 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
262 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
263 _MM_TRANSPOSE4_PS(Y,F,G,H);
264 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
265 VV = _mm_macc_ps(vfeps,Fp,Y);
266 vvdw12 = _mm_mul_ps(c12_00,VV);
267 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
268 fvdw12 = _mm_mul_ps(c12_00,FF);
269 vvdw = _mm_add_ps(vvdw12,vvdw6);
270 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
272 /* Update potential sum for this i atom from the interaction with this j atom. */
273 velecsum = _mm_add_ps(velecsum,velec);
274 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
276 fscal = _mm_add_ps(felec,fvdw);
278 /* Update vectorial force */
279 fix0 = _mm_macc_ps(dx00,fscal,fix0);
280 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
281 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
283 fjptrA = f+j_coord_offsetA;
284 fjptrB = f+j_coord_offsetB;
285 fjptrC = f+j_coord_offsetC;
286 fjptrD = f+j_coord_offsetD;
287 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
288 _mm_mul_ps(dx00,fscal),
289 _mm_mul_ps(dy00,fscal),
290 _mm_mul_ps(dz00,fscal));
292 /* Inner loop uses 76 flops */
298 /* Get j neighbor index, and coordinate index */
299 jnrlistA = jjnr[jidx];
300 jnrlistB = jjnr[jidx+1];
301 jnrlistC = jjnr[jidx+2];
302 jnrlistD = jjnr[jidx+3];
303 /* Sign of each element will be negative for non-real atoms.
304 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
305 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
307 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
308 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
309 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
310 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
311 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
312 j_coord_offsetA = DIM*jnrA;
313 j_coord_offsetB = DIM*jnrB;
314 j_coord_offsetC = DIM*jnrC;
315 j_coord_offsetD = DIM*jnrD;
317 /* load j atom coordinates */
318 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
319 x+j_coord_offsetC,x+j_coord_offsetD,
322 /* Calculate displacement vector */
323 dx00 = _mm_sub_ps(ix0,jx0);
324 dy00 = _mm_sub_ps(iy0,jy0);
325 dz00 = _mm_sub_ps(iz0,jz0);
327 /* Calculate squared distance and things based on it */
328 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
330 rinv00 = gmx_mm_invsqrt_ps(rsq00);
332 /* Load parameters for j particles */
333 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
334 charge+jnrC+0,charge+jnrD+0);
335 vdwjidx0A = 2*vdwtype[jnrA+0];
336 vdwjidx0B = 2*vdwtype[jnrB+0];
337 vdwjidx0C = 2*vdwtype[jnrC+0];
338 vdwjidx0D = 2*vdwtype[jnrD+0];
340 /**************************
341 * CALCULATE INTERACTIONS *
342 **************************/
344 r00 = _mm_mul_ps(rsq00,rinv00);
345 r00 = _mm_andnot_ps(dummy_mask,r00);
347 /* Compute parameters for interactions between i and j atoms */
348 qq00 = _mm_mul_ps(iq0,jq0);
349 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
350 vdwparam+vdwioffset0+vdwjidx0B,
351 vdwparam+vdwioffset0+vdwjidx0C,
352 vdwparam+vdwioffset0+vdwjidx0D,
355 /* Calculate table index by multiplying r with table scale and truncate to integer */
356 rt = _mm_mul_ps(r00,vftabscale);
357 vfitab = _mm_cvttps_epi32(rt);
359 vfeps = _mm_frcz_ps(rt);
361 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
363 twovfeps = _mm_add_ps(vfeps,vfeps);
364 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
366 /* CUBIC SPLINE TABLE ELECTROSTATICS */
367 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
368 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
369 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
370 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
371 _MM_TRANSPOSE4_PS(Y,F,G,H);
372 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
373 VV = _mm_macc_ps(vfeps,Fp,Y);
374 velec = _mm_mul_ps(qq00,VV);
375 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
376 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
378 /* CUBIC SPLINE TABLE DISPERSION */
379 vfitab = _mm_add_epi32(vfitab,ifour);
380 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
381 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
382 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
383 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
384 _MM_TRANSPOSE4_PS(Y,F,G,H);
385 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
386 VV = _mm_macc_ps(vfeps,Fp,Y);
387 vvdw6 = _mm_mul_ps(c6_00,VV);
388 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
389 fvdw6 = _mm_mul_ps(c6_00,FF);
391 /* CUBIC SPLINE TABLE REPULSION */
392 vfitab = _mm_add_epi32(vfitab,ifour);
393 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
394 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
395 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
396 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
397 _MM_TRANSPOSE4_PS(Y,F,G,H);
398 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
399 VV = _mm_macc_ps(vfeps,Fp,Y);
400 vvdw12 = _mm_mul_ps(c12_00,VV);
401 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
402 fvdw12 = _mm_mul_ps(c12_00,FF);
403 vvdw = _mm_add_ps(vvdw12,vvdw6);
404 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
406 /* Update potential sum for this i atom from the interaction with this j atom. */
407 velec = _mm_andnot_ps(dummy_mask,velec);
408 velecsum = _mm_add_ps(velecsum,velec);
409 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
410 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
412 fscal = _mm_add_ps(felec,fvdw);
414 fscal = _mm_andnot_ps(dummy_mask,fscal);
416 /* Update vectorial force */
417 fix0 = _mm_macc_ps(dx00,fscal,fix0);
418 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
419 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
421 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
422 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
423 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
424 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
425 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
426 _mm_mul_ps(dx00,fscal),
427 _mm_mul_ps(dy00,fscal),
428 _mm_mul_ps(dz00,fscal));
430 /* Inner loop uses 77 flops */
433 /* End of innermost loop */
435 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
436 f+i_coord_offset,fshift+i_shift_offset);
439 /* Update potential energies */
440 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
441 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
443 /* Increment number of inner iterations */
444 inneriter += j_index_end - j_index_start;
446 /* Outer loop uses 9 flops */
449 /* Increment number of outer iterations */
452 /* Update outer/inner flops */
454 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*77);
457 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_F_avx_128_fma_single
458 * Electrostatics interaction: CubicSplineTable
459 * VdW interaction: CubicSplineTable
460 * Geometry: Particle-Particle
461 * Calculate force/pot: Force
464 nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_F_avx_128_fma_single
465 (t_nblist * gmx_restrict nlist,
466 rvec * gmx_restrict xx,
467 rvec * gmx_restrict ff,
468 t_forcerec * gmx_restrict fr,
469 t_mdatoms * gmx_restrict mdatoms,
470 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
471 t_nrnb * gmx_restrict nrnb)
473 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
474 * just 0 for non-waters.
475 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
476 * jnr indices corresponding to data put in the four positions in the SIMD register.
478 int i_shift_offset,i_coord_offset,outeriter,inneriter;
479 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
480 int jnrA,jnrB,jnrC,jnrD;
481 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
482 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
483 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
485 real *shiftvec,*fshift,*x,*f;
486 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
488 __m128 fscal,rcutoff,rcutoff2,jidxall;
490 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
491 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
492 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
493 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
494 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
497 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
500 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
501 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
503 __m128i ifour = _mm_set1_epi32(4);
504 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
506 __m128 dummy_mask,cutoff_mask;
507 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
508 __m128 one = _mm_set1_ps(1.0);
509 __m128 two = _mm_set1_ps(2.0);
515 jindex = nlist->jindex;
517 shiftidx = nlist->shift;
519 shiftvec = fr->shift_vec[0];
520 fshift = fr->fshift[0];
521 facel = _mm_set1_ps(fr->epsfac);
522 charge = mdatoms->chargeA;
523 nvdwtype = fr->ntype;
525 vdwtype = mdatoms->typeA;
527 vftab = kernel_data->table_elec_vdw->data;
528 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
530 /* Avoid stupid compiler warnings */
531 jnrA = jnrB = jnrC = jnrD = 0;
540 for(iidx=0;iidx<4*DIM;iidx++)
545 /* Start outer loop over neighborlists */
546 for(iidx=0; iidx<nri; iidx++)
548 /* Load shift vector for this list */
549 i_shift_offset = DIM*shiftidx[iidx];
551 /* Load limits for loop over neighbors */
552 j_index_start = jindex[iidx];
553 j_index_end = jindex[iidx+1];
555 /* Get outer coordinate index */
557 i_coord_offset = DIM*inr;
559 /* Load i particle coords and add shift vector */
560 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
562 fix0 = _mm_setzero_ps();
563 fiy0 = _mm_setzero_ps();
564 fiz0 = _mm_setzero_ps();
566 /* Load parameters for i particles */
567 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
568 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
570 /* Start inner kernel loop */
571 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
574 /* Get j neighbor index, and coordinate index */
579 j_coord_offsetA = DIM*jnrA;
580 j_coord_offsetB = DIM*jnrB;
581 j_coord_offsetC = DIM*jnrC;
582 j_coord_offsetD = DIM*jnrD;
584 /* load j atom coordinates */
585 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
586 x+j_coord_offsetC,x+j_coord_offsetD,
589 /* Calculate displacement vector */
590 dx00 = _mm_sub_ps(ix0,jx0);
591 dy00 = _mm_sub_ps(iy0,jy0);
592 dz00 = _mm_sub_ps(iz0,jz0);
594 /* Calculate squared distance and things based on it */
595 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
597 rinv00 = gmx_mm_invsqrt_ps(rsq00);
599 /* Load parameters for j particles */
600 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
601 charge+jnrC+0,charge+jnrD+0);
602 vdwjidx0A = 2*vdwtype[jnrA+0];
603 vdwjidx0B = 2*vdwtype[jnrB+0];
604 vdwjidx0C = 2*vdwtype[jnrC+0];
605 vdwjidx0D = 2*vdwtype[jnrD+0];
607 /**************************
608 * CALCULATE INTERACTIONS *
609 **************************/
611 r00 = _mm_mul_ps(rsq00,rinv00);
613 /* Compute parameters for interactions between i and j atoms */
614 qq00 = _mm_mul_ps(iq0,jq0);
615 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
616 vdwparam+vdwioffset0+vdwjidx0B,
617 vdwparam+vdwioffset0+vdwjidx0C,
618 vdwparam+vdwioffset0+vdwjidx0D,
621 /* Calculate table index by multiplying r with table scale and truncate to integer */
622 rt = _mm_mul_ps(r00,vftabscale);
623 vfitab = _mm_cvttps_epi32(rt);
625 vfeps = _mm_frcz_ps(rt);
627 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
629 twovfeps = _mm_add_ps(vfeps,vfeps);
630 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
632 /* CUBIC SPLINE TABLE ELECTROSTATICS */
633 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
634 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
635 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
636 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
637 _MM_TRANSPOSE4_PS(Y,F,G,H);
638 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
639 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
640 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
642 /* CUBIC SPLINE TABLE DISPERSION */
643 vfitab = _mm_add_epi32(vfitab,ifour);
644 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
645 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
646 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
647 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
648 _MM_TRANSPOSE4_PS(Y,F,G,H);
649 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
650 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
651 fvdw6 = _mm_mul_ps(c6_00,FF);
653 /* CUBIC SPLINE TABLE REPULSION */
654 vfitab = _mm_add_epi32(vfitab,ifour);
655 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
656 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
657 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
658 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
659 _MM_TRANSPOSE4_PS(Y,F,G,H);
660 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
661 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
662 fvdw12 = _mm_mul_ps(c12_00,FF);
663 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
665 fscal = _mm_add_ps(felec,fvdw);
667 /* Update vectorial force */
668 fix0 = _mm_macc_ps(dx00,fscal,fix0);
669 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
670 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
672 fjptrA = f+j_coord_offsetA;
673 fjptrB = f+j_coord_offsetB;
674 fjptrC = f+j_coord_offsetC;
675 fjptrD = f+j_coord_offsetD;
676 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
677 _mm_mul_ps(dx00,fscal),
678 _mm_mul_ps(dy00,fscal),
679 _mm_mul_ps(dz00,fscal));
681 /* Inner loop uses 64 flops */
687 /* Get j neighbor index, and coordinate index */
688 jnrlistA = jjnr[jidx];
689 jnrlistB = jjnr[jidx+1];
690 jnrlistC = jjnr[jidx+2];
691 jnrlistD = jjnr[jidx+3];
692 /* Sign of each element will be negative for non-real atoms.
693 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
694 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
696 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
697 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
698 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
699 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
700 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
701 j_coord_offsetA = DIM*jnrA;
702 j_coord_offsetB = DIM*jnrB;
703 j_coord_offsetC = DIM*jnrC;
704 j_coord_offsetD = DIM*jnrD;
706 /* load j atom coordinates */
707 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
708 x+j_coord_offsetC,x+j_coord_offsetD,
711 /* Calculate displacement vector */
712 dx00 = _mm_sub_ps(ix0,jx0);
713 dy00 = _mm_sub_ps(iy0,jy0);
714 dz00 = _mm_sub_ps(iz0,jz0);
716 /* Calculate squared distance and things based on it */
717 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
719 rinv00 = gmx_mm_invsqrt_ps(rsq00);
721 /* Load parameters for j particles */
722 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
723 charge+jnrC+0,charge+jnrD+0);
724 vdwjidx0A = 2*vdwtype[jnrA+0];
725 vdwjidx0B = 2*vdwtype[jnrB+0];
726 vdwjidx0C = 2*vdwtype[jnrC+0];
727 vdwjidx0D = 2*vdwtype[jnrD+0];
729 /**************************
730 * CALCULATE INTERACTIONS *
731 **************************/
733 r00 = _mm_mul_ps(rsq00,rinv00);
734 r00 = _mm_andnot_ps(dummy_mask,r00);
736 /* Compute parameters for interactions between i and j atoms */
737 qq00 = _mm_mul_ps(iq0,jq0);
738 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
739 vdwparam+vdwioffset0+vdwjidx0B,
740 vdwparam+vdwioffset0+vdwjidx0C,
741 vdwparam+vdwioffset0+vdwjidx0D,
744 /* Calculate table index by multiplying r with table scale and truncate to integer */
745 rt = _mm_mul_ps(r00,vftabscale);
746 vfitab = _mm_cvttps_epi32(rt);
748 vfeps = _mm_frcz_ps(rt);
750 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
752 twovfeps = _mm_add_ps(vfeps,vfeps);
753 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
755 /* CUBIC SPLINE TABLE ELECTROSTATICS */
756 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
757 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
758 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
759 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
760 _MM_TRANSPOSE4_PS(Y,F,G,H);
761 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
762 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
763 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
765 /* CUBIC SPLINE TABLE DISPERSION */
766 vfitab = _mm_add_epi32(vfitab,ifour);
767 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
768 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
769 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
770 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
771 _MM_TRANSPOSE4_PS(Y,F,G,H);
772 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
773 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
774 fvdw6 = _mm_mul_ps(c6_00,FF);
776 /* CUBIC SPLINE TABLE REPULSION */
777 vfitab = _mm_add_epi32(vfitab,ifour);
778 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
779 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
780 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
781 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
782 _MM_TRANSPOSE4_PS(Y,F,G,H);
783 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
784 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
785 fvdw12 = _mm_mul_ps(c12_00,FF);
786 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
788 fscal = _mm_add_ps(felec,fvdw);
790 fscal = _mm_andnot_ps(dummy_mask,fscal);
792 /* Update vectorial force */
793 fix0 = _mm_macc_ps(dx00,fscal,fix0);
794 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
795 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
797 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
798 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
799 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
800 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
801 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
802 _mm_mul_ps(dx00,fscal),
803 _mm_mul_ps(dy00,fscal),
804 _mm_mul_ps(dz00,fscal));
806 /* Inner loop uses 65 flops */
809 /* End of innermost loop */
811 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
812 f+i_coord_offset,fshift+i_shift_offset);
814 /* Increment number of inner iterations */
815 inneriter += j_index_end - j_index_start;
817 /* Outer loop uses 7 flops */
820 /* Increment number of outer iterations */
823 /* Update outer/inner flops */
825 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*65);