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 "types/simple.h"
46 #include "gromacs/math/vec.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_ElecCoul_VdwNone_GeomP1P1_VF_avx_128_fma_single
54 * Electrostatics interaction: Coulomb
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecCoul_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;
110 /* Avoid stupid compiler warnings */
111 jnrA = jnrB = jnrC = jnrD = 0;
120 for(iidx=0;iidx<4*DIM;iidx++)
125 /* Start outer loop over neighborlists */
126 for(iidx=0; iidx<nri; iidx++)
128 /* Load shift vector for this list */
129 i_shift_offset = DIM*shiftidx[iidx];
131 /* Load limits for loop over neighbors */
132 j_index_start = jindex[iidx];
133 j_index_end = jindex[iidx+1];
135 /* Get outer coordinate index */
137 i_coord_offset = DIM*inr;
139 /* Load i particle coords and add shift vector */
140 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
142 fix0 = _mm_setzero_ps();
143 fiy0 = _mm_setzero_ps();
144 fiz0 = _mm_setzero_ps();
146 /* Load parameters for i particles */
147 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
149 /* Reset potential sums */
150 velecsum = _mm_setzero_ps();
152 /* Start inner kernel loop */
153 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
156 /* Get j neighbor index, and coordinate index */
161 j_coord_offsetA = DIM*jnrA;
162 j_coord_offsetB = DIM*jnrB;
163 j_coord_offsetC = DIM*jnrC;
164 j_coord_offsetD = DIM*jnrD;
166 /* load j atom coordinates */
167 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
168 x+j_coord_offsetC,x+j_coord_offsetD,
171 /* Calculate displacement vector */
172 dx00 = _mm_sub_ps(ix0,jx0);
173 dy00 = _mm_sub_ps(iy0,jy0);
174 dz00 = _mm_sub_ps(iz0,jz0);
176 /* Calculate squared distance and things based on it */
177 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
179 rinv00 = gmx_mm_invsqrt_ps(rsq00);
181 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
183 /* Load parameters for j particles */
184 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
185 charge+jnrC+0,charge+jnrD+0);
187 /**************************
188 * CALCULATE INTERACTIONS *
189 **************************/
191 /* Compute parameters for interactions between i and j atoms */
192 qq00 = _mm_mul_ps(iq0,jq0);
194 /* COULOMB ELECTROSTATICS */
195 velec = _mm_mul_ps(qq00,rinv00);
196 felec = _mm_mul_ps(velec,rinvsq00);
198 /* Update potential sum for this i atom from the interaction with this j atom. */
199 velecsum = _mm_add_ps(velecsum,velec);
203 /* Update vectorial force */
204 fix0 = _mm_macc_ps(dx00,fscal,fix0);
205 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
206 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
208 fjptrA = f+j_coord_offsetA;
209 fjptrB = f+j_coord_offsetB;
210 fjptrC = f+j_coord_offsetC;
211 fjptrD = f+j_coord_offsetD;
212 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
213 _mm_mul_ps(dx00,fscal),
214 _mm_mul_ps(dy00,fscal),
215 _mm_mul_ps(dz00,fscal));
217 /* Inner loop uses 31 flops */
223 /* Get j neighbor index, and coordinate index */
224 jnrlistA = jjnr[jidx];
225 jnrlistB = jjnr[jidx+1];
226 jnrlistC = jjnr[jidx+2];
227 jnrlistD = jjnr[jidx+3];
228 /* Sign of each element will be negative for non-real atoms.
229 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
230 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
232 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
233 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
234 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
235 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
236 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
237 j_coord_offsetA = DIM*jnrA;
238 j_coord_offsetB = DIM*jnrB;
239 j_coord_offsetC = DIM*jnrC;
240 j_coord_offsetD = DIM*jnrD;
242 /* load j atom coordinates */
243 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
244 x+j_coord_offsetC,x+j_coord_offsetD,
247 /* Calculate displacement vector */
248 dx00 = _mm_sub_ps(ix0,jx0);
249 dy00 = _mm_sub_ps(iy0,jy0);
250 dz00 = _mm_sub_ps(iz0,jz0);
252 /* Calculate squared distance and things based on it */
253 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
255 rinv00 = gmx_mm_invsqrt_ps(rsq00);
257 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
259 /* Load parameters for j particles */
260 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
261 charge+jnrC+0,charge+jnrD+0);
263 /**************************
264 * CALCULATE INTERACTIONS *
265 **************************/
267 /* Compute parameters for interactions between i and j atoms */
268 qq00 = _mm_mul_ps(iq0,jq0);
270 /* COULOMB ELECTROSTATICS */
271 velec = _mm_mul_ps(qq00,rinv00);
272 felec = _mm_mul_ps(velec,rinvsq00);
274 /* Update potential sum for this i atom from the interaction with this j atom. */
275 velec = _mm_andnot_ps(dummy_mask,velec);
276 velecsum = _mm_add_ps(velecsum,velec);
280 fscal = _mm_andnot_ps(dummy_mask,fscal);
282 /* Update vectorial force */
283 fix0 = _mm_macc_ps(dx00,fscal,fix0);
284 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
285 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
287 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
288 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
289 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
290 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
291 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
292 _mm_mul_ps(dx00,fscal),
293 _mm_mul_ps(dy00,fscal),
294 _mm_mul_ps(dz00,fscal));
296 /* Inner loop uses 31 flops */
299 /* End of innermost loop */
301 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
302 f+i_coord_offset,fshift+i_shift_offset);
305 /* Update potential energies */
306 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
308 /* Increment number of inner iterations */
309 inneriter += j_index_end - j_index_start;
311 /* Outer loop uses 8 flops */
314 /* Increment number of outer iterations */
317 /* Update outer/inner flops */
319 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*31);
322 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomP1P1_F_avx_128_fma_single
323 * Electrostatics interaction: Coulomb
324 * VdW interaction: None
325 * Geometry: Particle-Particle
326 * Calculate force/pot: Force
329 nb_kernel_ElecCoul_VdwNone_GeomP1P1_F_avx_128_fma_single
330 (t_nblist * gmx_restrict nlist,
331 rvec * gmx_restrict xx,
332 rvec * gmx_restrict ff,
333 t_forcerec * gmx_restrict fr,
334 t_mdatoms * gmx_restrict mdatoms,
335 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
336 t_nrnb * gmx_restrict nrnb)
338 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
339 * just 0 for non-waters.
340 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
341 * jnr indices corresponding to data put in the four positions in the SIMD register.
343 int i_shift_offset,i_coord_offset,outeriter,inneriter;
344 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
345 int jnrA,jnrB,jnrC,jnrD;
346 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
347 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
348 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
350 real *shiftvec,*fshift,*x,*f;
351 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
353 __m128 fscal,rcutoff,rcutoff2,jidxall;
355 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
356 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
357 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
358 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
359 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
361 __m128 dummy_mask,cutoff_mask;
362 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
363 __m128 one = _mm_set1_ps(1.0);
364 __m128 two = _mm_set1_ps(2.0);
370 jindex = nlist->jindex;
372 shiftidx = nlist->shift;
374 shiftvec = fr->shift_vec[0];
375 fshift = fr->fshift[0];
376 facel = _mm_set1_ps(fr->epsfac);
377 charge = mdatoms->chargeA;
379 /* Avoid stupid compiler warnings */
380 jnrA = jnrB = jnrC = jnrD = 0;
389 for(iidx=0;iidx<4*DIM;iidx++)
394 /* Start outer loop over neighborlists */
395 for(iidx=0; iidx<nri; iidx++)
397 /* Load shift vector for this list */
398 i_shift_offset = DIM*shiftidx[iidx];
400 /* Load limits for loop over neighbors */
401 j_index_start = jindex[iidx];
402 j_index_end = jindex[iidx+1];
404 /* Get outer coordinate index */
406 i_coord_offset = DIM*inr;
408 /* Load i particle coords and add shift vector */
409 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
411 fix0 = _mm_setzero_ps();
412 fiy0 = _mm_setzero_ps();
413 fiz0 = _mm_setzero_ps();
415 /* Load parameters for i particles */
416 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
418 /* Start inner kernel loop */
419 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
422 /* Get j neighbor index, and coordinate index */
427 j_coord_offsetA = DIM*jnrA;
428 j_coord_offsetB = DIM*jnrB;
429 j_coord_offsetC = DIM*jnrC;
430 j_coord_offsetD = DIM*jnrD;
432 /* load j atom coordinates */
433 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
434 x+j_coord_offsetC,x+j_coord_offsetD,
437 /* Calculate displacement vector */
438 dx00 = _mm_sub_ps(ix0,jx0);
439 dy00 = _mm_sub_ps(iy0,jy0);
440 dz00 = _mm_sub_ps(iz0,jz0);
442 /* Calculate squared distance and things based on it */
443 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
445 rinv00 = gmx_mm_invsqrt_ps(rsq00);
447 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
449 /* Load parameters for j particles */
450 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
451 charge+jnrC+0,charge+jnrD+0);
453 /**************************
454 * CALCULATE INTERACTIONS *
455 **************************/
457 /* Compute parameters for interactions between i and j atoms */
458 qq00 = _mm_mul_ps(iq0,jq0);
460 /* COULOMB ELECTROSTATICS */
461 velec = _mm_mul_ps(qq00,rinv00);
462 felec = _mm_mul_ps(velec,rinvsq00);
466 /* Update vectorial force */
467 fix0 = _mm_macc_ps(dx00,fscal,fix0);
468 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
469 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
471 fjptrA = f+j_coord_offsetA;
472 fjptrB = f+j_coord_offsetB;
473 fjptrC = f+j_coord_offsetC;
474 fjptrD = f+j_coord_offsetD;
475 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
476 _mm_mul_ps(dx00,fscal),
477 _mm_mul_ps(dy00,fscal),
478 _mm_mul_ps(dz00,fscal));
480 /* Inner loop uses 30 flops */
486 /* Get j neighbor index, and coordinate index */
487 jnrlistA = jjnr[jidx];
488 jnrlistB = jjnr[jidx+1];
489 jnrlistC = jjnr[jidx+2];
490 jnrlistD = jjnr[jidx+3];
491 /* Sign of each element will be negative for non-real atoms.
492 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
493 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
495 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
496 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
497 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
498 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
499 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
500 j_coord_offsetA = DIM*jnrA;
501 j_coord_offsetB = DIM*jnrB;
502 j_coord_offsetC = DIM*jnrC;
503 j_coord_offsetD = DIM*jnrD;
505 /* load j atom coordinates */
506 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
507 x+j_coord_offsetC,x+j_coord_offsetD,
510 /* Calculate displacement vector */
511 dx00 = _mm_sub_ps(ix0,jx0);
512 dy00 = _mm_sub_ps(iy0,jy0);
513 dz00 = _mm_sub_ps(iz0,jz0);
515 /* Calculate squared distance and things based on it */
516 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
518 rinv00 = gmx_mm_invsqrt_ps(rsq00);
520 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
522 /* Load parameters for j particles */
523 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
524 charge+jnrC+0,charge+jnrD+0);
526 /**************************
527 * CALCULATE INTERACTIONS *
528 **************************/
530 /* Compute parameters for interactions between i and j atoms */
531 qq00 = _mm_mul_ps(iq0,jq0);
533 /* COULOMB ELECTROSTATICS */
534 velec = _mm_mul_ps(qq00,rinv00);
535 felec = _mm_mul_ps(velec,rinvsq00);
539 fscal = _mm_andnot_ps(dummy_mask,fscal);
541 /* Update vectorial force */
542 fix0 = _mm_macc_ps(dx00,fscal,fix0);
543 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
544 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
546 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
547 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
548 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
549 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
550 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
551 _mm_mul_ps(dx00,fscal),
552 _mm_mul_ps(dy00,fscal),
553 _mm_mul_ps(dz00,fscal));
555 /* Inner loop uses 30 flops */
558 /* End of innermost loop */
560 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
561 f+i_coord_offset,fshift+i_shift_offset);
563 /* Increment number of inner iterations */
564 inneriter += j_index_end - j_index_start;
566 /* Outer loop uses 7 flops */
569 /* Increment number of outer iterations */
572 /* Update outer/inner flops */
574 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*30);