2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse4_1_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse4_1_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_VF_sse4_1_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_VF_sse4_1_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
91 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
103 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
105 __m128i ifour = _mm_set1_epi32(4);
106 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
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->ic->epsfac);
124 charge = mdatoms->chargeA;
125 krf = _mm_set1_ps(fr->ic->k_rf);
126 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
127 crf = _mm_set1_ps(fr->ic->c_rf);
128 nvdwtype = fr->ntype;
130 vdwtype = mdatoms->typeA;
132 vftab = kernel_data->table_vdw->data;
133 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
135 /* Setup water-specific parameters */
136 inr = nlist->iinr[0];
137 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
138 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
139 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
140 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
142 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
143 rcutoff_scalar = fr->ic->rcoulomb;
144 rcutoff = _mm_set1_ps(rcutoff_scalar);
145 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
147 /* Avoid stupid compiler warnings */
148 jnrA = jnrB = jnrC = jnrD = 0;
157 for(iidx=0;iidx<4*DIM;iidx++)
162 /* Start outer loop over neighborlists */
163 for(iidx=0; iidx<nri; iidx++)
165 /* Load shift vector for this list */
166 i_shift_offset = DIM*shiftidx[iidx];
168 /* Load limits for loop over neighbors */
169 j_index_start = jindex[iidx];
170 j_index_end = jindex[iidx+1];
172 /* Get outer coordinate index */
174 i_coord_offset = DIM*inr;
176 /* Load i particle coords and add shift vector */
177 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
178 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
180 fix0 = _mm_setzero_ps();
181 fiy0 = _mm_setzero_ps();
182 fiz0 = _mm_setzero_ps();
183 fix1 = _mm_setzero_ps();
184 fiy1 = _mm_setzero_ps();
185 fiz1 = _mm_setzero_ps();
186 fix2 = _mm_setzero_ps();
187 fiy2 = _mm_setzero_ps();
188 fiz2 = _mm_setzero_ps();
189 fix3 = _mm_setzero_ps();
190 fiy3 = _mm_setzero_ps();
191 fiz3 = _mm_setzero_ps();
193 /* Reset potential sums */
194 velecsum = _mm_setzero_ps();
195 vvdwsum = _mm_setzero_ps();
197 /* Start inner kernel loop */
198 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
201 /* Get j neighbor index, and coordinate index */
206 j_coord_offsetA = DIM*jnrA;
207 j_coord_offsetB = DIM*jnrB;
208 j_coord_offsetC = DIM*jnrC;
209 j_coord_offsetD = DIM*jnrD;
211 /* load j atom coordinates */
212 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
213 x+j_coord_offsetC,x+j_coord_offsetD,
216 /* Calculate displacement vector */
217 dx00 = _mm_sub_ps(ix0,jx0);
218 dy00 = _mm_sub_ps(iy0,jy0);
219 dz00 = _mm_sub_ps(iz0,jz0);
220 dx10 = _mm_sub_ps(ix1,jx0);
221 dy10 = _mm_sub_ps(iy1,jy0);
222 dz10 = _mm_sub_ps(iz1,jz0);
223 dx20 = _mm_sub_ps(ix2,jx0);
224 dy20 = _mm_sub_ps(iy2,jy0);
225 dz20 = _mm_sub_ps(iz2,jz0);
226 dx30 = _mm_sub_ps(ix3,jx0);
227 dy30 = _mm_sub_ps(iy3,jy0);
228 dz30 = _mm_sub_ps(iz3,jz0);
230 /* Calculate squared distance and things based on it */
231 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
232 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
233 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
234 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
236 rinv00 = sse41_invsqrt_f(rsq00);
237 rinv10 = sse41_invsqrt_f(rsq10);
238 rinv20 = sse41_invsqrt_f(rsq20);
239 rinv30 = sse41_invsqrt_f(rsq30);
241 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
242 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
243 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
245 /* Load parameters for j particles */
246 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
247 charge+jnrC+0,charge+jnrD+0);
248 vdwjidx0A = 2*vdwtype[jnrA+0];
249 vdwjidx0B = 2*vdwtype[jnrB+0];
250 vdwjidx0C = 2*vdwtype[jnrC+0];
251 vdwjidx0D = 2*vdwtype[jnrD+0];
253 fjx0 = _mm_setzero_ps();
254 fjy0 = _mm_setzero_ps();
255 fjz0 = _mm_setzero_ps();
257 /**************************
258 * CALCULATE INTERACTIONS *
259 **************************/
261 r00 = _mm_mul_ps(rsq00,rinv00);
263 /* Compute parameters for interactions between i and j atoms */
264 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
265 vdwparam+vdwioffset0+vdwjidx0B,
266 vdwparam+vdwioffset0+vdwjidx0C,
267 vdwparam+vdwioffset0+vdwjidx0D,
270 /* Calculate table index by multiplying r with table scale and truncate to integer */
271 rt = _mm_mul_ps(r00,vftabscale);
272 vfitab = _mm_cvttps_epi32(rt);
273 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
274 vfitab = _mm_slli_epi32(vfitab,3);
276 /* CUBIC SPLINE TABLE DISPERSION */
277 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
278 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
279 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
280 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
281 _MM_TRANSPOSE4_PS(Y,F,G,H);
282 Heps = _mm_mul_ps(vfeps,H);
283 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
284 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
285 vvdw6 = _mm_mul_ps(c6_00,VV);
286 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
287 fvdw6 = _mm_mul_ps(c6_00,FF);
289 /* CUBIC SPLINE TABLE REPULSION */
290 vfitab = _mm_add_epi32(vfitab,ifour);
291 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
292 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
293 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
294 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
295 _MM_TRANSPOSE4_PS(Y,F,G,H);
296 Heps = _mm_mul_ps(vfeps,H);
297 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
298 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
299 vvdw12 = _mm_mul_ps(c12_00,VV);
300 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
301 fvdw12 = _mm_mul_ps(c12_00,FF);
302 vvdw = _mm_add_ps(vvdw12,vvdw6);
303 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
305 /* Update potential sum for this i atom from the interaction with this j atom. */
306 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
310 /* Calculate temporary vectorial force */
311 tx = _mm_mul_ps(fscal,dx00);
312 ty = _mm_mul_ps(fscal,dy00);
313 tz = _mm_mul_ps(fscal,dz00);
315 /* Update vectorial force */
316 fix0 = _mm_add_ps(fix0,tx);
317 fiy0 = _mm_add_ps(fiy0,ty);
318 fiz0 = _mm_add_ps(fiz0,tz);
320 fjx0 = _mm_add_ps(fjx0,tx);
321 fjy0 = _mm_add_ps(fjy0,ty);
322 fjz0 = _mm_add_ps(fjz0,tz);
324 /**************************
325 * CALCULATE INTERACTIONS *
326 **************************/
328 if (gmx_mm_any_lt(rsq10,rcutoff2))
331 /* Compute parameters for interactions between i and j atoms */
332 qq10 = _mm_mul_ps(iq1,jq0);
334 /* REACTION-FIELD ELECTROSTATICS */
335 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
336 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
338 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
340 /* Update potential sum for this i atom from the interaction with this j atom. */
341 velec = _mm_and_ps(velec,cutoff_mask);
342 velecsum = _mm_add_ps(velecsum,velec);
346 fscal = _mm_and_ps(fscal,cutoff_mask);
348 /* Calculate temporary vectorial force */
349 tx = _mm_mul_ps(fscal,dx10);
350 ty = _mm_mul_ps(fscal,dy10);
351 tz = _mm_mul_ps(fscal,dz10);
353 /* Update vectorial force */
354 fix1 = _mm_add_ps(fix1,tx);
355 fiy1 = _mm_add_ps(fiy1,ty);
356 fiz1 = _mm_add_ps(fiz1,tz);
358 fjx0 = _mm_add_ps(fjx0,tx);
359 fjy0 = _mm_add_ps(fjy0,ty);
360 fjz0 = _mm_add_ps(fjz0,tz);
364 /**************************
365 * CALCULATE INTERACTIONS *
366 **************************/
368 if (gmx_mm_any_lt(rsq20,rcutoff2))
371 /* Compute parameters for interactions between i and j atoms */
372 qq20 = _mm_mul_ps(iq2,jq0);
374 /* REACTION-FIELD ELECTROSTATICS */
375 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
376 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
378 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
380 /* Update potential sum for this i atom from the interaction with this j atom. */
381 velec = _mm_and_ps(velec,cutoff_mask);
382 velecsum = _mm_add_ps(velecsum,velec);
386 fscal = _mm_and_ps(fscal,cutoff_mask);
388 /* Calculate temporary vectorial force */
389 tx = _mm_mul_ps(fscal,dx20);
390 ty = _mm_mul_ps(fscal,dy20);
391 tz = _mm_mul_ps(fscal,dz20);
393 /* Update vectorial force */
394 fix2 = _mm_add_ps(fix2,tx);
395 fiy2 = _mm_add_ps(fiy2,ty);
396 fiz2 = _mm_add_ps(fiz2,tz);
398 fjx0 = _mm_add_ps(fjx0,tx);
399 fjy0 = _mm_add_ps(fjy0,ty);
400 fjz0 = _mm_add_ps(fjz0,tz);
404 /**************************
405 * CALCULATE INTERACTIONS *
406 **************************/
408 if (gmx_mm_any_lt(rsq30,rcutoff2))
411 /* Compute parameters for interactions between i and j atoms */
412 qq30 = _mm_mul_ps(iq3,jq0);
414 /* REACTION-FIELD ELECTROSTATICS */
415 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
416 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
418 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
420 /* Update potential sum for this i atom from the interaction with this j atom. */
421 velec = _mm_and_ps(velec,cutoff_mask);
422 velecsum = _mm_add_ps(velecsum,velec);
426 fscal = _mm_and_ps(fscal,cutoff_mask);
428 /* Calculate temporary vectorial force */
429 tx = _mm_mul_ps(fscal,dx30);
430 ty = _mm_mul_ps(fscal,dy30);
431 tz = _mm_mul_ps(fscal,dz30);
433 /* Update vectorial force */
434 fix3 = _mm_add_ps(fix3,tx);
435 fiy3 = _mm_add_ps(fiy3,ty);
436 fiz3 = _mm_add_ps(fiz3,tz);
438 fjx0 = _mm_add_ps(fjx0,tx);
439 fjy0 = _mm_add_ps(fjy0,ty);
440 fjz0 = _mm_add_ps(fjz0,tz);
444 fjptrA = f+j_coord_offsetA;
445 fjptrB = f+j_coord_offsetB;
446 fjptrC = f+j_coord_offsetC;
447 fjptrD = f+j_coord_offsetD;
449 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
451 /* Inner loop uses 164 flops */
457 /* Get j neighbor index, and coordinate index */
458 jnrlistA = jjnr[jidx];
459 jnrlistB = jjnr[jidx+1];
460 jnrlistC = jjnr[jidx+2];
461 jnrlistD = jjnr[jidx+3];
462 /* Sign of each element will be negative for non-real atoms.
463 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
464 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
466 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
467 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
468 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
469 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
470 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
471 j_coord_offsetA = DIM*jnrA;
472 j_coord_offsetB = DIM*jnrB;
473 j_coord_offsetC = DIM*jnrC;
474 j_coord_offsetD = DIM*jnrD;
476 /* load j atom coordinates */
477 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
478 x+j_coord_offsetC,x+j_coord_offsetD,
481 /* Calculate displacement vector */
482 dx00 = _mm_sub_ps(ix0,jx0);
483 dy00 = _mm_sub_ps(iy0,jy0);
484 dz00 = _mm_sub_ps(iz0,jz0);
485 dx10 = _mm_sub_ps(ix1,jx0);
486 dy10 = _mm_sub_ps(iy1,jy0);
487 dz10 = _mm_sub_ps(iz1,jz0);
488 dx20 = _mm_sub_ps(ix2,jx0);
489 dy20 = _mm_sub_ps(iy2,jy0);
490 dz20 = _mm_sub_ps(iz2,jz0);
491 dx30 = _mm_sub_ps(ix3,jx0);
492 dy30 = _mm_sub_ps(iy3,jy0);
493 dz30 = _mm_sub_ps(iz3,jz0);
495 /* Calculate squared distance and things based on it */
496 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
497 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
498 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
499 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
501 rinv00 = sse41_invsqrt_f(rsq00);
502 rinv10 = sse41_invsqrt_f(rsq10);
503 rinv20 = sse41_invsqrt_f(rsq20);
504 rinv30 = sse41_invsqrt_f(rsq30);
506 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
507 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
508 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
510 /* Load parameters for j particles */
511 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
512 charge+jnrC+0,charge+jnrD+0);
513 vdwjidx0A = 2*vdwtype[jnrA+0];
514 vdwjidx0B = 2*vdwtype[jnrB+0];
515 vdwjidx0C = 2*vdwtype[jnrC+0];
516 vdwjidx0D = 2*vdwtype[jnrD+0];
518 fjx0 = _mm_setzero_ps();
519 fjy0 = _mm_setzero_ps();
520 fjz0 = _mm_setzero_ps();
522 /**************************
523 * CALCULATE INTERACTIONS *
524 **************************/
526 r00 = _mm_mul_ps(rsq00,rinv00);
527 r00 = _mm_andnot_ps(dummy_mask,r00);
529 /* Compute parameters for interactions between i and j atoms */
530 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
531 vdwparam+vdwioffset0+vdwjidx0B,
532 vdwparam+vdwioffset0+vdwjidx0C,
533 vdwparam+vdwioffset0+vdwjidx0D,
536 /* Calculate table index by multiplying r with table scale and truncate to integer */
537 rt = _mm_mul_ps(r00,vftabscale);
538 vfitab = _mm_cvttps_epi32(rt);
539 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
540 vfitab = _mm_slli_epi32(vfitab,3);
542 /* CUBIC SPLINE TABLE DISPERSION */
543 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
544 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
545 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
546 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
547 _MM_TRANSPOSE4_PS(Y,F,G,H);
548 Heps = _mm_mul_ps(vfeps,H);
549 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
550 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
551 vvdw6 = _mm_mul_ps(c6_00,VV);
552 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
553 fvdw6 = _mm_mul_ps(c6_00,FF);
555 /* CUBIC SPLINE TABLE REPULSION */
556 vfitab = _mm_add_epi32(vfitab,ifour);
557 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
558 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
559 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
560 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
561 _MM_TRANSPOSE4_PS(Y,F,G,H);
562 Heps = _mm_mul_ps(vfeps,H);
563 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
564 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
565 vvdw12 = _mm_mul_ps(c12_00,VV);
566 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
567 fvdw12 = _mm_mul_ps(c12_00,FF);
568 vvdw = _mm_add_ps(vvdw12,vvdw6);
569 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
571 /* Update potential sum for this i atom from the interaction with this j atom. */
572 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
573 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
577 fscal = _mm_andnot_ps(dummy_mask,fscal);
579 /* Calculate temporary vectorial force */
580 tx = _mm_mul_ps(fscal,dx00);
581 ty = _mm_mul_ps(fscal,dy00);
582 tz = _mm_mul_ps(fscal,dz00);
584 /* Update vectorial force */
585 fix0 = _mm_add_ps(fix0,tx);
586 fiy0 = _mm_add_ps(fiy0,ty);
587 fiz0 = _mm_add_ps(fiz0,tz);
589 fjx0 = _mm_add_ps(fjx0,tx);
590 fjy0 = _mm_add_ps(fjy0,ty);
591 fjz0 = _mm_add_ps(fjz0,tz);
593 /**************************
594 * CALCULATE INTERACTIONS *
595 **************************/
597 if (gmx_mm_any_lt(rsq10,rcutoff2))
600 /* Compute parameters for interactions between i and j atoms */
601 qq10 = _mm_mul_ps(iq1,jq0);
603 /* REACTION-FIELD ELECTROSTATICS */
604 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
605 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
607 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
609 /* Update potential sum for this i atom from the interaction with this j atom. */
610 velec = _mm_and_ps(velec,cutoff_mask);
611 velec = _mm_andnot_ps(dummy_mask,velec);
612 velecsum = _mm_add_ps(velecsum,velec);
616 fscal = _mm_and_ps(fscal,cutoff_mask);
618 fscal = _mm_andnot_ps(dummy_mask,fscal);
620 /* Calculate temporary vectorial force */
621 tx = _mm_mul_ps(fscal,dx10);
622 ty = _mm_mul_ps(fscal,dy10);
623 tz = _mm_mul_ps(fscal,dz10);
625 /* Update vectorial force */
626 fix1 = _mm_add_ps(fix1,tx);
627 fiy1 = _mm_add_ps(fiy1,ty);
628 fiz1 = _mm_add_ps(fiz1,tz);
630 fjx0 = _mm_add_ps(fjx0,tx);
631 fjy0 = _mm_add_ps(fjy0,ty);
632 fjz0 = _mm_add_ps(fjz0,tz);
636 /**************************
637 * CALCULATE INTERACTIONS *
638 **************************/
640 if (gmx_mm_any_lt(rsq20,rcutoff2))
643 /* Compute parameters for interactions between i and j atoms */
644 qq20 = _mm_mul_ps(iq2,jq0);
646 /* REACTION-FIELD ELECTROSTATICS */
647 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
648 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
650 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
652 /* Update potential sum for this i atom from the interaction with this j atom. */
653 velec = _mm_and_ps(velec,cutoff_mask);
654 velec = _mm_andnot_ps(dummy_mask,velec);
655 velecsum = _mm_add_ps(velecsum,velec);
659 fscal = _mm_and_ps(fscal,cutoff_mask);
661 fscal = _mm_andnot_ps(dummy_mask,fscal);
663 /* Calculate temporary vectorial force */
664 tx = _mm_mul_ps(fscal,dx20);
665 ty = _mm_mul_ps(fscal,dy20);
666 tz = _mm_mul_ps(fscal,dz20);
668 /* Update vectorial force */
669 fix2 = _mm_add_ps(fix2,tx);
670 fiy2 = _mm_add_ps(fiy2,ty);
671 fiz2 = _mm_add_ps(fiz2,tz);
673 fjx0 = _mm_add_ps(fjx0,tx);
674 fjy0 = _mm_add_ps(fjy0,ty);
675 fjz0 = _mm_add_ps(fjz0,tz);
679 /**************************
680 * CALCULATE INTERACTIONS *
681 **************************/
683 if (gmx_mm_any_lt(rsq30,rcutoff2))
686 /* Compute parameters for interactions between i and j atoms */
687 qq30 = _mm_mul_ps(iq3,jq0);
689 /* REACTION-FIELD ELECTROSTATICS */
690 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
691 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
693 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
695 /* Update potential sum for this i atom from the interaction with this j atom. */
696 velec = _mm_and_ps(velec,cutoff_mask);
697 velec = _mm_andnot_ps(dummy_mask,velec);
698 velecsum = _mm_add_ps(velecsum,velec);
702 fscal = _mm_and_ps(fscal,cutoff_mask);
704 fscal = _mm_andnot_ps(dummy_mask,fscal);
706 /* Calculate temporary vectorial force */
707 tx = _mm_mul_ps(fscal,dx30);
708 ty = _mm_mul_ps(fscal,dy30);
709 tz = _mm_mul_ps(fscal,dz30);
711 /* Update vectorial force */
712 fix3 = _mm_add_ps(fix3,tx);
713 fiy3 = _mm_add_ps(fiy3,ty);
714 fiz3 = _mm_add_ps(fiz3,tz);
716 fjx0 = _mm_add_ps(fjx0,tx);
717 fjy0 = _mm_add_ps(fjy0,ty);
718 fjz0 = _mm_add_ps(fjz0,tz);
722 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
723 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
724 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
725 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
727 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
729 /* Inner loop uses 165 flops */
732 /* End of innermost loop */
734 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
735 f+i_coord_offset,fshift+i_shift_offset);
738 /* Update potential energies */
739 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
740 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
742 /* Increment number of inner iterations */
743 inneriter += j_index_end - j_index_start;
745 /* Outer loop uses 26 flops */
748 /* Increment number of outer iterations */
751 /* Update outer/inner flops */
753 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*165);
756 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_sse4_1_single
757 * Electrostatics interaction: ReactionField
758 * VdW interaction: CubicSplineTable
759 * Geometry: Water4-Particle
760 * Calculate force/pot: Force
763 nb_kernel_ElecRFCut_VdwCSTab_GeomW4P1_F_sse4_1_single
764 (t_nblist * gmx_restrict nlist,
765 rvec * gmx_restrict xx,
766 rvec * gmx_restrict ff,
767 struct t_forcerec * gmx_restrict fr,
768 t_mdatoms * gmx_restrict mdatoms,
769 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
770 t_nrnb * gmx_restrict nrnb)
772 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
773 * just 0 for non-waters.
774 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
775 * jnr indices corresponding to data put in the four positions in the SIMD register.
777 int i_shift_offset,i_coord_offset,outeriter,inneriter;
778 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
779 int jnrA,jnrB,jnrC,jnrD;
780 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
781 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
782 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
784 real *shiftvec,*fshift,*x,*f;
785 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
787 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
789 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
791 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
793 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
795 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
796 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
797 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
798 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
799 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
800 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
801 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
802 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
805 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
808 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
809 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
811 __m128i ifour = _mm_set1_epi32(4);
812 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
814 __m128 dummy_mask,cutoff_mask;
815 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
816 __m128 one = _mm_set1_ps(1.0);
817 __m128 two = _mm_set1_ps(2.0);
823 jindex = nlist->jindex;
825 shiftidx = nlist->shift;
827 shiftvec = fr->shift_vec[0];
828 fshift = fr->fshift[0];
829 facel = _mm_set1_ps(fr->ic->epsfac);
830 charge = mdatoms->chargeA;
831 krf = _mm_set1_ps(fr->ic->k_rf);
832 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
833 crf = _mm_set1_ps(fr->ic->c_rf);
834 nvdwtype = fr->ntype;
836 vdwtype = mdatoms->typeA;
838 vftab = kernel_data->table_vdw->data;
839 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
841 /* Setup water-specific parameters */
842 inr = nlist->iinr[0];
843 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
844 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
845 iq3 = _mm_mul_ps(facel,_mm_set1_ps(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->ic->rcoulomb;
850 rcutoff = _mm_set1_ps(rcutoff_scalar);
851 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
853 /* Avoid stupid compiler warnings */
854 jnrA = jnrB = jnrC = jnrD = 0;
863 for(iidx=0;iidx<4*DIM;iidx++)
868 /* Start outer loop over neighborlists */
869 for(iidx=0; iidx<nri; iidx++)
871 /* Load shift vector for this list */
872 i_shift_offset = DIM*shiftidx[iidx];
874 /* Load limits for loop over neighbors */
875 j_index_start = jindex[iidx];
876 j_index_end = jindex[iidx+1];
878 /* Get outer coordinate index */
880 i_coord_offset = DIM*inr;
882 /* Load i particle coords and add shift vector */
883 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
884 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
886 fix0 = _mm_setzero_ps();
887 fiy0 = _mm_setzero_ps();
888 fiz0 = _mm_setzero_ps();
889 fix1 = _mm_setzero_ps();
890 fiy1 = _mm_setzero_ps();
891 fiz1 = _mm_setzero_ps();
892 fix2 = _mm_setzero_ps();
893 fiy2 = _mm_setzero_ps();
894 fiz2 = _mm_setzero_ps();
895 fix3 = _mm_setzero_ps();
896 fiy3 = _mm_setzero_ps();
897 fiz3 = _mm_setzero_ps();
899 /* Start inner kernel loop */
900 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
903 /* Get j neighbor index, and coordinate index */
908 j_coord_offsetA = DIM*jnrA;
909 j_coord_offsetB = DIM*jnrB;
910 j_coord_offsetC = DIM*jnrC;
911 j_coord_offsetD = DIM*jnrD;
913 /* load j atom coordinates */
914 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
915 x+j_coord_offsetC,x+j_coord_offsetD,
918 /* Calculate displacement vector */
919 dx00 = _mm_sub_ps(ix0,jx0);
920 dy00 = _mm_sub_ps(iy0,jy0);
921 dz00 = _mm_sub_ps(iz0,jz0);
922 dx10 = _mm_sub_ps(ix1,jx0);
923 dy10 = _mm_sub_ps(iy1,jy0);
924 dz10 = _mm_sub_ps(iz1,jz0);
925 dx20 = _mm_sub_ps(ix2,jx0);
926 dy20 = _mm_sub_ps(iy2,jy0);
927 dz20 = _mm_sub_ps(iz2,jz0);
928 dx30 = _mm_sub_ps(ix3,jx0);
929 dy30 = _mm_sub_ps(iy3,jy0);
930 dz30 = _mm_sub_ps(iz3,jz0);
932 /* Calculate squared distance and things based on it */
933 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
934 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
935 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
936 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
938 rinv00 = sse41_invsqrt_f(rsq00);
939 rinv10 = sse41_invsqrt_f(rsq10);
940 rinv20 = sse41_invsqrt_f(rsq20);
941 rinv30 = sse41_invsqrt_f(rsq30);
943 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
944 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
945 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
947 /* Load parameters for j particles */
948 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
949 charge+jnrC+0,charge+jnrD+0);
950 vdwjidx0A = 2*vdwtype[jnrA+0];
951 vdwjidx0B = 2*vdwtype[jnrB+0];
952 vdwjidx0C = 2*vdwtype[jnrC+0];
953 vdwjidx0D = 2*vdwtype[jnrD+0];
955 fjx0 = _mm_setzero_ps();
956 fjy0 = _mm_setzero_ps();
957 fjz0 = _mm_setzero_ps();
959 /**************************
960 * CALCULATE INTERACTIONS *
961 **************************/
963 r00 = _mm_mul_ps(rsq00,rinv00);
965 /* Compute parameters for interactions between i and j atoms */
966 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
967 vdwparam+vdwioffset0+vdwjidx0B,
968 vdwparam+vdwioffset0+vdwjidx0C,
969 vdwparam+vdwioffset0+vdwjidx0D,
972 /* Calculate table index by multiplying r with table scale and truncate to integer */
973 rt = _mm_mul_ps(r00,vftabscale);
974 vfitab = _mm_cvttps_epi32(rt);
975 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
976 vfitab = _mm_slli_epi32(vfitab,3);
978 /* CUBIC SPLINE TABLE DISPERSION */
979 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
980 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
981 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
982 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
983 _MM_TRANSPOSE4_PS(Y,F,G,H);
984 Heps = _mm_mul_ps(vfeps,H);
985 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
986 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
987 fvdw6 = _mm_mul_ps(c6_00,FF);
989 /* CUBIC SPLINE TABLE REPULSION */
990 vfitab = _mm_add_epi32(vfitab,ifour);
991 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
992 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
993 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
994 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
995 _MM_TRANSPOSE4_PS(Y,F,G,H);
996 Heps = _mm_mul_ps(vfeps,H);
997 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
998 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
999 fvdw12 = _mm_mul_ps(c12_00,FF);
1000 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1004 /* Calculate temporary vectorial force */
1005 tx = _mm_mul_ps(fscal,dx00);
1006 ty = _mm_mul_ps(fscal,dy00);
1007 tz = _mm_mul_ps(fscal,dz00);
1009 /* Update vectorial force */
1010 fix0 = _mm_add_ps(fix0,tx);
1011 fiy0 = _mm_add_ps(fiy0,ty);
1012 fiz0 = _mm_add_ps(fiz0,tz);
1014 fjx0 = _mm_add_ps(fjx0,tx);
1015 fjy0 = _mm_add_ps(fjy0,ty);
1016 fjz0 = _mm_add_ps(fjz0,tz);
1018 /**************************
1019 * CALCULATE INTERACTIONS *
1020 **************************/
1022 if (gmx_mm_any_lt(rsq10,rcutoff2))
1025 /* Compute parameters for interactions between i and j atoms */
1026 qq10 = _mm_mul_ps(iq1,jq0);
1028 /* REACTION-FIELD ELECTROSTATICS */
1029 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1031 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1035 fscal = _mm_and_ps(fscal,cutoff_mask);
1037 /* Calculate temporary vectorial force */
1038 tx = _mm_mul_ps(fscal,dx10);
1039 ty = _mm_mul_ps(fscal,dy10);
1040 tz = _mm_mul_ps(fscal,dz10);
1042 /* Update vectorial force */
1043 fix1 = _mm_add_ps(fix1,tx);
1044 fiy1 = _mm_add_ps(fiy1,ty);
1045 fiz1 = _mm_add_ps(fiz1,tz);
1047 fjx0 = _mm_add_ps(fjx0,tx);
1048 fjy0 = _mm_add_ps(fjy0,ty);
1049 fjz0 = _mm_add_ps(fjz0,tz);
1053 /**************************
1054 * CALCULATE INTERACTIONS *
1055 **************************/
1057 if (gmx_mm_any_lt(rsq20,rcutoff2))
1060 /* Compute parameters for interactions between i and j atoms */
1061 qq20 = _mm_mul_ps(iq2,jq0);
1063 /* REACTION-FIELD ELECTROSTATICS */
1064 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1066 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1070 fscal = _mm_and_ps(fscal,cutoff_mask);
1072 /* Calculate temporary vectorial force */
1073 tx = _mm_mul_ps(fscal,dx20);
1074 ty = _mm_mul_ps(fscal,dy20);
1075 tz = _mm_mul_ps(fscal,dz20);
1077 /* Update vectorial force */
1078 fix2 = _mm_add_ps(fix2,tx);
1079 fiy2 = _mm_add_ps(fiy2,ty);
1080 fiz2 = _mm_add_ps(fiz2,tz);
1082 fjx0 = _mm_add_ps(fjx0,tx);
1083 fjy0 = _mm_add_ps(fjy0,ty);
1084 fjz0 = _mm_add_ps(fjz0,tz);
1088 /**************************
1089 * CALCULATE INTERACTIONS *
1090 **************************/
1092 if (gmx_mm_any_lt(rsq30,rcutoff2))
1095 /* Compute parameters for interactions between i and j atoms */
1096 qq30 = _mm_mul_ps(iq3,jq0);
1098 /* REACTION-FIELD ELECTROSTATICS */
1099 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
1101 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1105 fscal = _mm_and_ps(fscal,cutoff_mask);
1107 /* Calculate temporary vectorial force */
1108 tx = _mm_mul_ps(fscal,dx30);
1109 ty = _mm_mul_ps(fscal,dy30);
1110 tz = _mm_mul_ps(fscal,dz30);
1112 /* Update vectorial force */
1113 fix3 = _mm_add_ps(fix3,tx);
1114 fiy3 = _mm_add_ps(fiy3,ty);
1115 fiz3 = _mm_add_ps(fiz3,tz);
1117 fjx0 = _mm_add_ps(fjx0,tx);
1118 fjy0 = _mm_add_ps(fjy0,ty);
1119 fjz0 = _mm_add_ps(fjz0,tz);
1123 fjptrA = f+j_coord_offsetA;
1124 fjptrB = f+j_coord_offsetB;
1125 fjptrC = f+j_coord_offsetC;
1126 fjptrD = f+j_coord_offsetD;
1128 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1130 /* Inner loop uses 138 flops */
1133 if(jidx<j_index_end)
1136 /* Get j neighbor index, and coordinate index */
1137 jnrlistA = jjnr[jidx];
1138 jnrlistB = jjnr[jidx+1];
1139 jnrlistC = jjnr[jidx+2];
1140 jnrlistD = jjnr[jidx+3];
1141 /* Sign of each element will be negative for non-real atoms.
1142 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1143 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1145 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1146 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1147 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1148 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1149 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1150 j_coord_offsetA = DIM*jnrA;
1151 j_coord_offsetB = DIM*jnrB;
1152 j_coord_offsetC = DIM*jnrC;
1153 j_coord_offsetD = DIM*jnrD;
1155 /* load j atom coordinates */
1156 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1157 x+j_coord_offsetC,x+j_coord_offsetD,
1160 /* Calculate displacement vector */
1161 dx00 = _mm_sub_ps(ix0,jx0);
1162 dy00 = _mm_sub_ps(iy0,jy0);
1163 dz00 = _mm_sub_ps(iz0,jz0);
1164 dx10 = _mm_sub_ps(ix1,jx0);
1165 dy10 = _mm_sub_ps(iy1,jy0);
1166 dz10 = _mm_sub_ps(iz1,jz0);
1167 dx20 = _mm_sub_ps(ix2,jx0);
1168 dy20 = _mm_sub_ps(iy2,jy0);
1169 dz20 = _mm_sub_ps(iz2,jz0);
1170 dx30 = _mm_sub_ps(ix3,jx0);
1171 dy30 = _mm_sub_ps(iy3,jy0);
1172 dz30 = _mm_sub_ps(iz3,jz0);
1174 /* Calculate squared distance and things based on it */
1175 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1176 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1177 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1178 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1180 rinv00 = sse41_invsqrt_f(rsq00);
1181 rinv10 = sse41_invsqrt_f(rsq10);
1182 rinv20 = sse41_invsqrt_f(rsq20);
1183 rinv30 = sse41_invsqrt_f(rsq30);
1185 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1186 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1187 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
1189 /* Load parameters for j particles */
1190 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1191 charge+jnrC+0,charge+jnrD+0);
1192 vdwjidx0A = 2*vdwtype[jnrA+0];
1193 vdwjidx0B = 2*vdwtype[jnrB+0];
1194 vdwjidx0C = 2*vdwtype[jnrC+0];
1195 vdwjidx0D = 2*vdwtype[jnrD+0];
1197 fjx0 = _mm_setzero_ps();
1198 fjy0 = _mm_setzero_ps();
1199 fjz0 = _mm_setzero_ps();
1201 /**************************
1202 * CALCULATE INTERACTIONS *
1203 **************************/
1205 r00 = _mm_mul_ps(rsq00,rinv00);
1206 r00 = _mm_andnot_ps(dummy_mask,r00);
1208 /* Compute parameters for interactions between i and j atoms */
1209 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1210 vdwparam+vdwioffset0+vdwjidx0B,
1211 vdwparam+vdwioffset0+vdwjidx0C,
1212 vdwparam+vdwioffset0+vdwjidx0D,
1215 /* Calculate table index by multiplying r with table scale and truncate to integer */
1216 rt = _mm_mul_ps(r00,vftabscale);
1217 vfitab = _mm_cvttps_epi32(rt);
1218 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1219 vfitab = _mm_slli_epi32(vfitab,3);
1221 /* CUBIC SPLINE TABLE DISPERSION */
1222 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1223 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1224 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1225 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1226 _MM_TRANSPOSE4_PS(Y,F,G,H);
1227 Heps = _mm_mul_ps(vfeps,H);
1228 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1229 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1230 fvdw6 = _mm_mul_ps(c6_00,FF);
1232 /* CUBIC SPLINE TABLE REPULSION */
1233 vfitab = _mm_add_epi32(vfitab,ifour);
1234 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1235 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1236 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1237 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1238 _MM_TRANSPOSE4_PS(Y,F,G,H);
1239 Heps = _mm_mul_ps(vfeps,H);
1240 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1241 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1242 fvdw12 = _mm_mul_ps(c12_00,FF);
1243 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1247 fscal = _mm_andnot_ps(dummy_mask,fscal);
1249 /* Calculate temporary vectorial force */
1250 tx = _mm_mul_ps(fscal,dx00);
1251 ty = _mm_mul_ps(fscal,dy00);
1252 tz = _mm_mul_ps(fscal,dz00);
1254 /* Update vectorial force */
1255 fix0 = _mm_add_ps(fix0,tx);
1256 fiy0 = _mm_add_ps(fiy0,ty);
1257 fiz0 = _mm_add_ps(fiz0,tz);
1259 fjx0 = _mm_add_ps(fjx0,tx);
1260 fjy0 = _mm_add_ps(fjy0,ty);
1261 fjz0 = _mm_add_ps(fjz0,tz);
1263 /**************************
1264 * CALCULATE INTERACTIONS *
1265 **************************/
1267 if (gmx_mm_any_lt(rsq10,rcutoff2))
1270 /* Compute parameters for interactions between i and j atoms */
1271 qq10 = _mm_mul_ps(iq1,jq0);
1273 /* REACTION-FIELD ELECTROSTATICS */
1274 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1276 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1280 fscal = _mm_and_ps(fscal,cutoff_mask);
1282 fscal = _mm_andnot_ps(dummy_mask,fscal);
1284 /* Calculate temporary vectorial force */
1285 tx = _mm_mul_ps(fscal,dx10);
1286 ty = _mm_mul_ps(fscal,dy10);
1287 tz = _mm_mul_ps(fscal,dz10);
1289 /* Update vectorial force */
1290 fix1 = _mm_add_ps(fix1,tx);
1291 fiy1 = _mm_add_ps(fiy1,ty);
1292 fiz1 = _mm_add_ps(fiz1,tz);
1294 fjx0 = _mm_add_ps(fjx0,tx);
1295 fjy0 = _mm_add_ps(fjy0,ty);
1296 fjz0 = _mm_add_ps(fjz0,tz);
1300 /**************************
1301 * CALCULATE INTERACTIONS *
1302 **************************/
1304 if (gmx_mm_any_lt(rsq20,rcutoff2))
1307 /* Compute parameters for interactions between i and j atoms */
1308 qq20 = _mm_mul_ps(iq2,jq0);
1310 /* REACTION-FIELD ELECTROSTATICS */
1311 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1313 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1317 fscal = _mm_and_ps(fscal,cutoff_mask);
1319 fscal = _mm_andnot_ps(dummy_mask,fscal);
1321 /* Calculate temporary vectorial force */
1322 tx = _mm_mul_ps(fscal,dx20);
1323 ty = _mm_mul_ps(fscal,dy20);
1324 tz = _mm_mul_ps(fscal,dz20);
1326 /* Update vectorial force */
1327 fix2 = _mm_add_ps(fix2,tx);
1328 fiy2 = _mm_add_ps(fiy2,ty);
1329 fiz2 = _mm_add_ps(fiz2,tz);
1331 fjx0 = _mm_add_ps(fjx0,tx);
1332 fjy0 = _mm_add_ps(fjy0,ty);
1333 fjz0 = _mm_add_ps(fjz0,tz);
1337 /**************************
1338 * CALCULATE INTERACTIONS *
1339 **************************/
1341 if (gmx_mm_any_lt(rsq30,rcutoff2))
1344 /* Compute parameters for interactions between i and j atoms */
1345 qq30 = _mm_mul_ps(iq3,jq0);
1347 /* REACTION-FIELD ELECTROSTATICS */
1348 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
1350 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1354 fscal = _mm_and_ps(fscal,cutoff_mask);
1356 fscal = _mm_andnot_ps(dummy_mask,fscal);
1358 /* Calculate temporary vectorial force */
1359 tx = _mm_mul_ps(fscal,dx30);
1360 ty = _mm_mul_ps(fscal,dy30);
1361 tz = _mm_mul_ps(fscal,dz30);
1363 /* Update vectorial force */
1364 fix3 = _mm_add_ps(fix3,tx);
1365 fiy3 = _mm_add_ps(fiy3,ty);
1366 fiz3 = _mm_add_ps(fiz3,tz);
1368 fjx0 = _mm_add_ps(fjx0,tx);
1369 fjy0 = _mm_add_ps(fjy0,ty);
1370 fjz0 = _mm_add_ps(fjz0,tz);
1374 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1375 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1376 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1377 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1379 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1381 /* Inner loop uses 139 flops */
1384 /* End of innermost loop */
1386 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1387 f+i_coord_offset,fshift+i_shift_offset);
1389 /* Increment number of inner iterations */
1390 inneriter += j_index_end - j_index_start;
1392 /* Outer loop uses 24 flops */
1395 /* Increment number of outer iterations */
1398 /* Update outer/inner flops */
1400 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*139);