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 "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwCSTab_GeomW3W3_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water3-Water3
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRF_VdwCSTab_GeomW3W3_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;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
94 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
95 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
96 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
97 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
98 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
99 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
100 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
101 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
102 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
103 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
104 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
105 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
106 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
109 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
112 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
113 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
115 __m128i ifour = _mm_set1_epi32(4);
116 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
118 __m128 dummy_mask,cutoff_mask;
119 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
120 __m128 one = _mm_set1_ps(1.0);
121 __m128 two = _mm_set1_ps(2.0);
127 jindex = nlist->jindex;
129 shiftidx = nlist->shift;
131 shiftvec = fr->shift_vec[0];
132 fshift = fr->fshift[0];
133 facel = _mm_set1_ps(fr->epsfac);
134 charge = mdatoms->chargeA;
135 krf = _mm_set1_ps(fr->ic->k_rf);
136 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
137 crf = _mm_set1_ps(fr->ic->c_rf);
138 nvdwtype = fr->ntype;
140 vdwtype = mdatoms->typeA;
142 vftab = kernel_data->table_vdw->data;
143 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
145 /* Setup water-specific parameters */
146 inr = nlist->iinr[0];
147 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
148 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
149 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
150 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
152 jq0 = _mm_set1_ps(charge[inr+0]);
153 jq1 = _mm_set1_ps(charge[inr+1]);
154 jq2 = _mm_set1_ps(charge[inr+2]);
155 vdwjidx0A = 2*vdwtype[inr+0];
156 qq00 = _mm_mul_ps(iq0,jq0);
157 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
158 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
159 qq01 = _mm_mul_ps(iq0,jq1);
160 qq02 = _mm_mul_ps(iq0,jq2);
161 qq10 = _mm_mul_ps(iq1,jq0);
162 qq11 = _mm_mul_ps(iq1,jq1);
163 qq12 = _mm_mul_ps(iq1,jq2);
164 qq20 = _mm_mul_ps(iq2,jq0);
165 qq21 = _mm_mul_ps(iq2,jq1);
166 qq22 = _mm_mul_ps(iq2,jq2);
168 /* Avoid stupid compiler warnings */
169 jnrA = jnrB = jnrC = jnrD = 0;
178 for(iidx=0;iidx<4*DIM;iidx++)
183 /* Start outer loop over neighborlists */
184 for(iidx=0; iidx<nri; iidx++)
186 /* Load shift vector for this list */
187 i_shift_offset = DIM*shiftidx[iidx];
189 /* Load limits for loop over neighbors */
190 j_index_start = jindex[iidx];
191 j_index_end = jindex[iidx+1];
193 /* Get outer coordinate index */
195 i_coord_offset = DIM*inr;
197 /* Load i particle coords and add shift vector */
198 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
199 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
201 fix0 = _mm_setzero_ps();
202 fiy0 = _mm_setzero_ps();
203 fiz0 = _mm_setzero_ps();
204 fix1 = _mm_setzero_ps();
205 fiy1 = _mm_setzero_ps();
206 fiz1 = _mm_setzero_ps();
207 fix2 = _mm_setzero_ps();
208 fiy2 = _mm_setzero_ps();
209 fiz2 = _mm_setzero_ps();
211 /* Reset potential sums */
212 velecsum = _mm_setzero_ps();
213 vvdwsum = _mm_setzero_ps();
215 /* Start inner kernel loop */
216 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
219 /* Get j neighbor index, and coordinate index */
224 j_coord_offsetA = DIM*jnrA;
225 j_coord_offsetB = DIM*jnrB;
226 j_coord_offsetC = DIM*jnrC;
227 j_coord_offsetD = DIM*jnrD;
229 /* load j atom coordinates */
230 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
231 x+j_coord_offsetC,x+j_coord_offsetD,
232 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
234 /* Calculate displacement vector */
235 dx00 = _mm_sub_ps(ix0,jx0);
236 dy00 = _mm_sub_ps(iy0,jy0);
237 dz00 = _mm_sub_ps(iz0,jz0);
238 dx01 = _mm_sub_ps(ix0,jx1);
239 dy01 = _mm_sub_ps(iy0,jy1);
240 dz01 = _mm_sub_ps(iz0,jz1);
241 dx02 = _mm_sub_ps(ix0,jx2);
242 dy02 = _mm_sub_ps(iy0,jy2);
243 dz02 = _mm_sub_ps(iz0,jz2);
244 dx10 = _mm_sub_ps(ix1,jx0);
245 dy10 = _mm_sub_ps(iy1,jy0);
246 dz10 = _mm_sub_ps(iz1,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 dx20 = _mm_sub_ps(ix2,jx0);
254 dy20 = _mm_sub_ps(iy2,jy0);
255 dz20 = _mm_sub_ps(iz2,jz0);
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);
263 /* Calculate squared distance and things based on it */
264 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
265 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
266 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
267 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
268 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
269 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
270 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
271 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
272 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
274 rinv00 = gmx_mm_invsqrt_ps(rsq00);
275 rinv01 = gmx_mm_invsqrt_ps(rsq01);
276 rinv02 = gmx_mm_invsqrt_ps(rsq02);
277 rinv10 = gmx_mm_invsqrt_ps(rsq10);
278 rinv11 = gmx_mm_invsqrt_ps(rsq11);
279 rinv12 = gmx_mm_invsqrt_ps(rsq12);
280 rinv20 = gmx_mm_invsqrt_ps(rsq20);
281 rinv21 = gmx_mm_invsqrt_ps(rsq21);
282 rinv22 = gmx_mm_invsqrt_ps(rsq22);
284 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
285 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
286 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
287 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
288 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
289 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
290 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
291 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
292 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
294 fjx0 = _mm_setzero_ps();
295 fjy0 = _mm_setzero_ps();
296 fjz0 = _mm_setzero_ps();
297 fjx1 = _mm_setzero_ps();
298 fjy1 = _mm_setzero_ps();
299 fjz1 = _mm_setzero_ps();
300 fjx2 = _mm_setzero_ps();
301 fjy2 = _mm_setzero_ps();
302 fjz2 = _mm_setzero_ps();
304 /**************************
305 * CALCULATE INTERACTIONS *
306 **************************/
308 r00 = _mm_mul_ps(rsq00,rinv00);
310 /* Calculate table index by multiplying r with table scale and truncate to integer */
311 rt = _mm_mul_ps(r00,vftabscale);
312 vfitab = _mm_cvttps_epi32(rt);
314 vfeps = _mm_frcz_ps(rt);
316 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
318 twovfeps = _mm_add_ps(vfeps,vfeps);
319 vfitab = _mm_slli_epi32(vfitab,3);
321 /* REACTION-FIELD ELECTROSTATICS */
322 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
323 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
325 /* CUBIC SPLINE TABLE DISPERSION */
326 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
327 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
328 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
329 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
330 _MM_TRANSPOSE4_PS(Y,F,G,H);
331 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
332 VV = _mm_macc_ps(vfeps,Fp,Y);
333 vvdw6 = _mm_mul_ps(c6_00,VV);
334 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
335 fvdw6 = _mm_mul_ps(c6_00,FF);
337 /* CUBIC SPLINE TABLE REPULSION */
338 vfitab = _mm_add_epi32(vfitab,ifour);
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 vvdw12 = _mm_mul_ps(c12_00,VV);
347 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
348 fvdw12 = _mm_mul_ps(c12_00,FF);
349 vvdw = _mm_add_ps(vvdw12,vvdw6);
350 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
352 /* Update potential sum for this i atom from the interaction with this j atom. */
353 velecsum = _mm_add_ps(velecsum,velec);
354 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
356 fscal = _mm_add_ps(felec,fvdw);
358 /* Update vectorial force */
359 fix0 = _mm_macc_ps(dx00,fscal,fix0);
360 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
361 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
363 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
364 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
365 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
367 /**************************
368 * CALCULATE INTERACTIONS *
369 **************************/
371 /* REACTION-FIELD ELECTROSTATICS */
372 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
373 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
375 /* Update potential sum for this i atom from the interaction with this j atom. */
376 velecsum = _mm_add_ps(velecsum,velec);
380 /* Update vectorial force */
381 fix0 = _mm_macc_ps(dx01,fscal,fix0);
382 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
383 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
385 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
386 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
387 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
389 /**************************
390 * CALCULATE INTERACTIONS *
391 **************************/
393 /* REACTION-FIELD ELECTROSTATICS */
394 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
395 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
397 /* Update potential sum for this i atom from the interaction with this j atom. */
398 velecsum = _mm_add_ps(velecsum,velec);
402 /* Update vectorial force */
403 fix0 = _mm_macc_ps(dx02,fscal,fix0);
404 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
405 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
407 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
408 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
409 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
411 /**************************
412 * CALCULATE INTERACTIONS *
413 **************************/
415 /* REACTION-FIELD ELECTROSTATICS */
416 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
417 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
419 /* Update potential sum for this i atom from the interaction with this j atom. */
420 velecsum = _mm_add_ps(velecsum,velec);
424 /* Update vectorial force */
425 fix1 = _mm_macc_ps(dx10,fscal,fix1);
426 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
427 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
429 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
430 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
431 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
433 /**************************
434 * CALCULATE INTERACTIONS *
435 **************************/
437 /* REACTION-FIELD ELECTROSTATICS */
438 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
439 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
441 /* Update potential sum for this i atom from the interaction with this j atom. */
442 velecsum = _mm_add_ps(velecsum,velec);
446 /* Update vectorial force */
447 fix1 = _mm_macc_ps(dx11,fscal,fix1);
448 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
449 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
451 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
452 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
453 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
455 /**************************
456 * CALCULATE INTERACTIONS *
457 **************************/
459 /* REACTION-FIELD ELECTROSTATICS */
460 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
461 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
463 /* Update potential sum for this i atom from the interaction with this j atom. */
464 velecsum = _mm_add_ps(velecsum,velec);
468 /* Update vectorial force */
469 fix1 = _mm_macc_ps(dx12,fscal,fix1);
470 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
471 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
473 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
474 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
475 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
477 /**************************
478 * CALCULATE INTERACTIONS *
479 **************************/
481 /* REACTION-FIELD ELECTROSTATICS */
482 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
483 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
485 /* Update potential sum for this i atom from the interaction with this j atom. */
486 velecsum = _mm_add_ps(velecsum,velec);
490 /* Update vectorial force */
491 fix2 = _mm_macc_ps(dx20,fscal,fix2);
492 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
493 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
495 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
496 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
497 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
499 /**************************
500 * CALCULATE INTERACTIONS *
501 **************************/
503 /* REACTION-FIELD ELECTROSTATICS */
504 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
505 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
507 /* Update potential sum for this i atom from the interaction with this j atom. */
508 velecsum = _mm_add_ps(velecsum,velec);
512 /* Update vectorial force */
513 fix2 = _mm_macc_ps(dx21,fscal,fix2);
514 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
515 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
517 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
518 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
519 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
521 /**************************
522 * CALCULATE INTERACTIONS *
523 **************************/
525 /* REACTION-FIELD ELECTROSTATICS */
526 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
527 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
529 /* Update potential sum for this i atom from the interaction with this j atom. */
530 velecsum = _mm_add_ps(velecsum,velec);
534 /* Update vectorial force */
535 fix2 = _mm_macc_ps(dx22,fscal,fix2);
536 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
537 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
539 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
540 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
541 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
543 fjptrA = f+j_coord_offsetA;
544 fjptrB = f+j_coord_offsetB;
545 fjptrC = f+j_coord_offsetC;
546 fjptrD = f+j_coord_offsetD;
548 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
549 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
551 /* Inner loop uses 350 flops */
557 /* Get j neighbor index, and coordinate index */
558 jnrlistA = jjnr[jidx];
559 jnrlistB = jjnr[jidx+1];
560 jnrlistC = jjnr[jidx+2];
561 jnrlistD = jjnr[jidx+3];
562 /* Sign of each element will be negative for non-real atoms.
563 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
564 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
566 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
567 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
568 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
569 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
570 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
571 j_coord_offsetA = DIM*jnrA;
572 j_coord_offsetB = DIM*jnrB;
573 j_coord_offsetC = DIM*jnrC;
574 j_coord_offsetD = DIM*jnrD;
576 /* load j atom coordinates */
577 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
578 x+j_coord_offsetC,x+j_coord_offsetD,
579 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
581 /* Calculate displacement vector */
582 dx00 = _mm_sub_ps(ix0,jx0);
583 dy00 = _mm_sub_ps(iy0,jy0);
584 dz00 = _mm_sub_ps(iz0,jz0);
585 dx01 = _mm_sub_ps(ix0,jx1);
586 dy01 = _mm_sub_ps(iy0,jy1);
587 dz01 = _mm_sub_ps(iz0,jz1);
588 dx02 = _mm_sub_ps(ix0,jx2);
589 dy02 = _mm_sub_ps(iy0,jy2);
590 dz02 = _mm_sub_ps(iz0,jz2);
591 dx10 = _mm_sub_ps(ix1,jx0);
592 dy10 = _mm_sub_ps(iy1,jy0);
593 dz10 = _mm_sub_ps(iz1,jz0);
594 dx11 = _mm_sub_ps(ix1,jx1);
595 dy11 = _mm_sub_ps(iy1,jy1);
596 dz11 = _mm_sub_ps(iz1,jz1);
597 dx12 = _mm_sub_ps(ix1,jx2);
598 dy12 = _mm_sub_ps(iy1,jy2);
599 dz12 = _mm_sub_ps(iz1,jz2);
600 dx20 = _mm_sub_ps(ix2,jx0);
601 dy20 = _mm_sub_ps(iy2,jy0);
602 dz20 = _mm_sub_ps(iz2,jz0);
603 dx21 = _mm_sub_ps(ix2,jx1);
604 dy21 = _mm_sub_ps(iy2,jy1);
605 dz21 = _mm_sub_ps(iz2,jz1);
606 dx22 = _mm_sub_ps(ix2,jx2);
607 dy22 = _mm_sub_ps(iy2,jy2);
608 dz22 = _mm_sub_ps(iz2,jz2);
610 /* Calculate squared distance and things based on it */
611 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
612 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
613 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
614 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
615 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
616 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
617 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
618 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
619 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
621 rinv00 = gmx_mm_invsqrt_ps(rsq00);
622 rinv01 = gmx_mm_invsqrt_ps(rsq01);
623 rinv02 = gmx_mm_invsqrt_ps(rsq02);
624 rinv10 = gmx_mm_invsqrt_ps(rsq10);
625 rinv11 = gmx_mm_invsqrt_ps(rsq11);
626 rinv12 = gmx_mm_invsqrt_ps(rsq12);
627 rinv20 = gmx_mm_invsqrt_ps(rsq20);
628 rinv21 = gmx_mm_invsqrt_ps(rsq21);
629 rinv22 = gmx_mm_invsqrt_ps(rsq22);
631 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
632 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
633 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
634 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
635 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
636 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
637 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
638 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
639 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
641 fjx0 = _mm_setzero_ps();
642 fjy0 = _mm_setzero_ps();
643 fjz0 = _mm_setzero_ps();
644 fjx1 = _mm_setzero_ps();
645 fjy1 = _mm_setzero_ps();
646 fjz1 = _mm_setzero_ps();
647 fjx2 = _mm_setzero_ps();
648 fjy2 = _mm_setzero_ps();
649 fjz2 = _mm_setzero_ps();
651 /**************************
652 * CALCULATE INTERACTIONS *
653 **************************/
655 r00 = _mm_mul_ps(rsq00,rinv00);
656 r00 = _mm_andnot_ps(dummy_mask,r00);
658 /* Calculate table index by multiplying r with table scale and truncate to integer */
659 rt = _mm_mul_ps(r00,vftabscale);
660 vfitab = _mm_cvttps_epi32(rt);
662 vfeps = _mm_frcz_ps(rt);
664 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
666 twovfeps = _mm_add_ps(vfeps,vfeps);
667 vfitab = _mm_slli_epi32(vfitab,3);
669 /* REACTION-FIELD ELECTROSTATICS */
670 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
671 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
673 /* CUBIC SPLINE TABLE DISPERSION */
674 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
675 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
676 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
677 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
678 _MM_TRANSPOSE4_PS(Y,F,G,H);
679 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
680 VV = _mm_macc_ps(vfeps,Fp,Y);
681 vvdw6 = _mm_mul_ps(c6_00,VV);
682 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
683 fvdw6 = _mm_mul_ps(c6_00,FF);
685 /* CUBIC SPLINE TABLE REPULSION */
686 vfitab = _mm_add_epi32(vfitab,ifour);
687 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
688 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
689 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
690 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
691 _MM_TRANSPOSE4_PS(Y,F,G,H);
692 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
693 VV = _mm_macc_ps(vfeps,Fp,Y);
694 vvdw12 = _mm_mul_ps(c12_00,VV);
695 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
696 fvdw12 = _mm_mul_ps(c12_00,FF);
697 vvdw = _mm_add_ps(vvdw12,vvdw6);
698 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
700 /* Update potential sum for this i atom from the interaction with this j atom. */
701 velec = _mm_andnot_ps(dummy_mask,velec);
702 velecsum = _mm_add_ps(velecsum,velec);
703 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
704 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
706 fscal = _mm_add_ps(felec,fvdw);
708 fscal = _mm_andnot_ps(dummy_mask,fscal);
710 /* Update vectorial force */
711 fix0 = _mm_macc_ps(dx00,fscal,fix0);
712 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
713 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
715 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
716 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
717 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
719 /**************************
720 * CALCULATE INTERACTIONS *
721 **************************/
723 /* REACTION-FIELD ELECTROSTATICS */
724 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
725 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
727 /* Update potential sum for this i atom from the interaction with this j atom. */
728 velec = _mm_andnot_ps(dummy_mask,velec);
729 velecsum = _mm_add_ps(velecsum,velec);
733 fscal = _mm_andnot_ps(dummy_mask,fscal);
735 /* Update vectorial force */
736 fix0 = _mm_macc_ps(dx01,fscal,fix0);
737 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
738 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
740 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
741 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
742 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
744 /**************************
745 * CALCULATE INTERACTIONS *
746 **************************/
748 /* REACTION-FIELD ELECTROSTATICS */
749 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
750 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
752 /* Update potential sum for this i atom from the interaction with this j atom. */
753 velec = _mm_andnot_ps(dummy_mask,velec);
754 velecsum = _mm_add_ps(velecsum,velec);
758 fscal = _mm_andnot_ps(dummy_mask,fscal);
760 /* Update vectorial force */
761 fix0 = _mm_macc_ps(dx02,fscal,fix0);
762 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
763 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
765 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
766 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
767 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
769 /**************************
770 * CALCULATE INTERACTIONS *
771 **************************/
773 /* REACTION-FIELD ELECTROSTATICS */
774 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
775 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
777 /* Update potential sum for this i atom from the interaction with this j atom. */
778 velec = _mm_andnot_ps(dummy_mask,velec);
779 velecsum = _mm_add_ps(velecsum,velec);
783 fscal = _mm_andnot_ps(dummy_mask,fscal);
785 /* Update vectorial force */
786 fix1 = _mm_macc_ps(dx10,fscal,fix1);
787 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
788 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
790 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
791 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
792 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
794 /**************************
795 * CALCULATE INTERACTIONS *
796 **************************/
798 /* REACTION-FIELD ELECTROSTATICS */
799 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
800 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
802 /* Update potential sum for this i atom from the interaction with this j atom. */
803 velec = _mm_andnot_ps(dummy_mask,velec);
804 velecsum = _mm_add_ps(velecsum,velec);
808 fscal = _mm_andnot_ps(dummy_mask,fscal);
810 /* Update vectorial force */
811 fix1 = _mm_macc_ps(dx11,fscal,fix1);
812 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
813 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
815 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
816 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
817 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
819 /**************************
820 * CALCULATE INTERACTIONS *
821 **************************/
823 /* REACTION-FIELD ELECTROSTATICS */
824 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
825 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
827 /* Update potential sum for this i atom from the interaction with this j atom. */
828 velec = _mm_andnot_ps(dummy_mask,velec);
829 velecsum = _mm_add_ps(velecsum,velec);
833 fscal = _mm_andnot_ps(dummy_mask,fscal);
835 /* Update vectorial force */
836 fix1 = _mm_macc_ps(dx12,fscal,fix1);
837 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
838 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
840 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
841 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
842 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
844 /**************************
845 * CALCULATE INTERACTIONS *
846 **************************/
848 /* REACTION-FIELD ELECTROSTATICS */
849 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
850 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
852 /* Update potential sum for this i atom from the interaction with this j atom. */
853 velec = _mm_andnot_ps(dummy_mask,velec);
854 velecsum = _mm_add_ps(velecsum,velec);
858 fscal = _mm_andnot_ps(dummy_mask,fscal);
860 /* Update vectorial force */
861 fix2 = _mm_macc_ps(dx20,fscal,fix2);
862 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
863 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
865 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
866 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
867 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
869 /**************************
870 * CALCULATE INTERACTIONS *
871 **************************/
873 /* REACTION-FIELD ELECTROSTATICS */
874 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
875 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
877 /* Update potential sum for this i atom from the interaction with this j atom. */
878 velec = _mm_andnot_ps(dummy_mask,velec);
879 velecsum = _mm_add_ps(velecsum,velec);
883 fscal = _mm_andnot_ps(dummy_mask,fscal);
885 /* Update vectorial force */
886 fix2 = _mm_macc_ps(dx21,fscal,fix2);
887 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
888 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
890 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
891 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
892 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
894 /**************************
895 * CALCULATE INTERACTIONS *
896 **************************/
898 /* REACTION-FIELD ELECTROSTATICS */
899 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
900 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
902 /* Update potential sum for this i atom from the interaction with this j atom. */
903 velec = _mm_andnot_ps(dummy_mask,velec);
904 velecsum = _mm_add_ps(velecsum,velec);
908 fscal = _mm_andnot_ps(dummy_mask,fscal);
910 /* Update vectorial force */
911 fix2 = _mm_macc_ps(dx22,fscal,fix2);
912 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
913 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
915 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
916 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
917 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
919 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
920 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
921 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
922 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
924 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
925 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
927 /* Inner loop uses 351 flops */
930 /* End of innermost loop */
932 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
933 f+i_coord_offset,fshift+i_shift_offset);
936 /* Update potential energies */
937 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
938 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
940 /* Increment number of inner iterations */
941 inneriter += j_index_end - j_index_start;
943 /* Outer loop uses 20 flops */
946 /* Increment number of outer iterations */
949 /* Update outer/inner flops */
951 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*351);
954 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwCSTab_GeomW3W3_F_avx_128_fma_single
955 * Electrostatics interaction: ReactionField
956 * VdW interaction: CubicSplineTable
957 * Geometry: Water3-Water3
958 * Calculate force/pot: Force
961 nb_kernel_ElecRF_VdwCSTab_GeomW3W3_F_avx_128_fma_single
962 (t_nblist * gmx_restrict nlist,
963 rvec * gmx_restrict xx,
964 rvec * gmx_restrict ff,
965 t_forcerec * gmx_restrict fr,
966 t_mdatoms * gmx_restrict mdatoms,
967 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
968 t_nrnb * gmx_restrict nrnb)
970 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
971 * just 0 for non-waters.
972 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
973 * jnr indices corresponding to data put in the four positions in the SIMD register.
975 int i_shift_offset,i_coord_offset,outeriter,inneriter;
976 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
977 int jnrA,jnrB,jnrC,jnrD;
978 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
979 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
980 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
982 real *shiftvec,*fshift,*x,*f;
983 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
985 __m128 fscal,rcutoff,rcutoff2,jidxall;
987 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
989 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
991 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
992 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
993 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
994 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
995 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
996 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
997 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
998 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
999 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1000 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1001 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1002 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1003 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1004 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1005 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1006 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1007 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1010 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1013 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1014 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1016 __m128i ifour = _mm_set1_epi32(4);
1017 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
1019 __m128 dummy_mask,cutoff_mask;
1020 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1021 __m128 one = _mm_set1_ps(1.0);
1022 __m128 two = _mm_set1_ps(2.0);
1028 jindex = nlist->jindex;
1030 shiftidx = nlist->shift;
1032 shiftvec = fr->shift_vec[0];
1033 fshift = fr->fshift[0];
1034 facel = _mm_set1_ps(fr->epsfac);
1035 charge = mdatoms->chargeA;
1036 krf = _mm_set1_ps(fr->ic->k_rf);
1037 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1038 crf = _mm_set1_ps(fr->ic->c_rf);
1039 nvdwtype = fr->ntype;
1040 vdwparam = fr->nbfp;
1041 vdwtype = mdatoms->typeA;
1043 vftab = kernel_data->table_vdw->data;
1044 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
1046 /* Setup water-specific parameters */
1047 inr = nlist->iinr[0];
1048 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1049 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1050 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1051 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1053 jq0 = _mm_set1_ps(charge[inr+0]);
1054 jq1 = _mm_set1_ps(charge[inr+1]);
1055 jq2 = _mm_set1_ps(charge[inr+2]);
1056 vdwjidx0A = 2*vdwtype[inr+0];
1057 qq00 = _mm_mul_ps(iq0,jq0);
1058 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1059 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1060 qq01 = _mm_mul_ps(iq0,jq1);
1061 qq02 = _mm_mul_ps(iq0,jq2);
1062 qq10 = _mm_mul_ps(iq1,jq0);
1063 qq11 = _mm_mul_ps(iq1,jq1);
1064 qq12 = _mm_mul_ps(iq1,jq2);
1065 qq20 = _mm_mul_ps(iq2,jq0);
1066 qq21 = _mm_mul_ps(iq2,jq1);
1067 qq22 = _mm_mul_ps(iq2,jq2);
1069 /* Avoid stupid compiler warnings */
1070 jnrA = jnrB = jnrC = jnrD = 0;
1071 j_coord_offsetA = 0;
1072 j_coord_offsetB = 0;
1073 j_coord_offsetC = 0;
1074 j_coord_offsetD = 0;
1079 for(iidx=0;iidx<4*DIM;iidx++)
1081 scratch[iidx] = 0.0;
1084 /* Start outer loop over neighborlists */
1085 for(iidx=0; iidx<nri; iidx++)
1087 /* Load shift vector for this list */
1088 i_shift_offset = DIM*shiftidx[iidx];
1090 /* Load limits for loop over neighbors */
1091 j_index_start = jindex[iidx];
1092 j_index_end = jindex[iidx+1];
1094 /* Get outer coordinate index */
1096 i_coord_offset = DIM*inr;
1098 /* Load i particle coords and add shift vector */
1099 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1100 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1102 fix0 = _mm_setzero_ps();
1103 fiy0 = _mm_setzero_ps();
1104 fiz0 = _mm_setzero_ps();
1105 fix1 = _mm_setzero_ps();
1106 fiy1 = _mm_setzero_ps();
1107 fiz1 = _mm_setzero_ps();
1108 fix2 = _mm_setzero_ps();
1109 fiy2 = _mm_setzero_ps();
1110 fiz2 = _mm_setzero_ps();
1112 /* Start inner kernel loop */
1113 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1116 /* Get j neighbor index, and coordinate index */
1118 jnrB = jjnr[jidx+1];
1119 jnrC = jjnr[jidx+2];
1120 jnrD = jjnr[jidx+3];
1121 j_coord_offsetA = DIM*jnrA;
1122 j_coord_offsetB = DIM*jnrB;
1123 j_coord_offsetC = DIM*jnrC;
1124 j_coord_offsetD = DIM*jnrD;
1126 /* load j atom coordinates */
1127 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1128 x+j_coord_offsetC,x+j_coord_offsetD,
1129 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1131 /* Calculate displacement vector */
1132 dx00 = _mm_sub_ps(ix0,jx0);
1133 dy00 = _mm_sub_ps(iy0,jy0);
1134 dz00 = _mm_sub_ps(iz0,jz0);
1135 dx01 = _mm_sub_ps(ix0,jx1);
1136 dy01 = _mm_sub_ps(iy0,jy1);
1137 dz01 = _mm_sub_ps(iz0,jz1);
1138 dx02 = _mm_sub_ps(ix0,jx2);
1139 dy02 = _mm_sub_ps(iy0,jy2);
1140 dz02 = _mm_sub_ps(iz0,jz2);
1141 dx10 = _mm_sub_ps(ix1,jx0);
1142 dy10 = _mm_sub_ps(iy1,jy0);
1143 dz10 = _mm_sub_ps(iz1,jz0);
1144 dx11 = _mm_sub_ps(ix1,jx1);
1145 dy11 = _mm_sub_ps(iy1,jy1);
1146 dz11 = _mm_sub_ps(iz1,jz1);
1147 dx12 = _mm_sub_ps(ix1,jx2);
1148 dy12 = _mm_sub_ps(iy1,jy2);
1149 dz12 = _mm_sub_ps(iz1,jz2);
1150 dx20 = _mm_sub_ps(ix2,jx0);
1151 dy20 = _mm_sub_ps(iy2,jy0);
1152 dz20 = _mm_sub_ps(iz2,jz0);
1153 dx21 = _mm_sub_ps(ix2,jx1);
1154 dy21 = _mm_sub_ps(iy2,jy1);
1155 dz21 = _mm_sub_ps(iz2,jz1);
1156 dx22 = _mm_sub_ps(ix2,jx2);
1157 dy22 = _mm_sub_ps(iy2,jy2);
1158 dz22 = _mm_sub_ps(iz2,jz2);
1160 /* Calculate squared distance and things based on it */
1161 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1162 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1163 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1164 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1165 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1166 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1167 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1168 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1169 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1171 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1172 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1173 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1174 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1175 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1176 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1177 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1178 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1179 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1181 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1182 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1183 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1184 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1185 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1186 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1187 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1188 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1189 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1191 fjx0 = _mm_setzero_ps();
1192 fjy0 = _mm_setzero_ps();
1193 fjz0 = _mm_setzero_ps();
1194 fjx1 = _mm_setzero_ps();
1195 fjy1 = _mm_setzero_ps();
1196 fjz1 = _mm_setzero_ps();
1197 fjx2 = _mm_setzero_ps();
1198 fjy2 = _mm_setzero_ps();
1199 fjz2 = _mm_setzero_ps();
1201 /**************************
1202 * CALCULATE INTERACTIONS *
1203 **************************/
1205 r00 = _mm_mul_ps(rsq00,rinv00);
1207 /* Calculate table index by multiplying r with table scale and truncate to integer */
1208 rt = _mm_mul_ps(r00,vftabscale);
1209 vfitab = _mm_cvttps_epi32(rt);
1211 vfeps = _mm_frcz_ps(rt);
1213 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1215 twovfeps = _mm_add_ps(vfeps,vfeps);
1216 vfitab = _mm_slli_epi32(vfitab,3);
1218 /* REACTION-FIELD ELECTROSTATICS */
1219 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1221 /* CUBIC SPLINE TABLE DISPERSION */
1222 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1223 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1224 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1225 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1226 _MM_TRANSPOSE4_PS(Y,F,G,H);
1227 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1228 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1229 fvdw6 = _mm_mul_ps(c6_00,FF);
1231 /* CUBIC SPLINE TABLE REPULSION */
1232 vfitab = _mm_add_epi32(vfitab,ifour);
1233 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1234 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1235 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1236 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1237 _MM_TRANSPOSE4_PS(Y,F,G,H);
1238 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1239 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1240 fvdw12 = _mm_mul_ps(c12_00,FF);
1241 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1243 fscal = _mm_add_ps(felec,fvdw);
1245 /* Update vectorial force */
1246 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1247 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1248 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1250 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1251 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1252 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1254 /**************************
1255 * CALCULATE INTERACTIONS *
1256 **************************/
1258 /* REACTION-FIELD ELECTROSTATICS */
1259 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1263 /* Update vectorial force */
1264 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1265 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1266 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1268 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1269 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1270 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1272 /**************************
1273 * CALCULATE INTERACTIONS *
1274 **************************/
1276 /* REACTION-FIELD ELECTROSTATICS */
1277 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1281 /* Update vectorial force */
1282 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1283 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1284 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1286 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1287 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1288 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1290 /**************************
1291 * CALCULATE INTERACTIONS *
1292 **************************/
1294 /* REACTION-FIELD ELECTROSTATICS */
1295 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1299 /* Update vectorial force */
1300 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1301 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1302 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1304 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1305 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1306 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1308 /**************************
1309 * CALCULATE INTERACTIONS *
1310 **************************/
1312 /* REACTION-FIELD ELECTROSTATICS */
1313 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1317 /* Update vectorial force */
1318 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1319 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1320 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1322 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1323 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1324 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1326 /**************************
1327 * CALCULATE INTERACTIONS *
1328 **************************/
1330 /* REACTION-FIELD ELECTROSTATICS */
1331 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1335 /* Update vectorial force */
1336 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1337 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1338 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1340 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1341 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1342 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1344 /**************************
1345 * CALCULATE INTERACTIONS *
1346 **************************/
1348 /* REACTION-FIELD ELECTROSTATICS */
1349 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1353 /* Update vectorial force */
1354 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1355 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1356 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1358 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1359 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1360 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1362 /**************************
1363 * CALCULATE INTERACTIONS *
1364 **************************/
1366 /* REACTION-FIELD ELECTROSTATICS */
1367 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1371 /* Update vectorial force */
1372 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1373 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1374 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1376 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1377 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1378 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1380 /**************************
1381 * CALCULATE INTERACTIONS *
1382 **************************/
1384 /* REACTION-FIELD ELECTROSTATICS */
1385 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1389 /* Update vectorial force */
1390 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1391 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1392 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1394 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1395 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1396 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1398 fjptrA = f+j_coord_offsetA;
1399 fjptrB = f+j_coord_offsetB;
1400 fjptrC = f+j_coord_offsetC;
1401 fjptrD = f+j_coord_offsetD;
1403 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1404 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1406 /* Inner loop uses 297 flops */
1409 if(jidx<j_index_end)
1412 /* Get j neighbor index, and coordinate index */
1413 jnrlistA = jjnr[jidx];
1414 jnrlistB = jjnr[jidx+1];
1415 jnrlistC = jjnr[jidx+2];
1416 jnrlistD = jjnr[jidx+3];
1417 /* Sign of each element will be negative for non-real atoms.
1418 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1419 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1421 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1422 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1423 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1424 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1425 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1426 j_coord_offsetA = DIM*jnrA;
1427 j_coord_offsetB = DIM*jnrB;
1428 j_coord_offsetC = DIM*jnrC;
1429 j_coord_offsetD = DIM*jnrD;
1431 /* load j atom coordinates */
1432 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1433 x+j_coord_offsetC,x+j_coord_offsetD,
1434 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1436 /* Calculate displacement vector */
1437 dx00 = _mm_sub_ps(ix0,jx0);
1438 dy00 = _mm_sub_ps(iy0,jy0);
1439 dz00 = _mm_sub_ps(iz0,jz0);
1440 dx01 = _mm_sub_ps(ix0,jx1);
1441 dy01 = _mm_sub_ps(iy0,jy1);
1442 dz01 = _mm_sub_ps(iz0,jz1);
1443 dx02 = _mm_sub_ps(ix0,jx2);
1444 dy02 = _mm_sub_ps(iy0,jy2);
1445 dz02 = _mm_sub_ps(iz0,jz2);
1446 dx10 = _mm_sub_ps(ix1,jx0);
1447 dy10 = _mm_sub_ps(iy1,jy0);
1448 dz10 = _mm_sub_ps(iz1,jz0);
1449 dx11 = _mm_sub_ps(ix1,jx1);
1450 dy11 = _mm_sub_ps(iy1,jy1);
1451 dz11 = _mm_sub_ps(iz1,jz1);
1452 dx12 = _mm_sub_ps(ix1,jx2);
1453 dy12 = _mm_sub_ps(iy1,jy2);
1454 dz12 = _mm_sub_ps(iz1,jz2);
1455 dx20 = _mm_sub_ps(ix2,jx0);
1456 dy20 = _mm_sub_ps(iy2,jy0);
1457 dz20 = _mm_sub_ps(iz2,jz0);
1458 dx21 = _mm_sub_ps(ix2,jx1);
1459 dy21 = _mm_sub_ps(iy2,jy1);
1460 dz21 = _mm_sub_ps(iz2,jz1);
1461 dx22 = _mm_sub_ps(ix2,jx2);
1462 dy22 = _mm_sub_ps(iy2,jy2);
1463 dz22 = _mm_sub_ps(iz2,jz2);
1465 /* Calculate squared distance and things based on it */
1466 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1467 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1468 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1469 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1470 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1471 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1472 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1473 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1474 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1476 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1477 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1478 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1479 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1480 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1481 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1482 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1483 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1484 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1486 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1487 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1488 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1489 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1490 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1491 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1492 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1493 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1494 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1496 fjx0 = _mm_setzero_ps();
1497 fjy0 = _mm_setzero_ps();
1498 fjz0 = _mm_setzero_ps();
1499 fjx1 = _mm_setzero_ps();
1500 fjy1 = _mm_setzero_ps();
1501 fjz1 = _mm_setzero_ps();
1502 fjx2 = _mm_setzero_ps();
1503 fjy2 = _mm_setzero_ps();
1504 fjz2 = _mm_setzero_ps();
1506 /**************************
1507 * CALCULATE INTERACTIONS *
1508 **************************/
1510 r00 = _mm_mul_ps(rsq00,rinv00);
1511 r00 = _mm_andnot_ps(dummy_mask,r00);
1513 /* Calculate table index by multiplying r with table scale and truncate to integer */
1514 rt = _mm_mul_ps(r00,vftabscale);
1515 vfitab = _mm_cvttps_epi32(rt);
1517 vfeps = _mm_frcz_ps(rt);
1519 vfeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
1521 twovfeps = _mm_add_ps(vfeps,vfeps);
1522 vfitab = _mm_slli_epi32(vfitab,3);
1524 /* REACTION-FIELD ELECTROSTATICS */
1525 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1527 /* CUBIC SPLINE TABLE DISPERSION */
1528 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1529 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1530 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1531 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1532 _MM_TRANSPOSE4_PS(Y,F,G,H);
1533 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1534 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1535 fvdw6 = _mm_mul_ps(c6_00,FF);
1537 /* CUBIC SPLINE TABLE REPULSION */
1538 vfitab = _mm_add_epi32(vfitab,ifour);
1539 Y = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,0) );
1540 F = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,1) );
1541 G = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,2) );
1542 H = _mm_load_ps( vftab + _mm_extract_epi32(vfitab,3) );
1543 _MM_TRANSPOSE4_PS(Y,F,G,H);
1544 Fp = _mm_macc_ps(vfeps,_mm_macc_ps(H,vfeps,G),F);
1545 FF = _mm_macc_ps(vfeps,_mm_macc_ps(twovfeps,H,G),Fp);
1546 fvdw12 = _mm_mul_ps(c12_00,FF);
1547 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1549 fscal = _mm_add_ps(felec,fvdw);
1551 fscal = _mm_andnot_ps(dummy_mask,fscal);
1553 /* Update vectorial force */
1554 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1555 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1556 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1558 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1559 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1560 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1562 /**************************
1563 * CALCULATE INTERACTIONS *
1564 **************************/
1566 /* REACTION-FIELD ELECTROSTATICS */
1567 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1571 fscal = _mm_andnot_ps(dummy_mask,fscal);
1573 /* Update vectorial force */
1574 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1575 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1576 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1578 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1579 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1580 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1582 /**************************
1583 * CALCULATE INTERACTIONS *
1584 **************************/
1586 /* REACTION-FIELD ELECTROSTATICS */
1587 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1591 fscal = _mm_andnot_ps(dummy_mask,fscal);
1593 /* Update vectorial force */
1594 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1595 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1596 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1598 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1599 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1600 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1602 /**************************
1603 * CALCULATE INTERACTIONS *
1604 **************************/
1606 /* REACTION-FIELD ELECTROSTATICS */
1607 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1611 fscal = _mm_andnot_ps(dummy_mask,fscal);
1613 /* Update vectorial force */
1614 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1615 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1616 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1618 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1619 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1620 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1622 /**************************
1623 * CALCULATE INTERACTIONS *
1624 **************************/
1626 /* REACTION-FIELD ELECTROSTATICS */
1627 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1631 fscal = _mm_andnot_ps(dummy_mask,fscal);
1633 /* Update vectorial force */
1634 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1635 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1636 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1638 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1639 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1640 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1642 /**************************
1643 * CALCULATE INTERACTIONS *
1644 **************************/
1646 /* REACTION-FIELD ELECTROSTATICS */
1647 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1651 fscal = _mm_andnot_ps(dummy_mask,fscal);
1653 /* Update vectorial force */
1654 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1655 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1656 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1658 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1659 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1660 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1662 /**************************
1663 * CALCULATE INTERACTIONS *
1664 **************************/
1666 /* REACTION-FIELD ELECTROSTATICS */
1667 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1671 fscal = _mm_andnot_ps(dummy_mask,fscal);
1673 /* Update vectorial force */
1674 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1675 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1676 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1678 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1679 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1680 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1682 /**************************
1683 * CALCULATE INTERACTIONS *
1684 **************************/
1686 /* REACTION-FIELD ELECTROSTATICS */
1687 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1691 fscal = _mm_andnot_ps(dummy_mask,fscal);
1693 /* Update vectorial force */
1694 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1695 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1696 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1698 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1699 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1700 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1702 /**************************
1703 * CALCULATE INTERACTIONS *
1704 **************************/
1706 /* REACTION-FIELD ELECTROSTATICS */
1707 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1711 fscal = _mm_andnot_ps(dummy_mask,fscal);
1713 /* Update vectorial force */
1714 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1715 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1716 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1718 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1719 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1720 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1722 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1723 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1724 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1725 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1727 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1728 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1730 /* Inner loop uses 298 flops */
1733 /* End of innermost loop */
1735 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1736 f+i_coord_offset,fshift+i_shift_offset);
1738 /* Increment number of inner iterations */
1739 inneriter += j_index_end - j_index_start;
1741 /* Outer loop uses 18 flops */
1744 /* Increment number of outer iterations */
1747 /* Update outer/inner flops */
1749 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*298);