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_ElecCoul_VdwNone_GeomP1P1_VF_avx_128_fma_single
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwNone_GeomP1P1_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;
85 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128 dummy_mask,cutoff_mask;
91 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
92 __m128 one = _mm_set1_ps(1.0);
93 __m128 two = _mm_set1_ps(2.0);
99 jindex = nlist->jindex;
101 shiftidx = nlist->shift;
103 shiftvec = fr->shift_vec[0];
104 fshift = fr->fshift[0];
105 facel = _mm_set1_ps(fr->epsfac);
106 charge = mdatoms->chargeA;
108 /* Avoid stupid compiler warnings */
109 jnrA = jnrB = jnrC = jnrD = 0;
118 for(iidx=0;iidx<4*DIM;iidx++)
123 /* Start outer loop over neighborlists */
124 for(iidx=0; iidx<nri; iidx++)
126 /* Load shift vector for this list */
127 i_shift_offset = DIM*shiftidx[iidx];
129 /* Load limits for loop over neighbors */
130 j_index_start = jindex[iidx];
131 j_index_end = jindex[iidx+1];
133 /* Get outer coordinate index */
135 i_coord_offset = DIM*inr;
137 /* Load i particle coords and add shift vector */
138 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
140 fix0 = _mm_setzero_ps();
141 fiy0 = _mm_setzero_ps();
142 fiz0 = _mm_setzero_ps();
144 /* Load parameters for i particles */
145 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
147 /* Reset potential sums */
148 velecsum = _mm_setzero_ps();
150 /* Start inner kernel loop */
151 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
154 /* Get j neighbor index, and coordinate index */
159 j_coord_offsetA = DIM*jnrA;
160 j_coord_offsetB = DIM*jnrB;
161 j_coord_offsetC = DIM*jnrC;
162 j_coord_offsetD = DIM*jnrD;
164 /* load j atom coordinates */
165 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
166 x+j_coord_offsetC,x+j_coord_offsetD,
169 /* Calculate displacement vector */
170 dx00 = _mm_sub_ps(ix0,jx0);
171 dy00 = _mm_sub_ps(iy0,jy0);
172 dz00 = _mm_sub_ps(iz0,jz0);
174 /* Calculate squared distance and things based on it */
175 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
177 rinv00 = gmx_mm_invsqrt_ps(rsq00);
179 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
181 /* Load parameters for j particles */
182 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
183 charge+jnrC+0,charge+jnrD+0);
185 /**************************
186 * CALCULATE INTERACTIONS *
187 **************************/
189 /* Compute parameters for interactions between i and j atoms */
190 qq00 = _mm_mul_ps(iq0,jq0);
192 /* COULOMB ELECTROSTATICS */
193 velec = _mm_mul_ps(qq00,rinv00);
194 felec = _mm_mul_ps(velec,rinvsq00);
196 /* Update potential sum for this i atom from the interaction with this j atom. */
197 velecsum = _mm_add_ps(velecsum,velec);
201 /* Update vectorial force */
202 fix0 = _mm_macc_ps(dx00,fscal,fix0);
203 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
204 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
206 fjptrA = f+j_coord_offsetA;
207 fjptrB = f+j_coord_offsetB;
208 fjptrC = f+j_coord_offsetC;
209 fjptrD = f+j_coord_offsetD;
210 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
211 _mm_mul_ps(dx00,fscal),
212 _mm_mul_ps(dy00,fscal),
213 _mm_mul_ps(dz00,fscal));
215 /* Inner loop uses 31 flops */
221 /* Get j neighbor index, and coordinate index */
222 jnrlistA = jjnr[jidx];
223 jnrlistB = jjnr[jidx+1];
224 jnrlistC = jjnr[jidx+2];
225 jnrlistD = jjnr[jidx+3];
226 /* Sign of each element will be negative for non-real atoms.
227 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
228 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
230 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
231 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
232 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
233 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
234 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
235 j_coord_offsetA = DIM*jnrA;
236 j_coord_offsetB = DIM*jnrB;
237 j_coord_offsetC = DIM*jnrC;
238 j_coord_offsetD = DIM*jnrD;
240 /* load j atom coordinates */
241 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
242 x+j_coord_offsetC,x+j_coord_offsetD,
245 /* Calculate displacement vector */
246 dx00 = _mm_sub_ps(ix0,jx0);
247 dy00 = _mm_sub_ps(iy0,jy0);
248 dz00 = _mm_sub_ps(iz0,jz0);
250 /* Calculate squared distance and things based on it */
251 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
253 rinv00 = gmx_mm_invsqrt_ps(rsq00);
255 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
257 /* Load parameters for j particles */
258 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
259 charge+jnrC+0,charge+jnrD+0);
261 /**************************
262 * CALCULATE INTERACTIONS *
263 **************************/
265 /* Compute parameters for interactions between i and j atoms */
266 qq00 = _mm_mul_ps(iq0,jq0);
268 /* COULOMB ELECTROSTATICS */
269 velec = _mm_mul_ps(qq00,rinv00);
270 felec = _mm_mul_ps(velec,rinvsq00);
272 /* Update potential sum for this i atom from the interaction with this j atom. */
273 velec = _mm_andnot_ps(dummy_mask,velec);
274 velecsum = _mm_add_ps(velecsum,velec);
278 fscal = _mm_andnot_ps(dummy_mask,fscal);
280 /* Update vectorial force */
281 fix0 = _mm_macc_ps(dx00,fscal,fix0);
282 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
283 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
285 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
286 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
287 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
288 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
289 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
290 _mm_mul_ps(dx00,fscal),
291 _mm_mul_ps(dy00,fscal),
292 _mm_mul_ps(dz00,fscal));
294 /* Inner loop uses 31 flops */
297 /* End of innermost loop */
299 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
300 f+i_coord_offset,fshift+i_shift_offset);
303 /* Update potential energies */
304 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
306 /* Increment number of inner iterations */
307 inneriter += j_index_end - j_index_start;
309 /* Outer loop uses 8 flops */
312 /* Increment number of outer iterations */
315 /* Update outer/inner flops */
317 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*31);
320 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomP1P1_F_avx_128_fma_single
321 * Electrostatics interaction: Coulomb
322 * VdW interaction: None
323 * Geometry: Particle-Particle
324 * Calculate force/pot: Force
327 nb_kernel_ElecCoul_VdwNone_GeomP1P1_F_avx_128_fma_single
328 (t_nblist * gmx_restrict nlist,
329 rvec * gmx_restrict xx,
330 rvec * gmx_restrict ff,
331 t_forcerec * gmx_restrict fr,
332 t_mdatoms * gmx_restrict mdatoms,
333 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
334 t_nrnb * gmx_restrict nrnb)
336 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
337 * just 0 for non-waters.
338 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
339 * jnr indices corresponding to data put in the four positions in the SIMD register.
341 int i_shift_offset,i_coord_offset,outeriter,inneriter;
342 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
343 int jnrA,jnrB,jnrC,jnrD;
344 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
345 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
346 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
348 real *shiftvec,*fshift,*x,*f;
349 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
351 __m128 fscal,rcutoff,rcutoff2,jidxall;
353 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
354 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
355 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
356 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
357 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
359 __m128 dummy_mask,cutoff_mask;
360 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
361 __m128 one = _mm_set1_ps(1.0);
362 __m128 two = _mm_set1_ps(2.0);
368 jindex = nlist->jindex;
370 shiftidx = nlist->shift;
372 shiftvec = fr->shift_vec[0];
373 fshift = fr->fshift[0];
374 facel = _mm_set1_ps(fr->epsfac);
375 charge = mdatoms->chargeA;
377 /* Avoid stupid compiler warnings */
378 jnrA = jnrB = jnrC = jnrD = 0;
387 for(iidx=0;iidx<4*DIM;iidx++)
392 /* Start outer loop over neighborlists */
393 for(iidx=0; iidx<nri; iidx++)
395 /* Load shift vector for this list */
396 i_shift_offset = DIM*shiftidx[iidx];
398 /* Load limits for loop over neighbors */
399 j_index_start = jindex[iidx];
400 j_index_end = jindex[iidx+1];
402 /* Get outer coordinate index */
404 i_coord_offset = DIM*inr;
406 /* Load i particle coords and add shift vector */
407 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
409 fix0 = _mm_setzero_ps();
410 fiy0 = _mm_setzero_ps();
411 fiz0 = _mm_setzero_ps();
413 /* Load parameters for i particles */
414 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
416 /* Start inner kernel loop */
417 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
420 /* Get j neighbor index, and coordinate index */
425 j_coord_offsetA = DIM*jnrA;
426 j_coord_offsetB = DIM*jnrB;
427 j_coord_offsetC = DIM*jnrC;
428 j_coord_offsetD = DIM*jnrD;
430 /* load j atom coordinates */
431 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
432 x+j_coord_offsetC,x+j_coord_offsetD,
435 /* Calculate displacement vector */
436 dx00 = _mm_sub_ps(ix0,jx0);
437 dy00 = _mm_sub_ps(iy0,jy0);
438 dz00 = _mm_sub_ps(iz0,jz0);
440 /* Calculate squared distance and things based on it */
441 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
443 rinv00 = gmx_mm_invsqrt_ps(rsq00);
445 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
447 /* Load parameters for j particles */
448 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
449 charge+jnrC+0,charge+jnrD+0);
451 /**************************
452 * CALCULATE INTERACTIONS *
453 **************************/
455 /* Compute parameters for interactions between i and j atoms */
456 qq00 = _mm_mul_ps(iq0,jq0);
458 /* COULOMB ELECTROSTATICS */
459 velec = _mm_mul_ps(qq00,rinv00);
460 felec = _mm_mul_ps(velec,rinvsq00);
464 /* Update vectorial force */
465 fix0 = _mm_macc_ps(dx00,fscal,fix0);
466 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
467 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
469 fjptrA = f+j_coord_offsetA;
470 fjptrB = f+j_coord_offsetB;
471 fjptrC = f+j_coord_offsetC;
472 fjptrD = f+j_coord_offsetD;
473 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
474 _mm_mul_ps(dx00,fscal),
475 _mm_mul_ps(dy00,fscal),
476 _mm_mul_ps(dz00,fscal));
478 /* Inner loop uses 30 flops */
484 /* Get j neighbor index, and coordinate index */
485 jnrlistA = jjnr[jidx];
486 jnrlistB = jjnr[jidx+1];
487 jnrlistC = jjnr[jidx+2];
488 jnrlistD = jjnr[jidx+3];
489 /* Sign of each element will be negative for non-real atoms.
490 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
491 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
493 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
494 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
495 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
496 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
497 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
498 j_coord_offsetA = DIM*jnrA;
499 j_coord_offsetB = DIM*jnrB;
500 j_coord_offsetC = DIM*jnrC;
501 j_coord_offsetD = DIM*jnrD;
503 /* load j atom coordinates */
504 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
505 x+j_coord_offsetC,x+j_coord_offsetD,
508 /* Calculate displacement vector */
509 dx00 = _mm_sub_ps(ix0,jx0);
510 dy00 = _mm_sub_ps(iy0,jy0);
511 dz00 = _mm_sub_ps(iz0,jz0);
513 /* Calculate squared distance and things based on it */
514 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
516 rinv00 = gmx_mm_invsqrt_ps(rsq00);
518 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
520 /* Load parameters for j particles */
521 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
522 charge+jnrC+0,charge+jnrD+0);
524 /**************************
525 * CALCULATE INTERACTIONS *
526 **************************/
528 /* Compute parameters for interactions between i and j atoms */
529 qq00 = _mm_mul_ps(iq0,jq0);
531 /* COULOMB ELECTROSTATICS */
532 velec = _mm_mul_ps(qq00,rinv00);
533 felec = _mm_mul_ps(velec,rinvsq00);
537 fscal = _mm_andnot_ps(dummy_mask,fscal);
539 /* Update vectorial force */
540 fix0 = _mm_macc_ps(dx00,fscal,fix0);
541 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
542 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
544 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
545 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
546 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
547 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
548 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
549 _mm_mul_ps(dx00,fscal),
550 _mm_mul_ps(dy00,fscal),
551 _mm_mul_ps(dz00,fscal));
553 /* Inner loop uses 30 flops */
556 /* End of innermost loop */
558 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
559 f+i_coord_offset,fshift+i_shift_offset);
561 /* Increment number of inner iterations */
562 inneriter += j_index_end - j_index_start;
564 /* Outer loop uses 7 flops */
567 /* Increment number of outer iterations */
570 /* Update outer/inner flops */
572 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*30);