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.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomW3P1_VF_avx_128_fma_single
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEw_VdwNone_GeomW3P1_VF_avx_128_fma_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
98 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
100 __m128 dummy_mask,cutoff_mask;
101 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
102 __m128 one = _mm_set1_ps(1.0);
103 __m128 two = _mm_set1_ps(2.0);
109 jindex = nlist->jindex;
111 shiftidx = nlist->shift;
113 shiftvec = fr->shift_vec[0];
114 fshift = fr->fshift[0];
115 facel = _mm_set1_ps(fr->epsfac);
116 charge = mdatoms->chargeA;
118 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
119 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
120 beta2 = _mm_mul_ps(beta,beta);
121 beta3 = _mm_mul_ps(beta,beta2);
122 ewtab = fr->ic->tabq_coul_FDV0;
123 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
124 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
126 /* Setup water-specific parameters */
127 inr = nlist->iinr[0];
128 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
129 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
130 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
132 /* Avoid stupid compiler warnings */
133 jnrA = jnrB = jnrC = jnrD = 0;
142 for(iidx=0;iidx<4*DIM;iidx++)
147 /* Start outer loop over neighborlists */
148 for(iidx=0; iidx<nri; iidx++)
150 /* Load shift vector for this list */
151 i_shift_offset = DIM*shiftidx[iidx];
153 /* Load limits for loop over neighbors */
154 j_index_start = jindex[iidx];
155 j_index_end = jindex[iidx+1];
157 /* Get outer coordinate index */
159 i_coord_offset = DIM*inr;
161 /* Load i particle coords and add shift vector */
162 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
163 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
165 fix0 = _mm_setzero_ps();
166 fiy0 = _mm_setzero_ps();
167 fiz0 = _mm_setzero_ps();
168 fix1 = _mm_setzero_ps();
169 fiy1 = _mm_setzero_ps();
170 fiz1 = _mm_setzero_ps();
171 fix2 = _mm_setzero_ps();
172 fiy2 = _mm_setzero_ps();
173 fiz2 = _mm_setzero_ps();
175 /* Reset potential sums */
176 velecsum = _mm_setzero_ps();
178 /* Start inner kernel loop */
179 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
182 /* Get j neighbor index, and coordinate index */
187 j_coord_offsetA = DIM*jnrA;
188 j_coord_offsetB = DIM*jnrB;
189 j_coord_offsetC = DIM*jnrC;
190 j_coord_offsetD = DIM*jnrD;
192 /* load j atom coordinates */
193 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
194 x+j_coord_offsetC,x+j_coord_offsetD,
197 /* Calculate displacement vector */
198 dx00 = _mm_sub_ps(ix0,jx0);
199 dy00 = _mm_sub_ps(iy0,jy0);
200 dz00 = _mm_sub_ps(iz0,jz0);
201 dx10 = _mm_sub_ps(ix1,jx0);
202 dy10 = _mm_sub_ps(iy1,jy0);
203 dz10 = _mm_sub_ps(iz1,jz0);
204 dx20 = _mm_sub_ps(ix2,jx0);
205 dy20 = _mm_sub_ps(iy2,jy0);
206 dz20 = _mm_sub_ps(iz2,jz0);
208 /* Calculate squared distance and things based on it */
209 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
210 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
211 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
213 rinv00 = gmx_mm_invsqrt_ps(rsq00);
214 rinv10 = gmx_mm_invsqrt_ps(rsq10);
215 rinv20 = gmx_mm_invsqrt_ps(rsq20);
217 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
218 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
219 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
221 /* Load parameters for j particles */
222 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
223 charge+jnrC+0,charge+jnrD+0);
225 fjx0 = _mm_setzero_ps();
226 fjy0 = _mm_setzero_ps();
227 fjz0 = _mm_setzero_ps();
229 /**************************
230 * CALCULATE INTERACTIONS *
231 **************************/
233 r00 = _mm_mul_ps(rsq00,rinv00);
235 /* Compute parameters for interactions between i and j atoms */
236 qq00 = _mm_mul_ps(iq0,jq0);
238 /* EWALD ELECTROSTATICS */
240 /* Analytical PME correction */
241 zeta2 = _mm_mul_ps(beta2,rsq00);
242 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
243 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
244 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
245 felec = _mm_mul_ps(qq00,felec);
246 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
247 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
248 velec = _mm_mul_ps(qq00,velec);
250 /* Update potential sum for this i atom from the interaction with this j atom. */
251 velecsum = _mm_add_ps(velecsum,velec);
255 /* Update vectorial force */
256 fix0 = _mm_macc_ps(dx00,fscal,fix0);
257 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
258 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
260 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
261 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
262 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
264 /**************************
265 * CALCULATE INTERACTIONS *
266 **************************/
268 r10 = _mm_mul_ps(rsq10,rinv10);
270 /* Compute parameters for interactions between i and j atoms */
271 qq10 = _mm_mul_ps(iq1,jq0);
273 /* EWALD ELECTROSTATICS */
275 /* Analytical PME correction */
276 zeta2 = _mm_mul_ps(beta2,rsq10);
277 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
278 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
279 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
280 felec = _mm_mul_ps(qq10,felec);
281 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
282 velec = _mm_nmacc_ps(pmecorrV,beta,rinv10);
283 velec = _mm_mul_ps(qq10,velec);
285 /* Update potential sum for this i atom from the interaction with this j atom. */
286 velecsum = _mm_add_ps(velecsum,velec);
290 /* Update vectorial force */
291 fix1 = _mm_macc_ps(dx10,fscal,fix1);
292 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
293 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
295 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
296 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
297 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
299 /**************************
300 * CALCULATE INTERACTIONS *
301 **************************/
303 r20 = _mm_mul_ps(rsq20,rinv20);
305 /* Compute parameters for interactions between i and j atoms */
306 qq20 = _mm_mul_ps(iq2,jq0);
308 /* EWALD ELECTROSTATICS */
310 /* Analytical PME correction */
311 zeta2 = _mm_mul_ps(beta2,rsq20);
312 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
313 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
314 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
315 felec = _mm_mul_ps(qq20,felec);
316 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
317 velec = _mm_nmacc_ps(pmecorrV,beta,rinv20);
318 velec = _mm_mul_ps(qq20,velec);
320 /* Update potential sum for this i atom from the interaction with this j atom. */
321 velecsum = _mm_add_ps(velecsum,velec);
325 /* Update vectorial force */
326 fix2 = _mm_macc_ps(dx20,fscal,fix2);
327 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
328 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
330 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
331 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
332 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
334 fjptrA = f+j_coord_offsetA;
335 fjptrB = f+j_coord_offsetB;
336 fjptrC = f+j_coord_offsetC;
337 fjptrD = f+j_coord_offsetD;
339 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
341 /* Inner loop uses 87 flops */
347 /* Get j neighbor index, and coordinate index */
348 jnrlistA = jjnr[jidx];
349 jnrlistB = jjnr[jidx+1];
350 jnrlistC = jjnr[jidx+2];
351 jnrlistD = jjnr[jidx+3];
352 /* Sign of each element will be negative for non-real atoms.
353 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
354 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
356 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
357 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
358 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
359 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
360 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
361 j_coord_offsetA = DIM*jnrA;
362 j_coord_offsetB = DIM*jnrB;
363 j_coord_offsetC = DIM*jnrC;
364 j_coord_offsetD = DIM*jnrD;
366 /* load j atom coordinates */
367 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
368 x+j_coord_offsetC,x+j_coord_offsetD,
371 /* Calculate displacement vector */
372 dx00 = _mm_sub_ps(ix0,jx0);
373 dy00 = _mm_sub_ps(iy0,jy0);
374 dz00 = _mm_sub_ps(iz0,jz0);
375 dx10 = _mm_sub_ps(ix1,jx0);
376 dy10 = _mm_sub_ps(iy1,jy0);
377 dz10 = _mm_sub_ps(iz1,jz0);
378 dx20 = _mm_sub_ps(ix2,jx0);
379 dy20 = _mm_sub_ps(iy2,jy0);
380 dz20 = _mm_sub_ps(iz2,jz0);
382 /* Calculate squared distance and things based on it */
383 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
384 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
385 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
387 rinv00 = gmx_mm_invsqrt_ps(rsq00);
388 rinv10 = gmx_mm_invsqrt_ps(rsq10);
389 rinv20 = gmx_mm_invsqrt_ps(rsq20);
391 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
392 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
393 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
395 /* Load parameters for j particles */
396 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
397 charge+jnrC+0,charge+jnrD+0);
399 fjx0 = _mm_setzero_ps();
400 fjy0 = _mm_setzero_ps();
401 fjz0 = _mm_setzero_ps();
403 /**************************
404 * CALCULATE INTERACTIONS *
405 **************************/
407 r00 = _mm_mul_ps(rsq00,rinv00);
408 r00 = _mm_andnot_ps(dummy_mask,r00);
410 /* Compute parameters for interactions between i and j atoms */
411 qq00 = _mm_mul_ps(iq0,jq0);
413 /* EWALD ELECTROSTATICS */
415 /* Analytical PME correction */
416 zeta2 = _mm_mul_ps(beta2,rsq00);
417 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
418 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
419 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
420 felec = _mm_mul_ps(qq00,felec);
421 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
422 velec = _mm_nmacc_ps(pmecorrV,beta,rinv00);
423 velec = _mm_mul_ps(qq00,velec);
425 /* Update potential sum for this i atom from the interaction with this j atom. */
426 velec = _mm_andnot_ps(dummy_mask,velec);
427 velecsum = _mm_add_ps(velecsum,velec);
431 fscal = _mm_andnot_ps(dummy_mask,fscal);
433 /* Update vectorial force */
434 fix0 = _mm_macc_ps(dx00,fscal,fix0);
435 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
436 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
438 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
439 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
440 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
442 /**************************
443 * CALCULATE INTERACTIONS *
444 **************************/
446 r10 = _mm_mul_ps(rsq10,rinv10);
447 r10 = _mm_andnot_ps(dummy_mask,r10);
449 /* Compute parameters for interactions between i and j atoms */
450 qq10 = _mm_mul_ps(iq1,jq0);
452 /* EWALD ELECTROSTATICS */
454 /* Analytical PME correction */
455 zeta2 = _mm_mul_ps(beta2,rsq10);
456 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
457 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
458 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
459 felec = _mm_mul_ps(qq10,felec);
460 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
461 velec = _mm_nmacc_ps(pmecorrV,beta,rinv10);
462 velec = _mm_mul_ps(qq10,velec);
464 /* Update potential sum for this i atom from the interaction with this j atom. */
465 velec = _mm_andnot_ps(dummy_mask,velec);
466 velecsum = _mm_add_ps(velecsum,velec);
470 fscal = _mm_andnot_ps(dummy_mask,fscal);
472 /* Update vectorial force */
473 fix1 = _mm_macc_ps(dx10,fscal,fix1);
474 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
475 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
477 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
478 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
479 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
481 /**************************
482 * CALCULATE INTERACTIONS *
483 **************************/
485 r20 = _mm_mul_ps(rsq20,rinv20);
486 r20 = _mm_andnot_ps(dummy_mask,r20);
488 /* Compute parameters for interactions between i and j atoms */
489 qq20 = _mm_mul_ps(iq2,jq0);
491 /* EWALD ELECTROSTATICS */
493 /* Analytical PME correction */
494 zeta2 = _mm_mul_ps(beta2,rsq20);
495 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
496 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
497 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
498 felec = _mm_mul_ps(qq20,felec);
499 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
500 velec = _mm_nmacc_ps(pmecorrV,beta,rinv20);
501 velec = _mm_mul_ps(qq20,velec);
503 /* Update potential sum for this i atom from the interaction with this j atom. */
504 velec = _mm_andnot_ps(dummy_mask,velec);
505 velecsum = _mm_add_ps(velecsum,velec);
509 fscal = _mm_andnot_ps(dummy_mask,fscal);
511 /* Update vectorial force */
512 fix2 = _mm_macc_ps(dx20,fscal,fix2);
513 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
514 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
516 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
517 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
518 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
520 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
521 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
522 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
523 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
525 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
527 /* Inner loop uses 90 flops */
530 /* End of innermost loop */
532 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
533 f+i_coord_offset,fshift+i_shift_offset);
536 /* Update potential energies */
537 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
539 /* Increment number of inner iterations */
540 inneriter += j_index_end - j_index_start;
542 /* Outer loop uses 19 flops */
545 /* Increment number of outer iterations */
548 /* Update outer/inner flops */
550 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*90);
553 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomW3P1_F_avx_128_fma_single
554 * Electrostatics interaction: Ewald
555 * VdW interaction: None
556 * Geometry: Water3-Particle
557 * Calculate force/pot: Force
560 nb_kernel_ElecEw_VdwNone_GeomW3P1_F_avx_128_fma_single
561 (t_nblist * gmx_restrict nlist,
562 rvec * gmx_restrict xx,
563 rvec * gmx_restrict ff,
564 t_forcerec * gmx_restrict fr,
565 t_mdatoms * gmx_restrict mdatoms,
566 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
567 t_nrnb * gmx_restrict nrnb)
569 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
570 * just 0 for non-waters.
571 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
572 * jnr indices corresponding to data put in the four positions in the SIMD register.
574 int i_shift_offset,i_coord_offset,outeriter,inneriter;
575 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
576 int jnrA,jnrB,jnrC,jnrD;
577 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
578 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
579 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
581 real *shiftvec,*fshift,*x,*f;
582 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
584 __m128 fscal,rcutoff,rcutoff2,jidxall;
586 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
588 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
590 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
591 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
592 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
593 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
594 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
595 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
596 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
599 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
600 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
602 __m128 dummy_mask,cutoff_mask;
603 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
604 __m128 one = _mm_set1_ps(1.0);
605 __m128 two = _mm_set1_ps(2.0);
611 jindex = nlist->jindex;
613 shiftidx = nlist->shift;
615 shiftvec = fr->shift_vec[0];
616 fshift = fr->fshift[0];
617 facel = _mm_set1_ps(fr->epsfac);
618 charge = mdatoms->chargeA;
620 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
621 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
622 beta2 = _mm_mul_ps(beta,beta);
623 beta3 = _mm_mul_ps(beta,beta2);
624 ewtab = fr->ic->tabq_coul_F;
625 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
626 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
628 /* Setup water-specific parameters */
629 inr = nlist->iinr[0];
630 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
631 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
632 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
634 /* Avoid stupid compiler warnings */
635 jnrA = jnrB = jnrC = jnrD = 0;
644 for(iidx=0;iidx<4*DIM;iidx++)
649 /* Start outer loop over neighborlists */
650 for(iidx=0; iidx<nri; iidx++)
652 /* Load shift vector for this list */
653 i_shift_offset = DIM*shiftidx[iidx];
655 /* Load limits for loop over neighbors */
656 j_index_start = jindex[iidx];
657 j_index_end = jindex[iidx+1];
659 /* Get outer coordinate index */
661 i_coord_offset = DIM*inr;
663 /* Load i particle coords and add shift vector */
664 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
665 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
667 fix0 = _mm_setzero_ps();
668 fiy0 = _mm_setzero_ps();
669 fiz0 = _mm_setzero_ps();
670 fix1 = _mm_setzero_ps();
671 fiy1 = _mm_setzero_ps();
672 fiz1 = _mm_setzero_ps();
673 fix2 = _mm_setzero_ps();
674 fiy2 = _mm_setzero_ps();
675 fiz2 = _mm_setzero_ps();
677 /* Start inner kernel loop */
678 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
681 /* Get j neighbor index, and coordinate index */
686 j_coord_offsetA = DIM*jnrA;
687 j_coord_offsetB = DIM*jnrB;
688 j_coord_offsetC = DIM*jnrC;
689 j_coord_offsetD = DIM*jnrD;
691 /* load j atom coordinates */
692 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
693 x+j_coord_offsetC,x+j_coord_offsetD,
696 /* Calculate displacement vector */
697 dx00 = _mm_sub_ps(ix0,jx0);
698 dy00 = _mm_sub_ps(iy0,jy0);
699 dz00 = _mm_sub_ps(iz0,jz0);
700 dx10 = _mm_sub_ps(ix1,jx0);
701 dy10 = _mm_sub_ps(iy1,jy0);
702 dz10 = _mm_sub_ps(iz1,jz0);
703 dx20 = _mm_sub_ps(ix2,jx0);
704 dy20 = _mm_sub_ps(iy2,jy0);
705 dz20 = _mm_sub_ps(iz2,jz0);
707 /* Calculate squared distance and things based on it */
708 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
709 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
710 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
712 rinv00 = gmx_mm_invsqrt_ps(rsq00);
713 rinv10 = gmx_mm_invsqrt_ps(rsq10);
714 rinv20 = gmx_mm_invsqrt_ps(rsq20);
716 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
717 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
718 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
720 /* Load parameters for j particles */
721 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
722 charge+jnrC+0,charge+jnrD+0);
724 fjx0 = _mm_setzero_ps();
725 fjy0 = _mm_setzero_ps();
726 fjz0 = _mm_setzero_ps();
728 /**************************
729 * CALCULATE INTERACTIONS *
730 **************************/
732 r00 = _mm_mul_ps(rsq00,rinv00);
734 /* Compute parameters for interactions between i and j atoms */
735 qq00 = _mm_mul_ps(iq0,jq0);
737 /* EWALD ELECTROSTATICS */
739 /* Analytical PME correction */
740 zeta2 = _mm_mul_ps(beta2,rsq00);
741 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
742 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
743 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
744 felec = _mm_mul_ps(qq00,felec);
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);
757 /**************************
758 * CALCULATE INTERACTIONS *
759 **************************/
761 r10 = _mm_mul_ps(rsq10,rinv10);
763 /* Compute parameters for interactions between i and j atoms */
764 qq10 = _mm_mul_ps(iq1,jq0);
766 /* EWALD ELECTROSTATICS */
768 /* Analytical PME correction */
769 zeta2 = _mm_mul_ps(beta2,rsq10);
770 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
771 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
772 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
773 felec = _mm_mul_ps(qq10,felec);
777 /* Update vectorial force */
778 fix1 = _mm_macc_ps(dx10,fscal,fix1);
779 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
780 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
782 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
783 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
784 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
786 /**************************
787 * CALCULATE INTERACTIONS *
788 **************************/
790 r20 = _mm_mul_ps(rsq20,rinv20);
792 /* Compute parameters for interactions between i and j atoms */
793 qq20 = _mm_mul_ps(iq2,jq0);
795 /* EWALD ELECTROSTATICS */
797 /* Analytical PME correction */
798 zeta2 = _mm_mul_ps(beta2,rsq20);
799 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
800 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
801 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
802 felec = _mm_mul_ps(qq20,felec);
806 /* Update vectorial force */
807 fix2 = _mm_macc_ps(dx20,fscal,fix2);
808 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
809 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
811 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
812 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
813 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
815 fjptrA = f+j_coord_offsetA;
816 fjptrB = f+j_coord_offsetB;
817 fjptrC = f+j_coord_offsetC;
818 fjptrD = f+j_coord_offsetD;
820 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
822 /* Inner loop uses 84 flops */
828 /* Get j neighbor index, and coordinate index */
829 jnrlistA = jjnr[jidx];
830 jnrlistB = jjnr[jidx+1];
831 jnrlistC = jjnr[jidx+2];
832 jnrlistD = jjnr[jidx+3];
833 /* Sign of each element will be negative for non-real atoms.
834 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
835 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
837 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
838 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
839 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
840 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
841 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
842 j_coord_offsetA = DIM*jnrA;
843 j_coord_offsetB = DIM*jnrB;
844 j_coord_offsetC = DIM*jnrC;
845 j_coord_offsetD = DIM*jnrD;
847 /* load j atom coordinates */
848 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
849 x+j_coord_offsetC,x+j_coord_offsetD,
852 /* Calculate displacement vector */
853 dx00 = _mm_sub_ps(ix0,jx0);
854 dy00 = _mm_sub_ps(iy0,jy0);
855 dz00 = _mm_sub_ps(iz0,jz0);
856 dx10 = _mm_sub_ps(ix1,jx0);
857 dy10 = _mm_sub_ps(iy1,jy0);
858 dz10 = _mm_sub_ps(iz1,jz0);
859 dx20 = _mm_sub_ps(ix2,jx0);
860 dy20 = _mm_sub_ps(iy2,jy0);
861 dz20 = _mm_sub_ps(iz2,jz0);
863 /* Calculate squared distance and things based on it */
864 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
865 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
866 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
868 rinv00 = gmx_mm_invsqrt_ps(rsq00);
869 rinv10 = gmx_mm_invsqrt_ps(rsq10);
870 rinv20 = gmx_mm_invsqrt_ps(rsq20);
872 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
873 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
874 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
876 /* Load parameters for j particles */
877 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
878 charge+jnrC+0,charge+jnrD+0);
880 fjx0 = _mm_setzero_ps();
881 fjy0 = _mm_setzero_ps();
882 fjz0 = _mm_setzero_ps();
884 /**************************
885 * CALCULATE INTERACTIONS *
886 **************************/
888 r00 = _mm_mul_ps(rsq00,rinv00);
889 r00 = _mm_andnot_ps(dummy_mask,r00);
891 /* Compute parameters for interactions between i and j atoms */
892 qq00 = _mm_mul_ps(iq0,jq0);
894 /* EWALD ELECTROSTATICS */
896 /* Analytical PME correction */
897 zeta2 = _mm_mul_ps(beta2,rsq00);
898 rinv3 = _mm_mul_ps(rinvsq00,rinv00);
899 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
900 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
901 felec = _mm_mul_ps(qq00,felec);
905 fscal = _mm_andnot_ps(dummy_mask,fscal);
907 /* Update vectorial force */
908 fix0 = _mm_macc_ps(dx00,fscal,fix0);
909 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
910 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
912 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
913 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
914 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
916 /**************************
917 * CALCULATE INTERACTIONS *
918 **************************/
920 r10 = _mm_mul_ps(rsq10,rinv10);
921 r10 = _mm_andnot_ps(dummy_mask,r10);
923 /* Compute parameters for interactions between i and j atoms */
924 qq10 = _mm_mul_ps(iq1,jq0);
926 /* EWALD ELECTROSTATICS */
928 /* Analytical PME correction */
929 zeta2 = _mm_mul_ps(beta2,rsq10);
930 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
931 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
932 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
933 felec = _mm_mul_ps(qq10,felec);
937 fscal = _mm_andnot_ps(dummy_mask,fscal);
939 /* Update vectorial force */
940 fix1 = _mm_macc_ps(dx10,fscal,fix1);
941 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
942 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
944 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
945 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
946 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
948 /**************************
949 * CALCULATE INTERACTIONS *
950 **************************/
952 r20 = _mm_mul_ps(rsq20,rinv20);
953 r20 = _mm_andnot_ps(dummy_mask,r20);
955 /* Compute parameters for interactions between i and j atoms */
956 qq20 = _mm_mul_ps(iq2,jq0);
958 /* EWALD ELECTROSTATICS */
960 /* Analytical PME correction */
961 zeta2 = _mm_mul_ps(beta2,rsq20);
962 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
963 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
964 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
965 felec = _mm_mul_ps(qq20,felec);
969 fscal = _mm_andnot_ps(dummy_mask,fscal);
971 /* Update vectorial force */
972 fix2 = _mm_macc_ps(dx20,fscal,fix2);
973 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
974 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
976 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
977 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
978 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
980 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
981 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
982 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
983 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
985 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
987 /* Inner loop uses 87 flops */
990 /* End of innermost loop */
992 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
993 f+i_coord_offset,fshift+i_shift_offset);
995 /* Increment number of inner iterations */
996 inneriter += j_index_end - j_index_start;
998 /* Outer loop uses 18 flops */
1001 /* Increment number of outer iterations */
1004 /* Update outer/inner flops */
1006 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*87);