2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse2_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_VF_sse2_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_VF_sse2_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
99 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
100 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
102 __m128i ifour = _mm_set1_epi32(4);
103 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
105 __m128 dummy_mask,cutoff_mask;
106 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107 __m128 one = _mm_set1_ps(1.0);
108 __m128 two = _mm_set1_ps(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_ps(fr->ic->epsfac);
121 charge = mdatoms->chargeA;
122 krf = _mm_set1_ps(fr->ic->k_rf);
123 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
124 crf = _mm_set1_ps(fr->ic->c_rf);
125 nvdwtype = fr->ntype;
127 vdwtype = mdatoms->typeA;
129 vftab = kernel_data->table_vdw->data;
130 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
132 /* Setup water-specific parameters */
133 inr = nlist->iinr[0];
134 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+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 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
139 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
140 rcutoff_scalar = fr->ic->rcoulomb;
141 rcutoff = _mm_set1_ps(rcutoff_scalar);
142 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
144 /* Avoid stupid compiler warnings */
145 jnrA = jnrB = jnrC = jnrD = 0;
154 for(iidx=0;iidx<4*DIM;iidx++)
159 /* Start outer loop over neighborlists */
160 for(iidx=0; iidx<nri; iidx++)
162 /* Load shift vector for this list */
163 i_shift_offset = DIM*shiftidx[iidx];
165 /* Load limits for loop over neighbors */
166 j_index_start = jindex[iidx];
167 j_index_end = jindex[iidx+1];
169 /* Get outer coordinate index */
171 i_coord_offset = DIM*inr;
173 /* Load i particle coords and add shift vector */
174 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
175 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
177 fix0 = _mm_setzero_ps();
178 fiy0 = _mm_setzero_ps();
179 fiz0 = _mm_setzero_ps();
180 fix1 = _mm_setzero_ps();
181 fiy1 = _mm_setzero_ps();
182 fiz1 = _mm_setzero_ps();
183 fix2 = _mm_setzero_ps();
184 fiy2 = _mm_setzero_ps();
185 fiz2 = _mm_setzero_ps();
187 /* Reset potential sums */
188 velecsum = _mm_setzero_ps();
189 vvdwsum = _mm_setzero_ps();
191 /* Start inner kernel loop */
192 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
195 /* Get j neighbor index, and coordinate index */
200 j_coord_offsetA = DIM*jnrA;
201 j_coord_offsetB = DIM*jnrB;
202 j_coord_offsetC = DIM*jnrC;
203 j_coord_offsetD = DIM*jnrD;
205 /* load j atom coordinates */
206 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
207 x+j_coord_offsetC,x+j_coord_offsetD,
210 /* Calculate displacement vector */
211 dx00 = _mm_sub_ps(ix0,jx0);
212 dy00 = _mm_sub_ps(iy0,jy0);
213 dz00 = _mm_sub_ps(iz0,jz0);
214 dx10 = _mm_sub_ps(ix1,jx0);
215 dy10 = _mm_sub_ps(iy1,jy0);
216 dz10 = _mm_sub_ps(iz1,jz0);
217 dx20 = _mm_sub_ps(ix2,jx0);
218 dy20 = _mm_sub_ps(iy2,jy0);
219 dz20 = _mm_sub_ps(iz2,jz0);
221 /* Calculate squared distance and things based on it */
222 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
223 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
224 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
226 rinv00 = sse2_invsqrt_f(rsq00);
227 rinv10 = sse2_invsqrt_f(rsq10);
228 rinv20 = sse2_invsqrt_f(rsq20);
230 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
231 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
232 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
234 /* Load parameters for j particles */
235 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
236 charge+jnrC+0,charge+jnrD+0);
237 vdwjidx0A = 2*vdwtype[jnrA+0];
238 vdwjidx0B = 2*vdwtype[jnrB+0];
239 vdwjidx0C = 2*vdwtype[jnrC+0];
240 vdwjidx0D = 2*vdwtype[jnrD+0];
242 fjx0 = _mm_setzero_ps();
243 fjy0 = _mm_setzero_ps();
244 fjz0 = _mm_setzero_ps();
246 /**************************
247 * CALCULATE INTERACTIONS *
248 **************************/
250 if (gmx_mm_any_lt(rsq00,rcutoff2))
253 r00 = _mm_mul_ps(rsq00,rinv00);
255 /* Compute parameters for interactions between i and j atoms */
256 qq00 = _mm_mul_ps(iq0,jq0);
257 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
258 vdwparam+vdwioffset0+vdwjidx0B,
259 vdwparam+vdwioffset0+vdwjidx0C,
260 vdwparam+vdwioffset0+vdwjidx0D,
263 /* Calculate table index by multiplying r with table scale and truncate to integer */
264 rt = _mm_mul_ps(r00,vftabscale);
265 vfitab = _mm_cvttps_epi32(rt);
266 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
267 vfitab = _mm_slli_epi32(vfitab,3);
269 /* REACTION-FIELD ELECTROSTATICS */
270 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
271 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
273 /* CUBIC SPLINE TABLE DISPERSION */
274 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
275 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
276 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
277 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
278 _MM_TRANSPOSE4_PS(Y,F,G,H);
279 Heps = _mm_mul_ps(vfeps,H);
280 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
281 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
282 vvdw6 = _mm_mul_ps(c6_00,VV);
283 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
284 fvdw6 = _mm_mul_ps(c6_00,FF);
286 /* CUBIC SPLINE TABLE REPULSION */
287 vfitab = _mm_add_epi32(vfitab,ifour);
288 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
289 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
290 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
291 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
292 _MM_TRANSPOSE4_PS(Y,F,G,H);
293 Heps = _mm_mul_ps(vfeps,H);
294 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
295 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
296 vvdw12 = _mm_mul_ps(c12_00,VV);
297 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
298 fvdw12 = _mm_mul_ps(c12_00,FF);
299 vvdw = _mm_add_ps(vvdw12,vvdw6);
300 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
302 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
304 /* Update potential sum for this i atom from the interaction with this j atom. */
305 velec = _mm_and_ps(velec,cutoff_mask);
306 velecsum = _mm_add_ps(velecsum,velec);
307 vvdw = _mm_and_ps(vvdw,cutoff_mask);
308 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
310 fscal = _mm_add_ps(felec,fvdw);
312 fscal = _mm_and_ps(fscal,cutoff_mask);
314 /* Calculate temporary vectorial force */
315 tx = _mm_mul_ps(fscal,dx00);
316 ty = _mm_mul_ps(fscal,dy00);
317 tz = _mm_mul_ps(fscal,dz00);
319 /* Update vectorial force */
320 fix0 = _mm_add_ps(fix0,tx);
321 fiy0 = _mm_add_ps(fiy0,ty);
322 fiz0 = _mm_add_ps(fiz0,tz);
324 fjx0 = _mm_add_ps(fjx0,tx);
325 fjy0 = _mm_add_ps(fjy0,ty);
326 fjz0 = _mm_add_ps(fjz0,tz);
330 /**************************
331 * CALCULATE INTERACTIONS *
332 **************************/
334 if (gmx_mm_any_lt(rsq10,rcutoff2))
337 /* Compute parameters for interactions between i and j atoms */
338 qq10 = _mm_mul_ps(iq1,jq0);
340 /* REACTION-FIELD ELECTROSTATICS */
341 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
342 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
344 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
346 /* Update potential sum for this i atom from the interaction with this j atom. */
347 velec = _mm_and_ps(velec,cutoff_mask);
348 velecsum = _mm_add_ps(velecsum,velec);
352 fscal = _mm_and_ps(fscal,cutoff_mask);
354 /* Calculate temporary vectorial force */
355 tx = _mm_mul_ps(fscal,dx10);
356 ty = _mm_mul_ps(fscal,dy10);
357 tz = _mm_mul_ps(fscal,dz10);
359 /* Update vectorial force */
360 fix1 = _mm_add_ps(fix1,tx);
361 fiy1 = _mm_add_ps(fiy1,ty);
362 fiz1 = _mm_add_ps(fiz1,tz);
364 fjx0 = _mm_add_ps(fjx0,tx);
365 fjy0 = _mm_add_ps(fjy0,ty);
366 fjz0 = _mm_add_ps(fjz0,tz);
370 /**************************
371 * CALCULATE INTERACTIONS *
372 **************************/
374 if (gmx_mm_any_lt(rsq20,rcutoff2))
377 /* Compute parameters for interactions between i and j atoms */
378 qq20 = _mm_mul_ps(iq2,jq0);
380 /* REACTION-FIELD ELECTROSTATICS */
381 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
382 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
384 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
386 /* Update potential sum for this i atom from the interaction with this j atom. */
387 velec = _mm_and_ps(velec,cutoff_mask);
388 velecsum = _mm_add_ps(velecsum,velec);
392 fscal = _mm_and_ps(fscal,cutoff_mask);
394 /* Calculate temporary vectorial force */
395 tx = _mm_mul_ps(fscal,dx20);
396 ty = _mm_mul_ps(fscal,dy20);
397 tz = _mm_mul_ps(fscal,dz20);
399 /* Update vectorial force */
400 fix2 = _mm_add_ps(fix2,tx);
401 fiy2 = _mm_add_ps(fiy2,ty);
402 fiz2 = _mm_add_ps(fiz2,tz);
404 fjx0 = _mm_add_ps(fjx0,tx);
405 fjy0 = _mm_add_ps(fjy0,ty);
406 fjz0 = _mm_add_ps(fjz0,tz);
410 fjptrA = f+j_coord_offsetA;
411 fjptrB = f+j_coord_offsetB;
412 fjptrC = f+j_coord_offsetC;
413 fjptrD = f+j_coord_offsetD;
415 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
417 /* Inner loop uses 144 flops */
423 /* Get j neighbor index, and coordinate index */
424 jnrlistA = jjnr[jidx];
425 jnrlistB = jjnr[jidx+1];
426 jnrlistC = jjnr[jidx+2];
427 jnrlistD = jjnr[jidx+3];
428 /* Sign of each element will be negative for non-real atoms.
429 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
430 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
432 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
433 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
434 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
435 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
436 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
437 j_coord_offsetA = DIM*jnrA;
438 j_coord_offsetB = DIM*jnrB;
439 j_coord_offsetC = DIM*jnrC;
440 j_coord_offsetD = DIM*jnrD;
442 /* load j atom coordinates */
443 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
444 x+j_coord_offsetC,x+j_coord_offsetD,
447 /* Calculate displacement vector */
448 dx00 = _mm_sub_ps(ix0,jx0);
449 dy00 = _mm_sub_ps(iy0,jy0);
450 dz00 = _mm_sub_ps(iz0,jz0);
451 dx10 = _mm_sub_ps(ix1,jx0);
452 dy10 = _mm_sub_ps(iy1,jy0);
453 dz10 = _mm_sub_ps(iz1,jz0);
454 dx20 = _mm_sub_ps(ix2,jx0);
455 dy20 = _mm_sub_ps(iy2,jy0);
456 dz20 = _mm_sub_ps(iz2,jz0);
458 /* Calculate squared distance and things based on it */
459 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
460 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
461 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
463 rinv00 = sse2_invsqrt_f(rsq00);
464 rinv10 = sse2_invsqrt_f(rsq10);
465 rinv20 = sse2_invsqrt_f(rsq20);
467 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
468 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
469 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
471 /* Load parameters for j particles */
472 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
473 charge+jnrC+0,charge+jnrD+0);
474 vdwjidx0A = 2*vdwtype[jnrA+0];
475 vdwjidx0B = 2*vdwtype[jnrB+0];
476 vdwjidx0C = 2*vdwtype[jnrC+0];
477 vdwjidx0D = 2*vdwtype[jnrD+0];
479 fjx0 = _mm_setzero_ps();
480 fjy0 = _mm_setzero_ps();
481 fjz0 = _mm_setzero_ps();
483 /**************************
484 * CALCULATE INTERACTIONS *
485 **************************/
487 if (gmx_mm_any_lt(rsq00,rcutoff2))
490 r00 = _mm_mul_ps(rsq00,rinv00);
491 r00 = _mm_andnot_ps(dummy_mask,r00);
493 /* Compute parameters for interactions between i and j atoms */
494 qq00 = _mm_mul_ps(iq0,jq0);
495 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
496 vdwparam+vdwioffset0+vdwjidx0B,
497 vdwparam+vdwioffset0+vdwjidx0C,
498 vdwparam+vdwioffset0+vdwjidx0D,
501 /* Calculate table index by multiplying r with table scale and truncate to integer */
502 rt = _mm_mul_ps(r00,vftabscale);
503 vfitab = _mm_cvttps_epi32(rt);
504 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
505 vfitab = _mm_slli_epi32(vfitab,3);
507 /* REACTION-FIELD ELECTROSTATICS */
508 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
509 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
511 /* CUBIC SPLINE TABLE DISPERSION */
512 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
513 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
514 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
515 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
516 _MM_TRANSPOSE4_PS(Y,F,G,H);
517 Heps = _mm_mul_ps(vfeps,H);
518 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
519 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
520 vvdw6 = _mm_mul_ps(c6_00,VV);
521 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
522 fvdw6 = _mm_mul_ps(c6_00,FF);
524 /* CUBIC SPLINE TABLE REPULSION */
525 vfitab = _mm_add_epi32(vfitab,ifour);
526 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
527 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
528 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
529 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
530 _MM_TRANSPOSE4_PS(Y,F,G,H);
531 Heps = _mm_mul_ps(vfeps,H);
532 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
533 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
534 vvdw12 = _mm_mul_ps(c12_00,VV);
535 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
536 fvdw12 = _mm_mul_ps(c12_00,FF);
537 vvdw = _mm_add_ps(vvdw12,vvdw6);
538 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
540 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
542 /* Update potential sum for this i atom from the interaction with this j atom. */
543 velec = _mm_and_ps(velec,cutoff_mask);
544 velec = _mm_andnot_ps(dummy_mask,velec);
545 velecsum = _mm_add_ps(velecsum,velec);
546 vvdw = _mm_and_ps(vvdw,cutoff_mask);
547 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
548 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
550 fscal = _mm_add_ps(felec,fvdw);
552 fscal = _mm_and_ps(fscal,cutoff_mask);
554 fscal = _mm_andnot_ps(dummy_mask,fscal);
556 /* Calculate temporary vectorial force */
557 tx = _mm_mul_ps(fscal,dx00);
558 ty = _mm_mul_ps(fscal,dy00);
559 tz = _mm_mul_ps(fscal,dz00);
561 /* Update vectorial force */
562 fix0 = _mm_add_ps(fix0,tx);
563 fiy0 = _mm_add_ps(fiy0,ty);
564 fiz0 = _mm_add_ps(fiz0,tz);
566 fjx0 = _mm_add_ps(fjx0,tx);
567 fjy0 = _mm_add_ps(fjy0,ty);
568 fjz0 = _mm_add_ps(fjz0,tz);
572 /**************************
573 * CALCULATE INTERACTIONS *
574 **************************/
576 if (gmx_mm_any_lt(rsq10,rcutoff2))
579 /* Compute parameters for interactions between i and j atoms */
580 qq10 = _mm_mul_ps(iq1,jq0);
582 /* REACTION-FIELD ELECTROSTATICS */
583 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
584 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
586 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
588 /* Update potential sum for this i atom from the interaction with this j atom. */
589 velec = _mm_and_ps(velec,cutoff_mask);
590 velec = _mm_andnot_ps(dummy_mask,velec);
591 velecsum = _mm_add_ps(velecsum,velec);
595 fscal = _mm_and_ps(fscal,cutoff_mask);
597 fscal = _mm_andnot_ps(dummy_mask,fscal);
599 /* Calculate temporary vectorial force */
600 tx = _mm_mul_ps(fscal,dx10);
601 ty = _mm_mul_ps(fscal,dy10);
602 tz = _mm_mul_ps(fscal,dz10);
604 /* Update vectorial force */
605 fix1 = _mm_add_ps(fix1,tx);
606 fiy1 = _mm_add_ps(fiy1,ty);
607 fiz1 = _mm_add_ps(fiz1,tz);
609 fjx0 = _mm_add_ps(fjx0,tx);
610 fjy0 = _mm_add_ps(fjy0,ty);
611 fjz0 = _mm_add_ps(fjz0,tz);
615 /**************************
616 * CALCULATE INTERACTIONS *
617 **************************/
619 if (gmx_mm_any_lt(rsq20,rcutoff2))
622 /* Compute parameters for interactions between i and j atoms */
623 qq20 = _mm_mul_ps(iq2,jq0);
625 /* REACTION-FIELD ELECTROSTATICS */
626 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
627 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
629 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
631 /* Update potential sum for this i atom from the interaction with this j atom. */
632 velec = _mm_and_ps(velec,cutoff_mask);
633 velec = _mm_andnot_ps(dummy_mask,velec);
634 velecsum = _mm_add_ps(velecsum,velec);
638 fscal = _mm_and_ps(fscal,cutoff_mask);
640 fscal = _mm_andnot_ps(dummy_mask,fscal);
642 /* Calculate temporary vectorial force */
643 tx = _mm_mul_ps(fscal,dx20);
644 ty = _mm_mul_ps(fscal,dy20);
645 tz = _mm_mul_ps(fscal,dz20);
647 /* Update vectorial force */
648 fix2 = _mm_add_ps(fix2,tx);
649 fiy2 = _mm_add_ps(fiy2,ty);
650 fiz2 = _mm_add_ps(fiz2,tz);
652 fjx0 = _mm_add_ps(fjx0,tx);
653 fjy0 = _mm_add_ps(fjy0,ty);
654 fjz0 = _mm_add_ps(fjz0,tz);
658 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
659 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
660 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
661 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
663 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
665 /* Inner loop uses 145 flops */
668 /* End of innermost loop */
670 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
671 f+i_coord_offset,fshift+i_shift_offset);
674 /* Update potential energies */
675 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
676 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
678 /* Increment number of inner iterations */
679 inneriter += j_index_end - j_index_start;
681 /* Outer loop uses 20 flops */
684 /* Increment number of outer iterations */
687 /* Update outer/inner flops */
689 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*145);
692 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_sse2_single
693 * Electrostatics interaction: ReactionField
694 * VdW interaction: CubicSplineTable
695 * Geometry: Water3-Particle
696 * Calculate force/pot: Force
699 nb_kernel_ElecRFCut_VdwCSTab_GeomW3P1_F_sse2_single
700 (t_nblist * gmx_restrict nlist,
701 rvec * gmx_restrict xx,
702 rvec * gmx_restrict ff,
703 struct t_forcerec * gmx_restrict fr,
704 t_mdatoms * gmx_restrict mdatoms,
705 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
706 t_nrnb * gmx_restrict nrnb)
708 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
709 * just 0 for non-waters.
710 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
711 * jnr indices corresponding to data put in the four positions in the SIMD register.
713 int i_shift_offset,i_coord_offset,outeriter,inneriter;
714 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
715 int jnrA,jnrB,jnrC,jnrD;
716 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
717 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
718 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
720 real *shiftvec,*fshift,*x,*f;
721 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
723 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
725 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
727 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
729 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
730 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
731 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
732 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
733 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
734 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
735 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
738 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
741 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
742 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
744 __m128i ifour = _mm_set1_epi32(4);
745 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
747 __m128 dummy_mask,cutoff_mask;
748 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
749 __m128 one = _mm_set1_ps(1.0);
750 __m128 two = _mm_set1_ps(2.0);
756 jindex = nlist->jindex;
758 shiftidx = nlist->shift;
760 shiftvec = fr->shift_vec[0];
761 fshift = fr->fshift[0];
762 facel = _mm_set1_ps(fr->ic->epsfac);
763 charge = mdatoms->chargeA;
764 krf = _mm_set1_ps(fr->ic->k_rf);
765 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
766 crf = _mm_set1_ps(fr->ic->c_rf);
767 nvdwtype = fr->ntype;
769 vdwtype = mdatoms->typeA;
771 vftab = kernel_data->table_vdw->data;
772 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
774 /* Setup water-specific parameters */
775 inr = nlist->iinr[0];
776 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
777 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
778 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
779 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
781 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
782 rcutoff_scalar = fr->ic->rcoulomb;
783 rcutoff = _mm_set1_ps(rcutoff_scalar);
784 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
786 /* Avoid stupid compiler warnings */
787 jnrA = jnrB = jnrC = jnrD = 0;
796 for(iidx=0;iidx<4*DIM;iidx++)
801 /* Start outer loop over neighborlists */
802 for(iidx=0; iidx<nri; iidx++)
804 /* Load shift vector for this list */
805 i_shift_offset = DIM*shiftidx[iidx];
807 /* Load limits for loop over neighbors */
808 j_index_start = jindex[iidx];
809 j_index_end = jindex[iidx+1];
811 /* Get outer coordinate index */
813 i_coord_offset = DIM*inr;
815 /* Load i particle coords and add shift vector */
816 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
817 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
819 fix0 = _mm_setzero_ps();
820 fiy0 = _mm_setzero_ps();
821 fiz0 = _mm_setzero_ps();
822 fix1 = _mm_setzero_ps();
823 fiy1 = _mm_setzero_ps();
824 fiz1 = _mm_setzero_ps();
825 fix2 = _mm_setzero_ps();
826 fiy2 = _mm_setzero_ps();
827 fiz2 = _mm_setzero_ps();
829 /* Start inner kernel loop */
830 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
833 /* Get j neighbor index, and coordinate index */
838 j_coord_offsetA = DIM*jnrA;
839 j_coord_offsetB = DIM*jnrB;
840 j_coord_offsetC = DIM*jnrC;
841 j_coord_offsetD = DIM*jnrD;
843 /* load j atom coordinates */
844 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
845 x+j_coord_offsetC,x+j_coord_offsetD,
848 /* Calculate displacement vector */
849 dx00 = _mm_sub_ps(ix0,jx0);
850 dy00 = _mm_sub_ps(iy0,jy0);
851 dz00 = _mm_sub_ps(iz0,jz0);
852 dx10 = _mm_sub_ps(ix1,jx0);
853 dy10 = _mm_sub_ps(iy1,jy0);
854 dz10 = _mm_sub_ps(iz1,jz0);
855 dx20 = _mm_sub_ps(ix2,jx0);
856 dy20 = _mm_sub_ps(iy2,jy0);
857 dz20 = _mm_sub_ps(iz2,jz0);
859 /* Calculate squared distance and things based on it */
860 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
861 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
862 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
864 rinv00 = sse2_invsqrt_f(rsq00);
865 rinv10 = sse2_invsqrt_f(rsq10);
866 rinv20 = sse2_invsqrt_f(rsq20);
868 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
869 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
870 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
872 /* Load parameters for j particles */
873 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
874 charge+jnrC+0,charge+jnrD+0);
875 vdwjidx0A = 2*vdwtype[jnrA+0];
876 vdwjidx0B = 2*vdwtype[jnrB+0];
877 vdwjidx0C = 2*vdwtype[jnrC+0];
878 vdwjidx0D = 2*vdwtype[jnrD+0];
880 fjx0 = _mm_setzero_ps();
881 fjy0 = _mm_setzero_ps();
882 fjz0 = _mm_setzero_ps();
884 /**************************
885 * CALCULATE INTERACTIONS *
886 **************************/
888 if (gmx_mm_any_lt(rsq00,rcutoff2))
891 r00 = _mm_mul_ps(rsq00,rinv00);
893 /* Compute parameters for interactions between i and j atoms */
894 qq00 = _mm_mul_ps(iq0,jq0);
895 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
896 vdwparam+vdwioffset0+vdwjidx0B,
897 vdwparam+vdwioffset0+vdwjidx0C,
898 vdwparam+vdwioffset0+vdwjidx0D,
901 /* Calculate table index by multiplying r with table scale and truncate to integer */
902 rt = _mm_mul_ps(r00,vftabscale);
903 vfitab = _mm_cvttps_epi32(rt);
904 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
905 vfitab = _mm_slli_epi32(vfitab,3);
907 /* REACTION-FIELD ELECTROSTATICS */
908 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
910 /* CUBIC SPLINE TABLE DISPERSION */
911 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
912 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
913 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
914 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
915 _MM_TRANSPOSE4_PS(Y,F,G,H);
916 Heps = _mm_mul_ps(vfeps,H);
917 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
918 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
919 fvdw6 = _mm_mul_ps(c6_00,FF);
921 /* CUBIC SPLINE TABLE REPULSION */
922 vfitab = _mm_add_epi32(vfitab,ifour);
923 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
924 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
925 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
926 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
927 _MM_TRANSPOSE4_PS(Y,F,G,H);
928 Heps = _mm_mul_ps(vfeps,H);
929 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
930 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
931 fvdw12 = _mm_mul_ps(c12_00,FF);
932 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
934 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
936 fscal = _mm_add_ps(felec,fvdw);
938 fscal = _mm_and_ps(fscal,cutoff_mask);
940 /* Calculate temporary vectorial force */
941 tx = _mm_mul_ps(fscal,dx00);
942 ty = _mm_mul_ps(fscal,dy00);
943 tz = _mm_mul_ps(fscal,dz00);
945 /* Update vectorial force */
946 fix0 = _mm_add_ps(fix0,tx);
947 fiy0 = _mm_add_ps(fiy0,ty);
948 fiz0 = _mm_add_ps(fiz0,tz);
950 fjx0 = _mm_add_ps(fjx0,tx);
951 fjy0 = _mm_add_ps(fjy0,ty);
952 fjz0 = _mm_add_ps(fjz0,tz);
956 /**************************
957 * CALCULATE INTERACTIONS *
958 **************************/
960 if (gmx_mm_any_lt(rsq10,rcutoff2))
963 /* Compute parameters for interactions between i and j atoms */
964 qq10 = _mm_mul_ps(iq1,jq0);
966 /* REACTION-FIELD ELECTROSTATICS */
967 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
969 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
973 fscal = _mm_and_ps(fscal,cutoff_mask);
975 /* Calculate temporary vectorial force */
976 tx = _mm_mul_ps(fscal,dx10);
977 ty = _mm_mul_ps(fscal,dy10);
978 tz = _mm_mul_ps(fscal,dz10);
980 /* Update vectorial force */
981 fix1 = _mm_add_ps(fix1,tx);
982 fiy1 = _mm_add_ps(fiy1,ty);
983 fiz1 = _mm_add_ps(fiz1,tz);
985 fjx0 = _mm_add_ps(fjx0,tx);
986 fjy0 = _mm_add_ps(fjy0,ty);
987 fjz0 = _mm_add_ps(fjz0,tz);
991 /**************************
992 * CALCULATE INTERACTIONS *
993 **************************/
995 if (gmx_mm_any_lt(rsq20,rcutoff2))
998 /* Compute parameters for interactions between i and j atoms */
999 qq20 = _mm_mul_ps(iq2,jq0);
1001 /* REACTION-FIELD ELECTROSTATICS */
1002 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1004 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1008 fscal = _mm_and_ps(fscal,cutoff_mask);
1010 /* Calculate temporary vectorial force */
1011 tx = _mm_mul_ps(fscal,dx20);
1012 ty = _mm_mul_ps(fscal,dy20);
1013 tz = _mm_mul_ps(fscal,dz20);
1015 /* Update vectorial force */
1016 fix2 = _mm_add_ps(fix2,tx);
1017 fiy2 = _mm_add_ps(fiy2,ty);
1018 fiz2 = _mm_add_ps(fiz2,tz);
1020 fjx0 = _mm_add_ps(fjx0,tx);
1021 fjy0 = _mm_add_ps(fjy0,ty);
1022 fjz0 = _mm_add_ps(fjz0,tz);
1026 fjptrA = f+j_coord_offsetA;
1027 fjptrB = f+j_coord_offsetB;
1028 fjptrC = f+j_coord_offsetC;
1029 fjptrD = f+j_coord_offsetD;
1031 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1033 /* Inner loop uses 117 flops */
1036 if(jidx<j_index_end)
1039 /* Get j neighbor index, and coordinate index */
1040 jnrlistA = jjnr[jidx];
1041 jnrlistB = jjnr[jidx+1];
1042 jnrlistC = jjnr[jidx+2];
1043 jnrlistD = jjnr[jidx+3];
1044 /* Sign of each element will be negative for non-real atoms.
1045 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1046 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1048 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1049 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1050 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1051 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1052 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1053 j_coord_offsetA = DIM*jnrA;
1054 j_coord_offsetB = DIM*jnrB;
1055 j_coord_offsetC = DIM*jnrC;
1056 j_coord_offsetD = DIM*jnrD;
1058 /* load j atom coordinates */
1059 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1060 x+j_coord_offsetC,x+j_coord_offsetD,
1063 /* Calculate displacement vector */
1064 dx00 = _mm_sub_ps(ix0,jx0);
1065 dy00 = _mm_sub_ps(iy0,jy0);
1066 dz00 = _mm_sub_ps(iz0,jz0);
1067 dx10 = _mm_sub_ps(ix1,jx0);
1068 dy10 = _mm_sub_ps(iy1,jy0);
1069 dz10 = _mm_sub_ps(iz1,jz0);
1070 dx20 = _mm_sub_ps(ix2,jx0);
1071 dy20 = _mm_sub_ps(iy2,jy0);
1072 dz20 = _mm_sub_ps(iz2,jz0);
1074 /* Calculate squared distance and things based on it */
1075 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1076 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1077 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1079 rinv00 = sse2_invsqrt_f(rsq00);
1080 rinv10 = sse2_invsqrt_f(rsq10);
1081 rinv20 = sse2_invsqrt_f(rsq20);
1083 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1084 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1085 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1087 /* Load parameters for j particles */
1088 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1089 charge+jnrC+0,charge+jnrD+0);
1090 vdwjidx0A = 2*vdwtype[jnrA+0];
1091 vdwjidx0B = 2*vdwtype[jnrB+0];
1092 vdwjidx0C = 2*vdwtype[jnrC+0];
1093 vdwjidx0D = 2*vdwtype[jnrD+0];
1095 fjx0 = _mm_setzero_ps();
1096 fjy0 = _mm_setzero_ps();
1097 fjz0 = _mm_setzero_ps();
1099 /**************************
1100 * CALCULATE INTERACTIONS *
1101 **************************/
1103 if (gmx_mm_any_lt(rsq00,rcutoff2))
1106 r00 = _mm_mul_ps(rsq00,rinv00);
1107 r00 = _mm_andnot_ps(dummy_mask,r00);
1109 /* Compute parameters for interactions between i and j atoms */
1110 qq00 = _mm_mul_ps(iq0,jq0);
1111 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1112 vdwparam+vdwioffset0+vdwjidx0B,
1113 vdwparam+vdwioffset0+vdwjidx0C,
1114 vdwparam+vdwioffset0+vdwjidx0D,
1117 /* Calculate table index by multiplying r with table scale and truncate to integer */
1118 rt = _mm_mul_ps(r00,vftabscale);
1119 vfitab = _mm_cvttps_epi32(rt);
1120 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
1121 vfitab = _mm_slli_epi32(vfitab,3);
1123 /* REACTION-FIELD ELECTROSTATICS */
1124 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1126 /* CUBIC SPLINE TABLE DISPERSION */
1127 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1128 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1129 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1130 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1131 _MM_TRANSPOSE4_PS(Y,F,G,H);
1132 Heps = _mm_mul_ps(vfeps,H);
1133 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1134 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1135 fvdw6 = _mm_mul_ps(c6_00,FF);
1137 /* CUBIC SPLINE TABLE REPULSION */
1138 vfitab = _mm_add_epi32(vfitab,ifour);
1139 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1140 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1141 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1142 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1143 _MM_TRANSPOSE4_PS(Y,F,G,H);
1144 Heps = _mm_mul_ps(vfeps,H);
1145 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1146 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1147 fvdw12 = _mm_mul_ps(c12_00,FF);
1148 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1150 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1152 fscal = _mm_add_ps(felec,fvdw);
1154 fscal = _mm_and_ps(fscal,cutoff_mask);
1156 fscal = _mm_andnot_ps(dummy_mask,fscal);
1158 /* Calculate temporary vectorial force */
1159 tx = _mm_mul_ps(fscal,dx00);
1160 ty = _mm_mul_ps(fscal,dy00);
1161 tz = _mm_mul_ps(fscal,dz00);
1163 /* Update vectorial force */
1164 fix0 = _mm_add_ps(fix0,tx);
1165 fiy0 = _mm_add_ps(fiy0,ty);
1166 fiz0 = _mm_add_ps(fiz0,tz);
1168 fjx0 = _mm_add_ps(fjx0,tx);
1169 fjy0 = _mm_add_ps(fjy0,ty);
1170 fjz0 = _mm_add_ps(fjz0,tz);
1174 /**************************
1175 * CALCULATE INTERACTIONS *
1176 **************************/
1178 if (gmx_mm_any_lt(rsq10,rcutoff2))
1181 /* Compute parameters for interactions between i and j atoms */
1182 qq10 = _mm_mul_ps(iq1,jq0);
1184 /* REACTION-FIELD ELECTROSTATICS */
1185 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1187 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1191 fscal = _mm_and_ps(fscal,cutoff_mask);
1193 fscal = _mm_andnot_ps(dummy_mask,fscal);
1195 /* Calculate temporary vectorial force */
1196 tx = _mm_mul_ps(fscal,dx10);
1197 ty = _mm_mul_ps(fscal,dy10);
1198 tz = _mm_mul_ps(fscal,dz10);
1200 /* Update vectorial force */
1201 fix1 = _mm_add_ps(fix1,tx);
1202 fiy1 = _mm_add_ps(fiy1,ty);
1203 fiz1 = _mm_add_ps(fiz1,tz);
1205 fjx0 = _mm_add_ps(fjx0,tx);
1206 fjy0 = _mm_add_ps(fjy0,ty);
1207 fjz0 = _mm_add_ps(fjz0,tz);
1211 /**************************
1212 * CALCULATE INTERACTIONS *
1213 **************************/
1215 if (gmx_mm_any_lt(rsq20,rcutoff2))
1218 /* Compute parameters for interactions between i and j atoms */
1219 qq20 = _mm_mul_ps(iq2,jq0);
1221 /* REACTION-FIELD ELECTROSTATICS */
1222 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1224 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1228 fscal = _mm_and_ps(fscal,cutoff_mask);
1230 fscal = _mm_andnot_ps(dummy_mask,fscal);
1232 /* Calculate temporary vectorial force */
1233 tx = _mm_mul_ps(fscal,dx20);
1234 ty = _mm_mul_ps(fscal,dy20);
1235 tz = _mm_mul_ps(fscal,dz20);
1237 /* Update vectorial force */
1238 fix2 = _mm_add_ps(fix2,tx);
1239 fiy2 = _mm_add_ps(fiy2,ty);
1240 fiz2 = _mm_add_ps(fiz2,tz);
1242 fjx0 = _mm_add_ps(fjx0,tx);
1243 fjy0 = _mm_add_ps(fjy0,ty);
1244 fjz0 = _mm_add_ps(fjz0,tz);
1248 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1249 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1250 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1251 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1253 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1255 /* Inner loop uses 118 flops */
1258 /* End of innermost loop */
1260 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1261 f+i_coord_offset,fshift+i_shift_offset);
1263 /* Increment number of inner iterations */
1264 inneriter += j_index_end - j_index_start;
1266 /* Outer loop uses 18 flops */
1269 /* Increment number of outer iterations */
1272 /* Update outer/inner flops */
1274 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*118);