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_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gmx_math_x86_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_avx_128_fma_double
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: CubicSplineTable
56 * Geometry: Water3-Water3
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_VF_avx_128_fma_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
77 int j_coord_offsetA,j_coord_offsetB;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
80 real *shiftvec,*fshift,*x,*f;
81 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 int vdwjidx1A,vdwjidx1B;
91 __m128d jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
92 int vdwjidx2A,vdwjidx2B;
93 __m128d jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
94 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
95 __m128d dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
96 __m128d dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
97 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
98 __m128d dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
99 __m128d dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
100 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
101 __m128d dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
102 __m128d dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
103 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
106 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
109 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
110 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
112 __m128i ifour = _mm_set1_epi32(4);
113 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
115 __m128d dummy_mask,cutoff_mask;
116 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
117 __m128d one = _mm_set1_pd(1.0);
118 __m128d two = _mm_set1_pd(2.0);
124 jindex = nlist->jindex;
126 shiftidx = nlist->shift;
128 shiftvec = fr->shift_vec[0];
129 fshift = fr->fshift[0];
130 facel = _mm_set1_pd(fr->epsfac);
131 charge = mdatoms->chargeA;
132 krf = _mm_set1_pd(fr->ic->k_rf);
133 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
134 crf = _mm_set1_pd(fr->ic->c_rf);
135 nvdwtype = fr->ntype;
137 vdwtype = mdatoms->typeA;
139 vftab = kernel_data->table_vdw->data;
140 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
142 /* Setup water-specific parameters */
143 inr = nlist->iinr[0];
144 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
145 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
146 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
147 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
149 jq0 = _mm_set1_pd(charge[inr+0]);
150 jq1 = _mm_set1_pd(charge[inr+1]);
151 jq2 = _mm_set1_pd(charge[inr+2]);
152 vdwjidx0A = 2*vdwtype[inr+0];
153 qq00 = _mm_mul_pd(iq0,jq0);
154 c6_00 = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A]);
155 c12_00 = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A+1]);
156 qq01 = _mm_mul_pd(iq0,jq1);
157 qq02 = _mm_mul_pd(iq0,jq2);
158 qq10 = _mm_mul_pd(iq1,jq0);
159 qq11 = _mm_mul_pd(iq1,jq1);
160 qq12 = _mm_mul_pd(iq1,jq2);
161 qq20 = _mm_mul_pd(iq2,jq0);
162 qq21 = _mm_mul_pd(iq2,jq1);
163 qq22 = _mm_mul_pd(iq2,jq2);
165 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
166 rcutoff_scalar = fr->rcoulomb;
167 rcutoff = _mm_set1_pd(rcutoff_scalar);
168 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
170 /* Avoid stupid compiler warnings */
178 /* Start outer loop over neighborlists */
179 for(iidx=0; iidx<nri; iidx++)
181 /* Load shift vector for this list */
182 i_shift_offset = DIM*shiftidx[iidx];
184 /* Load limits for loop over neighbors */
185 j_index_start = jindex[iidx];
186 j_index_end = jindex[iidx+1];
188 /* Get outer coordinate index */
190 i_coord_offset = DIM*inr;
192 /* Load i particle coords and add shift vector */
193 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
194 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
196 fix0 = _mm_setzero_pd();
197 fiy0 = _mm_setzero_pd();
198 fiz0 = _mm_setzero_pd();
199 fix1 = _mm_setzero_pd();
200 fiy1 = _mm_setzero_pd();
201 fiz1 = _mm_setzero_pd();
202 fix2 = _mm_setzero_pd();
203 fiy2 = _mm_setzero_pd();
204 fiz2 = _mm_setzero_pd();
206 /* Reset potential sums */
207 velecsum = _mm_setzero_pd();
208 vvdwsum = _mm_setzero_pd();
210 /* Start inner kernel loop */
211 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
214 /* Get j neighbor index, and coordinate index */
217 j_coord_offsetA = DIM*jnrA;
218 j_coord_offsetB = DIM*jnrB;
220 /* load j atom coordinates */
221 gmx_mm_load_3rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
222 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
224 /* Calculate displacement vector */
225 dx00 = _mm_sub_pd(ix0,jx0);
226 dy00 = _mm_sub_pd(iy0,jy0);
227 dz00 = _mm_sub_pd(iz0,jz0);
228 dx01 = _mm_sub_pd(ix0,jx1);
229 dy01 = _mm_sub_pd(iy0,jy1);
230 dz01 = _mm_sub_pd(iz0,jz1);
231 dx02 = _mm_sub_pd(ix0,jx2);
232 dy02 = _mm_sub_pd(iy0,jy2);
233 dz02 = _mm_sub_pd(iz0,jz2);
234 dx10 = _mm_sub_pd(ix1,jx0);
235 dy10 = _mm_sub_pd(iy1,jy0);
236 dz10 = _mm_sub_pd(iz1,jz0);
237 dx11 = _mm_sub_pd(ix1,jx1);
238 dy11 = _mm_sub_pd(iy1,jy1);
239 dz11 = _mm_sub_pd(iz1,jz1);
240 dx12 = _mm_sub_pd(ix1,jx2);
241 dy12 = _mm_sub_pd(iy1,jy2);
242 dz12 = _mm_sub_pd(iz1,jz2);
243 dx20 = _mm_sub_pd(ix2,jx0);
244 dy20 = _mm_sub_pd(iy2,jy0);
245 dz20 = _mm_sub_pd(iz2,jz0);
246 dx21 = _mm_sub_pd(ix2,jx1);
247 dy21 = _mm_sub_pd(iy2,jy1);
248 dz21 = _mm_sub_pd(iz2,jz1);
249 dx22 = _mm_sub_pd(ix2,jx2);
250 dy22 = _mm_sub_pd(iy2,jy2);
251 dz22 = _mm_sub_pd(iz2,jz2);
253 /* Calculate squared distance and things based on it */
254 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
255 rsq01 = gmx_mm_calc_rsq_pd(dx01,dy01,dz01);
256 rsq02 = gmx_mm_calc_rsq_pd(dx02,dy02,dz02);
257 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
258 rsq11 = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
259 rsq12 = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
260 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
261 rsq21 = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
262 rsq22 = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
264 rinv00 = gmx_mm_invsqrt_pd(rsq00);
265 rinv01 = gmx_mm_invsqrt_pd(rsq01);
266 rinv02 = gmx_mm_invsqrt_pd(rsq02);
267 rinv10 = gmx_mm_invsqrt_pd(rsq10);
268 rinv11 = gmx_mm_invsqrt_pd(rsq11);
269 rinv12 = gmx_mm_invsqrt_pd(rsq12);
270 rinv20 = gmx_mm_invsqrt_pd(rsq20);
271 rinv21 = gmx_mm_invsqrt_pd(rsq21);
272 rinv22 = gmx_mm_invsqrt_pd(rsq22);
274 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
275 rinvsq01 = _mm_mul_pd(rinv01,rinv01);
276 rinvsq02 = _mm_mul_pd(rinv02,rinv02);
277 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
278 rinvsq11 = _mm_mul_pd(rinv11,rinv11);
279 rinvsq12 = _mm_mul_pd(rinv12,rinv12);
280 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
281 rinvsq21 = _mm_mul_pd(rinv21,rinv21);
282 rinvsq22 = _mm_mul_pd(rinv22,rinv22);
284 fjx0 = _mm_setzero_pd();
285 fjy0 = _mm_setzero_pd();
286 fjz0 = _mm_setzero_pd();
287 fjx1 = _mm_setzero_pd();
288 fjy1 = _mm_setzero_pd();
289 fjz1 = _mm_setzero_pd();
290 fjx2 = _mm_setzero_pd();
291 fjy2 = _mm_setzero_pd();
292 fjz2 = _mm_setzero_pd();
294 /**************************
295 * CALCULATE INTERACTIONS *
296 **************************/
298 if (gmx_mm_any_lt(rsq00,rcutoff2))
301 r00 = _mm_mul_pd(rsq00,rinv00);
303 /* Calculate table index by multiplying r with table scale and truncate to integer */
304 rt = _mm_mul_pd(r00,vftabscale);
305 vfitab = _mm_cvttpd_epi32(rt);
307 vfeps = _mm_frcz_pd(rt);
309 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
311 twovfeps = _mm_add_pd(vfeps,vfeps);
312 vfitab = _mm_slli_epi32(vfitab,3);
314 /* REACTION-FIELD ELECTROSTATICS */
315 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
316 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
318 /* CUBIC SPLINE TABLE DISPERSION */
319 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
320 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
321 GMX_MM_TRANSPOSE2_PD(Y,F);
322 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
323 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
324 GMX_MM_TRANSPOSE2_PD(G,H);
325 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
326 VV = _mm_macc_pd(vfeps,Fp,Y);
327 vvdw6 = _mm_mul_pd(c6_00,VV);
328 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
329 fvdw6 = _mm_mul_pd(c6_00,FF);
331 /* CUBIC SPLINE TABLE REPULSION */
332 vfitab = _mm_add_epi32(vfitab,ifour);
333 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
334 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
335 GMX_MM_TRANSPOSE2_PD(Y,F);
336 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
337 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
338 GMX_MM_TRANSPOSE2_PD(G,H);
339 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
340 VV = _mm_macc_pd(vfeps,Fp,Y);
341 vvdw12 = _mm_mul_pd(c12_00,VV);
342 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
343 fvdw12 = _mm_mul_pd(c12_00,FF);
344 vvdw = _mm_add_pd(vvdw12,vvdw6);
345 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
347 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
349 /* Update potential sum for this i atom from the interaction with this j atom. */
350 velec = _mm_and_pd(velec,cutoff_mask);
351 velecsum = _mm_add_pd(velecsum,velec);
352 vvdw = _mm_and_pd(vvdw,cutoff_mask);
353 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
355 fscal = _mm_add_pd(felec,fvdw);
357 fscal = _mm_and_pd(fscal,cutoff_mask);
359 /* Update vectorial force */
360 fix0 = _mm_macc_pd(dx00,fscal,fix0);
361 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
362 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
364 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
365 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
366 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
370 /**************************
371 * CALCULATE INTERACTIONS *
372 **************************/
374 if (gmx_mm_any_lt(rsq01,rcutoff2))
377 /* REACTION-FIELD ELECTROSTATICS */
378 velec = _mm_mul_pd(qq01,_mm_sub_pd(_mm_macc_pd(krf,rsq01,rinv01),crf));
379 felec = _mm_mul_pd(qq01,_mm_msub_pd(rinv01,rinvsq01,krf2));
381 cutoff_mask = _mm_cmplt_pd(rsq01,rcutoff2);
383 /* Update potential sum for this i atom from the interaction with this j atom. */
384 velec = _mm_and_pd(velec,cutoff_mask);
385 velecsum = _mm_add_pd(velecsum,velec);
389 fscal = _mm_and_pd(fscal,cutoff_mask);
391 /* Update vectorial force */
392 fix0 = _mm_macc_pd(dx01,fscal,fix0);
393 fiy0 = _mm_macc_pd(dy01,fscal,fiy0);
394 fiz0 = _mm_macc_pd(dz01,fscal,fiz0);
396 fjx1 = _mm_macc_pd(dx01,fscal,fjx1);
397 fjy1 = _mm_macc_pd(dy01,fscal,fjy1);
398 fjz1 = _mm_macc_pd(dz01,fscal,fjz1);
402 /**************************
403 * CALCULATE INTERACTIONS *
404 **************************/
406 if (gmx_mm_any_lt(rsq02,rcutoff2))
409 /* REACTION-FIELD ELECTROSTATICS */
410 velec = _mm_mul_pd(qq02,_mm_sub_pd(_mm_macc_pd(krf,rsq02,rinv02),crf));
411 felec = _mm_mul_pd(qq02,_mm_msub_pd(rinv02,rinvsq02,krf2));
413 cutoff_mask = _mm_cmplt_pd(rsq02,rcutoff2);
415 /* Update potential sum for this i atom from the interaction with this j atom. */
416 velec = _mm_and_pd(velec,cutoff_mask);
417 velecsum = _mm_add_pd(velecsum,velec);
421 fscal = _mm_and_pd(fscal,cutoff_mask);
423 /* Update vectorial force */
424 fix0 = _mm_macc_pd(dx02,fscal,fix0);
425 fiy0 = _mm_macc_pd(dy02,fscal,fiy0);
426 fiz0 = _mm_macc_pd(dz02,fscal,fiz0);
428 fjx2 = _mm_macc_pd(dx02,fscal,fjx2);
429 fjy2 = _mm_macc_pd(dy02,fscal,fjy2);
430 fjz2 = _mm_macc_pd(dz02,fscal,fjz2);
434 /**************************
435 * CALCULATE INTERACTIONS *
436 **************************/
438 if (gmx_mm_any_lt(rsq10,rcutoff2))
441 /* REACTION-FIELD ELECTROSTATICS */
442 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
443 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
445 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
447 /* Update potential sum for this i atom from the interaction with this j atom. */
448 velec = _mm_and_pd(velec,cutoff_mask);
449 velecsum = _mm_add_pd(velecsum,velec);
453 fscal = _mm_and_pd(fscal,cutoff_mask);
455 /* Update vectorial force */
456 fix1 = _mm_macc_pd(dx10,fscal,fix1);
457 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
458 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
460 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
461 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
462 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
466 /**************************
467 * CALCULATE INTERACTIONS *
468 **************************/
470 if (gmx_mm_any_lt(rsq11,rcutoff2))
473 /* REACTION-FIELD ELECTROSTATICS */
474 velec = _mm_mul_pd(qq11,_mm_sub_pd(_mm_macc_pd(krf,rsq11,rinv11),crf));
475 felec = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
477 cutoff_mask = _mm_cmplt_pd(rsq11,rcutoff2);
479 /* Update potential sum for this i atom from the interaction with this j atom. */
480 velec = _mm_and_pd(velec,cutoff_mask);
481 velecsum = _mm_add_pd(velecsum,velec);
485 fscal = _mm_and_pd(fscal,cutoff_mask);
487 /* Update vectorial force */
488 fix1 = _mm_macc_pd(dx11,fscal,fix1);
489 fiy1 = _mm_macc_pd(dy11,fscal,fiy1);
490 fiz1 = _mm_macc_pd(dz11,fscal,fiz1);
492 fjx1 = _mm_macc_pd(dx11,fscal,fjx1);
493 fjy1 = _mm_macc_pd(dy11,fscal,fjy1);
494 fjz1 = _mm_macc_pd(dz11,fscal,fjz1);
498 /**************************
499 * CALCULATE INTERACTIONS *
500 **************************/
502 if (gmx_mm_any_lt(rsq12,rcutoff2))
505 /* REACTION-FIELD ELECTROSTATICS */
506 velec = _mm_mul_pd(qq12,_mm_sub_pd(_mm_macc_pd(krf,rsq12,rinv12),crf));
507 felec = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
509 cutoff_mask = _mm_cmplt_pd(rsq12,rcutoff2);
511 /* Update potential sum for this i atom from the interaction with this j atom. */
512 velec = _mm_and_pd(velec,cutoff_mask);
513 velecsum = _mm_add_pd(velecsum,velec);
517 fscal = _mm_and_pd(fscal,cutoff_mask);
519 /* Update vectorial force */
520 fix1 = _mm_macc_pd(dx12,fscal,fix1);
521 fiy1 = _mm_macc_pd(dy12,fscal,fiy1);
522 fiz1 = _mm_macc_pd(dz12,fscal,fiz1);
524 fjx2 = _mm_macc_pd(dx12,fscal,fjx2);
525 fjy2 = _mm_macc_pd(dy12,fscal,fjy2);
526 fjz2 = _mm_macc_pd(dz12,fscal,fjz2);
530 /**************************
531 * CALCULATE INTERACTIONS *
532 **************************/
534 if (gmx_mm_any_lt(rsq20,rcutoff2))
537 /* REACTION-FIELD ELECTROSTATICS */
538 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
539 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
541 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
543 /* Update potential sum for this i atom from the interaction with this j atom. */
544 velec = _mm_and_pd(velec,cutoff_mask);
545 velecsum = _mm_add_pd(velecsum,velec);
549 fscal = _mm_and_pd(fscal,cutoff_mask);
551 /* Update vectorial force */
552 fix2 = _mm_macc_pd(dx20,fscal,fix2);
553 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
554 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
556 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
557 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
558 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
562 /**************************
563 * CALCULATE INTERACTIONS *
564 **************************/
566 if (gmx_mm_any_lt(rsq21,rcutoff2))
569 /* REACTION-FIELD ELECTROSTATICS */
570 velec = _mm_mul_pd(qq21,_mm_sub_pd(_mm_macc_pd(krf,rsq21,rinv21),crf));
571 felec = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
573 cutoff_mask = _mm_cmplt_pd(rsq21,rcutoff2);
575 /* Update potential sum for this i atom from the interaction with this j atom. */
576 velec = _mm_and_pd(velec,cutoff_mask);
577 velecsum = _mm_add_pd(velecsum,velec);
581 fscal = _mm_and_pd(fscal,cutoff_mask);
583 /* Update vectorial force */
584 fix2 = _mm_macc_pd(dx21,fscal,fix2);
585 fiy2 = _mm_macc_pd(dy21,fscal,fiy2);
586 fiz2 = _mm_macc_pd(dz21,fscal,fiz2);
588 fjx1 = _mm_macc_pd(dx21,fscal,fjx1);
589 fjy1 = _mm_macc_pd(dy21,fscal,fjy1);
590 fjz1 = _mm_macc_pd(dz21,fscal,fjz1);
594 /**************************
595 * CALCULATE INTERACTIONS *
596 **************************/
598 if (gmx_mm_any_lt(rsq22,rcutoff2))
601 /* REACTION-FIELD ELECTROSTATICS */
602 velec = _mm_mul_pd(qq22,_mm_sub_pd(_mm_macc_pd(krf,rsq22,rinv22),crf));
603 felec = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
605 cutoff_mask = _mm_cmplt_pd(rsq22,rcutoff2);
607 /* Update potential sum for this i atom from the interaction with this j atom. */
608 velec = _mm_and_pd(velec,cutoff_mask);
609 velecsum = _mm_add_pd(velecsum,velec);
613 fscal = _mm_and_pd(fscal,cutoff_mask);
615 /* Update vectorial force */
616 fix2 = _mm_macc_pd(dx22,fscal,fix2);
617 fiy2 = _mm_macc_pd(dy22,fscal,fiy2);
618 fiz2 = _mm_macc_pd(dz22,fscal,fiz2);
620 fjx2 = _mm_macc_pd(dx22,fscal,fjx2);
621 fjy2 = _mm_macc_pd(dy22,fscal,fjy2);
622 fjz2 = _mm_macc_pd(dz22,fscal,fjz2);
626 gmx_mm_decrement_3rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
628 /* Inner loop uses 387 flops */
635 j_coord_offsetA = DIM*jnrA;
637 /* load j atom coordinates */
638 gmx_mm_load_3rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
639 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
641 /* Calculate displacement vector */
642 dx00 = _mm_sub_pd(ix0,jx0);
643 dy00 = _mm_sub_pd(iy0,jy0);
644 dz00 = _mm_sub_pd(iz0,jz0);
645 dx01 = _mm_sub_pd(ix0,jx1);
646 dy01 = _mm_sub_pd(iy0,jy1);
647 dz01 = _mm_sub_pd(iz0,jz1);
648 dx02 = _mm_sub_pd(ix0,jx2);
649 dy02 = _mm_sub_pd(iy0,jy2);
650 dz02 = _mm_sub_pd(iz0,jz2);
651 dx10 = _mm_sub_pd(ix1,jx0);
652 dy10 = _mm_sub_pd(iy1,jy0);
653 dz10 = _mm_sub_pd(iz1,jz0);
654 dx11 = _mm_sub_pd(ix1,jx1);
655 dy11 = _mm_sub_pd(iy1,jy1);
656 dz11 = _mm_sub_pd(iz1,jz1);
657 dx12 = _mm_sub_pd(ix1,jx2);
658 dy12 = _mm_sub_pd(iy1,jy2);
659 dz12 = _mm_sub_pd(iz1,jz2);
660 dx20 = _mm_sub_pd(ix2,jx0);
661 dy20 = _mm_sub_pd(iy2,jy0);
662 dz20 = _mm_sub_pd(iz2,jz0);
663 dx21 = _mm_sub_pd(ix2,jx1);
664 dy21 = _mm_sub_pd(iy2,jy1);
665 dz21 = _mm_sub_pd(iz2,jz1);
666 dx22 = _mm_sub_pd(ix2,jx2);
667 dy22 = _mm_sub_pd(iy2,jy2);
668 dz22 = _mm_sub_pd(iz2,jz2);
670 /* Calculate squared distance and things based on it */
671 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
672 rsq01 = gmx_mm_calc_rsq_pd(dx01,dy01,dz01);
673 rsq02 = gmx_mm_calc_rsq_pd(dx02,dy02,dz02);
674 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
675 rsq11 = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
676 rsq12 = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
677 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
678 rsq21 = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
679 rsq22 = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
681 rinv00 = gmx_mm_invsqrt_pd(rsq00);
682 rinv01 = gmx_mm_invsqrt_pd(rsq01);
683 rinv02 = gmx_mm_invsqrt_pd(rsq02);
684 rinv10 = gmx_mm_invsqrt_pd(rsq10);
685 rinv11 = gmx_mm_invsqrt_pd(rsq11);
686 rinv12 = gmx_mm_invsqrt_pd(rsq12);
687 rinv20 = gmx_mm_invsqrt_pd(rsq20);
688 rinv21 = gmx_mm_invsqrt_pd(rsq21);
689 rinv22 = gmx_mm_invsqrt_pd(rsq22);
691 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
692 rinvsq01 = _mm_mul_pd(rinv01,rinv01);
693 rinvsq02 = _mm_mul_pd(rinv02,rinv02);
694 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
695 rinvsq11 = _mm_mul_pd(rinv11,rinv11);
696 rinvsq12 = _mm_mul_pd(rinv12,rinv12);
697 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
698 rinvsq21 = _mm_mul_pd(rinv21,rinv21);
699 rinvsq22 = _mm_mul_pd(rinv22,rinv22);
701 fjx0 = _mm_setzero_pd();
702 fjy0 = _mm_setzero_pd();
703 fjz0 = _mm_setzero_pd();
704 fjx1 = _mm_setzero_pd();
705 fjy1 = _mm_setzero_pd();
706 fjz1 = _mm_setzero_pd();
707 fjx2 = _mm_setzero_pd();
708 fjy2 = _mm_setzero_pd();
709 fjz2 = _mm_setzero_pd();
711 /**************************
712 * CALCULATE INTERACTIONS *
713 **************************/
715 if (gmx_mm_any_lt(rsq00,rcutoff2))
718 r00 = _mm_mul_pd(rsq00,rinv00);
720 /* Calculate table index by multiplying r with table scale and truncate to integer */
721 rt = _mm_mul_pd(r00,vftabscale);
722 vfitab = _mm_cvttpd_epi32(rt);
724 vfeps = _mm_frcz_pd(rt);
726 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
728 twovfeps = _mm_add_pd(vfeps,vfeps);
729 vfitab = _mm_slli_epi32(vfitab,3);
731 /* REACTION-FIELD ELECTROSTATICS */
732 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
733 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
735 /* CUBIC SPLINE TABLE DISPERSION */
736 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
737 F = _mm_setzero_pd();
738 GMX_MM_TRANSPOSE2_PD(Y,F);
739 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
740 H = _mm_setzero_pd();
741 GMX_MM_TRANSPOSE2_PD(G,H);
742 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
743 VV = _mm_macc_pd(vfeps,Fp,Y);
744 vvdw6 = _mm_mul_pd(c6_00,VV);
745 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
746 fvdw6 = _mm_mul_pd(c6_00,FF);
748 /* CUBIC SPLINE TABLE REPULSION */
749 vfitab = _mm_add_epi32(vfitab,ifour);
750 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
751 F = _mm_setzero_pd();
752 GMX_MM_TRANSPOSE2_PD(Y,F);
753 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
754 H = _mm_setzero_pd();
755 GMX_MM_TRANSPOSE2_PD(G,H);
756 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
757 VV = _mm_macc_pd(vfeps,Fp,Y);
758 vvdw12 = _mm_mul_pd(c12_00,VV);
759 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
760 fvdw12 = _mm_mul_pd(c12_00,FF);
761 vvdw = _mm_add_pd(vvdw12,vvdw6);
762 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
764 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
766 /* Update potential sum for this i atom from the interaction with this j atom. */
767 velec = _mm_and_pd(velec,cutoff_mask);
768 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
769 velecsum = _mm_add_pd(velecsum,velec);
770 vvdw = _mm_and_pd(vvdw,cutoff_mask);
771 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
772 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
774 fscal = _mm_add_pd(felec,fvdw);
776 fscal = _mm_and_pd(fscal,cutoff_mask);
778 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
780 /* Update vectorial force */
781 fix0 = _mm_macc_pd(dx00,fscal,fix0);
782 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
783 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
785 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
786 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
787 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
791 /**************************
792 * CALCULATE INTERACTIONS *
793 **************************/
795 if (gmx_mm_any_lt(rsq01,rcutoff2))
798 /* REACTION-FIELD ELECTROSTATICS */
799 velec = _mm_mul_pd(qq01,_mm_sub_pd(_mm_macc_pd(krf,rsq01,rinv01),crf));
800 felec = _mm_mul_pd(qq01,_mm_msub_pd(rinv01,rinvsq01,krf2));
802 cutoff_mask = _mm_cmplt_pd(rsq01,rcutoff2);
804 /* Update potential sum for this i atom from the interaction with this j atom. */
805 velec = _mm_and_pd(velec,cutoff_mask);
806 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
807 velecsum = _mm_add_pd(velecsum,velec);
811 fscal = _mm_and_pd(fscal,cutoff_mask);
813 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
815 /* Update vectorial force */
816 fix0 = _mm_macc_pd(dx01,fscal,fix0);
817 fiy0 = _mm_macc_pd(dy01,fscal,fiy0);
818 fiz0 = _mm_macc_pd(dz01,fscal,fiz0);
820 fjx1 = _mm_macc_pd(dx01,fscal,fjx1);
821 fjy1 = _mm_macc_pd(dy01,fscal,fjy1);
822 fjz1 = _mm_macc_pd(dz01,fscal,fjz1);
826 /**************************
827 * CALCULATE INTERACTIONS *
828 **************************/
830 if (gmx_mm_any_lt(rsq02,rcutoff2))
833 /* REACTION-FIELD ELECTROSTATICS */
834 velec = _mm_mul_pd(qq02,_mm_sub_pd(_mm_macc_pd(krf,rsq02,rinv02),crf));
835 felec = _mm_mul_pd(qq02,_mm_msub_pd(rinv02,rinvsq02,krf2));
837 cutoff_mask = _mm_cmplt_pd(rsq02,rcutoff2);
839 /* Update potential sum for this i atom from the interaction with this j atom. */
840 velec = _mm_and_pd(velec,cutoff_mask);
841 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
842 velecsum = _mm_add_pd(velecsum,velec);
846 fscal = _mm_and_pd(fscal,cutoff_mask);
848 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
850 /* Update vectorial force */
851 fix0 = _mm_macc_pd(dx02,fscal,fix0);
852 fiy0 = _mm_macc_pd(dy02,fscal,fiy0);
853 fiz0 = _mm_macc_pd(dz02,fscal,fiz0);
855 fjx2 = _mm_macc_pd(dx02,fscal,fjx2);
856 fjy2 = _mm_macc_pd(dy02,fscal,fjy2);
857 fjz2 = _mm_macc_pd(dz02,fscal,fjz2);
861 /**************************
862 * CALCULATE INTERACTIONS *
863 **************************/
865 if (gmx_mm_any_lt(rsq10,rcutoff2))
868 /* REACTION-FIELD ELECTROSTATICS */
869 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
870 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
872 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
874 /* Update potential sum for this i atom from the interaction with this j atom. */
875 velec = _mm_and_pd(velec,cutoff_mask);
876 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
877 velecsum = _mm_add_pd(velecsum,velec);
881 fscal = _mm_and_pd(fscal,cutoff_mask);
883 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
885 /* Update vectorial force */
886 fix1 = _mm_macc_pd(dx10,fscal,fix1);
887 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
888 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
890 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
891 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
892 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
896 /**************************
897 * CALCULATE INTERACTIONS *
898 **************************/
900 if (gmx_mm_any_lt(rsq11,rcutoff2))
903 /* REACTION-FIELD ELECTROSTATICS */
904 velec = _mm_mul_pd(qq11,_mm_sub_pd(_mm_macc_pd(krf,rsq11,rinv11),crf));
905 felec = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
907 cutoff_mask = _mm_cmplt_pd(rsq11,rcutoff2);
909 /* Update potential sum for this i atom from the interaction with this j atom. */
910 velec = _mm_and_pd(velec,cutoff_mask);
911 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
912 velecsum = _mm_add_pd(velecsum,velec);
916 fscal = _mm_and_pd(fscal,cutoff_mask);
918 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
920 /* Update vectorial force */
921 fix1 = _mm_macc_pd(dx11,fscal,fix1);
922 fiy1 = _mm_macc_pd(dy11,fscal,fiy1);
923 fiz1 = _mm_macc_pd(dz11,fscal,fiz1);
925 fjx1 = _mm_macc_pd(dx11,fscal,fjx1);
926 fjy1 = _mm_macc_pd(dy11,fscal,fjy1);
927 fjz1 = _mm_macc_pd(dz11,fscal,fjz1);
931 /**************************
932 * CALCULATE INTERACTIONS *
933 **************************/
935 if (gmx_mm_any_lt(rsq12,rcutoff2))
938 /* REACTION-FIELD ELECTROSTATICS */
939 velec = _mm_mul_pd(qq12,_mm_sub_pd(_mm_macc_pd(krf,rsq12,rinv12),crf));
940 felec = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
942 cutoff_mask = _mm_cmplt_pd(rsq12,rcutoff2);
944 /* Update potential sum for this i atom from the interaction with this j atom. */
945 velec = _mm_and_pd(velec,cutoff_mask);
946 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
947 velecsum = _mm_add_pd(velecsum,velec);
951 fscal = _mm_and_pd(fscal,cutoff_mask);
953 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
955 /* Update vectorial force */
956 fix1 = _mm_macc_pd(dx12,fscal,fix1);
957 fiy1 = _mm_macc_pd(dy12,fscal,fiy1);
958 fiz1 = _mm_macc_pd(dz12,fscal,fiz1);
960 fjx2 = _mm_macc_pd(dx12,fscal,fjx2);
961 fjy2 = _mm_macc_pd(dy12,fscal,fjy2);
962 fjz2 = _mm_macc_pd(dz12,fscal,fjz2);
966 /**************************
967 * CALCULATE INTERACTIONS *
968 **************************/
970 if (gmx_mm_any_lt(rsq20,rcutoff2))
973 /* REACTION-FIELD ELECTROSTATICS */
974 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
975 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
977 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
979 /* Update potential sum for this i atom from the interaction with this j atom. */
980 velec = _mm_and_pd(velec,cutoff_mask);
981 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
982 velecsum = _mm_add_pd(velecsum,velec);
986 fscal = _mm_and_pd(fscal,cutoff_mask);
988 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
990 /* Update vectorial force */
991 fix2 = _mm_macc_pd(dx20,fscal,fix2);
992 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
993 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
995 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
996 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
997 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1001 /**************************
1002 * CALCULATE INTERACTIONS *
1003 **************************/
1005 if (gmx_mm_any_lt(rsq21,rcutoff2))
1008 /* REACTION-FIELD ELECTROSTATICS */
1009 velec = _mm_mul_pd(qq21,_mm_sub_pd(_mm_macc_pd(krf,rsq21,rinv21),crf));
1010 felec = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
1012 cutoff_mask = _mm_cmplt_pd(rsq21,rcutoff2);
1014 /* Update potential sum for this i atom from the interaction with this j atom. */
1015 velec = _mm_and_pd(velec,cutoff_mask);
1016 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
1017 velecsum = _mm_add_pd(velecsum,velec);
1021 fscal = _mm_and_pd(fscal,cutoff_mask);
1023 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1025 /* Update vectorial force */
1026 fix2 = _mm_macc_pd(dx21,fscal,fix2);
1027 fiy2 = _mm_macc_pd(dy21,fscal,fiy2);
1028 fiz2 = _mm_macc_pd(dz21,fscal,fiz2);
1030 fjx1 = _mm_macc_pd(dx21,fscal,fjx1);
1031 fjy1 = _mm_macc_pd(dy21,fscal,fjy1);
1032 fjz1 = _mm_macc_pd(dz21,fscal,fjz1);
1036 /**************************
1037 * CALCULATE INTERACTIONS *
1038 **************************/
1040 if (gmx_mm_any_lt(rsq22,rcutoff2))
1043 /* REACTION-FIELD ELECTROSTATICS */
1044 velec = _mm_mul_pd(qq22,_mm_sub_pd(_mm_macc_pd(krf,rsq22,rinv22),crf));
1045 felec = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
1047 cutoff_mask = _mm_cmplt_pd(rsq22,rcutoff2);
1049 /* Update potential sum for this i atom from the interaction with this j atom. */
1050 velec = _mm_and_pd(velec,cutoff_mask);
1051 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
1052 velecsum = _mm_add_pd(velecsum,velec);
1056 fscal = _mm_and_pd(fscal,cutoff_mask);
1058 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1060 /* Update vectorial force */
1061 fix2 = _mm_macc_pd(dx22,fscal,fix2);
1062 fiy2 = _mm_macc_pd(dy22,fscal,fiy2);
1063 fiz2 = _mm_macc_pd(dz22,fscal,fiz2);
1065 fjx2 = _mm_macc_pd(dx22,fscal,fjx2);
1066 fjy2 = _mm_macc_pd(dy22,fscal,fjy2);
1067 fjz2 = _mm_macc_pd(dz22,fscal,fjz2);
1071 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1073 /* Inner loop uses 387 flops */
1076 /* End of innermost loop */
1078 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1079 f+i_coord_offset,fshift+i_shift_offset);
1082 /* Update potential energies */
1083 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
1084 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
1086 /* Increment number of inner iterations */
1087 inneriter += j_index_end - j_index_start;
1089 /* Outer loop uses 20 flops */
1092 /* Increment number of outer iterations */
1095 /* Update outer/inner flops */
1097 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*387);
1100 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_128_fma_double
1101 * Electrostatics interaction: ReactionField
1102 * VdW interaction: CubicSplineTable
1103 * Geometry: Water3-Water3
1104 * Calculate force/pot: Force
1107 nb_kernel_ElecRFCut_VdwCSTab_GeomW3W3_F_avx_128_fma_double
1108 (t_nblist * gmx_restrict nlist,
1109 rvec * gmx_restrict xx,
1110 rvec * gmx_restrict ff,
1111 t_forcerec * gmx_restrict fr,
1112 t_mdatoms * gmx_restrict mdatoms,
1113 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1114 t_nrnb * gmx_restrict nrnb)
1116 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1117 * just 0 for non-waters.
1118 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
1119 * jnr indices corresponding to data put in the four positions in the SIMD register.
1121 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1122 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1124 int j_coord_offsetA,j_coord_offsetB;
1125 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1126 real rcutoff_scalar;
1127 real *shiftvec,*fshift,*x,*f;
1128 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1130 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1132 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1134 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1135 int vdwjidx0A,vdwjidx0B;
1136 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1137 int vdwjidx1A,vdwjidx1B;
1138 __m128d jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1139 int vdwjidx2A,vdwjidx2B;
1140 __m128d jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1141 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1142 __m128d dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1143 __m128d dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1144 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1145 __m128d dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1146 __m128d dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1147 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1148 __m128d dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1149 __m128d dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1150 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
1153 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1156 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
1157 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
1159 __m128i ifour = _mm_set1_epi32(4);
1160 __m128d rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
1162 __m128d dummy_mask,cutoff_mask;
1163 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
1164 __m128d one = _mm_set1_pd(1.0);
1165 __m128d two = _mm_set1_pd(2.0);
1171 jindex = nlist->jindex;
1173 shiftidx = nlist->shift;
1175 shiftvec = fr->shift_vec[0];
1176 fshift = fr->fshift[0];
1177 facel = _mm_set1_pd(fr->epsfac);
1178 charge = mdatoms->chargeA;
1179 krf = _mm_set1_pd(fr->ic->k_rf);
1180 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
1181 crf = _mm_set1_pd(fr->ic->c_rf);
1182 nvdwtype = fr->ntype;
1183 vdwparam = fr->nbfp;
1184 vdwtype = mdatoms->typeA;
1186 vftab = kernel_data->table_vdw->data;
1187 vftabscale = _mm_set1_pd(kernel_data->table_vdw->scale);
1189 /* Setup water-specific parameters */
1190 inr = nlist->iinr[0];
1191 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
1192 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
1193 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
1194 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1196 jq0 = _mm_set1_pd(charge[inr+0]);
1197 jq1 = _mm_set1_pd(charge[inr+1]);
1198 jq2 = _mm_set1_pd(charge[inr+2]);
1199 vdwjidx0A = 2*vdwtype[inr+0];
1200 qq00 = _mm_mul_pd(iq0,jq0);
1201 c6_00 = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A]);
1202 c12_00 = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A+1]);
1203 qq01 = _mm_mul_pd(iq0,jq1);
1204 qq02 = _mm_mul_pd(iq0,jq2);
1205 qq10 = _mm_mul_pd(iq1,jq0);
1206 qq11 = _mm_mul_pd(iq1,jq1);
1207 qq12 = _mm_mul_pd(iq1,jq2);
1208 qq20 = _mm_mul_pd(iq2,jq0);
1209 qq21 = _mm_mul_pd(iq2,jq1);
1210 qq22 = _mm_mul_pd(iq2,jq2);
1212 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1213 rcutoff_scalar = fr->rcoulomb;
1214 rcutoff = _mm_set1_pd(rcutoff_scalar);
1215 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
1217 /* Avoid stupid compiler warnings */
1219 j_coord_offsetA = 0;
1220 j_coord_offsetB = 0;
1225 /* Start outer loop over neighborlists */
1226 for(iidx=0; iidx<nri; iidx++)
1228 /* Load shift vector for this list */
1229 i_shift_offset = DIM*shiftidx[iidx];
1231 /* Load limits for loop over neighbors */
1232 j_index_start = jindex[iidx];
1233 j_index_end = jindex[iidx+1];
1235 /* Get outer coordinate index */
1237 i_coord_offset = DIM*inr;
1239 /* Load i particle coords and add shift vector */
1240 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
1241 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1243 fix0 = _mm_setzero_pd();
1244 fiy0 = _mm_setzero_pd();
1245 fiz0 = _mm_setzero_pd();
1246 fix1 = _mm_setzero_pd();
1247 fiy1 = _mm_setzero_pd();
1248 fiz1 = _mm_setzero_pd();
1249 fix2 = _mm_setzero_pd();
1250 fiy2 = _mm_setzero_pd();
1251 fiz2 = _mm_setzero_pd();
1253 /* Start inner kernel loop */
1254 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
1257 /* Get j neighbor index, and coordinate index */
1259 jnrB = jjnr[jidx+1];
1260 j_coord_offsetA = DIM*jnrA;
1261 j_coord_offsetB = DIM*jnrB;
1263 /* load j atom coordinates */
1264 gmx_mm_load_3rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
1265 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1267 /* Calculate displacement vector */
1268 dx00 = _mm_sub_pd(ix0,jx0);
1269 dy00 = _mm_sub_pd(iy0,jy0);
1270 dz00 = _mm_sub_pd(iz0,jz0);
1271 dx01 = _mm_sub_pd(ix0,jx1);
1272 dy01 = _mm_sub_pd(iy0,jy1);
1273 dz01 = _mm_sub_pd(iz0,jz1);
1274 dx02 = _mm_sub_pd(ix0,jx2);
1275 dy02 = _mm_sub_pd(iy0,jy2);
1276 dz02 = _mm_sub_pd(iz0,jz2);
1277 dx10 = _mm_sub_pd(ix1,jx0);
1278 dy10 = _mm_sub_pd(iy1,jy0);
1279 dz10 = _mm_sub_pd(iz1,jz0);
1280 dx11 = _mm_sub_pd(ix1,jx1);
1281 dy11 = _mm_sub_pd(iy1,jy1);
1282 dz11 = _mm_sub_pd(iz1,jz1);
1283 dx12 = _mm_sub_pd(ix1,jx2);
1284 dy12 = _mm_sub_pd(iy1,jy2);
1285 dz12 = _mm_sub_pd(iz1,jz2);
1286 dx20 = _mm_sub_pd(ix2,jx0);
1287 dy20 = _mm_sub_pd(iy2,jy0);
1288 dz20 = _mm_sub_pd(iz2,jz0);
1289 dx21 = _mm_sub_pd(ix2,jx1);
1290 dy21 = _mm_sub_pd(iy2,jy1);
1291 dz21 = _mm_sub_pd(iz2,jz1);
1292 dx22 = _mm_sub_pd(ix2,jx2);
1293 dy22 = _mm_sub_pd(iy2,jy2);
1294 dz22 = _mm_sub_pd(iz2,jz2);
1296 /* Calculate squared distance and things based on it */
1297 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1298 rsq01 = gmx_mm_calc_rsq_pd(dx01,dy01,dz01);
1299 rsq02 = gmx_mm_calc_rsq_pd(dx02,dy02,dz02);
1300 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
1301 rsq11 = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
1302 rsq12 = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
1303 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
1304 rsq21 = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
1305 rsq22 = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
1307 rinv00 = gmx_mm_invsqrt_pd(rsq00);
1308 rinv01 = gmx_mm_invsqrt_pd(rsq01);
1309 rinv02 = gmx_mm_invsqrt_pd(rsq02);
1310 rinv10 = gmx_mm_invsqrt_pd(rsq10);
1311 rinv11 = gmx_mm_invsqrt_pd(rsq11);
1312 rinv12 = gmx_mm_invsqrt_pd(rsq12);
1313 rinv20 = gmx_mm_invsqrt_pd(rsq20);
1314 rinv21 = gmx_mm_invsqrt_pd(rsq21);
1315 rinv22 = gmx_mm_invsqrt_pd(rsq22);
1317 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
1318 rinvsq01 = _mm_mul_pd(rinv01,rinv01);
1319 rinvsq02 = _mm_mul_pd(rinv02,rinv02);
1320 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
1321 rinvsq11 = _mm_mul_pd(rinv11,rinv11);
1322 rinvsq12 = _mm_mul_pd(rinv12,rinv12);
1323 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
1324 rinvsq21 = _mm_mul_pd(rinv21,rinv21);
1325 rinvsq22 = _mm_mul_pd(rinv22,rinv22);
1327 fjx0 = _mm_setzero_pd();
1328 fjy0 = _mm_setzero_pd();
1329 fjz0 = _mm_setzero_pd();
1330 fjx1 = _mm_setzero_pd();
1331 fjy1 = _mm_setzero_pd();
1332 fjz1 = _mm_setzero_pd();
1333 fjx2 = _mm_setzero_pd();
1334 fjy2 = _mm_setzero_pd();
1335 fjz2 = _mm_setzero_pd();
1337 /**************************
1338 * CALCULATE INTERACTIONS *
1339 **************************/
1341 if (gmx_mm_any_lt(rsq00,rcutoff2))
1344 r00 = _mm_mul_pd(rsq00,rinv00);
1346 /* Calculate table index by multiplying r with table scale and truncate to integer */
1347 rt = _mm_mul_pd(r00,vftabscale);
1348 vfitab = _mm_cvttpd_epi32(rt);
1350 vfeps = _mm_frcz_pd(rt);
1352 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
1354 twovfeps = _mm_add_pd(vfeps,vfeps);
1355 vfitab = _mm_slli_epi32(vfitab,3);
1357 /* REACTION-FIELD ELECTROSTATICS */
1358 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
1360 /* CUBIC SPLINE TABLE DISPERSION */
1361 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
1362 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
1363 GMX_MM_TRANSPOSE2_PD(Y,F);
1364 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
1365 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
1366 GMX_MM_TRANSPOSE2_PD(G,H);
1367 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
1368 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
1369 fvdw6 = _mm_mul_pd(c6_00,FF);
1371 /* CUBIC SPLINE TABLE REPULSION */
1372 vfitab = _mm_add_epi32(vfitab,ifour);
1373 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
1374 F = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) );
1375 GMX_MM_TRANSPOSE2_PD(Y,F);
1376 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
1377 H = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,1) +2);
1378 GMX_MM_TRANSPOSE2_PD(G,H);
1379 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
1380 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
1381 fvdw12 = _mm_mul_pd(c12_00,FF);
1382 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
1384 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
1386 fscal = _mm_add_pd(felec,fvdw);
1388 fscal = _mm_and_pd(fscal,cutoff_mask);
1390 /* Update vectorial force */
1391 fix0 = _mm_macc_pd(dx00,fscal,fix0);
1392 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
1393 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
1395 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
1396 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
1397 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
1401 /**************************
1402 * CALCULATE INTERACTIONS *
1403 **************************/
1405 if (gmx_mm_any_lt(rsq01,rcutoff2))
1408 /* REACTION-FIELD ELECTROSTATICS */
1409 felec = _mm_mul_pd(qq01,_mm_msub_pd(rinv01,rinvsq01,krf2));
1411 cutoff_mask = _mm_cmplt_pd(rsq01,rcutoff2);
1415 fscal = _mm_and_pd(fscal,cutoff_mask);
1417 /* Update vectorial force */
1418 fix0 = _mm_macc_pd(dx01,fscal,fix0);
1419 fiy0 = _mm_macc_pd(dy01,fscal,fiy0);
1420 fiz0 = _mm_macc_pd(dz01,fscal,fiz0);
1422 fjx1 = _mm_macc_pd(dx01,fscal,fjx1);
1423 fjy1 = _mm_macc_pd(dy01,fscal,fjy1);
1424 fjz1 = _mm_macc_pd(dz01,fscal,fjz1);
1428 /**************************
1429 * CALCULATE INTERACTIONS *
1430 **************************/
1432 if (gmx_mm_any_lt(rsq02,rcutoff2))
1435 /* REACTION-FIELD ELECTROSTATICS */
1436 felec = _mm_mul_pd(qq02,_mm_msub_pd(rinv02,rinvsq02,krf2));
1438 cutoff_mask = _mm_cmplt_pd(rsq02,rcutoff2);
1442 fscal = _mm_and_pd(fscal,cutoff_mask);
1444 /* Update vectorial force */
1445 fix0 = _mm_macc_pd(dx02,fscal,fix0);
1446 fiy0 = _mm_macc_pd(dy02,fscal,fiy0);
1447 fiz0 = _mm_macc_pd(dz02,fscal,fiz0);
1449 fjx2 = _mm_macc_pd(dx02,fscal,fjx2);
1450 fjy2 = _mm_macc_pd(dy02,fscal,fjy2);
1451 fjz2 = _mm_macc_pd(dz02,fscal,fjz2);
1455 /**************************
1456 * CALCULATE INTERACTIONS *
1457 **************************/
1459 if (gmx_mm_any_lt(rsq10,rcutoff2))
1462 /* REACTION-FIELD ELECTROSTATICS */
1463 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
1465 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1469 fscal = _mm_and_pd(fscal,cutoff_mask);
1471 /* Update vectorial force */
1472 fix1 = _mm_macc_pd(dx10,fscal,fix1);
1473 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1474 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1476 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1477 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1478 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1482 /**************************
1483 * CALCULATE INTERACTIONS *
1484 **************************/
1486 if (gmx_mm_any_lt(rsq11,rcutoff2))
1489 /* REACTION-FIELD ELECTROSTATICS */
1490 felec = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
1492 cutoff_mask = _mm_cmplt_pd(rsq11,rcutoff2);
1496 fscal = _mm_and_pd(fscal,cutoff_mask);
1498 /* Update vectorial force */
1499 fix1 = _mm_macc_pd(dx11,fscal,fix1);
1500 fiy1 = _mm_macc_pd(dy11,fscal,fiy1);
1501 fiz1 = _mm_macc_pd(dz11,fscal,fiz1);
1503 fjx1 = _mm_macc_pd(dx11,fscal,fjx1);
1504 fjy1 = _mm_macc_pd(dy11,fscal,fjy1);
1505 fjz1 = _mm_macc_pd(dz11,fscal,fjz1);
1509 /**************************
1510 * CALCULATE INTERACTIONS *
1511 **************************/
1513 if (gmx_mm_any_lt(rsq12,rcutoff2))
1516 /* REACTION-FIELD ELECTROSTATICS */
1517 felec = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
1519 cutoff_mask = _mm_cmplt_pd(rsq12,rcutoff2);
1523 fscal = _mm_and_pd(fscal,cutoff_mask);
1525 /* Update vectorial force */
1526 fix1 = _mm_macc_pd(dx12,fscal,fix1);
1527 fiy1 = _mm_macc_pd(dy12,fscal,fiy1);
1528 fiz1 = _mm_macc_pd(dz12,fscal,fiz1);
1530 fjx2 = _mm_macc_pd(dx12,fscal,fjx2);
1531 fjy2 = _mm_macc_pd(dy12,fscal,fjy2);
1532 fjz2 = _mm_macc_pd(dz12,fscal,fjz2);
1536 /**************************
1537 * CALCULATE INTERACTIONS *
1538 **************************/
1540 if (gmx_mm_any_lt(rsq20,rcutoff2))
1543 /* REACTION-FIELD ELECTROSTATICS */
1544 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1546 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1550 fscal = _mm_and_pd(fscal,cutoff_mask);
1552 /* Update vectorial force */
1553 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1554 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1555 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1557 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1558 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1559 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1563 /**************************
1564 * CALCULATE INTERACTIONS *
1565 **************************/
1567 if (gmx_mm_any_lt(rsq21,rcutoff2))
1570 /* REACTION-FIELD ELECTROSTATICS */
1571 felec = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
1573 cutoff_mask = _mm_cmplt_pd(rsq21,rcutoff2);
1577 fscal = _mm_and_pd(fscal,cutoff_mask);
1579 /* Update vectorial force */
1580 fix2 = _mm_macc_pd(dx21,fscal,fix2);
1581 fiy2 = _mm_macc_pd(dy21,fscal,fiy2);
1582 fiz2 = _mm_macc_pd(dz21,fscal,fiz2);
1584 fjx1 = _mm_macc_pd(dx21,fscal,fjx1);
1585 fjy1 = _mm_macc_pd(dy21,fscal,fjy1);
1586 fjz1 = _mm_macc_pd(dz21,fscal,fjz1);
1590 /**************************
1591 * CALCULATE INTERACTIONS *
1592 **************************/
1594 if (gmx_mm_any_lt(rsq22,rcutoff2))
1597 /* REACTION-FIELD ELECTROSTATICS */
1598 felec = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
1600 cutoff_mask = _mm_cmplt_pd(rsq22,rcutoff2);
1604 fscal = _mm_and_pd(fscal,cutoff_mask);
1606 /* Update vectorial force */
1607 fix2 = _mm_macc_pd(dx22,fscal,fix2);
1608 fiy2 = _mm_macc_pd(dy22,fscal,fiy2);
1609 fiz2 = _mm_macc_pd(dz22,fscal,fiz2);
1611 fjx2 = _mm_macc_pd(dx22,fscal,fjx2);
1612 fjy2 = _mm_macc_pd(dy22,fscal,fjy2);
1613 fjz2 = _mm_macc_pd(dz22,fscal,fjz2);
1617 gmx_mm_decrement_3rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1619 /* Inner loop uses 324 flops */
1622 if(jidx<j_index_end)
1626 j_coord_offsetA = DIM*jnrA;
1628 /* load j atom coordinates */
1629 gmx_mm_load_3rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
1630 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1632 /* Calculate displacement vector */
1633 dx00 = _mm_sub_pd(ix0,jx0);
1634 dy00 = _mm_sub_pd(iy0,jy0);
1635 dz00 = _mm_sub_pd(iz0,jz0);
1636 dx01 = _mm_sub_pd(ix0,jx1);
1637 dy01 = _mm_sub_pd(iy0,jy1);
1638 dz01 = _mm_sub_pd(iz0,jz1);
1639 dx02 = _mm_sub_pd(ix0,jx2);
1640 dy02 = _mm_sub_pd(iy0,jy2);
1641 dz02 = _mm_sub_pd(iz0,jz2);
1642 dx10 = _mm_sub_pd(ix1,jx0);
1643 dy10 = _mm_sub_pd(iy1,jy0);
1644 dz10 = _mm_sub_pd(iz1,jz0);
1645 dx11 = _mm_sub_pd(ix1,jx1);
1646 dy11 = _mm_sub_pd(iy1,jy1);
1647 dz11 = _mm_sub_pd(iz1,jz1);
1648 dx12 = _mm_sub_pd(ix1,jx2);
1649 dy12 = _mm_sub_pd(iy1,jy2);
1650 dz12 = _mm_sub_pd(iz1,jz2);
1651 dx20 = _mm_sub_pd(ix2,jx0);
1652 dy20 = _mm_sub_pd(iy2,jy0);
1653 dz20 = _mm_sub_pd(iz2,jz0);
1654 dx21 = _mm_sub_pd(ix2,jx1);
1655 dy21 = _mm_sub_pd(iy2,jy1);
1656 dz21 = _mm_sub_pd(iz2,jz1);
1657 dx22 = _mm_sub_pd(ix2,jx2);
1658 dy22 = _mm_sub_pd(iy2,jy2);
1659 dz22 = _mm_sub_pd(iz2,jz2);
1661 /* Calculate squared distance and things based on it */
1662 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1663 rsq01 = gmx_mm_calc_rsq_pd(dx01,dy01,dz01);
1664 rsq02 = gmx_mm_calc_rsq_pd(dx02,dy02,dz02);
1665 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
1666 rsq11 = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
1667 rsq12 = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
1668 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
1669 rsq21 = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
1670 rsq22 = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
1672 rinv00 = gmx_mm_invsqrt_pd(rsq00);
1673 rinv01 = gmx_mm_invsqrt_pd(rsq01);
1674 rinv02 = gmx_mm_invsqrt_pd(rsq02);
1675 rinv10 = gmx_mm_invsqrt_pd(rsq10);
1676 rinv11 = gmx_mm_invsqrt_pd(rsq11);
1677 rinv12 = gmx_mm_invsqrt_pd(rsq12);
1678 rinv20 = gmx_mm_invsqrt_pd(rsq20);
1679 rinv21 = gmx_mm_invsqrt_pd(rsq21);
1680 rinv22 = gmx_mm_invsqrt_pd(rsq22);
1682 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
1683 rinvsq01 = _mm_mul_pd(rinv01,rinv01);
1684 rinvsq02 = _mm_mul_pd(rinv02,rinv02);
1685 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
1686 rinvsq11 = _mm_mul_pd(rinv11,rinv11);
1687 rinvsq12 = _mm_mul_pd(rinv12,rinv12);
1688 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
1689 rinvsq21 = _mm_mul_pd(rinv21,rinv21);
1690 rinvsq22 = _mm_mul_pd(rinv22,rinv22);
1692 fjx0 = _mm_setzero_pd();
1693 fjy0 = _mm_setzero_pd();
1694 fjz0 = _mm_setzero_pd();
1695 fjx1 = _mm_setzero_pd();
1696 fjy1 = _mm_setzero_pd();
1697 fjz1 = _mm_setzero_pd();
1698 fjx2 = _mm_setzero_pd();
1699 fjy2 = _mm_setzero_pd();
1700 fjz2 = _mm_setzero_pd();
1702 /**************************
1703 * CALCULATE INTERACTIONS *
1704 **************************/
1706 if (gmx_mm_any_lt(rsq00,rcutoff2))
1709 r00 = _mm_mul_pd(rsq00,rinv00);
1711 /* Calculate table index by multiplying r with table scale and truncate to integer */
1712 rt = _mm_mul_pd(r00,vftabscale);
1713 vfitab = _mm_cvttpd_epi32(rt);
1715 vfeps = _mm_frcz_pd(rt);
1717 vfeps = _mm_sub_pd(rt,_mm_round_pd(rt, _MM_FROUND_FLOOR));
1719 twovfeps = _mm_add_pd(vfeps,vfeps);
1720 vfitab = _mm_slli_epi32(vfitab,3);
1722 /* REACTION-FIELD ELECTROSTATICS */
1723 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
1725 /* CUBIC SPLINE TABLE DISPERSION */
1726 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
1727 F = _mm_setzero_pd();
1728 GMX_MM_TRANSPOSE2_PD(Y,F);
1729 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
1730 H = _mm_setzero_pd();
1731 GMX_MM_TRANSPOSE2_PD(G,H);
1732 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
1733 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
1734 fvdw6 = _mm_mul_pd(c6_00,FF);
1736 /* CUBIC SPLINE TABLE REPULSION */
1737 vfitab = _mm_add_epi32(vfitab,ifour);
1738 Y = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) );
1739 F = _mm_setzero_pd();
1740 GMX_MM_TRANSPOSE2_PD(Y,F);
1741 G = _mm_load_pd( vftab + _mm_extract_epi32(vfitab,0) +2);
1742 H = _mm_setzero_pd();
1743 GMX_MM_TRANSPOSE2_PD(G,H);
1744 Fp = _mm_macc_pd(vfeps,_mm_macc_pd(H,vfeps,G),F);
1745 FF = _mm_macc_pd(vfeps,_mm_macc_pd(twovfeps,H,G),Fp);
1746 fvdw12 = _mm_mul_pd(c12_00,FF);
1747 fvdw = _mm_xor_pd(signbit,_mm_mul_pd(_mm_add_pd(fvdw6,fvdw12),_mm_mul_pd(vftabscale,rinv00)));
1749 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
1751 fscal = _mm_add_pd(felec,fvdw);
1753 fscal = _mm_and_pd(fscal,cutoff_mask);
1755 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1757 /* Update vectorial force */
1758 fix0 = _mm_macc_pd(dx00,fscal,fix0);
1759 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
1760 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
1762 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
1763 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
1764 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
1768 /**************************
1769 * CALCULATE INTERACTIONS *
1770 **************************/
1772 if (gmx_mm_any_lt(rsq01,rcutoff2))
1775 /* REACTION-FIELD ELECTROSTATICS */
1776 felec = _mm_mul_pd(qq01,_mm_msub_pd(rinv01,rinvsq01,krf2));
1778 cutoff_mask = _mm_cmplt_pd(rsq01,rcutoff2);
1782 fscal = _mm_and_pd(fscal,cutoff_mask);
1784 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1786 /* Update vectorial force */
1787 fix0 = _mm_macc_pd(dx01,fscal,fix0);
1788 fiy0 = _mm_macc_pd(dy01,fscal,fiy0);
1789 fiz0 = _mm_macc_pd(dz01,fscal,fiz0);
1791 fjx1 = _mm_macc_pd(dx01,fscal,fjx1);
1792 fjy1 = _mm_macc_pd(dy01,fscal,fjy1);
1793 fjz1 = _mm_macc_pd(dz01,fscal,fjz1);
1797 /**************************
1798 * CALCULATE INTERACTIONS *
1799 **************************/
1801 if (gmx_mm_any_lt(rsq02,rcutoff2))
1804 /* REACTION-FIELD ELECTROSTATICS */
1805 felec = _mm_mul_pd(qq02,_mm_msub_pd(rinv02,rinvsq02,krf2));
1807 cutoff_mask = _mm_cmplt_pd(rsq02,rcutoff2);
1811 fscal = _mm_and_pd(fscal,cutoff_mask);
1813 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1815 /* Update vectorial force */
1816 fix0 = _mm_macc_pd(dx02,fscal,fix0);
1817 fiy0 = _mm_macc_pd(dy02,fscal,fiy0);
1818 fiz0 = _mm_macc_pd(dz02,fscal,fiz0);
1820 fjx2 = _mm_macc_pd(dx02,fscal,fjx2);
1821 fjy2 = _mm_macc_pd(dy02,fscal,fjy2);
1822 fjz2 = _mm_macc_pd(dz02,fscal,fjz2);
1826 /**************************
1827 * CALCULATE INTERACTIONS *
1828 **************************/
1830 if (gmx_mm_any_lt(rsq10,rcutoff2))
1833 /* REACTION-FIELD ELECTROSTATICS */
1834 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
1836 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
1840 fscal = _mm_and_pd(fscal,cutoff_mask);
1842 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1844 /* Update vectorial force */
1845 fix1 = _mm_macc_pd(dx10,fscal,fix1);
1846 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
1847 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
1849 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
1850 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
1851 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
1855 /**************************
1856 * CALCULATE INTERACTIONS *
1857 **************************/
1859 if (gmx_mm_any_lt(rsq11,rcutoff2))
1862 /* REACTION-FIELD ELECTROSTATICS */
1863 felec = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
1865 cutoff_mask = _mm_cmplt_pd(rsq11,rcutoff2);
1869 fscal = _mm_and_pd(fscal,cutoff_mask);
1871 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1873 /* Update vectorial force */
1874 fix1 = _mm_macc_pd(dx11,fscal,fix1);
1875 fiy1 = _mm_macc_pd(dy11,fscal,fiy1);
1876 fiz1 = _mm_macc_pd(dz11,fscal,fiz1);
1878 fjx1 = _mm_macc_pd(dx11,fscal,fjx1);
1879 fjy1 = _mm_macc_pd(dy11,fscal,fjy1);
1880 fjz1 = _mm_macc_pd(dz11,fscal,fjz1);
1884 /**************************
1885 * CALCULATE INTERACTIONS *
1886 **************************/
1888 if (gmx_mm_any_lt(rsq12,rcutoff2))
1891 /* REACTION-FIELD ELECTROSTATICS */
1892 felec = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
1894 cutoff_mask = _mm_cmplt_pd(rsq12,rcutoff2);
1898 fscal = _mm_and_pd(fscal,cutoff_mask);
1900 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1902 /* Update vectorial force */
1903 fix1 = _mm_macc_pd(dx12,fscal,fix1);
1904 fiy1 = _mm_macc_pd(dy12,fscal,fiy1);
1905 fiz1 = _mm_macc_pd(dz12,fscal,fiz1);
1907 fjx2 = _mm_macc_pd(dx12,fscal,fjx2);
1908 fjy2 = _mm_macc_pd(dy12,fscal,fjy2);
1909 fjz2 = _mm_macc_pd(dz12,fscal,fjz2);
1913 /**************************
1914 * CALCULATE INTERACTIONS *
1915 **************************/
1917 if (gmx_mm_any_lt(rsq20,rcutoff2))
1920 /* REACTION-FIELD ELECTROSTATICS */
1921 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1923 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
1927 fscal = _mm_and_pd(fscal,cutoff_mask);
1929 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1931 /* Update vectorial force */
1932 fix2 = _mm_macc_pd(dx20,fscal,fix2);
1933 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
1934 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
1936 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
1937 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
1938 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
1942 /**************************
1943 * CALCULATE INTERACTIONS *
1944 **************************/
1946 if (gmx_mm_any_lt(rsq21,rcutoff2))
1949 /* REACTION-FIELD ELECTROSTATICS */
1950 felec = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
1952 cutoff_mask = _mm_cmplt_pd(rsq21,rcutoff2);
1956 fscal = _mm_and_pd(fscal,cutoff_mask);
1958 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1960 /* Update vectorial force */
1961 fix2 = _mm_macc_pd(dx21,fscal,fix2);
1962 fiy2 = _mm_macc_pd(dy21,fscal,fiy2);
1963 fiz2 = _mm_macc_pd(dz21,fscal,fiz2);
1965 fjx1 = _mm_macc_pd(dx21,fscal,fjx1);
1966 fjy1 = _mm_macc_pd(dy21,fscal,fjy1);
1967 fjz1 = _mm_macc_pd(dz21,fscal,fjz1);
1971 /**************************
1972 * CALCULATE INTERACTIONS *
1973 **************************/
1975 if (gmx_mm_any_lt(rsq22,rcutoff2))
1978 /* REACTION-FIELD ELECTROSTATICS */
1979 felec = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
1981 cutoff_mask = _mm_cmplt_pd(rsq22,rcutoff2);
1985 fscal = _mm_and_pd(fscal,cutoff_mask);
1987 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1989 /* Update vectorial force */
1990 fix2 = _mm_macc_pd(dx22,fscal,fix2);
1991 fiy2 = _mm_macc_pd(dy22,fscal,fiy2);
1992 fiz2 = _mm_macc_pd(dz22,fscal,fiz2);
1994 fjx2 = _mm_macc_pd(dx22,fscal,fjx2);
1995 fjy2 = _mm_macc_pd(dy22,fscal,fjy2);
1996 fjz2 = _mm_macc_pd(dz22,fscal,fjz2);
2000 gmx_mm_decrement_3rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2002 /* Inner loop uses 324 flops */
2005 /* End of innermost loop */
2007 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2008 f+i_coord_offset,fshift+i_shift_offset);
2010 /* Increment number of inner iterations */
2011 inneriter += j_index_end - j_index_start;
2013 /* Outer loop uses 18 flops */
2016 /* Increment number of outer iterations */
2019 /* Update outer/inner flops */
2021 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*324);