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_double kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_sse2_double.h"
48 #include "kernelutil_x86_sse2_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_VF_sse2_double
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_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
100 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
101 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
103 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
105 __m128d dummy_mask,cutoff_mask;
106 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
107 __m128d one = _mm_set1_pd(1.0);
108 __m128d two = _mm_set1_pd(2.0);
114 jindex = nlist->jindex;
116 shiftidx = nlist->shift;
118 shiftvec = fr->shift_vec[0];
119 fshift = fr->fshift[0];
120 facel = _mm_set1_pd(fr->epsfac);
121 charge = mdatoms->chargeA;
122 nvdwtype = fr->ntype;
124 vdwtype = mdatoms->typeA;
126 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
127 ewtab = fr->ic->tabq_coul_FDV0;
128 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
129 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
131 /* Setup water-specific parameters */
132 inr = nlist->iinr[0];
133 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
134 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
135 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
136 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
138 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
139 rcutoff_scalar = fr->rcoulomb;
140 rcutoff = _mm_set1_pd(rcutoff_scalar);
141 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
143 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
144 rvdw = _mm_set1_pd(fr->rvdw);
146 /* Avoid stupid compiler warnings */
154 /* Start outer loop over neighborlists */
155 for(iidx=0; iidx<nri; iidx++)
157 /* Load shift vector for this list */
158 i_shift_offset = DIM*shiftidx[iidx];
160 /* Load limits for loop over neighbors */
161 j_index_start = jindex[iidx];
162 j_index_end = jindex[iidx+1];
164 /* Get outer coordinate index */
166 i_coord_offset = DIM*inr;
168 /* Load i particle coords and add shift vector */
169 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
170 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
172 fix0 = _mm_setzero_pd();
173 fiy0 = _mm_setzero_pd();
174 fiz0 = _mm_setzero_pd();
175 fix1 = _mm_setzero_pd();
176 fiy1 = _mm_setzero_pd();
177 fiz1 = _mm_setzero_pd();
178 fix2 = _mm_setzero_pd();
179 fiy2 = _mm_setzero_pd();
180 fiz2 = _mm_setzero_pd();
181 fix3 = _mm_setzero_pd();
182 fiy3 = _mm_setzero_pd();
183 fiz3 = _mm_setzero_pd();
185 /* Reset potential sums */
186 velecsum = _mm_setzero_pd();
187 vvdwsum = _mm_setzero_pd();
189 /* Start inner kernel loop */
190 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
193 /* Get j neighbor index, and coordinate index */
196 j_coord_offsetA = DIM*jnrA;
197 j_coord_offsetB = DIM*jnrB;
199 /* load j atom coordinates */
200 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
203 /* Calculate displacement vector */
204 dx00 = _mm_sub_pd(ix0,jx0);
205 dy00 = _mm_sub_pd(iy0,jy0);
206 dz00 = _mm_sub_pd(iz0,jz0);
207 dx10 = _mm_sub_pd(ix1,jx0);
208 dy10 = _mm_sub_pd(iy1,jy0);
209 dz10 = _mm_sub_pd(iz1,jz0);
210 dx20 = _mm_sub_pd(ix2,jx0);
211 dy20 = _mm_sub_pd(iy2,jy0);
212 dz20 = _mm_sub_pd(iz2,jz0);
213 dx30 = _mm_sub_pd(ix3,jx0);
214 dy30 = _mm_sub_pd(iy3,jy0);
215 dz30 = _mm_sub_pd(iz3,jz0);
217 /* Calculate squared distance and things based on it */
218 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
219 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
220 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
221 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
223 rinv10 = gmx_mm_invsqrt_pd(rsq10);
224 rinv20 = gmx_mm_invsqrt_pd(rsq20);
225 rinv30 = gmx_mm_invsqrt_pd(rsq30);
227 rinvsq00 = gmx_mm_inv_pd(rsq00);
228 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
229 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
230 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
232 /* Load parameters for j particles */
233 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
234 vdwjidx0A = 2*vdwtype[jnrA+0];
235 vdwjidx0B = 2*vdwtype[jnrB+0];
237 fjx0 = _mm_setzero_pd();
238 fjy0 = _mm_setzero_pd();
239 fjz0 = _mm_setzero_pd();
241 /**************************
242 * CALCULATE INTERACTIONS *
243 **************************/
245 if (gmx_mm_any_lt(rsq00,rcutoff2))
248 /* Compute parameters for interactions between i and j atoms */
249 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
250 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
252 /* LENNARD-JONES DISPERSION/REPULSION */
254 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
255 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
256 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
257 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
258 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
259 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
261 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
263 /* Update potential sum for this i atom from the interaction with this j atom. */
264 vvdw = _mm_and_pd(vvdw,cutoff_mask);
265 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
269 fscal = _mm_and_pd(fscal,cutoff_mask);
271 /* Calculate temporary vectorial force */
272 tx = _mm_mul_pd(fscal,dx00);
273 ty = _mm_mul_pd(fscal,dy00);
274 tz = _mm_mul_pd(fscal,dz00);
276 /* Update vectorial force */
277 fix0 = _mm_add_pd(fix0,tx);
278 fiy0 = _mm_add_pd(fiy0,ty);
279 fiz0 = _mm_add_pd(fiz0,tz);
281 fjx0 = _mm_add_pd(fjx0,tx);
282 fjy0 = _mm_add_pd(fjy0,ty);
283 fjz0 = _mm_add_pd(fjz0,tz);
287 /**************************
288 * CALCULATE INTERACTIONS *
289 **************************/
291 if (gmx_mm_any_lt(rsq10,rcutoff2))
294 r10 = _mm_mul_pd(rsq10,rinv10);
296 /* Compute parameters for interactions between i and j atoms */
297 qq10 = _mm_mul_pd(iq1,jq0);
299 /* EWALD ELECTROSTATICS */
301 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
302 ewrt = _mm_mul_pd(r10,ewtabscale);
303 ewitab = _mm_cvttpd_epi32(ewrt);
304 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
305 ewitab = _mm_slli_epi32(ewitab,2);
306 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
307 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
308 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
309 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
310 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
311 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
312 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
313 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
314 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
315 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
317 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
319 /* Update potential sum for this i atom from the interaction with this j atom. */
320 velec = _mm_and_pd(velec,cutoff_mask);
321 velecsum = _mm_add_pd(velecsum,velec);
325 fscal = _mm_and_pd(fscal,cutoff_mask);
327 /* Calculate temporary vectorial force */
328 tx = _mm_mul_pd(fscal,dx10);
329 ty = _mm_mul_pd(fscal,dy10);
330 tz = _mm_mul_pd(fscal,dz10);
332 /* Update vectorial force */
333 fix1 = _mm_add_pd(fix1,tx);
334 fiy1 = _mm_add_pd(fiy1,ty);
335 fiz1 = _mm_add_pd(fiz1,tz);
337 fjx0 = _mm_add_pd(fjx0,tx);
338 fjy0 = _mm_add_pd(fjy0,ty);
339 fjz0 = _mm_add_pd(fjz0,tz);
343 /**************************
344 * CALCULATE INTERACTIONS *
345 **************************/
347 if (gmx_mm_any_lt(rsq20,rcutoff2))
350 r20 = _mm_mul_pd(rsq20,rinv20);
352 /* Compute parameters for interactions between i and j atoms */
353 qq20 = _mm_mul_pd(iq2,jq0);
355 /* EWALD ELECTROSTATICS */
357 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
358 ewrt = _mm_mul_pd(r20,ewtabscale);
359 ewitab = _mm_cvttpd_epi32(ewrt);
360 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
361 ewitab = _mm_slli_epi32(ewitab,2);
362 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
363 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
364 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
365 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
366 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
367 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
368 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
369 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
370 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
371 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
373 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
375 /* Update potential sum for this i atom from the interaction with this j atom. */
376 velec = _mm_and_pd(velec,cutoff_mask);
377 velecsum = _mm_add_pd(velecsum,velec);
381 fscal = _mm_and_pd(fscal,cutoff_mask);
383 /* Calculate temporary vectorial force */
384 tx = _mm_mul_pd(fscal,dx20);
385 ty = _mm_mul_pd(fscal,dy20);
386 tz = _mm_mul_pd(fscal,dz20);
388 /* Update vectorial force */
389 fix2 = _mm_add_pd(fix2,tx);
390 fiy2 = _mm_add_pd(fiy2,ty);
391 fiz2 = _mm_add_pd(fiz2,tz);
393 fjx0 = _mm_add_pd(fjx0,tx);
394 fjy0 = _mm_add_pd(fjy0,ty);
395 fjz0 = _mm_add_pd(fjz0,tz);
399 /**************************
400 * CALCULATE INTERACTIONS *
401 **************************/
403 if (gmx_mm_any_lt(rsq30,rcutoff2))
406 r30 = _mm_mul_pd(rsq30,rinv30);
408 /* Compute parameters for interactions between i and j atoms */
409 qq30 = _mm_mul_pd(iq3,jq0);
411 /* EWALD ELECTROSTATICS */
413 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
414 ewrt = _mm_mul_pd(r30,ewtabscale);
415 ewitab = _mm_cvttpd_epi32(ewrt);
416 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
417 ewitab = _mm_slli_epi32(ewitab,2);
418 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
419 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
420 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
421 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
422 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
423 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
424 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
425 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
426 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_sub_pd(rinv30,sh_ewald),velec));
427 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
429 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
431 /* Update potential sum for this i atom from the interaction with this j atom. */
432 velec = _mm_and_pd(velec,cutoff_mask);
433 velecsum = _mm_add_pd(velecsum,velec);
437 fscal = _mm_and_pd(fscal,cutoff_mask);
439 /* Calculate temporary vectorial force */
440 tx = _mm_mul_pd(fscal,dx30);
441 ty = _mm_mul_pd(fscal,dy30);
442 tz = _mm_mul_pd(fscal,dz30);
444 /* Update vectorial force */
445 fix3 = _mm_add_pd(fix3,tx);
446 fiy3 = _mm_add_pd(fiy3,ty);
447 fiz3 = _mm_add_pd(fiz3,tz);
449 fjx0 = _mm_add_pd(fjx0,tx);
450 fjy0 = _mm_add_pd(fjy0,ty);
451 fjz0 = _mm_add_pd(fjz0,tz);
455 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
457 /* Inner loop uses 182 flops */
464 j_coord_offsetA = DIM*jnrA;
466 /* load j atom coordinates */
467 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
470 /* Calculate displacement vector */
471 dx00 = _mm_sub_pd(ix0,jx0);
472 dy00 = _mm_sub_pd(iy0,jy0);
473 dz00 = _mm_sub_pd(iz0,jz0);
474 dx10 = _mm_sub_pd(ix1,jx0);
475 dy10 = _mm_sub_pd(iy1,jy0);
476 dz10 = _mm_sub_pd(iz1,jz0);
477 dx20 = _mm_sub_pd(ix2,jx0);
478 dy20 = _mm_sub_pd(iy2,jy0);
479 dz20 = _mm_sub_pd(iz2,jz0);
480 dx30 = _mm_sub_pd(ix3,jx0);
481 dy30 = _mm_sub_pd(iy3,jy0);
482 dz30 = _mm_sub_pd(iz3,jz0);
484 /* Calculate squared distance and things based on it */
485 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
486 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
487 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
488 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
490 rinv10 = gmx_mm_invsqrt_pd(rsq10);
491 rinv20 = gmx_mm_invsqrt_pd(rsq20);
492 rinv30 = gmx_mm_invsqrt_pd(rsq30);
494 rinvsq00 = gmx_mm_inv_pd(rsq00);
495 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
496 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
497 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
499 /* Load parameters for j particles */
500 jq0 = _mm_load_sd(charge+jnrA+0);
501 vdwjidx0A = 2*vdwtype[jnrA+0];
503 fjx0 = _mm_setzero_pd();
504 fjy0 = _mm_setzero_pd();
505 fjz0 = _mm_setzero_pd();
507 /**************************
508 * CALCULATE INTERACTIONS *
509 **************************/
511 if (gmx_mm_any_lt(rsq00,rcutoff2))
514 /* Compute parameters for interactions between i and j atoms */
515 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
517 /* LENNARD-JONES DISPERSION/REPULSION */
519 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
520 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
521 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
522 vvdw = _mm_sub_pd(_mm_mul_pd( _mm_sub_pd(vvdw12 , _mm_mul_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
523 _mm_mul_pd( _mm_sub_pd(vvdw6,_mm_mul_pd(c6_00,sh_vdw_invrcut6)),one_sixth));
524 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
526 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
528 /* Update potential sum for this i atom from the interaction with this j atom. */
529 vvdw = _mm_and_pd(vvdw,cutoff_mask);
530 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
531 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
535 fscal = _mm_and_pd(fscal,cutoff_mask);
537 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
539 /* Calculate temporary vectorial force */
540 tx = _mm_mul_pd(fscal,dx00);
541 ty = _mm_mul_pd(fscal,dy00);
542 tz = _mm_mul_pd(fscal,dz00);
544 /* Update vectorial force */
545 fix0 = _mm_add_pd(fix0,tx);
546 fiy0 = _mm_add_pd(fiy0,ty);
547 fiz0 = _mm_add_pd(fiz0,tz);
549 fjx0 = _mm_add_pd(fjx0,tx);
550 fjy0 = _mm_add_pd(fjy0,ty);
551 fjz0 = _mm_add_pd(fjz0,tz);
555 /**************************
556 * CALCULATE INTERACTIONS *
557 **************************/
559 if (gmx_mm_any_lt(rsq10,rcutoff2))
562 r10 = _mm_mul_pd(rsq10,rinv10);
564 /* Compute parameters for interactions between i and j atoms */
565 qq10 = _mm_mul_pd(iq1,jq0);
567 /* EWALD ELECTROSTATICS */
569 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
570 ewrt = _mm_mul_pd(r10,ewtabscale);
571 ewitab = _mm_cvttpd_epi32(ewrt);
572 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
573 ewitab = _mm_slli_epi32(ewitab,2);
574 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
575 ewtabD = _mm_setzero_pd();
576 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
577 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
578 ewtabFn = _mm_setzero_pd();
579 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
580 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
581 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
582 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_sub_pd(rinv10,sh_ewald),velec));
583 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
585 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
587 /* Update potential sum for this i atom from the interaction with this j atom. */
588 velec = _mm_and_pd(velec,cutoff_mask);
589 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
590 velecsum = _mm_add_pd(velecsum,velec);
594 fscal = _mm_and_pd(fscal,cutoff_mask);
596 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
598 /* Calculate temporary vectorial force */
599 tx = _mm_mul_pd(fscal,dx10);
600 ty = _mm_mul_pd(fscal,dy10);
601 tz = _mm_mul_pd(fscal,dz10);
603 /* Update vectorial force */
604 fix1 = _mm_add_pd(fix1,tx);
605 fiy1 = _mm_add_pd(fiy1,ty);
606 fiz1 = _mm_add_pd(fiz1,tz);
608 fjx0 = _mm_add_pd(fjx0,tx);
609 fjy0 = _mm_add_pd(fjy0,ty);
610 fjz0 = _mm_add_pd(fjz0,tz);
614 /**************************
615 * CALCULATE INTERACTIONS *
616 **************************/
618 if (gmx_mm_any_lt(rsq20,rcutoff2))
621 r20 = _mm_mul_pd(rsq20,rinv20);
623 /* Compute parameters for interactions between i and j atoms */
624 qq20 = _mm_mul_pd(iq2,jq0);
626 /* EWALD ELECTROSTATICS */
628 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
629 ewrt = _mm_mul_pd(r20,ewtabscale);
630 ewitab = _mm_cvttpd_epi32(ewrt);
631 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
632 ewitab = _mm_slli_epi32(ewitab,2);
633 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
634 ewtabD = _mm_setzero_pd();
635 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
636 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
637 ewtabFn = _mm_setzero_pd();
638 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
639 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
640 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
641 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_sub_pd(rinv20,sh_ewald),velec));
642 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
644 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
646 /* Update potential sum for this i atom from the interaction with this j atom. */
647 velec = _mm_and_pd(velec,cutoff_mask);
648 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
649 velecsum = _mm_add_pd(velecsum,velec);
653 fscal = _mm_and_pd(fscal,cutoff_mask);
655 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
657 /* Calculate temporary vectorial force */
658 tx = _mm_mul_pd(fscal,dx20);
659 ty = _mm_mul_pd(fscal,dy20);
660 tz = _mm_mul_pd(fscal,dz20);
662 /* Update vectorial force */
663 fix2 = _mm_add_pd(fix2,tx);
664 fiy2 = _mm_add_pd(fiy2,ty);
665 fiz2 = _mm_add_pd(fiz2,tz);
667 fjx0 = _mm_add_pd(fjx0,tx);
668 fjy0 = _mm_add_pd(fjy0,ty);
669 fjz0 = _mm_add_pd(fjz0,tz);
673 /**************************
674 * CALCULATE INTERACTIONS *
675 **************************/
677 if (gmx_mm_any_lt(rsq30,rcutoff2))
680 r30 = _mm_mul_pd(rsq30,rinv30);
682 /* Compute parameters for interactions between i and j atoms */
683 qq30 = _mm_mul_pd(iq3,jq0);
685 /* EWALD ELECTROSTATICS */
687 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
688 ewrt = _mm_mul_pd(r30,ewtabscale);
689 ewitab = _mm_cvttpd_epi32(ewrt);
690 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
691 ewitab = _mm_slli_epi32(ewitab,2);
692 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
693 ewtabD = _mm_setzero_pd();
694 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
695 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
696 ewtabFn = _mm_setzero_pd();
697 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
698 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
699 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
700 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_sub_pd(rinv30,sh_ewald),velec));
701 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
703 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
705 /* Update potential sum for this i atom from the interaction with this j atom. */
706 velec = _mm_and_pd(velec,cutoff_mask);
707 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
708 velecsum = _mm_add_pd(velecsum,velec);
712 fscal = _mm_and_pd(fscal,cutoff_mask);
714 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
716 /* Calculate temporary vectorial force */
717 tx = _mm_mul_pd(fscal,dx30);
718 ty = _mm_mul_pd(fscal,dy30);
719 tz = _mm_mul_pd(fscal,dz30);
721 /* Update vectorial force */
722 fix3 = _mm_add_pd(fix3,tx);
723 fiy3 = _mm_add_pd(fiy3,ty);
724 fiz3 = _mm_add_pd(fiz3,tz);
726 fjx0 = _mm_add_pd(fjx0,tx);
727 fjy0 = _mm_add_pd(fjy0,ty);
728 fjz0 = _mm_add_pd(fjz0,tz);
732 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
734 /* Inner loop uses 182 flops */
737 /* End of innermost loop */
739 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
740 f+i_coord_offset,fshift+i_shift_offset);
743 /* Update potential energies */
744 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
745 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
747 /* Increment number of inner iterations */
748 inneriter += j_index_end - j_index_start;
750 /* Outer loop uses 26 flops */
753 /* Increment number of outer iterations */
756 /* Update outer/inner flops */
758 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*182);
761 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse2_double
762 * Electrostatics interaction: Ewald
763 * VdW interaction: LennardJones
764 * Geometry: Water4-Particle
765 * Calculate force/pot: Force
768 nb_kernel_ElecEwSh_VdwLJSh_GeomW4P1_F_sse2_double
769 (t_nblist * gmx_restrict nlist,
770 rvec * gmx_restrict xx,
771 rvec * gmx_restrict ff,
772 t_forcerec * gmx_restrict fr,
773 t_mdatoms * gmx_restrict mdatoms,
774 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
775 t_nrnb * gmx_restrict nrnb)
777 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
778 * just 0 for non-waters.
779 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
780 * jnr indices corresponding to data put in the four positions in the SIMD register.
782 int i_shift_offset,i_coord_offset,outeriter,inneriter;
783 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
785 int j_coord_offsetA,j_coord_offsetB;
786 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
788 real *shiftvec,*fshift,*x,*f;
789 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
791 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
793 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
795 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
797 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
798 int vdwjidx0A,vdwjidx0B;
799 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
800 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
801 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
802 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
803 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
804 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
807 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
810 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
811 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
813 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
815 __m128d dummy_mask,cutoff_mask;
816 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
817 __m128d one = _mm_set1_pd(1.0);
818 __m128d two = _mm_set1_pd(2.0);
824 jindex = nlist->jindex;
826 shiftidx = nlist->shift;
828 shiftvec = fr->shift_vec[0];
829 fshift = fr->fshift[0];
830 facel = _mm_set1_pd(fr->epsfac);
831 charge = mdatoms->chargeA;
832 nvdwtype = fr->ntype;
834 vdwtype = mdatoms->typeA;
836 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
837 ewtab = fr->ic->tabq_coul_F;
838 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
839 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
841 /* Setup water-specific parameters */
842 inr = nlist->iinr[0];
843 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
844 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
845 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
846 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
848 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
849 rcutoff_scalar = fr->rcoulomb;
850 rcutoff = _mm_set1_pd(rcutoff_scalar);
851 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
853 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
854 rvdw = _mm_set1_pd(fr->rvdw);
856 /* Avoid stupid compiler warnings */
864 /* Start outer loop over neighborlists */
865 for(iidx=0; iidx<nri; iidx++)
867 /* Load shift vector for this list */
868 i_shift_offset = DIM*shiftidx[iidx];
870 /* Load limits for loop over neighbors */
871 j_index_start = jindex[iidx];
872 j_index_end = jindex[iidx+1];
874 /* Get outer coordinate index */
876 i_coord_offset = DIM*inr;
878 /* Load i particle coords and add shift vector */
879 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
880 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
882 fix0 = _mm_setzero_pd();
883 fiy0 = _mm_setzero_pd();
884 fiz0 = _mm_setzero_pd();
885 fix1 = _mm_setzero_pd();
886 fiy1 = _mm_setzero_pd();
887 fiz1 = _mm_setzero_pd();
888 fix2 = _mm_setzero_pd();
889 fiy2 = _mm_setzero_pd();
890 fiz2 = _mm_setzero_pd();
891 fix3 = _mm_setzero_pd();
892 fiy3 = _mm_setzero_pd();
893 fiz3 = _mm_setzero_pd();
895 /* Start inner kernel loop */
896 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
899 /* Get j neighbor index, and coordinate index */
902 j_coord_offsetA = DIM*jnrA;
903 j_coord_offsetB = DIM*jnrB;
905 /* load j atom coordinates */
906 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
909 /* Calculate displacement vector */
910 dx00 = _mm_sub_pd(ix0,jx0);
911 dy00 = _mm_sub_pd(iy0,jy0);
912 dz00 = _mm_sub_pd(iz0,jz0);
913 dx10 = _mm_sub_pd(ix1,jx0);
914 dy10 = _mm_sub_pd(iy1,jy0);
915 dz10 = _mm_sub_pd(iz1,jz0);
916 dx20 = _mm_sub_pd(ix2,jx0);
917 dy20 = _mm_sub_pd(iy2,jy0);
918 dz20 = _mm_sub_pd(iz2,jz0);
919 dx30 = _mm_sub_pd(ix3,jx0);
920 dy30 = _mm_sub_pd(iy3,jy0);
921 dz30 = _mm_sub_pd(iz3,jz0);
923 /* Calculate squared distance and things based on it */
924 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
925 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
926 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
927 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
929 rinv10 = gmx_mm_invsqrt_pd(rsq10);
930 rinv20 = gmx_mm_invsqrt_pd(rsq20);
931 rinv30 = gmx_mm_invsqrt_pd(rsq30);
933 rinvsq00 = gmx_mm_inv_pd(rsq00);
934 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
935 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
936 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
938 /* Load parameters for j particles */
939 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
940 vdwjidx0A = 2*vdwtype[jnrA+0];
941 vdwjidx0B = 2*vdwtype[jnrB+0];
943 fjx0 = _mm_setzero_pd();
944 fjy0 = _mm_setzero_pd();
945 fjz0 = _mm_setzero_pd();
947 /**************************
948 * CALCULATE INTERACTIONS *
949 **************************/
951 if (gmx_mm_any_lt(rsq00,rcutoff2))
954 /* Compute parameters for interactions between i and j atoms */
955 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
956 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
958 /* LENNARD-JONES DISPERSION/REPULSION */
960 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
961 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
963 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
967 fscal = _mm_and_pd(fscal,cutoff_mask);
969 /* Calculate temporary vectorial force */
970 tx = _mm_mul_pd(fscal,dx00);
971 ty = _mm_mul_pd(fscal,dy00);
972 tz = _mm_mul_pd(fscal,dz00);
974 /* Update vectorial force */
975 fix0 = _mm_add_pd(fix0,tx);
976 fiy0 = _mm_add_pd(fiy0,ty);
977 fiz0 = _mm_add_pd(fiz0,tz);
979 fjx0 = _mm_add_pd(fjx0,tx);
980 fjy0 = _mm_add_pd(fjy0,ty);
981 fjz0 = _mm_add_pd(fjz0,tz);
985 /**************************
986 * CALCULATE INTERACTIONS *
987 **************************/
989 if (gmx_mm_any_lt(rsq10,rcutoff2))
992 r10 = _mm_mul_pd(rsq10,rinv10);
994 /* Compute parameters for interactions between i and j atoms */
995 qq10 = _mm_mul_pd(iq1,jq0);
997 /* EWALD ELECTROSTATICS */
999 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1000 ewrt = _mm_mul_pd(r10,ewtabscale);
1001 ewitab = _mm_cvttpd_epi32(ewrt);
1002 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
1003 gmx_mm_load_2pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1005 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
1006 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
1008 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1012 fscal = _mm_and_pd(fscal,cutoff_mask);
1014 /* Calculate temporary vectorial force */
1015 tx = _mm_mul_pd(fscal,dx10);
1016 ty = _mm_mul_pd(fscal,dy10);
1017 tz = _mm_mul_pd(fscal,dz10);
1019 /* Update vectorial force */
1020 fix1 = _mm_add_pd(fix1,tx);
1021 fiy1 = _mm_add_pd(fiy1,ty);
1022 fiz1 = _mm_add_pd(fiz1,tz);
1024 fjx0 = _mm_add_pd(fjx0,tx);
1025 fjy0 = _mm_add_pd(fjy0,ty);
1026 fjz0 = _mm_add_pd(fjz0,tz);
1030 /**************************
1031 * CALCULATE INTERACTIONS *
1032 **************************/
1034 if (gmx_mm_any_lt(rsq20,rcutoff2))
1037 r20 = _mm_mul_pd(rsq20,rinv20);
1039 /* Compute parameters for interactions between i and j atoms */
1040 qq20 = _mm_mul_pd(iq2,jq0);
1042 /* EWALD ELECTROSTATICS */
1044 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1045 ewrt = _mm_mul_pd(r20,ewtabscale);
1046 ewitab = _mm_cvttpd_epi32(ewrt);
1047 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
1048 gmx_mm_load_2pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1050 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
1051 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
1053 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1057 fscal = _mm_and_pd(fscal,cutoff_mask);
1059 /* Calculate temporary vectorial force */
1060 tx = _mm_mul_pd(fscal,dx20);
1061 ty = _mm_mul_pd(fscal,dy20);
1062 tz = _mm_mul_pd(fscal,dz20);
1064 /* Update vectorial force */
1065 fix2 = _mm_add_pd(fix2,tx);
1066 fiy2 = _mm_add_pd(fiy2,ty);
1067 fiz2 = _mm_add_pd(fiz2,tz);
1069 fjx0 = _mm_add_pd(fjx0,tx);
1070 fjy0 = _mm_add_pd(fjy0,ty);
1071 fjz0 = _mm_add_pd(fjz0,tz);
1075 /**************************
1076 * CALCULATE INTERACTIONS *
1077 **************************/
1079 if (gmx_mm_any_lt(rsq30,rcutoff2))
1082 r30 = _mm_mul_pd(rsq30,rinv30);
1084 /* Compute parameters for interactions between i and j atoms */
1085 qq30 = _mm_mul_pd(iq3,jq0);
1087 /* EWALD ELECTROSTATICS */
1089 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1090 ewrt = _mm_mul_pd(r30,ewtabscale);
1091 ewitab = _mm_cvttpd_epi32(ewrt);
1092 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
1093 gmx_mm_load_2pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
1095 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
1096 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
1098 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
1102 fscal = _mm_and_pd(fscal,cutoff_mask);
1104 /* Calculate temporary vectorial force */
1105 tx = _mm_mul_pd(fscal,dx30);
1106 ty = _mm_mul_pd(fscal,dy30);
1107 tz = _mm_mul_pd(fscal,dz30);
1109 /* Update vectorial force */
1110 fix3 = _mm_add_pd(fix3,tx);
1111 fiy3 = _mm_add_pd(fiy3,ty);
1112 fiz3 = _mm_add_pd(fiz3,tz);
1114 fjx0 = _mm_add_pd(fjx0,tx);
1115 fjy0 = _mm_add_pd(fjy0,ty);
1116 fjz0 = _mm_add_pd(fjz0,tz);
1120 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
1122 /* Inner loop uses 150 flops */
1125 if(jidx<j_index_end)
1129 j_coord_offsetA = DIM*jnrA;
1131 /* load j atom coordinates */
1132 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
1135 /* Calculate displacement vector */
1136 dx00 = _mm_sub_pd(ix0,jx0);
1137 dy00 = _mm_sub_pd(iy0,jy0);
1138 dz00 = _mm_sub_pd(iz0,jz0);
1139 dx10 = _mm_sub_pd(ix1,jx0);
1140 dy10 = _mm_sub_pd(iy1,jy0);
1141 dz10 = _mm_sub_pd(iz1,jz0);
1142 dx20 = _mm_sub_pd(ix2,jx0);
1143 dy20 = _mm_sub_pd(iy2,jy0);
1144 dz20 = _mm_sub_pd(iz2,jz0);
1145 dx30 = _mm_sub_pd(ix3,jx0);
1146 dy30 = _mm_sub_pd(iy3,jy0);
1147 dz30 = _mm_sub_pd(iz3,jz0);
1149 /* Calculate squared distance and things based on it */
1150 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1151 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
1152 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
1153 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
1155 rinv10 = gmx_mm_invsqrt_pd(rsq10);
1156 rinv20 = gmx_mm_invsqrt_pd(rsq20);
1157 rinv30 = gmx_mm_invsqrt_pd(rsq30);
1159 rinvsq00 = gmx_mm_inv_pd(rsq00);
1160 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
1161 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
1162 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
1164 /* Load parameters for j particles */
1165 jq0 = _mm_load_sd(charge+jnrA+0);
1166 vdwjidx0A = 2*vdwtype[jnrA+0];
1168 fjx0 = _mm_setzero_pd();
1169 fjy0 = _mm_setzero_pd();
1170 fjz0 = _mm_setzero_pd();
1172 /**************************
1173 * CALCULATE INTERACTIONS *
1174 **************************/
1176 if (gmx_mm_any_lt(rsq00,rcutoff2))
1179 /* Compute parameters for interactions between i and j atoms */
1180 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
1182 /* LENNARD-JONES DISPERSION/REPULSION */
1184 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
1185 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
1187 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
1191 fscal = _mm_and_pd(fscal,cutoff_mask);
1193 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1195 /* Calculate temporary vectorial force */
1196 tx = _mm_mul_pd(fscal,dx00);
1197 ty = _mm_mul_pd(fscal,dy00);
1198 tz = _mm_mul_pd(fscal,dz00);
1200 /* Update vectorial force */
1201 fix0 = _mm_add_pd(fix0,tx);
1202 fiy0 = _mm_add_pd(fiy0,ty);
1203 fiz0 = _mm_add_pd(fiz0,tz);
1205 fjx0 = _mm_add_pd(fjx0,tx);
1206 fjy0 = _mm_add_pd(fjy0,ty);
1207 fjz0 = _mm_add_pd(fjz0,tz);
1211 /**************************
1212 * CALCULATE INTERACTIONS *
1213 **************************/
1215 if (gmx_mm_any_lt(rsq10,rcutoff2))
1218 r10 = _mm_mul_pd(rsq10,rinv10);
1220 /* Compute parameters for interactions between i and j atoms */
1221 qq10 = _mm_mul_pd(iq1,jq0);
1223 /* EWALD ELECTROSTATICS */
1225 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1226 ewrt = _mm_mul_pd(r10,ewtabscale);
1227 ewitab = _mm_cvttpd_epi32(ewrt);
1228 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
1229 gmx_mm_load_1pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1230 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
1231 felec = _mm_mul_pd(_mm_mul_pd(qq10,rinv10),_mm_sub_pd(rinvsq10,felec));
1233 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1237 fscal = _mm_and_pd(fscal,cutoff_mask);
1239 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1241 /* Calculate temporary vectorial force */
1242 tx = _mm_mul_pd(fscal,dx10);
1243 ty = _mm_mul_pd(fscal,dy10);
1244 tz = _mm_mul_pd(fscal,dz10);
1246 /* Update vectorial force */
1247 fix1 = _mm_add_pd(fix1,tx);
1248 fiy1 = _mm_add_pd(fiy1,ty);
1249 fiz1 = _mm_add_pd(fiz1,tz);
1251 fjx0 = _mm_add_pd(fjx0,tx);
1252 fjy0 = _mm_add_pd(fjy0,ty);
1253 fjz0 = _mm_add_pd(fjz0,tz);
1257 /**************************
1258 * CALCULATE INTERACTIONS *
1259 **************************/
1261 if (gmx_mm_any_lt(rsq20,rcutoff2))
1264 r20 = _mm_mul_pd(rsq20,rinv20);
1266 /* Compute parameters for interactions between i and j atoms */
1267 qq20 = _mm_mul_pd(iq2,jq0);
1269 /* EWALD ELECTROSTATICS */
1271 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1272 ewrt = _mm_mul_pd(r20,ewtabscale);
1273 ewitab = _mm_cvttpd_epi32(ewrt);
1274 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
1275 gmx_mm_load_1pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1276 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
1277 felec = _mm_mul_pd(_mm_mul_pd(qq20,rinv20),_mm_sub_pd(rinvsq20,felec));
1279 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1283 fscal = _mm_and_pd(fscal,cutoff_mask);
1285 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1287 /* Calculate temporary vectorial force */
1288 tx = _mm_mul_pd(fscal,dx20);
1289 ty = _mm_mul_pd(fscal,dy20);
1290 tz = _mm_mul_pd(fscal,dz20);
1292 /* Update vectorial force */
1293 fix2 = _mm_add_pd(fix2,tx);
1294 fiy2 = _mm_add_pd(fiy2,ty);
1295 fiz2 = _mm_add_pd(fiz2,tz);
1297 fjx0 = _mm_add_pd(fjx0,tx);
1298 fjy0 = _mm_add_pd(fjy0,ty);
1299 fjz0 = _mm_add_pd(fjz0,tz);
1303 /**************************
1304 * CALCULATE INTERACTIONS *
1305 **************************/
1307 if (gmx_mm_any_lt(rsq30,rcutoff2))
1310 r30 = _mm_mul_pd(rsq30,rinv30);
1312 /* Compute parameters for interactions between i and j atoms */
1313 qq30 = _mm_mul_pd(iq3,jq0);
1315 /* EWALD ELECTROSTATICS */
1317 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
1318 ewrt = _mm_mul_pd(r30,ewtabscale);
1319 ewitab = _mm_cvttpd_epi32(ewrt);
1320 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
1321 gmx_mm_load_1pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
1322 felec = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
1323 felec = _mm_mul_pd(_mm_mul_pd(qq30,rinv30),_mm_sub_pd(rinvsq30,felec));
1325 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
1329 fscal = _mm_and_pd(fscal,cutoff_mask);
1331 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1333 /* Calculate temporary vectorial force */
1334 tx = _mm_mul_pd(fscal,dx30);
1335 ty = _mm_mul_pd(fscal,dy30);
1336 tz = _mm_mul_pd(fscal,dz30);
1338 /* Update vectorial force */
1339 fix3 = _mm_add_pd(fix3,tx);
1340 fiy3 = _mm_add_pd(fiy3,ty);
1341 fiz3 = _mm_add_pd(fiz3,tz);
1343 fjx0 = _mm_add_pd(fjx0,tx);
1344 fjy0 = _mm_add_pd(fjy0,ty);
1345 fjz0 = _mm_add_pd(fjz0,tz);
1349 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1351 /* Inner loop uses 150 flops */
1354 /* End of innermost loop */
1356 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1357 f+i_coord_offset,fshift+i_shift_offset);
1359 /* Increment number of inner iterations */
1360 inneriter += j_index_end - j_index_start;
1362 /* Outer loop uses 24 flops */
1365 /* Increment number of outer iterations */
1368 /* Update outer/inner flops */
1370 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*150);