2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 avx_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gmx_math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwCSTab_GeomW4W4_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water4-Water4
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRF_VdwCSTab_GeomW4W4_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
92 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
96 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
97 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
98 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
99 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
100 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
101 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
102 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
103 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
104 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
105 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
106 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
107 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
108 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
109 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
110 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
111 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
114 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
117 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
118 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
120 __m128i ifour = _mm_set1_epi32(4);
121 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
123 __m128 dummy_mask,cutoff_mask;
124 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
125 __m128 one = _mm_set1_ps(1.0);
126 __m128 two = _mm_set1_ps(2.0);
132 jindex = nlist->jindex;
134 shiftidx = nlist->shift;
136 shiftvec = fr->shift_vec[0];
137 fshift = fr->fshift[0];
138 facel = _mm_set1_ps(fr->epsfac);
139 charge = mdatoms->chargeA;
140 krf = _mm_set1_ps(fr->ic->k_rf);
141 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
142 crf = _mm_set1_ps(fr->ic->c_rf);
143 nvdwtype = fr->ntype;
145 vdwtype = mdatoms->typeA;
147 vftab = kernel_data->table_vdw->data;
148 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
150 /* Setup water-specific parameters */
151 inr = nlist->iinr[0];
152 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
153 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
154 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
155 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
157 jq1 = _mm_set1_ps(charge[inr+1]);
158 jq2 = _mm_set1_ps(charge[inr+2]);
159 jq3 = _mm_set1_ps(charge[inr+3]);
160 vdwjidx0A = 2*vdwtype[inr+0];
161 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
162 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
163 qq11 = _mm_mul_ps(iq1,jq1);
164 qq12 = _mm_mul_ps(iq1,jq2);
165 qq13 = _mm_mul_ps(iq1,jq3);
166 qq21 = _mm_mul_ps(iq2,jq1);
167 qq22 = _mm_mul_ps(iq2,jq2);
168 qq23 = _mm_mul_ps(iq2,jq3);
169 qq31 = _mm_mul_ps(iq3,jq1);
170 qq32 = _mm_mul_ps(iq3,jq2);
171 qq33 = _mm_mul_ps(iq3,jq3);
173 /* Avoid stupid compiler warnings */
174 jnrA = jnrB = jnrC = jnrD = 0;
183 for(iidx=0;iidx<4*DIM;iidx++)
188 /* Start outer loop over neighborlists */
189 for(iidx=0; iidx<nri; iidx++)
191 /* Load shift vector for this list */
192 i_shift_offset = DIM*shiftidx[iidx];
194 /* Load limits for loop over neighbors */
195 j_index_start = jindex[iidx];
196 j_index_end = jindex[iidx+1];
198 /* Get outer coordinate index */
200 i_coord_offset = DIM*inr;
202 /* Load i particle coords and add shift vector */
203 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
204 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
206 fix0 = _mm_setzero_ps();
207 fiy0 = _mm_setzero_ps();
208 fiz0 = _mm_setzero_ps();
209 fix1 = _mm_setzero_ps();
210 fiy1 = _mm_setzero_ps();
211 fiz1 = _mm_setzero_ps();
212 fix2 = _mm_setzero_ps();
213 fiy2 = _mm_setzero_ps();
214 fiz2 = _mm_setzero_ps();
215 fix3 = _mm_setzero_ps();
216 fiy3 = _mm_setzero_ps();
217 fiz3 = _mm_setzero_ps();
219 /* Reset potential sums */
220 velecsum = _mm_setzero_ps();
221 vvdwsum = _mm_setzero_ps();
223 /* Start inner kernel loop */
224 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
227 /* Get j neighbor index, and coordinate index */
232 j_coord_offsetA = DIM*jnrA;
233 j_coord_offsetB = DIM*jnrB;
234 j_coord_offsetC = DIM*jnrC;
235 j_coord_offsetD = DIM*jnrD;
237 /* load j atom coordinates */
238 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
239 x+j_coord_offsetC,x+j_coord_offsetD,
240 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
241 &jy2,&jz2,&jx3,&jy3,&jz3);
243 /* Calculate displacement vector */
244 dx00 = _mm_sub_ps(ix0,jx0);
245 dy00 = _mm_sub_ps(iy0,jy0);
246 dz00 = _mm_sub_ps(iz0,jz0);
247 dx11 = _mm_sub_ps(ix1,jx1);
248 dy11 = _mm_sub_ps(iy1,jy1);
249 dz11 = _mm_sub_ps(iz1,jz1);
250 dx12 = _mm_sub_ps(ix1,jx2);
251 dy12 = _mm_sub_ps(iy1,jy2);
252 dz12 = _mm_sub_ps(iz1,jz2);
253 dx13 = _mm_sub_ps(ix1,jx3);
254 dy13 = _mm_sub_ps(iy1,jy3);
255 dz13 = _mm_sub_ps(iz1,jz3);
256 dx21 = _mm_sub_ps(ix2,jx1);
257 dy21 = _mm_sub_ps(iy2,jy1);
258 dz21 = _mm_sub_ps(iz2,jz1);
259 dx22 = _mm_sub_ps(ix2,jx2);
260 dy22 = _mm_sub_ps(iy2,jy2);
261 dz22 = _mm_sub_ps(iz2,jz2);
262 dx23 = _mm_sub_ps(ix2,jx3);
263 dy23 = _mm_sub_ps(iy2,jy3);
264 dz23 = _mm_sub_ps(iz2,jz3);
265 dx31 = _mm_sub_ps(ix3,jx1);
266 dy31 = _mm_sub_ps(iy3,jy1);
267 dz31 = _mm_sub_ps(iz3,jz1);
268 dx32 = _mm_sub_ps(ix3,jx2);
269 dy32 = _mm_sub_ps(iy3,jy2);
270 dz32 = _mm_sub_ps(iz3,jz2);
271 dx33 = _mm_sub_ps(ix3,jx3);
272 dy33 = _mm_sub_ps(iy3,jy3);
273 dz33 = _mm_sub_ps(iz3,jz3);
275 /* Calculate squared distance and things based on it */
276 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
277 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
278 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
279 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
280 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
281 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
282 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
283 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
284 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
285 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
287 rinv00 = gmx_mm_invsqrt_ps(rsq00);
288 rinv11 = gmx_mm_invsqrt_ps(rsq11);
289 rinv12 = gmx_mm_invsqrt_ps(rsq12);
290 rinv13 = gmx_mm_invsqrt_ps(rsq13);
291 rinv21 = gmx_mm_invsqrt_ps(rsq21);
292 rinv22 = gmx_mm_invsqrt_ps(rsq22);
293 rinv23 = gmx_mm_invsqrt_ps(rsq23);
294 rinv31 = gmx_mm_invsqrt_ps(rsq31);
295 rinv32 = gmx_mm_invsqrt_ps(rsq32);
296 rinv33 = gmx_mm_invsqrt_ps(rsq33);
298 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
299 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
300 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
301 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
302 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
303 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
304 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
305 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
306 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
308 fjx0 = _mm_setzero_ps();
309 fjy0 = _mm_setzero_ps();
310 fjz0 = _mm_setzero_ps();
311 fjx1 = _mm_setzero_ps();
312 fjy1 = _mm_setzero_ps();
313 fjz1 = _mm_setzero_ps();
314 fjx2 = _mm_setzero_ps();
315 fjy2 = _mm_setzero_ps();
316 fjz2 = _mm_setzero_ps();
317 fjx3 = _mm_setzero_ps();
318 fjy3 = _mm_setzero_ps();
319 fjz3 = _mm_setzero_ps();
321 /**************************
322 * CALCULATE INTERACTIONS *
323 **************************/
325 r00 = _mm_mul_ps(rsq00,rinv00);
327 /* Calculate table index by multiplying r with table scale and truncate to integer */
328 rt = _mm_mul_ps(r00,vftabscale);
329 vfitab = _mm_cvttps_epi32(rt);
331 vfeps = _mm_frcz_ps(rt);
333 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
335 twovfeps = _mm_add_ps(vfeps,vfeps);
336 vfitab = _mm_slli_epi32(vfitab,3);
338 /* CUBIC SPLINE TABLE DISPERSION */
339 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
340 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
341 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
342 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
343 _MM_TRANSPOSE4_PS(Y,F,G,H);
344 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
345 VV = _mm_macc_ps(vfeps,Fp,Y);
346 vvdw6 = _mm_mul_ps(c6_00,VV);
347 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
348 fvdw6 = _mm_mul_ps(c6_00,FF);
350 /* CUBIC SPLINE TABLE REPULSION */
351 vfitab = _mm_add_epi32(vfitab,ifour);
352 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
353 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
354 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
355 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
356 _MM_TRANSPOSE4_PS(Y,F,G,H);
357 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
358 VV = _mm_macc_ps(vfeps,Fp,Y);
359 vvdw12 = _mm_mul_ps(c12_00,VV);
360 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
361 fvdw12 = _mm_mul_ps(c12_00,FF);
362 vvdw = _mm_add_ps(vvdw12,vvdw6);
363 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
365 /* Update potential sum for this i atom from the interaction with this j atom. */
366 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
370 /* Update vectorial force */
371 fix0 = _mm_macc_ps(dx00,fscal,fix0);
372 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
373 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
375 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
376 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
377 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
379 /**************************
380 * CALCULATE INTERACTIONS *
381 **************************/
383 /* REACTION-FIELD ELECTROSTATICS */
384 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
385 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
387 /* Update potential sum for this i atom from the interaction with this j atom. */
388 velecsum = _mm_add_ps(velecsum,velec);
392 /* Update vectorial force */
393 fix1 = _mm_macc_ps(dx11,fscal,fix1);
394 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
395 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
397 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
398 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
399 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
401 /**************************
402 * CALCULATE INTERACTIONS *
403 **************************/
405 /* REACTION-FIELD ELECTROSTATICS */
406 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
407 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
409 /* Update potential sum for this i atom from the interaction with this j atom. */
410 velecsum = _mm_add_ps(velecsum,velec);
414 /* Update vectorial force */
415 fix1 = _mm_macc_ps(dx12,fscal,fix1);
416 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
417 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
419 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
420 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
421 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
423 /**************************
424 * CALCULATE INTERACTIONS *
425 **************************/
427 /* REACTION-FIELD ELECTROSTATICS */
428 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
429 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
431 /* Update potential sum for this i atom from the interaction with this j atom. */
432 velecsum = _mm_add_ps(velecsum,velec);
436 /* Update vectorial force */
437 fix1 = _mm_macc_ps(dx13,fscal,fix1);
438 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
439 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
441 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
442 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
443 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
445 /**************************
446 * CALCULATE INTERACTIONS *
447 **************************/
449 /* REACTION-FIELD ELECTROSTATICS */
450 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
451 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
453 /* Update potential sum for this i atom from the interaction with this j atom. */
454 velecsum = _mm_add_ps(velecsum,velec);
458 /* Update vectorial force */
459 fix2 = _mm_macc_ps(dx21,fscal,fix2);
460 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
461 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
463 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
464 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
465 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
467 /**************************
468 * CALCULATE INTERACTIONS *
469 **************************/
471 /* REACTION-FIELD ELECTROSTATICS */
472 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
473 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
475 /* Update potential sum for this i atom from the interaction with this j atom. */
476 velecsum = _mm_add_ps(velecsum,velec);
480 /* Update vectorial force */
481 fix2 = _mm_macc_ps(dx22,fscal,fix2);
482 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
483 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
485 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
486 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
487 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
489 /**************************
490 * CALCULATE INTERACTIONS *
491 **************************/
493 /* REACTION-FIELD ELECTROSTATICS */
494 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
495 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
497 /* Update potential sum for this i atom from the interaction with this j atom. */
498 velecsum = _mm_add_ps(velecsum,velec);
502 /* Update vectorial force */
503 fix2 = _mm_macc_ps(dx23,fscal,fix2);
504 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
505 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
507 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
508 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
509 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
511 /**************************
512 * CALCULATE INTERACTIONS *
513 **************************/
515 /* REACTION-FIELD ELECTROSTATICS */
516 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
517 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
519 /* Update potential sum for this i atom from the interaction with this j atom. */
520 velecsum = _mm_add_ps(velecsum,velec);
524 /* Update vectorial force */
525 fix3 = _mm_macc_ps(dx31,fscal,fix3);
526 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
527 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
529 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
530 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
531 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
533 /**************************
534 * CALCULATE INTERACTIONS *
535 **************************/
537 /* REACTION-FIELD ELECTROSTATICS */
538 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
539 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
541 /* Update potential sum for this i atom from the interaction with this j atom. */
542 velecsum = _mm_add_ps(velecsum,velec);
546 /* Update vectorial force */
547 fix3 = _mm_macc_ps(dx32,fscal,fix3);
548 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
549 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
551 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
552 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
553 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
555 /**************************
556 * CALCULATE INTERACTIONS *
557 **************************/
559 /* REACTION-FIELD ELECTROSTATICS */
560 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
561 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
563 /* Update potential sum for this i atom from the interaction with this j atom. */
564 velecsum = _mm_add_ps(velecsum,velec);
568 /* Update vectorial force */
569 fix3 = _mm_macc_ps(dx33,fscal,fix3);
570 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
571 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
573 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
574 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
575 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
577 fjptrA = f+j_coord_offsetA;
578 fjptrB = f+j_coord_offsetB;
579 fjptrC = f+j_coord_offsetC;
580 fjptrD = f+j_coord_offsetD;
582 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
583 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
584 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
586 /* Inner loop uses 377 flops */
592 /* Get j neighbor index, and coordinate index */
593 jnrlistA = jjnr[jidx];
594 jnrlistB = jjnr[jidx+1];
595 jnrlistC = jjnr[jidx+2];
596 jnrlistD = jjnr[jidx+3];
597 /* Sign of each element will be negative for non-real atoms.
598 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
599 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
601 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
602 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
603 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
604 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
605 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
606 j_coord_offsetA = DIM*jnrA;
607 j_coord_offsetB = DIM*jnrB;
608 j_coord_offsetC = DIM*jnrC;
609 j_coord_offsetD = DIM*jnrD;
611 /* load j atom coordinates */
612 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
613 x+j_coord_offsetC,x+j_coord_offsetD,
614 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
615 &jy2,&jz2,&jx3,&jy3,&jz3);
617 /* Calculate displacement vector */
618 dx00 = _mm_sub_ps(ix0,jx0);
619 dy00 = _mm_sub_ps(iy0,jy0);
620 dz00 = _mm_sub_ps(iz0,jz0);
621 dx11 = _mm_sub_ps(ix1,jx1);
622 dy11 = _mm_sub_ps(iy1,jy1);
623 dz11 = _mm_sub_ps(iz1,jz1);
624 dx12 = _mm_sub_ps(ix1,jx2);
625 dy12 = _mm_sub_ps(iy1,jy2);
626 dz12 = _mm_sub_ps(iz1,jz2);
627 dx13 = _mm_sub_ps(ix1,jx3);
628 dy13 = _mm_sub_ps(iy1,jy3);
629 dz13 = _mm_sub_ps(iz1,jz3);
630 dx21 = _mm_sub_ps(ix2,jx1);
631 dy21 = _mm_sub_ps(iy2,jy1);
632 dz21 = _mm_sub_ps(iz2,jz1);
633 dx22 = _mm_sub_ps(ix2,jx2);
634 dy22 = _mm_sub_ps(iy2,jy2);
635 dz22 = _mm_sub_ps(iz2,jz2);
636 dx23 = _mm_sub_ps(ix2,jx3);
637 dy23 = _mm_sub_ps(iy2,jy3);
638 dz23 = _mm_sub_ps(iz2,jz3);
639 dx31 = _mm_sub_ps(ix3,jx1);
640 dy31 = _mm_sub_ps(iy3,jy1);
641 dz31 = _mm_sub_ps(iz3,jz1);
642 dx32 = _mm_sub_ps(ix3,jx2);
643 dy32 = _mm_sub_ps(iy3,jy2);
644 dz32 = _mm_sub_ps(iz3,jz2);
645 dx33 = _mm_sub_ps(ix3,jx3);
646 dy33 = _mm_sub_ps(iy3,jy3);
647 dz33 = _mm_sub_ps(iz3,jz3);
649 /* Calculate squared distance and things based on it */
650 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
651 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
652 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
653 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
654 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
655 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
656 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
657 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
658 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
659 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
661 rinv00 = gmx_mm_invsqrt_ps(rsq00);
662 rinv11 = gmx_mm_invsqrt_ps(rsq11);
663 rinv12 = gmx_mm_invsqrt_ps(rsq12);
664 rinv13 = gmx_mm_invsqrt_ps(rsq13);
665 rinv21 = gmx_mm_invsqrt_ps(rsq21);
666 rinv22 = gmx_mm_invsqrt_ps(rsq22);
667 rinv23 = gmx_mm_invsqrt_ps(rsq23);
668 rinv31 = gmx_mm_invsqrt_ps(rsq31);
669 rinv32 = gmx_mm_invsqrt_ps(rsq32);
670 rinv33 = gmx_mm_invsqrt_ps(rsq33);
672 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
673 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
674 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
675 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
676 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
677 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
678 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
679 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
680 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
682 fjx0 = _mm_setzero_ps();
683 fjy0 = _mm_setzero_ps();
684 fjz0 = _mm_setzero_ps();
685 fjx1 = _mm_setzero_ps();
686 fjy1 = _mm_setzero_ps();
687 fjz1 = _mm_setzero_ps();
688 fjx2 = _mm_setzero_ps();
689 fjy2 = _mm_setzero_ps();
690 fjz2 = _mm_setzero_ps();
691 fjx3 = _mm_setzero_ps();
692 fjy3 = _mm_setzero_ps();
693 fjz3 = _mm_setzero_ps();
695 /**************************
696 * CALCULATE INTERACTIONS *
697 **************************/
699 r00 = _mm_mul_ps(rsq00,rinv00);
700 r00 = _mm_andnot_ps(dummy_mask,r00);
702 /* Calculate table index by multiplying r with table scale and truncate to integer */
703 rt = _mm_mul_ps(r00,vftabscale);
704 vfitab = _mm_cvttps_epi32(rt);
706 vfeps = _mm_frcz_ps(rt);
708 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
710 twovfeps = _mm_add_ps(vfeps,vfeps);
711 vfitab = _mm_slli_epi32(vfitab,3);
713 /* CUBIC SPLINE TABLE DISPERSION */
714 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
715 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
716 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
717 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
718 _MM_TRANSPOSE4_PS(Y,F,G,H);
719 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
720 VV = _mm_macc_ps(vfeps,Fp,Y);
721 vvdw6 = _mm_mul_ps(c6_00,VV);
722 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
723 fvdw6 = _mm_mul_ps(c6_00,FF);
725 /* CUBIC SPLINE TABLE REPULSION */
726 vfitab = _mm_add_epi32(vfitab,ifour);
727 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
728 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
729 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
730 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
731 _MM_TRANSPOSE4_PS(Y,F,G,H);
732 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
733 VV = _mm_macc_ps(vfeps,Fp,Y);
734 vvdw12 = _mm_mul_ps(c12_00,VV);
735 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
736 fvdw12 = _mm_mul_ps(c12_00,FF);
737 vvdw = _mm_add_ps(vvdw12,vvdw6);
738 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
740 /* Update potential sum for this i atom from the interaction with this j atom. */
741 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
742 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
746 fscal = _mm_andnot_ps(dummy_mask,fscal);
748 /* Update vectorial force */
749 fix0 = _mm_macc_ps(dx00,fscal,fix0);
750 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
751 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
753 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
754 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
755 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
757 /**************************
758 * CALCULATE INTERACTIONS *
759 **************************/
761 /* REACTION-FIELD ELECTROSTATICS */
762 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
763 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
765 /* Update potential sum for this i atom from the interaction with this j atom. */
766 velec = _mm_andnot_ps(dummy_mask,velec);
767 velecsum = _mm_add_ps(velecsum,velec);
771 fscal = _mm_andnot_ps(dummy_mask,fscal);
773 /* Update vectorial force */
774 fix1 = _mm_macc_ps(dx11,fscal,fix1);
775 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
776 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
778 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
779 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
780 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
782 /**************************
783 * CALCULATE INTERACTIONS *
784 **************************/
786 /* REACTION-FIELD ELECTROSTATICS */
787 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
788 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
790 /* Update potential sum for this i atom from the interaction with this j atom. */
791 velec = _mm_andnot_ps(dummy_mask,velec);
792 velecsum = _mm_add_ps(velecsum,velec);
796 fscal = _mm_andnot_ps(dummy_mask,fscal);
798 /* Update vectorial force */
799 fix1 = _mm_macc_ps(dx12,fscal,fix1);
800 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
801 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
803 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
804 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
805 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
807 /**************************
808 * CALCULATE INTERACTIONS *
809 **************************/
811 /* REACTION-FIELD ELECTROSTATICS */
812 velec = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
813 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
815 /* Update potential sum for this i atom from the interaction with this j atom. */
816 velec = _mm_andnot_ps(dummy_mask,velec);
817 velecsum = _mm_add_ps(velecsum,velec);
821 fscal = _mm_andnot_ps(dummy_mask,fscal);
823 /* Update vectorial force */
824 fix1 = _mm_macc_ps(dx13,fscal,fix1);
825 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
826 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
828 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
829 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
830 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
832 /**************************
833 * CALCULATE INTERACTIONS *
834 **************************/
836 /* REACTION-FIELD ELECTROSTATICS */
837 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
838 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
840 /* Update potential sum for this i atom from the interaction with this j atom. */
841 velec = _mm_andnot_ps(dummy_mask,velec);
842 velecsum = _mm_add_ps(velecsum,velec);
846 fscal = _mm_andnot_ps(dummy_mask,fscal);
848 /* Update vectorial force */
849 fix2 = _mm_macc_ps(dx21,fscal,fix2);
850 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
851 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
853 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
854 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
855 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
857 /**************************
858 * CALCULATE INTERACTIONS *
859 **************************/
861 /* REACTION-FIELD ELECTROSTATICS */
862 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
863 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
865 /* Update potential sum for this i atom from the interaction with this j atom. */
866 velec = _mm_andnot_ps(dummy_mask,velec);
867 velecsum = _mm_add_ps(velecsum,velec);
871 fscal = _mm_andnot_ps(dummy_mask,fscal);
873 /* Update vectorial force */
874 fix2 = _mm_macc_ps(dx22,fscal,fix2);
875 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
876 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
878 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
879 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
880 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
882 /**************************
883 * CALCULATE INTERACTIONS *
884 **************************/
886 /* REACTION-FIELD ELECTROSTATICS */
887 velec = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
888 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
890 /* Update potential sum for this i atom from the interaction with this j atom. */
891 velec = _mm_andnot_ps(dummy_mask,velec);
892 velecsum = _mm_add_ps(velecsum,velec);
896 fscal = _mm_andnot_ps(dummy_mask,fscal);
898 /* Update vectorial force */
899 fix2 = _mm_macc_ps(dx23,fscal,fix2);
900 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
901 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
903 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
904 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
905 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
907 /**************************
908 * CALCULATE INTERACTIONS *
909 **************************/
911 /* REACTION-FIELD ELECTROSTATICS */
912 velec = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
913 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
915 /* Update potential sum for this i atom from the interaction with this j atom. */
916 velec = _mm_andnot_ps(dummy_mask,velec);
917 velecsum = _mm_add_ps(velecsum,velec);
921 fscal = _mm_andnot_ps(dummy_mask,fscal);
923 /* Update vectorial force */
924 fix3 = _mm_macc_ps(dx31,fscal,fix3);
925 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
926 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
928 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
929 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
930 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
932 /**************************
933 * CALCULATE INTERACTIONS *
934 **************************/
936 /* REACTION-FIELD ELECTROSTATICS */
937 velec = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
938 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
940 /* Update potential sum for this i atom from the interaction with this j atom. */
941 velec = _mm_andnot_ps(dummy_mask,velec);
942 velecsum = _mm_add_ps(velecsum,velec);
946 fscal = _mm_andnot_ps(dummy_mask,fscal);
948 /* Update vectorial force */
949 fix3 = _mm_macc_ps(dx32,fscal,fix3);
950 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
951 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
953 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
954 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
955 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
957 /**************************
958 * CALCULATE INTERACTIONS *
959 **************************/
961 /* REACTION-FIELD ELECTROSTATICS */
962 velec = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
963 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
965 /* Update potential sum for this i atom from the interaction with this j atom. */
966 velec = _mm_andnot_ps(dummy_mask,velec);
967 velecsum = _mm_add_ps(velecsum,velec);
971 fscal = _mm_andnot_ps(dummy_mask,fscal);
973 /* Update vectorial force */
974 fix3 = _mm_macc_ps(dx33,fscal,fix3);
975 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
976 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
978 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
979 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
980 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
982 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
983 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
984 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
985 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
987 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
988 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
989 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
991 /* Inner loop uses 378 flops */
994 /* End of innermost loop */
996 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
997 f+i_coord_offset,fshift+i_shift_offset);
1000 /* Update potential energies */
1001 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1002 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1004 /* Increment number of inner iterations */
1005 inneriter += j_index_end - j_index_start;
1007 /* Outer loop uses 26 flops */
1010 /* Increment number of outer iterations */
1013 /* Update outer/inner flops */
1015 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*378);
1018 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwCSTab_GeomW4W4_F_avx_128_fma_single
1019 * Electrostatics interaction: ReactionField
1020 * VdW interaction: CubicSplineTable
1021 * Geometry: Water4-Water4
1022 * Calculate force/pot: Force
1025 nb_kernel_ElecRF_VdwCSTab_GeomW4W4_F_avx_128_fma_single
1026 (t_nblist * gmx_restrict nlist,
1027 rvec * gmx_restrict xx,
1028 rvec * gmx_restrict ff,
1029 t_forcerec * gmx_restrict fr,
1030 t_mdatoms * gmx_restrict mdatoms,
1031 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1032 t_nrnb * gmx_restrict nrnb)
1034 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1035 * just 0 for non-waters.
1036 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1037 * jnr indices corresponding to data put in the four positions in the SIMD register.
1039 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1040 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1041 int jnrA,jnrB,jnrC,jnrD;
1042 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1043 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1044 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1045 real rcutoff_scalar;
1046 real *shiftvec,*fshift,*x,*f;
1047 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1048 real scratch[4*DIM];
1049 __m128 fscal,rcutoff,rcutoff2,jidxall;
1051 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1053 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1055 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1057 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
1058 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1059 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1060 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1061 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1062 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1063 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1064 int vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
1065 __m128 jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
1066 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1067 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1068 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1069 __m128 dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
1070 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1071 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1072 __m128 dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
1073 __m128 dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
1074 __m128 dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
1075 __m128 dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
1076 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1079 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1082 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1083 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1085 __m128i ifour = _mm_set1_epi32(4);
1086 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
1088 __m128 dummy_mask,cutoff_mask;
1089 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1090 __m128 one = _mm_set1_ps(1.0);
1091 __m128 two = _mm_set1_ps(2.0);
1097 jindex = nlist->jindex;
1099 shiftidx = nlist->shift;
1101 shiftvec = fr->shift_vec[0];
1102 fshift = fr->fshift[0];
1103 facel = _mm_set1_ps(fr->epsfac);
1104 charge = mdatoms->chargeA;
1105 krf = _mm_set1_ps(fr->ic->k_rf);
1106 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1107 crf = _mm_set1_ps(fr->ic->c_rf);
1108 nvdwtype = fr->ntype;
1109 vdwparam = fr->nbfp;
1110 vdwtype = mdatoms->typeA;
1112 vftab = kernel_data->table_vdw->data;
1113 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
1115 /* Setup water-specific parameters */
1116 inr = nlist->iinr[0];
1117 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1118 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1119 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
1120 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1122 jq1 = _mm_set1_ps(charge[inr+1]);
1123 jq2 = _mm_set1_ps(charge[inr+2]);
1124 jq3 = _mm_set1_ps(charge[inr+3]);
1125 vdwjidx0A = 2*vdwtype[inr+0];
1126 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1127 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1128 qq11 = _mm_mul_ps(iq1,jq1);
1129 qq12 = _mm_mul_ps(iq1,jq2);
1130 qq13 = _mm_mul_ps(iq1,jq3);
1131 qq21 = _mm_mul_ps(iq2,jq1);
1132 qq22 = _mm_mul_ps(iq2,jq2);
1133 qq23 = _mm_mul_ps(iq2,jq3);
1134 qq31 = _mm_mul_ps(iq3,jq1);
1135 qq32 = _mm_mul_ps(iq3,jq2);
1136 qq33 = _mm_mul_ps(iq3,jq3);
1138 /* Avoid stupid compiler warnings */
1139 jnrA = jnrB = jnrC = jnrD = 0;
1140 j_coord_offsetA = 0;
1141 j_coord_offsetB = 0;
1142 j_coord_offsetC = 0;
1143 j_coord_offsetD = 0;
1148 for(iidx=0;iidx<4*DIM;iidx++)
1150 scratch[iidx] = 0.0;
1153 /* Start outer loop over neighborlists */
1154 for(iidx=0; iidx<nri; iidx++)
1156 /* Load shift vector for this list */
1157 i_shift_offset = DIM*shiftidx[iidx];
1159 /* Load limits for loop over neighbors */
1160 j_index_start = jindex[iidx];
1161 j_index_end = jindex[iidx+1];
1163 /* Get outer coordinate index */
1165 i_coord_offset = DIM*inr;
1167 /* Load i particle coords and add shift vector */
1168 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1169 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1171 fix0 = _mm_setzero_ps();
1172 fiy0 = _mm_setzero_ps();
1173 fiz0 = _mm_setzero_ps();
1174 fix1 = _mm_setzero_ps();
1175 fiy1 = _mm_setzero_ps();
1176 fiz1 = _mm_setzero_ps();
1177 fix2 = _mm_setzero_ps();
1178 fiy2 = _mm_setzero_ps();
1179 fiz2 = _mm_setzero_ps();
1180 fix3 = _mm_setzero_ps();
1181 fiy3 = _mm_setzero_ps();
1182 fiz3 = _mm_setzero_ps();
1184 /* Start inner kernel loop */
1185 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1188 /* Get j neighbor index, and coordinate index */
1190 jnrB = jjnr[jidx+1];
1191 jnrC = jjnr[jidx+2];
1192 jnrD = jjnr[jidx+3];
1193 j_coord_offsetA = DIM*jnrA;
1194 j_coord_offsetB = DIM*jnrB;
1195 j_coord_offsetC = DIM*jnrC;
1196 j_coord_offsetD = DIM*jnrD;
1198 /* load j atom coordinates */
1199 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1200 x+j_coord_offsetC,x+j_coord_offsetD,
1201 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1202 &jy2,&jz2,&jx3,&jy3,&jz3);
1204 /* Calculate displacement vector */
1205 dx00 = _mm_sub_ps(ix0,jx0);
1206 dy00 = _mm_sub_ps(iy0,jy0);
1207 dz00 = _mm_sub_ps(iz0,jz0);
1208 dx11 = _mm_sub_ps(ix1,jx1);
1209 dy11 = _mm_sub_ps(iy1,jy1);
1210 dz11 = _mm_sub_ps(iz1,jz1);
1211 dx12 = _mm_sub_ps(ix1,jx2);
1212 dy12 = _mm_sub_ps(iy1,jy2);
1213 dz12 = _mm_sub_ps(iz1,jz2);
1214 dx13 = _mm_sub_ps(ix1,jx3);
1215 dy13 = _mm_sub_ps(iy1,jy3);
1216 dz13 = _mm_sub_ps(iz1,jz3);
1217 dx21 = _mm_sub_ps(ix2,jx1);
1218 dy21 = _mm_sub_ps(iy2,jy1);
1219 dz21 = _mm_sub_ps(iz2,jz1);
1220 dx22 = _mm_sub_ps(ix2,jx2);
1221 dy22 = _mm_sub_ps(iy2,jy2);
1222 dz22 = _mm_sub_ps(iz2,jz2);
1223 dx23 = _mm_sub_ps(ix2,jx3);
1224 dy23 = _mm_sub_ps(iy2,jy3);
1225 dz23 = _mm_sub_ps(iz2,jz3);
1226 dx31 = _mm_sub_ps(ix3,jx1);
1227 dy31 = _mm_sub_ps(iy3,jy1);
1228 dz31 = _mm_sub_ps(iz3,jz1);
1229 dx32 = _mm_sub_ps(ix3,jx2);
1230 dy32 = _mm_sub_ps(iy3,jy2);
1231 dz32 = _mm_sub_ps(iz3,jz2);
1232 dx33 = _mm_sub_ps(ix3,jx3);
1233 dy33 = _mm_sub_ps(iy3,jy3);
1234 dz33 = _mm_sub_ps(iz3,jz3);
1236 /* Calculate squared distance and things based on it */
1237 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1238 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1239 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1240 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1241 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1242 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1243 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1244 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1245 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1246 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1248 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1249 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1250 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1251 rinv13 = gmx_mm_invsqrt_ps(rsq13);
1252 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1253 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1254 rinv23 = gmx_mm_invsqrt_ps(rsq23);
1255 rinv31 = gmx_mm_invsqrt_ps(rsq31);
1256 rinv32 = gmx_mm_invsqrt_ps(rsq32);
1257 rinv33 = gmx_mm_invsqrt_ps(rsq33);
1259 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1260 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1261 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1262 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1263 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1264 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1265 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1266 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1267 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1269 fjx0 = _mm_setzero_ps();
1270 fjy0 = _mm_setzero_ps();
1271 fjz0 = _mm_setzero_ps();
1272 fjx1 = _mm_setzero_ps();
1273 fjy1 = _mm_setzero_ps();
1274 fjz1 = _mm_setzero_ps();
1275 fjx2 = _mm_setzero_ps();
1276 fjy2 = _mm_setzero_ps();
1277 fjz2 = _mm_setzero_ps();
1278 fjx3 = _mm_setzero_ps();
1279 fjy3 = _mm_setzero_ps();
1280 fjz3 = _mm_setzero_ps();
1282 /**************************
1283 * CALCULATE INTERACTIONS *
1284 **************************/
1286 r00 = _mm_mul_ps(rsq00,rinv00);
1288 /* Calculate table index by multiplying r with table scale and truncate to integer */
1289 rt = _mm_mul_ps(r00,vftabscale);
1290 vfitab = _mm_cvttps_epi32(rt);
1292 vfeps = _mm_frcz_ps(rt);
1294 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1296 twovfeps = _mm_add_ps(vfeps,vfeps);
1297 vfitab = _mm_slli_epi32(vfitab,3);
1299 /* CUBIC SPLINE TABLE DISPERSION */
1300 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1301 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1302 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1303 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1304 _MM_TRANSPOSE4_PS(Y,F,G,H);
1305 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1306 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1307 fvdw6 = _mm_mul_ps(c6_00,FF);
1309 /* CUBIC SPLINE TABLE REPULSION */
1310 vfitab = _mm_add_epi32(vfitab,ifour);
1311 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1312 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1313 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1314 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1315 _MM_TRANSPOSE4_PS(Y,F,G,H);
1316 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1317 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1318 fvdw12 = _mm_mul_ps(c12_00,FF);
1319 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1323 /* Update vectorial force */
1324 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1325 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1326 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1328 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1329 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1330 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1332 /**************************
1333 * CALCULATE INTERACTIONS *
1334 **************************/
1336 /* REACTION-FIELD ELECTROSTATICS */
1337 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1341 /* Update vectorial force */
1342 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1343 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1344 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1346 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1347 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1348 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1350 /**************************
1351 * CALCULATE INTERACTIONS *
1352 **************************/
1354 /* REACTION-FIELD ELECTROSTATICS */
1355 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1359 /* Update vectorial force */
1360 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1361 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1362 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1364 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1365 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1366 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1368 /**************************
1369 * CALCULATE INTERACTIONS *
1370 **************************/
1372 /* REACTION-FIELD ELECTROSTATICS */
1373 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1377 /* Update vectorial force */
1378 fix1 = _mm_macc_ps(dx13,fscal,fix1);
1379 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
1380 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
1382 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
1383 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
1384 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
1386 /**************************
1387 * CALCULATE INTERACTIONS *
1388 **************************/
1390 /* REACTION-FIELD ELECTROSTATICS */
1391 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1395 /* Update vectorial force */
1396 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1397 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1398 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1400 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1401 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1402 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1404 /**************************
1405 * CALCULATE INTERACTIONS *
1406 **************************/
1408 /* REACTION-FIELD ELECTROSTATICS */
1409 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1413 /* Update vectorial force */
1414 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1415 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1416 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1418 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1419 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1420 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1422 /**************************
1423 * CALCULATE INTERACTIONS *
1424 **************************/
1426 /* REACTION-FIELD ELECTROSTATICS */
1427 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1431 /* Update vectorial force */
1432 fix2 = _mm_macc_ps(dx23,fscal,fix2);
1433 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
1434 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
1436 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
1437 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
1438 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
1440 /**************************
1441 * CALCULATE INTERACTIONS *
1442 **************************/
1444 /* REACTION-FIELD ELECTROSTATICS */
1445 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1449 /* Update vectorial force */
1450 fix3 = _mm_macc_ps(dx31,fscal,fix3);
1451 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
1452 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
1454 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
1455 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
1456 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
1458 /**************************
1459 * CALCULATE INTERACTIONS *
1460 **************************/
1462 /* REACTION-FIELD ELECTROSTATICS */
1463 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1467 /* Update vectorial force */
1468 fix3 = _mm_macc_ps(dx32,fscal,fix3);
1469 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
1470 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
1472 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
1473 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
1474 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
1476 /**************************
1477 * CALCULATE INTERACTIONS *
1478 **************************/
1480 /* REACTION-FIELD ELECTROSTATICS */
1481 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1485 /* Update vectorial force */
1486 fix3 = _mm_macc_ps(dx33,fscal,fix3);
1487 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
1488 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
1490 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
1491 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
1492 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
1494 fjptrA = f+j_coord_offsetA;
1495 fjptrB = f+j_coord_offsetB;
1496 fjptrC = f+j_coord_offsetC;
1497 fjptrD = f+j_coord_offsetD;
1499 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1500 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1501 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1503 /* Inner loop uses 324 flops */
1506 if(jidx<j_index_end)
1509 /* Get j neighbor index, and coordinate index */
1510 jnrlistA = jjnr[jidx];
1511 jnrlistB = jjnr[jidx+1];
1512 jnrlistC = jjnr[jidx+2];
1513 jnrlistD = jjnr[jidx+3];
1514 /* Sign of each element will be negative for non-real atoms.
1515 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1516 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1518 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1519 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1520 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1521 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1522 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1523 j_coord_offsetA = DIM*jnrA;
1524 j_coord_offsetB = DIM*jnrB;
1525 j_coord_offsetC = DIM*jnrC;
1526 j_coord_offsetD = DIM*jnrD;
1528 /* load j atom coordinates */
1529 gmx_mm_load_4rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1530 x+j_coord_offsetC,x+j_coord_offsetD,
1531 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1532 &jy2,&jz2,&jx3,&jy3,&jz3);
1534 /* Calculate displacement vector */
1535 dx00 = _mm_sub_ps(ix0,jx0);
1536 dy00 = _mm_sub_ps(iy0,jy0);
1537 dz00 = _mm_sub_ps(iz0,jz0);
1538 dx11 = _mm_sub_ps(ix1,jx1);
1539 dy11 = _mm_sub_ps(iy1,jy1);
1540 dz11 = _mm_sub_ps(iz1,jz1);
1541 dx12 = _mm_sub_ps(ix1,jx2);
1542 dy12 = _mm_sub_ps(iy1,jy2);
1543 dz12 = _mm_sub_ps(iz1,jz2);
1544 dx13 = _mm_sub_ps(ix1,jx3);
1545 dy13 = _mm_sub_ps(iy1,jy3);
1546 dz13 = _mm_sub_ps(iz1,jz3);
1547 dx21 = _mm_sub_ps(ix2,jx1);
1548 dy21 = _mm_sub_ps(iy2,jy1);
1549 dz21 = _mm_sub_ps(iz2,jz1);
1550 dx22 = _mm_sub_ps(ix2,jx2);
1551 dy22 = _mm_sub_ps(iy2,jy2);
1552 dz22 = _mm_sub_ps(iz2,jz2);
1553 dx23 = _mm_sub_ps(ix2,jx3);
1554 dy23 = _mm_sub_ps(iy2,jy3);
1555 dz23 = _mm_sub_ps(iz2,jz3);
1556 dx31 = _mm_sub_ps(ix3,jx1);
1557 dy31 = _mm_sub_ps(iy3,jy1);
1558 dz31 = _mm_sub_ps(iz3,jz1);
1559 dx32 = _mm_sub_ps(ix3,jx2);
1560 dy32 = _mm_sub_ps(iy3,jy2);
1561 dz32 = _mm_sub_ps(iz3,jz2);
1562 dx33 = _mm_sub_ps(ix3,jx3);
1563 dy33 = _mm_sub_ps(iy3,jy3);
1564 dz33 = _mm_sub_ps(iz3,jz3);
1566 /* Calculate squared distance and things based on it */
1567 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1568 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1569 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1570 rsq13 = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1571 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1572 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1573 rsq23 = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1574 rsq31 = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1575 rsq32 = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1576 rsq33 = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1578 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1579 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1580 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1581 rinv13 = gmx_mm_invsqrt_ps(rsq13);
1582 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1583 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1584 rinv23 = gmx_mm_invsqrt_ps(rsq23);
1585 rinv31 = gmx_mm_invsqrt_ps(rsq31);
1586 rinv32 = gmx_mm_invsqrt_ps(rsq32);
1587 rinv33 = gmx_mm_invsqrt_ps(rsq33);
1589 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1590 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1591 rinvsq13 = _mm_mul_ps(rinv13,rinv13);
1592 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1593 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1594 rinvsq23 = _mm_mul_ps(rinv23,rinv23);
1595 rinvsq31 = _mm_mul_ps(rinv31,rinv31);
1596 rinvsq32 = _mm_mul_ps(rinv32,rinv32);
1597 rinvsq33 = _mm_mul_ps(rinv33,rinv33);
1599 fjx0 = _mm_setzero_ps();
1600 fjy0 = _mm_setzero_ps();
1601 fjz0 = _mm_setzero_ps();
1602 fjx1 = _mm_setzero_ps();
1603 fjy1 = _mm_setzero_ps();
1604 fjz1 = _mm_setzero_ps();
1605 fjx2 = _mm_setzero_ps();
1606 fjy2 = _mm_setzero_ps();
1607 fjz2 = _mm_setzero_ps();
1608 fjx3 = _mm_setzero_ps();
1609 fjy3 = _mm_setzero_ps();
1610 fjz3 = _mm_setzero_ps();
1612 /**************************
1613 * CALCULATE INTERACTIONS *
1614 **************************/
1616 r00 = _mm_mul_ps(rsq00,rinv00);
1617 r00 = _mm_andnot_ps(dummy_mask,r00);
1619 /* Calculate table index by multiplying r with table scale and truncate to integer */
1620 rt = _mm_mul_ps(r00,vftabscale);
1621 vfitab = _mm_cvttps_epi32(rt);
1623 vfeps = _mm_frcz_ps(rt);
1625 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1627 twovfeps = _mm_add_ps(vfeps,vfeps);
1628 vfitab = _mm_slli_epi32(vfitab,3);
1630 /* CUBIC SPLINE TABLE DISPERSION */
1631 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1632 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1633 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1634 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1635 _MM_TRANSPOSE4_PS(Y,F,G,H);
1636 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1637 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1638 fvdw6 = _mm_mul_ps(c6_00,FF);
1640 /* CUBIC SPLINE TABLE REPULSION */
1641 vfitab = _mm_add_epi32(vfitab,ifour);
1642 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1643 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1644 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1645 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1646 _MM_TRANSPOSE4_PS(Y,F,G,H);
1647 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1648 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1649 fvdw12 = _mm_mul_ps(c12_00,FF);
1650 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1654 fscal = _mm_andnot_ps(dummy_mask,fscal);
1656 /* Update vectorial force */
1657 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1658 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1659 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1661 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1662 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1663 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1665 /**************************
1666 * CALCULATE INTERACTIONS *
1667 **************************/
1669 /* REACTION-FIELD ELECTROSTATICS */
1670 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1674 fscal = _mm_andnot_ps(dummy_mask,fscal);
1676 /* Update vectorial force */
1677 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1678 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1679 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1681 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1682 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1683 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1685 /**************************
1686 * CALCULATE INTERACTIONS *
1687 **************************/
1689 /* REACTION-FIELD ELECTROSTATICS */
1690 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1694 fscal = _mm_andnot_ps(dummy_mask,fscal);
1696 /* Update vectorial force */
1697 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1698 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1699 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1701 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1702 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1703 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1705 /**************************
1706 * CALCULATE INTERACTIONS *
1707 **************************/
1709 /* REACTION-FIELD ELECTROSTATICS */
1710 felec = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1714 fscal = _mm_andnot_ps(dummy_mask,fscal);
1716 /* Update vectorial force */
1717 fix1 = _mm_macc_ps(dx13,fscal,fix1);
1718 fiy1 = _mm_macc_ps(dy13,fscal,fiy1);
1719 fiz1 = _mm_macc_ps(dz13,fscal,fiz1);
1721 fjx3 = _mm_macc_ps(dx13,fscal,fjx3);
1722 fjy3 = _mm_macc_ps(dy13,fscal,fjy3);
1723 fjz3 = _mm_macc_ps(dz13,fscal,fjz3);
1725 /**************************
1726 * CALCULATE INTERACTIONS *
1727 **************************/
1729 /* REACTION-FIELD ELECTROSTATICS */
1730 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1734 fscal = _mm_andnot_ps(dummy_mask,fscal);
1736 /* Update vectorial force */
1737 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1738 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1739 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1741 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1742 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1743 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1745 /**************************
1746 * CALCULATE INTERACTIONS *
1747 **************************/
1749 /* REACTION-FIELD ELECTROSTATICS */
1750 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1754 fscal = _mm_andnot_ps(dummy_mask,fscal);
1756 /* Update vectorial force */
1757 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1758 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1759 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1761 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1762 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1763 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1765 /**************************
1766 * CALCULATE INTERACTIONS *
1767 **************************/
1769 /* REACTION-FIELD ELECTROSTATICS */
1770 felec = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1774 fscal = _mm_andnot_ps(dummy_mask,fscal);
1776 /* Update vectorial force */
1777 fix2 = _mm_macc_ps(dx23,fscal,fix2);
1778 fiy2 = _mm_macc_ps(dy23,fscal,fiy2);
1779 fiz2 = _mm_macc_ps(dz23,fscal,fiz2);
1781 fjx3 = _mm_macc_ps(dx23,fscal,fjx3);
1782 fjy3 = _mm_macc_ps(dy23,fscal,fjy3);
1783 fjz3 = _mm_macc_ps(dz23,fscal,fjz3);
1785 /**************************
1786 * CALCULATE INTERACTIONS *
1787 **************************/
1789 /* REACTION-FIELD ELECTROSTATICS */
1790 felec = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1794 fscal = _mm_andnot_ps(dummy_mask,fscal);
1796 /* Update vectorial force */
1797 fix3 = _mm_macc_ps(dx31,fscal,fix3);
1798 fiy3 = _mm_macc_ps(dy31,fscal,fiy3);
1799 fiz3 = _mm_macc_ps(dz31,fscal,fiz3);
1801 fjx1 = _mm_macc_ps(dx31,fscal,fjx1);
1802 fjy1 = _mm_macc_ps(dy31,fscal,fjy1);
1803 fjz1 = _mm_macc_ps(dz31,fscal,fjz1);
1805 /**************************
1806 * CALCULATE INTERACTIONS *
1807 **************************/
1809 /* REACTION-FIELD ELECTROSTATICS */
1810 felec = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1814 fscal = _mm_andnot_ps(dummy_mask,fscal);
1816 /* Update vectorial force */
1817 fix3 = _mm_macc_ps(dx32,fscal,fix3);
1818 fiy3 = _mm_macc_ps(dy32,fscal,fiy3);
1819 fiz3 = _mm_macc_ps(dz32,fscal,fiz3);
1821 fjx2 = _mm_macc_ps(dx32,fscal,fjx2);
1822 fjy2 = _mm_macc_ps(dy32,fscal,fjy2);
1823 fjz2 = _mm_macc_ps(dz32,fscal,fjz2);
1825 /**************************
1826 * CALCULATE INTERACTIONS *
1827 **************************/
1829 /* REACTION-FIELD ELECTROSTATICS */
1830 felec = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1834 fscal = _mm_andnot_ps(dummy_mask,fscal);
1836 /* Update vectorial force */
1837 fix3 = _mm_macc_ps(dx33,fscal,fix3);
1838 fiy3 = _mm_macc_ps(dy33,fscal,fiy3);
1839 fiz3 = _mm_macc_ps(dz33,fscal,fiz3);
1841 fjx3 = _mm_macc_ps(dx33,fscal,fjx3);
1842 fjy3 = _mm_macc_ps(dy33,fscal,fjy3);
1843 fjz3 = _mm_macc_ps(dz33,fscal,fjz3);
1845 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1846 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1847 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1848 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1850 gmx_mm_decrement_4rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1851 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,
1852 fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1854 /* Inner loop uses 325 flops */
1857 /* End of innermost loop */
1859 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1860 f+i_coord_offset,fshift+i_shift_offset);
1862 /* Increment number of inner iterations */
1863 inneriter += j_index_end - j_index_start;
1865 /* Outer loop uses 24 flops */
1868 /* Increment number of outer iterations */
1871 /* Update outer/inner flops */
1873 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*325);