Remove all unnecessary HAVE_CONFIG_H
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecEw_VdwNone_GeomW4P1_avx_128_fma_single.c
blobefe5e3a942933b6b6b9f0ad3dbb2a6b669b1ed98
1 /*
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.
38 #include "config.h"
40 #include <math.h>
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.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_GeomW4P1_VF_avx_128_fma_single
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
57 void
58 nb_kernel_ElecEw_VdwNone_GeomW4P1_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;
78 real rcutoff_scalar;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 real scratch[4*DIM];
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
83 int vdwioffset1;
84 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 int vdwioffset2;
86 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 int vdwioffset3;
88 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
95 real *charge;
96 __m128i ewitab;
97 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
98 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
99 real *ewtab;
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);
104 x = xx[0];
105 f = ff[0];
107 nri = nlist->nri;
108 iinr = nlist->iinr;
109 jindex = nlist->jindex;
110 jjnr = nlist->jjnr;
111 shiftidx = nlist->shift;
112 gid = nlist->gid;
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 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
129 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
130 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
132 /* Avoid stupid compiler warnings */
133 jnrA = jnrB = jnrC = jnrD = 0;
134 j_coord_offsetA = 0;
135 j_coord_offsetB = 0;
136 j_coord_offsetC = 0;
137 j_coord_offsetD = 0;
139 outeriter = 0;
140 inneriter = 0;
142 for(iidx=0;iidx<4*DIM;iidx++)
144 scratch[iidx] = 0.0;
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 */
158 inr = iinr[iidx];
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+DIM,
163 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
165 fix1 = _mm_setzero_ps();
166 fiy1 = _mm_setzero_ps();
167 fiz1 = _mm_setzero_ps();
168 fix2 = _mm_setzero_ps();
169 fiy2 = _mm_setzero_ps();
170 fiz2 = _mm_setzero_ps();
171 fix3 = _mm_setzero_ps();
172 fiy3 = _mm_setzero_ps();
173 fiz3 = _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 */
183 jnrA = jjnr[jidx];
184 jnrB = jjnr[jidx+1];
185 jnrC = jjnr[jidx+2];
186 jnrD = jjnr[jidx+3];
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,
195 &jx0,&jy0,&jz0);
197 /* Calculate displacement vector */
198 dx10 = _mm_sub_ps(ix1,jx0);
199 dy10 = _mm_sub_ps(iy1,jy0);
200 dz10 = _mm_sub_ps(iz1,jz0);
201 dx20 = _mm_sub_ps(ix2,jx0);
202 dy20 = _mm_sub_ps(iy2,jy0);
203 dz20 = _mm_sub_ps(iz2,jz0);
204 dx30 = _mm_sub_ps(ix3,jx0);
205 dy30 = _mm_sub_ps(iy3,jy0);
206 dz30 = _mm_sub_ps(iz3,jz0);
208 /* Calculate squared distance and things based on it */
209 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
210 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
211 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
213 rinv10 = gmx_mm_invsqrt_ps(rsq10);
214 rinv20 = gmx_mm_invsqrt_ps(rsq20);
215 rinv30 = gmx_mm_invsqrt_ps(rsq30);
217 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
218 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
219 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
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 r10 = _mm_mul_ps(rsq10,rinv10);
235 /* Compute parameters for interactions between i and j atoms */
236 qq10 = _mm_mul_ps(iq1,jq0);
238 /* EWALD ELECTROSTATICS */
240 /* Analytical PME correction */
241 zeta2 = _mm_mul_ps(beta2,rsq10);
242 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
243 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
244 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
245 felec = _mm_mul_ps(qq10,felec);
246 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
247 velec = _mm_nmacc_ps(pmecorrV,beta,rinv10);
248 velec = _mm_mul_ps(qq10,velec);
250 /* Update potential sum for this i atom from the interaction with this j atom. */
251 velecsum = _mm_add_ps(velecsum,velec);
253 fscal = felec;
255 /* Update vectorial force */
256 fix1 = _mm_macc_ps(dx10,fscal,fix1);
257 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
258 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
260 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
261 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
262 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
264 /**************************
265 * CALCULATE INTERACTIONS *
266 **************************/
268 r20 = _mm_mul_ps(rsq20,rinv20);
270 /* Compute parameters for interactions between i and j atoms */
271 qq20 = _mm_mul_ps(iq2,jq0);
273 /* EWALD ELECTROSTATICS */
275 /* Analytical PME correction */
276 zeta2 = _mm_mul_ps(beta2,rsq20);
277 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
278 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
279 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
280 felec = _mm_mul_ps(qq20,felec);
281 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
282 velec = _mm_nmacc_ps(pmecorrV,beta,rinv20);
283 velec = _mm_mul_ps(qq20,velec);
285 /* Update potential sum for this i atom from the interaction with this j atom. */
286 velecsum = _mm_add_ps(velecsum,velec);
288 fscal = felec;
290 /* Update vectorial force */
291 fix2 = _mm_macc_ps(dx20,fscal,fix2);
292 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
293 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
295 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
296 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
297 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
299 /**************************
300 * CALCULATE INTERACTIONS *
301 **************************/
303 r30 = _mm_mul_ps(rsq30,rinv30);
305 /* Compute parameters for interactions between i and j atoms */
306 qq30 = _mm_mul_ps(iq3,jq0);
308 /* EWALD ELECTROSTATICS */
310 /* Analytical PME correction */
311 zeta2 = _mm_mul_ps(beta2,rsq30);
312 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
313 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
314 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
315 felec = _mm_mul_ps(qq30,felec);
316 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
317 velec = _mm_nmacc_ps(pmecorrV,beta,rinv30);
318 velec = _mm_mul_ps(qq30,velec);
320 /* Update potential sum for this i atom from the interaction with this j atom. */
321 velecsum = _mm_add_ps(velecsum,velec);
323 fscal = felec;
325 /* Update vectorial force */
326 fix3 = _mm_macc_ps(dx30,fscal,fix3);
327 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
328 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
330 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
331 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
332 fjz0 = _mm_macc_ps(dz30,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 */
344 if(jidx<j_index_end)
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,
369 &jx0,&jy0,&jz0);
371 /* Calculate displacement vector */
372 dx10 = _mm_sub_ps(ix1,jx0);
373 dy10 = _mm_sub_ps(iy1,jy0);
374 dz10 = _mm_sub_ps(iz1,jz0);
375 dx20 = _mm_sub_ps(ix2,jx0);
376 dy20 = _mm_sub_ps(iy2,jy0);
377 dz20 = _mm_sub_ps(iz2,jz0);
378 dx30 = _mm_sub_ps(ix3,jx0);
379 dy30 = _mm_sub_ps(iy3,jy0);
380 dz30 = _mm_sub_ps(iz3,jz0);
382 /* Calculate squared distance and things based on it */
383 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
384 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
385 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
387 rinv10 = gmx_mm_invsqrt_ps(rsq10);
388 rinv20 = gmx_mm_invsqrt_ps(rsq20);
389 rinv30 = gmx_mm_invsqrt_ps(rsq30);
391 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
392 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
393 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
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 r10 = _mm_mul_ps(rsq10,rinv10);
408 r10 = _mm_andnot_ps(dummy_mask,r10);
410 /* Compute parameters for interactions between i and j atoms */
411 qq10 = _mm_mul_ps(iq1,jq0);
413 /* EWALD ELECTROSTATICS */
415 /* Analytical PME correction */
416 zeta2 = _mm_mul_ps(beta2,rsq10);
417 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
418 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
419 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
420 felec = _mm_mul_ps(qq10,felec);
421 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
422 velec = _mm_nmacc_ps(pmecorrV,beta,rinv10);
423 velec = _mm_mul_ps(qq10,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);
429 fscal = felec;
431 fscal = _mm_andnot_ps(dummy_mask,fscal);
433 /* Update vectorial force */
434 fix1 = _mm_macc_ps(dx10,fscal,fix1);
435 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
436 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
438 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
439 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
440 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
442 /**************************
443 * CALCULATE INTERACTIONS *
444 **************************/
446 r20 = _mm_mul_ps(rsq20,rinv20);
447 r20 = _mm_andnot_ps(dummy_mask,r20);
449 /* Compute parameters for interactions between i and j atoms */
450 qq20 = _mm_mul_ps(iq2,jq0);
452 /* EWALD ELECTROSTATICS */
454 /* Analytical PME correction */
455 zeta2 = _mm_mul_ps(beta2,rsq20);
456 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
457 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
458 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
459 felec = _mm_mul_ps(qq20,felec);
460 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
461 velec = _mm_nmacc_ps(pmecorrV,beta,rinv20);
462 velec = _mm_mul_ps(qq20,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);
468 fscal = felec;
470 fscal = _mm_andnot_ps(dummy_mask,fscal);
472 /* Update vectorial force */
473 fix2 = _mm_macc_ps(dx20,fscal,fix2);
474 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
475 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
477 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
478 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
479 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
481 /**************************
482 * CALCULATE INTERACTIONS *
483 **************************/
485 r30 = _mm_mul_ps(rsq30,rinv30);
486 r30 = _mm_andnot_ps(dummy_mask,r30);
488 /* Compute parameters for interactions between i and j atoms */
489 qq30 = _mm_mul_ps(iq3,jq0);
491 /* EWALD ELECTROSTATICS */
493 /* Analytical PME correction */
494 zeta2 = _mm_mul_ps(beta2,rsq30);
495 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
496 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
497 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
498 felec = _mm_mul_ps(qq30,felec);
499 pmecorrV = gmx_mm_pmecorrV_ps(zeta2);
500 velec = _mm_nmacc_ps(pmecorrV,beta,rinv30);
501 velec = _mm_mul_ps(qq30,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);
507 fscal = felec;
509 fscal = _mm_andnot_ps(dummy_mask,fscal);
511 /* Update vectorial force */
512 fix3 = _mm_macc_ps(dx30,fscal,fix3);
513 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
514 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
516 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
517 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
518 fjz0 = _mm_macc_ps(dz30,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(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
533 f+i_coord_offset+DIM,fshift+i_shift_offset);
535 ggid = gid[iidx];
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 */
546 outeriter += nri;
548 /* Update outer/inner flops */
550 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*90);
553 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomW4P1_F_avx_128_fma_single
554 * Electrostatics interaction: Ewald
555 * VdW interaction: None
556 * Geometry: Water4-Particle
557 * Calculate force/pot: Force
559 void
560 nb_kernel_ElecEw_VdwNone_GeomW4P1_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;
580 real rcutoff_scalar;
581 real *shiftvec,*fshift,*x,*f;
582 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
583 real scratch[4*DIM];
584 __m128 fscal,rcutoff,rcutoff2,jidxall;
585 int vdwioffset1;
586 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
587 int vdwioffset2;
588 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
589 int vdwioffset3;
590 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
591 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
592 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
593 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
594 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
595 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
596 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
597 real *charge;
598 __m128i ewitab;
599 __m128 ewtabscale,eweps,twoeweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
600 __m128 beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
601 real *ewtab;
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);
606 x = xx[0];
607 f = ff[0];
609 nri = nlist->nri;
610 iinr = nlist->iinr;
611 jindex = nlist->jindex;
612 jjnr = nlist->jjnr;
613 shiftidx = nlist->shift;
614 gid = nlist->gid;
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 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
631 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
632 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
634 /* Avoid stupid compiler warnings */
635 jnrA = jnrB = jnrC = jnrD = 0;
636 j_coord_offsetA = 0;
637 j_coord_offsetB = 0;
638 j_coord_offsetC = 0;
639 j_coord_offsetD = 0;
641 outeriter = 0;
642 inneriter = 0;
644 for(iidx=0;iidx<4*DIM;iidx++)
646 scratch[iidx] = 0.0;
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 */
660 inr = iinr[iidx];
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+DIM,
665 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
667 fix1 = _mm_setzero_ps();
668 fiy1 = _mm_setzero_ps();
669 fiz1 = _mm_setzero_ps();
670 fix2 = _mm_setzero_ps();
671 fiy2 = _mm_setzero_ps();
672 fiz2 = _mm_setzero_ps();
673 fix3 = _mm_setzero_ps();
674 fiy3 = _mm_setzero_ps();
675 fiz3 = _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 */
682 jnrA = jjnr[jidx];
683 jnrB = jjnr[jidx+1];
684 jnrC = jjnr[jidx+2];
685 jnrD = jjnr[jidx+3];
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,
694 &jx0,&jy0,&jz0);
696 /* Calculate displacement vector */
697 dx10 = _mm_sub_ps(ix1,jx0);
698 dy10 = _mm_sub_ps(iy1,jy0);
699 dz10 = _mm_sub_ps(iz1,jz0);
700 dx20 = _mm_sub_ps(ix2,jx0);
701 dy20 = _mm_sub_ps(iy2,jy0);
702 dz20 = _mm_sub_ps(iz2,jz0);
703 dx30 = _mm_sub_ps(ix3,jx0);
704 dy30 = _mm_sub_ps(iy3,jy0);
705 dz30 = _mm_sub_ps(iz3,jz0);
707 /* Calculate squared distance and things based on it */
708 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
709 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
710 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
712 rinv10 = gmx_mm_invsqrt_ps(rsq10);
713 rinv20 = gmx_mm_invsqrt_ps(rsq20);
714 rinv30 = gmx_mm_invsqrt_ps(rsq30);
716 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
717 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
718 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
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 r10 = _mm_mul_ps(rsq10,rinv10);
734 /* Compute parameters for interactions between i and j atoms */
735 qq10 = _mm_mul_ps(iq1,jq0);
737 /* EWALD ELECTROSTATICS */
739 /* Analytical PME correction */
740 zeta2 = _mm_mul_ps(beta2,rsq10);
741 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
742 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
743 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
744 felec = _mm_mul_ps(qq10,felec);
746 fscal = felec;
748 /* Update vectorial force */
749 fix1 = _mm_macc_ps(dx10,fscal,fix1);
750 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
751 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
753 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
754 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
755 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
757 /**************************
758 * CALCULATE INTERACTIONS *
759 **************************/
761 r20 = _mm_mul_ps(rsq20,rinv20);
763 /* Compute parameters for interactions between i and j atoms */
764 qq20 = _mm_mul_ps(iq2,jq0);
766 /* EWALD ELECTROSTATICS */
768 /* Analytical PME correction */
769 zeta2 = _mm_mul_ps(beta2,rsq20);
770 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
771 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
772 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
773 felec = _mm_mul_ps(qq20,felec);
775 fscal = felec;
777 /* Update vectorial force */
778 fix2 = _mm_macc_ps(dx20,fscal,fix2);
779 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
780 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
782 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
783 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
784 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
786 /**************************
787 * CALCULATE INTERACTIONS *
788 **************************/
790 r30 = _mm_mul_ps(rsq30,rinv30);
792 /* Compute parameters for interactions between i and j atoms */
793 qq30 = _mm_mul_ps(iq3,jq0);
795 /* EWALD ELECTROSTATICS */
797 /* Analytical PME correction */
798 zeta2 = _mm_mul_ps(beta2,rsq30);
799 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
800 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
801 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
802 felec = _mm_mul_ps(qq30,felec);
804 fscal = felec;
806 /* Update vectorial force */
807 fix3 = _mm_macc_ps(dx30,fscal,fix3);
808 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
809 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
811 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
812 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
813 fjz0 = _mm_macc_ps(dz30,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 */
825 if(jidx<j_index_end)
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,
850 &jx0,&jy0,&jz0);
852 /* Calculate displacement vector */
853 dx10 = _mm_sub_ps(ix1,jx0);
854 dy10 = _mm_sub_ps(iy1,jy0);
855 dz10 = _mm_sub_ps(iz1,jz0);
856 dx20 = _mm_sub_ps(ix2,jx0);
857 dy20 = _mm_sub_ps(iy2,jy0);
858 dz20 = _mm_sub_ps(iz2,jz0);
859 dx30 = _mm_sub_ps(ix3,jx0);
860 dy30 = _mm_sub_ps(iy3,jy0);
861 dz30 = _mm_sub_ps(iz3,jz0);
863 /* Calculate squared distance and things based on it */
864 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
865 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
866 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
868 rinv10 = gmx_mm_invsqrt_ps(rsq10);
869 rinv20 = gmx_mm_invsqrt_ps(rsq20);
870 rinv30 = gmx_mm_invsqrt_ps(rsq30);
872 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
873 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
874 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
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 r10 = _mm_mul_ps(rsq10,rinv10);
889 r10 = _mm_andnot_ps(dummy_mask,r10);
891 /* Compute parameters for interactions between i and j atoms */
892 qq10 = _mm_mul_ps(iq1,jq0);
894 /* EWALD ELECTROSTATICS */
896 /* Analytical PME correction */
897 zeta2 = _mm_mul_ps(beta2,rsq10);
898 rinv3 = _mm_mul_ps(rinvsq10,rinv10);
899 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
900 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
901 felec = _mm_mul_ps(qq10,felec);
903 fscal = felec;
905 fscal = _mm_andnot_ps(dummy_mask,fscal);
907 /* Update vectorial force */
908 fix1 = _mm_macc_ps(dx10,fscal,fix1);
909 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
910 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
912 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
913 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
914 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
916 /**************************
917 * CALCULATE INTERACTIONS *
918 **************************/
920 r20 = _mm_mul_ps(rsq20,rinv20);
921 r20 = _mm_andnot_ps(dummy_mask,r20);
923 /* Compute parameters for interactions between i and j atoms */
924 qq20 = _mm_mul_ps(iq2,jq0);
926 /* EWALD ELECTROSTATICS */
928 /* Analytical PME correction */
929 zeta2 = _mm_mul_ps(beta2,rsq20);
930 rinv3 = _mm_mul_ps(rinvsq20,rinv20);
931 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
932 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
933 felec = _mm_mul_ps(qq20,felec);
935 fscal = felec;
937 fscal = _mm_andnot_ps(dummy_mask,fscal);
939 /* Update vectorial force */
940 fix2 = _mm_macc_ps(dx20,fscal,fix2);
941 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
942 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
944 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
945 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
946 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
948 /**************************
949 * CALCULATE INTERACTIONS *
950 **************************/
952 r30 = _mm_mul_ps(rsq30,rinv30);
953 r30 = _mm_andnot_ps(dummy_mask,r30);
955 /* Compute parameters for interactions between i and j atoms */
956 qq30 = _mm_mul_ps(iq3,jq0);
958 /* EWALD ELECTROSTATICS */
960 /* Analytical PME correction */
961 zeta2 = _mm_mul_ps(beta2,rsq30);
962 rinv3 = _mm_mul_ps(rinvsq30,rinv30);
963 pmecorrF = gmx_mm_pmecorrF_ps(zeta2);
964 felec = _mm_macc_ps(pmecorrF,beta3,rinv3);
965 felec = _mm_mul_ps(qq30,felec);
967 fscal = felec;
969 fscal = _mm_andnot_ps(dummy_mask,fscal);
971 /* Update vectorial force */
972 fix3 = _mm_macc_ps(dx30,fscal,fix3);
973 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
974 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
976 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
977 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
978 fjz0 = _mm_macc_ps(dz30,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(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
993 f+i_coord_offset+DIM,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 */
1002 outeriter += nri;
1004 /* Update outer/inner flops */
1006 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*87);