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_ElecEw_VdwNone_GeomW4P1_VF_avx_128_fma_single
54 * Electrostatics interaction: Ewald
55 * VdW interaction: None
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEw_VdwNone_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 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
100 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
102 __m128 dummy_mask,cutoff_mask;
103 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
104 __m128 one = _mm_set1_ps(1.0);
105 __m128 two = _mm_set1_ps(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm_set1_ps(fr->epsfac);
118 charge = mdatoms->chargeA;
120 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
121 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
122 beta2 = _mm_mul_ps(beta,beta);
123 beta3 = _mm_mul_ps(beta,beta2);
124 ewtab = fr->ic->tabq_coul_FDV0;
125 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
126 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
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]));
134 /* Avoid stupid compiler warnings */
135 jnrA = jnrB = jnrC = jnrD = 0;
144 for(iidx=0;iidx<4*DIM;iidx++)
149 /* Start outer loop over neighborlists */
150 for(iidx=0; iidx<nri; iidx++)
152 /* Load shift vector for this list */
153 i_shift_offset = DIM*shiftidx[iidx];
155 /* Load limits for loop over neighbors */
156 j_index_start = jindex[iidx];
157 j_index_end = jindex[iidx+1];
159 /* Get outer coordinate index */
161 i_coord_offset = DIM*inr;
163 /* Load i particle coords and add shift vector */
164 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
165 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
167 fix1 = _mm_setzero_ps();
168 fiy1 = _mm_setzero_ps();
169 fiz1 = _mm_setzero_ps();
170 fix2 = _mm_setzero_ps();
171 fiy2 = _mm_setzero_ps();
172 fiz2 = _mm_setzero_ps();
173 fix3 = _mm_setzero_ps();
174 fiy3 = _mm_setzero_ps();
175 fiz3 = _mm_setzero_ps();
177 /* Reset potential sums */
178 velecsum = _mm_setzero_ps();
180 /* Start inner kernel loop */
181 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
184 /* Get j neighbor index, and coordinate index */
189 j_coord_offsetA = DIM*jnrA;
190 j_coord_offsetB = DIM*jnrB;
191 j_coord_offsetC = DIM*jnrC;
192 j_coord_offsetD = DIM*jnrD;
194 /* load j atom coordinates */
195 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
196 x+j_coord_offsetC,x+j_coord_offsetD,
199 /* Calculate displacement vector */
200 dx10 = _mm_sub_ps(ix1,jx0);
201 dy10 = _mm_sub_ps(iy1,jy0);
202 dz10 = _mm_sub_ps(iz1,jz0);
203 dx20 = _mm_sub_ps(ix2,jx0);
204 dy20 = _mm_sub_ps(iy2,jy0);
205 dz20 = _mm_sub_ps(iz2,jz0);
206 dx30 = _mm_sub_ps(ix3,jx0);
207 dy30 = _mm_sub_ps(iy3,jy0);
208 dz30 = _mm_sub_ps(iz3,jz0);
210 /* Calculate squared distance and things based on it */
211 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
212 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
213 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
215 rinv10 = gmx_mm_invsqrt_ps(rsq10);
216 rinv20 = gmx_mm_invsqrt_ps(rsq20);
217 rinv30 = gmx_mm_invsqrt_ps(rsq30);
219 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
220 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
221 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
223 /* Load parameters for j particles */
224 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
225 charge+jnrC+0,charge+jnrD+0);
227 fjx0 = _mm_setzero_ps();
228 fjy0 = _mm_setzero_ps();
229 fjz0 = _mm_setzero_ps();
231 /**************************
232 * CALCULATE INTERACTIONS *
233 **************************/
235 r10 = _mm_mul_ps(rsq10,rinv10);
237 /* Compute parameters for interactions between i and j atoms */
238 qq10 = _mm_mul_ps(iq1,jq0);
240 /* EWALD ELECTROSTATICS */
242 /* Analytical PME correction */
243 zeta2 = _mm_mul_ps(beta2,rsq10);
244 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
245 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
246 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
247 felec = _mm_mul_ps(qq10,felec);
248 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
249 velec = _mm_nmacc_ps(pmecorrV,beta,rinv10);
250 velec = _mm_mul_ps(qq10,velec);
252 /* Update potential sum for this i atom from the interaction with this j atom. */
253 velecsum = _mm_add_ps(velecsum,velec);
257 /* Update vectorial force */
258 fix1 = _mm_macc_ps(dx10,fscal,fix1);
259 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
260 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
262 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
263 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
264 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
266 /**************************
267 * CALCULATE INTERACTIONS *
268 **************************/
270 r20 = _mm_mul_ps(rsq20,rinv20);
272 /* Compute parameters for interactions between i and j atoms */
273 qq20 = _mm_mul_ps(iq2,jq0);
275 /* EWALD ELECTROSTATICS */
277 /* Analytical PME correction */
278 zeta2 = _mm_mul_ps(beta2,rsq20);
279 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
280 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
281 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
282 felec = _mm_mul_ps(qq20,felec);
283 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
284 velec = _mm_nmacc_ps(pmecorrV,beta,rinv20);
285 velec = _mm_mul_ps(qq20,velec);
287 /* Update potential sum for this i atom from the interaction with this j atom. */
288 velecsum = _mm_add_ps(velecsum,velec);
292 /* Update vectorial force */
293 fix2 = _mm_macc_ps(dx20,fscal,fix2);
294 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
295 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
297 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
298 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
299 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
301 /**************************
302 * CALCULATE INTERACTIONS *
303 **************************/
305 r30 = _mm_mul_ps(rsq30,rinv30);
307 /* Compute parameters for interactions between i and j atoms */
308 qq30 = _mm_mul_ps(iq3,jq0);
310 /* EWALD ELECTROSTATICS */
312 /* Analytical PME correction */
313 zeta2 = _mm_mul_ps(beta2,rsq30);
314 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
315 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
316 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
317 felec = _mm_mul_ps(qq30,felec);
318 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
319 velec = _mm_nmacc_ps(pmecorrV,beta,rinv30);
320 velec = _mm_mul_ps(qq30,velec);
322 /* Update potential sum for this i atom from the interaction with this j atom. */
323 velecsum = _mm_add_ps(velecsum,velec);
327 /* Update vectorial force */
328 fix3 = _mm_macc_ps(dx30,fscal,fix3);
329 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
330 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
332 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
333 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
334 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
336 fjptrA = f+j_coord_offsetA;
337 fjptrB = f+j_coord_offsetB;
338 fjptrC = f+j_coord_offsetC;
339 fjptrD = f+j_coord_offsetD;
341 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
343 /* Inner loop uses 87 flops */
349 /* Get j neighbor index, and coordinate index */
350 jnrlistA = jjnr[jidx];
351 jnrlistB = jjnr[jidx+1];
352 jnrlistC = jjnr[jidx+2];
353 jnrlistD = jjnr[jidx+3];
354 /* Sign of each element will be negative for non-real atoms.
355 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
356 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
358 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
359 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
360 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
361 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
362 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
363 j_coord_offsetA = DIM*jnrA;
364 j_coord_offsetB = DIM*jnrB;
365 j_coord_offsetC = DIM*jnrC;
366 j_coord_offsetD = DIM*jnrD;
368 /* load j atom coordinates */
369 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
370 x+j_coord_offsetC,x+j_coord_offsetD,
373 /* Calculate displacement vector */
374 dx10 = _mm_sub_ps(ix1,jx0);
375 dy10 = _mm_sub_ps(iy1,jy0);
376 dz10 = _mm_sub_ps(iz1,jz0);
377 dx20 = _mm_sub_ps(ix2,jx0);
378 dy20 = _mm_sub_ps(iy2,jy0);
379 dz20 = _mm_sub_ps(iz2,jz0);
380 dx30 = _mm_sub_ps(ix3,jx0);
381 dy30 = _mm_sub_ps(iy3,jy0);
382 dz30 = _mm_sub_ps(iz3,jz0);
384 /* Calculate squared distance and things based on it */
385 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
386 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
387 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
389 rinv10 = gmx_mm_invsqrt_ps(rsq10);
390 rinv20 = gmx_mm_invsqrt_ps(rsq20);
391 rinv30 = gmx_mm_invsqrt_ps(rsq30);
393 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
394 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
395 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
397 /* Load parameters for j particles */
398 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
399 charge+jnrC+0,charge+jnrD+0);
401 fjx0 = _mm_setzero_ps();
402 fjy0 = _mm_setzero_ps();
403 fjz0 = _mm_setzero_ps();
405 /**************************
406 * CALCULATE INTERACTIONS *
407 **************************/
409 r10 = _mm_mul_ps(rsq10,rinv10);
410 r10 = _mm_andnot_ps(dummy_mask,r10);
412 /* Compute parameters for interactions between i and j atoms */
413 qq10 = _mm_mul_ps(iq1,jq0);
415 /* EWALD ELECTROSTATICS */
417 /* Analytical PME correction */
418 zeta2 = _mm_mul_ps(beta2,rsq10);
419 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
420 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
421 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
422 felec = _mm_mul_ps(qq10,felec);
423 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
424 velec = _mm_nmacc_ps(pmecorrV,beta,rinv10);
425 velec = _mm_mul_ps(qq10,velec);
427 /* Update potential sum for this i atom from the interaction with this j atom. */
428 velec = _mm_andnot_ps(dummy_mask,velec);
429 velecsum = _mm_add_ps(velecsum,velec);
433 fscal = _mm_andnot_ps(dummy_mask,fscal);
435 /* Update vectorial force */
436 fix1 = _mm_macc_ps(dx10,fscal,fix1);
437 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
438 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
440 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
441 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
442 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
444 /**************************
445 * CALCULATE INTERACTIONS *
446 **************************/
448 r20 = _mm_mul_ps(rsq20,rinv20);
449 r20 = _mm_andnot_ps(dummy_mask,r20);
451 /* Compute parameters for interactions between i and j atoms */
452 qq20 = _mm_mul_ps(iq2,jq0);
454 /* EWALD ELECTROSTATICS */
456 /* Analytical PME correction */
457 zeta2 = _mm_mul_ps(beta2,rsq20);
458 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
459 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
460 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
461 felec = _mm_mul_ps(qq20,felec);
462 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
463 velec = _mm_nmacc_ps(pmecorrV,beta,rinv20);
464 velec = _mm_mul_ps(qq20,velec);
466 /* Update potential sum for this i atom from the interaction with this j atom. */
467 velec = _mm_andnot_ps(dummy_mask,velec);
468 velecsum = _mm_add_ps(velecsum,velec);
472 fscal = _mm_andnot_ps(dummy_mask,fscal);
474 /* Update vectorial force */
475 fix2 = _mm_macc_ps(dx20,fscal,fix2);
476 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
477 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
479 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
480 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
481 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
483 /**************************
484 * CALCULATE INTERACTIONS *
485 **************************/
487 r30 = _mm_mul_ps(rsq30,rinv30);
488 r30 = _mm_andnot_ps(dummy_mask,r30);
490 /* Compute parameters for interactions between i and j atoms */
491 qq30 = _mm_mul_ps(iq3,jq0);
493 /* EWALD ELECTROSTATICS */
495 /* Analytical PME correction */
496 zeta2 = _mm_mul_ps(beta2,rsq30);
497 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
498 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
499 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
500 felec = _mm_mul_ps(qq30,felec);
501 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
502 velec = _mm_nmacc_ps(pmecorrV,beta,rinv30);
503 velec = _mm_mul_ps(qq30,velec);
505 /* Update potential sum for this i atom from the interaction with this j atom. */
506 velec = _mm_andnot_ps(dummy_mask,velec);
507 velecsum = _mm_add_ps(velecsum,velec);
511 fscal = _mm_andnot_ps(dummy_mask,fscal);
513 /* Update vectorial force */
514 fix3 = _mm_macc_ps(dx30,fscal,fix3);
515 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
516 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
518 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
519 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
520 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
522 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
523 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
524 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
525 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
527 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
529 /* Inner loop uses 90 flops */
532 /* End of innermost loop */
534 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
535 f+i_coord_offset+DIM,fshift+i_shift_offset);
538 /* Update potential energies */
539 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
541 /* Increment number of inner iterations */
542 inneriter += j_index_end - j_index_start;
544 /* Outer loop uses 19 flops */
547 /* Increment number of outer iterations */
550 /* Update outer/inner flops */
552 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*90);
555 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomW4P1_F_avx_128_fma_single
556 * Electrostatics interaction: Ewald
557 * VdW interaction: None
558 * Geometry: Water4-Particle
559 * Calculate force/pot: Force
562 nb_kernel_ElecEw_VdwNone_GeomW4P1_F_avx_128_fma_single
563 (t_nblist * gmx_restrict nlist,
564 rvec * gmx_restrict xx,
565 rvec * gmx_restrict ff,
566 t_forcerec * gmx_restrict fr,
567 t_mdatoms * gmx_restrict mdatoms,
568 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
569 t_nrnb * gmx_restrict nrnb)
571 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
572 * just 0 for non-waters.
573 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
574 * jnr indices corresponding to data put in the four positions in the SIMD register.
576 int i_shift_offset,i_coord_offset,outeriter,inneriter;
577 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
578 int jnrA,jnrB,jnrC,jnrD;
579 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
580 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
581 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
583 real *shiftvec,*fshift,*x,*f;
584 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
586 __m128 fscal,rcutoff,rcutoff2,jidxall;
588 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
590 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
592 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
593 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
594 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
595 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
596 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
597 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
598 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
601 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
602 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
604 __m128 dummy_mask,cutoff_mask;
605 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
606 __m128 one = _mm_set1_ps(1.0);
607 __m128 two = _mm_set1_ps(2.0);
613 jindex = nlist->jindex;
615 shiftidx = nlist->shift;
617 shiftvec = fr->shift_vec[0];
618 fshift = fr->fshift[0];
619 facel = _mm_set1_ps(fr->epsfac);
620 charge = mdatoms->chargeA;
622 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
623 beta = _mm_set1_ps(fr->ic->ewaldcoeff_q);
624 beta2 = _mm_mul_ps(beta,beta);
625 beta3 = _mm_mul_ps(beta,beta2);
626 ewtab = fr->ic->tabq_coul_F;
627 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
628 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
630 /* Setup water-specific parameters */
631 inr = nlist->iinr[0];
632 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
633 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
634 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
636 /* Avoid stupid compiler warnings */
637 jnrA = jnrB = jnrC = jnrD = 0;
646 for(iidx=0;iidx<4*DIM;iidx++)
651 /* Start outer loop over neighborlists */
652 for(iidx=0; iidx<nri; iidx++)
654 /* Load shift vector for this list */
655 i_shift_offset = DIM*shiftidx[iidx];
657 /* Load limits for loop over neighbors */
658 j_index_start = jindex[iidx];
659 j_index_end = jindex[iidx+1];
661 /* Get outer coordinate index */
663 i_coord_offset = DIM*inr;
665 /* Load i particle coords and add shift vector */
666 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
667 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
669 fix1 = _mm_setzero_ps();
670 fiy1 = _mm_setzero_ps();
671 fiz1 = _mm_setzero_ps();
672 fix2 = _mm_setzero_ps();
673 fiy2 = _mm_setzero_ps();
674 fiz2 = _mm_setzero_ps();
675 fix3 = _mm_setzero_ps();
676 fiy3 = _mm_setzero_ps();
677 fiz3 = _mm_setzero_ps();
679 /* Start inner kernel loop */
680 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
683 /* Get j neighbor index, and coordinate index */
688 j_coord_offsetA = DIM*jnrA;
689 j_coord_offsetB = DIM*jnrB;
690 j_coord_offsetC = DIM*jnrC;
691 j_coord_offsetD = DIM*jnrD;
693 /* load j atom coordinates */
694 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
695 x+j_coord_offsetC,x+j_coord_offsetD,
698 /* Calculate displacement vector */
699 dx10 = _mm_sub_ps(ix1,jx0);
700 dy10 = _mm_sub_ps(iy1,jy0);
701 dz10 = _mm_sub_ps(iz1,jz0);
702 dx20 = _mm_sub_ps(ix2,jx0);
703 dy20 = _mm_sub_ps(iy2,jy0);
704 dz20 = _mm_sub_ps(iz2,jz0);
705 dx30 = _mm_sub_ps(ix3,jx0);
706 dy30 = _mm_sub_ps(iy3,jy0);
707 dz30 = _mm_sub_ps(iz3,jz0);
709 /* Calculate squared distance and things based on it */
710 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
711 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
712 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
714 rinv10 = gmx_mm_invsqrt_ps(rsq10);
715 rinv20 = gmx_mm_invsqrt_ps(rsq20);
716 rinv30 = gmx_mm_invsqrt_ps(rsq30);
718 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
719 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
720 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
722 /* Load parameters for j particles */
723 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
724 charge+jnrC+0,charge+jnrD+0);
726 fjx0 = _mm_setzero_ps();
727 fjy0 = _mm_setzero_ps();
728 fjz0 = _mm_setzero_ps();
730 /**************************
731 * CALCULATE INTERACTIONS *
732 **************************/
734 r10 = _mm_mul_ps(rsq10,rinv10);
736 /* Compute parameters for interactions between i and j atoms */
737 qq10 = _mm_mul_ps(iq1,jq0);
739 /* EWALD ELECTROSTATICS */
741 /* Analytical PME correction */
742 zeta2 = _mm_mul_ps(beta2,rsq10);
743 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
744 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
745 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
746 felec = _mm_mul_ps(qq10,felec);
750 /* Update vectorial force */
751 fix1 = _mm_macc_ps(dx10,fscal,fix1);
752 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
753 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
755 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
756 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
757 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
759 /**************************
760 * CALCULATE INTERACTIONS *
761 **************************/
763 r20 = _mm_mul_ps(rsq20,rinv20);
765 /* Compute parameters for interactions between i and j atoms */
766 qq20 = _mm_mul_ps(iq2,jq0);
768 /* EWALD ELECTROSTATICS */
770 /* Analytical PME correction */
771 zeta2 = _mm_mul_ps(beta2,rsq20);
772 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
773 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
774 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
775 felec = _mm_mul_ps(qq20,felec);
779 /* Update vectorial force */
780 fix2 = _mm_macc_ps(dx20,fscal,fix2);
781 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
782 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
784 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
785 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
786 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
788 /**************************
789 * CALCULATE INTERACTIONS *
790 **************************/
792 r30 = _mm_mul_ps(rsq30,rinv30);
794 /* Compute parameters for interactions between i and j atoms */
795 qq30 = _mm_mul_ps(iq3,jq0);
797 /* EWALD ELECTROSTATICS */
799 /* Analytical PME correction */
800 zeta2 = _mm_mul_ps(beta2,rsq30);
801 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
802 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
803 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
804 felec = _mm_mul_ps(qq30,felec);
808 /* Update vectorial force */
809 fix3 = _mm_macc_ps(dx30,fscal,fix3);
810 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
811 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
813 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
814 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
815 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
817 fjptrA = f+j_coord_offsetA;
818 fjptrB = f+j_coord_offsetB;
819 fjptrC = f+j_coord_offsetC;
820 fjptrD = f+j_coord_offsetD;
822 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
824 /* Inner loop uses 84 flops */
830 /* Get j neighbor index, and coordinate index */
831 jnrlistA = jjnr[jidx];
832 jnrlistB = jjnr[jidx+1];
833 jnrlistC = jjnr[jidx+2];
834 jnrlistD = jjnr[jidx+3];
835 /* Sign of each element will be negative for non-real atoms.
836 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
837 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
839 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
840 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
841 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
842 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
843 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
844 j_coord_offsetA = DIM*jnrA;
845 j_coord_offsetB = DIM*jnrB;
846 j_coord_offsetC = DIM*jnrC;
847 j_coord_offsetD = DIM*jnrD;
849 /* load j atom coordinates */
850 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
851 x+j_coord_offsetC,x+j_coord_offsetD,
854 /* Calculate displacement vector */
855 dx10 = _mm_sub_ps(ix1,jx0);
856 dy10 = _mm_sub_ps(iy1,jy0);
857 dz10 = _mm_sub_ps(iz1,jz0);
858 dx20 = _mm_sub_ps(ix2,jx0);
859 dy20 = _mm_sub_ps(iy2,jy0);
860 dz20 = _mm_sub_ps(iz2,jz0);
861 dx30 = _mm_sub_ps(ix3,jx0);
862 dy30 = _mm_sub_ps(iy3,jy0);
863 dz30 = _mm_sub_ps(iz3,jz0);
865 /* Calculate squared distance and things based on it */
866 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
867 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
868 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
870 rinv10 = gmx_mm_invsqrt_ps(rsq10);
871 rinv20 = gmx_mm_invsqrt_ps(rsq20);
872 rinv30 = gmx_mm_invsqrt_ps(rsq30);
874 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
875 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
876 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
878 /* Load parameters for j particles */
879 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
880 charge+jnrC+0,charge+jnrD+0);
882 fjx0 = _mm_setzero_ps();
883 fjy0 = _mm_setzero_ps();
884 fjz0 = _mm_setzero_ps();
886 /**************************
887 * CALCULATE INTERACTIONS *
888 **************************/
890 r10 = _mm_mul_ps(rsq10,rinv10);
891 r10 = _mm_andnot_ps(dummy_mask,r10);
893 /* Compute parameters for interactions between i and j atoms */
894 qq10 = _mm_mul_ps(iq1,jq0);
896 /* EWALD ELECTROSTATICS */
898 /* Analytical PME correction */
899 zeta2 = _mm_mul_ps(beta2,rsq10);
900 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
901 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
902 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
903 felec = _mm_mul_ps(qq10,felec);
907 fscal = _mm_andnot_ps(dummy_mask,fscal);
909 /* Update vectorial force */
910 fix1 = _mm_macc_ps(dx10,fscal,fix1);
911 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
912 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
914 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
915 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
916 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
918 /**************************
919 * CALCULATE INTERACTIONS *
920 **************************/
922 r20 = _mm_mul_ps(rsq20,rinv20);
923 r20 = _mm_andnot_ps(dummy_mask,r20);
925 /* Compute parameters for interactions between i and j atoms */
926 qq20 = _mm_mul_ps(iq2,jq0);
928 /* EWALD ELECTROSTATICS */
930 /* Analytical PME correction */
931 zeta2 = _mm_mul_ps(beta2,rsq20);
932 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
933 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
934 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
935 felec = _mm_mul_ps(qq20,felec);
939 fscal = _mm_andnot_ps(dummy_mask,fscal);
941 /* Update vectorial force */
942 fix2 = _mm_macc_ps(dx20,fscal,fix2);
943 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
944 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
946 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
947 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
948 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
950 /**************************
951 * CALCULATE INTERACTIONS *
952 **************************/
954 r30 = _mm_mul_ps(rsq30,rinv30);
955 r30 = _mm_andnot_ps(dummy_mask,r30);
957 /* Compute parameters for interactions between i and j atoms */
958 qq30 = _mm_mul_ps(iq3,jq0);
960 /* EWALD ELECTROSTATICS */
962 /* Analytical PME correction */
963 zeta2 = _mm_mul_ps(beta2,rsq30);
964 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
965 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
966 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
967 felec = _mm_mul_ps(qq30,felec);
971 fscal = _mm_andnot_ps(dummy_mask,fscal);
973 /* Update vectorial force */
974 fix3 = _mm_macc_ps(dx30,fscal,fix3);
975 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
976 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
978 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
979 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
980 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
982 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
983 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
984 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
985 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
987 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
989 /* Inner loop uses 87 flops */
992 /* End of innermost loop */
994 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
995 f+i_coord_offset+DIM,fshift+i_shift_offset);
997 /* Increment number of inner iterations */
998 inneriter += j_index_end - j_index_start;
1000 /* Outer loop uses 18 flops */
1003 /* Increment number of outer iterations */
1006 /* Update outer/inner flops */
1008 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*87);