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 sse4_1_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse4_1_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_sse4_1_single
51 * Electrostatics interaction: Ewald
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_sse4_1_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;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
103 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
105 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
107 __m128 dummy_mask,cutoff_mask;
108 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
109 __m128 one = _mm_set1_ps(1.0);
110 __m128 two = _mm_set1_ps(2.0);
116 jindex = nlist->jindex;
118 shiftidx = nlist->shift;
120 shiftvec = fr->shift_vec[0];
121 fshift = fr->fshift[0];
122 facel = _mm_set1_ps(fr->ic->epsfac);
123 charge = mdatoms->chargeA;
124 nvdwtype = fr->ntype;
126 vdwtype = mdatoms->typeA;
128 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
129 ewtab = fr->ic->tabq_coul_FDV0;
130 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
131 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
133 /* Setup water-specific parameters */
134 inr = nlist->iinr[0];
135 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
136 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
137 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
138 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
140 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
141 rcutoff_scalar = fr->ic->rcoulomb;
142 rcutoff = _mm_set1_ps(rcutoff_scalar);
143 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
145 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
146 rvdw = _mm_set1_ps(fr->ic->rvdw);
148 /* Avoid stupid compiler warnings */
149 jnrA = jnrB = jnrC = jnrD = 0;
158 for(iidx=0;iidx<4*DIM;iidx++)
163 /* Start outer loop over neighborlists */
164 for(iidx=0; iidx<nri; iidx++)
166 /* Load shift vector for this list */
167 i_shift_offset = DIM*shiftidx[iidx];
169 /* Load limits for loop over neighbors */
170 j_index_start = jindex[iidx];
171 j_index_end = jindex[iidx+1];
173 /* Get outer coordinate index */
175 i_coord_offset = DIM*inr;
177 /* Load i particle coords and add shift vector */
178 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
179 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
181 fix0 = _mm_setzero_ps();
182 fiy0 = _mm_setzero_ps();
183 fiz0 = _mm_setzero_ps();
184 fix1 = _mm_setzero_ps();
185 fiy1 = _mm_setzero_ps();
186 fiz1 = _mm_setzero_ps();
187 fix2 = _mm_setzero_ps();
188 fiy2 = _mm_setzero_ps();
189 fiz2 = _mm_setzero_ps();
190 fix3 = _mm_setzero_ps();
191 fiy3 = _mm_setzero_ps();
192 fiz3 = _mm_setzero_ps();
194 /* Reset potential sums */
195 velecsum = _mm_setzero_ps();
196 vvdwsum = _mm_setzero_ps();
198 /* Start inner kernel loop */
199 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
202 /* Get j neighbor index, and coordinate index */
207 j_coord_offsetA = DIM*jnrA;
208 j_coord_offsetB = DIM*jnrB;
209 j_coord_offsetC = DIM*jnrC;
210 j_coord_offsetD = DIM*jnrD;
212 /* load j atom coordinates */
213 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
214 x+j_coord_offsetC,x+j_coord_offsetD,
217 /* Calculate displacement vector */
218 dx00 = _mm_sub_ps(ix0,jx0);
219 dy00 = _mm_sub_ps(iy0,jy0);
220 dz00 = _mm_sub_ps(iz0,jz0);
221 dx10 = _mm_sub_ps(ix1,jx0);
222 dy10 = _mm_sub_ps(iy1,jy0);
223 dz10 = _mm_sub_ps(iz1,jz0);
224 dx20 = _mm_sub_ps(ix2,jx0);
225 dy20 = _mm_sub_ps(iy2,jy0);
226 dz20 = _mm_sub_ps(iz2,jz0);
227 dx30 = _mm_sub_ps(ix3,jx0);
228 dy30 = _mm_sub_ps(iy3,jy0);
229 dz30 = _mm_sub_ps(iz3,jz0);
231 /* Calculate squared distance and things based on it */
232 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
233 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
234 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
235 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
237 rinv10 = sse41_invsqrt_f(rsq10);
238 rinv20 = sse41_invsqrt_f(rsq20);
239 rinv30 = sse41_invsqrt_f(rsq30);
241 rinvsq00 = sse41_inv_f(rsq00);
242 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
243 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
244 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
246 /* Load parameters for j particles */
247 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
248 charge+jnrC+0,charge+jnrD+0);
249 vdwjidx0A = 2*vdwtype[jnrA+0];
250 vdwjidx0B = 2*vdwtype[jnrB+0];
251 vdwjidx0C = 2*vdwtype[jnrC+0];
252 vdwjidx0D = 2*vdwtype[jnrD+0];
254 fjx0 = _mm_setzero_ps();
255 fjy0 = _mm_setzero_ps();
256 fjz0 = _mm_setzero_ps();
258 /**************************
259 * CALCULATE INTERACTIONS *
260 **************************/
262 if (gmx_mm_any_lt(rsq00,rcutoff2))
265 /* Compute parameters for interactions between i and j atoms */
266 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
267 vdwparam+vdwioffset0+vdwjidx0B,
268 vdwparam+vdwioffset0+vdwjidx0C,
269 vdwparam+vdwioffset0+vdwjidx0D,
272 /* LENNARD-JONES DISPERSION/REPULSION */
274 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
275 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
276 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
277 vvdw = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
278 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
279 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
281 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
283 /* Update potential sum for this i atom from the interaction with this j atom. */
284 vvdw = _mm_and_ps(vvdw,cutoff_mask);
285 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
289 fscal = _mm_and_ps(fscal,cutoff_mask);
291 /* Calculate temporary vectorial force */
292 tx = _mm_mul_ps(fscal,dx00);
293 ty = _mm_mul_ps(fscal,dy00);
294 tz = _mm_mul_ps(fscal,dz00);
296 /* Update vectorial force */
297 fix0 = _mm_add_ps(fix0,tx);
298 fiy0 = _mm_add_ps(fiy0,ty);
299 fiz0 = _mm_add_ps(fiz0,tz);
301 fjx0 = _mm_add_ps(fjx0,tx);
302 fjy0 = _mm_add_ps(fjy0,ty);
303 fjz0 = _mm_add_ps(fjz0,tz);
307 /**************************
308 * CALCULATE INTERACTIONS *
309 **************************/
311 if (gmx_mm_any_lt(rsq10,rcutoff2))
314 r10 = _mm_mul_ps(rsq10,rinv10);
316 /* Compute parameters for interactions between i and j atoms */
317 qq10 = _mm_mul_ps(iq1,jq0);
319 /* EWALD ELECTROSTATICS */
321 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
322 ewrt = _mm_mul_ps(r10,ewtabscale);
323 ewitab = _mm_cvttps_epi32(ewrt);
324 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
325 ewitab = _mm_slli_epi32(ewitab,2);
326 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
327 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
328 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
329 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
330 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
331 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
332 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
333 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_sub_ps(rinv10,sh_ewald),velec));
334 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
336 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
338 /* Update potential sum for this i atom from the interaction with this j atom. */
339 velec = _mm_and_ps(velec,cutoff_mask);
340 velecsum = _mm_add_ps(velecsum,velec);
344 fscal = _mm_and_ps(fscal,cutoff_mask);
346 /* Calculate temporary vectorial force */
347 tx = _mm_mul_ps(fscal,dx10);
348 ty = _mm_mul_ps(fscal,dy10);
349 tz = _mm_mul_ps(fscal,dz10);
351 /* Update vectorial force */
352 fix1 = _mm_add_ps(fix1,tx);
353 fiy1 = _mm_add_ps(fiy1,ty);
354 fiz1 = _mm_add_ps(fiz1,tz);
356 fjx0 = _mm_add_ps(fjx0,tx);
357 fjy0 = _mm_add_ps(fjy0,ty);
358 fjz0 = _mm_add_ps(fjz0,tz);
362 /**************************
363 * CALCULATE INTERACTIONS *
364 **************************/
366 if (gmx_mm_any_lt(rsq20,rcutoff2))
369 r20 = _mm_mul_ps(rsq20,rinv20);
371 /* Compute parameters for interactions between i and j atoms */
372 qq20 = _mm_mul_ps(iq2,jq0);
374 /* EWALD ELECTROSTATICS */
376 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
377 ewrt = _mm_mul_ps(r20,ewtabscale);
378 ewitab = _mm_cvttps_epi32(ewrt);
379 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
380 ewitab = _mm_slli_epi32(ewitab,2);
381 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
382 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
383 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
384 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
385 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
386 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
387 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
388 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_sub_ps(rinv20,sh_ewald),velec));
389 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
391 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
393 /* Update potential sum for this i atom from the interaction with this j atom. */
394 velec = _mm_and_ps(velec,cutoff_mask);
395 velecsum = _mm_add_ps(velecsum,velec);
399 fscal = _mm_and_ps(fscal,cutoff_mask);
401 /* Calculate temporary vectorial force */
402 tx = _mm_mul_ps(fscal,dx20);
403 ty = _mm_mul_ps(fscal,dy20);
404 tz = _mm_mul_ps(fscal,dz20);
406 /* Update vectorial force */
407 fix2 = _mm_add_ps(fix2,tx);
408 fiy2 = _mm_add_ps(fiy2,ty);
409 fiz2 = _mm_add_ps(fiz2,tz);
411 fjx0 = _mm_add_ps(fjx0,tx);
412 fjy0 = _mm_add_ps(fjy0,ty);
413 fjz0 = _mm_add_ps(fjz0,tz);
417 /**************************
418 * CALCULATE INTERACTIONS *
419 **************************/
421 if (gmx_mm_any_lt(rsq30,rcutoff2))
424 r30 = _mm_mul_ps(rsq30,rinv30);
426 /* Compute parameters for interactions between i and j atoms */
427 qq30 = _mm_mul_ps(iq3,jq0);
429 /* EWALD ELECTROSTATICS */
431 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
432 ewrt = _mm_mul_ps(r30,ewtabscale);
433 ewitab = _mm_cvttps_epi32(ewrt);
434 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
435 ewitab = _mm_slli_epi32(ewitab,2);
436 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
437 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
438 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
439 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
440 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
441 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
442 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
443 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_sub_ps(rinv30,sh_ewald),velec));
444 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
446 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
448 /* Update potential sum for this i atom from the interaction with this j atom. */
449 velec = _mm_and_ps(velec,cutoff_mask);
450 velecsum = _mm_add_ps(velecsum,velec);
454 fscal = _mm_and_ps(fscal,cutoff_mask);
456 /* Calculate temporary vectorial force */
457 tx = _mm_mul_ps(fscal,dx30);
458 ty = _mm_mul_ps(fscal,dy30);
459 tz = _mm_mul_ps(fscal,dz30);
461 /* Update vectorial force */
462 fix3 = _mm_add_ps(fix3,tx);
463 fiy3 = _mm_add_ps(fiy3,ty);
464 fiz3 = _mm_add_ps(fiz3,tz);
466 fjx0 = _mm_add_ps(fjx0,tx);
467 fjy0 = _mm_add_ps(fjy0,ty);
468 fjz0 = _mm_add_ps(fjz0,tz);
472 fjptrA = f+j_coord_offsetA;
473 fjptrB = f+j_coord_offsetB;
474 fjptrC = f+j_coord_offsetC;
475 fjptrD = f+j_coord_offsetD;
477 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
479 /* Inner loop uses 179 flops */
485 /* Get j neighbor index, and coordinate index */
486 jnrlistA = jjnr[jidx];
487 jnrlistB = jjnr[jidx+1];
488 jnrlistC = jjnr[jidx+2];
489 jnrlistD = jjnr[jidx+3];
490 /* Sign of each element will be negative for non-real atoms.
491 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
492 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
494 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
495 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
496 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
497 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
498 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
499 j_coord_offsetA = DIM*jnrA;
500 j_coord_offsetB = DIM*jnrB;
501 j_coord_offsetC = DIM*jnrC;
502 j_coord_offsetD = DIM*jnrD;
504 /* load j atom coordinates */
505 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
506 x+j_coord_offsetC,x+j_coord_offsetD,
509 /* Calculate displacement vector */
510 dx00 = _mm_sub_ps(ix0,jx0);
511 dy00 = _mm_sub_ps(iy0,jy0);
512 dz00 = _mm_sub_ps(iz0,jz0);
513 dx10 = _mm_sub_ps(ix1,jx0);
514 dy10 = _mm_sub_ps(iy1,jy0);
515 dz10 = _mm_sub_ps(iz1,jz0);
516 dx20 = _mm_sub_ps(ix2,jx0);
517 dy20 = _mm_sub_ps(iy2,jy0);
518 dz20 = _mm_sub_ps(iz2,jz0);
519 dx30 = _mm_sub_ps(ix3,jx0);
520 dy30 = _mm_sub_ps(iy3,jy0);
521 dz30 = _mm_sub_ps(iz3,jz0);
523 /* Calculate squared distance and things based on it */
524 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
525 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
526 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
527 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
529 rinv10 = sse41_invsqrt_f(rsq10);
530 rinv20 = sse41_invsqrt_f(rsq20);
531 rinv30 = sse41_invsqrt_f(rsq30);
533 rinvsq00 = sse41_inv_f(rsq00);
534 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
535 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
536 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
538 /* Load parameters for j particles */
539 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
540 charge+jnrC+0,charge+jnrD+0);
541 vdwjidx0A = 2*vdwtype[jnrA+0];
542 vdwjidx0B = 2*vdwtype[jnrB+0];
543 vdwjidx0C = 2*vdwtype[jnrC+0];
544 vdwjidx0D = 2*vdwtype[jnrD+0];
546 fjx0 = _mm_setzero_ps();
547 fjy0 = _mm_setzero_ps();
548 fjz0 = _mm_setzero_ps();
550 /**************************
551 * CALCULATE INTERACTIONS *
552 **************************/
554 if (gmx_mm_any_lt(rsq00,rcutoff2))
557 /* Compute parameters for interactions between i and j atoms */
558 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
559 vdwparam+vdwioffset0+vdwjidx0B,
560 vdwparam+vdwioffset0+vdwjidx0C,
561 vdwparam+vdwioffset0+vdwjidx0D,
564 /* LENNARD-JONES DISPERSION/REPULSION */
566 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
567 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
568 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
569 vvdw = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
570 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
571 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
573 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
575 /* Update potential sum for this i atom from the interaction with this j atom. */
576 vvdw = _mm_and_ps(vvdw,cutoff_mask);
577 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
578 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
582 fscal = _mm_and_ps(fscal,cutoff_mask);
584 fscal = _mm_andnot_ps(dummy_mask,fscal);
586 /* Calculate temporary vectorial force */
587 tx = _mm_mul_ps(fscal,dx00);
588 ty = _mm_mul_ps(fscal,dy00);
589 tz = _mm_mul_ps(fscal,dz00);
591 /* Update vectorial force */
592 fix0 = _mm_add_ps(fix0,tx);
593 fiy0 = _mm_add_ps(fiy0,ty);
594 fiz0 = _mm_add_ps(fiz0,tz);
596 fjx0 = _mm_add_ps(fjx0,tx);
597 fjy0 = _mm_add_ps(fjy0,ty);
598 fjz0 = _mm_add_ps(fjz0,tz);
602 /**************************
603 * CALCULATE INTERACTIONS *
604 **************************/
606 if (gmx_mm_any_lt(rsq10,rcutoff2))
609 r10 = _mm_mul_ps(rsq10,rinv10);
610 r10 = _mm_andnot_ps(dummy_mask,r10);
612 /* Compute parameters for interactions between i and j atoms */
613 qq10 = _mm_mul_ps(iq1,jq0);
615 /* EWALD ELECTROSTATICS */
617 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
618 ewrt = _mm_mul_ps(r10,ewtabscale);
619 ewitab = _mm_cvttps_epi32(ewrt);
620 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
621 ewitab = _mm_slli_epi32(ewitab,2);
622 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
623 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
624 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
625 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
626 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
627 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
628 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
629 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_sub_ps(rinv10,sh_ewald),velec));
630 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
632 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
634 /* Update potential sum for this i atom from the interaction with this j atom. */
635 velec = _mm_and_ps(velec,cutoff_mask);
636 velec = _mm_andnot_ps(dummy_mask,velec);
637 velecsum = _mm_add_ps(velecsum,velec);
641 fscal = _mm_and_ps(fscal,cutoff_mask);
643 fscal = _mm_andnot_ps(dummy_mask,fscal);
645 /* Calculate temporary vectorial force */
646 tx = _mm_mul_ps(fscal,dx10);
647 ty = _mm_mul_ps(fscal,dy10);
648 tz = _mm_mul_ps(fscal,dz10);
650 /* Update vectorial force */
651 fix1 = _mm_add_ps(fix1,tx);
652 fiy1 = _mm_add_ps(fiy1,ty);
653 fiz1 = _mm_add_ps(fiz1,tz);
655 fjx0 = _mm_add_ps(fjx0,tx);
656 fjy0 = _mm_add_ps(fjy0,ty);
657 fjz0 = _mm_add_ps(fjz0,tz);
661 /**************************
662 * CALCULATE INTERACTIONS *
663 **************************/
665 if (gmx_mm_any_lt(rsq20,rcutoff2))
668 r20 = _mm_mul_ps(rsq20,rinv20);
669 r20 = _mm_andnot_ps(dummy_mask,r20);
671 /* Compute parameters for interactions between i and j atoms */
672 qq20 = _mm_mul_ps(iq2,jq0);
674 /* EWALD ELECTROSTATICS */
676 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
677 ewrt = _mm_mul_ps(r20,ewtabscale);
678 ewitab = _mm_cvttps_epi32(ewrt);
679 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
680 ewitab = _mm_slli_epi32(ewitab,2);
681 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
682 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
683 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
684 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
685 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
686 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
687 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
688 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_sub_ps(rinv20,sh_ewald),velec));
689 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
691 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
693 /* Update potential sum for this i atom from the interaction with this j atom. */
694 velec = _mm_and_ps(velec,cutoff_mask);
695 velec = _mm_andnot_ps(dummy_mask,velec);
696 velecsum = _mm_add_ps(velecsum,velec);
700 fscal = _mm_and_ps(fscal,cutoff_mask);
702 fscal = _mm_andnot_ps(dummy_mask,fscal);
704 /* Calculate temporary vectorial force */
705 tx = _mm_mul_ps(fscal,dx20);
706 ty = _mm_mul_ps(fscal,dy20);
707 tz = _mm_mul_ps(fscal,dz20);
709 /* Update vectorial force */
710 fix2 = _mm_add_ps(fix2,tx);
711 fiy2 = _mm_add_ps(fiy2,ty);
712 fiz2 = _mm_add_ps(fiz2,tz);
714 fjx0 = _mm_add_ps(fjx0,tx);
715 fjy0 = _mm_add_ps(fjy0,ty);
716 fjz0 = _mm_add_ps(fjz0,tz);
720 /**************************
721 * CALCULATE INTERACTIONS *
722 **************************/
724 if (gmx_mm_any_lt(rsq30,rcutoff2))
727 r30 = _mm_mul_ps(rsq30,rinv30);
728 r30 = _mm_andnot_ps(dummy_mask,r30);
730 /* Compute parameters for interactions between i and j atoms */
731 qq30 = _mm_mul_ps(iq3,jq0);
733 /* EWALD ELECTROSTATICS */
735 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
736 ewrt = _mm_mul_ps(r30,ewtabscale);
737 ewitab = _mm_cvttps_epi32(ewrt);
738 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
739 ewitab = _mm_slli_epi32(ewitab,2);
740 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
741 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
742 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
743 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
744 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
745 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
746 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
747 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_sub_ps(rinv30,sh_ewald),velec));
748 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
750 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
752 /* Update potential sum for this i atom from the interaction with this j atom. */
753 velec = _mm_and_ps(velec,cutoff_mask);
754 velec = _mm_andnot_ps(dummy_mask,velec);
755 velecsum = _mm_add_ps(velecsum,velec);
759 fscal = _mm_and_ps(fscal,cutoff_mask);
761 fscal = _mm_andnot_ps(dummy_mask,fscal);
763 /* Calculate temporary vectorial force */
764 tx = _mm_mul_ps(fscal,dx30);
765 ty = _mm_mul_ps(fscal,dy30);
766 tz = _mm_mul_ps(fscal,dz30);
768 /* Update vectorial force */
769 fix3 = _mm_add_ps(fix3,tx);
770 fiy3 = _mm_add_ps(fiy3,ty);
771 fiz3 = _mm_add_ps(fiz3,tz);
773 fjx0 = _mm_add_ps(fjx0,tx);
774 fjy0 = _mm_add_ps(fjy0,ty);
775 fjz0 = _mm_add_ps(fjz0,tz);
779 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
780 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
781 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
782 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
784 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
786 /* Inner loop uses 182 flops */
789 /* End of innermost loop */
791 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
792 f+i_coord_offset,fshift+i_shift_offset);
795 /* Update potential energies */
796 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
797 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
799 /* Increment number of inner iterations */
800 inneriter += j_index_end - j_index_start;
802 /* Outer loop uses 26 flops */
805 /* Increment number of outer iterations */
808 /* Update outer/inner flops */
810 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*182);
813 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse4_1_single
814 * Electrostatics interaction: Ewald
815 * VdW interaction: LennardJones
816 * Geometry: Water4-Particle
817 * Calculate force/pot: Force
820 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse4_1_single
821 (t_nblist * gmx_restrict nlist,
822 rvec * gmx_restrict xx,
823 rvec * gmx_restrict ff,
824 struct t_forcerec * gmx_restrict fr,
825 t_mdatoms * gmx_restrict mdatoms,
826 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
827 t_nrnb * gmx_restrict nrnb)
829 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
830 * just 0 for non-waters.
831 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
832 * jnr indices corresponding to data put in the four positions in the SIMD register.
834 int i_shift_offset,i_coord_offset,outeriter,inneriter;
835 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
836 int jnrA,jnrB,jnrC,jnrD;
837 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
838 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
839 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
841 real *shiftvec,*fshift,*x,*f;
842 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
844 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
846 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
848 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
850 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
852 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
853 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
854 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
855 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
856 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
857 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
858 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
859 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
862 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
865 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
866 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
868 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
870 __m128 dummy_mask,cutoff_mask;
871 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
872 __m128 one = _mm_set1_ps(1.0);
873 __m128 two = _mm_set1_ps(2.0);
879 jindex = nlist->jindex;
881 shiftidx = nlist->shift;
883 shiftvec = fr->shift_vec[0];
884 fshift = fr->fshift[0];
885 facel = _mm_set1_ps(fr->ic->epsfac);
886 charge = mdatoms->chargeA;
887 nvdwtype = fr->ntype;
889 vdwtype = mdatoms->typeA;
891 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
892 ewtab = fr->ic->tabq_coul_F;
893 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
894 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
896 /* Setup water-specific parameters */
897 inr = nlist->iinr[0];
898 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
899 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
900 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
901 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
903 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
904 rcutoff_scalar = fr->ic->rcoulomb;
905 rcutoff = _mm_set1_ps(rcutoff_scalar);
906 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
908 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
909 rvdw = _mm_set1_ps(fr->ic->rvdw);
911 /* Avoid stupid compiler warnings */
912 jnrA = jnrB = jnrC = jnrD = 0;
921 for(iidx=0;iidx<4*DIM;iidx++)
926 /* Start outer loop over neighborlists */
927 for(iidx=0; iidx<nri; iidx++)
929 /* Load shift vector for this list */
930 i_shift_offset = DIM*shiftidx[iidx];
932 /* Load limits for loop over neighbors */
933 j_index_start = jindex[iidx];
934 j_index_end = jindex[iidx+1];
936 /* Get outer coordinate index */
938 i_coord_offset = DIM*inr;
940 /* Load i particle coords and add shift vector */
941 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
942 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
944 fix0 = _mm_setzero_ps();
945 fiy0 = _mm_setzero_ps();
946 fiz0 = _mm_setzero_ps();
947 fix1 = _mm_setzero_ps();
948 fiy1 = _mm_setzero_ps();
949 fiz1 = _mm_setzero_ps();
950 fix2 = _mm_setzero_ps();
951 fiy2 = _mm_setzero_ps();
952 fiz2 = _mm_setzero_ps();
953 fix3 = _mm_setzero_ps();
954 fiy3 = _mm_setzero_ps();
955 fiz3 = _mm_setzero_ps();
957 /* Start inner kernel loop */
958 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
961 /* Get j neighbor index, and coordinate index */
966 j_coord_offsetA = DIM*jnrA;
967 j_coord_offsetB = DIM*jnrB;
968 j_coord_offsetC = DIM*jnrC;
969 j_coord_offsetD = DIM*jnrD;
971 /* load j atom coordinates */
972 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
973 x+j_coord_offsetC,x+j_coord_offsetD,
976 /* Calculate displacement vector */
977 dx00 = _mm_sub_ps(ix0,jx0);
978 dy00 = _mm_sub_ps(iy0,jy0);
979 dz00 = _mm_sub_ps(iz0,jz0);
980 dx10 = _mm_sub_ps(ix1,jx0);
981 dy10 = _mm_sub_ps(iy1,jy0);
982 dz10 = _mm_sub_ps(iz1,jz0);
983 dx20 = _mm_sub_ps(ix2,jx0);
984 dy20 = _mm_sub_ps(iy2,jy0);
985 dz20 = _mm_sub_ps(iz2,jz0);
986 dx30 = _mm_sub_ps(ix3,jx0);
987 dy30 = _mm_sub_ps(iy3,jy0);
988 dz30 = _mm_sub_ps(iz3,jz0);
990 /* Calculate squared distance and things based on it */
991 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
992 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
993 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
994 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
996 rinv10 = sse41_invsqrt_f(rsq10);
997 rinv20 = sse41_invsqrt_f(rsq20);
998 rinv30 = sse41_invsqrt_f(rsq30);
1000 rinvsq00 = sse41_inv_f(rsq00);
1001 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1002 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1003 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1005 /* Load parameters for j particles */
1006 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1007 charge+jnrC+0,charge+jnrD+0);
1008 vdwjidx0A = 2*vdwtype[jnrA+0];
1009 vdwjidx0B = 2*vdwtype[jnrB+0];
1010 vdwjidx0C = 2*vdwtype[jnrC+0];
1011 vdwjidx0D = 2*vdwtype[jnrD+0];
1013 fjx0 = _mm_setzero_ps();
1014 fjy0 = _mm_setzero_ps();
1015 fjz0 = _mm_setzero_ps();
1017 /**************************
1018 * CALCULATE INTERACTIONS *
1019 **************************/
1021 if (gmx_mm_any_lt(rsq00,rcutoff2))
1024 /* Compute parameters for interactions between i and j atoms */
1025 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1026 vdwparam+vdwioffset0+vdwjidx0B,
1027 vdwparam+vdwioffset0+vdwjidx0C,
1028 vdwparam+vdwioffset0+vdwjidx0D,
1031 /* LENNARD-JONES DISPERSION/REPULSION */
1033 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1034 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1036 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1040 fscal = _mm_and_ps(fscal,cutoff_mask);
1042 /* Calculate temporary vectorial force */
1043 tx = _mm_mul_ps(fscal,dx00);
1044 ty = _mm_mul_ps(fscal,dy00);
1045 tz = _mm_mul_ps(fscal,dz00);
1047 /* Update vectorial force */
1048 fix0 = _mm_add_ps(fix0,tx);
1049 fiy0 = _mm_add_ps(fiy0,ty);
1050 fiz0 = _mm_add_ps(fiz0,tz);
1052 fjx0 = _mm_add_ps(fjx0,tx);
1053 fjy0 = _mm_add_ps(fjy0,ty);
1054 fjz0 = _mm_add_ps(fjz0,tz);
1058 /**************************
1059 * CALCULATE INTERACTIONS *
1060 **************************/
1062 if (gmx_mm_any_lt(rsq10,rcutoff2))
1065 r10 = _mm_mul_ps(rsq10,rinv10);
1067 /* Compute parameters for interactions between i and j atoms */
1068 qq10 = _mm_mul_ps(iq1,jq0);
1070 /* EWALD ELECTROSTATICS */
1072 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1073 ewrt = _mm_mul_ps(r10,ewtabscale);
1074 ewitab = _mm_cvttps_epi32(ewrt);
1075 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1076 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1077 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1079 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1080 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
1082 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1086 fscal = _mm_and_ps(fscal,cutoff_mask);
1088 /* Calculate temporary vectorial force */
1089 tx = _mm_mul_ps(fscal,dx10);
1090 ty = _mm_mul_ps(fscal,dy10);
1091 tz = _mm_mul_ps(fscal,dz10);
1093 /* Update vectorial force */
1094 fix1 = _mm_add_ps(fix1,tx);
1095 fiy1 = _mm_add_ps(fiy1,ty);
1096 fiz1 = _mm_add_ps(fiz1,tz);
1098 fjx0 = _mm_add_ps(fjx0,tx);
1099 fjy0 = _mm_add_ps(fjy0,ty);
1100 fjz0 = _mm_add_ps(fjz0,tz);
1104 /**************************
1105 * CALCULATE INTERACTIONS *
1106 **************************/
1108 if (gmx_mm_any_lt(rsq20,rcutoff2))
1111 r20 = _mm_mul_ps(rsq20,rinv20);
1113 /* Compute parameters for interactions between i and j atoms */
1114 qq20 = _mm_mul_ps(iq2,jq0);
1116 /* EWALD ELECTROSTATICS */
1118 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1119 ewrt = _mm_mul_ps(r20,ewtabscale);
1120 ewitab = _mm_cvttps_epi32(ewrt);
1121 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1122 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1123 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1125 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1126 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
1128 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1132 fscal = _mm_and_ps(fscal,cutoff_mask);
1134 /* Calculate temporary vectorial force */
1135 tx = _mm_mul_ps(fscal,dx20);
1136 ty = _mm_mul_ps(fscal,dy20);
1137 tz = _mm_mul_ps(fscal,dz20);
1139 /* Update vectorial force */
1140 fix2 = _mm_add_ps(fix2,tx);
1141 fiy2 = _mm_add_ps(fiy2,ty);
1142 fiz2 = _mm_add_ps(fiz2,tz);
1144 fjx0 = _mm_add_ps(fjx0,tx);
1145 fjy0 = _mm_add_ps(fjy0,ty);
1146 fjz0 = _mm_add_ps(fjz0,tz);
1150 /**************************
1151 * CALCULATE INTERACTIONS *
1152 **************************/
1154 if (gmx_mm_any_lt(rsq30,rcutoff2))
1157 r30 = _mm_mul_ps(rsq30,rinv30);
1159 /* Compute parameters for interactions between i and j atoms */
1160 qq30 = _mm_mul_ps(iq3,jq0);
1162 /* EWALD ELECTROSTATICS */
1164 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1165 ewrt = _mm_mul_ps(r30,ewtabscale);
1166 ewitab = _mm_cvttps_epi32(ewrt);
1167 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1168 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1169 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1171 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1172 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
1174 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1178 fscal = _mm_and_ps(fscal,cutoff_mask);
1180 /* Calculate temporary vectorial force */
1181 tx = _mm_mul_ps(fscal,dx30);
1182 ty = _mm_mul_ps(fscal,dy30);
1183 tz = _mm_mul_ps(fscal,dz30);
1185 /* Update vectorial force */
1186 fix3 = _mm_add_ps(fix3,tx);
1187 fiy3 = _mm_add_ps(fiy3,ty);
1188 fiz3 = _mm_add_ps(fiz3,tz);
1190 fjx0 = _mm_add_ps(fjx0,tx);
1191 fjy0 = _mm_add_ps(fjy0,ty);
1192 fjz0 = _mm_add_ps(fjz0,tz);
1196 fjptrA = f+j_coord_offsetA;
1197 fjptrB = f+j_coord_offsetB;
1198 fjptrC = f+j_coord_offsetC;
1199 fjptrD = f+j_coord_offsetD;
1201 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1203 /* Inner loop uses 147 flops */
1206 if(jidx<j_index_end)
1209 /* Get j neighbor index, and coordinate index */
1210 jnrlistA = jjnr[jidx];
1211 jnrlistB = jjnr[jidx+1];
1212 jnrlistC = jjnr[jidx+2];
1213 jnrlistD = jjnr[jidx+3];
1214 /* Sign of each element will be negative for non-real atoms.
1215 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1216 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1218 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1219 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1220 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1221 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1222 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1223 j_coord_offsetA = DIM*jnrA;
1224 j_coord_offsetB = DIM*jnrB;
1225 j_coord_offsetC = DIM*jnrC;
1226 j_coord_offsetD = DIM*jnrD;
1228 /* load j atom coordinates */
1229 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1230 x+j_coord_offsetC,x+j_coord_offsetD,
1233 /* Calculate displacement vector */
1234 dx00 = _mm_sub_ps(ix0,jx0);
1235 dy00 = _mm_sub_ps(iy0,jy0);
1236 dz00 = _mm_sub_ps(iz0,jz0);
1237 dx10 = _mm_sub_ps(ix1,jx0);
1238 dy10 = _mm_sub_ps(iy1,jy0);
1239 dz10 = _mm_sub_ps(iz1,jz0);
1240 dx20 = _mm_sub_ps(ix2,jx0);
1241 dy20 = _mm_sub_ps(iy2,jy0);
1242 dz20 = _mm_sub_ps(iz2,jz0);
1243 dx30 = _mm_sub_ps(ix3,jx0);
1244 dy30 = _mm_sub_ps(iy3,jy0);
1245 dz30 = _mm_sub_ps(iz3,jz0);
1247 /* Calculate squared distance and things based on it */
1248 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1249 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1250 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1251 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1253 rinv10 = sse41_invsqrt_f(rsq10);
1254 rinv20 = sse41_invsqrt_f(rsq20);
1255 rinv30 = sse41_invsqrt_f(rsq30);
1257 rinvsq00 = sse41_inv_f(rsq00);
1258 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1259 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1260 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1262 /* Load parameters for j particles */
1263 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1264 charge+jnrC+0,charge+jnrD+0);
1265 vdwjidx0A = 2*vdwtype[jnrA+0];
1266 vdwjidx0B = 2*vdwtype[jnrB+0];
1267 vdwjidx0C = 2*vdwtype[jnrC+0];
1268 vdwjidx0D = 2*vdwtype[jnrD+0];
1270 fjx0 = _mm_setzero_ps();
1271 fjy0 = _mm_setzero_ps();
1272 fjz0 = _mm_setzero_ps();
1274 /**************************
1275 * CALCULATE INTERACTIONS *
1276 **************************/
1278 if (gmx_mm_any_lt(rsq00,rcutoff2))
1281 /* Compute parameters for interactions between i and j atoms */
1282 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1283 vdwparam+vdwioffset0+vdwjidx0B,
1284 vdwparam+vdwioffset0+vdwjidx0C,
1285 vdwparam+vdwioffset0+vdwjidx0D,
1288 /* LENNARD-JONES DISPERSION/REPULSION */
1290 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1291 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1293 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1297 fscal = _mm_and_ps(fscal,cutoff_mask);
1299 fscal = _mm_andnot_ps(dummy_mask,fscal);
1301 /* Calculate temporary vectorial force */
1302 tx = _mm_mul_ps(fscal,dx00);
1303 ty = _mm_mul_ps(fscal,dy00);
1304 tz = _mm_mul_ps(fscal,dz00);
1306 /* Update vectorial force */
1307 fix0 = _mm_add_ps(fix0,tx);
1308 fiy0 = _mm_add_ps(fiy0,ty);
1309 fiz0 = _mm_add_ps(fiz0,tz);
1311 fjx0 = _mm_add_ps(fjx0,tx);
1312 fjy0 = _mm_add_ps(fjy0,ty);
1313 fjz0 = _mm_add_ps(fjz0,tz);
1317 /**************************
1318 * CALCULATE INTERACTIONS *
1319 **************************/
1321 if (gmx_mm_any_lt(rsq10,rcutoff2))
1324 r10 = _mm_mul_ps(rsq10,rinv10);
1325 r10 = _mm_andnot_ps(dummy_mask,r10);
1327 /* Compute parameters for interactions between i and j atoms */
1328 qq10 = _mm_mul_ps(iq1,jq0);
1330 /* EWALD ELECTROSTATICS */
1332 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1333 ewrt = _mm_mul_ps(r10,ewtabscale);
1334 ewitab = _mm_cvttps_epi32(ewrt);
1335 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1336 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1337 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1339 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1340 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
1342 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1346 fscal = _mm_and_ps(fscal,cutoff_mask);
1348 fscal = _mm_andnot_ps(dummy_mask,fscal);
1350 /* Calculate temporary vectorial force */
1351 tx = _mm_mul_ps(fscal,dx10);
1352 ty = _mm_mul_ps(fscal,dy10);
1353 tz = _mm_mul_ps(fscal,dz10);
1355 /* Update vectorial force */
1356 fix1 = _mm_add_ps(fix1,tx);
1357 fiy1 = _mm_add_ps(fiy1,ty);
1358 fiz1 = _mm_add_ps(fiz1,tz);
1360 fjx0 = _mm_add_ps(fjx0,tx);
1361 fjy0 = _mm_add_ps(fjy0,ty);
1362 fjz0 = _mm_add_ps(fjz0,tz);
1366 /**************************
1367 * CALCULATE INTERACTIONS *
1368 **************************/
1370 if (gmx_mm_any_lt(rsq20,rcutoff2))
1373 r20 = _mm_mul_ps(rsq20,rinv20);
1374 r20 = _mm_andnot_ps(dummy_mask,r20);
1376 /* Compute parameters for interactions between i and j atoms */
1377 qq20 = _mm_mul_ps(iq2,jq0);
1379 /* EWALD ELECTROSTATICS */
1381 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1382 ewrt = _mm_mul_ps(r20,ewtabscale);
1383 ewitab = _mm_cvttps_epi32(ewrt);
1384 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1385 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1386 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1388 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1389 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
1391 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1395 fscal = _mm_and_ps(fscal,cutoff_mask);
1397 fscal = _mm_andnot_ps(dummy_mask,fscal);
1399 /* Calculate temporary vectorial force */
1400 tx = _mm_mul_ps(fscal,dx20);
1401 ty = _mm_mul_ps(fscal,dy20);
1402 tz = _mm_mul_ps(fscal,dz20);
1404 /* Update vectorial force */
1405 fix2 = _mm_add_ps(fix2,tx);
1406 fiy2 = _mm_add_ps(fiy2,ty);
1407 fiz2 = _mm_add_ps(fiz2,tz);
1409 fjx0 = _mm_add_ps(fjx0,tx);
1410 fjy0 = _mm_add_ps(fjy0,ty);
1411 fjz0 = _mm_add_ps(fjz0,tz);
1415 /**************************
1416 * CALCULATE INTERACTIONS *
1417 **************************/
1419 if (gmx_mm_any_lt(rsq30,rcutoff2))
1422 r30 = _mm_mul_ps(rsq30,rinv30);
1423 r30 = _mm_andnot_ps(dummy_mask,r30);
1425 /* Compute parameters for interactions between i and j atoms */
1426 qq30 = _mm_mul_ps(iq3,jq0);
1428 /* EWALD ELECTROSTATICS */
1430 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1431 ewrt = _mm_mul_ps(r30,ewtabscale);
1432 ewitab = _mm_cvttps_epi32(ewrt);
1433 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
1434 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
1435 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
1437 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1438 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
1440 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1444 fscal = _mm_and_ps(fscal,cutoff_mask);
1446 fscal = _mm_andnot_ps(dummy_mask,fscal);
1448 /* Calculate temporary vectorial force */
1449 tx = _mm_mul_ps(fscal,dx30);
1450 ty = _mm_mul_ps(fscal,dy30);
1451 tz = _mm_mul_ps(fscal,dz30);
1453 /* Update vectorial force */
1454 fix3 = _mm_add_ps(fix3,tx);
1455 fiy3 = _mm_add_ps(fiy3,ty);
1456 fiz3 = _mm_add_ps(fiz3,tz);
1458 fjx0 = _mm_add_ps(fjx0,tx);
1459 fjy0 = _mm_add_ps(fjy0,ty);
1460 fjz0 = _mm_add_ps(fjz0,tz);
1464 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1465 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1466 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1467 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1469 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1471 /* Inner loop uses 150 flops */
1474 /* End of innermost loop */
1476 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1477 f+i_coord_offset,fshift+i_shift_offset);
1479 /* Increment number of inner iterations */
1480 inneriter += j_index_end - j_index_start;
1482 /* Outer loop uses 24 flops */
1485 /* Increment number of outer iterations */
1488 /* Update outer/inner flops */
1490 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*150);