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 sse2_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_sse2_single.h"
48 #include "kernelutil_x86_sse2_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_sse2_single
52 * Electrostatics interaction: Ewald
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_sse2_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;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
94 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
95 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
96 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
97 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
100 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
103 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
104 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
106 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
108 __m128 dummy_mask,cutoff_mask;
109 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
110 __m128 one = _mm_set1_ps(1.0);
111 __m128 two = _mm_set1_ps(2.0);
117 jindex = nlist->jindex;
119 shiftidx = nlist->shift;
121 shiftvec = fr->shift_vec[0];
122 fshift = fr->fshift[0];
123 facel = _mm_set1_ps(fr->epsfac);
124 charge = mdatoms->chargeA;
125 nvdwtype = fr->ntype;
127 vdwtype = mdatoms->typeA;
129 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
130 ewtab = fr->ic->tabq_coul_FDV0;
131 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
132 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
134 /* Setup water-specific parameters */
135 inr = nlist->iinr[0];
136 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
137 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
138 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
139 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
141 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
142 rcutoff_scalar = fr->rcoulomb;
143 rcutoff = _mm_set1_ps(rcutoff_scalar);
144 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
146 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
147 rvdw = _mm_set1_ps(fr->rvdw);
149 /* Avoid stupid compiler warnings */
150 jnrA = jnrB = jnrC = jnrD = 0;
159 for(iidx=0;iidx<4*DIM;iidx++)
164 /* Start outer loop over neighborlists */
165 for(iidx=0; iidx<nri; iidx++)
167 /* Load shift vector for this list */
168 i_shift_offset = DIM*shiftidx[iidx];
170 /* Load limits for loop over neighbors */
171 j_index_start = jindex[iidx];
172 j_index_end = jindex[iidx+1];
174 /* Get outer coordinate index */
176 i_coord_offset = DIM*inr;
178 /* Load i particle coords and add shift vector */
179 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
180 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
182 fix0 = _mm_setzero_ps();
183 fiy0 = _mm_setzero_ps();
184 fiz0 = _mm_setzero_ps();
185 fix1 = _mm_setzero_ps();
186 fiy1 = _mm_setzero_ps();
187 fiz1 = _mm_setzero_ps();
188 fix2 = _mm_setzero_ps();
189 fiy2 = _mm_setzero_ps();
190 fiz2 = _mm_setzero_ps();
191 fix3 = _mm_setzero_ps();
192 fiy3 = _mm_setzero_ps();
193 fiz3 = _mm_setzero_ps();
195 /* Reset potential sums */
196 velecsum = _mm_setzero_ps();
197 vvdwsum = _mm_setzero_ps();
199 /* Start inner kernel loop */
200 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
203 /* Get j neighbor index, and coordinate index */
208 j_coord_offsetA = DIM*jnrA;
209 j_coord_offsetB = DIM*jnrB;
210 j_coord_offsetC = DIM*jnrC;
211 j_coord_offsetD = DIM*jnrD;
213 /* load j atom coordinates */
214 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
215 x+j_coord_offsetC,x+j_coord_offsetD,
218 /* Calculate displacement vector */
219 dx00 = _mm_sub_ps(ix0,jx0);
220 dy00 = _mm_sub_ps(iy0,jy0);
221 dz00 = _mm_sub_ps(iz0,jz0);
222 dx10 = _mm_sub_ps(ix1,jx0);
223 dy10 = _mm_sub_ps(iy1,jy0);
224 dz10 = _mm_sub_ps(iz1,jz0);
225 dx20 = _mm_sub_ps(ix2,jx0);
226 dy20 = _mm_sub_ps(iy2,jy0);
227 dz20 = _mm_sub_ps(iz2,jz0);
228 dx30 = _mm_sub_ps(ix3,jx0);
229 dy30 = _mm_sub_ps(iy3,jy0);
230 dz30 = _mm_sub_ps(iz3,jz0);
232 /* Calculate squared distance and things based on it */
233 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
234 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
235 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
236 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
238 rinv10 = gmx_mm_invsqrt_ps(rsq10);
239 rinv20 = gmx_mm_invsqrt_ps(rsq20);
240 rinv30 = gmx_mm_invsqrt_ps(rsq30);
242 rinvsq00 = gmx_mm_inv_ps(rsq00);
243 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
244 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
245 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
247 /* Load parameters for j particles */
248 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
249 charge+jnrC+0,charge+jnrD+0);
250 vdwjidx0A = 2*vdwtype[jnrA+0];
251 vdwjidx0B = 2*vdwtype[jnrB+0];
252 vdwjidx0C = 2*vdwtype[jnrC+0];
253 vdwjidx0D = 2*vdwtype[jnrD+0];
255 fjx0 = _mm_setzero_ps();
256 fjy0 = _mm_setzero_ps();
257 fjz0 = _mm_setzero_ps();
259 /**************************
260 * CALCULATE INTERACTIONS *
261 **************************/
263 if (gmx_mm_any_lt(rsq00,rcutoff2))
266 /* Compute parameters for interactions between i and j atoms */
267 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
268 vdwparam+vdwioffset0+vdwjidx0B,
269 vdwparam+vdwioffset0+vdwjidx0C,
270 vdwparam+vdwioffset0+vdwjidx0D,
273 /* LENNARD-JONES DISPERSION/REPULSION */
275 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
276 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
277 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
278 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) ,
279 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
280 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
282 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
284 /* Update potential sum for this i atom from the interaction with this j atom. */
285 vvdw = _mm_and_ps(vvdw,cutoff_mask);
286 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
290 fscal = _mm_and_ps(fscal,cutoff_mask);
292 /* Calculate temporary vectorial force */
293 tx = _mm_mul_ps(fscal,dx00);
294 ty = _mm_mul_ps(fscal,dy00);
295 tz = _mm_mul_ps(fscal,dz00);
297 /* Update vectorial force */
298 fix0 = _mm_add_ps(fix0,tx);
299 fiy0 = _mm_add_ps(fiy0,ty);
300 fiz0 = _mm_add_ps(fiz0,tz);
302 fjx0 = _mm_add_ps(fjx0,tx);
303 fjy0 = _mm_add_ps(fjy0,ty);
304 fjz0 = _mm_add_ps(fjz0,tz);
308 /**************************
309 * CALCULATE INTERACTIONS *
310 **************************/
312 if (gmx_mm_any_lt(rsq10,rcutoff2))
315 r10 = _mm_mul_ps(rsq10,rinv10);
317 /* Compute parameters for interactions between i and j atoms */
318 qq10 = _mm_mul_ps(iq1,jq0);
320 /* EWALD ELECTROSTATICS */
322 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
323 ewrt = _mm_mul_ps(r10,ewtabscale);
324 ewitab = _mm_cvttps_epi32(ewrt);
325 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
326 ewitab = _mm_slli_epi32(ewitab,2);
327 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
328 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
329 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
330 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
331 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
332 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
333 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
334 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_sub_ps(rinv10,sh_ewald),velec));
335 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
337 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
339 /* Update potential sum for this i atom from the interaction with this j atom. */
340 velec = _mm_and_ps(velec,cutoff_mask);
341 velecsum = _mm_add_ps(velecsum,velec);
345 fscal = _mm_and_ps(fscal,cutoff_mask);
347 /* Calculate temporary vectorial force */
348 tx = _mm_mul_ps(fscal,dx10);
349 ty = _mm_mul_ps(fscal,dy10);
350 tz = _mm_mul_ps(fscal,dz10);
352 /* Update vectorial force */
353 fix1 = _mm_add_ps(fix1,tx);
354 fiy1 = _mm_add_ps(fiy1,ty);
355 fiz1 = _mm_add_ps(fiz1,tz);
357 fjx0 = _mm_add_ps(fjx0,tx);
358 fjy0 = _mm_add_ps(fjy0,ty);
359 fjz0 = _mm_add_ps(fjz0,tz);
363 /**************************
364 * CALCULATE INTERACTIONS *
365 **************************/
367 if (gmx_mm_any_lt(rsq20,rcutoff2))
370 r20 = _mm_mul_ps(rsq20,rinv20);
372 /* Compute parameters for interactions between i and j atoms */
373 qq20 = _mm_mul_ps(iq2,jq0);
375 /* EWALD ELECTROSTATICS */
377 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
378 ewrt = _mm_mul_ps(r20,ewtabscale);
379 ewitab = _mm_cvttps_epi32(ewrt);
380 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
381 ewitab = _mm_slli_epi32(ewitab,2);
382 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
383 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
384 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
385 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
386 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
387 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
388 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
389 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_sub_ps(rinv20,sh_ewald),velec));
390 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
392 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
394 /* Update potential sum for this i atom from the interaction with this j atom. */
395 velec = _mm_and_ps(velec,cutoff_mask);
396 velecsum = _mm_add_ps(velecsum,velec);
400 fscal = _mm_and_ps(fscal,cutoff_mask);
402 /* Calculate temporary vectorial force */
403 tx = _mm_mul_ps(fscal,dx20);
404 ty = _mm_mul_ps(fscal,dy20);
405 tz = _mm_mul_ps(fscal,dz20);
407 /* Update vectorial force */
408 fix2 = _mm_add_ps(fix2,tx);
409 fiy2 = _mm_add_ps(fiy2,ty);
410 fiz2 = _mm_add_ps(fiz2,tz);
412 fjx0 = _mm_add_ps(fjx0,tx);
413 fjy0 = _mm_add_ps(fjy0,ty);
414 fjz0 = _mm_add_ps(fjz0,tz);
418 /**************************
419 * CALCULATE INTERACTIONS *
420 **************************/
422 if (gmx_mm_any_lt(rsq30,rcutoff2))
425 r30 = _mm_mul_ps(rsq30,rinv30);
427 /* Compute parameters for interactions between i and j atoms */
428 qq30 = _mm_mul_ps(iq3,jq0);
430 /* EWALD ELECTROSTATICS */
432 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
433 ewrt = _mm_mul_ps(r30,ewtabscale);
434 ewitab = _mm_cvttps_epi32(ewrt);
435 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
436 ewitab = _mm_slli_epi32(ewitab,2);
437 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
438 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
439 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
440 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
441 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
442 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
443 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
444 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_sub_ps(rinv30,sh_ewald),velec));
445 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
447 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
449 /* Update potential sum for this i atom from the interaction with this j atom. */
450 velec = _mm_and_ps(velec,cutoff_mask);
451 velecsum = _mm_add_ps(velecsum,velec);
455 fscal = _mm_and_ps(fscal,cutoff_mask);
457 /* Calculate temporary vectorial force */
458 tx = _mm_mul_ps(fscal,dx30);
459 ty = _mm_mul_ps(fscal,dy30);
460 tz = _mm_mul_ps(fscal,dz30);
462 /* Update vectorial force */
463 fix3 = _mm_add_ps(fix3,tx);
464 fiy3 = _mm_add_ps(fiy3,ty);
465 fiz3 = _mm_add_ps(fiz3,tz);
467 fjx0 = _mm_add_ps(fjx0,tx);
468 fjy0 = _mm_add_ps(fjy0,ty);
469 fjz0 = _mm_add_ps(fjz0,tz);
473 fjptrA = f+j_coord_offsetA;
474 fjptrB = f+j_coord_offsetB;
475 fjptrC = f+j_coord_offsetC;
476 fjptrD = f+j_coord_offsetD;
478 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
480 /* Inner loop uses 179 flops */
486 /* Get j neighbor index, and coordinate index */
487 jnrlistA = jjnr[jidx];
488 jnrlistB = jjnr[jidx+1];
489 jnrlistC = jjnr[jidx+2];
490 jnrlistD = jjnr[jidx+3];
491 /* Sign of each element will be negative for non-real atoms.
492 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
493 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
495 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
496 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
497 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
498 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
499 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
500 j_coord_offsetA = DIM*jnrA;
501 j_coord_offsetB = DIM*jnrB;
502 j_coord_offsetC = DIM*jnrC;
503 j_coord_offsetD = DIM*jnrD;
505 /* load j atom coordinates */
506 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
507 x+j_coord_offsetC,x+j_coord_offsetD,
510 /* Calculate displacement vector */
511 dx00 = _mm_sub_ps(ix0,jx0);
512 dy00 = _mm_sub_ps(iy0,jy0);
513 dz00 = _mm_sub_ps(iz0,jz0);
514 dx10 = _mm_sub_ps(ix1,jx0);
515 dy10 = _mm_sub_ps(iy1,jy0);
516 dz10 = _mm_sub_ps(iz1,jz0);
517 dx20 = _mm_sub_ps(ix2,jx0);
518 dy20 = _mm_sub_ps(iy2,jy0);
519 dz20 = _mm_sub_ps(iz2,jz0);
520 dx30 = _mm_sub_ps(ix3,jx0);
521 dy30 = _mm_sub_ps(iy3,jy0);
522 dz30 = _mm_sub_ps(iz3,jz0);
524 /* Calculate squared distance and things based on it */
525 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
526 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
527 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
528 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
530 rinv10 = gmx_mm_invsqrt_ps(rsq10);
531 rinv20 = gmx_mm_invsqrt_ps(rsq20);
532 rinv30 = gmx_mm_invsqrt_ps(rsq30);
534 rinvsq00 = gmx_mm_inv_ps(rsq00);
535 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
536 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
537 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
539 /* Load parameters for j particles */
540 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
541 charge+jnrC+0,charge+jnrD+0);
542 vdwjidx0A = 2*vdwtype[jnrA+0];
543 vdwjidx0B = 2*vdwtype[jnrB+0];
544 vdwjidx0C = 2*vdwtype[jnrC+0];
545 vdwjidx0D = 2*vdwtype[jnrD+0];
547 fjx0 = _mm_setzero_ps();
548 fjy0 = _mm_setzero_ps();
549 fjz0 = _mm_setzero_ps();
551 /**************************
552 * CALCULATE INTERACTIONS *
553 **************************/
555 if (gmx_mm_any_lt(rsq00,rcutoff2))
558 /* Compute parameters for interactions between i and j atoms */
559 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
560 vdwparam+vdwioffset0+vdwjidx0B,
561 vdwparam+vdwioffset0+vdwjidx0C,
562 vdwparam+vdwioffset0+vdwjidx0D,
565 /* LENNARD-JONES DISPERSION/REPULSION */
567 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
568 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
569 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
570 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) ,
571 _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
572 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
574 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
576 /* Update potential sum for this i atom from the interaction with this j atom. */
577 vvdw = _mm_and_ps(vvdw,cutoff_mask);
578 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
579 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
583 fscal = _mm_and_ps(fscal,cutoff_mask);
585 fscal = _mm_andnot_ps(dummy_mask,fscal);
587 /* Calculate temporary vectorial force */
588 tx = _mm_mul_ps(fscal,dx00);
589 ty = _mm_mul_ps(fscal,dy00);
590 tz = _mm_mul_ps(fscal,dz00);
592 /* Update vectorial force */
593 fix0 = _mm_add_ps(fix0,tx);
594 fiy0 = _mm_add_ps(fiy0,ty);
595 fiz0 = _mm_add_ps(fiz0,tz);
597 fjx0 = _mm_add_ps(fjx0,tx);
598 fjy0 = _mm_add_ps(fjy0,ty);
599 fjz0 = _mm_add_ps(fjz0,tz);
603 /**************************
604 * CALCULATE INTERACTIONS *
605 **************************/
607 if (gmx_mm_any_lt(rsq10,rcutoff2))
610 r10 = _mm_mul_ps(rsq10,rinv10);
611 r10 = _mm_andnot_ps(dummy_mask,r10);
613 /* Compute parameters for interactions between i and j atoms */
614 qq10 = _mm_mul_ps(iq1,jq0);
616 /* EWALD ELECTROSTATICS */
618 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
619 ewrt = _mm_mul_ps(r10,ewtabscale);
620 ewitab = _mm_cvttps_epi32(ewrt);
621 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
622 ewitab = _mm_slli_epi32(ewitab,2);
623 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
624 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
625 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
626 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
627 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
628 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
629 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
630 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_sub_ps(rinv10,sh_ewald),velec));
631 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
633 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
635 /* Update potential sum for this i atom from the interaction with this j atom. */
636 velec = _mm_and_ps(velec,cutoff_mask);
637 velec = _mm_andnot_ps(dummy_mask,velec);
638 velecsum = _mm_add_ps(velecsum,velec);
642 fscal = _mm_and_ps(fscal,cutoff_mask);
644 fscal = _mm_andnot_ps(dummy_mask,fscal);
646 /* Calculate temporary vectorial force */
647 tx = _mm_mul_ps(fscal,dx10);
648 ty = _mm_mul_ps(fscal,dy10);
649 tz = _mm_mul_ps(fscal,dz10);
651 /* Update vectorial force */
652 fix1 = _mm_add_ps(fix1,tx);
653 fiy1 = _mm_add_ps(fiy1,ty);
654 fiz1 = _mm_add_ps(fiz1,tz);
656 fjx0 = _mm_add_ps(fjx0,tx);
657 fjy0 = _mm_add_ps(fjy0,ty);
658 fjz0 = _mm_add_ps(fjz0,tz);
662 /**************************
663 * CALCULATE INTERACTIONS *
664 **************************/
666 if (gmx_mm_any_lt(rsq20,rcutoff2))
669 r20 = _mm_mul_ps(rsq20,rinv20);
670 r20 = _mm_andnot_ps(dummy_mask,r20);
672 /* Compute parameters for interactions between i and j atoms */
673 qq20 = _mm_mul_ps(iq2,jq0);
675 /* EWALD ELECTROSTATICS */
677 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
678 ewrt = _mm_mul_ps(r20,ewtabscale);
679 ewitab = _mm_cvttps_epi32(ewrt);
680 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
681 ewitab = _mm_slli_epi32(ewitab,2);
682 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
683 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
684 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
685 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
686 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
687 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
688 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
689 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_sub_ps(rinv20,sh_ewald),velec));
690 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
692 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
694 /* Update potential sum for this i atom from the interaction with this j atom. */
695 velec = _mm_and_ps(velec,cutoff_mask);
696 velec = _mm_andnot_ps(dummy_mask,velec);
697 velecsum = _mm_add_ps(velecsum,velec);
701 fscal = _mm_and_ps(fscal,cutoff_mask);
703 fscal = _mm_andnot_ps(dummy_mask,fscal);
705 /* Calculate temporary vectorial force */
706 tx = _mm_mul_ps(fscal,dx20);
707 ty = _mm_mul_ps(fscal,dy20);
708 tz = _mm_mul_ps(fscal,dz20);
710 /* Update vectorial force */
711 fix2 = _mm_add_ps(fix2,tx);
712 fiy2 = _mm_add_ps(fiy2,ty);
713 fiz2 = _mm_add_ps(fiz2,tz);
715 fjx0 = _mm_add_ps(fjx0,tx);
716 fjy0 = _mm_add_ps(fjy0,ty);
717 fjz0 = _mm_add_ps(fjz0,tz);
721 /**************************
722 * CALCULATE INTERACTIONS *
723 **************************/
725 if (gmx_mm_any_lt(rsq30,rcutoff2))
728 r30 = _mm_mul_ps(rsq30,rinv30);
729 r30 = _mm_andnot_ps(dummy_mask,r30);
731 /* Compute parameters for interactions between i and j atoms */
732 qq30 = _mm_mul_ps(iq3,jq0);
734 /* EWALD ELECTROSTATICS */
736 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
737 ewrt = _mm_mul_ps(r30,ewtabscale);
738 ewitab = _mm_cvttps_epi32(ewrt);
739 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
740 ewitab = _mm_slli_epi32(ewitab,2);
741 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
742 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
743 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
744 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
745 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
746 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
747 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
748 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_sub_ps(rinv30,sh_ewald),velec));
749 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
751 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
753 /* Update potential sum for this i atom from the interaction with this j atom. */
754 velec = _mm_and_ps(velec,cutoff_mask);
755 velec = _mm_andnot_ps(dummy_mask,velec);
756 velecsum = _mm_add_ps(velecsum,velec);
760 fscal = _mm_and_ps(fscal,cutoff_mask);
762 fscal = _mm_andnot_ps(dummy_mask,fscal);
764 /* Calculate temporary vectorial force */
765 tx = _mm_mul_ps(fscal,dx30);
766 ty = _mm_mul_ps(fscal,dy30);
767 tz = _mm_mul_ps(fscal,dz30);
769 /* Update vectorial force */
770 fix3 = _mm_add_ps(fix3,tx);
771 fiy3 = _mm_add_ps(fiy3,ty);
772 fiz3 = _mm_add_ps(fiz3,tz);
774 fjx0 = _mm_add_ps(fjx0,tx);
775 fjy0 = _mm_add_ps(fjy0,ty);
776 fjz0 = _mm_add_ps(fjz0,tz);
780 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
781 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
782 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
783 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
785 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
787 /* Inner loop uses 182 flops */
790 /* End of innermost loop */
792 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
793 f+i_coord_offset,fshift+i_shift_offset);
796 /* Update potential energies */
797 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
798 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
800 /* Increment number of inner iterations */
801 inneriter += j_index_end - j_index_start;
803 /* Outer loop uses 26 flops */
806 /* Increment number of outer iterations */
809 /* Update outer/inner flops */
811 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*182);
814 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse2_single
815 * Electrostatics interaction: Ewald
816 * VdW interaction: LennardJones
817 * Geometry: Water4-Particle
818 * Calculate force/pot: Force
821 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse2_single
822 (t_nblist * gmx_restrict nlist,
823 rvec * gmx_restrict xx,
824 rvec * gmx_restrict ff,
825 t_forcerec * gmx_restrict fr,
826 t_mdatoms * gmx_restrict mdatoms,
827 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
828 t_nrnb * gmx_restrict nrnb)
830 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
831 * just 0 for non-waters.
832 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
833 * jnr indices corresponding to data put in the four positions in the SIMD register.
835 int i_shift_offset,i_coord_offset,outeriter,inneriter;
836 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
837 int jnrA,jnrB,jnrC,jnrD;
838 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
839 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
840 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
842 real *shiftvec,*fshift,*x,*f;
843 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
845 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
847 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
849 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
851 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
853 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
854 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
855 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
856 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
857 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
858 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
859 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
860 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
863 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
866 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
867 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
869 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
871 __m128 dummy_mask,cutoff_mask;
872 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
873 __m128 one = _mm_set1_ps(1.0);
874 __m128 two = _mm_set1_ps(2.0);
880 jindex = nlist->jindex;
882 shiftidx = nlist->shift;
884 shiftvec = fr->shift_vec[0];
885 fshift = fr->fshift[0];
886 facel = _mm_set1_ps(fr->epsfac);
887 charge = mdatoms->chargeA;
888 nvdwtype = fr->ntype;
890 vdwtype = mdatoms->typeA;
892 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
893 ewtab = fr->ic->tabq_coul_F;
894 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
895 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
897 /* Setup water-specific parameters */
898 inr = nlist->iinr[0];
899 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
900 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
901 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
902 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
904 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
905 rcutoff_scalar = fr->rcoulomb;
906 rcutoff = _mm_set1_ps(rcutoff_scalar);
907 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
909 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
910 rvdw = _mm_set1_ps(fr->rvdw);
912 /* Avoid stupid compiler warnings */
913 jnrA = jnrB = jnrC = jnrD = 0;
922 for(iidx=0;iidx<4*DIM;iidx++)
927 /* Start outer loop over neighborlists */
928 for(iidx=0; iidx<nri; iidx++)
930 /* Load shift vector for this list */
931 i_shift_offset = DIM*shiftidx[iidx];
933 /* Load limits for loop over neighbors */
934 j_index_start = jindex[iidx];
935 j_index_end = jindex[iidx+1];
937 /* Get outer coordinate index */
939 i_coord_offset = DIM*inr;
941 /* Load i particle coords and add shift vector */
942 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
943 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
945 fix0 = _mm_setzero_ps();
946 fiy0 = _mm_setzero_ps();
947 fiz0 = _mm_setzero_ps();
948 fix1 = _mm_setzero_ps();
949 fiy1 = _mm_setzero_ps();
950 fiz1 = _mm_setzero_ps();
951 fix2 = _mm_setzero_ps();
952 fiy2 = _mm_setzero_ps();
953 fiz2 = _mm_setzero_ps();
954 fix3 = _mm_setzero_ps();
955 fiy3 = _mm_setzero_ps();
956 fiz3 = _mm_setzero_ps();
958 /* Start inner kernel loop */
959 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
962 /* Get j neighbor index, and coordinate index */
967 j_coord_offsetA = DIM*jnrA;
968 j_coord_offsetB = DIM*jnrB;
969 j_coord_offsetC = DIM*jnrC;
970 j_coord_offsetD = DIM*jnrD;
972 /* load j atom coordinates */
973 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
974 x+j_coord_offsetC,x+j_coord_offsetD,
977 /* Calculate displacement vector */
978 dx00 = _mm_sub_ps(ix0,jx0);
979 dy00 = _mm_sub_ps(iy0,jy0);
980 dz00 = _mm_sub_ps(iz0,jz0);
981 dx10 = _mm_sub_ps(ix1,jx0);
982 dy10 = _mm_sub_ps(iy1,jy0);
983 dz10 = _mm_sub_ps(iz1,jz0);
984 dx20 = _mm_sub_ps(ix2,jx0);
985 dy20 = _mm_sub_ps(iy2,jy0);
986 dz20 = _mm_sub_ps(iz2,jz0);
987 dx30 = _mm_sub_ps(ix3,jx0);
988 dy30 = _mm_sub_ps(iy3,jy0);
989 dz30 = _mm_sub_ps(iz3,jz0);
991 /* Calculate squared distance and things based on it */
992 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
993 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
994 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
995 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
997 rinv10 = gmx_mm_invsqrt_ps(rsq10);
998 rinv20 = gmx_mm_invsqrt_ps(rsq20);
999 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1001 rinvsq00 = gmx_mm_inv_ps(rsq00);
1002 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1003 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1004 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1006 /* Load parameters for j particles */
1007 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1008 charge+jnrC+0,charge+jnrD+0);
1009 vdwjidx0A = 2*vdwtype[jnrA+0];
1010 vdwjidx0B = 2*vdwtype[jnrB+0];
1011 vdwjidx0C = 2*vdwtype[jnrC+0];
1012 vdwjidx0D = 2*vdwtype[jnrD+0];
1014 fjx0 = _mm_setzero_ps();
1015 fjy0 = _mm_setzero_ps();
1016 fjz0 = _mm_setzero_ps();
1018 /**************************
1019 * CALCULATE INTERACTIONS *
1020 **************************/
1022 if (gmx_mm_any_lt(rsq00,rcutoff2))
1025 /* Compute parameters for interactions between i and j atoms */
1026 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1027 vdwparam+vdwioffset0+vdwjidx0B,
1028 vdwparam+vdwioffset0+vdwjidx0C,
1029 vdwparam+vdwioffset0+vdwjidx0D,
1032 /* LENNARD-JONES DISPERSION/REPULSION */
1034 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1035 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1037 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1041 fscal = _mm_and_ps(fscal,cutoff_mask);
1043 /* Calculate temporary vectorial force */
1044 tx = _mm_mul_ps(fscal,dx00);
1045 ty = _mm_mul_ps(fscal,dy00);
1046 tz = _mm_mul_ps(fscal,dz00);
1048 /* Update vectorial force */
1049 fix0 = _mm_add_ps(fix0,tx);
1050 fiy0 = _mm_add_ps(fiy0,ty);
1051 fiz0 = _mm_add_ps(fiz0,tz);
1053 fjx0 = _mm_add_ps(fjx0,tx);
1054 fjy0 = _mm_add_ps(fjy0,ty);
1055 fjz0 = _mm_add_ps(fjz0,tz);
1059 /**************************
1060 * CALCULATE INTERACTIONS *
1061 **************************/
1063 if (gmx_mm_any_lt(rsq10,rcutoff2))
1066 r10 = _mm_mul_ps(rsq10,rinv10);
1068 /* Compute parameters for interactions between i and j atoms */
1069 qq10 = _mm_mul_ps(iq1,jq0);
1071 /* EWALD ELECTROSTATICS */
1073 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1074 ewrt = _mm_mul_ps(r10,ewtabscale);
1075 ewitab = _mm_cvttps_epi32(ewrt);
1076 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
1077 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1078 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
1080 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1081 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
1083 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1087 fscal = _mm_and_ps(fscal,cutoff_mask);
1089 /* Calculate temporary vectorial force */
1090 tx = _mm_mul_ps(fscal,dx10);
1091 ty = _mm_mul_ps(fscal,dy10);
1092 tz = _mm_mul_ps(fscal,dz10);
1094 /* Update vectorial force */
1095 fix1 = _mm_add_ps(fix1,tx);
1096 fiy1 = _mm_add_ps(fiy1,ty);
1097 fiz1 = _mm_add_ps(fiz1,tz);
1099 fjx0 = _mm_add_ps(fjx0,tx);
1100 fjy0 = _mm_add_ps(fjy0,ty);
1101 fjz0 = _mm_add_ps(fjz0,tz);
1105 /**************************
1106 * CALCULATE INTERACTIONS *
1107 **************************/
1109 if (gmx_mm_any_lt(rsq20,rcutoff2))
1112 r20 = _mm_mul_ps(rsq20,rinv20);
1114 /* Compute parameters for interactions between i and j atoms */
1115 qq20 = _mm_mul_ps(iq2,jq0);
1117 /* EWALD ELECTROSTATICS */
1119 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1120 ewrt = _mm_mul_ps(r20,ewtabscale);
1121 ewitab = _mm_cvttps_epi32(ewrt);
1122 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
1123 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1124 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
1126 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1127 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
1129 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1133 fscal = _mm_and_ps(fscal,cutoff_mask);
1135 /* Calculate temporary vectorial force */
1136 tx = _mm_mul_ps(fscal,dx20);
1137 ty = _mm_mul_ps(fscal,dy20);
1138 tz = _mm_mul_ps(fscal,dz20);
1140 /* Update vectorial force */
1141 fix2 = _mm_add_ps(fix2,tx);
1142 fiy2 = _mm_add_ps(fiy2,ty);
1143 fiz2 = _mm_add_ps(fiz2,tz);
1145 fjx0 = _mm_add_ps(fjx0,tx);
1146 fjy0 = _mm_add_ps(fjy0,ty);
1147 fjz0 = _mm_add_ps(fjz0,tz);
1151 /**************************
1152 * CALCULATE INTERACTIONS *
1153 **************************/
1155 if (gmx_mm_any_lt(rsq30,rcutoff2))
1158 r30 = _mm_mul_ps(rsq30,rinv30);
1160 /* Compute parameters for interactions between i and j atoms */
1161 qq30 = _mm_mul_ps(iq3,jq0);
1163 /* EWALD ELECTROSTATICS */
1165 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1166 ewrt = _mm_mul_ps(r30,ewtabscale);
1167 ewitab = _mm_cvttps_epi32(ewrt);
1168 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
1169 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1170 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
1172 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1173 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
1175 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1179 fscal = _mm_and_ps(fscal,cutoff_mask);
1181 /* Calculate temporary vectorial force */
1182 tx = _mm_mul_ps(fscal,dx30);
1183 ty = _mm_mul_ps(fscal,dy30);
1184 tz = _mm_mul_ps(fscal,dz30);
1186 /* Update vectorial force */
1187 fix3 = _mm_add_ps(fix3,tx);
1188 fiy3 = _mm_add_ps(fiy3,ty);
1189 fiz3 = _mm_add_ps(fiz3,tz);
1191 fjx0 = _mm_add_ps(fjx0,tx);
1192 fjy0 = _mm_add_ps(fjy0,ty);
1193 fjz0 = _mm_add_ps(fjz0,tz);
1197 fjptrA = f+j_coord_offsetA;
1198 fjptrB = f+j_coord_offsetB;
1199 fjptrC = f+j_coord_offsetC;
1200 fjptrD = f+j_coord_offsetD;
1202 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1204 /* Inner loop uses 147 flops */
1207 if(jidx<j_index_end)
1210 /* Get j neighbor index, and coordinate index */
1211 jnrlistA = jjnr[jidx];
1212 jnrlistB = jjnr[jidx+1];
1213 jnrlistC = jjnr[jidx+2];
1214 jnrlistD = jjnr[jidx+3];
1215 /* Sign of each element will be negative for non-real atoms.
1216 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1217 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1219 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1220 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1221 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1222 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1223 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1224 j_coord_offsetA = DIM*jnrA;
1225 j_coord_offsetB = DIM*jnrB;
1226 j_coord_offsetC = DIM*jnrC;
1227 j_coord_offsetD = DIM*jnrD;
1229 /* load j atom coordinates */
1230 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1231 x+j_coord_offsetC,x+j_coord_offsetD,
1234 /* Calculate displacement vector */
1235 dx00 = _mm_sub_ps(ix0,jx0);
1236 dy00 = _mm_sub_ps(iy0,jy0);
1237 dz00 = _mm_sub_ps(iz0,jz0);
1238 dx10 = _mm_sub_ps(ix1,jx0);
1239 dy10 = _mm_sub_ps(iy1,jy0);
1240 dz10 = _mm_sub_ps(iz1,jz0);
1241 dx20 = _mm_sub_ps(ix2,jx0);
1242 dy20 = _mm_sub_ps(iy2,jy0);
1243 dz20 = _mm_sub_ps(iz2,jz0);
1244 dx30 = _mm_sub_ps(ix3,jx0);
1245 dy30 = _mm_sub_ps(iy3,jy0);
1246 dz30 = _mm_sub_ps(iz3,jz0);
1248 /* Calculate squared distance and things based on it */
1249 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1250 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1251 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1252 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1254 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1255 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1256 rinv30 = gmx_mm_invsqrt_ps(rsq30);
1258 rinvsq00 = gmx_mm_inv_ps(rsq00);
1259 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1260 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1261 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1263 /* Load parameters for j particles */
1264 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1265 charge+jnrC+0,charge+jnrD+0);
1266 vdwjidx0A = 2*vdwtype[jnrA+0];
1267 vdwjidx0B = 2*vdwtype[jnrB+0];
1268 vdwjidx0C = 2*vdwtype[jnrC+0];
1269 vdwjidx0D = 2*vdwtype[jnrD+0];
1271 fjx0 = _mm_setzero_ps();
1272 fjy0 = _mm_setzero_ps();
1273 fjz0 = _mm_setzero_ps();
1275 /**************************
1276 * CALCULATE INTERACTIONS *
1277 **************************/
1279 if (gmx_mm_any_lt(rsq00,rcutoff2))
1282 /* Compute parameters for interactions between i and j atoms */
1283 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1284 vdwparam+vdwioffset0+vdwjidx0B,
1285 vdwparam+vdwioffset0+vdwjidx0C,
1286 vdwparam+vdwioffset0+vdwjidx0D,
1289 /* LENNARD-JONES DISPERSION/REPULSION */
1291 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1292 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1294 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1298 fscal = _mm_and_ps(fscal,cutoff_mask);
1300 fscal = _mm_andnot_ps(dummy_mask,fscal);
1302 /* Calculate temporary vectorial force */
1303 tx = _mm_mul_ps(fscal,dx00);
1304 ty = _mm_mul_ps(fscal,dy00);
1305 tz = _mm_mul_ps(fscal,dz00);
1307 /* Update vectorial force */
1308 fix0 = _mm_add_ps(fix0,tx);
1309 fiy0 = _mm_add_ps(fiy0,ty);
1310 fiz0 = _mm_add_ps(fiz0,tz);
1312 fjx0 = _mm_add_ps(fjx0,tx);
1313 fjy0 = _mm_add_ps(fjy0,ty);
1314 fjz0 = _mm_add_ps(fjz0,tz);
1318 /**************************
1319 * CALCULATE INTERACTIONS *
1320 **************************/
1322 if (gmx_mm_any_lt(rsq10,rcutoff2))
1325 r10 = _mm_mul_ps(rsq10,rinv10);
1326 r10 = _mm_andnot_ps(dummy_mask,r10);
1328 /* Compute parameters for interactions between i and j atoms */
1329 qq10 = _mm_mul_ps(iq1,jq0);
1331 /* EWALD ELECTROSTATICS */
1333 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1334 ewrt = _mm_mul_ps(r10,ewtabscale);
1335 ewitab = _mm_cvttps_epi32(ewrt);
1336 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
1337 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1338 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
1340 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1341 felec = _mm_mul_ps(_mm_mul_ps(qq10,rinv10),_mm_sub_ps(rinvsq10,felec));
1343 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1347 fscal = _mm_and_ps(fscal,cutoff_mask);
1349 fscal = _mm_andnot_ps(dummy_mask,fscal);
1351 /* Calculate temporary vectorial force */
1352 tx = _mm_mul_ps(fscal,dx10);
1353 ty = _mm_mul_ps(fscal,dy10);
1354 tz = _mm_mul_ps(fscal,dz10);
1356 /* Update vectorial force */
1357 fix1 = _mm_add_ps(fix1,tx);
1358 fiy1 = _mm_add_ps(fiy1,ty);
1359 fiz1 = _mm_add_ps(fiz1,tz);
1361 fjx0 = _mm_add_ps(fjx0,tx);
1362 fjy0 = _mm_add_ps(fjy0,ty);
1363 fjz0 = _mm_add_ps(fjz0,tz);
1367 /**************************
1368 * CALCULATE INTERACTIONS *
1369 **************************/
1371 if (gmx_mm_any_lt(rsq20,rcutoff2))
1374 r20 = _mm_mul_ps(rsq20,rinv20);
1375 r20 = _mm_andnot_ps(dummy_mask,r20);
1377 /* Compute parameters for interactions between i and j atoms */
1378 qq20 = _mm_mul_ps(iq2,jq0);
1380 /* EWALD ELECTROSTATICS */
1382 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1383 ewrt = _mm_mul_ps(r20,ewtabscale);
1384 ewitab = _mm_cvttps_epi32(ewrt);
1385 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
1386 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1387 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
1389 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1390 felec = _mm_mul_ps(_mm_mul_ps(qq20,rinv20),_mm_sub_ps(rinvsq20,felec));
1392 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1396 fscal = _mm_and_ps(fscal,cutoff_mask);
1398 fscal = _mm_andnot_ps(dummy_mask,fscal);
1400 /* Calculate temporary vectorial force */
1401 tx = _mm_mul_ps(fscal,dx20);
1402 ty = _mm_mul_ps(fscal,dy20);
1403 tz = _mm_mul_ps(fscal,dz20);
1405 /* Update vectorial force */
1406 fix2 = _mm_add_ps(fix2,tx);
1407 fiy2 = _mm_add_ps(fiy2,ty);
1408 fiz2 = _mm_add_ps(fiz2,tz);
1410 fjx0 = _mm_add_ps(fjx0,tx);
1411 fjy0 = _mm_add_ps(fjy0,ty);
1412 fjz0 = _mm_add_ps(fjz0,tz);
1416 /**************************
1417 * CALCULATE INTERACTIONS *
1418 **************************/
1420 if (gmx_mm_any_lt(rsq30,rcutoff2))
1423 r30 = _mm_mul_ps(rsq30,rinv30);
1424 r30 = _mm_andnot_ps(dummy_mask,r30);
1426 /* Compute parameters for interactions between i and j atoms */
1427 qq30 = _mm_mul_ps(iq3,jq0);
1429 /* EWALD ELECTROSTATICS */
1431 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1432 ewrt = _mm_mul_ps(r30,ewtabscale);
1433 ewitab = _mm_cvttps_epi32(ewrt);
1434 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
1435 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1436 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
1438 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
1439 felec = _mm_mul_ps(_mm_mul_ps(qq30,rinv30),_mm_sub_ps(rinvsq30,felec));
1441 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1445 fscal = _mm_and_ps(fscal,cutoff_mask);
1447 fscal = _mm_andnot_ps(dummy_mask,fscal);
1449 /* Calculate temporary vectorial force */
1450 tx = _mm_mul_ps(fscal,dx30);
1451 ty = _mm_mul_ps(fscal,dy30);
1452 tz = _mm_mul_ps(fscal,dz30);
1454 /* Update vectorial force */
1455 fix3 = _mm_add_ps(fix3,tx);
1456 fiy3 = _mm_add_ps(fiy3,ty);
1457 fiz3 = _mm_add_ps(fiz3,tz);
1459 fjx0 = _mm_add_ps(fjx0,tx);
1460 fjy0 = _mm_add_ps(fjy0,ty);
1461 fjz0 = _mm_add_ps(fjz0,tz);
1465 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1466 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1467 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1468 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1470 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1472 /* Inner loop uses 150 flops */
1475 /* End of innermost loop */
1477 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1478 f+i_coord_offset,fshift+i_shift_offset);
1480 /* Increment number of inner iterations */
1481 inneriter += j_index_end - j_index_start;
1483 /* Outer loop uses 24 flops */
1486 /* Increment number of outer iterations */
1489 /* Update outer/inner flops */
1491 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*150);