2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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 sse2_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwCSTab_GeomP1P1_VF_sse2_single
51 * Electrostatics interaction: Ewald
52 * VdW interaction: CubicSplineTable
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEw_VdwCSTab_GeomP1P1_VF_sse2_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
85 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
93 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
94 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
96 __m128i ifour = _mm_set1_epi32(4);
97 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
100 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
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->ic->epsfac);
118 charge = mdatoms->chargeA;
119 nvdwtype = fr->ntype;
121 vdwtype = mdatoms->typeA;
123 vftab = kernel_data->table_vdw->data;
124 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
126 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
127 ewtab = fr->ic->tabq_coul_FDV0;
128 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
129 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
131 /* Avoid stupid compiler warnings */
132 jnrA = jnrB = jnrC = jnrD = 0;
141 for(iidx=0;iidx<4*DIM;iidx++)
146 /* Start outer loop over neighborlists */
147 for(iidx=0; iidx<nri; iidx++)
149 /* Load shift vector for this list */
150 i_shift_offset = DIM*shiftidx[iidx];
152 /* Load limits for loop over neighbors */
153 j_index_start = jindex[iidx];
154 j_index_end = jindex[iidx+1];
156 /* Get outer coordinate index */
158 i_coord_offset = DIM*inr;
160 /* Load i particle coords and add shift vector */
161 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
163 fix0 = _mm_setzero_ps();
164 fiy0 = _mm_setzero_ps();
165 fiz0 = _mm_setzero_ps();
167 /* Load parameters for i particles */
168 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
169 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
171 /* Reset potential sums */
172 velecsum = _mm_setzero_ps();
173 vvdwsum = _mm_setzero_ps();
175 /* Start inner kernel loop */
176 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
179 /* Get j neighbor index, and coordinate index */
184 j_coord_offsetA = DIM*jnrA;
185 j_coord_offsetB = DIM*jnrB;
186 j_coord_offsetC = DIM*jnrC;
187 j_coord_offsetD = DIM*jnrD;
189 /* load j atom coordinates */
190 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
191 x+j_coord_offsetC,x+j_coord_offsetD,
194 /* Calculate displacement vector */
195 dx00 = _mm_sub_ps(ix0,jx0);
196 dy00 = _mm_sub_ps(iy0,jy0);
197 dz00 = _mm_sub_ps(iz0,jz0);
199 /* Calculate squared distance and things based on it */
200 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
202 rinv00 = sse2_invsqrt_f(rsq00);
204 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
206 /* Load parameters for j particles */
207 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
208 charge+jnrC+0,charge+jnrD+0);
209 vdwjidx0A = 2*vdwtype[jnrA+0];
210 vdwjidx0B = 2*vdwtype[jnrB+0];
211 vdwjidx0C = 2*vdwtype[jnrC+0];
212 vdwjidx0D = 2*vdwtype[jnrD+0];
214 /**************************
215 * CALCULATE INTERACTIONS *
216 **************************/
218 r00 = _mm_mul_ps(rsq00,rinv00);
220 /* Compute parameters for interactions between i and j atoms */
221 qq00 = _mm_mul_ps(iq0,jq0);
222 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
223 vdwparam+vdwioffset0+vdwjidx0B,
224 vdwparam+vdwioffset0+vdwjidx0C,
225 vdwparam+vdwioffset0+vdwjidx0D,
228 /* Calculate table index by multiplying r with table scale and truncate to integer */
229 rt = _mm_mul_ps(r00,vftabscale);
230 vfitab = _mm_cvttps_epi32(rt);
231 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
232 vfitab = _mm_slli_epi32(vfitab,3);
234 /* EWALD ELECTROSTATICS */
236 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
237 ewrt = _mm_mul_ps(r00,ewtabscale);
238 ewitab = _mm_cvttps_epi32(ewrt);
239 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
240 ewitab = _mm_slli_epi32(ewitab,2);
241 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
242 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
243 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
244 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
245 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
246 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
247 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
248 velec = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
249 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
251 /* CUBIC SPLINE TABLE DISPERSION */
252 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
253 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
254 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
255 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
256 _MM_TRANSPOSE4_PS(Y,F,G,H);
257 Heps = _mm_mul_ps(vfeps,H);
258 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
259 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
260 vvdw6 = _mm_mul_ps(c6_00,VV);
261 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
262 fvdw6 = _mm_mul_ps(c6_00,FF);
264 /* CUBIC SPLINE TABLE REPULSION */
265 vfitab = _mm_add_epi32(vfitab,ifour);
266 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
267 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
268 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
269 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
270 _MM_TRANSPOSE4_PS(Y,F,G,H);
271 Heps = _mm_mul_ps(vfeps,H);
272 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
273 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
274 vvdw12 = _mm_mul_ps(c12_00,VV);
275 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
276 fvdw12 = _mm_mul_ps(c12_00,FF);
277 vvdw = _mm_add_ps(vvdw12,vvdw6);
278 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
280 /* Update potential sum for this i atom from the interaction with this j atom. */
281 velecsum = _mm_add_ps(velecsum,velec);
282 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
284 fscal = _mm_add_ps(felec,fvdw);
286 /* Calculate temporary vectorial force */
287 tx = _mm_mul_ps(fscal,dx00);
288 ty = _mm_mul_ps(fscal,dy00);
289 tz = _mm_mul_ps(fscal,dz00);
291 /* Update vectorial force */
292 fix0 = _mm_add_ps(fix0,tx);
293 fiy0 = _mm_add_ps(fiy0,ty);
294 fiz0 = _mm_add_ps(fiz0,tz);
296 fjptrA = f+j_coord_offsetA;
297 fjptrB = f+j_coord_offsetB;
298 fjptrC = f+j_coord_offsetC;
299 fjptrD = f+j_coord_offsetD;
300 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
302 /* Inner loop uses 75 flops */
308 /* Get j neighbor index, and coordinate index */
309 jnrlistA = jjnr[jidx];
310 jnrlistB = jjnr[jidx+1];
311 jnrlistC = jjnr[jidx+2];
312 jnrlistD = jjnr[jidx+3];
313 /* Sign of each element will be negative for non-real atoms.
314 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
315 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
317 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
318 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
319 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
320 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
321 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
322 j_coord_offsetA = DIM*jnrA;
323 j_coord_offsetB = DIM*jnrB;
324 j_coord_offsetC = DIM*jnrC;
325 j_coord_offsetD = DIM*jnrD;
327 /* load j atom coordinates */
328 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
329 x+j_coord_offsetC,x+j_coord_offsetD,
332 /* Calculate displacement vector */
333 dx00 = _mm_sub_ps(ix0,jx0);
334 dy00 = _mm_sub_ps(iy0,jy0);
335 dz00 = _mm_sub_ps(iz0,jz0);
337 /* Calculate squared distance and things based on it */
338 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
340 rinv00 = sse2_invsqrt_f(rsq00);
342 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
344 /* Load parameters for j particles */
345 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
346 charge+jnrC+0,charge+jnrD+0);
347 vdwjidx0A = 2*vdwtype[jnrA+0];
348 vdwjidx0B = 2*vdwtype[jnrB+0];
349 vdwjidx0C = 2*vdwtype[jnrC+0];
350 vdwjidx0D = 2*vdwtype[jnrD+0];
352 /**************************
353 * CALCULATE INTERACTIONS *
354 **************************/
356 r00 = _mm_mul_ps(rsq00,rinv00);
357 r00 = _mm_andnot_ps(dummy_mask,r00);
359 /* Compute parameters for interactions between i and j atoms */
360 qq00 = _mm_mul_ps(iq0,jq0);
361 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
362 vdwparam+vdwioffset0+vdwjidx0B,
363 vdwparam+vdwioffset0+vdwjidx0C,
364 vdwparam+vdwioffset0+vdwjidx0D,
367 /* Calculate table index by multiplying r with table scale and truncate to integer */
368 rt = _mm_mul_ps(r00,vftabscale);
369 vfitab = _mm_cvttps_epi32(rt);
370 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
371 vfitab = _mm_slli_epi32(vfitab,3);
373 /* EWALD ELECTROSTATICS */
375 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
376 ewrt = _mm_mul_ps(r00,ewtabscale);
377 ewitab = _mm_cvttps_epi32(ewrt);
378 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
379 ewitab = _mm_slli_epi32(ewitab,2);
380 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
381 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
382 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
383 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
384 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
385 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
386 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
387 velec = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
388 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
390 /* CUBIC SPLINE TABLE DISPERSION */
391 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
392 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
393 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
394 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
395 _MM_TRANSPOSE4_PS(Y,F,G,H);
396 Heps = _mm_mul_ps(vfeps,H);
397 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
398 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
399 vvdw6 = _mm_mul_ps(c6_00,VV);
400 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
401 fvdw6 = _mm_mul_ps(c6_00,FF);
403 /* CUBIC SPLINE TABLE REPULSION */
404 vfitab = _mm_add_epi32(vfitab,ifour);
405 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
406 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
407 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
408 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
409 _MM_TRANSPOSE4_PS(Y,F,G,H);
410 Heps = _mm_mul_ps(vfeps,H);
411 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
412 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
413 vvdw12 = _mm_mul_ps(c12_00,VV);
414 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
415 fvdw12 = _mm_mul_ps(c12_00,FF);
416 vvdw = _mm_add_ps(vvdw12,vvdw6);
417 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
419 /* Update potential sum for this i atom from the interaction with this j atom. */
420 velec = _mm_andnot_ps(dummy_mask,velec);
421 velecsum = _mm_add_ps(velecsum,velec);
422 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
423 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
425 fscal = _mm_add_ps(felec,fvdw);
427 fscal = _mm_andnot_ps(dummy_mask,fscal);
429 /* Calculate temporary vectorial force */
430 tx = _mm_mul_ps(fscal,dx00);
431 ty = _mm_mul_ps(fscal,dy00);
432 tz = _mm_mul_ps(fscal,dz00);
434 /* Update vectorial force */
435 fix0 = _mm_add_ps(fix0,tx);
436 fiy0 = _mm_add_ps(fiy0,ty);
437 fiz0 = _mm_add_ps(fiz0,tz);
439 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
440 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
441 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
442 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
443 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
445 /* Inner loop uses 76 flops */
448 /* End of innermost loop */
450 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
451 f+i_coord_offset,fshift+i_shift_offset);
454 /* Update potential energies */
455 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
456 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
458 /* Increment number of inner iterations */
459 inneriter += j_index_end - j_index_start;
461 /* Outer loop uses 9 flops */
464 /* Increment number of outer iterations */
467 /* Update outer/inner flops */
469 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*76);
472 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwCSTab_GeomP1P1_F_sse2_single
473 * Electrostatics interaction: Ewald
474 * VdW interaction: CubicSplineTable
475 * Geometry: Particle-Particle
476 * Calculate force/pot: Force
479 nb_kernel_ElecEw_VdwCSTab_GeomP1P1_F_sse2_single
480 (t_nblist * gmx_restrict nlist,
481 rvec * gmx_restrict xx,
482 rvec * gmx_restrict ff,
483 struct t_forcerec * gmx_restrict fr,
484 t_mdatoms * gmx_restrict mdatoms,
485 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
486 t_nrnb * gmx_restrict nrnb)
488 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
489 * just 0 for non-waters.
490 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
491 * jnr indices corresponding to data put in the four positions in the SIMD register.
493 int i_shift_offset,i_coord_offset,outeriter,inneriter;
494 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
495 int jnrA,jnrB,jnrC,jnrD;
496 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
497 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
498 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
500 real *shiftvec,*fshift,*x,*f;
501 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
503 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
505 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
506 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
507 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
508 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
509 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
512 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
515 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
516 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
518 __m128i ifour = _mm_set1_epi32(4);
519 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
522 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
524 __m128 dummy_mask,cutoff_mask;
525 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
526 __m128 one = _mm_set1_ps(1.0);
527 __m128 two = _mm_set1_ps(2.0);
533 jindex = nlist->jindex;
535 shiftidx = nlist->shift;
537 shiftvec = fr->shift_vec[0];
538 fshift = fr->fshift[0];
539 facel = _mm_set1_ps(fr->ic->epsfac);
540 charge = mdatoms->chargeA;
541 nvdwtype = fr->ntype;
543 vdwtype = mdatoms->typeA;
545 vftab = kernel_data->table_vdw->data;
546 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
548 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
549 ewtab = fr->ic->tabq_coul_F;
550 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
551 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
553 /* Avoid stupid compiler warnings */
554 jnrA = jnrB = jnrC = jnrD = 0;
563 for(iidx=0;iidx<4*DIM;iidx++)
568 /* Start outer loop over neighborlists */
569 for(iidx=0; iidx<nri; iidx++)
571 /* Load shift vector for this list */
572 i_shift_offset = DIM*shiftidx[iidx];
574 /* Load limits for loop over neighbors */
575 j_index_start = jindex[iidx];
576 j_index_end = jindex[iidx+1];
578 /* Get outer coordinate index */
580 i_coord_offset = DIM*inr;
582 /* Load i particle coords and add shift vector */
583 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
585 fix0 = _mm_setzero_ps();
586 fiy0 = _mm_setzero_ps();
587 fiz0 = _mm_setzero_ps();
589 /* Load parameters for i particles */
590 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
591 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
593 /* Start inner kernel loop */
594 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
597 /* Get j neighbor index, and coordinate index */
602 j_coord_offsetA = DIM*jnrA;
603 j_coord_offsetB = DIM*jnrB;
604 j_coord_offsetC = DIM*jnrC;
605 j_coord_offsetD = DIM*jnrD;
607 /* load j atom coordinates */
608 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
609 x+j_coord_offsetC,x+j_coord_offsetD,
612 /* Calculate displacement vector */
613 dx00 = _mm_sub_ps(ix0,jx0);
614 dy00 = _mm_sub_ps(iy0,jy0);
615 dz00 = _mm_sub_ps(iz0,jz0);
617 /* Calculate squared distance and things based on it */
618 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
620 rinv00 = sse2_invsqrt_f(rsq00);
622 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
624 /* Load parameters for j particles */
625 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
626 charge+jnrC+0,charge+jnrD+0);
627 vdwjidx0A = 2*vdwtype[jnrA+0];
628 vdwjidx0B = 2*vdwtype[jnrB+0];
629 vdwjidx0C = 2*vdwtype[jnrC+0];
630 vdwjidx0D = 2*vdwtype[jnrD+0];
632 /**************************
633 * CALCULATE INTERACTIONS *
634 **************************/
636 r00 = _mm_mul_ps(rsq00,rinv00);
638 /* Compute parameters for interactions between i and j atoms */
639 qq00 = _mm_mul_ps(iq0,jq0);
640 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
641 vdwparam+vdwioffset0+vdwjidx0B,
642 vdwparam+vdwioffset0+vdwjidx0C,
643 vdwparam+vdwioffset0+vdwjidx0D,
646 /* Calculate table index by multiplying r with table scale and truncate to integer */
647 rt = _mm_mul_ps(r00,vftabscale);
648 vfitab = _mm_cvttps_epi32(rt);
649 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
650 vfitab = _mm_slli_epi32(vfitab,3);
652 /* EWALD ELECTROSTATICS */
654 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
655 ewrt = _mm_mul_ps(r00,ewtabscale);
656 ewitab = _mm_cvttps_epi32(ewrt);
657 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
658 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
659 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
661 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
662 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
664 /* CUBIC SPLINE TABLE DISPERSION */
665 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
666 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
667 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
668 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
669 _MM_TRANSPOSE4_PS(Y,F,G,H);
670 Heps = _mm_mul_ps(vfeps,H);
671 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
672 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
673 fvdw6 = _mm_mul_ps(c6_00,FF);
675 /* CUBIC SPLINE TABLE REPULSION */
676 vfitab = _mm_add_epi32(vfitab,ifour);
677 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
678 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
679 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
680 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
681 _MM_TRANSPOSE4_PS(Y,F,G,H);
682 Heps = _mm_mul_ps(vfeps,H);
683 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
684 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
685 fvdw12 = _mm_mul_ps(c12_00,FF);
686 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
688 fscal = _mm_add_ps(felec,fvdw);
690 /* Calculate temporary vectorial force */
691 tx = _mm_mul_ps(fscal,dx00);
692 ty = _mm_mul_ps(fscal,dy00);
693 tz = _mm_mul_ps(fscal,dz00);
695 /* Update vectorial force */
696 fix0 = _mm_add_ps(fix0,tx);
697 fiy0 = _mm_add_ps(fiy0,ty);
698 fiz0 = _mm_add_ps(fiz0,tz);
700 fjptrA = f+j_coord_offsetA;
701 fjptrB = f+j_coord_offsetB;
702 fjptrC = f+j_coord_offsetC;
703 fjptrD = f+j_coord_offsetD;
704 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
706 /* Inner loop uses 62 flops */
712 /* Get j neighbor index, and coordinate index */
713 jnrlistA = jjnr[jidx];
714 jnrlistB = jjnr[jidx+1];
715 jnrlistC = jjnr[jidx+2];
716 jnrlistD = jjnr[jidx+3];
717 /* Sign of each element will be negative for non-real atoms.
718 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
719 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
721 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
722 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
723 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
724 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
725 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
726 j_coord_offsetA = DIM*jnrA;
727 j_coord_offsetB = DIM*jnrB;
728 j_coord_offsetC = DIM*jnrC;
729 j_coord_offsetD = DIM*jnrD;
731 /* load j atom coordinates */
732 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
733 x+j_coord_offsetC,x+j_coord_offsetD,
736 /* Calculate displacement vector */
737 dx00 = _mm_sub_ps(ix0,jx0);
738 dy00 = _mm_sub_ps(iy0,jy0);
739 dz00 = _mm_sub_ps(iz0,jz0);
741 /* Calculate squared distance and things based on it */
742 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
744 rinv00 = sse2_invsqrt_f(rsq00);
746 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
748 /* Load parameters for j particles */
749 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
750 charge+jnrC+0,charge+jnrD+0);
751 vdwjidx0A = 2*vdwtype[jnrA+0];
752 vdwjidx0B = 2*vdwtype[jnrB+0];
753 vdwjidx0C = 2*vdwtype[jnrC+0];
754 vdwjidx0D = 2*vdwtype[jnrD+0];
756 /**************************
757 * CALCULATE INTERACTIONS *
758 **************************/
760 r00 = _mm_mul_ps(rsq00,rinv00);
761 r00 = _mm_andnot_ps(dummy_mask,r00);
763 /* Compute parameters for interactions between i and j atoms */
764 qq00 = _mm_mul_ps(iq0,jq0);
765 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
766 vdwparam+vdwioffset0+vdwjidx0B,
767 vdwparam+vdwioffset0+vdwjidx0C,
768 vdwparam+vdwioffset0+vdwjidx0D,
771 /* Calculate table index by multiplying r with table scale and truncate to integer */
772 rt = _mm_mul_ps(r00,vftabscale);
773 vfitab = _mm_cvttps_epi32(rt);
774 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
775 vfitab = _mm_slli_epi32(vfitab,3);
777 /* EWALD ELECTROSTATICS */
779 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
780 ewrt = _mm_mul_ps(r00,ewtabscale);
781 ewitab = _mm_cvttps_epi32(ewrt);
782 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
783 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
784 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
786 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
787 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
789 /* CUBIC SPLINE TABLE DISPERSION */
790 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
791 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
792 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
793 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
794 _MM_TRANSPOSE4_PS(Y,F,G,H);
795 Heps = _mm_mul_ps(vfeps,H);
796 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
797 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
798 fvdw6 = _mm_mul_ps(c6_00,FF);
800 /* CUBIC SPLINE TABLE REPULSION */
801 vfitab = _mm_add_epi32(vfitab,ifour);
802 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
803 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
804 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
805 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
806 _MM_TRANSPOSE4_PS(Y,F,G,H);
807 Heps = _mm_mul_ps(vfeps,H);
808 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
809 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
810 fvdw12 = _mm_mul_ps(c12_00,FF);
811 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
813 fscal = _mm_add_ps(felec,fvdw);
815 fscal = _mm_andnot_ps(dummy_mask,fscal);
817 /* Calculate temporary vectorial force */
818 tx = _mm_mul_ps(fscal,dx00);
819 ty = _mm_mul_ps(fscal,dy00);
820 tz = _mm_mul_ps(fscal,dz00);
822 /* Update vectorial force */
823 fix0 = _mm_add_ps(fix0,tx);
824 fiy0 = _mm_add_ps(fiy0,ty);
825 fiz0 = _mm_add_ps(fiz0,tz);
827 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
828 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
829 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
830 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
831 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
833 /* Inner loop uses 63 flops */
836 /* End of innermost loop */
838 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
839 f+i_coord_offset,fshift+i_shift_offset);
841 /* Increment number of inner iterations */
842 inneriter += j_index_end - j_index_start;
844 /* Outer loop uses 7 flops */
847 /* Increment number of outer iterations */
850 /* Update outer/inner flops */
852 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*63);