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.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.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_ElecRF_VdwNone_GeomP1P1_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRF_VdwNone_GeomP1P1_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
92 __m128 dummy_mask,cutoff_mask;
93 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
94 __m128 one = _mm_set1_ps(1.0);
95 __m128 two = _mm_set1_ps(2.0);
101 jindex = nlist->jindex;
103 shiftidx = nlist->shift;
105 shiftvec = fr->shift_vec[0];
106 fshift = fr->fshift[0];
107 facel = _mm_set1_ps(fr->epsfac);
108 charge = mdatoms->chargeA;
109 krf = _mm_set1_ps(fr->ic->k_rf);
110 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
111 crf = _mm_set1_ps(fr->ic->c_rf);
113 /* Avoid stupid compiler warnings */
114 jnrA = jnrB = jnrC = jnrD = 0;
123 for(iidx=0;iidx<4*DIM;iidx++)
128 /* Start outer loop over neighborlists */
129 for(iidx=0; iidx<nri; iidx++)
131 /* Load shift vector for this list */
132 i_shift_offset = DIM*shiftidx[iidx];
134 /* Load limits for loop over neighbors */
135 j_index_start = jindex[iidx];
136 j_index_end = jindex[iidx+1];
138 /* Get outer coordinate index */
140 i_coord_offset = DIM*inr;
142 /* Load i particle coords and add shift vector */
143 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
145 fix0 = _mm_setzero_ps();
146 fiy0 = _mm_setzero_ps();
147 fiz0 = _mm_setzero_ps();
149 /* Load parameters for i particles */
150 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
152 /* Reset potential sums */
153 velecsum = _mm_setzero_ps();
155 /* Start inner kernel loop */
156 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
159 /* Get j neighbor index, and coordinate index */
164 j_coord_offsetA = DIM*jnrA;
165 j_coord_offsetB = DIM*jnrB;
166 j_coord_offsetC = DIM*jnrC;
167 j_coord_offsetD = DIM*jnrD;
169 /* load j atom coordinates */
170 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
171 x+j_coord_offsetC,x+j_coord_offsetD,
174 /* Calculate displacement vector */
175 dx00 = _mm_sub_ps(ix0,jx0);
176 dy00 = _mm_sub_ps(iy0,jy0);
177 dz00 = _mm_sub_ps(iz0,jz0);
179 /* Calculate squared distance and things based on it */
180 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
182 rinv00 = gmx_mm_invsqrt_ps(rsq00);
184 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
186 /* Load parameters for j particles */
187 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
188 charge+jnrC+0,charge+jnrD+0);
190 /**************************
191 * CALCULATE INTERACTIONS *
192 **************************/
194 /* Compute parameters for interactions between i and j atoms */
195 qq00 = _mm_mul_ps(iq0,jq0);
197 /* REACTION-FIELD ELECTROSTATICS */
198 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
199 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
201 /* Update potential sum for this i atom from the interaction with this j atom. */
202 velecsum = _mm_add_ps(velecsum,velec);
206 /* Update vectorial force */
207 fix0 = _mm_macc_ps(dx00,fscal,fix0);
208 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
209 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
211 fjptrA = f+j_coord_offsetA;
212 fjptrB = f+j_coord_offsetB;
213 fjptrC = f+j_coord_offsetC;
214 fjptrD = f+j_coord_offsetD;
215 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
216 _mm_mul_ps(dx00,fscal),
217 _mm_mul_ps(dy00,fscal),
218 _mm_mul_ps(dz00,fscal));
220 /* Inner loop uses 35 flops */
226 /* Get j neighbor index, and coordinate index */
227 jnrlistA = jjnr[jidx];
228 jnrlistB = jjnr[jidx+1];
229 jnrlistC = jjnr[jidx+2];
230 jnrlistD = jjnr[jidx+3];
231 /* Sign of each element will be negative for non-real atoms.
232 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
233 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
235 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
236 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
237 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
238 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
239 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
240 j_coord_offsetA = DIM*jnrA;
241 j_coord_offsetB = DIM*jnrB;
242 j_coord_offsetC = DIM*jnrC;
243 j_coord_offsetD = DIM*jnrD;
245 /* load j atom coordinates */
246 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
247 x+j_coord_offsetC,x+j_coord_offsetD,
250 /* Calculate displacement vector */
251 dx00 = _mm_sub_ps(ix0,jx0);
252 dy00 = _mm_sub_ps(iy0,jy0);
253 dz00 = _mm_sub_ps(iz0,jz0);
255 /* Calculate squared distance and things based on it */
256 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
258 rinv00 = gmx_mm_invsqrt_ps(rsq00);
260 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
262 /* Load parameters for j particles */
263 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
264 charge+jnrC+0,charge+jnrD+0);
266 /**************************
267 * CALCULATE INTERACTIONS *
268 **************************/
270 /* Compute parameters for interactions between i and j atoms */
271 qq00 = _mm_mul_ps(iq0,jq0);
273 /* REACTION-FIELD ELECTROSTATICS */
274 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
275 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
277 /* Update potential sum for this i atom from the interaction with this j atom. */
278 velec = _mm_andnot_ps(dummy_mask,velec);
279 velecsum = _mm_add_ps(velecsum,velec);
283 fscal = _mm_andnot_ps(dummy_mask,fscal);
285 /* Update vectorial force */
286 fix0 = _mm_macc_ps(dx00,fscal,fix0);
287 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
288 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
290 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
291 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
292 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
293 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
294 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
295 _mm_mul_ps(dx00,fscal),
296 _mm_mul_ps(dy00,fscal),
297 _mm_mul_ps(dz00,fscal));
299 /* Inner loop uses 35 flops */
302 /* End of innermost loop */
304 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
305 f+i_coord_offset,fshift+i_shift_offset);
308 /* Update potential energies */
309 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
311 /* Increment number of inner iterations */
312 inneriter += j_index_end - j_index_start;
314 /* Outer loop uses 8 flops */
317 /* Increment number of outer iterations */
320 /* Update outer/inner flops */
322 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*35);
325 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomP1P1_F_avx_128_fma_single
326 * Electrostatics interaction: ReactionField
327 * VdW interaction: None
328 * Geometry: Particle-Particle
329 * Calculate force/pot: Force
332 nb_kernel_ElecRF_VdwNone_GeomP1P1_F_avx_128_fma_single
333 (t_nblist * gmx_restrict nlist,
334 rvec * gmx_restrict xx,
335 rvec * gmx_restrict ff,
336 t_forcerec * gmx_restrict fr,
337 t_mdatoms * gmx_restrict mdatoms,
338 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
339 t_nrnb * gmx_restrict nrnb)
341 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
342 * just 0 for non-waters.
343 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
344 * jnr indices corresponding to data put in the four positions in the SIMD register.
346 int i_shift_offset,i_coord_offset,outeriter,inneriter;
347 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
348 int jnrA,jnrB,jnrC,jnrD;
349 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
350 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
351 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
353 real *shiftvec,*fshift,*x,*f;
354 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
356 __m128 fscal,rcutoff,rcutoff2,jidxall;
358 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
359 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
360 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
361 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
362 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
364 __m128 dummy_mask,cutoff_mask;
365 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
366 __m128 one = _mm_set1_ps(1.0);
367 __m128 two = _mm_set1_ps(2.0);
373 jindex = nlist->jindex;
375 shiftidx = nlist->shift;
377 shiftvec = fr->shift_vec[0];
378 fshift = fr->fshift[0];
379 facel = _mm_set1_ps(fr->epsfac);
380 charge = mdatoms->chargeA;
381 krf = _mm_set1_ps(fr->ic->k_rf);
382 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
383 crf = _mm_set1_ps(fr->ic->c_rf);
385 /* Avoid stupid compiler warnings */
386 jnrA = jnrB = jnrC = jnrD = 0;
395 for(iidx=0;iidx<4*DIM;iidx++)
400 /* Start outer loop over neighborlists */
401 for(iidx=0; iidx<nri; iidx++)
403 /* Load shift vector for this list */
404 i_shift_offset = DIM*shiftidx[iidx];
406 /* Load limits for loop over neighbors */
407 j_index_start = jindex[iidx];
408 j_index_end = jindex[iidx+1];
410 /* Get outer coordinate index */
412 i_coord_offset = DIM*inr;
414 /* Load i particle coords and add shift vector */
415 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
417 fix0 = _mm_setzero_ps();
418 fiy0 = _mm_setzero_ps();
419 fiz0 = _mm_setzero_ps();
421 /* Load parameters for i particles */
422 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
424 /* Start inner kernel loop */
425 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
428 /* Get j neighbor index, and coordinate index */
433 j_coord_offsetA = DIM*jnrA;
434 j_coord_offsetB = DIM*jnrB;
435 j_coord_offsetC = DIM*jnrC;
436 j_coord_offsetD = DIM*jnrD;
438 /* load j atom coordinates */
439 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
440 x+j_coord_offsetC,x+j_coord_offsetD,
443 /* Calculate displacement vector */
444 dx00 = _mm_sub_ps(ix0,jx0);
445 dy00 = _mm_sub_ps(iy0,jy0);
446 dz00 = _mm_sub_ps(iz0,jz0);
448 /* Calculate squared distance and things based on it */
449 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
451 rinv00 = gmx_mm_invsqrt_ps(rsq00);
453 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
455 /* Load parameters for j particles */
456 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
457 charge+jnrC+0,charge+jnrD+0);
459 /**************************
460 * CALCULATE INTERACTIONS *
461 **************************/
463 /* Compute parameters for interactions between i and j atoms */
464 qq00 = _mm_mul_ps(iq0,jq0);
466 /* REACTION-FIELD ELECTROSTATICS */
467 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
471 /* Update vectorial force */
472 fix0 = _mm_macc_ps(dx00,fscal,fix0);
473 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
474 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
476 fjptrA = f+j_coord_offsetA;
477 fjptrB = f+j_coord_offsetB;
478 fjptrC = f+j_coord_offsetC;
479 fjptrD = f+j_coord_offsetD;
480 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
481 _mm_mul_ps(dx00,fscal),
482 _mm_mul_ps(dy00,fscal),
483 _mm_mul_ps(dz00,fscal));
485 /* Inner loop uses 30 flops */
491 /* Get j neighbor index, and coordinate index */
492 jnrlistA = jjnr[jidx];
493 jnrlistB = jjnr[jidx+1];
494 jnrlistC = jjnr[jidx+2];
495 jnrlistD = jjnr[jidx+3];
496 /* Sign of each element will be negative for non-real atoms.
497 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
498 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
500 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
501 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
502 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
503 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
504 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
505 j_coord_offsetA = DIM*jnrA;
506 j_coord_offsetB = DIM*jnrB;
507 j_coord_offsetC = DIM*jnrC;
508 j_coord_offsetD = DIM*jnrD;
510 /* load j atom coordinates */
511 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
512 x+j_coord_offsetC,x+j_coord_offsetD,
515 /* Calculate displacement vector */
516 dx00 = _mm_sub_ps(ix0,jx0);
517 dy00 = _mm_sub_ps(iy0,jy0);
518 dz00 = _mm_sub_ps(iz0,jz0);
520 /* Calculate squared distance and things based on it */
521 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
523 rinv00 = gmx_mm_invsqrt_ps(rsq00);
525 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
527 /* Load parameters for j particles */
528 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
529 charge+jnrC+0,charge+jnrD+0);
531 /**************************
532 * CALCULATE INTERACTIONS *
533 **************************/
535 /* Compute parameters for interactions between i and j atoms */
536 qq00 = _mm_mul_ps(iq0,jq0);
538 /* REACTION-FIELD ELECTROSTATICS */
539 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
543 fscal = _mm_andnot_ps(dummy_mask,fscal);
545 /* Update vectorial force */
546 fix0 = _mm_macc_ps(dx00,fscal,fix0);
547 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
548 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
550 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
551 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
552 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
553 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
554 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
555 _mm_mul_ps(dx00,fscal),
556 _mm_mul_ps(dy00,fscal),
557 _mm_mul_ps(dz00,fscal));
559 /* Inner loop uses 30 flops */
562 /* End of innermost loop */
564 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
565 f+i_coord_offset,fshift+i_shift_offset);
567 /* Increment number of inner iterations */
568 inneriter += j_index_end - j_index_start;
570 /* Outer loop uses 7 flops */
573 /* Increment number of outer iterations */
576 /* Update outer/inner flops */
578 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*30);