2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, 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.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_VF_avx_128_fma_single
52 * Electrostatics interaction: CubicSplineTable
53 * VdW interaction: CubicSplineTable
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_VF_avx_128_fma_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
91 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
94 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
95 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
97 __m128i ifour = _mm_set1_epi32(4);
98 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
100 __m128 dummy_mask,cutoff_mask;
101 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
102 __m128 one = _mm_set1_ps(1.0);
103 __m128 two = _mm_set1_ps(2.0);
109 jindex = nlist->jindex;
111 shiftidx = nlist->shift;
113 shiftvec = fr->shift_vec[0];
114 fshift = fr->fshift[0];
115 facel = _mm_set1_ps(fr->epsfac);
116 charge = mdatoms->chargeA;
117 nvdwtype = fr->ntype;
119 vdwtype = mdatoms->typeA;
121 vftab = kernel_data->table_elec_vdw->data;
122 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
124 /* Avoid stupid compiler warnings */
125 jnrA = jnrB = jnrC = jnrD = 0;
134 for(iidx=0;iidx<4*DIM;iidx++)
139 /* Start outer loop over neighborlists */
140 for(iidx=0; iidx<nri; iidx++)
142 /* Load shift vector for this list */
143 i_shift_offset = DIM*shiftidx[iidx];
145 /* Load limits for loop over neighbors */
146 j_index_start = jindex[iidx];
147 j_index_end = jindex[iidx+1];
149 /* Get outer coordinate index */
151 i_coord_offset = DIM*inr;
153 /* Load i particle coords and add shift vector */
154 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
156 fix0 = _mm_setzero_ps();
157 fiy0 = _mm_setzero_ps();
158 fiz0 = _mm_setzero_ps();
160 /* Load parameters for i particles */
161 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
162 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
164 /* Reset potential sums */
165 velecsum = _mm_setzero_ps();
166 vvdwsum = _mm_setzero_ps();
168 /* Start inner kernel loop */
169 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
172 /* Get j neighbor index, and coordinate index */
177 j_coord_offsetA = DIM*jnrA;
178 j_coord_offsetB = DIM*jnrB;
179 j_coord_offsetC = DIM*jnrC;
180 j_coord_offsetD = DIM*jnrD;
182 /* load j atom coordinates */
183 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
184 x+j_coord_offsetC,x+j_coord_offsetD,
187 /* Calculate displacement vector */
188 dx00 = _mm_sub_ps(ix0,jx0);
189 dy00 = _mm_sub_ps(iy0,jy0);
190 dz00 = _mm_sub_ps(iz0,jz0);
192 /* Calculate squared distance and things based on it */
193 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
195 rinv00 = gmx_mm_invsqrt_ps(rsq00);
197 /* Load parameters for j particles */
198 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
199 charge+jnrC+0,charge+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 /* Calculate table index by multiplying r with table scale and truncate to integer */
220 rt = _mm_mul_ps(r00,vftabscale);
221 vfitab = _mm_cvttps_epi32(rt);
223 vfeps = _mm_frcz_ps(rt);
225 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
227 twovfeps = _mm_add_ps(vfeps,vfeps);
228 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
230 /* CUBIC SPLINE TABLE ELECTROSTATICS */
231 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
232 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
233 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
234 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
235 _MM_TRANSPOSE4_PS(Y,F,G,H);
236 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
237 VV = _mm_macc_ps(vfeps,Fp,Y);
238 velec = _mm_mul_ps(qq00,VV);
239 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
240 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
242 /* CUBIC SPLINE TABLE DISPERSION */
243 vfitab = _mm_add_epi32(vfitab,ifour);
244 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
245 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
246 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
247 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
248 _MM_TRANSPOSE4_PS(Y,F,G,H);
249 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
250 VV = _mm_macc_ps(vfeps,Fp,Y);
251 vvdw6 = _mm_mul_ps(c6_00,VV);
252 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
253 fvdw6 = _mm_mul_ps(c6_00,FF);
255 /* CUBIC SPLINE TABLE REPULSION */
256 vfitab = _mm_add_epi32(vfitab,ifour);
257 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
258 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
259 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
260 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
261 _MM_TRANSPOSE4_PS(Y,F,G,H);
262 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
263 VV = _mm_macc_ps(vfeps,Fp,Y);
264 vvdw12 = _mm_mul_ps(c12_00,VV);
265 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
266 fvdw12 = _mm_mul_ps(c12_00,FF);
267 vvdw = _mm_add_ps(vvdw12,vvdw6);
268 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
270 /* Update potential sum for this i atom from the interaction with this j atom. */
271 velecsum = _mm_add_ps(velecsum,velec);
272 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
274 fscal = _mm_add_ps(felec,fvdw);
276 /* Update vectorial force */
277 fix0 = _mm_macc_ps(dx00,fscal,fix0);
278 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
279 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
281 fjptrA = f+j_coord_offsetA;
282 fjptrB = f+j_coord_offsetB;
283 fjptrC = f+j_coord_offsetC;
284 fjptrD = f+j_coord_offsetD;
285 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
286 _mm_mul_ps(dx00,fscal),
287 _mm_mul_ps(dy00,fscal),
288 _mm_mul_ps(dz00,fscal));
290 /* Inner loop uses 76 flops */
296 /* Get j neighbor index, and coordinate index */
297 jnrlistA = jjnr[jidx];
298 jnrlistB = jjnr[jidx+1];
299 jnrlistC = jjnr[jidx+2];
300 jnrlistD = jjnr[jidx+3];
301 /* Sign of each element will be negative for non-real atoms.
302 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
303 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
305 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
306 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
307 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
308 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
309 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
310 j_coord_offsetA = DIM*jnrA;
311 j_coord_offsetB = DIM*jnrB;
312 j_coord_offsetC = DIM*jnrC;
313 j_coord_offsetD = DIM*jnrD;
315 /* load j atom coordinates */
316 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
317 x+j_coord_offsetC,x+j_coord_offsetD,
320 /* Calculate displacement vector */
321 dx00 = _mm_sub_ps(ix0,jx0);
322 dy00 = _mm_sub_ps(iy0,jy0);
323 dz00 = _mm_sub_ps(iz0,jz0);
325 /* Calculate squared distance and things based on it */
326 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
328 rinv00 = gmx_mm_invsqrt_ps(rsq00);
330 /* Load parameters for j particles */
331 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
332 charge+jnrC+0,charge+jnrD+0);
333 vdwjidx0A = 2*vdwtype[jnrA+0];
334 vdwjidx0B = 2*vdwtype[jnrB+0];
335 vdwjidx0C = 2*vdwtype[jnrC+0];
336 vdwjidx0D = 2*vdwtype[jnrD+0];
338 /**************************
339 * CALCULATE INTERACTIONS *
340 **************************/
342 r00 = _mm_mul_ps(rsq00,rinv00);
343 r00 = _mm_andnot_ps(dummy_mask,r00);
345 /* Compute parameters for interactions between i and j atoms */
346 qq00 = _mm_mul_ps(iq0,jq0);
347 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
348 vdwparam+vdwioffset0+vdwjidx0B,
349 vdwparam+vdwioffset0+vdwjidx0C,
350 vdwparam+vdwioffset0+vdwjidx0D,
353 /* Calculate table index by multiplying r with table scale and truncate to integer */
354 rt = _mm_mul_ps(r00,vftabscale);
355 vfitab = _mm_cvttps_epi32(rt);
357 vfeps = _mm_frcz_ps(rt);
359 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
361 twovfeps = _mm_add_ps(vfeps,vfeps);
362 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
364 /* CUBIC SPLINE TABLE ELECTROSTATICS */
365 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
366 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
367 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
368 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
369 _MM_TRANSPOSE4_PS(Y,F,G,H);
370 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
371 VV = _mm_macc_ps(vfeps,Fp,Y);
372 velec = _mm_mul_ps(qq00,VV);
373 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
374 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
376 /* CUBIC SPLINE TABLE DISPERSION */
377 vfitab = _mm_add_epi32(vfitab,ifour);
378 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
379 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
380 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
381 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
382 _MM_TRANSPOSE4_PS(Y,F,G,H);
383 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
384 VV = _mm_macc_ps(vfeps,Fp,Y);
385 vvdw6 = _mm_mul_ps(c6_00,VV);
386 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
387 fvdw6 = _mm_mul_ps(c6_00,FF);
389 /* CUBIC SPLINE TABLE REPULSION */
390 vfitab = _mm_add_epi32(vfitab,ifour);
391 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
392 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
393 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
394 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
395 _MM_TRANSPOSE4_PS(Y,F,G,H);
396 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
397 VV = _mm_macc_ps(vfeps,Fp,Y);
398 vvdw12 = _mm_mul_ps(c12_00,VV);
399 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
400 fvdw12 = _mm_mul_ps(c12_00,FF);
401 vvdw = _mm_add_ps(vvdw12,vvdw6);
402 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
404 /* Update potential sum for this i atom from the interaction with this j atom. */
405 velec = _mm_andnot_ps(dummy_mask,velec);
406 velecsum = _mm_add_ps(velecsum,velec);
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 77 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(vvdwsum,kernel_data->energygrp_vdw+ggid);
441 /* Increment number of inner iterations */
442 inneriter += j_index_end - j_index_start;
444 /* Outer loop uses 9 flops */
447 /* Increment number of outer iterations */
450 /* Update outer/inner flops */
452 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*77);
455 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_F_avx_128_fma_single
456 * Electrostatics interaction: CubicSplineTable
457 * VdW interaction: CubicSplineTable
458 * Geometry: Particle-Particle
459 * Calculate force/pot: Force
462 nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_F_avx_128_fma_single
463 (t_nblist * gmx_restrict nlist,
464 rvec * gmx_restrict xx,
465 rvec * gmx_restrict ff,
466 t_forcerec * gmx_restrict fr,
467 t_mdatoms * gmx_restrict mdatoms,
468 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
469 t_nrnb * gmx_restrict nrnb)
471 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
472 * just 0 for non-waters.
473 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
474 * jnr indices corresponding to data put in the four positions in the SIMD register.
476 int i_shift_offset,i_coord_offset,outeriter,inneriter;
477 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
478 int jnrA,jnrB,jnrC,jnrD;
479 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
480 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
481 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
483 real *shiftvec,*fshift,*x,*f;
484 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
486 __m128 fscal,rcutoff,rcutoff2,jidxall;
488 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
489 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
490 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
491 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
492 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
495 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
498 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
499 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
501 __m128i ifour = _mm_set1_epi32(4);
502 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
504 __m128 dummy_mask,cutoff_mask;
505 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
506 __m128 one = _mm_set1_ps(1.0);
507 __m128 two = _mm_set1_ps(2.0);
513 jindex = nlist->jindex;
515 shiftidx = nlist->shift;
517 shiftvec = fr->shift_vec[0];
518 fshift = fr->fshift[0];
519 facel = _mm_set1_ps(fr->epsfac);
520 charge = mdatoms->chargeA;
521 nvdwtype = fr->ntype;
523 vdwtype = mdatoms->typeA;
525 vftab = kernel_data->table_elec_vdw->data;
526 vftabscale = _mm_set1_ps(kernel_data->table_elec_vdw->scale);
528 /* Avoid stupid compiler warnings */
529 jnrA = jnrB = jnrC = jnrD = 0;
538 for(iidx=0;iidx<4*DIM;iidx++)
543 /* Start outer loop over neighborlists */
544 for(iidx=0; iidx<nri; iidx++)
546 /* Load shift vector for this list */
547 i_shift_offset = DIM*shiftidx[iidx];
549 /* Load limits for loop over neighbors */
550 j_index_start = jindex[iidx];
551 j_index_end = jindex[iidx+1];
553 /* Get outer coordinate index */
555 i_coord_offset = DIM*inr;
557 /* Load i particle coords and add shift vector */
558 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
560 fix0 = _mm_setzero_ps();
561 fiy0 = _mm_setzero_ps();
562 fiz0 = _mm_setzero_ps();
564 /* Load parameters for i particles */
565 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
566 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
568 /* Start inner kernel loop */
569 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
572 /* Get j neighbor index, and coordinate index */
577 j_coord_offsetA = DIM*jnrA;
578 j_coord_offsetB = DIM*jnrB;
579 j_coord_offsetC = DIM*jnrC;
580 j_coord_offsetD = DIM*jnrD;
582 /* load j atom coordinates */
583 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
584 x+j_coord_offsetC,x+j_coord_offsetD,
587 /* Calculate displacement vector */
588 dx00 = _mm_sub_ps(ix0,jx0);
589 dy00 = _mm_sub_ps(iy0,jy0);
590 dz00 = _mm_sub_ps(iz0,jz0);
592 /* Calculate squared distance and things based on it */
593 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
595 rinv00 = gmx_mm_invsqrt_ps(rsq00);
597 /* Load parameters for j particles */
598 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
599 charge+jnrC+0,charge+jnrD+0);
600 vdwjidx0A = 2*vdwtype[jnrA+0];
601 vdwjidx0B = 2*vdwtype[jnrB+0];
602 vdwjidx0C = 2*vdwtype[jnrC+0];
603 vdwjidx0D = 2*vdwtype[jnrD+0];
605 /**************************
606 * CALCULATE INTERACTIONS *
607 **************************/
609 r00 = _mm_mul_ps(rsq00,rinv00);
611 /* Compute parameters for interactions between i and j atoms */
612 qq00 = _mm_mul_ps(iq0,jq0);
613 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
614 vdwparam+vdwioffset0+vdwjidx0B,
615 vdwparam+vdwioffset0+vdwjidx0C,
616 vdwparam+vdwioffset0+vdwjidx0D,
619 /* Calculate table index by multiplying r with table scale and truncate to integer */
620 rt = _mm_mul_ps(r00,vftabscale);
621 vfitab = _mm_cvttps_epi32(rt);
623 vfeps = _mm_frcz_ps(rt);
625 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
627 twovfeps = _mm_add_ps(vfeps,vfeps);
628 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
630 /* CUBIC SPLINE TABLE ELECTROSTATICS */
631 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
632 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
633 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
634 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
635 _MM_TRANSPOSE4_PS(Y,F,G,H);
636 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
637 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
638 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
640 /* CUBIC SPLINE TABLE DISPERSION */
641 vfitab = _mm_add_epi32(vfitab,ifour);
642 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
643 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
644 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
645 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
646 _MM_TRANSPOSE4_PS(Y,F,G,H);
647 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
648 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
649 fvdw6 = _mm_mul_ps(c6_00,FF);
651 /* CUBIC SPLINE TABLE REPULSION */
652 vfitab = _mm_add_epi32(vfitab,ifour);
653 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
654 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
655 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
656 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
657 _MM_TRANSPOSE4_PS(Y,F,G,H);
658 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
659 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
660 fvdw12 = _mm_mul_ps(c12_00,FF);
661 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
663 fscal = _mm_add_ps(felec,fvdw);
665 /* Update vectorial force */
666 fix0 = _mm_macc_ps(dx00,fscal,fix0);
667 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
668 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
670 fjptrA = f+j_coord_offsetA;
671 fjptrB = f+j_coord_offsetB;
672 fjptrC = f+j_coord_offsetC;
673 fjptrD = f+j_coord_offsetD;
674 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
675 _mm_mul_ps(dx00,fscal),
676 _mm_mul_ps(dy00,fscal),
677 _mm_mul_ps(dz00,fscal));
679 /* Inner loop uses 64 flops */
685 /* Get j neighbor index, and coordinate index */
686 jnrlistA = jjnr[jidx];
687 jnrlistB = jjnr[jidx+1];
688 jnrlistC = jjnr[jidx+2];
689 jnrlistD = jjnr[jidx+3];
690 /* Sign of each element will be negative for non-real atoms.
691 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
692 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
694 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
695 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
696 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
697 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
698 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
699 j_coord_offsetA = DIM*jnrA;
700 j_coord_offsetB = DIM*jnrB;
701 j_coord_offsetC = DIM*jnrC;
702 j_coord_offsetD = DIM*jnrD;
704 /* load j atom coordinates */
705 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
706 x+j_coord_offsetC,x+j_coord_offsetD,
709 /* Calculate displacement vector */
710 dx00 = _mm_sub_ps(ix0,jx0);
711 dy00 = _mm_sub_ps(iy0,jy0);
712 dz00 = _mm_sub_ps(iz0,jz0);
714 /* Calculate squared distance and things based on it */
715 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
717 rinv00 = gmx_mm_invsqrt_ps(rsq00);
719 /* Load parameters for j particles */
720 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
721 charge+jnrC+0,charge+jnrD+0);
722 vdwjidx0A = 2*vdwtype[jnrA+0];
723 vdwjidx0B = 2*vdwtype[jnrB+0];
724 vdwjidx0C = 2*vdwtype[jnrC+0];
725 vdwjidx0D = 2*vdwtype[jnrD+0];
727 /**************************
728 * CALCULATE INTERACTIONS *
729 **************************/
731 r00 = _mm_mul_ps(rsq00,rinv00);
732 r00 = _mm_andnot_ps(dummy_mask,r00);
734 /* Compute parameters for interactions between i and j atoms */
735 qq00 = _mm_mul_ps(iq0,jq0);
736 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
737 vdwparam+vdwioffset0+vdwjidx0B,
738 vdwparam+vdwioffset0+vdwjidx0C,
739 vdwparam+vdwioffset0+vdwjidx0D,
742 /* Calculate table index by multiplying r with table scale and truncate to integer */
743 rt = _mm_mul_ps(r00,vftabscale);
744 vfitab = _mm_cvttps_epi32(rt);
746 vfeps = _mm_frcz_ps(rt);
748 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
750 twovfeps = _mm_add_ps(vfeps,vfeps);
751 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
753 /* CUBIC SPLINE TABLE ELECTROSTATICS */
754 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
755 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
756 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
757 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
758 _MM_TRANSPOSE4_PS(Y,F,G,H);
759 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
760 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
761 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
763 /* CUBIC SPLINE TABLE DISPERSION */
764 vfitab = _mm_add_epi32(vfitab,ifour);
765 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
766 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
767 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
768 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
769 _MM_TRANSPOSE4_PS(Y,F,G,H);
770 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
771 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
772 fvdw6 = _mm_mul_ps(c6_00,FF);
774 /* CUBIC SPLINE TABLE REPULSION */
775 vfitab = _mm_add_epi32(vfitab,ifour);
776 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
777 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
778 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
779 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
780 _MM_TRANSPOSE4_PS(Y,F,G,H);
781 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
782 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
783 fvdw12 = _mm_mul_ps(c12_00,FF);
784 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
786 fscal = _mm_add_ps(felec,fvdw);
788 fscal = _mm_andnot_ps(dummy_mask,fscal);
790 /* Update vectorial force */
791 fix0 = _mm_macc_ps(dx00,fscal,fix0);
792 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
793 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
795 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
796 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
797 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
798 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
799 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
800 _mm_mul_ps(dx00,fscal),
801 _mm_mul_ps(dy00,fscal),
802 _mm_mul_ps(dz00,fscal));
804 /* Inner loop uses 65 flops */
807 /* End of innermost loop */
809 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
810 f+i_coord_offset,fshift+i_shift_offset);
812 /* Increment number of inner iterations */
813 inneriter += j_index_end - j_index_start;
815 /* Outer loop uses 7 flops */
818 /* Increment number of outer iterations */
821 /* Update outer/inner flops */
823 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*65);