2 * Note: this file was generated by the Gromacs avx_128_fma_single 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_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
38 * Electrostatics interaction: Coulomb
39 * VdW interaction: LennardJones
40 * Geometry: Water4-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_single
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_128, 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 j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
65 real *shiftvec,*fshift,*x,*f;
66 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
68 __m128 fscal,rcutoff,rcutoff2,jidxall;
70 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
76 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
77 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
78 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
79 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
80 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
81 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
82 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
83 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
86 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
89 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
90 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
91 __m128 dummy_mask,cutoff_mask;
92 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
93 __m128 one = _mm_set1_ps(1.0);
94 __m128 two = _mm_set1_ps(2.0);
100 jindex = nlist->jindex;
102 shiftidx = nlist->shift;
104 shiftvec = fr->shift_vec[0];
105 fshift = fr->fshift[0];
106 facel = _mm_set1_ps(fr->epsfac);
107 charge = mdatoms->chargeA;
108 nvdwtype = fr->ntype;
110 vdwtype = mdatoms->typeA;
112 /* Setup water-specific parameters */
113 inr = nlist->iinr[0];
114 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
115 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
116 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
117 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
119 /* Avoid stupid compiler warnings */
120 jnrA = jnrB = jnrC = jnrD = 0;
129 for(iidx=0;iidx<4*DIM;iidx++)
134 /* Start outer loop over neighborlists */
135 for(iidx=0; iidx<nri; iidx++)
137 /* Load shift vector for this list */
138 i_shift_offset = DIM*shiftidx[iidx];
140 /* Load limits for loop over neighbors */
141 j_index_start = jindex[iidx];
142 j_index_end = jindex[iidx+1];
144 /* Get outer coordinate index */
146 i_coord_offset = DIM*inr;
148 /* Load i particle coords and add shift vector */
149 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
150 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
152 fix0 = _mm_setzero_ps();
153 fiy0 = _mm_setzero_ps();
154 fiz0 = _mm_setzero_ps();
155 fix1 = _mm_setzero_ps();
156 fiy1 = _mm_setzero_ps();
157 fiz1 = _mm_setzero_ps();
158 fix2 = _mm_setzero_ps();
159 fiy2 = _mm_setzero_ps();
160 fiz2 = _mm_setzero_ps();
161 fix3 = _mm_setzero_ps();
162 fiy3 = _mm_setzero_ps();
163 fiz3 = _mm_setzero_ps();
165 /* Reset potential sums */
166 velecsum = _mm_setzero_ps();
167 vvdwsum = _mm_setzero_ps();
169 /* Start inner kernel loop */
170 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
173 /* Get j neighbor index, and coordinate index */
178 j_coord_offsetA = DIM*jnrA;
179 j_coord_offsetB = DIM*jnrB;
180 j_coord_offsetC = DIM*jnrC;
181 j_coord_offsetD = DIM*jnrD;
183 /* load j atom coordinates */
184 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
185 x+j_coord_offsetC,x+j_coord_offsetD,
188 /* Calculate displacement vector */
189 dx00 = _mm_sub_ps(ix0,jx0);
190 dy00 = _mm_sub_ps(iy0,jy0);
191 dz00 = _mm_sub_ps(iz0,jz0);
192 dx10 = _mm_sub_ps(ix1,jx0);
193 dy10 = _mm_sub_ps(iy1,jy0);
194 dz10 = _mm_sub_ps(iz1,jz0);
195 dx20 = _mm_sub_ps(ix2,jx0);
196 dy20 = _mm_sub_ps(iy2,jy0);
197 dz20 = _mm_sub_ps(iz2,jz0);
198 dx30 = _mm_sub_ps(ix3,jx0);
199 dy30 = _mm_sub_ps(iy3,jy0);
200 dz30 = _mm_sub_ps(iz3,jz0);
202 /* Calculate squared distance and things based on it */
203 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
204 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
205 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
206 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
208 rinv10 = gmx_mm_invsqrt_ps(rsq10);
209 rinv20 = gmx_mm_invsqrt_ps(rsq20);
210 rinv30 = gmx_mm_invsqrt_ps(rsq30);
212 rinvsq00 = gmx_mm_inv_ps(rsq00);
213 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
214 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
215 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
217 /* Load parameters for j particles */
218 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
219 charge+jnrC+0,charge+jnrD+0);
220 vdwjidx0A = 2*vdwtype[jnrA+0];
221 vdwjidx0B = 2*vdwtype[jnrB+0];
222 vdwjidx0C = 2*vdwtype[jnrC+0];
223 vdwjidx0D = 2*vdwtype[jnrD+0];
225 fjx0 = _mm_setzero_ps();
226 fjy0 = _mm_setzero_ps();
227 fjz0 = _mm_setzero_ps();
229 /**************************
230 * CALCULATE INTERACTIONS *
231 **************************/
233 /* Compute parameters for interactions between i and j atoms */
234 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
235 vdwparam+vdwioffset0+vdwjidx0B,
236 vdwparam+vdwioffset0+vdwjidx0C,
237 vdwparam+vdwioffset0+vdwjidx0D,
240 /* LENNARD-JONES DISPERSION/REPULSION */
242 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
243 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
244 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
245 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
246 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
248 /* Update potential sum for this i atom from the interaction with this j atom. */
249 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
253 /* Update vectorial force */
254 fix0 = _mm_macc_ps(dx00,fscal,fix0);
255 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
256 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
258 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
259 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
260 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
262 /**************************
263 * CALCULATE INTERACTIONS *
264 **************************/
266 /* Compute parameters for interactions between i and j atoms */
267 qq10 = _mm_mul_ps(iq1,jq0);
269 /* COULOMB ELECTROSTATICS */
270 velec = _mm_mul_ps(qq10,rinv10);
271 felec = _mm_mul_ps(velec,rinvsq10);
273 /* Update potential sum for this i atom from the interaction with this j atom. */
274 velecsum = _mm_add_ps(velecsum,velec);
278 /* Update vectorial force */
279 fix1 = _mm_macc_ps(dx10,fscal,fix1);
280 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
281 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
283 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
284 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
285 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
287 /**************************
288 * CALCULATE INTERACTIONS *
289 **************************/
291 /* Compute parameters for interactions between i and j atoms */
292 qq20 = _mm_mul_ps(iq2,jq0);
294 /* COULOMB ELECTROSTATICS */
295 velec = _mm_mul_ps(qq20,rinv20);
296 felec = _mm_mul_ps(velec,rinvsq20);
298 /* Update potential sum for this i atom from the interaction with this j atom. */
299 velecsum = _mm_add_ps(velecsum,velec);
303 /* Update vectorial force */
304 fix2 = _mm_macc_ps(dx20,fscal,fix2);
305 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
306 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
308 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
309 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
310 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
312 /**************************
313 * CALCULATE INTERACTIONS *
314 **************************/
316 /* Compute parameters for interactions between i and j atoms */
317 qq30 = _mm_mul_ps(iq3,jq0);
319 /* COULOMB ELECTROSTATICS */
320 velec = _mm_mul_ps(qq30,rinv30);
321 felec = _mm_mul_ps(velec,rinvsq30);
323 /* Update potential sum for this i atom from the interaction with this j atom. */
324 velecsum = _mm_add_ps(velecsum,velec);
328 /* Update vectorial force */
329 fix3 = _mm_macc_ps(dx30,fscal,fix3);
330 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
331 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
333 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
334 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
335 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
337 fjptrA = f+j_coord_offsetA;
338 fjptrB = f+j_coord_offsetB;
339 fjptrC = f+j_coord_offsetC;
340 fjptrD = f+j_coord_offsetD;
342 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
344 /* Inner loop uses 128 flops */
350 /* Get j neighbor index, and coordinate index */
351 jnrlistA = jjnr[jidx];
352 jnrlistB = jjnr[jidx+1];
353 jnrlistC = jjnr[jidx+2];
354 jnrlistD = jjnr[jidx+3];
355 /* Sign of each element will be negative for non-real atoms.
356 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
357 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
359 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
360 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
361 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
362 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
363 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
364 j_coord_offsetA = DIM*jnrA;
365 j_coord_offsetB = DIM*jnrB;
366 j_coord_offsetC = DIM*jnrC;
367 j_coord_offsetD = DIM*jnrD;
369 /* load j atom coordinates */
370 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
371 x+j_coord_offsetC,x+j_coord_offsetD,
374 /* Calculate displacement vector */
375 dx00 = _mm_sub_ps(ix0,jx0);
376 dy00 = _mm_sub_ps(iy0,jy0);
377 dz00 = _mm_sub_ps(iz0,jz0);
378 dx10 = _mm_sub_ps(ix1,jx0);
379 dy10 = _mm_sub_ps(iy1,jy0);
380 dz10 = _mm_sub_ps(iz1,jz0);
381 dx20 = _mm_sub_ps(ix2,jx0);
382 dy20 = _mm_sub_ps(iy2,jy0);
383 dz20 = _mm_sub_ps(iz2,jz0);
384 dx30 = _mm_sub_ps(ix3,jx0);
385 dy30 = _mm_sub_ps(iy3,jy0);
386 dz30 = _mm_sub_ps(iz3,jz0);
388 /* Calculate squared distance and things based on it */
389 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
390 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
391 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
392 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
394 rinv10 = gmx_mm_invsqrt_ps(rsq10);
395 rinv20 = gmx_mm_invsqrt_ps(rsq20);
396 rinv30 = gmx_mm_invsqrt_ps(rsq30);
398 rinvsq00 = gmx_mm_inv_ps(rsq00);
399 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
400 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
401 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
403 /* Load parameters for j particles */
404 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
405 charge+jnrC+0,charge+jnrD+0);
406 vdwjidx0A = 2*vdwtype[jnrA+0];
407 vdwjidx0B = 2*vdwtype[jnrB+0];
408 vdwjidx0C = 2*vdwtype[jnrC+0];
409 vdwjidx0D = 2*vdwtype[jnrD+0];
411 fjx0 = _mm_setzero_ps();
412 fjy0 = _mm_setzero_ps();
413 fjz0 = _mm_setzero_ps();
415 /**************************
416 * CALCULATE INTERACTIONS *
417 **************************/
419 /* Compute parameters for interactions between i and j atoms */
420 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
421 vdwparam+vdwioffset0+vdwjidx0B,
422 vdwparam+vdwioffset0+vdwjidx0C,
423 vdwparam+vdwioffset0+vdwjidx0D,
426 /* LENNARD-JONES DISPERSION/REPULSION */
428 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
429 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
430 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
431 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
432 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
434 /* Update potential sum for this i atom from the interaction with this j atom. */
435 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
436 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
440 fscal = _mm_andnot_ps(dummy_mask,fscal);
442 /* Update vectorial force */
443 fix0 = _mm_macc_ps(dx00,fscal,fix0);
444 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
445 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
447 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
448 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
449 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
451 /**************************
452 * CALCULATE INTERACTIONS *
453 **************************/
455 /* Compute parameters for interactions between i and j atoms */
456 qq10 = _mm_mul_ps(iq1,jq0);
458 /* COULOMB ELECTROSTATICS */
459 velec = _mm_mul_ps(qq10,rinv10);
460 felec = _mm_mul_ps(velec,rinvsq10);
462 /* Update potential sum for this i atom from the interaction with this j atom. */
463 velec = _mm_andnot_ps(dummy_mask,velec);
464 velecsum = _mm_add_ps(velecsum,velec);
468 fscal = _mm_andnot_ps(dummy_mask,fscal);
470 /* Update vectorial force */
471 fix1 = _mm_macc_ps(dx10,fscal,fix1);
472 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
473 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
475 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
476 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
477 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
479 /**************************
480 * CALCULATE INTERACTIONS *
481 **************************/
483 /* Compute parameters for interactions between i and j atoms */
484 qq20 = _mm_mul_ps(iq2,jq0);
486 /* COULOMB ELECTROSTATICS */
487 velec = _mm_mul_ps(qq20,rinv20);
488 felec = _mm_mul_ps(velec,rinvsq20);
490 /* Update potential sum for this i atom from the interaction with this j atom. */
491 velec = _mm_andnot_ps(dummy_mask,velec);
492 velecsum = _mm_add_ps(velecsum,velec);
496 fscal = _mm_andnot_ps(dummy_mask,fscal);
498 /* Update vectorial force */
499 fix2 = _mm_macc_ps(dx20,fscal,fix2);
500 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
501 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
503 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
504 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
505 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
507 /**************************
508 * CALCULATE INTERACTIONS *
509 **************************/
511 /* Compute parameters for interactions between i and j atoms */
512 qq30 = _mm_mul_ps(iq3,jq0);
514 /* COULOMB ELECTROSTATICS */
515 velec = _mm_mul_ps(qq30,rinv30);
516 felec = _mm_mul_ps(velec,rinvsq30);
518 /* Update potential sum for this i atom from the interaction with this j atom. */
519 velec = _mm_andnot_ps(dummy_mask,velec);
520 velecsum = _mm_add_ps(velecsum,velec);
524 fscal = _mm_andnot_ps(dummy_mask,fscal);
526 /* Update vectorial force */
527 fix3 = _mm_macc_ps(dx30,fscal,fix3);
528 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
529 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
531 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
532 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
533 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
535 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
536 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
537 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
538 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
540 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
542 /* Inner loop uses 128 flops */
545 /* End of innermost loop */
547 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
548 f+i_coord_offset,fshift+i_shift_offset);
551 /* Update potential energies */
552 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
553 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
555 /* Increment number of inner iterations */
556 inneriter += j_index_end - j_index_start;
558 /* Outer loop uses 26 flops */
561 /* Increment number of outer iterations */
564 /* Update outer/inner flops */
566 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*128);
569 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
570 * Electrostatics interaction: Coulomb
571 * VdW interaction: LennardJones
572 * Geometry: Water4-Particle
573 * Calculate force/pot: Force
576 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_single
577 (t_nblist * gmx_restrict nlist,
578 rvec * gmx_restrict xx,
579 rvec * gmx_restrict ff,
580 t_forcerec * gmx_restrict fr,
581 t_mdatoms * gmx_restrict mdatoms,
582 nb_kernel_data_t * gmx_restrict kernel_data,
583 t_nrnb * gmx_restrict nrnb)
585 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
586 * just 0 for non-waters.
587 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
588 * jnr indices corresponding to data put in the four positions in the SIMD register.
590 int i_shift_offset,i_coord_offset,outeriter,inneriter;
591 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
592 int jnrA,jnrB,jnrC,jnrD;
593 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
594 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
595 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
597 real *shiftvec,*fshift,*x,*f;
598 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
600 __m128 fscal,rcutoff,rcutoff2,jidxall;
602 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
604 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
606 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
608 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
609 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
610 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
611 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
612 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
613 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
614 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
615 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
618 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
621 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
622 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
623 __m128 dummy_mask,cutoff_mask;
624 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
625 __m128 one = _mm_set1_ps(1.0);
626 __m128 two = _mm_set1_ps(2.0);
632 jindex = nlist->jindex;
634 shiftidx = nlist->shift;
636 shiftvec = fr->shift_vec[0];
637 fshift = fr->fshift[0];
638 facel = _mm_set1_ps(fr->epsfac);
639 charge = mdatoms->chargeA;
640 nvdwtype = fr->ntype;
642 vdwtype = mdatoms->typeA;
644 /* Setup water-specific parameters */
645 inr = nlist->iinr[0];
646 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
647 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
648 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
649 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
651 /* Avoid stupid compiler warnings */
652 jnrA = jnrB = jnrC = jnrD = 0;
661 for(iidx=0;iidx<4*DIM;iidx++)
666 /* Start outer loop over neighborlists */
667 for(iidx=0; iidx<nri; iidx++)
669 /* Load shift vector for this list */
670 i_shift_offset = DIM*shiftidx[iidx];
672 /* Load limits for loop over neighbors */
673 j_index_start = jindex[iidx];
674 j_index_end = jindex[iidx+1];
676 /* Get outer coordinate index */
678 i_coord_offset = DIM*inr;
680 /* Load i particle coords and add shift vector */
681 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
682 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
684 fix0 = _mm_setzero_ps();
685 fiy0 = _mm_setzero_ps();
686 fiz0 = _mm_setzero_ps();
687 fix1 = _mm_setzero_ps();
688 fiy1 = _mm_setzero_ps();
689 fiz1 = _mm_setzero_ps();
690 fix2 = _mm_setzero_ps();
691 fiy2 = _mm_setzero_ps();
692 fiz2 = _mm_setzero_ps();
693 fix3 = _mm_setzero_ps();
694 fiy3 = _mm_setzero_ps();
695 fiz3 = _mm_setzero_ps();
697 /* Start inner kernel loop */
698 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
701 /* Get j neighbor index, and coordinate index */
706 j_coord_offsetA = DIM*jnrA;
707 j_coord_offsetB = DIM*jnrB;
708 j_coord_offsetC = DIM*jnrC;
709 j_coord_offsetD = DIM*jnrD;
711 /* load j atom coordinates */
712 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
713 x+j_coord_offsetC,x+j_coord_offsetD,
716 /* Calculate displacement vector */
717 dx00 = _mm_sub_ps(ix0,jx0);
718 dy00 = _mm_sub_ps(iy0,jy0);
719 dz00 = _mm_sub_ps(iz0,jz0);
720 dx10 = _mm_sub_ps(ix1,jx0);
721 dy10 = _mm_sub_ps(iy1,jy0);
722 dz10 = _mm_sub_ps(iz1,jz0);
723 dx20 = _mm_sub_ps(ix2,jx0);
724 dy20 = _mm_sub_ps(iy2,jy0);
725 dz20 = _mm_sub_ps(iz2,jz0);
726 dx30 = _mm_sub_ps(ix3,jx0);
727 dy30 = _mm_sub_ps(iy3,jy0);
728 dz30 = _mm_sub_ps(iz3,jz0);
730 /* Calculate squared distance and things based on it */
731 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
732 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
733 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
734 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
736 rinv10 = gmx_mm_invsqrt_ps(rsq10);
737 rinv20 = gmx_mm_invsqrt_ps(rsq20);
738 rinv30 = gmx_mm_invsqrt_ps(rsq30);
740 rinvsq00 = gmx_mm_inv_ps(rsq00);
741 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
742 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
743 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
745 /* Load parameters for j particles */
746 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
747 charge+jnrC+0,charge+jnrD+0);
748 vdwjidx0A = 2*vdwtype[jnrA+0];
749 vdwjidx0B = 2*vdwtype[jnrB+0];
750 vdwjidx0C = 2*vdwtype[jnrC+0];
751 vdwjidx0D = 2*vdwtype[jnrD+0];
753 fjx0 = _mm_setzero_ps();
754 fjy0 = _mm_setzero_ps();
755 fjz0 = _mm_setzero_ps();
757 /**************************
758 * CALCULATE INTERACTIONS *
759 **************************/
761 /* Compute parameters for interactions between i and j atoms */
762 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
763 vdwparam+vdwioffset0+vdwjidx0B,
764 vdwparam+vdwioffset0+vdwjidx0C,
765 vdwparam+vdwioffset0+vdwjidx0D,
768 /* LENNARD-JONES DISPERSION/REPULSION */
770 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
771 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
775 /* Update vectorial force */
776 fix0 = _mm_macc_ps(dx00,fscal,fix0);
777 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
778 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
780 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
781 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
782 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
784 /**************************
785 * CALCULATE INTERACTIONS *
786 **************************/
788 /* Compute parameters for interactions between i and j atoms */
789 qq10 = _mm_mul_ps(iq1,jq0);
791 /* COULOMB ELECTROSTATICS */
792 velec = _mm_mul_ps(qq10,rinv10);
793 felec = _mm_mul_ps(velec,rinvsq10);
797 /* Update vectorial force */
798 fix1 = _mm_macc_ps(dx10,fscal,fix1);
799 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
800 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
802 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
803 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
804 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
806 /**************************
807 * CALCULATE INTERACTIONS *
808 **************************/
810 /* Compute parameters for interactions between i and j atoms */
811 qq20 = _mm_mul_ps(iq2,jq0);
813 /* COULOMB ELECTROSTATICS */
814 velec = _mm_mul_ps(qq20,rinv20);
815 felec = _mm_mul_ps(velec,rinvsq20);
819 /* Update vectorial force */
820 fix2 = _mm_macc_ps(dx20,fscal,fix2);
821 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
822 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
824 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
825 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
826 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
828 /**************************
829 * CALCULATE INTERACTIONS *
830 **************************/
832 /* Compute parameters for interactions between i and j atoms */
833 qq30 = _mm_mul_ps(iq3,jq0);
835 /* COULOMB ELECTROSTATICS */
836 velec = _mm_mul_ps(qq30,rinv30);
837 felec = _mm_mul_ps(velec,rinvsq30);
841 /* Update vectorial force */
842 fix3 = _mm_macc_ps(dx30,fscal,fix3);
843 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
844 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
846 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
847 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
848 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
850 fjptrA = f+j_coord_offsetA;
851 fjptrB = f+j_coord_offsetB;
852 fjptrC = f+j_coord_offsetC;
853 fjptrD = f+j_coord_offsetD;
855 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
857 /* Inner loop uses 120 flops */
863 /* Get j neighbor index, and coordinate index */
864 jnrlistA = jjnr[jidx];
865 jnrlistB = jjnr[jidx+1];
866 jnrlistC = jjnr[jidx+2];
867 jnrlistD = jjnr[jidx+3];
868 /* Sign of each element will be negative for non-real atoms.
869 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
870 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
872 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
873 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
874 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
875 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
876 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
877 j_coord_offsetA = DIM*jnrA;
878 j_coord_offsetB = DIM*jnrB;
879 j_coord_offsetC = DIM*jnrC;
880 j_coord_offsetD = DIM*jnrD;
882 /* load j atom coordinates */
883 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
884 x+j_coord_offsetC,x+j_coord_offsetD,
887 /* Calculate displacement vector */
888 dx00 = _mm_sub_ps(ix0,jx0);
889 dy00 = _mm_sub_ps(iy0,jy0);
890 dz00 = _mm_sub_ps(iz0,jz0);
891 dx10 = _mm_sub_ps(ix1,jx0);
892 dy10 = _mm_sub_ps(iy1,jy0);
893 dz10 = _mm_sub_ps(iz1,jz0);
894 dx20 = _mm_sub_ps(ix2,jx0);
895 dy20 = _mm_sub_ps(iy2,jy0);
896 dz20 = _mm_sub_ps(iz2,jz0);
897 dx30 = _mm_sub_ps(ix3,jx0);
898 dy30 = _mm_sub_ps(iy3,jy0);
899 dz30 = _mm_sub_ps(iz3,jz0);
901 /* Calculate squared distance and things based on it */
902 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
903 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
904 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
905 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
907 rinv10 = gmx_mm_invsqrt_ps(rsq10);
908 rinv20 = gmx_mm_invsqrt_ps(rsq20);
909 rinv30 = gmx_mm_invsqrt_ps(rsq30);
911 rinvsq00 = gmx_mm_inv_ps(rsq00);
912 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
913 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
914 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
916 /* Load parameters for j particles */
917 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
918 charge+jnrC+0,charge+jnrD+0);
919 vdwjidx0A = 2*vdwtype[jnrA+0];
920 vdwjidx0B = 2*vdwtype[jnrB+0];
921 vdwjidx0C = 2*vdwtype[jnrC+0];
922 vdwjidx0D = 2*vdwtype[jnrD+0];
924 fjx0 = _mm_setzero_ps();
925 fjy0 = _mm_setzero_ps();
926 fjz0 = _mm_setzero_ps();
928 /**************************
929 * CALCULATE INTERACTIONS *
930 **************************/
932 /* Compute parameters for interactions between i and j atoms */
933 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
934 vdwparam+vdwioffset0+vdwjidx0B,
935 vdwparam+vdwioffset0+vdwjidx0C,
936 vdwparam+vdwioffset0+vdwjidx0D,
939 /* LENNARD-JONES DISPERSION/REPULSION */
941 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
942 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
946 fscal = _mm_andnot_ps(dummy_mask,fscal);
948 /* Update vectorial force */
949 fix0 = _mm_macc_ps(dx00,fscal,fix0);
950 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
951 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
953 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
954 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
955 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
957 /**************************
958 * CALCULATE INTERACTIONS *
959 **************************/
961 /* Compute parameters for interactions between i and j atoms */
962 qq10 = _mm_mul_ps(iq1,jq0);
964 /* COULOMB ELECTROSTATICS */
965 velec = _mm_mul_ps(qq10,rinv10);
966 felec = _mm_mul_ps(velec,rinvsq10);
970 fscal = _mm_andnot_ps(dummy_mask,fscal);
972 /* Update vectorial force */
973 fix1 = _mm_macc_ps(dx10,fscal,fix1);
974 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
975 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
977 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
978 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
979 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
981 /**************************
982 * CALCULATE INTERACTIONS *
983 **************************/
985 /* Compute parameters for interactions between i and j atoms */
986 qq20 = _mm_mul_ps(iq2,jq0);
988 /* COULOMB ELECTROSTATICS */
989 velec = _mm_mul_ps(qq20,rinv20);
990 felec = _mm_mul_ps(velec,rinvsq20);
994 fscal = _mm_andnot_ps(dummy_mask,fscal);
996 /* Update vectorial force */
997 fix2 = _mm_macc_ps(dx20,fscal,fix2);
998 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
999 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
1001 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
1002 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
1003 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
1005 /**************************
1006 * CALCULATE INTERACTIONS *
1007 **************************/
1009 /* Compute parameters for interactions between i and j atoms */
1010 qq30 = _mm_mul_ps(iq3,jq0);
1012 /* COULOMB ELECTROSTATICS */
1013 velec = _mm_mul_ps(qq30,rinv30);
1014 felec = _mm_mul_ps(velec,rinvsq30);
1018 fscal = _mm_andnot_ps(dummy_mask,fscal);
1020 /* Update vectorial force */
1021 fix3 = _mm_macc_ps(dx30,fscal,fix3);
1022 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
1023 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
1025 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
1026 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
1027 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
1029 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1030 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1031 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1032 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1034 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1036 /* Inner loop uses 120 flops */
1039 /* End of innermost loop */
1041 gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1042 f+i_coord_offset,fshift+i_shift_offset);
1044 /* Increment number of inner iterations */
1045 inneriter += j_index_end - j_index_start;
1047 /* Outer loop uses 24 flops */
1050 /* Increment number of outer iterations */
1053 /* Update outer/inner flops */
1055 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*120);