2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
54 * Electrostatics interaction: Coulomb
55 * VdW interaction: LennardJones
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
90 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
92 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
93 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
94 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
95 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
96 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
97 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
98 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
99 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
102 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
105 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
106 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
107 __m128 dummy_mask,cutoff_mask;
108 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
109 __m128 one = _mm_set1_ps(1.0);
110 __m128 two = _mm_set1_ps(2.0);
116 jindex = nlist->jindex;
118 shiftidx = nlist->shift;
120 shiftvec = fr->shift_vec[0];
121 fshift = fr->fshift[0];
122 facel = _mm_set1_ps(fr->epsfac);
123 charge = mdatoms->chargeA;
124 nvdwtype = fr->ntype;
126 vdwtype = mdatoms->typeA;
128 /* Setup water-specific parameters */
129 inr = nlist->iinr[0];
130 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
131 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
132 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
133 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
135 /* Avoid stupid compiler warnings */
136 jnrA = jnrB = jnrC = jnrD = 0;
145 for(iidx=0;iidx<4*DIM;iidx++)
150 /* Start outer loop over neighborlists */
151 for(iidx=0; iidx<nri; iidx++)
153 /* Load shift vector for this list */
154 i_shift_offset = DIM*shiftidx[iidx];
156 /* Load limits for loop over neighbors */
157 j_index_start = jindex[iidx];
158 j_index_end = jindex[iidx+1];
160 /* Get outer coordinate index */
162 i_coord_offset = DIM*inr;
164 /* Load i particle coords and add shift vector */
165 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
166 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
168 fix0 = _mm_setzero_ps();
169 fiy0 = _mm_setzero_ps();
170 fiz0 = _mm_setzero_ps();
171 fix1 = _mm_setzero_ps();
172 fiy1 = _mm_setzero_ps();
173 fiz1 = _mm_setzero_ps();
174 fix2 = _mm_setzero_ps();
175 fiy2 = _mm_setzero_ps();
176 fiz2 = _mm_setzero_ps();
177 fix3 = _mm_setzero_ps();
178 fiy3 = _mm_setzero_ps();
179 fiz3 = _mm_setzero_ps();
181 /* Reset potential sums */
182 velecsum = _mm_setzero_ps();
183 vvdwsum = _mm_setzero_ps();
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_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
201 x+j_coord_offsetC,x+j_coord_offsetD,
204 /* Calculate displacement vector */
205 dx00 = _mm_sub_ps(ix0,jx0);
206 dy00 = _mm_sub_ps(iy0,jy0);
207 dz00 = _mm_sub_ps(iz0,jz0);
208 dx10 = _mm_sub_ps(ix1,jx0);
209 dy10 = _mm_sub_ps(iy1,jy0);
210 dz10 = _mm_sub_ps(iz1,jz0);
211 dx20 = _mm_sub_ps(ix2,jx0);
212 dy20 = _mm_sub_ps(iy2,jy0);
213 dz20 = _mm_sub_ps(iz2,jz0);
214 dx30 = _mm_sub_ps(ix3,jx0);
215 dy30 = _mm_sub_ps(iy3,jy0);
216 dz30 = _mm_sub_ps(iz3,jz0);
218 /* Calculate squared distance and things based on it */
219 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
220 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
221 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
222 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
224 rinv10 = gmx_mm_invsqrt_ps(rsq10);
225 rinv20 = gmx_mm_invsqrt_ps(rsq20);
226 rinv30 = gmx_mm_invsqrt_ps(rsq30);
228 rinvsq00 = gmx_mm_inv_ps(rsq00);
229 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
230 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
231 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
233 /* Load parameters for j particles */
234 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
235 charge+jnrC+0,charge+jnrD+0);
236 vdwjidx0A = 2*vdwtype[jnrA+0];
237 vdwjidx0B = 2*vdwtype[jnrB+0];
238 vdwjidx0C = 2*vdwtype[jnrC+0];
239 vdwjidx0D = 2*vdwtype[jnrD+0];
241 fjx0 = _mm_setzero_ps();
242 fjy0 = _mm_setzero_ps();
243 fjz0 = _mm_setzero_ps();
245 /**************************
246 * CALCULATE INTERACTIONS *
247 **************************/
249 /* Compute parameters for interactions between i and j atoms */
250 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
251 vdwparam+vdwioffset0+vdwjidx0B,
252 vdwparam+vdwioffset0+vdwjidx0C,
253 vdwparam+vdwioffset0+vdwjidx0D,
256 /* LENNARD-JONES DISPERSION/REPULSION */
258 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
259 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
260 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
261 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
262 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
264 /* Update potential sum for this i atom from the interaction with this j atom. */
265 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
269 /* Update vectorial force */
270 fix0 = _mm_macc_ps(dx00,fscal,fix0);
271 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
272 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
274 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
275 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
276 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
278 /**************************
279 * CALCULATE INTERACTIONS *
280 **************************/
282 /* Compute parameters for interactions between i and j atoms */
283 qq10 = _mm_mul_ps(iq1,jq0);
285 /* COULOMB ELECTROSTATICS */
286 velec = _mm_mul_ps(qq10,rinv10);
287 felec = _mm_mul_ps(velec,rinvsq10);
289 /* Update potential sum for this i atom from the interaction with this j atom. */
290 velecsum = _mm_add_ps(velecsum,velec);
294 /* Update vectorial force */
295 fix1 = _mm_macc_ps(dx10,fscal,fix1);
296 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
297 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
299 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
300 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
301 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
303 /**************************
304 * CALCULATE INTERACTIONS *
305 **************************/
307 /* Compute parameters for interactions between i and j atoms */
308 qq20 = _mm_mul_ps(iq2,jq0);
310 /* COULOMB ELECTROSTATICS */
311 velec = _mm_mul_ps(qq20,rinv20);
312 felec = _mm_mul_ps(velec,rinvsq20);
314 /* Update potential sum for this i atom from the interaction with this j atom. */
315 velecsum = _mm_add_ps(velecsum,velec);
319 /* Update vectorial force */
320 fix2 = _mm_macc_ps(dx20,fscal,fix2);
321 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
322 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
324 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
325 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
326 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
328 /**************************
329 * CALCULATE INTERACTIONS *
330 **************************/
332 /* Compute parameters for interactions between i and j atoms */
333 qq30 = _mm_mul_ps(iq3,jq0);
335 /* COULOMB ELECTROSTATICS */
336 velec = _mm_mul_ps(qq30,rinv30);
337 felec = _mm_mul_ps(velec,rinvsq30);
339 /* Update potential sum for this i atom from the interaction with this j atom. */
340 velecsum = _mm_add_ps(velecsum,velec);
344 /* Update vectorial force */
345 fix3 = _mm_macc_ps(dx30,fscal,fix3);
346 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
347 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
349 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
350 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
351 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
353 fjptrA = f+j_coord_offsetA;
354 fjptrB = f+j_coord_offsetB;
355 fjptrC = f+j_coord_offsetC;
356 fjptrD = f+j_coord_offsetD;
358 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
360 /* Inner loop uses 128 flops */
366 /* Get j neighbor index, and coordinate index */
367 jnrlistA = jjnr[jidx];
368 jnrlistB = jjnr[jidx+1];
369 jnrlistC = jjnr[jidx+2];
370 jnrlistD = jjnr[jidx+3];
371 /* Sign of each element will be negative for non-real atoms.
372 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
373 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
375 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
376 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
377 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
378 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
379 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
380 j_coord_offsetA = DIM*jnrA;
381 j_coord_offsetB = DIM*jnrB;
382 j_coord_offsetC = DIM*jnrC;
383 j_coord_offsetD = DIM*jnrD;
385 /* load j atom coordinates */
386 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
387 x+j_coord_offsetC,x+j_coord_offsetD,
390 /* Calculate displacement vector */
391 dx00 = _mm_sub_ps(ix0,jx0);
392 dy00 = _mm_sub_ps(iy0,jy0);
393 dz00 = _mm_sub_ps(iz0,jz0);
394 dx10 = _mm_sub_ps(ix1,jx0);
395 dy10 = _mm_sub_ps(iy1,jy0);
396 dz10 = _mm_sub_ps(iz1,jz0);
397 dx20 = _mm_sub_ps(ix2,jx0);
398 dy20 = _mm_sub_ps(iy2,jy0);
399 dz20 = _mm_sub_ps(iz2,jz0);
400 dx30 = _mm_sub_ps(ix3,jx0);
401 dy30 = _mm_sub_ps(iy3,jy0);
402 dz30 = _mm_sub_ps(iz3,jz0);
404 /* Calculate squared distance and things based on it */
405 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
406 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
407 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
408 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
410 rinv10 = gmx_mm_invsqrt_ps(rsq10);
411 rinv20 = gmx_mm_invsqrt_ps(rsq20);
412 rinv30 = gmx_mm_invsqrt_ps(rsq30);
414 rinvsq00 = gmx_mm_inv_ps(rsq00);
415 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
416 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
417 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
419 /* Load parameters for j particles */
420 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
421 charge+jnrC+0,charge+jnrD+0);
422 vdwjidx0A = 2*vdwtype[jnrA+0];
423 vdwjidx0B = 2*vdwtype[jnrB+0];
424 vdwjidx0C = 2*vdwtype[jnrC+0];
425 vdwjidx0D = 2*vdwtype[jnrD+0];
427 fjx0 = _mm_setzero_ps();
428 fjy0 = _mm_setzero_ps();
429 fjz0 = _mm_setzero_ps();
431 /**************************
432 * CALCULATE INTERACTIONS *
433 **************************/
435 /* Compute parameters for interactions between i and j atoms */
436 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
437 vdwparam+vdwioffset0+vdwjidx0B,
438 vdwparam+vdwioffset0+vdwjidx0C,
439 vdwparam+vdwioffset0+vdwjidx0D,
442 /* LENNARD-JONES DISPERSION/REPULSION */
444 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
445 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
446 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
447 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
448 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
450 /* Update potential sum for this i atom from the interaction with this j atom. */
451 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
452 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
456 fscal = _mm_andnot_ps(dummy_mask,fscal);
458 /* Update vectorial force */
459 fix0 = _mm_macc_ps(dx00,fscal,fix0);
460 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
461 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
463 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
464 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
465 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
467 /**************************
468 * CALCULATE INTERACTIONS *
469 **************************/
471 /* Compute parameters for interactions between i and j atoms */
472 qq10 = _mm_mul_ps(iq1,jq0);
474 /* COULOMB ELECTROSTATICS */
475 velec = _mm_mul_ps(qq10,rinv10);
476 felec = _mm_mul_ps(velec,rinvsq10);
478 /* Update potential sum for this i atom from the interaction with this j atom. */
479 velec = _mm_andnot_ps(dummy_mask,velec);
480 velecsum = _mm_add_ps(velecsum,velec);
484 fscal = _mm_andnot_ps(dummy_mask,fscal);
486 /* Update vectorial force */
487 fix1 = _mm_macc_ps(dx10,fscal,fix1);
488 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
489 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
491 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
492 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
493 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
495 /**************************
496 * CALCULATE INTERACTIONS *
497 **************************/
499 /* Compute parameters for interactions between i and j atoms */
500 qq20 = _mm_mul_ps(iq2,jq0);
502 /* COULOMB ELECTROSTATICS */
503 velec = _mm_mul_ps(qq20,rinv20);
504 felec = _mm_mul_ps(velec,rinvsq20);
506 /* Update potential sum for this i atom from the interaction with this j atom. */
507 velec = _mm_andnot_ps(dummy_mask,velec);
508 velecsum = _mm_add_ps(velecsum,velec);
512 fscal = _mm_andnot_ps(dummy_mask,fscal);
514 /* Update vectorial force */
515 fix2 = _mm_macc_ps(dx20,fscal,fix2);
516 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
517 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
519 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
520 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
521 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
523 /**************************
524 * CALCULATE INTERACTIONS *
525 **************************/
527 /* Compute parameters for interactions between i and j atoms */
528 qq30 = _mm_mul_ps(iq3,jq0);
530 /* COULOMB ELECTROSTATICS */
531 velec = _mm_mul_ps(qq30,rinv30);
532 felec = _mm_mul_ps(velec,rinvsq30);
534 /* Update potential sum for this i atom from the interaction with this j atom. */
535 velec = _mm_andnot_ps(dummy_mask,velec);
536 velecsum = _mm_add_ps(velecsum,velec);
540 fscal = _mm_andnot_ps(dummy_mask,fscal);
542 /* Update vectorial force */
543 fix3 = _mm_macc_ps(dx30,fscal,fix3);
544 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
545 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
547 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
548 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
549 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
551 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
552 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
553 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
554 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
556 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
558 /* Inner loop uses 128 flops */
561 /* End of innermost loop */
563 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
564 f+i_coord_offset,fshift+i_shift_offset);
567 /* Update potential energies */
568 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
569 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
571 /* Increment number of inner iterations */
572 inneriter += j_index_end - j_index_start;
574 /* Outer loop uses 26 flops */
577 /* Increment number of outer iterations */
580 /* Update outer/inner flops */
582 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*128);
585 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
586 * Electrostatics interaction: Coulomb
587 * VdW interaction: LennardJones
588 * Geometry: Water4-Particle
589 * Calculate force/pot: Force
592 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
593 (t_nblist * gmx_restrict nlist,
594 rvec * gmx_restrict xx,
595 rvec * gmx_restrict ff,
596 t_forcerec * gmx_restrict fr,
597 t_mdatoms * gmx_restrict mdatoms,
598 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
599 t_nrnb * gmx_restrict nrnb)
601 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
602 * just 0 for non-waters.
603 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
604 * jnr indices corresponding to data put in the four positions in the SIMD register.
606 int i_shift_offset,i_coord_offset,outeriter,inneriter;
607 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
608 int jnrA,jnrB,jnrC,jnrD;
609 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
610 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
611 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
613 real *shiftvec,*fshift,*x,*f;
614 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
616 __m128 fscal,rcutoff,rcutoff2,jidxall;
618 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
620 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
622 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
624 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
625 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
626 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
627 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
628 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
629 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
630 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
631 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
634 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
637 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
638 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
639 __m128 dummy_mask,cutoff_mask;
640 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
641 __m128 one = _mm_set1_ps(1.0);
642 __m128 two = _mm_set1_ps(2.0);
648 jindex = nlist->jindex;
650 shiftidx = nlist->shift;
652 shiftvec = fr->shift_vec[0];
653 fshift = fr->fshift[0];
654 facel = _mm_set1_ps(fr->epsfac);
655 charge = mdatoms->chargeA;
656 nvdwtype = fr->ntype;
658 vdwtype = mdatoms->typeA;
660 /* Setup water-specific parameters */
661 inr = nlist->iinr[0];
662 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
663 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
664 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
665 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
667 /* Avoid stupid compiler warnings */
668 jnrA = jnrB = jnrC = jnrD = 0;
677 for(iidx=0;iidx<4*DIM;iidx++)
682 /* Start outer loop over neighborlists */
683 for(iidx=0; iidx<nri; iidx++)
685 /* Load shift vector for this list */
686 i_shift_offset = DIM*shiftidx[iidx];
688 /* Load limits for loop over neighbors */
689 j_index_start = jindex[iidx];
690 j_index_end = jindex[iidx+1];
692 /* Get outer coordinate index */
694 i_coord_offset = DIM*inr;
696 /* Load i particle coords and add shift vector */
697 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
698 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
700 fix0 = _mm_setzero_ps();
701 fiy0 = _mm_setzero_ps();
702 fiz0 = _mm_setzero_ps();
703 fix1 = _mm_setzero_ps();
704 fiy1 = _mm_setzero_ps();
705 fiz1 = _mm_setzero_ps();
706 fix2 = _mm_setzero_ps();
707 fiy2 = _mm_setzero_ps();
708 fiz2 = _mm_setzero_ps();
709 fix3 = _mm_setzero_ps();
710 fiy3 = _mm_setzero_ps();
711 fiz3 = _mm_setzero_ps();
713 /* Start inner kernel loop */
714 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
717 /* Get j neighbor index, and coordinate index */
722 j_coord_offsetA = DIM*jnrA;
723 j_coord_offsetB = DIM*jnrB;
724 j_coord_offsetC = DIM*jnrC;
725 j_coord_offsetD = DIM*jnrD;
727 /* load j atom coordinates */
728 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
729 x+j_coord_offsetC,x+j_coord_offsetD,
732 /* Calculate displacement vector */
733 dx00 = _mm_sub_ps(ix0,jx0);
734 dy00 = _mm_sub_ps(iy0,jy0);
735 dz00 = _mm_sub_ps(iz0,jz0);
736 dx10 = _mm_sub_ps(ix1,jx0);
737 dy10 = _mm_sub_ps(iy1,jy0);
738 dz10 = _mm_sub_ps(iz1,jz0);
739 dx20 = _mm_sub_ps(ix2,jx0);
740 dy20 = _mm_sub_ps(iy2,jy0);
741 dz20 = _mm_sub_ps(iz2,jz0);
742 dx30 = _mm_sub_ps(ix3,jx0);
743 dy30 = _mm_sub_ps(iy3,jy0);
744 dz30 = _mm_sub_ps(iz3,jz0);
746 /* Calculate squared distance and things based on it */
747 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
748 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
749 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
750 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
752 rinv10 = gmx_mm_invsqrt_ps(rsq10);
753 rinv20 = gmx_mm_invsqrt_ps(rsq20);
754 rinv30 = gmx_mm_invsqrt_ps(rsq30);
756 rinvsq00 = gmx_mm_inv_ps(rsq00);
757 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
758 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
759 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
761 /* Load parameters for j particles */
762 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
763 charge+jnrC+0,charge+jnrD+0);
764 vdwjidx0A = 2*vdwtype[jnrA+0];
765 vdwjidx0B = 2*vdwtype[jnrB+0];
766 vdwjidx0C = 2*vdwtype[jnrC+0];
767 vdwjidx0D = 2*vdwtype[jnrD+0];
769 fjx0 = _mm_setzero_ps();
770 fjy0 = _mm_setzero_ps();
771 fjz0 = _mm_setzero_ps();
773 /**************************
774 * CALCULATE INTERACTIONS *
775 **************************/
777 /* Compute parameters for interactions between i and j atoms */
778 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
779 vdwparam+vdwioffset0+vdwjidx0B,
780 vdwparam+vdwioffset0+vdwjidx0C,
781 vdwparam+vdwioffset0+vdwjidx0D,
784 /* LENNARD-JONES DISPERSION/REPULSION */
786 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
787 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
791 /* Update vectorial force */
792 fix0 = _mm_macc_ps(dx00,fscal,fix0);
793 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
794 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
796 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
797 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
798 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
800 /**************************
801 * CALCULATE INTERACTIONS *
802 **************************/
804 /* Compute parameters for interactions between i and j atoms */
805 qq10 = _mm_mul_ps(iq1,jq0);
807 /* COULOMB ELECTROSTATICS */
808 velec = _mm_mul_ps(qq10,rinv10);
809 felec = _mm_mul_ps(velec,rinvsq10);
813 /* Update vectorial force */
814 fix1 = _mm_macc_ps(dx10,fscal,fix1);
815 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
816 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
818 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
819 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
820 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
822 /**************************
823 * CALCULATE INTERACTIONS *
824 **************************/
826 /* Compute parameters for interactions between i and j atoms */
827 qq20 = _mm_mul_ps(iq2,jq0);
829 /* COULOMB ELECTROSTATICS */
830 velec = _mm_mul_ps(qq20,rinv20);
831 felec = _mm_mul_ps(velec,rinvsq20);
835 /* Update vectorial force */
836 fix2 = _mm_macc_ps(dx20,fscal,fix2);
837 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
838 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
840 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
841 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
842 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
844 /**************************
845 * CALCULATE INTERACTIONS *
846 **************************/
848 /* Compute parameters for interactions between i and j atoms */
849 qq30 = _mm_mul_ps(iq3,jq0);
851 /* COULOMB ELECTROSTATICS */
852 velec = _mm_mul_ps(qq30,rinv30);
853 felec = _mm_mul_ps(velec,rinvsq30);
857 /* Update vectorial force */
858 fix3 = _mm_macc_ps(dx30,fscal,fix3);
859 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
860 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
862 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
863 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
864 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
866 fjptrA = f+j_coord_offsetA;
867 fjptrB = f+j_coord_offsetB;
868 fjptrC = f+j_coord_offsetC;
869 fjptrD = f+j_coord_offsetD;
871 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
873 /* Inner loop uses 120 flops */
879 /* Get j neighbor index, and coordinate index */
880 jnrlistA = jjnr[jidx];
881 jnrlistB = jjnr[jidx+1];
882 jnrlistC = jjnr[jidx+2];
883 jnrlistD = jjnr[jidx+3];
884 /* Sign of each element will be negative for non-real atoms.
885 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
886 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
888 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
889 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
890 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
891 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
892 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
893 j_coord_offsetA = DIM*jnrA;
894 j_coord_offsetB = DIM*jnrB;
895 j_coord_offsetC = DIM*jnrC;
896 j_coord_offsetD = DIM*jnrD;
898 /* load j atom coordinates */
899 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
900 x+j_coord_offsetC,x+j_coord_offsetD,
903 /* Calculate displacement vector */
904 dx00 = _mm_sub_ps(ix0,jx0);
905 dy00 = _mm_sub_ps(iy0,jy0);
906 dz00 = _mm_sub_ps(iz0,jz0);
907 dx10 = _mm_sub_ps(ix1,jx0);
908 dy10 = _mm_sub_ps(iy1,jy0);
909 dz10 = _mm_sub_ps(iz1,jz0);
910 dx20 = _mm_sub_ps(ix2,jx0);
911 dy20 = _mm_sub_ps(iy2,jy0);
912 dz20 = _mm_sub_ps(iz2,jz0);
913 dx30 = _mm_sub_ps(ix3,jx0);
914 dy30 = _mm_sub_ps(iy3,jy0);
915 dz30 = _mm_sub_ps(iz3,jz0);
917 /* Calculate squared distance and things based on it */
918 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
919 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
920 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
921 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
923 rinv10 = gmx_mm_invsqrt_ps(rsq10);
924 rinv20 = gmx_mm_invsqrt_ps(rsq20);
925 rinv30 = gmx_mm_invsqrt_ps(rsq30);
927 rinvsq00 = gmx_mm_inv_ps(rsq00);
928 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
929 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
930 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
932 /* Load parameters for j particles */
933 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
934 charge+jnrC+0,charge+jnrD+0);
935 vdwjidx0A = 2*vdwtype[jnrA+0];
936 vdwjidx0B = 2*vdwtype[jnrB+0];
937 vdwjidx0C = 2*vdwtype[jnrC+0];
938 vdwjidx0D = 2*vdwtype[jnrD+0];
940 fjx0 = _mm_setzero_ps();
941 fjy0 = _mm_setzero_ps();
942 fjz0 = _mm_setzero_ps();
944 /**************************
945 * CALCULATE INTERACTIONS *
946 **************************/
948 /* Compute parameters for interactions between i and j atoms */
949 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
950 vdwparam+vdwioffset0+vdwjidx0B,
951 vdwparam+vdwioffset0+vdwjidx0C,
952 vdwparam+vdwioffset0+vdwjidx0D,
955 /* LENNARD-JONES DISPERSION/REPULSION */
957 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
958 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
962 fscal = _mm_andnot_ps(dummy_mask,fscal);
964 /* Update vectorial force */
965 fix0 = _mm_macc_ps(dx00,fscal,fix0);
966 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
967 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
969 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
970 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
971 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
973 /**************************
974 * CALCULATE INTERACTIONS *
975 **************************/
977 /* Compute parameters for interactions between i and j atoms */
978 qq10 = _mm_mul_ps(iq1,jq0);
980 /* COULOMB ELECTROSTATICS */
981 velec = _mm_mul_ps(qq10,rinv10);
982 felec = _mm_mul_ps(velec,rinvsq10);
986 fscal = _mm_andnot_ps(dummy_mask,fscal);
988 /* Update vectorial force */
989 fix1 = _mm_macc_ps(dx10,fscal,fix1);
990 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
991 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
993 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
994 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
995 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
997 /**************************
998 * CALCULATE INTERACTIONS *
999 **************************/
1001 /* Compute parameters for interactions between i and j atoms */
1002 qq20 = _mm_mul_ps(iq2,jq0);
1004 /* COULOMB ELECTROSTATICS */
1005 velec = _mm_mul_ps(qq20,rinv20);
1006 felec = _mm_mul_ps(velec,rinvsq20);
1010 fscal = _mm_andnot_ps(dummy_mask,fscal);
1012 /* Update vectorial force */
1013 fix2 = _mm_macc_ps(dx20,fscal,fix2);
1014 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
1015 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1017 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1018 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1019 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1021 /**************************
1022 * CALCULATE INTERACTIONS *
1023 **************************/
1025 /* Compute parameters for interactions between i and j atoms */
1026 qq30 = _mm_mul_ps(iq3,jq0);
1028 /* COULOMB ELECTROSTATICS */
1029 velec = _mm_mul_ps(qq30,rinv30);
1030 felec = _mm_mul_ps(velec,rinvsq30);
1034 fscal = _mm_andnot_ps(dummy_mask,fscal);
1036 /* Update vectorial force */
1037 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1038 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1039 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1041 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1042 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1043 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1045 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1046 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1047 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1048 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1050 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1052 /* Inner loop uses 120 flops */
1055 /* End of innermost loop */
1057 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1058 f+i_coord_offset,fshift+i_shift_offset);
1060 /* Increment number of inner iterations */
1061 inneriter += j_index_end - j_index_start;
1063 /* Outer loop uses 24 flops */
1066 /* Increment number of outer iterations */
1069 /* Update outer/inner flops */
1071 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*120);