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 sse4_1_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_sse4_1_single.h"
48 #include "kernelutil_x86_sse4_1_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_VF_sse4_1_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_sse4_1_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 SSE, 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 tx,ty,tz,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,vftabscale,Y,F,G,H,Heps,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);
222 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
223 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
225 /* CUBIC SPLINE TABLE ELECTROSTATICS */
226 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
227 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
228 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
229 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
230 _MM_TRANSPOSE4_PS(Y,F,G,H);
231 Heps = _mm_mul_ps(vfeps,H);
232 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
233 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
234 velec = _mm_mul_ps(qq00,VV);
235 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
236 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
238 /* CUBIC SPLINE TABLE DISPERSION */
239 vfitab = _mm_add_epi32(vfitab,ifour);
240 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
241 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
242 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
243 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
244 _MM_TRANSPOSE4_PS(Y,F,G,H);
245 Heps = _mm_mul_ps(vfeps,H);
246 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
247 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
248 vvdw6 = _mm_mul_ps(c6_00,VV);
249 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
250 fvdw6 = _mm_mul_ps(c6_00,FF);
252 /* CUBIC SPLINE TABLE REPULSION */
253 vfitab = _mm_add_epi32(vfitab,ifour);
254 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
255 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
256 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
257 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
258 _MM_TRANSPOSE4_PS(Y,F,G,H);
259 Heps = _mm_mul_ps(vfeps,H);
260 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
261 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
262 vvdw12 = _mm_mul_ps(c12_00,VV);
263 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
264 fvdw12 = _mm_mul_ps(c12_00,FF);
265 vvdw = _mm_add_ps(vvdw12,vvdw6);
266 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
268 /* Update potential sum for this i atom from the interaction with this j atom. */
269 velecsum = _mm_add_ps(velecsum,velec);
270 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
272 fscal = _mm_add_ps(felec,fvdw);
274 /* Calculate temporary vectorial force */
275 tx = _mm_mul_ps(fscal,dx00);
276 ty = _mm_mul_ps(fscal,dy00);
277 tz = _mm_mul_ps(fscal,dz00);
279 /* Update vectorial force */
280 fix0 = _mm_add_ps(fix0,tx);
281 fiy0 = _mm_add_ps(fiy0,ty);
282 fiz0 = _mm_add_ps(fiz0,tz);
284 fjptrA = f+j_coord_offsetA;
285 fjptrB = f+j_coord_offsetB;
286 fjptrC = f+j_coord_offsetC;
287 fjptrD = f+j_coord_offsetD;
288 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
290 /* Inner loop uses 73 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);
356 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
357 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
359 /* CUBIC SPLINE TABLE ELECTROSTATICS */
360 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
361 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
362 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
363 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
364 _MM_TRANSPOSE4_PS(Y,F,G,H);
365 Heps = _mm_mul_ps(vfeps,H);
366 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
367 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
368 velec = _mm_mul_ps(qq00,VV);
369 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
370 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
372 /* CUBIC SPLINE TABLE DISPERSION */
373 vfitab = _mm_add_epi32(vfitab,ifour);
374 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
375 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
376 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
377 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
378 _MM_TRANSPOSE4_PS(Y,F,G,H);
379 Heps = _mm_mul_ps(vfeps,H);
380 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
381 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
382 vvdw6 = _mm_mul_ps(c6_00,VV);
383 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
384 fvdw6 = _mm_mul_ps(c6_00,FF);
386 /* CUBIC SPLINE TABLE REPULSION */
387 vfitab = _mm_add_epi32(vfitab,ifour);
388 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
389 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
390 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
391 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
392 _MM_TRANSPOSE4_PS(Y,F,G,H);
393 Heps = _mm_mul_ps(vfeps,H);
394 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
395 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
396 vvdw12 = _mm_mul_ps(c12_00,VV);
397 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
398 fvdw12 = _mm_mul_ps(c12_00,FF);
399 vvdw = _mm_add_ps(vvdw12,vvdw6);
400 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
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 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
406 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
408 fscal = _mm_add_ps(felec,fvdw);
410 fscal = _mm_andnot_ps(dummy_mask,fscal);
412 /* Calculate temporary vectorial force */
413 tx = _mm_mul_ps(fscal,dx00);
414 ty = _mm_mul_ps(fscal,dy00);
415 tz = _mm_mul_ps(fscal,dz00);
417 /* Update vectorial force */
418 fix0 = _mm_add_ps(fix0,tx);
419 fiy0 = _mm_add_ps(fiy0,ty);
420 fiz0 = _mm_add_ps(fiz0,tz);
422 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
423 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
424 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
425 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
426 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
428 /* Inner loop uses 74 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*74);
455 * Gromacs nonbonded kernel: nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_F_sse4_1_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_sse4_1_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 SSE, 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 tx,ty,tz,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,vftabscale,Y,F,G,H,Heps,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);
622 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
623 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
625 /* CUBIC SPLINE TABLE ELECTROSTATICS */
626 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
627 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
628 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
629 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
630 _MM_TRANSPOSE4_PS(Y,F,G,H);
631 Heps = _mm_mul_ps(vfeps,H);
632 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
633 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
634 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
636 /* CUBIC SPLINE TABLE DISPERSION */
637 vfitab = _mm_add_epi32(vfitab,ifour);
638 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
639 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
640 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
641 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
642 _MM_TRANSPOSE4_PS(Y,F,G,H);
643 Heps = _mm_mul_ps(vfeps,H);
644 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
645 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
646 fvdw6 = _mm_mul_ps(c6_00,FF);
648 /* CUBIC SPLINE TABLE REPULSION */
649 vfitab = _mm_add_epi32(vfitab,ifour);
650 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
651 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
652 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
653 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
654 _MM_TRANSPOSE4_PS(Y,F,G,H);
655 Heps = _mm_mul_ps(vfeps,H);
656 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
657 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
658 fvdw12 = _mm_mul_ps(c12_00,FF);
659 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
661 fscal = _mm_add_ps(felec,fvdw);
663 /* Calculate temporary vectorial force */
664 tx = _mm_mul_ps(fscal,dx00);
665 ty = _mm_mul_ps(fscal,dy00);
666 tz = _mm_mul_ps(fscal,dz00);
668 /* Update vectorial force */
669 fix0 = _mm_add_ps(fix0,tx);
670 fiy0 = _mm_add_ps(fiy0,ty);
671 fiz0 = _mm_add_ps(fiz0,tz);
673 fjptrA = f+j_coord_offsetA;
674 fjptrB = f+j_coord_offsetB;
675 fjptrC = f+j_coord_offsetC;
676 fjptrD = f+j_coord_offsetD;
677 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
679 /* Inner loop uses 61 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);
745 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
746 vfitab = _mm_slli_epi32(_mm_add_epi32(vfitab,_mm_slli_epi32(vfitab,1)),2);
748 /* CUBIC SPLINE TABLE ELECTROSTATICS */
749 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
750 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
751 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
752 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
753 _MM_TRANSPOSE4_PS(Y,F,G,H);
754 Heps = _mm_mul_ps(vfeps,H);
755 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
756 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
757 felec = _mm_xor_ps(signbit,_mm_mul_ps(_mm_mul_ps(qq00,FF),_mm_mul_ps(vftabscale,rinv00)));
759 /* CUBIC SPLINE TABLE DISPERSION */
760 vfitab = _mm_add_epi32(vfitab,ifour);
761 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
762 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
763 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
764 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
765 _MM_TRANSPOSE4_PS(Y,F,G,H);
766 Heps = _mm_mul_ps(vfeps,H);
767 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
768 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
769 fvdw6 = _mm_mul_ps(c6_00,FF);
771 /* CUBIC SPLINE TABLE REPULSION */
772 vfitab = _mm_add_epi32(vfitab,ifour);
773 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
774 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
775 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
776 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
777 _MM_TRANSPOSE4_PS(Y,F,G,H);
778 Heps = _mm_mul_ps(vfeps,H);
779 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
780 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
781 fvdw12 = _mm_mul_ps(c12_00,FF);
782 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
784 fscal = _mm_add_ps(felec,fvdw);
786 fscal = _mm_andnot_ps(dummy_mask,fscal);
788 /* Calculate temporary vectorial force */
789 tx = _mm_mul_ps(fscal,dx00);
790 ty = _mm_mul_ps(fscal,dy00);
791 tz = _mm_mul_ps(fscal,dz00);
793 /* Update vectorial force */
794 fix0 = _mm_add_ps(fix0,tx);
795 fiy0 = _mm_add_ps(fiy0,ty);
796 fiz0 = _mm_add_ps(fiz0,tz);
798 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
799 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
800 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
801 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
802 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
804 /* Inner loop uses 62 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*62);