2 * Note: this file was generated by the Gromacs avx_256_double kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_256_double.h"
34 #include "kernelutil_x86_avx_256_double.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3W3_VF_avx_256_double
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: None
40 * Geometry: Water3-Water3
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwNone_GeomW3W3_VF_avx_256_double
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
63 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
64 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
66 real *shiftvec,*fshift,*x,*f;
67 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
69 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
70 real * vdwioffsetptr0;
71 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72 real * vdwioffsetptr1;
73 __m256d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74 real * vdwioffsetptr2;
75 __m256d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
77 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
78 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
79 __m256d jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
80 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
81 __m256d jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
82 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
83 __m256d dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
84 __m256d dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
85 __m256d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
86 __m256d dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
87 __m256d dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
88 __m256d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
89 __m256d dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
90 __m256d dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
91 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
93 __m256d dummy_mask,cutoff_mask;
94 __m128 tmpmask0,tmpmask1;
95 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
96 __m256d one = _mm256_set1_pd(1.0);
97 __m256d two = _mm256_set1_pd(2.0);
103 jindex = nlist->jindex;
105 shiftidx = nlist->shift;
107 shiftvec = fr->shift_vec[0];
108 fshift = fr->fshift[0];
109 facel = _mm256_set1_pd(fr->epsfac);
110 charge = mdatoms->chargeA;
111 krf = _mm256_set1_pd(fr->ic->k_rf);
112 krf2 = _mm256_set1_pd(fr->ic->k_rf*2.0);
113 crf = _mm256_set1_pd(fr->ic->c_rf);
115 /* Setup water-specific parameters */
116 inr = nlist->iinr[0];
117 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
118 iq1 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+1]));
119 iq2 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+2]));
121 jq0 = _mm256_set1_pd(charge[inr+0]);
122 jq1 = _mm256_set1_pd(charge[inr+1]);
123 jq2 = _mm256_set1_pd(charge[inr+2]);
124 qq00 = _mm256_mul_pd(iq0,jq0);
125 qq01 = _mm256_mul_pd(iq0,jq1);
126 qq02 = _mm256_mul_pd(iq0,jq2);
127 qq10 = _mm256_mul_pd(iq1,jq0);
128 qq11 = _mm256_mul_pd(iq1,jq1);
129 qq12 = _mm256_mul_pd(iq1,jq2);
130 qq20 = _mm256_mul_pd(iq2,jq0);
131 qq21 = _mm256_mul_pd(iq2,jq1);
132 qq22 = _mm256_mul_pd(iq2,jq2);
134 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
135 rcutoff_scalar = fr->rcoulomb;
136 rcutoff = _mm256_set1_pd(rcutoff_scalar);
137 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
139 /* Avoid stupid compiler warnings */
140 jnrA = jnrB = jnrC = jnrD = 0;
149 for(iidx=0;iidx<4*DIM;iidx++)
154 /* Start outer loop over neighborlists */
155 for(iidx=0; iidx<nri; iidx++)
157 /* Load shift vector for this list */
158 i_shift_offset = DIM*shiftidx[iidx];
160 /* Load limits for loop over neighbors */
161 j_index_start = jindex[iidx];
162 j_index_end = jindex[iidx+1];
164 /* Get outer coordinate index */
166 i_coord_offset = DIM*inr;
168 /* Load i particle coords and add shift vector */
169 gmx_mm256_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
170 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
172 fix0 = _mm256_setzero_pd();
173 fiy0 = _mm256_setzero_pd();
174 fiz0 = _mm256_setzero_pd();
175 fix1 = _mm256_setzero_pd();
176 fiy1 = _mm256_setzero_pd();
177 fiz1 = _mm256_setzero_pd();
178 fix2 = _mm256_setzero_pd();
179 fiy2 = _mm256_setzero_pd();
180 fiz2 = _mm256_setzero_pd();
182 /* Reset potential sums */
183 velecsum = _mm256_setzero_pd();
185 /* Start inner kernel loop */
186 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
189 /* Get j neighbor index, and coordinate index */
194 j_coord_offsetA = DIM*jnrA;
195 j_coord_offsetB = DIM*jnrB;
196 j_coord_offsetC = DIM*jnrC;
197 j_coord_offsetD = DIM*jnrD;
199 /* load j atom coordinates */
200 gmx_mm256_load_3rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
201 x+j_coord_offsetC,x+j_coord_offsetD,
202 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
204 /* Calculate displacement vector */
205 dx00 = _mm256_sub_pd(ix0,jx0);
206 dy00 = _mm256_sub_pd(iy0,jy0);
207 dz00 = _mm256_sub_pd(iz0,jz0);
208 dx01 = _mm256_sub_pd(ix0,jx1);
209 dy01 = _mm256_sub_pd(iy0,jy1);
210 dz01 = _mm256_sub_pd(iz0,jz1);
211 dx02 = _mm256_sub_pd(ix0,jx2);
212 dy02 = _mm256_sub_pd(iy0,jy2);
213 dz02 = _mm256_sub_pd(iz0,jz2);
214 dx10 = _mm256_sub_pd(ix1,jx0);
215 dy10 = _mm256_sub_pd(iy1,jy0);
216 dz10 = _mm256_sub_pd(iz1,jz0);
217 dx11 = _mm256_sub_pd(ix1,jx1);
218 dy11 = _mm256_sub_pd(iy1,jy1);
219 dz11 = _mm256_sub_pd(iz1,jz1);
220 dx12 = _mm256_sub_pd(ix1,jx2);
221 dy12 = _mm256_sub_pd(iy1,jy2);
222 dz12 = _mm256_sub_pd(iz1,jz2);
223 dx20 = _mm256_sub_pd(ix2,jx0);
224 dy20 = _mm256_sub_pd(iy2,jy0);
225 dz20 = _mm256_sub_pd(iz2,jz0);
226 dx21 = _mm256_sub_pd(ix2,jx1);
227 dy21 = _mm256_sub_pd(iy2,jy1);
228 dz21 = _mm256_sub_pd(iz2,jz1);
229 dx22 = _mm256_sub_pd(ix2,jx2);
230 dy22 = _mm256_sub_pd(iy2,jy2);
231 dz22 = _mm256_sub_pd(iz2,jz2);
233 /* Calculate squared distance and things based on it */
234 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
235 rsq01 = gmx_mm256_calc_rsq_pd(dx01,dy01,dz01);
236 rsq02 = gmx_mm256_calc_rsq_pd(dx02,dy02,dz02);
237 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
238 rsq11 = gmx_mm256_calc_rsq_pd(dx11,dy11,dz11);
239 rsq12 = gmx_mm256_calc_rsq_pd(dx12,dy12,dz12);
240 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
241 rsq21 = gmx_mm256_calc_rsq_pd(dx21,dy21,dz21);
242 rsq22 = gmx_mm256_calc_rsq_pd(dx22,dy22,dz22);
244 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
245 rinv01 = gmx_mm256_invsqrt_pd(rsq01);
246 rinv02 = gmx_mm256_invsqrt_pd(rsq02);
247 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
248 rinv11 = gmx_mm256_invsqrt_pd(rsq11);
249 rinv12 = gmx_mm256_invsqrt_pd(rsq12);
250 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
251 rinv21 = gmx_mm256_invsqrt_pd(rsq21);
252 rinv22 = gmx_mm256_invsqrt_pd(rsq22);
254 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
255 rinvsq01 = _mm256_mul_pd(rinv01,rinv01);
256 rinvsq02 = _mm256_mul_pd(rinv02,rinv02);
257 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
258 rinvsq11 = _mm256_mul_pd(rinv11,rinv11);
259 rinvsq12 = _mm256_mul_pd(rinv12,rinv12);
260 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
261 rinvsq21 = _mm256_mul_pd(rinv21,rinv21);
262 rinvsq22 = _mm256_mul_pd(rinv22,rinv22);
264 fjx0 = _mm256_setzero_pd();
265 fjy0 = _mm256_setzero_pd();
266 fjz0 = _mm256_setzero_pd();
267 fjx1 = _mm256_setzero_pd();
268 fjy1 = _mm256_setzero_pd();
269 fjz1 = _mm256_setzero_pd();
270 fjx2 = _mm256_setzero_pd();
271 fjy2 = _mm256_setzero_pd();
272 fjz2 = _mm256_setzero_pd();
274 /**************************
275 * CALCULATE INTERACTIONS *
276 **************************/
278 if (gmx_mm256_any_lt(rsq00,rcutoff2))
281 /* REACTION-FIELD ELECTROSTATICS */
282 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_add_pd(rinv00,_mm256_mul_pd(krf,rsq00)),crf));
283 felec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
285 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
287 /* Update potential sum for this i atom from the interaction with this j atom. */
288 velec = _mm256_and_pd(velec,cutoff_mask);
289 velecsum = _mm256_add_pd(velecsum,velec);
293 fscal = _mm256_and_pd(fscal,cutoff_mask);
295 /* Calculate temporary vectorial force */
296 tx = _mm256_mul_pd(fscal,dx00);
297 ty = _mm256_mul_pd(fscal,dy00);
298 tz = _mm256_mul_pd(fscal,dz00);
300 /* Update vectorial force */
301 fix0 = _mm256_add_pd(fix0,tx);
302 fiy0 = _mm256_add_pd(fiy0,ty);
303 fiz0 = _mm256_add_pd(fiz0,tz);
305 fjx0 = _mm256_add_pd(fjx0,tx);
306 fjy0 = _mm256_add_pd(fjy0,ty);
307 fjz0 = _mm256_add_pd(fjz0,tz);
311 /**************************
312 * CALCULATE INTERACTIONS *
313 **************************/
315 if (gmx_mm256_any_lt(rsq01,rcutoff2))
318 /* REACTION-FIELD ELECTROSTATICS */
319 velec = _mm256_mul_pd(qq01,_mm256_sub_pd(_mm256_add_pd(rinv01,_mm256_mul_pd(krf,rsq01)),crf));
320 felec = _mm256_mul_pd(qq01,_mm256_sub_pd(_mm256_mul_pd(rinv01,rinvsq01),krf2));
322 cutoff_mask = _mm256_cmp_pd(rsq01,rcutoff2,_CMP_LT_OQ);
324 /* Update potential sum for this i atom from the interaction with this j atom. */
325 velec = _mm256_and_pd(velec,cutoff_mask);
326 velecsum = _mm256_add_pd(velecsum,velec);
330 fscal = _mm256_and_pd(fscal,cutoff_mask);
332 /* Calculate temporary vectorial force */
333 tx = _mm256_mul_pd(fscal,dx01);
334 ty = _mm256_mul_pd(fscal,dy01);
335 tz = _mm256_mul_pd(fscal,dz01);
337 /* Update vectorial force */
338 fix0 = _mm256_add_pd(fix0,tx);
339 fiy0 = _mm256_add_pd(fiy0,ty);
340 fiz0 = _mm256_add_pd(fiz0,tz);
342 fjx1 = _mm256_add_pd(fjx1,tx);
343 fjy1 = _mm256_add_pd(fjy1,ty);
344 fjz1 = _mm256_add_pd(fjz1,tz);
348 /**************************
349 * CALCULATE INTERACTIONS *
350 **************************/
352 if (gmx_mm256_any_lt(rsq02,rcutoff2))
355 /* REACTION-FIELD ELECTROSTATICS */
356 velec = _mm256_mul_pd(qq02,_mm256_sub_pd(_mm256_add_pd(rinv02,_mm256_mul_pd(krf,rsq02)),crf));
357 felec = _mm256_mul_pd(qq02,_mm256_sub_pd(_mm256_mul_pd(rinv02,rinvsq02),krf2));
359 cutoff_mask = _mm256_cmp_pd(rsq02,rcutoff2,_CMP_LT_OQ);
361 /* Update potential sum for this i atom from the interaction with this j atom. */
362 velec = _mm256_and_pd(velec,cutoff_mask);
363 velecsum = _mm256_add_pd(velecsum,velec);
367 fscal = _mm256_and_pd(fscal,cutoff_mask);
369 /* Calculate temporary vectorial force */
370 tx = _mm256_mul_pd(fscal,dx02);
371 ty = _mm256_mul_pd(fscal,dy02);
372 tz = _mm256_mul_pd(fscal,dz02);
374 /* Update vectorial force */
375 fix0 = _mm256_add_pd(fix0,tx);
376 fiy0 = _mm256_add_pd(fiy0,ty);
377 fiz0 = _mm256_add_pd(fiz0,tz);
379 fjx2 = _mm256_add_pd(fjx2,tx);
380 fjy2 = _mm256_add_pd(fjy2,ty);
381 fjz2 = _mm256_add_pd(fjz2,tz);
385 /**************************
386 * CALCULATE INTERACTIONS *
387 **************************/
389 if (gmx_mm256_any_lt(rsq10,rcutoff2))
392 /* REACTION-FIELD ELECTROSTATICS */
393 velec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_add_pd(rinv10,_mm256_mul_pd(krf,rsq10)),crf));
394 felec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_mul_pd(rinv10,rinvsq10),krf2));
396 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
398 /* Update potential sum for this i atom from the interaction with this j atom. */
399 velec = _mm256_and_pd(velec,cutoff_mask);
400 velecsum = _mm256_add_pd(velecsum,velec);
404 fscal = _mm256_and_pd(fscal,cutoff_mask);
406 /* Calculate temporary vectorial force */
407 tx = _mm256_mul_pd(fscal,dx10);
408 ty = _mm256_mul_pd(fscal,dy10);
409 tz = _mm256_mul_pd(fscal,dz10);
411 /* Update vectorial force */
412 fix1 = _mm256_add_pd(fix1,tx);
413 fiy1 = _mm256_add_pd(fiy1,ty);
414 fiz1 = _mm256_add_pd(fiz1,tz);
416 fjx0 = _mm256_add_pd(fjx0,tx);
417 fjy0 = _mm256_add_pd(fjy0,ty);
418 fjz0 = _mm256_add_pd(fjz0,tz);
422 /**************************
423 * CALCULATE INTERACTIONS *
424 **************************/
426 if (gmx_mm256_any_lt(rsq11,rcutoff2))
429 /* REACTION-FIELD ELECTROSTATICS */
430 velec = _mm256_mul_pd(qq11,_mm256_sub_pd(_mm256_add_pd(rinv11,_mm256_mul_pd(krf,rsq11)),crf));
431 felec = _mm256_mul_pd(qq11,_mm256_sub_pd(_mm256_mul_pd(rinv11,rinvsq11),krf2));
433 cutoff_mask = _mm256_cmp_pd(rsq11,rcutoff2,_CMP_LT_OQ);
435 /* Update potential sum for this i atom from the interaction with this j atom. */
436 velec = _mm256_and_pd(velec,cutoff_mask);
437 velecsum = _mm256_add_pd(velecsum,velec);
441 fscal = _mm256_and_pd(fscal,cutoff_mask);
443 /* Calculate temporary vectorial force */
444 tx = _mm256_mul_pd(fscal,dx11);
445 ty = _mm256_mul_pd(fscal,dy11);
446 tz = _mm256_mul_pd(fscal,dz11);
448 /* Update vectorial force */
449 fix1 = _mm256_add_pd(fix1,tx);
450 fiy1 = _mm256_add_pd(fiy1,ty);
451 fiz1 = _mm256_add_pd(fiz1,tz);
453 fjx1 = _mm256_add_pd(fjx1,tx);
454 fjy1 = _mm256_add_pd(fjy1,ty);
455 fjz1 = _mm256_add_pd(fjz1,tz);
459 /**************************
460 * CALCULATE INTERACTIONS *
461 **************************/
463 if (gmx_mm256_any_lt(rsq12,rcutoff2))
466 /* REACTION-FIELD ELECTROSTATICS */
467 velec = _mm256_mul_pd(qq12,_mm256_sub_pd(_mm256_add_pd(rinv12,_mm256_mul_pd(krf,rsq12)),crf));
468 felec = _mm256_mul_pd(qq12,_mm256_sub_pd(_mm256_mul_pd(rinv12,rinvsq12),krf2));
470 cutoff_mask = _mm256_cmp_pd(rsq12,rcutoff2,_CMP_LT_OQ);
472 /* Update potential sum for this i atom from the interaction with this j atom. */
473 velec = _mm256_and_pd(velec,cutoff_mask);
474 velecsum = _mm256_add_pd(velecsum,velec);
478 fscal = _mm256_and_pd(fscal,cutoff_mask);
480 /* Calculate temporary vectorial force */
481 tx = _mm256_mul_pd(fscal,dx12);
482 ty = _mm256_mul_pd(fscal,dy12);
483 tz = _mm256_mul_pd(fscal,dz12);
485 /* Update vectorial force */
486 fix1 = _mm256_add_pd(fix1,tx);
487 fiy1 = _mm256_add_pd(fiy1,ty);
488 fiz1 = _mm256_add_pd(fiz1,tz);
490 fjx2 = _mm256_add_pd(fjx2,tx);
491 fjy2 = _mm256_add_pd(fjy2,ty);
492 fjz2 = _mm256_add_pd(fjz2,tz);
496 /**************************
497 * CALCULATE INTERACTIONS *
498 **************************/
500 if (gmx_mm256_any_lt(rsq20,rcutoff2))
503 /* REACTION-FIELD ELECTROSTATICS */
504 velec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_add_pd(rinv20,_mm256_mul_pd(krf,rsq20)),crf));
505 felec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_mul_pd(rinv20,rinvsq20),krf2));
507 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
509 /* Update potential sum for this i atom from the interaction with this j atom. */
510 velec = _mm256_and_pd(velec,cutoff_mask);
511 velecsum = _mm256_add_pd(velecsum,velec);
515 fscal = _mm256_and_pd(fscal,cutoff_mask);
517 /* Calculate temporary vectorial force */
518 tx = _mm256_mul_pd(fscal,dx20);
519 ty = _mm256_mul_pd(fscal,dy20);
520 tz = _mm256_mul_pd(fscal,dz20);
522 /* Update vectorial force */
523 fix2 = _mm256_add_pd(fix2,tx);
524 fiy2 = _mm256_add_pd(fiy2,ty);
525 fiz2 = _mm256_add_pd(fiz2,tz);
527 fjx0 = _mm256_add_pd(fjx0,tx);
528 fjy0 = _mm256_add_pd(fjy0,ty);
529 fjz0 = _mm256_add_pd(fjz0,tz);
533 /**************************
534 * CALCULATE INTERACTIONS *
535 **************************/
537 if (gmx_mm256_any_lt(rsq21,rcutoff2))
540 /* REACTION-FIELD ELECTROSTATICS */
541 velec = _mm256_mul_pd(qq21,_mm256_sub_pd(_mm256_add_pd(rinv21,_mm256_mul_pd(krf,rsq21)),crf));
542 felec = _mm256_mul_pd(qq21,_mm256_sub_pd(_mm256_mul_pd(rinv21,rinvsq21),krf2));
544 cutoff_mask = _mm256_cmp_pd(rsq21,rcutoff2,_CMP_LT_OQ);
546 /* Update potential sum for this i atom from the interaction with this j atom. */
547 velec = _mm256_and_pd(velec,cutoff_mask);
548 velecsum = _mm256_add_pd(velecsum,velec);
552 fscal = _mm256_and_pd(fscal,cutoff_mask);
554 /* Calculate temporary vectorial force */
555 tx = _mm256_mul_pd(fscal,dx21);
556 ty = _mm256_mul_pd(fscal,dy21);
557 tz = _mm256_mul_pd(fscal,dz21);
559 /* Update vectorial force */
560 fix2 = _mm256_add_pd(fix2,tx);
561 fiy2 = _mm256_add_pd(fiy2,ty);
562 fiz2 = _mm256_add_pd(fiz2,tz);
564 fjx1 = _mm256_add_pd(fjx1,tx);
565 fjy1 = _mm256_add_pd(fjy1,ty);
566 fjz1 = _mm256_add_pd(fjz1,tz);
570 /**************************
571 * CALCULATE INTERACTIONS *
572 **************************/
574 if (gmx_mm256_any_lt(rsq22,rcutoff2))
577 /* REACTION-FIELD ELECTROSTATICS */
578 velec = _mm256_mul_pd(qq22,_mm256_sub_pd(_mm256_add_pd(rinv22,_mm256_mul_pd(krf,rsq22)),crf));
579 felec = _mm256_mul_pd(qq22,_mm256_sub_pd(_mm256_mul_pd(rinv22,rinvsq22),krf2));
581 cutoff_mask = _mm256_cmp_pd(rsq22,rcutoff2,_CMP_LT_OQ);
583 /* Update potential sum for this i atom from the interaction with this j atom. */
584 velec = _mm256_and_pd(velec,cutoff_mask);
585 velecsum = _mm256_add_pd(velecsum,velec);
589 fscal = _mm256_and_pd(fscal,cutoff_mask);
591 /* Calculate temporary vectorial force */
592 tx = _mm256_mul_pd(fscal,dx22);
593 ty = _mm256_mul_pd(fscal,dy22);
594 tz = _mm256_mul_pd(fscal,dz22);
596 /* Update vectorial force */
597 fix2 = _mm256_add_pd(fix2,tx);
598 fiy2 = _mm256_add_pd(fiy2,ty);
599 fiz2 = _mm256_add_pd(fiz2,tz);
601 fjx2 = _mm256_add_pd(fjx2,tx);
602 fjy2 = _mm256_add_pd(fjy2,ty);
603 fjz2 = _mm256_add_pd(fjz2,tz);
607 fjptrA = f+j_coord_offsetA;
608 fjptrB = f+j_coord_offsetB;
609 fjptrC = f+j_coord_offsetC;
610 fjptrD = f+j_coord_offsetD;
612 gmx_mm256_decrement_3rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,
613 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
615 /* Inner loop uses 324 flops */
621 /* Get j neighbor index, and coordinate index */
622 jnrlistA = jjnr[jidx];
623 jnrlistB = jjnr[jidx+1];
624 jnrlistC = jjnr[jidx+2];
625 jnrlistD = jjnr[jidx+3];
626 /* Sign of each element will be negative for non-real atoms.
627 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
628 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
630 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
632 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
633 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
634 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
636 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
637 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
638 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
639 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
640 j_coord_offsetA = DIM*jnrA;
641 j_coord_offsetB = DIM*jnrB;
642 j_coord_offsetC = DIM*jnrC;
643 j_coord_offsetD = DIM*jnrD;
645 /* load j atom coordinates */
646 gmx_mm256_load_3rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
647 x+j_coord_offsetC,x+j_coord_offsetD,
648 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
650 /* Calculate displacement vector */
651 dx00 = _mm256_sub_pd(ix0,jx0);
652 dy00 = _mm256_sub_pd(iy0,jy0);
653 dz00 = _mm256_sub_pd(iz0,jz0);
654 dx01 = _mm256_sub_pd(ix0,jx1);
655 dy01 = _mm256_sub_pd(iy0,jy1);
656 dz01 = _mm256_sub_pd(iz0,jz1);
657 dx02 = _mm256_sub_pd(ix0,jx2);
658 dy02 = _mm256_sub_pd(iy0,jy2);
659 dz02 = _mm256_sub_pd(iz0,jz2);
660 dx10 = _mm256_sub_pd(ix1,jx0);
661 dy10 = _mm256_sub_pd(iy1,jy0);
662 dz10 = _mm256_sub_pd(iz1,jz0);
663 dx11 = _mm256_sub_pd(ix1,jx1);
664 dy11 = _mm256_sub_pd(iy1,jy1);
665 dz11 = _mm256_sub_pd(iz1,jz1);
666 dx12 = _mm256_sub_pd(ix1,jx2);
667 dy12 = _mm256_sub_pd(iy1,jy2);
668 dz12 = _mm256_sub_pd(iz1,jz2);
669 dx20 = _mm256_sub_pd(ix2,jx0);
670 dy20 = _mm256_sub_pd(iy2,jy0);
671 dz20 = _mm256_sub_pd(iz2,jz0);
672 dx21 = _mm256_sub_pd(ix2,jx1);
673 dy21 = _mm256_sub_pd(iy2,jy1);
674 dz21 = _mm256_sub_pd(iz2,jz1);
675 dx22 = _mm256_sub_pd(ix2,jx2);
676 dy22 = _mm256_sub_pd(iy2,jy2);
677 dz22 = _mm256_sub_pd(iz2,jz2);
679 /* Calculate squared distance and things based on it */
680 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
681 rsq01 = gmx_mm256_calc_rsq_pd(dx01,dy01,dz01);
682 rsq02 = gmx_mm256_calc_rsq_pd(dx02,dy02,dz02);
683 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
684 rsq11 = gmx_mm256_calc_rsq_pd(dx11,dy11,dz11);
685 rsq12 = gmx_mm256_calc_rsq_pd(dx12,dy12,dz12);
686 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
687 rsq21 = gmx_mm256_calc_rsq_pd(dx21,dy21,dz21);
688 rsq22 = gmx_mm256_calc_rsq_pd(dx22,dy22,dz22);
690 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
691 rinv01 = gmx_mm256_invsqrt_pd(rsq01);
692 rinv02 = gmx_mm256_invsqrt_pd(rsq02);
693 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
694 rinv11 = gmx_mm256_invsqrt_pd(rsq11);
695 rinv12 = gmx_mm256_invsqrt_pd(rsq12);
696 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
697 rinv21 = gmx_mm256_invsqrt_pd(rsq21);
698 rinv22 = gmx_mm256_invsqrt_pd(rsq22);
700 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
701 rinvsq01 = _mm256_mul_pd(rinv01,rinv01);
702 rinvsq02 = _mm256_mul_pd(rinv02,rinv02);
703 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
704 rinvsq11 = _mm256_mul_pd(rinv11,rinv11);
705 rinvsq12 = _mm256_mul_pd(rinv12,rinv12);
706 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
707 rinvsq21 = _mm256_mul_pd(rinv21,rinv21);
708 rinvsq22 = _mm256_mul_pd(rinv22,rinv22);
710 fjx0 = _mm256_setzero_pd();
711 fjy0 = _mm256_setzero_pd();
712 fjz0 = _mm256_setzero_pd();
713 fjx1 = _mm256_setzero_pd();
714 fjy1 = _mm256_setzero_pd();
715 fjz1 = _mm256_setzero_pd();
716 fjx2 = _mm256_setzero_pd();
717 fjy2 = _mm256_setzero_pd();
718 fjz2 = _mm256_setzero_pd();
720 /**************************
721 * CALCULATE INTERACTIONS *
722 **************************/
724 if (gmx_mm256_any_lt(rsq00,rcutoff2))
727 /* REACTION-FIELD ELECTROSTATICS */
728 velec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_add_pd(rinv00,_mm256_mul_pd(krf,rsq00)),crf));
729 felec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
731 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
733 /* Update potential sum for this i atom from the interaction with this j atom. */
734 velec = _mm256_and_pd(velec,cutoff_mask);
735 velec = _mm256_andnot_pd(dummy_mask,velec);
736 velecsum = _mm256_add_pd(velecsum,velec);
740 fscal = _mm256_and_pd(fscal,cutoff_mask);
742 fscal = _mm256_andnot_pd(dummy_mask,fscal);
744 /* Calculate temporary vectorial force */
745 tx = _mm256_mul_pd(fscal,dx00);
746 ty = _mm256_mul_pd(fscal,dy00);
747 tz = _mm256_mul_pd(fscal,dz00);
749 /* Update vectorial force */
750 fix0 = _mm256_add_pd(fix0,tx);
751 fiy0 = _mm256_add_pd(fiy0,ty);
752 fiz0 = _mm256_add_pd(fiz0,tz);
754 fjx0 = _mm256_add_pd(fjx0,tx);
755 fjy0 = _mm256_add_pd(fjy0,ty);
756 fjz0 = _mm256_add_pd(fjz0,tz);
760 /**************************
761 * CALCULATE INTERACTIONS *
762 **************************/
764 if (gmx_mm256_any_lt(rsq01,rcutoff2))
767 /* REACTION-FIELD ELECTROSTATICS */
768 velec = _mm256_mul_pd(qq01,_mm256_sub_pd(_mm256_add_pd(rinv01,_mm256_mul_pd(krf,rsq01)),crf));
769 felec = _mm256_mul_pd(qq01,_mm256_sub_pd(_mm256_mul_pd(rinv01,rinvsq01),krf2));
771 cutoff_mask = _mm256_cmp_pd(rsq01,rcutoff2,_CMP_LT_OQ);
773 /* Update potential sum for this i atom from the interaction with this j atom. */
774 velec = _mm256_and_pd(velec,cutoff_mask);
775 velec = _mm256_andnot_pd(dummy_mask,velec);
776 velecsum = _mm256_add_pd(velecsum,velec);
780 fscal = _mm256_and_pd(fscal,cutoff_mask);
782 fscal = _mm256_andnot_pd(dummy_mask,fscal);
784 /* Calculate temporary vectorial force */
785 tx = _mm256_mul_pd(fscal,dx01);
786 ty = _mm256_mul_pd(fscal,dy01);
787 tz = _mm256_mul_pd(fscal,dz01);
789 /* Update vectorial force */
790 fix0 = _mm256_add_pd(fix0,tx);
791 fiy0 = _mm256_add_pd(fiy0,ty);
792 fiz0 = _mm256_add_pd(fiz0,tz);
794 fjx1 = _mm256_add_pd(fjx1,tx);
795 fjy1 = _mm256_add_pd(fjy1,ty);
796 fjz1 = _mm256_add_pd(fjz1,tz);
800 /**************************
801 * CALCULATE INTERACTIONS *
802 **************************/
804 if (gmx_mm256_any_lt(rsq02,rcutoff2))
807 /* REACTION-FIELD ELECTROSTATICS */
808 velec = _mm256_mul_pd(qq02,_mm256_sub_pd(_mm256_add_pd(rinv02,_mm256_mul_pd(krf,rsq02)),crf));
809 felec = _mm256_mul_pd(qq02,_mm256_sub_pd(_mm256_mul_pd(rinv02,rinvsq02),krf2));
811 cutoff_mask = _mm256_cmp_pd(rsq02,rcutoff2,_CMP_LT_OQ);
813 /* Update potential sum for this i atom from the interaction with this j atom. */
814 velec = _mm256_and_pd(velec,cutoff_mask);
815 velec = _mm256_andnot_pd(dummy_mask,velec);
816 velecsum = _mm256_add_pd(velecsum,velec);
820 fscal = _mm256_and_pd(fscal,cutoff_mask);
822 fscal = _mm256_andnot_pd(dummy_mask,fscal);
824 /* Calculate temporary vectorial force */
825 tx = _mm256_mul_pd(fscal,dx02);
826 ty = _mm256_mul_pd(fscal,dy02);
827 tz = _mm256_mul_pd(fscal,dz02);
829 /* Update vectorial force */
830 fix0 = _mm256_add_pd(fix0,tx);
831 fiy0 = _mm256_add_pd(fiy0,ty);
832 fiz0 = _mm256_add_pd(fiz0,tz);
834 fjx2 = _mm256_add_pd(fjx2,tx);
835 fjy2 = _mm256_add_pd(fjy2,ty);
836 fjz2 = _mm256_add_pd(fjz2,tz);
840 /**************************
841 * CALCULATE INTERACTIONS *
842 **************************/
844 if (gmx_mm256_any_lt(rsq10,rcutoff2))
847 /* REACTION-FIELD ELECTROSTATICS */
848 velec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_add_pd(rinv10,_mm256_mul_pd(krf,rsq10)),crf));
849 felec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_mul_pd(rinv10,rinvsq10),krf2));
851 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
853 /* Update potential sum for this i atom from the interaction with this j atom. */
854 velec = _mm256_and_pd(velec,cutoff_mask);
855 velec = _mm256_andnot_pd(dummy_mask,velec);
856 velecsum = _mm256_add_pd(velecsum,velec);
860 fscal = _mm256_and_pd(fscal,cutoff_mask);
862 fscal = _mm256_andnot_pd(dummy_mask,fscal);
864 /* Calculate temporary vectorial force */
865 tx = _mm256_mul_pd(fscal,dx10);
866 ty = _mm256_mul_pd(fscal,dy10);
867 tz = _mm256_mul_pd(fscal,dz10);
869 /* Update vectorial force */
870 fix1 = _mm256_add_pd(fix1,tx);
871 fiy1 = _mm256_add_pd(fiy1,ty);
872 fiz1 = _mm256_add_pd(fiz1,tz);
874 fjx0 = _mm256_add_pd(fjx0,tx);
875 fjy0 = _mm256_add_pd(fjy0,ty);
876 fjz0 = _mm256_add_pd(fjz0,tz);
880 /**************************
881 * CALCULATE INTERACTIONS *
882 **************************/
884 if (gmx_mm256_any_lt(rsq11,rcutoff2))
887 /* REACTION-FIELD ELECTROSTATICS */
888 velec = _mm256_mul_pd(qq11,_mm256_sub_pd(_mm256_add_pd(rinv11,_mm256_mul_pd(krf,rsq11)),crf));
889 felec = _mm256_mul_pd(qq11,_mm256_sub_pd(_mm256_mul_pd(rinv11,rinvsq11),krf2));
891 cutoff_mask = _mm256_cmp_pd(rsq11,rcutoff2,_CMP_LT_OQ);
893 /* Update potential sum for this i atom from the interaction with this j atom. */
894 velec = _mm256_and_pd(velec,cutoff_mask);
895 velec = _mm256_andnot_pd(dummy_mask,velec);
896 velecsum = _mm256_add_pd(velecsum,velec);
900 fscal = _mm256_and_pd(fscal,cutoff_mask);
902 fscal = _mm256_andnot_pd(dummy_mask,fscal);
904 /* Calculate temporary vectorial force */
905 tx = _mm256_mul_pd(fscal,dx11);
906 ty = _mm256_mul_pd(fscal,dy11);
907 tz = _mm256_mul_pd(fscal,dz11);
909 /* Update vectorial force */
910 fix1 = _mm256_add_pd(fix1,tx);
911 fiy1 = _mm256_add_pd(fiy1,ty);
912 fiz1 = _mm256_add_pd(fiz1,tz);
914 fjx1 = _mm256_add_pd(fjx1,tx);
915 fjy1 = _mm256_add_pd(fjy1,ty);
916 fjz1 = _mm256_add_pd(fjz1,tz);
920 /**************************
921 * CALCULATE INTERACTIONS *
922 **************************/
924 if (gmx_mm256_any_lt(rsq12,rcutoff2))
927 /* REACTION-FIELD ELECTROSTATICS */
928 velec = _mm256_mul_pd(qq12,_mm256_sub_pd(_mm256_add_pd(rinv12,_mm256_mul_pd(krf,rsq12)),crf));
929 felec = _mm256_mul_pd(qq12,_mm256_sub_pd(_mm256_mul_pd(rinv12,rinvsq12),krf2));
931 cutoff_mask = _mm256_cmp_pd(rsq12,rcutoff2,_CMP_LT_OQ);
933 /* Update potential sum for this i atom from the interaction with this j atom. */
934 velec = _mm256_and_pd(velec,cutoff_mask);
935 velec = _mm256_andnot_pd(dummy_mask,velec);
936 velecsum = _mm256_add_pd(velecsum,velec);
940 fscal = _mm256_and_pd(fscal,cutoff_mask);
942 fscal = _mm256_andnot_pd(dummy_mask,fscal);
944 /* Calculate temporary vectorial force */
945 tx = _mm256_mul_pd(fscal,dx12);
946 ty = _mm256_mul_pd(fscal,dy12);
947 tz = _mm256_mul_pd(fscal,dz12);
949 /* Update vectorial force */
950 fix1 = _mm256_add_pd(fix1,tx);
951 fiy1 = _mm256_add_pd(fiy1,ty);
952 fiz1 = _mm256_add_pd(fiz1,tz);
954 fjx2 = _mm256_add_pd(fjx2,tx);
955 fjy2 = _mm256_add_pd(fjy2,ty);
956 fjz2 = _mm256_add_pd(fjz2,tz);
960 /**************************
961 * CALCULATE INTERACTIONS *
962 **************************/
964 if (gmx_mm256_any_lt(rsq20,rcutoff2))
967 /* REACTION-FIELD ELECTROSTATICS */
968 velec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_add_pd(rinv20,_mm256_mul_pd(krf,rsq20)),crf));
969 felec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_mul_pd(rinv20,rinvsq20),krf2));
971 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
973 /* Update potential sum for this i atom from the interaction with this j atom. */
974 velec = _mm256_and_pd(velec,cutoff_mask);
975 velec = _mm256_andnot_pd(dummy_mask,velec);
976 velecsum = _mm256_add_pd(velecsum,velec);
980 fscal = _mm256_and_pd(fscal,cutoff_mask);
982 fscal = _mm256_andnot_pd(dummy_mask,fscal);
984 /* Calculate temporary vectorial force */
985 tx = _mm256_mul_pd(fscal,dx20);
986 ty = _mm256_mul_pd(fscal,dy20);
987 tz = _mm256_mul_pd(fscal,dz20);
989 /* Update vectorial force */
990 fix2 = _mm256_add_pd(fix2,tx);
991 fiy2 = _mm256_add_pd(fiy2,ty);
992 fiz2 = _mm256_add_pd(fiz2,tz);
994 fjx0 = _mm256_add_pd(fjx0,tx);
995 fjy0 = _mm256_add_pd(fjy0,ty);
996 fjz0 = _mm256_add_pd(fjz0,tz);
1000 /**************************
1001 * CALCULATE INTERACTIONS *
1002 **************************/
1004 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1007 /* REACTION-FIELD ELECTROSTATICS */
1008 velec = _mm256_mul_pd(qq21,_mm256_sub_pd(_mm256_add_pd(rinv21,_mm256_mul_pd(krf,rsq21)),crf));
1009 felec = _mm256_mul_pd(qq21,_mm256_sub_pd(_mm256_mul_pd(rinv21,rinvsq21),krf2));
1011 cutoff_mask = _mm256_cmp_pd(rsq21,rcutoff2,_CMP_LT_OQ);
1013 /* Update potential sum for this i atom from the interaction with this j atom. */
1014 velec = _mm256_and_pd(velec,cutoff_mask);
1015 velec = _mm256_andnot_pd(dummy_mask,velec);
1016 velecsum = _mm256_add_pd(velecsum,velec);
1020 fscal = _mm256_and_pd(fscal,cutoff_mask);
1022 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1024 /* Calculate temporary vectorial force */
1025 tx = _mm256_mul_pd(fscal,dx21);
1026 ty = _mm256_mul_pd(fscal,dy21);
1027 tz = _mm256_mul_pd(fscal,dz21);
1029 /* Update vectorial force */
1030 fix2 = _mm256_add_pd(fix2,tx);
1031 fiy2 = _mm256_add_pd(fiy2,ty);
1032 fiz2 = _mm256_add_pd(fiz2,tz);
1034 fjx1 = _mm256_add_pd(fjx1,tx);
1035 fjy1 = _mm256_add_pd(fjy1,ty);
1036 fjz1 = _mm256_add_pd(fjz1,tz);
1040 /**************************
1041 * CALCULATE INTERACTIONS *
1042 **************************/
1044 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1047 /* REACTION-FIELD ELECTROSTATICS */
1048 velec = _mm256_mul_pd(qq22,_mm256_sub_pd(_mm256_add_pd(rinv22,_mm256_mul_pd(krf,rsq22)),crf));
1049 felec = _mm256_mul_pd(qq22,_mm256_sub_pd(_mm256_mul_pd(rinv22,rinvsq22),krf2));
1051 cutoff_mask = _mm256_cmp_pd(rsq22,rcutoff2,_CMP_LT_OQ);
1053 /* Update potential sum for this i atom from the interaction with this j atom. */
1054 velec = _mm256_and_pd(velec,cutoff_mask);
1055 velec = _mm256_andnot_pd(dummy_mask,velec);
1056 velecsum = _mm256_add_pd(velecsum,velec);
1060 fscal = _mm256_and_pd(fscal,cutoff_mask);
1062 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1064 /* Calculate temporary vectorial force */
1065 tx = _mm256_mul_pd(fscal,dx22);
1066 ty = _mm256_mul_pd(fscal,dy22);
1067 tz = _mm256_mul_pd(fscal,dz22);
1069 /* Update vectorial force */
1070 fix2 = _mm256_add_pd(fix2,tx);
1071 fiy2 = _mm256_add_pd(fiy2,ty);
1072 fiz2 = _mm256_add_pd(fiz2,tz);
1074 fjx2 = _mm256_add_pd(fjx2,tx);
1075 fjy2 = _mm256_add_pd(fjy2,ty);
1076 fjz2 = _mm256_add_pd(fjz2,tz);
1080 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1081 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1082 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1083 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1085 gmx_mm256_decrement_3rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,
1086 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1088 /* Inner loop uses 324 flops */
1091 /* End of innermost loop */
1093 gmx_mm256_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1094 f+i_coord_offset,fshift+i_shift_offset);
1097 /* Update potential energies */
1098 gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
1100 /* Increment number of inner iterations */
1101 inneriter += j_index_end - j_index_start;
1103 /* Outer loop uses 19 flops */
1106 /* Increment number of outer iterations */
1109 /* Update outer/inner flops */
1111 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_VF,outeriter*19 + inneriter*324);
1114 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3W3_F_avx_256_double
1115 * Electrostatics interaction: ReactionField
1116 * VdW interaction: None
1117 * Geometry: Water3-Water3
1118 * Calculate force/pot: Force
1121 nb_kernel_ElecRFCut_VdwNone_GeomW3W3_F_avx_256_double
1122 (t_nblist * gmx_restrict nlist,
1123 rvec * gmx_restrict xx,
1124 rvec * gmx_restrict ff,
1125 t_forcerec * gmx_restrict fr,
1126 t_mdatoms * gmx_restrict mdatoms,
1127 nb_kernel_data_t * gmx_restrict kernel_data,
1128 t_nrnb * gmx_restrict nrnb)
1130 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1131 * just 0 for non-waters.
1132 * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
1133 * jnr indices corresponding to data put in the four positions in the SIMD register.
1135 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1136 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1137 int jnrA,jnrB,jnrC,jnrD;
1138 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1139 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1140 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1141 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1142 real rcutoff_scalar;
1143 real *shiftvec,*fshift,*x,*f;
1144 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1145 real scratch[4*DIM];
1146 __m256d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1147 real * vdwioffsetptr0;
1148 __m256d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1149 real * vdwioffsetptr1;
1150 __m256d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1151 real * vdwioffsetptr2;
1152 __m256d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1153 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1154 __m256d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1155 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1156 __m256d jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1157 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1158 __m256d jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1159 __m256d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1160 __m256d dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1161 __m256d dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1162 __m256d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1163 __m256d dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1164 __m256d dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1165 __m256d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1166 __m256d dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1167 __m256d dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1168 __m256d velec,felec,velecsum,facel,crf,krf,krf2;
1170 __m256d dummy_mask,cutoff_mask;
1171 __m128 tmpmask0,tmpmask1;
1172 __m256d signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
1173 __m256d one = _mm256_set1_pd(1.0);
1174 __m256d two = _mm256_set1_pd(2.0);
1180 jindex = nlist->jindex;
1182 shiftidx = nlist->shift;
1184 shiftvec = fr->shift_vec[0];
1185 fshift = fr->fshift[0];
1186 facel = _mm256_set1_pd(fr->epsfac);
1187 charge = mdatoms->chargeA;
1188 krf = _mm256_set1_pd(fr->ic->k_rf);
1189 krf2 = _mm256_set1_pd(fr->ic->k_rf*2.0);
1190 crf = _mm256_set1_pd(fr->ic->c_rf);
1192 /* Setup water-specific parameters */
1193 inr = nlist->iinr[0];
1194 iq0 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
1195 iq1 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+1]));
1196 iq2 = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+2]));
1198 jq0 = _mm256_set1_pd(charge[inr+0]);
1199 jq1 = _mm256_set1_pd(charge[inr+1]);
1200 jq2 = _mm256_set1_pd(charge[inr+2]);
1201 qq00 = _mm256_mul_pd(iq0,jq0);
1202 qq01 = _mm256_mul_pd(iq0,jq1);
1203 qq02 = _mm256_mul_pd(iq0,jq2);
1204 qq10 = _mm256_mul_pd(iq1,jq0);
1205 qq11 = _mm256_mul_pd(iq1,jq1);
1206 qq12 = _mm256_mul_pd(iq1,jq2);
1207 qq20 = _mm256_mul_pd(iq2,jq0);
1208 qq21 = _mm256_mul_pd(iq2,jq1);
1209 qq22 = _mm256_mul_pd(iq2,jq2);
1211 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1212 rcutoff_scalar = fr->rcoulomb;
1213 rcutoff = _mm256_set1_pd(rcutoff_scalar);
1214 rcutoff2 = _mm256_mul_pd(rcutoff,rcutoff);
1216 /* Avoid stupid compiler warnings */
1217 jnrA = jnrB = jnrC = jnrD = 0;
1218 j_coord_offsetA = 0;
1219 j_coord_offsetB = 0;
1220 j_coord_offsetC = 0;
1221 j_coord_offsetD = 0;
1226 for(iidx=0;iidx<4*DIM;iidx++)
1228 scratch[iidx] = 0.0;
1231 /* Start outer loop over neighborlists */
1232 for(iidx=0; iidx<nri; iidx++)
1234 /* Load shift vector for this list */
1235 i_shift_offset = DIM*shiftidx[iidx];
1237 /* Load limits for loop over neighbors */
1238 j_index_start = jindex[iidx];
1239 j_index_end = jindex[iidx+1];
1241 /* Get outer coordinate index */
1243 i_coord_offset = DIM*inr;
1245 /* Load i particle coords and add shift vector */
1246 gmx_mm256_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
1247 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1249 fix0 = _mm256_setzero_pd();
1250 fiy0 = _mm256_setzero_pd();
1251 fiz0 = _mm256_setzero_pd();
1252 fix1 = _mm256_setzero_pd();
1253 fiy1 = _mm256_setzero_pd();
1254 fiz1 = _mm256_setzero_pd();
1255 fix2 = _mm256_setzero_pd();
1256 fiy2 = _mm256_setzero_pd();
1257 fiz2 = _mm256_setzero_pd();
1259 /* Start inner kernel loop */
1260 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1263 /* Get j neighbor index, and coordinate index */
1265 jnrB = jjnr[jidx+1];
1266 jnrC = jjnr[jidx+2];
1267 jnrD = jjnr[jidx+3];
1268 j_coord_offsetA = DIM*jnrA;
1269 j_coord_offsetB = DIM*jnrB;
1270 j_coord_offsetC = DIM*jnrC;
1271 j_coord_offsetD = DIM*jnrD;
1273 /* load j atom coordinates */
1274 gmx_mm256_load_3rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
1275 x+j_coord_offsetC,x+j_coord_offsetD,
1276 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1278 /* Calculate displacement vector */
1279 dx00 = _mm256_sub_pd(ix0,jx0);
1280 dy00 = _mm256_sub_pd(iy0,jy0);
1281 dz00 = _mm256_sub_pd(iz0,jz0);
1282 dx01 = _mm256_sub_pd(ix0,jx1);
1283 dy01 = _mm256_sub_pd(iy0,jy1);
1284 dz01 = _mm256_sub_pd(iz0,jz1);
1285 dx02 = _mm256_sub_pd(ix0,jx2);
1286 dy02 = _mm256_sub_pd(iy0,jy2);
1287 dz02 = _mm256_sub_pd(iz0,jz2);
1288 dx10 = _mm256_sub_pd(ix1,jx0);
1289 dy10 = _mm256_sub_pd(iy1,jy0);
1290 dz10 = _mm256_sub_pd(iz1,jz0);
1291 dx11 = _mm256_sub_pd(ix1,jx1);
1292 dy11 = _mm256_sub_pd(iy1,jy1);
1293 dz11 = _mm256_sub_pd(iz1,jz1);
1294 dx12 = _mm256_sub_pd(ix1,jx2);
1295 dy12 = _mm256_sub_pd(iy1,jy2);
1296 dz12 = _mm256_sub_pd(iz1,jz2);
1297 dx20 = _mm256_sub_pd(ix2,jx0);
1298 dy20 = _mm256_sub_pd(iy2,jy0);
1299 dz20 = _mm256_sub_pd(iz2,jz0);
1300 dx21 = _mm256_sub_pd(ix2,jx1);
1301 dy21 = _mm256_sub_pd(iy2,jy1);
1302 dz21 = _mm256_sub_pd(iz2,jz1);
1303 dx22 = _mm256_sub_pd(ix2,jx2);
1304 dy22 = _mm256_sub_pd(iy2,jy2);
1305 dz22 = _mm256_sub_pd(iz2,jz2);
1307 /* Calculate squared distance and things based on it */
1308 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
1309 rsq01 = gmx_mm256_calc_rsq_pd(dx01,dy01,dz01);
1310 rsq02 = gmx_mm256_calc_rsq_pd(dx02,dy02,dz02);
1311 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
1312 rsq11 = gmx_mm256_calc_rsq_pd(dx11,dy11,dz11);
1313 rsq12 = gmx_mm256_calc_rsq_pd(dx12,dy12,dz12);
1314 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
1315 rsq21 = gmx_mm256_calc_rsq_pd(dx21,dy21,dz21);
1316 rsq22 = gmx_mm256_calc_rsq_pd(dx22,dy22,dz22);
1318 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
1319 rinv01 = gmx_mm256_invsqrt_pd(rsq01);
1320 rinv02 = gmx_mm256_invsqrt_pd(rsq02);
1321 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
1322 rinv11 = gmx_mm256_invsqrt_pd(rsq11);
1323 rinv12 = gmx_mm256_invsqrt_pd(rsq12);
1324 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
1325 rinv21 = gmx_mm256_invsqrt_pd(rsq21);
1326 rinv22 = gmx_mm256_invsqrt_pd(rsq22);
1328 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
1329 rinvsq01 = _mm256_mul_pd(rinv01,rinv01);
1330 rinvsq02 = _mm256_mul_pd(rinv02,rinv02);
1331 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
1332 rinvsq11 = _mm256_mul_pd(rinv11,rinv11);
1333 rinvsq12 = _mm256_mul_pd(rinv12,rinv12);
1334 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
1335 rinvsq21 = _mm256_mul_pd(rinv21,rinv21);
1336 rinvsq22 = _mm256_mul_pd(rinv22,rinv22);
1338 fjx0 = _mm256_setzero_pd();
1339 fjy0 = _mm256_setzero_pd();
1340 fjz0 = _mm256_setzero_pd();
1341 fjx1 = _mm256_setzero_pd();
1342 fjy1 = _mm256_setzero_pd();
1343 fjz1 = _mm256_setzero_pd();
1344 fjx2 = _mm256_setzero_pd();
1345 fjy2 = _mm256_setzero_pd();
1346 fjz2 = _mm256_setzero_pd();
1348 /**************************
1349 * CALCULATE INTERACTIONS *
1350 **************************/
1352 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1355 /* REACTION-FIELD ELECTROSTATICS */
1356 felec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
1358 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
1362 fscal = _mm256_and_pd(fscal,cutoff_mask);
1364 /* Calculate temporary vectorial force */
1365 tx = _mm256_mul_pd(fscal,dx00);
1366 ty = _mm256_mul_pd(fscal,dy00);
1367 tz = _mm256_mul_pd(fscal,dz00);
1369 /* Update vectorial force */
1370 fix0 = _mm256_add_pd(fix0,tx);
1371 fiy0 = _mm256_add_pd(fiy0,ty);
1372 fiz0 = _mm256_add_pd(fiz0,tz);
1374 fjx0 = _mm256_add_pd(fjx0,tx);
1375 fjy0 = _mm256_add_pd(fjy0,ty);
1376 fjz0 = _mm256_add_pd(fjz0,tz);
1380 /**************************
1381 * CALCULATE INTERACTIONS *
1382 **************************/
1384 if (gmx_mm256_any_lt(rsq01,rcutoff2))
1387 /* REACTION-FIELD ELECTROSTATICS */
1388 felec = _mm256_mul_pd(qq01,_mm256_sub_pd(_mm256_mul_pd(rinv01,rinvsq01),krf2));
1390 cutoff_mask = _mm256_cmp_pd(rsq01,rcutoff2,_CMP_LT_OQ);
1394 fscal = _mm256_and_pd(fscal,cutoff_mask);
1396 /* Calculate temporary vectorial force */
1397 tx = _mm256_mul_pd(fscal,dx01);
1398 ty = _mm256_mul_pd(fscal,dy01);
1399 tz = _mm256_mul_pd(fscal,dz01);
1401 /* Update vectorial force */
1402 fix0 = _mm256_add_pd(fix0,tx);
1403 fiy0 = _mm256_add_pd(fiy0,ty);
1404 fiz0 = _mm256_add_pd(fiz0,tz);
1406 fjx1 = _mm256_add_pd(fjx1,tx);
1407 fjy1 = _mm256_add_pd(fjy1,ty);
1408 fjz1 = _mm256_add_pd(fjz1,tz);
1412 /**************************
1413 * CALCULATE INTERACTIONS *
1414 **************************/
1416 if (gmx_mm256_any_lt(rsq02,rcutoff2))
1419 /* REACTION-FIELD ELECTROSTATICS */
1420 felec = _mm256_mul_pd(qq02,_mm256_sub_pd(_mm256_mul_pd(rinv02,rinvsq02),krf2));
1422 cutoff_mask = _mm256_cmp_pd(rsq02,rcutoff2,_CMP_LT_OQ);
1426 fscal = _mm256_and_pd(fscal,cutoff_mask);
1428 /* Calculate temporary vectorial force */
1429 tx = _mm256_mul_pd(fscal,dx02);
1430 ty = _mm256_mul_pd(fscal,dy02);
1431 tz = _mm256_mul_pd(fscal,dz02);
1433 /* Update vectorial force */
1434 fix0 = _mm256_add_pd(fix0,tx);
1435 fiy0 = _mm256_add_pd(fiy0,ty);
1436 fiz0 = _mm256_add_pd(fiz0,tz);
1438 fjx2 = _mm256_add_pd(fjx2,tx);
1439 fjy2 = _mm256_add_pd(fjy2,ty);
1440 fjz2 = _mm256_add_pd(fjz2,tz);
1444 /**************************
1445 * CALCULATE INTERACTIONS *
1446 **************************/
1448 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1451 /* REACTION-FIELD ELECTROSTATICS */
1452 felec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_mul_pd(rinv10,rinvsq10),krf2));
1454 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
1458 fscal = _mm256_and_pd(fscal,cutoff_mask);
1460 /* Calculate temporary vectorial force */
1461 tx = _mm256_mul_pd(fscal,dx10);
1462 ty = _mm256_mul_pd(fscal,dy10);
1463 tz = _mm256_mul_pd(fscal,dz10);
1465 /* Update vectorial force */
1466 fix1 = _mm256_add_pd(fix1,tx);
1467 fiy1 = _mm256_add_pd(fiy1,ty);
1468 fiz1 = _mm256_add_pd(fiz1,tz);
1470 fjx0 = _mm256_add_pd(fjx0,tx);
1471 fjy0 = _mm256_add_pd(fjy0,ty);
1472 fjz0 = _mm256_add_pd(fjz0,tz);
1476 /**************************
1477 * CALCULATE INTERACTIONS *
1478 **************************/
1480 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1483 /* REACTION-FIELD ELECTROSTATICS */
1484 felec = _mm256_mul_pd(qq11,_mm256_sub_pd(_mm256_mul_pd(rinv11,rinvsq11),krf2));
1486 cutoff_mask = _mm256_cmp_pd(rsq11,rcutoff2,_CMP_LT_OQ);
1490 fscal = _mm256_and_pd(fscal,cutoff_mask);
1492 /* Calculate temporary vectorial force */
1493 tx = _mm256_mul_pd(fscal,dx11);
1494 ty = _mm256_mul_pd(fscal,dy11);
1495 tz = _mm256_mul_pd(fscal,dz11);
1497 /* Update vectorial force */
1498 fix1 = _mm256_add_pd(fix1,tx);
1499 fiy1 = _mm256_add_pd(fiy1,ty);
1500 fiz1 = _mm256_add_pd(fiz1,tz);
1502 fjx1 = _mm256_add_pd(fjx1,tx);
1503 fjy1 = _mm256_add_pd(fjy1,ty);
1504 fjz1 = _mm256_add_pd(fjz1,tz);
1508 /**************************
1509 * CALCULATE INTERACTIONS *
1510 **************************/
1512 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1515 /* REACTION-FIELD ELECTROSTATICS */
1516 felec = _mm256_mul_pd(qq12,_mm256_sub_pd(_mm256_mul_pd(rinv12,rinvsq12),krf2));
1518 cutoff_mask = _mm256_cmp_pd(rsq12,rcutoff2,_CMP_LT_OQ);
1522 fscal = _mm256_and_pd(fscal,cutoff_mask);
1524 /* Calculate temporary vectorial force */
1525 tx = _mm256_mul_pd(fscal,dx12);
1526 ty = _mm256_mul_pd(fscal,dy12);
1527 tz = _mm256_mul_pd(fscal,dz12);
1529 /* Update vectorial force */
1530 fix1 = _mm256_add_pd(fix1,tx);
1531 fiy1 = _mm256_add_pd(fiy1,ty);
1532 fiz1 = _mm256_add_pd(fiz1,tz);
1534 fjx2 = _mm256_add_pd(fjx2,tx);
1535 fjy2 = _mm256_add_pd(fjy2,ty);
1536 fjz2 = _mm256_add_pd(fjz2,tz);
1540 /**************************
1541 * CALCULATE INTERACTIONS *
1542 **************************/
1544 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1547 /* REACTION-FIELD ELECTROSTATICS */
1548 felec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_mul_pd(rinv20,rinvsq20),krf2));
1550 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
1554 fscal = _mm256_and_pd(fscal,cutoff_mask);
1556 /* Calculate temporary vectorial force */
1557 tx = _mm256_mul_pd(fscal,dx20);
1558 ty = _mm256_mul_pd(fscal,dy20);
1559 tz = _mm256_mul_pd(fscal,dz20);
1561 /* Update vectorial force */
1562 fix2 = _mm256_add_pd(fix2,tx);
1563 fiy2 = _mm256_add_pd(fiy2,ty);
1564 fiz2 = _mm256_add_pd(fiz2,tz);
1566 fjx0 = _mm256_add_pd(fjx0,tx);
1567 fjy0 = _mm256_add_pd(fjy0,ty);
1568 fjz0 = _mm256_add_pd(fjz0,tz);
1572 /**************************
1573 * CALCULATE INTERACTIONS *
1574 **************************/
1576 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1579 /* REACTION-FIELD ELECTROSTATICS */
1580 felec = _mm256_mul_pd(qq21,_mm256_sub_pd(_mm256_mul_pd(rinv21,rinvsq21),krf2));
1582 cutoff_mask = _mm256_cmp_pd(rsq21,rcutoff2,_CMP_LT_OQ);
1586 fscal = _mm256_and_pd(fscal,cutoff_mask);
1588 /* Calculate temporary vectorial force */
1589 tx = _mm256_mul_pd(fscal,dx21);
1590 ty = _mm256_mul_pd(fscal,dy21);
1591 tz = _mm256_mul_pd(fscal,dz21);
1593 /* Update vectorial force */
1594 fix2 = _mm256_add_pd(fix2,tx);
1595 fiy2 = _mm256_add_pd(fiy2,ty);
1596 fiz2 = _mm256_add_pd(fiz2,tz);
1598 fjx1 = _mm256_add_pd(fjx1,tx);
1599 fjy1 = _mm256_add_pd(fjy1,ty);
1600 fjz1 = _mm256_add_pd(fjz1,tz);
1604 /**************************
1605 * CALCULATE INTERACTIONS *
1606 **************************/
1608 if (gmx_mm256_any_lt(rsq22,rcutoff2))
1611 /* REACTION-FIELD ELECTROSTATICS */
1612 felec = _mm256_mul_pd(qq22,_mm256_sub_pd(_mm256_mul_pd(rinv22,rinvsq22),krf2));
1614 cutoff_mask = _mm256_cmp_pd(rsq22,rcutoff2,_CMP_LT_OQ);
1618 fscal = _mm256_and_pd(fscal,cutoff_mask);
1620 /* Calculate temporary vectorial force */
1621 tx = _mm256_mul_pd(fscal,dx22);
1622 ty = _mm256_mul_pd(fscal,dy22);
1623 tz = _mm256_mul_pd(fscal,dz22);
1625 /* Update vectorial force */
1626 fix2 = _mm256_add_pd(fix2,tx);
1627 fiy2 = _mm256_add_pd(fiy2,ty);
1628 fiz2 = _mm256_add_pd(fiz2,tz);
1630 fjx2 = _mm256_add_pd(fjx2,tx);
1631 fjy2 = _mm256_add_pd(fjy2,ty);
1632 fjz2 = _mm256_add_pd(fjz2,tz);
1636 fjptrA = f+j_coord_offsetA;
1637 fjptrB = f+j_coord_offsetB;
1638 fjptrC = f+j_coord_offsetC;
1639 fjptrD = f+j_coord_offsetD;
1641 gmx_mm256_decrement_3rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,
1642 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1644 /* Inner loop uses 270 flops */
1647 if(jidx<j_index_end)
1650 /* Get j neighbor index, and coordinate index */
1651 jnrlistA = jjnr[jidx];
1652 jnrlistB = jjnr[jidx+1];
1653 jnrlistC = jjnr[jidx+2];
1654 jnrlistD = jjnr[jidx+3];
1655 /* Sign of each element will be negative for non-real atoms.
1656 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1657 * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
1659 tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1661 tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
1662 tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
1663 dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
1665 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1666 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1667 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1668 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1669 j_coord_offsetA = DIM*jnrA;
1670 j_coord_offsetB = DIM*jnrB;
1671 j_coord_offsetC = DIM*jnrC;
1672 j_coord_offsetD = DIM*jnrD;
1674 /* load j atom coordinates */
1675 gmx_mm256_load_3rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
1676 x+j_coord_offsetC,x+j_coord_offsetD,
1677 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1679 /* Calculate displacement vector */
1680 dx00 = _mm256_sub_pd(ix0,jx0);
1681 dy00 = _mm256_sub_pd(iy0,jy0);
1682 dz00 = _mm256_sub_pd(iz0,jz0);
1683 dx01 = _mm256_sub_pd(ix0,jx1);
1684 dy01 = _mm256_sub_pd(iy0,jy1);
1685 dz01 = _mm256_sub_pd(iz0,jz1);
1686 dx02 = _mm256_sub_pd(ix0,jx2);
1687 dy02 = _mm256_sub_pd(iy0,jy2);
1688 dz02 = _mm256_sub_pd(iz0,jz2);
1689 dx10 = _mm256_sub_pd(ix1,jx0);
1690 dy10 = _mm256_sub_pd(iy1,jy0);
1691 dz10 = _mm256_sub_pd(iz1,jz0);
1692 dx11 = _mm256_sub_pd(ix1,jx1);
1693 dy11 = _mm256_sub_pd(iy1,jy1);
1694 dz11 = _mm256_sub_pd(iz1,jz1);
1695 dx12 = _mm256_sub_pd(ix1,jx2);
1696 dy12 = _mm256_sub_pd(iy1,jy2);
1697 dz12 = _mm256_sub_pd(iz1,jz2);
1698 dx20 = _mm256_sub_pd(ix2,jx0);
1699 dy20 = _mm256_sub_pd(iy2,jy0);
1700 dz20 = _mm256_sub_pd(iz2,jz0);
1701 dx21 = _mm256_sub_pd(ix2,jx1);
1702 dy21 = _mm256_sub_pd(iy2,jy1);
1703 dz21 = _mm256_sub_pd(iz2,jz1);
1704 dx22 = _mm256_sub_pd(ix2,jx2);
1705 dy22 = _mm256_sub_pd(iy2,jy2);
1706 dz22 = _mm256_sub_pd(iz2,jz2);
1708 /* Calculate squared distance and things based on it */
1709 rsq00 = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
1710 rsq01 = gmx_mm256_calc_rsq_pd(dx01,dy01,dz01);
1711 rsq02 = gmx_mm256_calc_rsq_pd(dx02,dy02,dz02);
1712 rsq10 = gmx_mm256_calc_rsq_pd(dx10,dy10,dz10);
1713 rsq11 = gmx_mm256_calc_rsq_pd(dx11,dy11,dz11);
1714 rsq12 = gmx_mm256_calc_rsq_pd(dx12,dy12,dz12);
1715 rsq20 = gmx_mm256_calc_rsq_pd(dx20,dy20,dz20);
1716 rsq21 = gmx_mm256_calc_rsq_pd(dx21,dy21,dz21);
1717 rsq22 = gmx_mm256_calc_rsq_pd(dx22,dy22,dz22);
1719 rinv00 = gmx_mm256_invsqrt_pd(rsq00);
1720 rinv01 = gmx_mm256_invsqrt_pd(rsq01);
1721 rinv02 = gmx_mm256_invsqrt_pd(rsq02);
1722 rinv10 = gmx_mm256_invsqrt_pd(rsq10);
1723 rinv11 = gmx_mm256_invsqrt_pd(rsq11);
1724 rinv12 = gmx_mm256_invsqrt_pd(rsq12);
1725 rinv20 = gmx_mm256_invsqrt_pd(rsq20);
1726 rinv21 = gmx_mm256_invsqrt_pd(rsq21);
1727 rinv22 = gmx_mm256_invsqrt_pd(rsq22);
1729 rinvsq00 = _mm256_mul_pd(rinv00,rinv00);
1730 rinvsq01 = _mm256_mul_pd(rinv01,rinv01);
1731 rinvsq02 = _mm256_mul_pd(rinv02,rinv02);
1732 rinvsq10 = _mm256_mul_pd(rinv10,rinv10);
1733 rinvsq11 = _mm256_mul_pd(rinv11,rinv11);
1734 rinvsq12 = _mm256_mul_pd(rinv12,rinv12);
1735 rinvsq20 = _mm256_mul_pd(rinv20,rinv20);
1736 rinvsq21 = _mm256_mul_pd(rinv21,rinv21);
1737 rinvsq22 = _mm256_mul_pd(rinv22,rinv22);
1739 fjx0 = _mm256_setzero_pd();
1740 fjy0 = _mm256_setzero_pd();
1741 fjz0 = _mm256_setzero_pd();
1742 fjx1 = _mm256_setzero_pd();
1743 fjy1 = _mm256_setzero_pd();
1744 fjz1 = _mm256_setzero_pd();
1745 fjx2 = _mm256_setzero_pd();
1746 fjy2 = _mm256_setzero_pd();
1747 fjz2 = _mm256_setzero_pd();
1749 /**************************
1750 * CALCULATE INTERACTIONS *
1751 **************************/
1753 if (gmx_mm256_any_lt(rsq00,rcutoff2))
1756 /* REACTION-FIELD ELECTROSTATICS */
1757 felec = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
1759 cutoff_mask = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
1763 fscal = _mm256_and_pd(fscal,cutoff_mask);
1765 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1767 /* Calculate temporary vectorial force */
1768 tx = _mm256_mul_pd(fscal,dx00);
1769 ty = _mm256_mul_pd(fscal,dy00);
1770 tz = _mm256_mul_pd(fscal,dz00);
1772 /* Update vectorial force */
1773 fix0 = _mm256_add_pd(fix0,tx);
1774 fiy0 = _mm256_add_pd(fiy0,ty);
1775 fiz0 = _mm256_add_pd(fiz0,tz);
1777 fjx0 = _mm256_add_pd(fjx0,tx);
1778 fjy0 = _mm256_add_pd(fjy0,ty);
1779 fjz0 = _mm256_add_pd(fjz0,tz);
1783 /**************************
1784 * CALCULATE INTERACTIONS *
1785 **************************/
1787 if (gmx_mm256_any_lt(rsq01,rcutoff2))
1790 /* REACTION-FIELD ELECTROSTATICS */
1791 felec = _mm256_mul_pd(qq01,_mm256_sub_pd(_mm256_mul_pd(rinv01,rinvsq01),krf2));
1793 cutoff_mask = _mm256_cmp_pd(rsq01,rcutoff2,_CMP_LT_OQ);
1797 fscal = _mm256_and_pd(fscal,cutoff_mask);
1799 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1801 /* Calculate temporary vectorial force */
1802 tx = _mm256_mul_pd(fscal,dx01);
1803 ty = _mm256_mul_pd(fscal,dy01);
1804 tz = _mm256_mul_pd(fscal,dz01);
1806 /* Update vectorial force */
1807 fix0 = _mm256_add_pd(fix0,tx);
1808 fiy0 = _mm256_add_pd(fiy0,ty);
1809 fiz0 = _mm256_add_pd(fiz0,tz);
1811 fjx1 = _mm256_add_pd(fjx1,tx);
1812 fjy1 = _mm256_add_pd(fjy1,ty);
1813 fjz1 = _mm256_add_pd(fjz1,tz);
1817 /**************************
1818 * CALCULATE INTERACTIONS *
1819 **************************/
1821 if (gmx_mm256_any_lt(rsq02,rcutoff2))
1824 /* REACTION-FIELD ELECTROSTATICS */
1825 felec = _mm256_mul_pd(qq02,_mm256_sub_pd(_mm256_mul_pd(rinv02,rinvsq02),krf2));
1827 cutoff_mask = _mm256_cmp_pd(rsq02,rcutoff2,_CMP_LT_OQ);
1831 fscal = _mm256_and_pd(fscal,cutoff_mask);
1833 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1835 /* Calculate temporary vectorial force */
1836 tx = _mm256_mul_pd(fscal,dx02);
1837 ty = _mm256_mul_pd(fscal,dy02);
1838 tz = _mm256_mul_pd(fscal,dz02);
1840 /* Update vectorial force */
1841 fix0 = _mm256_add_pd(fix0,tx);
1842 fiy0 = _mm256_add_pd(fiy0,ty);
1843 fiz0 = _mm256_add_pd(fiz0,tz);
1845 fjx2 = _mm256_add_pd(fjx2,tx);
1846 fjy2 = _mm256_add_pd(fjy2,ty);
1847 fjz2 = _mm256_add_pd(fjz2,tz);
1851 /**************************
1852 * CALCULATE INTERACTIONS *
1853 **************************/
1855 if (gmx_mm256_any_lt(rsq10,rcutoff2))
1858 /* REACTION-FIELD ELECTROSTATICS */
1859 felec = _mm256_mul_pd(qq10,_mm256_sub_pd(_mm256_mul_pd(rinv10,rinvsq10),krf2));
1861 cutoff_mask = _mm256_cmp_pd(rsq10,rcutoff2,_CMP_LT_OQ);
1865 fscal = _mm256_and_pd(fscal,cutoff_mask);
1867 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1869 /* Calculate temporary vectorial force */
1870 tx = _mm256_mul_pd(fscal,dx10);
1871 ty = _mm256_mul_pd(fscal,dy10);
1872 tz = _mm256_mul_pd(fscal,dz10);
1874 /* Update vectorial force */
1875 fix1 = _mm256_add_pd(fix1,tx);
1876 fiy1 = _mm256_add_pd(fiy1,ty);
1877 fiz1 = _mm256_add_pd(fiz1,tz);
1879 fjx0 = _mm256_add_pd(fjx0,tx);
1880 fjy0 = _mm256_add_pd(fjy0,ty);
1881 fjz0 = _mm256_add_pd(fjz0,tz);
1885 /**************************
1886 * CALCULATE INTERACTIONS *
1887 **************************/
1889 if (gmx_mm256_any_lt(rsq11,rcutoff2))
1892 /* REACTION-FIELD ELECTROSTATICS */
1893 felec = _mm256_mul_pd(qq11,_mm256_sub_pd(_mm256_mul_pd(rinv11,rinvsq11),krf2));
1895 cutoff_mask = _mm256_cmp_pd(rsq11,rcutoff2,_CMP_LT_OQ);
1899 fscal = _mm256_and_pd(fscal,cutoff_mask);
1901 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1903 /* Calculate temporary vectorial force */
1904 tx = _mm256_mul_pd(fscal,dx11);
1905 ty = _mm256_mul_pd(fscal,dy11);
1906 tz = _mm256_mul_pd(fscal,dz11);
1908 /* Update vectorial force */
1909 fix1 = _mm256_add_pd(fix1,tx);
1910 fiy1 = _mm256_add_pd(fiy1,ty);
1911 fiz1 = _mm256_add_pd(fiz1,tz);
1913 fjx1 = _mm256_add_pd(fjx1,tx);
1914 fjy1 = _mm256_add_pd(fjy1,ty);
1915 fjz1 = _mm256_add_pd(fjz1,tz);
1919 /**************************
1920 * CALCULATE INTERACTIONS *
1921 **************************/
1923 if (gmx_mm256_any_lt(rsq12,rcutoff2))
1926 /* REACTION-FIELD ELECTROSTATICS */
1927 felec = _mm256_mul_pd(qq12,_mm256_sub_pd(_mm256_mul_pd(rinv12,rinvsq12),krf2));
1929 cutoff_mask = _mm256_cmp_pd(rsq12,rcutoff2,_CMP_LT_OQ);
1933 fscal = _mm256_and_pd(fscal,cutoff_mask);
1935 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1937 /* Calculate temporary vectorial force */
1938 tx = _mm256_mul_pd(fscal,dx12);
1939 ty = _mm256_mul_pd(fscal,dy12);
1940 tz = _mm256_mul_pd(fscal,dz12);
1942 /* Update vectorial force */
1943 fix1 = _mm256_add_pd(fix1,tx);
1944 fiy1 = _mm256_add_pd(fiy1,ty);
1945 fiz1 = _mm256_add_pd(fiz1,tz);
1947 fjx2 = _mm256_add_pd(fjx2,tx);
1948 fjy2 = _mm256_add_pd(fjy2,ty);
1949 fjz2 = _mm256_add_pd(fjz2,tz);
1953 /**************************
1954 * CALCULATE INTERACTIONS *
1955 **************************/
1957 if (gmx_mm256_any_lt(rsq20,rcutoff2))
1960 /* REACTION-FIELD ELECTROSTATICS */
1961 felec = _mm256_mul_pd(qq20,_mm256_sub_pd(_mm256_mul_pd(rinv20,rinvsq20),krf2));
1963 cutoff_mask = _mm256_cmp_pd(rsq20,rcutoff2,_CMP_LT_OQ);
1967 fscal = _mm256_and_pd(fscal,cutoff_mask);
1969 fscal = _mm256_andnot_pd(dummy_mask,fscal);
1971 /* Calculate temporary vectorial force */
1972 tx = _mm256_mul_pd(fscal,dx20);
1973 ty = _mm256_mul_pd(fscal,dy20);
1974 tz = _mm256_mul_pd(fscal,dz20);
1976 /* Update vectorial force */
1977 fix2 = _mm256_add_pd(fix2,tx);
1978 fiy2 = _mm256_add_pd(fiy2,ty);
1979 fiz2 = _mm256_add_pd(fiz2,tz);
1981 fjx0 = _mm256_add_pd(fjx0,tx);
1982 fjy0 = _mm256_add_pd(fjy0,ty);
1983 fjz0 = _mm256_add_pd(fjz0,tz);
1987 /**************************
1988 * CALCULATE INTERACTIONS *
1989 **************************/
1991 if (gmx_mm256_any_lt(rsq21,rcutoff2))
1994 /* REACTION-FIELD ELECTROSTATICS */
1995 felec = _mm256_mul_pd(qq21,_mm256_sub_pd(_mm256_mul_pd(rinv21,rinvsq21),krf2));
1997 cutoff_mask = _mm256_cmp_pd(rsq21,rcutoff2,_CMP_LT_OQ);
2001 fscal = _mm256_and_pd(fscal,cutoff_mask);
2003 fscal = _mm256_andnot_pd(dummy_mask,fscal);
2005 /* Calculate temporary vectorial force */
2006 tx = _mm256_mul_pd(fscal,dx21);
2007 ty = _mm256_mul_pd(fscal,dy21);
2008 tz = _mm256_mul_pd(fscal,dz21);
2010 /* Update vectorial force */
2011 fix2 = _mm256_add_pd(fix2,tx);
2012 fiy2 = _mm256_add_pd(fiy2,ty);
2013 fiz2 = _mm256_add_pd(fiz2,tz);
2015 fjx1 = _mm256_add_pd(fjx1,tx);
2016 fjy1 = _mm256_add_pd(fjy1,ty);
2017 fjz1 = _mm256_add_pd(fjz1,tz);
2021 /**************************
2022 * CALCULATE INTERACTIONS *
2023 **************************/
2025 if (gmx_mm256_any_lt(rsq22,rcutoff2))
2028 /* REACTION-FIELD ELECTROSTATICS */
2029 felec = _mm256_mul_pd(qq22,_mm256_sub_pd(_mm256_mul_pd(rinv22,rinvsq22),krf2));
2031 cutoff_mask = _mm256_cmp_pd(rsq22,rcutoff2,_CMP_LT_OQ);
2035 fscal = _mm256_and_pd(fscal,cutoff_mask);
2037 fscal = _mm256_andnot_pd(dummy_mask,fscal);
2039 /* Calculate temporary vectorial force */
2040 tx = _mm256_mul_pd(fscal,dx22);
2041 ty = _mm256_mul_pd(fscal,dy22);
2042 tz = _mm256_mul_pd(fscal,dz22);
2044 /* Update vectorial force */
2045 fix2 = _mm256_add_pd(fix2,tx);
2046 fiy2 = _mm256_add_pd(fiy2,ty);
2047 fiz2 = _mm256_add_pd(fiz2,tz);
2049 fjx2 = _mm256_add_pd(fjx2,tx);
2050 fjy2 = _mm256_add_pd(fjy2,ty);
2051 fjz2 = _mm256_add_pd(fjz2,tz);
2055 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2056 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2057 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2058 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2060 gmx_mm256_decrement_3rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,
2061 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2063 /* Inner loop uses 270 flops */
2066 /* End of innermost loop */
2068 gmx_mm256_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2069 f+i_coord_offset,fshift+i_shift_offset);
2071 /* Increment number of inner iterations */
2072 inneriter += j_index_end - j_index_start;
2074 /* Outer loop uses 18 flops */
2077 /* Increment number of outer iterations */
2080 /* Update outer/inner flops */
2082 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_F,outeriter*18 + inneriter*270);