2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Water3-Water3
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
94 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
95 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
96 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
97 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
98 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
99 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
100 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
101 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
102 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
103 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
104 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
105 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
106 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
109 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
112 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
113 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
114 __m128 dummy_mask,cutoff_mask;
115 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
116 __m128 one = _mm_set1_ps(1.0);
117 __m128 two = _mm_set1_ps(2.0);
123 jindex = nlist->jindex;
125 shiftidx = nlist->shift;
127 shiftvec = fr->shift_vec[0];
128 fshift = fr->fshift[0];
129 facel = _mm_set1_ps(fr->epsfac);
130 charge = mdatoms->chargeA;
131 krf = _mm_set1_ps(fr->ic->k_rf);
132 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
133 crf = _mm_set1_ps(fr->ic->c_rf);
134 nvdwtype = fr->ntype;
136 vdwtype = mdatoms->typeA;
138 /* Setup water-specific parameters */
139 inr = nlist->iinr[0];
140 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
141 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
142 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
143 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
145 jq0 = _mm_set1_ps(charge[inr+0]);
146 jq1 = _mm_set1_ps(charge[inr+1]);
147 jq2 = _mm_set1_ps(charge[inr+2]);
148 vdwjidx0A = 2*vdwtype[inr+0];
149 qq00 = _mm_mul_ps(iq0,jq0);
150 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
151 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
152 qq01 = _mm_mul_ps(iq0,jq1);
153 qq02 = _mm_mul_ps(iq0,jq2);
154 qq10 = _mm_mul_ps(iq1,jq0);
155 qq11 = _mm_mul_ps(iq1,jq1);
156 qq12 = _mm_mul_ps(iq1,jq2);
157 qq20 = _mm_mul_ps(iq2,jq0);
158 qq21 = _mm_mul_ps(iq2,jq1);
159 qq22 = _mm_mul_ps(iq2,jq2);
161 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
162 rcutoff_scalar = fr->rcoulomb;
163 rcutoff = _mm_set1_ps(rcutoff_scalar);
164 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
166 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
167 rvdw = _mm_set1_ps(fr->rvdw);
169 /* Avoid stupid compiler warnings */
170 jnrA = jnrB = jnrC = jnrD = 0;
179 for(iidx=0;iidx<4*DIM;iidx++)
184 /* Start outer loop over neighborlists */
185 for(iidx=0; iidx<nri; iidx++)
187 /* Load shift vector for this list */
188 i_shift_offset = DIM*shiftidx[iidx];
190 /* Load limits for loop over neighbors */
191 j_index_start = jindex[iidx];
192 j_index_end = jindex[iidx+1];
194 /* Get outer coordinate index */
196 i_coord_offset = DIM*inr;
198 /* Load i particle coords and add shift vector */
199 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
200 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
202 fix0 = _mm_setzero_ps();
203 fiy0 = _mm_setzero_ps();
204 fiz0 = _mm_setzero_ps();
205 fix1 = _mm_setzero_ps();
206 fiy1 = _mm_setzero_ps();
207 fiz1 = _mm_setzero_ps();
208 fix2 = _mm_setzero_ps();
209 fiy2 = _mm_setzero_ps();
210 fiz2 = _mm_setzero_ps();
212 /* Reset potential sums */
213 velecsum = _mm_setzero_ps();
214 vvdwsum = _mm_setzero_ps();
216 /* Start inner kernel loop */
217 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
220 /* Get j neighbor index, and coordinate index */
225 j_coord_offsetA = DIM*jnrA;
226 j_coord_offsetB = DIM*jnrB;
227 j_coord_offsetC = DIM*jnrC;
228 j_coord_offsetD = DIM*jnrD;
230 /* load j atom coordinates */
231 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
232 x+j_coord_offsetC,x+j_coord_offsetD,
233 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
235 /* Calculate displacement vector */
236 dx00 = _mm_sub_ps(ix0,jx0);
237 dy00 = _mm_sub_ps(iy0,jy0);
238 dz00 = _mm_sub_ps(iz0,jz0);
239 dx01 = _mm_sub_ps(ix0,jx1);
240 dy01 = _mm_sub_ps(iy0,jy1);
241 dz01 = _mm_sub_ps(iz0,jz1);
242 dx02 = _mm_sub_ps(ix0,jx2);
243 dy02 = _mm_sub_ps(iy0,jy2);
244 dz02 = _mm_sub_ps(iz0,jz2);
245 dx10 = _mm_sub_ps(ix1,jx0);
246 dy10 = _mm_sub_ps(iy1,jy0);
247 dz10 = _mm_sub_ps(iz1,jz0);
248 dx11 = _mm_sub_ps(ix1,jx1);
249 dy11 = _mm_sub_ps(iy1,jy1);
250 dz11 = _mm_sub_ps(iz1,jz1);
251 dx12 = _mm_sub_ps(ix1,jx2);
252 dy12 = _mm_sub_ps(iy1,jy2);
253 dz12 = _mm_sub_ps(iz1,jz2);
254 dx20 = _mm_sub_ps(ix2,jx0);
255 dy20 = _mm_sub_ps(iy2,jy0);
256 dz20 = _mm_sub_ps(iz2,jz0);
257 dx21 = _mm_sub_ps(ix2,jx1);
258 dy21 = _mm_sub_ps(iy2,jy1);
259 dz21 = _mm_sub_ps(iz2,jz1);
260 dx22 = _mm_sub_ps(ix2,jx2);
261 dy22 = _mm_sub_ps(iy2,jy2);
262 dz22 = _mm_sub_ps(iz2,jz2);
264 /* Calculate squared distance and things based on it */
265 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
266 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
267 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
268 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
269 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
270 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
271 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
272 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
273 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
275 rinv00 = gmx_mm_invsqrt_ps(rsq00);
276 rinv01 = gmx_mm_invsqrt_ps(rsq01);
277 rinv02 = gmx_mm_invsqrt_ps(rsq02);
278 rinv10 = gmx_mm_invsqrt_ps(rsq10);
279 rinv11 = gmx_mm_invsqrt_ps(rsq11);
280 rinv12 = gmx_mm_invsqrt_ps(rsq12);
281 rinv20 = gmx_mm_invsqrt_ps(rsq20);
282 rinv21 = gmx_mm_invsqrt_ps(rsq21);
283 rinv22 = gmx_mm_invsqrt_ps(rsq22);
285 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
286 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
287 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
288 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
289 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
290 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
291 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
292 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
293 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
295 fjx0 = _mm_setzero_ps();
296 fjy0 = _mm_setzero_ps();
297 fjz0 = _mm_setzero_ps();
298 fjx1 = _mm_setzero_ps();
299 fjy1 = _mm_setzero_ps();
300 fjz1 = _mm_setzero_ps();
301 fjx2 = _mm_setzero_ps();
302 fjy2 = _mm_setzero_ps();
303 fjz2 = _mm_setzero_ps();
305 /**************************
306 * CALCULATE INTERACTIONS *
307 **************************/
309 if (gmx_mm_any_lt(rsq00,rcutoff2))
312 /* REACTION-FIELD ELECTROSTATICS */
313 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
314 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
316 /* LENNARD-JONES DISPERSION/REPULSION */
318 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
319 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
320 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
321 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
322 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
323 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
325 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
327 /* Update potential sum for this i atom from the interaction with this j atom. */
328 velec = _mm_and_ps(velec,cutoff_mask);
329 velecsum = _mm_add_ps(velecsum,velec);
330 vvdw = _mm_and_ps(vvdw,cutoff_mask);
331 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
333 fscal = _mm_add_ps(felec,fvdw);
335 fscal = _mm_and_ps(fscal,cutoff_mask);
337 /* Update vectorial force */
338 fix0 = _mm_macc_ps(dx00,fscal,fix0);
339 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
340 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
342 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
343 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
344 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
348 /**************************
349 * CALCULATE INTERACTIONS *
350 **************************/
352 if (gmx_mm_any_lt(rsq01,rcutoff2))
355 /* REACTION-FIELD ELECTROSTATICS */
356 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
357 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
359 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
361 /* Update potential sum for this i atom from the interaction with this j atom. */
362 velec = _mm_and_ps(velec,cutoff_mask);
363 velecsum = _mm_add_ps(velecsum,velec);
367 fscal = _mm_and_ps(fscal,cutoff_mask);
369 /* Update vectorial force */
370 fix0 = _mm_macc_ps(dx01,fscal,fix0);
371 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
372 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
374 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
375 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
376 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
380 /**************************
381 * CALCULATE INTERACTIONS *
382 **************************/
384 if (gmx_mm_any_lt(rsq02,rcutoff2))
387 /* REACTION-FIELD ELECTROSTATICS */
388 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
389 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
391 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
393 /* Update potential sum for this i atom from the interaction with this j atom. */
394 velec = _mm_and_ps(velec,cutoff_mask);
395 velecsum = _mm_add_ps(velecsum,velec);
399 fscal = _mm_and_ps(fscal,cutoff_mask);
401 /* Update vectorial force */
402 fix0 = _mm_macc_ps(dx02,fscal,fix0);
403 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
404 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
406 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
407 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
408 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
412 /**************************
413 * CALCULATE INTERACTIONS *
414 **************************/
416 if (gmx_mm_any_lt(rsq10,rcutoff2))
419 /* REACTION-FIELD ELECTROSTATICS */
420 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
421 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
423 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
425 /* Update potential sum for this i atom from the interaction with this j atom. */
426 velec = _mm_and_ps(velec,cutoff_mask);
427 velecsum = _mm_add_ps(velecsum,velec);
431 fscal = _mm_and_ps(fscal,cutoff_mask);
433 /* Update vectorial force */
434 fix1 = _mm_macc_ps(dx10,fscal,fix1);
435 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
436 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
438 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
439 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
440 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
444 /**************************
445 * CALCULATE INTERACTIONS *
446 **************************/
448 if (gmx_mm_any_lt(rsq11,rcutoff2))
451 /* REACTION-FIELD ELECTROSTATICS */
452 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
453 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
455 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
457 /* Update potential sum for this i atom from the interaction with this j atom. */
458 velec = _mm_and_ps(velec,cutoff_mask);
459 velecsum = _mm_add_ps(velecsum,velec);
463 fscal = _mm_and_ps(fscal,cutoff_mask);
465 /* Update vectorial force */
466 fix1 = _mm_macc_ps(dx11,fscal,fix1);
467 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
468 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
470 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
471 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
472 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
476 /**************************
477 * CALCULATE INTERACTIONS *
478 **************************/
480 if (gmx_mm_any_lt(rsq12,rcutoff2))
483 /* REACTION-FIELD ELECTROSTATICS */
484 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
485 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
487 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
489 /* Update potential sum for this i atom from the interaction with this j atom. */
490 velec = _mm_and_ps(velec,cutoff_mask);
491 velecsum = _mm_add_ps(velecsum,velec);
495 fscal = _mm_and_ps(fscal,cutoff_mask);
497 /* Update vectorial force */
498 fix1 = _mm_macc_ps(dx12,fscal,fix1);
499 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
500 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
502 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
503 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
504 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
508 /**************************
509 * CALCULATE INTERACTIONS *
510 **************************/
512 if (gmx_mm_any_lt(rsq20,rcutoff2))
515 /* REACTION-FIELD ELECTROSTATICS */
516 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
517 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
519 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
521 /* Update potential sum for this i atom from the interaction with this j atom. */
522 velec = _mm_and_ps(velec,cutoff_mask);
523 velecsum = _mm_add_ps(velecsum,velec);
527 fscal = _mm_and_ps(fscal,cutoff_mask);
529 /* Update vectorial force */
530 fix2 = _mm_macc_ps(dx20,fscal,fix2);
531 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
532 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
534 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
535 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
536 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
540 /**************************
541 * CALCULATE INTERACTIONS *
542 **************************/
544 if (gmx_mm_any_lt(rsq21,rcutoff2))
547 /* REACTION-FIELD ELECTROSTATICS */
548 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
549 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
551 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
553 /* Update potential sum for this i atom from the interaction with this j atom. */
554 velec = _mm_and_ps(velec,cutoff_mask);
555 velecsum = _mm_add_ps(velecsum,velec);
559 fscal = _mm_and_ps(fscal,cutoff_mask);
561 /* Update vectorial force */
562 fix2 = _mm_macc_ps(dx21,fscal,fix2);
563 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
564 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
566 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
567 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
568 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
572 /**************************
573 * CALCULATE INTERACTIONS *
574 **************************/
576 if (gmx_mm_any_lt(rsq22,rcutoff2))
579 /* REACTION-FIELD ELECTROSTATICS */
580 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
581 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
583 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
585 /* Update potential sum for this i atom from the interaction with this j atom. */
586 velec = _mm_and_ps(velec,cutoff_mask);
587 velecsum = _mm_add_ps(velecsum,velec);
591 fscal = _mm_and_ps(fscal,cutoff_mask);
593 /* Update vectorial force */
594 fix2 = _mm_macc_ps(dx22,fscal,fix2);
595 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
596 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
598 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
599 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
600 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
604 fjptrA = f+j_coord_offsetA;
605 fjptrB = f+j_coord_offsetB;
606 fjptrC = f+j_coord_offsetC;
607 fjptrD = f+j_coord_offsetD;
609 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
610 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
612 /* Inner loop uses 369 flops */
618 /* Get j neighbor index, and coordinate index */
619 jnrlistA = jjnr[jidx];
620 jnrlistB = jjnr[jidx+1];
621 jnrlistC = jjnr[jidx+2];
622 jnrlistD = jjnr[jidx+3];
623 /* Sign of each element will be negative for non-real atoms.
624 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
625 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
627 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
628 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
629 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
630 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
631 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
632 j_coord_offsetA = DIM*jnrA;
633 j_coord_offsetB = DIM*jnrB;
634 j_coord_offsetC = DIM*jnrC;
635 j_coord_offsetD = DIM*jnrD;
637 /* load j atom coordinates */
638 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
639 x+j_coord_offsetC,x+j_coord_offsetD,
640 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
642 /* Calculate displacement vector */
643 dx00 = _mm_sub_ps(ix0,jx0);
644 dy00 = _mm_sub_ps(iy0,jy0);
645 dz00 = _mm_sub_ps(iz0,jz0);
646 dx01 = _mm_sub_ps(ix0,jx1);
647 dy01 = _mm_sub_ps(iy0,jy1);
648 dz01 = _mm_sub_ps(iz0,jz1);
649 dx02 = _mm_sub_ps(ix0,jx2);
650 dy02 = _mm_sub_ps(iy0,jy2);
651 dz02 = _mm_sub_ps(iz0,jz2);
652 dx10 = _mm_sub_ps(ix1,jx0);
653 dy10 = _mm_sub_ps(iy1,jy0);
654 dz10 = _mm_sub_ps(iz1,jz0);
655 dx11 = _mm_sub_ps(ix1,jx1);
656 dy11 = _mm_sub_ps(iy1,jy1);
657 dz11 = _mm_sub_ps(iz1,jz1);
658 dx12 = _mm_sub_ps(ix1,jx2);
659 dy12 = _mm_sub_ps(iy1,jy2);
660 dz12 = _mm_sub_ps(iz1,jz2);
661 dx20 = _mm_sub_ps(ix2,jx0);
662 dy20 = _mm_sub_ps(iy2,jy0);
663 dz20 = _mm_sub_ps(iz2,jz0);
664 dx21 = _mm_sub_ps(ix2,jx1);
665 dy21 = _mm_sub_ps(iy2,jy1);
666 dz21 = _mm_sub_ps(iz2,jz1);
667 dx22 = _mm_sub_ps(ix2,jx2);
668 dy22 = _mm_sub_ps(iy2,jy2);
669 dz22 = _mm_sub_ps(iz2,jz2);
671 /* Calculate squared distance and things based on it */
672 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
673 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
674 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
675 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
676 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
677 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
678 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
679 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
680 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
682 rinv00 = gmx_mm_invsqrt_ps(rsq00);
683 rinv01 = gmx_mm_invsqrt_ps(rsq01);
684 rinv02 = gmx_mm_invsqrt_ps(rsq02);
685 rinv10 = gmx_mm_invsqrt_ps(rsq10);
686 rinv11 = gmx_mm_invsqrt_ps(rsq11);
687 rinv12 = gmx_mm_invsqrt_ps(rsq12);
688 rinv20 = gmx_mm_invsqrt_ps(rsq20);
689 rinv21 = gmx_mm_invsqrt_ps(rsq21);
690 rinv22 = gmx_mm_invsqrt_ps(rsq22);
692 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
693 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
694 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
695 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
696 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
697 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
698 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
699 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
700 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
702 fjx0 = _mm_setzero_ps();
703 fjy0 = _mm_setzero_ps();
704 fjz0 = _mm_setzero_ps();
705 fjx1 = _mm_setzero_ps();
706 fjy1 = _mm_setzero_ps();
707 fjz1 = _mm_setzero_ps();
708 fjx2 = _mm_setzero_ps();
709 fjy2 = _mm_setzero_ps();
710 fjz2 = _mm_setzero_ps();
712 /**************************
713 * CALCULATE INTERACTIONS *
714 **************************/
716 if (gmx_mm_any_lt(rsq00,rcutoff2))
719 /* REACTION-FIELD ELECTROSTATICS */
720 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
721 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
723 /* LENNARD-JONES DISPERSION/REPULSION */
725 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
726 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
727 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
728 vvdw = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
729 _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
730 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
732 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
734 /* Update potential sum for this i atom from the interaction with this j atom. */
735 velec = _mm_and_ps(velec,cutoff_mask);
736 velec = _mm_andnot_ps(dummy_mask,velec);
737 velecsum = _mm_add_ps(velecsum,velec);
738 vvdw = _mm_and_ps(vvdw,cutoff_mask);
739 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
740 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
742 fscal = _mm_add_ps(felec,fvdw);
744 fscal = _mm_and_ps(fscal,cutoff_mask);
746 fscal = _mm_andnot_ps(dummy_mask,fscal);
748 /* Update vectorial force */
749 fix0 = _mm_macc_ps(dx00,fscal,fix0);
750 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
751 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
753 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
754 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
755 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
759 /**************************
760 * CALCULATE INTERACTIONS *
761 **************************/
763 if (gmx_mm_any_lt(rsq01,rcutoff2))
766 /* REACTION-FIELD ELECTROSTATICS */
767 velec = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
768 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
770 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
772 /* Update potential sum for this i atom from the interaction with this j atom. */
773 velec = _mm_and_ps(velec,cutoff_mask);
774 velec = _mm_andnot_ps(dummy_mask,velec);
775 velecsum = _mm_add_ps(velecsum,velec);
779 fscal = _mm_and_ps(fscal,cutoff_mask);
781 fscal = _mm_andnot_ps(dummy_mask,fscal);
783 /* Update vectorial force */
784 fix0 = _mm_macc_ps(dx01,fscal,fix0);
785 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
786 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
788 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
789 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
790 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
794 /**************************
795 * CALCULATE INTERACTIONS *
796 **************************/
798 if (gmx_mm_any_lt(rsq02,rcutoff2))
801 /* REACTION-FIELD ELECTROSTATICS */
802 velec = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
803 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
805 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
807 /* Update potential sum for this i atom from the interaction with this j atom. */
808 velec = _mm_and_ps(velec,cutoff_mask);
809 velec = _mm_andnot_ps(dummy_mask,velec);
810 velecsum = _mm_add_ps(velecsum,velec);
814 fscal = _mm_and_ps(fscal,cutoff_mask);
816 fscal = _mm_andnot_ps(dummy_mask,fscal);
818 /* Update vectorial force */
819 fix0 = _mm_macc_ps(dx02,fscal,fix0);
820 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
821 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
823 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
824 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
825 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
829 /**************************
830 * CALCULATE INTERACTIONS *
831 **************************/
833 if (gmx_mm_any_lt(rsq10,rcutoff2))
836 /* REACTION-FIELD ELECTROSTATICS */
837 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
838 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
840 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
842 /* Update potential sum for this i atom from the interaction with this j atom. */
843 velec = _mm_and_ps(velec,cutoff_mask);
844 velec = _mm_andnot_ps(dummy_mask,velec);
845 velecsum = _mm_add_ps(velecsum,velec);
849 fscal = _mm_and_ps(fscal,cutoff_mask);
851 fscal = _mm_andnot_ps(dummy_mask,fscal);
853 /* Update vectorial force */
854 fix1 = _mm_macc_ps(dx10,fscal,fix1);
855 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
856 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
858 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
859 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
860 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
864 /**************************
865 * CALCULATE INTERACTIONS *
866 **************************/
868 if (gmx_mm_any_lt(rsq11,rcutoff2))
871 /* REACTION-FIELD ELECTROSTATICS */
872 velec = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
873 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
875 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
877 /* Update potential sum for this i atom from the interaction with this j atom. */
878 velec = _mm_and_ps(velec,cutoff_mask);
879 velec = _mm_andnot_ps(dummy_mask,velec);
880 velecsum = _mm_add_ps(velecsum,velec);
884 fscal = _mm_and_ps(fscal,cutoff_mask);
886 fscal = _mm_andnot_ps(dummy_mask,fscal);
888 /* Update vectorial force */
889 fix1 = _mm_macc_ps(dx11,fscal,fix1);
890 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
891 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
893 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
894 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
895 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
899 /**************************
900 * CALCULATE INTERACTIONS *
901 **************************/
903 if (gmx_mm_any_lt(rsq12,rcutoff2))
906 /* REACTION-FIELD ELECTROSTATICS */
907 velec = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
908 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
910 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
912 /* Update potential sum for this i atom from the interaction with this j atom. */
913 velec = _mm_and_ps(velec,cutoff_mask);
914 velec = _mm_andnot_ps(dummy_mask,velec);
915 velecsum = _mm_add_ps(velecsum,velec);
919 fscal = _mm_and_ps(fscal,cutoff_mask);
921 fscal = _mm_andnot_ps(dummy_mask,fscal);
923 /* Update vectorial force */
924 fix1 = _mm_macc_ps(dx12,fscal,fix1);
925 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
926 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
928 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
929 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
930 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
934 /**************************
935 * CALCULATE INTERACTIONS *
936 **************************/
938 if (gmx_mm_any_lt(rsq20,rcutoff2))
941 /* REACTION-FIELD ELECTROSTATICS */
942 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
943 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
945 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
947 /* Update potential sum for this i atom from the interaction with this j atom. */
948 velec = _mm_and_ps(velec,cutoff_mask);
949 velec = _mm_andnot_ps(dummy_mask,velec);
950 velecsum = _mm_add_ps(velecsum,velec);
954 fscal = _mm_and_ps(fscal,cutoff_mask);
956 fscal = _mm_andnot_ps(dummy_mask,fscal);
958 /* Update vectorial force */
959 fix2 = _mm_macc_ps(dx20,fscal,fix2);
960 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
961 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
963 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
964 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
965 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
969 /**************************
970 * CALCULATE INTERACTIONS *
971 **************************/
973 if (gmx_mm_any_lt(rsq21,rcutoff2))
976 /* REACTION-FIELD ELECTROSTATICS */
977 velec = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
978 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
980 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
982 /* Update potential sum for this i atom from the interaction with this j atom. */
983 velec = _mm_and_ps(velec,cutoff_mask);
984 velec = _mm_andnot_ps(dummy_mask,velec);
985 velecsum = _mm_add_ps(velecsum,velec);
989 fscal = _mm_and_ps(fscal,cutoff_mask);
991 fscal = _mm_andnot_ps(dummy_mask,fscal);
993 /* Update vectorial force */
994 fix2 = _mm_macc_ps(dx21,fscal,fix2);
995 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
996 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
998 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
999 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1000 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1004 /**************************
1005 * CALCULATE INTERACTIONS *
1006 **************************/
1008 if (gmx_mm_any_lt(rsq22,rcutoff2))
1011 /* REACTION-FIELD ELECTROSTATICS */
1012 velec = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
1013 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1015 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1017 /* Update potential sum for this i atom from the interaction with this j atom. */
1018 velec = _mm_and_ps(velec,cutoff_mask);
1019 velec = _mm_andnot_ps(dummy_mask,velec);
1020 velecsum = _mm_add_ps(velecsum,velec);
1024 fscal = _mm_and_ps(fscal,cutoff_mask);
1026 fscal = _mm_andnot_ps(dummy_mask,fscal);
1028 /* Update vectorial force */
1029 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1030 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1031 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1033 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1034 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1035 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1039 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1040 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1041 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1042 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1044 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1045 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1047 /* Inner loop uses 369 flops */
1050 /* End of innermost loop */
1052 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1053 f+i_coord_offset,fshift+i_shift_offset);
1056 /* Update potential energies */
1057 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1058 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1060 /* Increment number of inner iterations */
1061 inneriter += j_index_end - j_index_start;
1063 /* Outer loop uses 20 flops */
1066 /* Increment number of outer iterations */
1069 /* Update outer/inner flops */
1071 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*369);
1074 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_128_fma_single
1075 * Electrostatics interaction: ReactionField
1076 * VdW interaction: LennardJones
1077 * Geometry: Water3-Water3
1078 * Calculate force/pot: Force
1081 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_128_fma_single
1082 (t_nblist * gmx_restrict nlist,
1083 rvec * gmx_restrict xx,
1084 rvec * gmx_restrict ff,
1085 t_forcerec * gmx_restrict fr,
1086 t_mdatoms * gmx_restrict mdatoms,
1087 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1088 t_nrnb * gmx_restrict nrnb)
1090 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
1091 * just 0 for non-waters.
1092 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
1093 * jnr indices corresponding to data put in the four positions in the SIMD register.
1095 int i_shift_offset,i_coord_offset,outeriter,inneriter;
1096 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1097 int jnrA,jnrB,jnrC,jnrD;
1098 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1099 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1100 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
1101 real rcutoff_scalar;
1102 real *shiftvec,*fshift,*x,*f;
1103 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1104 real scratch[4*DIM];
1105 __m128 fscal,rcutoff,rcutoff2,jidxall;
1107 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1109 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1111 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1112 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1113 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1114 int vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1115 __m128 jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1116 int vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1117 __m128 jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1118 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1119 __m128 dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1120 __m128 dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1121 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1122 __m128 dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1123 __m128 dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1124 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1125 __m128 dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1126 __m128 dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1127 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
1130 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1133 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
1134 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
1135 __m128 dummy_mask,cutoff_mask;
1136 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1137 __m128 one = _mm_set1_ps(1.0);
1138 __m128 two = _mm_set1_ps(2.0);
1144 jindex = nlist->jindex;
1146 shiftidx = nlist->shift;
1148 shiftvec = fr->shift_vec[0];
1149 fshift = fr->fshift[0];
1150 facel = _mm_set1_ps(fr->epsfac);
1151 charge = mdatoms->chargeA;
1152 krf = _mm_set1_ps(fr->ic->k_rf);
1153 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
1154 crf = _mm_set1_ps(fr->ic->c_rf);
1155 nvdwtype = fr->ntype;
1156 vdwparam = fr->nbfp;
1157 vdwtype = mdatoms->typeA;
1159 /* Setup water-specific parameters */
1160 inr = nlist->iinr[0];
1161 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1162 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1163 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1164 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
1166 jq0 = _mm_set1_ps(charge[inr+0]);
1167 jq1 = _mm_set1_ps(charge[inr+1]);
1168 jq2 = _mm_set1_ps(charge[inr+2]);
1169 vdwjidx0A = 2*vdwtype[inr+0];
1170 qq00 = _mm_mul_ps(iq0,jq0);
1171 c6_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A]);
1172 c12_00 = _mm_set1_ps(vdwparam[vdwioffset0+vdwjidx0A+1]);
1173 qq01 = _mm_mul_ps(iq0,jq1);
1174 qq02 = _mm_mul_ps(iq0,jq2);
1175 qq10 = _mm_mul_ps(iq1,jq0);
1176 qq11 = _mm_mul_ps(iq1,jq1);
1177 qq12 = _mm_mul_ps(iq1,jq2);
1178 qq20 = _mm_mul_ps(iq2,jq0);
1179 qq21 = _mm_mul_ps(iq2,jq1);
1180 qq22 = _mm_mul_ps(iq2,jq2);
1182 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1183 rcutoff_scalar = fr->rcoulomb;
1184 rcutoff = _mm_set1_ps(rcutoff_scalar);
1185 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
1187 sh_vdw_invrcut6 = _mm_set1_ps(fr->ic->sh_invrc6);
1188 rvdw = _mm_set1_ps(fr->rvdw);
1190 /* Avoid stupid compiler warnings */
1191 jnrA = jnrB = jnrC = jnrD = 0;
1192 j_coord_offsetA = 0;
1193 j_coord_offsetB = 0;
1194 j_coord_offsetC = 0;
1195 j_coord_offsetD = 0;
1200 for(iidx=0;iidx<4*DIM;iidx++)
1202 scratch[iidx] = 0.0;
1205 /* Start outer loop over neighborlists */
1206 for(iidx=0; iidx<nri; iidx++)
1208 /* Load shift vector for this list */
1209 i_shift_offset = DIM*shiftidx[iidx];
1211 /* Load limits for loop over neighbors */
1212 j_index_start = jindex[iidx];
1213 j_index_end = jindex[iidx+1];
1215 /* Get outer coordinate index */
1217 i_coord_offset = DIM*inr;
1219 /* Load i particle coords and add shift vector */
1220 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1221 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1223 fix0 = _mm_setzero_ps();
1224 fiy0 = _mm_setzero_ps();
1225 fiz0 = _mm_setzero_ps();
1226 fix1 = _mm_setzero_ps();
1227 fiy1 = _mm_setzero_ps();
1228 fiz1 = _mm_setzero_ps();
1229 fix2 = _mm_setzero_ps();
1230 fiy2 = _mm_setzero_ps();
1231 fiz2 = _mm_setzero_ps();
1233 /* Start inner kernel loop */
1234 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1237 /* Get j neighbor index, and coordinate index */
1239 jnrB = jjnr[jidx+1];
1240 jnrC = jjnr[jidx+2];
1241 jnrD = jjnr[jidx+3];
1242 j_coord_offsetA = DIM*jnrA;
1243 j_coord_offsetB = DIM*jnrB;
1244 j_coord_offsetC = DIM*jnrC;
1245 j_coord_offsetD = DIM*jnrD;
1247 /* load j atom coordinates */
1248 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1249 x+j_coord_offsetC,x+j_coord_offsetD,
1250 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1252 /* Calculate displacement vector */
1253 dx00 = _mm_sub_ps(ix0,jx0);
1254 dy00 = _mm_sub_ps(iy0,jy0);
1255 dz00 = _mm_sub_ps(iz0,jz0);
1256 dx01 = _mm_sub_ps(ix0,jx1);
1257 dy01 = _mm_sub_ps(iy0,jy1);
1258 dz01 = _mm_sub_ps(iz0,jz1);
1259 dx02 = _mm_sub_ps(ix0,jx2);
1260 dy02 = _mm_sub_ps(iy0,jy2);
1261 dz02 = _mm_sub_ps(iz0,jz2);
1262 dx10 = _mm_sub_ps(ix1,jx0);
1263 dy10 = _mm_sub_ps(iy1,jy0);
1264 dz10 = _mm_sub_ps(iz1,jz0);
1265 dx11 = _mm_sub_ps(ix1,jx1);
1266 dy11 = _mm_sub_ps(iy1,jy1);
1267 dz11 = _mm_sub_ps(iz1,jz1);
1268 dx12 = _mm_sub_ps(ix1,jx2);
1269 dy12 = _mm_sub_ps(iy1,jy2);
1270 dz12 = _mm_sub_ps(iz1,jz2);
1271 dx20 = _mm_sub_ps(ix2,jx0);
1272 dy20 = _mm_sub_ps(iy2,jy0);
1273 dz20 = _mm_sub_ps(iz2,jz0);
1274 dx21 = _mm_sub_ps(ix2,jx1);
1275 dy21 = _mm_sub_ps(iy2,jy1);
1276 dz21 = _mm_sub_ps(iz2,jz1);
1277 dx22 = _mm_sub_ps(ix2,jx2);
1278 dy22 = _mm_sub_ps(iy2,jy2);
1279 dz22 = _mm_sub_ps(iz2,jz2);
1281 /* Calculate squared distance and things based on it */
1282 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1283 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1284 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1285 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1286 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1287 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1288 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1289 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1290 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1292 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1293 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1294 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1295 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1296 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1297 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1298 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1299 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1300 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1302 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1303 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1304 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1305 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1306 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1307 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1308 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1309 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1310 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1312 fjx0 = _mm_setzero_ps();
1313 fjy0 = _mm_setzero_ps();
1314 fjz0 = _mm_setzero_ps();
1315 fjx1 = _mm_setzero_ps();
1316 fjy1 = _mm_setzero_ps();
1317 fjz1 = _mm_setzero_ps();
1318 fjx2 = _mm_setzero_ps();
1319 fjy2 = _mm_setzero_ps();
1320 fjz2 = _mm_setzero_ps();
1322 /**************************
1323 * CALCULATE INTERACTIONS *
1324 **************************/
1326 if (gmx_mm_any_lt(rsq00,rcutoff2))
1329 /* REACTION-FIELD ELECTROSTATICS */
1330 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1332 /* LENNARD-JONES DISPERSION/REPULSION */
1334 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1335 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1337 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1339 fscal = _mm_add_ps(felec,fvdw);
1341 fscal = _mm_and_ps(fscal,cutoff_mask);
1343 /* Update vectorial force */
1344 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1345 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1346 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1348 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1349 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1350 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1354 /**************************
1355 * CALCULATE INTERACTIONS *
1356 **************************/
1358 if (gmx_mm_any_lt(rsq01,rcutoff2))
1361 /* REACTION-FIELD ELECTROSTATICS */
1362 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1364 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1368 fscal = _mm_and_ps(fscal,cutoff_mask);
1370 /* Update vectorial force */
1371 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1372 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1373 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1375 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1376 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1377 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1381 /**************************
1382 * CALCULATE INTERACTIONS *
1383 **************************/
1385 if (gmx_mm_any_lt(rsq02,rcutoff2))
1388 /* REACTION-FIELD ELECTROSTATICS */
1389 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1391 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1395 fscal = _mm_and_ps(fscal,cutoff_mask);
1397 /* Update vectorial force */
1398 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1399 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1400 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1402 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1403 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1404 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1408 /**************************
1409 * CALCULATE INTERACTIONS *
1410 **************************/
1412 if (gmx_mm_any_lt(rsq10,rcutoff2))
1415 /* REACTION-FIELD ELECTROSTATICS */
1416 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1418 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1422 fscal = _mm_and_ps(fscal,cutoff_mask);
1424 /* Update vectorial force */
1425 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1426 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1427 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1429 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1430 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1431 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1435 /**************************
1436 * CALCULATE INTERACTIONS *
1437 **************************/
1439 if (gmx_mm_any_lt(rsq11,rcutoff2))
1442 /* REACTION-FIELD ELECTROSTATICS */
1443 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1445 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1449 fscal = _mm_and_ps(fscal,cutoff_mask);
1451 /* Update vectorial force */
1452 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1453 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1454 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1456 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1457 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1458 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1462 /**************************
1463 * CALCULATE INTERACTIONS *
1464 **************************/
1466 if (gmx_mm_any_lt(rsq12,rcutoff2))
1469 /* REACTION-FIELD ELECTROSTATICS */
1470 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1472 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1476 fscal = _mm_and_ps(fscal,cutoff_mask);
1478 /* Update vectorial force */
1479 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1480 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1481 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1483 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1484 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1485 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1489 /**************************
1490 * CALCULATE INTERACTIONS *
1491 **************************/
1493 if (gmx_mm_any_lt(rsq20,rcutoff2))
1496 /* REACTION-FIELD ELECTROSTATICS */
1497 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1499 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1503 fscal = _mm_and_ps(fscal,cutoff_mask);
1505 /* Update vectorial force */
1506 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1507 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1508 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1510 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1511 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1512 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1516 /**************************
1517 * CALCULATE INTERACTIONS *
1518 **************************/
1520 if (gmx_mm_any_lt(rsq21,rcutoff2))
1523 /* REACTION-FIELD ELECTROSTATICS */
1524 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1526 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1530 fscal = _mm_and_ps(fscal,cutoff_mask);
1532 /* Update vectorial force */
1533 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1534 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1535 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1537 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1538 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1539 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1543 /**************************
1544 * CALCULATE INTERACTIONS *
1545 **************************/
1547 if (gmx_mm_any_lt(rsq22,rcutoff2))
1550 /* REACTION-FIELD ELECTROSTATICS */
1551 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1553 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1557 fscal = _mm_and_ps(fscal,cutoff_mask);
1559 /* Update vectorial force */
1560 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1561 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1562 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1564 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1565 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1566 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1570 fjptrA = f+j_coord_offsetA;
1571 fjptrB = f+j_coord_offsetB;
1572 fjptrC = f+j_coord_offsetC;
1573 fjptrD = f+j_coord_offsetD;
1575 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1576 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1578 /* Inner loop uses 304 flops */
1581 if(jidx<j_index_end)
1584 /* Get j neighbor index, and coordinate index */
1585 jnrlistA = jjnr[jidx];
1586 jnrlistB = jjnr[jidx+1];
1587 jnrlistC = jjnr[jidx+2];
1588 jnrlistD = jjnr[jidx+3];
1589 /* Sign of each element will be negative for non-real atoms.
1590 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1591 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1593 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1594 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
1595 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
1596 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
1597 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
1598 j_coord_offsetA = DIM*jnrA;
1599 j_coord_offsetB = DIM*jnrB;
1600 j_coord_offsetC = DIM*jnrC;
1601 j_coord_offsetD = DIM*jnrD;
1603 /* load j atom coordinates */
1604 gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1605 x+j_coord_offsetC,x+j_coord_offsetD,
1606 &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1608 /* Calculate displacement vector */
1609 dx00 = _mm_sub_ps(ix0,jx0);
1610 dy00 = _mm_sub_ps(iy0,jy0);
1611 dz00 = _mm_sub_ps(iz0,jz0);
1612 dx01 = _mm_sub_ps(ix0,jx1);
1613 dy01 = _mm_sub_ps(iy0,jy1);
1614 dz01 = _mm_sub_ps(iz0,jz1);
1615 dx02 = _mm_sub_ps(ix0,jx2);
1616 dy02 = _mm_sub_ps(iy0,jy2);
1617 dz02 = _mm_sub_ps(iz0,jz2);
1618 dx10 = _mm_sub_ps(ix1,jx0);
1619 dy10 = _mm_sub_ps(iy1,jy0);
1620 dz10 = _mm_sub_ps(iz1,jz0);
1621 dx11 = _mm_sub_ps(ix1,jx1);
1622 dy11 = _mm_sub_ps(iy1,jy1);
1623 dz11 = _mm_sub_ps(iz1,jz1);
1624 dx12 = _mm_sub_ps(ix1,jx2);
1625 dy12 = _mm_sub_ps(iy1,jy2);
1626 dz12 = _mm_sub_ps(iz1,jz2);
1627 dx20 = _mm_sub_ps(ix2,jx0);
1628 dy20 = _mm_sub_ps(iy2,jy0);
1629 dz20 = _mm_sub_ps(iz2,jz0);
1630 dx21 = _mm_sub_ps(ix2,jx1);
1631 dy21 = _mm_sub_ps(iy2,jy1);
1632 dz21 = _mm_sub_ps(iz2,jz1);
1633 dx22 = _mm_sub_ps(ix2,jx2);
1634 dy22 = _mm_sub_ps(iy2,jy2);
1635 dz22 = _mm_sub_ps(iz2,jz2);
1637 /* Calculate squared distance and things based on it */
1638 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1639 rsq01 = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1640 rsq02 = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1641 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1642 rsq11 = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1643 rsq12 = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1644 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1645 rsq21 = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1646 rsq22 = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1648 rinv00 = gmx_mm_invsqrt_ps(rsq00);
1649 rinv01 = gmx_mm_invsqrt_ps(rsq01);
1650 rinv02 = gmx_mm_invsqrt_ps(rsq02);
1651 rinv10 = gmx_mm_invsqrt_ps(rsq10);
1652 rinv11 = gmx_mm_invsqrt_ps(rsq11);
1653 rinv12 = gmx_mm_invsqrt_ps(rsq12);
1654 rinv20 = gmx_mm_invsqrt_ps(rsq20);
1655 rinv21 = gmx_mm_invsqrt_ps(rsq21);
1656 rinv22 = gmx_mm_invsqrt_ps(rsq22);
1658 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
1659 rinvsq01 = _mm_mul_ps(rinv01,rinv01);
1660 rinvsq02 = _mm_mul_ps(rinv02,rinv02);
1661 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
1662 rinvsq11 = _mm_mul_ps(rinv11,rinv11);
1663 rinvsq12 = _mm_mul_ps(rinv12,rinv12);
1664 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
1665 rinvsq21 = _mm_mul_ps(rinv21,rinv21);
1666 rinvsq22 = _mm_mul_ps(rinv22,rinv22);
1668 fjx0 = _mm_setzero_ps();
1669 fjy0 = _mm_setzero_ps();
1670 fjz0 = _mm_setzero_ps();
1671 fjx1 = _mm_setzero_ps();
1672 fjy1 = _mm_setzero_ps();
1673 fjz1 = _mm_setzero_ps();
1674 fjx2 = _mm_setzero_ps();
1675 fjy2 = _mm_setzero_ps();
1676 fjz2 = _mm_setzero_ps();
1678 /**************************
1679 * CALCULATE INTERACTIONS *
1680 **************************/
1682 if (gmx_mm_any_lt(rsq00,rcutoff2))
1685 /* REACTION-FIELD ELECTROSTATICS */
1686 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1688 /* LENNARD-JONES DISPERSION/REPULSION */
1690 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1691 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1693 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
1695 fscal = _mm_add_ps(felec,fvdw);
1697 fscal = _mm_and_ps(fscal,cutoff_mask);
1699 fscal = _mm_andnot_ps(dummy_mask,fscal);
1701 /* Update vectorial force */
1702 fix0 = _mm_macc_ps(dx00,fscal,fix0);
1703 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
1704 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
1706 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
1707 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
1708 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
1712 /**************************
1713 * CALCULATE INTERACTIONS *
1714 **************************/
1716 if (gmx_mm_any_lt(rsq01,rcutoff2))
1719 /* REACTION-FIELD ELECTROSTATICS */
1720 felec = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1722 cutoff_mask = _mm_cmplt_ps(rsq01,rcutoff2);
1726 fscal = _mm_and_ps(fscal,cutoff_mask);
1728 fscal = _mm_andnot_ps(dummy_mask,fscal);
1730 /* Update vectorial force */
1731 fix0 = _mm_macc_ps(dx01,fscal,fix0);
1732 fiy0 = _mm_macc_ps(dy01,fscal,fiy0);
1733 fiz0 = _mm_macc_ps(dz01,fscal,fiz0);
1735 fjx1 = _mm_macc_ps(dx01,fscal,fjx1);
1736 fjy1 = _mm_macc_ps(dy01,fscal,fjy1);
1737 fjz1 = _mm_macc_ps(dz01,fscal,fjz1);
1741 /**************************
1742 * CALCULATE INTERACTIONS *
1743 **************************/
1745 if (gmx_mm_any_lt(rsq02,rcutoff2))
1748 /* REACTION-FIELD ELECTROSTATICS */
1749 felec = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1751 cutoff_mask = _mm_cmplt_ps(rsq02,rcutoff2);
1755 fscal = _mm_and_ps(fscal,cutoff_mask);
1757 fscal = _mm_andnot_ps(dummy_mask,fscal);
1759 /* Update vectorial force */
1760 fix0 = _mm_macc_ps(dx02,fscal,fix0);
1761 fiy0 = _mm_macc_ps(dy02,fscal,fiy0);
1762 fiz0 = _mm_macc_ps(dz02,fscal,fiz0);
1764 fjx2 = _mm_macc_ps(dx02,fscal,fjx2);
1765 fjy2 = _mm_macc_ps(dy02,fscal,fjy2);
1766 fjz2 = _mm_macc_ps(dz02,fscal,fjz2);
1770 /**************************
1771 * CALCULATE INTERACTIONS *
1772 **************************/
1774 if (gmx_mm_any_lt(rsq10,rcutoff2))
1777 /* REACTION-FIELD ELECTROSTATICS */
1778 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1780 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
1784 fscal = _mm_and_ps(fscal,cutoff_mask);
1786 fscal = _mm_andnot_ps(dummy_mask,fscal);
1788 /* Update vectorial force */
1789 fix1 = _mm_macc_ps(dx10,fscal,fix1);
1790 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
1791 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
1793 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
1794 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
1795 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
1799 /**************************
1800 * CALCULATE INTERACTIONS *
1801 **************************/
1803 if (gmx_mm_any_lt(rsq11,rcutoff2))
1806 /* REACTION-FIELD ELECTROSTATICS */
1807 felec = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1809 cutoff_mask = _mm_cmplt_ps(rsq11,rcutoff2);
1813 fscal = _mm_and_ps(fscal,cutoff_mask);
1815 fscal = _mm_andnot_ps(dummy_mask,fscal);
1817 /* Update vectorial force */
1818 fix1 = _mm_macc_ps(dx11,fscal,fix1);
1819 fiy1 = _mm_macc_ps(dy11,fscal,fiy1);
1820 fiz1 = _mm_macc_ps(dz11,fscal,fiz1);
1822 fjx1 = _mm_macc_ps(dx11,fscal,fjx1);
1823 fjy1 = _mm_macc_ps(dy11,fscal,fjy1);
1824 fjz1 = _mm_macc_ps(dz11,fscal,fjz1);
1828 /**************************
1829 * CALCULATE INTERACTIONS *
1830 **************************/
1832 if (gmx_mm_any_lt(rsq12,rcutoff2))
1835 /* REACTION-FIELD ELECTROSTATICS */
1836 felec = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1838 cutoff_mask = _mm_cmplt_ps(rsq12,rcutoff2);
1842 fscal = _mm_and_ps(fscal,cutoff_mask);
1844 fscal = _mm_andnot_ps(dummy_mask,fscal);
1846 /* Update vectorial force */
1847 fix1 = _mm_macc_ps(dx12,fscal,fix1);
1848 fiy1 = _mm_macc_ps(dy12,fscal,fiy1);
1849 fiz1 = _mm_macc_ps(dz12,fscal,fiz1);
1851 fjx2 = _mm_macc_ps(dx12,fscal,fjx2);
1852 fjy2 = _mm_macc_ps(dy12,fscal,fjy2);
1853 fjz2 = _mm_macc_ps(dz12,fscal,fjz2);
1857 /**************************
1858 * CALCULATE INTERACTIONS *
1859 **************************/
1861 if (gmx_mm_any_lt(rsq20,rcutoff2))
1864 /* REACTION-FIELD ELECTROSTATICS */
1865 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1867 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1871 fscal = _mm_and_ps(fscal,cutoff_mask);
1873 fscal = _mm_andnot_ps(dummy_mask,fscal);
1875 /* Update vectorial force */
1876 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1877 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1878 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1880 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1881 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1882 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1886 /**************************
1887 * CALCULATE INTERACTIONS *
1888 **************************/
1890 if (gmx_mm_any_lt(rsq21,rcutoff2))
1893 /* REACTION-FIELD ELECTROSTATICS */
1894 felec = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1896 cutoff_mask = _mm_cmplt_ps(rsq21,rcutoff2);
1900 fscal = _mm_and_ps(fscal,cutoff_mask);
1902 fscal = _mm_andnot_ps(dummy_mask,fscal);
1904 /* Update vectorial force */
1905 fix2 = _mm_macc_ps(dx21,fscal,fix2);
1906 fiy2 = _mm_macc_ps(dy21,fscal,fiy2);
1907 fiz2 = _mm_macc_ps(dz21,fscal,fiz2);
1909 fjx1 = _mm_macc_ps(dx21,fscal,fjx1);
1910 fjy1 = _mm_macc_ps(dy21,fscal,fjy1);
1911 fjz1 = _mm_macc_ps(dz21,fscal,fjz1);
1915 /**************************
1916 * CALCULATE INTERACTIONS *
1917 **************************/
1919 if (gmx_mm_any_lt(rsq22,rcutoff2))
1922 /* REACTION-FIELD ELECTROSTATICS */
1923 felec = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1925 cutoff_mask = _mm_cmplt_ps(rsq22,rcutoff2);
1929 fscal = _mm_and_ps(fscal,cutoff_mask);
1931 fscal = _mm_andnot_ps(dummy_mask,fscal);
1933 /* Update vectorial force */
1934 fix2 = _mm_macc_ps(dx22,fscal,fix2);
1935 fiy2 = _mm_macc_ps(dy22,fscal,fiy2);
1936 fiz2 = _mm_macc_ps(dz22,fscal,fiz2);
1938 fjx2 = _mm_macc_ps(dx22,fscal,fjx2);
1939 fjy2 = _mm_macc_ps(dy22,fscal,fjy2);
1940 fjz2 = _mm_macc_ps(dz22,fscal,fjz2);
1944 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1945 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1946 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1947 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1949 gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1950 fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1952 /* Inner loop uses 304 flops */
1955 /* End of innermost loop */
1957 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1958 f+i_coord_offset,fshift+i_shift_offset);
1960 /* Increment number of inner iterations */
1961 inneriter += j_index_end - j_index_start;
1963 /* Outer loop uses 18 flops */
1966 /* Increment number of outer iterations */
1969 /* Update outer/inner flops */
1971 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*304);