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_ElecRF_VdwNone_GeomP1P1_VF_avx_128_fma_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRF_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;
107 krf = _mm_set1_ps(fr->ic->k_rf);
108 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
109 crf = _mm_set1_ps(fr->ic->c_rf);
111 /* Avoid stupid compiler warnings */
112 jnrA = jnrB = jnrC = jnrD = 0;
121 for(iidx=0;iidx<4*DIM;iidx++)
126 /* Start outer loop over neighborlists */
127 for(iidx=0; iidx<nri; iidx++)
129 /* Load shift vector for this list */
130 i_shift_offset = DIM*shiftidx[iidx];
132 /* Load limits for loop over neighbors */
133 j_index_start = jindex[iidx];
134 j_index_end = jindex[iidx+1];
136 /* Get outer coordinate index */
138 i_coord_offset = DIM*inr;
140 /* Load i particle coords and add shift vector */
141 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
143 fix0 = _mm_setzero_ps();
144 fiy0 = _mm_setzero_ps();
145 fiz0 = _mm_setzero_ps();
147 /* Load parameters for i particles */
148 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
150 /* Reset potential sums */
151 velecsum = _mm_setzero_ps();
153 /* Start inner kernel loop */
154 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
157 /* Get j neighbor index, and coordinate index */
162 j_coord_offsetA = DIM*jnrA;
163 j_coord_offsetB = DIM*jnrB;
164 j_coord_offsetC = DIM*jnrC;
165 j_coord_offsetD = DIM*jnrD;
167 /* load j atom coordinates */
168 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
169 x+j_coord_offsetC,x+j_coord_offsetD,
172 /* Calculate displacement vector */
173 dx00 = _mm_sub_ps(ix0,jx0);
174 dy00 = _mm_sub_ps(iy0,jy0);
175 dz00 = _mm_sub_ps(iz0,jz0);
177 /* Calculate squared distance and things based on it */
178 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
180 rinv00 = gmx_mm_invsqrt_ps(rsq00);
182 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
184 /* Load parameters for j particles */
185 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
186 charge+jnrC+0,charge+jnrD+0);
188 /**************************
189 * CALCULATE INTERACTIONS *
190 **************************/
192 /* Compute parameters for interactions between i and j atoms */
193 qq00 = _mm_mul_ps(iq0,jq0);
195 /* REACTION-FIELD ELECTROSTATICS */
196 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
197 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
199 /* Update potential sum for this i atom from the interaction with this j atom. */
200 velecsum = _mm_add_ps(velecsum,velec);
204 /* Update vectorial force */
205 fix0 = _mm_macc_ps(dx00,fscal,fix0);
206 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
207 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
209 fjptrA = f+j_coord_offsetA;
210 fjptrB = f+j_coord_offsetB;
211 fjptrC = f+j_coord_offsetC;
212 fjptrD = f+j_coord_offsetD;
213 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
214 _mm_mul_ps(dx00,fscal),
215 _mm_mul_ps(dy00,fscal),
216 _mm_mul_ps(dz00,fscal));
218 /* Inner loop uses 35 flops */
224 /* Get j neighbor index, and coordinate index */
225 jnrlistA = jjnr[jidx];
226 jnrlistB = jjnr[jidx+1];
227 jnrlistC = jjnr[jidx+2];
228 jnrlistD = jjnr[jidx+3];
229 /* Sign of each element will be negative for non-real atoms.
230 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
231 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
233 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
234 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
235 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
236 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
237 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
238 j_coord_offsetA = DIM*jnrA;
239 j_coord_offsetB = DIM*jnrB;
240 j_coord_offsetC = DIM*jnrC;
241 j_coord_offsetD = DIM*jnrD;
243 /* load j atom coordinates */
244 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
245 x+j_coord_offsetC,x+j_coord_offsetD,
248 /* Calculate displacement vector */
249 dx00 = _mm_sub_ps(ix0,jx0);
250 dy00 = _mm_sub_ps(iy0,jy0);
251 dz00 = _mm_sub_ps(iz0,jz0);
253 /* Calculate squared distance and things based on it */
254 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
256 rinv00 = gmx_mm_invsqrt_ps(rsq00);
258 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
260 /* Load parameters for j particles */
261 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
262 charge+jnrC+0,charge+jnrD+0);
264 /**************************
265 * CALCULATE INTERACTIONS *
266 **************************/
268 /* Compute parameters for interactions between i and j atoms */
269 qq00 = _mm_mul_ps(iq0,jq0);
271 /* REACTION-FIELD ELECTROSTATICS */
272 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
273 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
275 /* Update potential sum for this i atom from the interaction with this j atom. */
276 velec = _mm_andnot_ps(dummy_mask,velec);
277 velecsum = _mm_add_ps(velecsum,velec);
281 fscal = _mm_andnot_ps(dummy_mask,fscal);
283 /* Update vectorial force */
284 fix0 = _mm_macc_ps(dx00,fscal,fix0);
285 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
286 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
288 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
289 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
290 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
291 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
292 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
293 _mm_mul_ps(dx00,fscal),
294 _mm_mul_ps(dy00,fscal),
295 _mm_mul_ps(dz00,fscal));
297 /* Inner loop uses 35 flops */
300 /* End of innermost loop */
302 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
303 f+i_coord_offset,fshift+i_shift_offset);
306 /* Update potential energies */
307 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
309 /* Increment number of inner iterations */
310 inneriter += j_index_end - j_index_start;
312 /* Outer loop uses 8 flops */
315 /* Increment number of outer iterations */
318 /* Update outer/inner flops */
320 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*35);
323 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomP1P1_F_avx_128_fma_single
324 * Electrostatics interaction: ReactionField
325 * VdW interaction: None
326 * Geometry: Particle-Particle
327 * Calculate force/pot: Force
330 nb_kernel_ElecRF_VdwNone_GeomP1P1_F_avx_128_fma_single
331 (t_nblist * gmx_restrict nlist,
332 rvec * gmx_restrict xx,
333 rvec * gmx_restrict ff,
334 t_forcerec * gmx_restrict fr,
335 t_mdatoms * gmx_restrict mdatoms,
336 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
337 t_nrnb * gmx_restrict nrnb)
339 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
340 * just 0 for non-waters.
341 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
342 * jnr indices corresponding to data put in the four positions in the SIMD register.
344 int i_shift_offset,i_coord_offset,outeriter,inneriter;
345 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
346 int jnrA,jnrB,jnrC,jnrD;
347 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
348 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
349 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
351 real *shiftvec,*fshift,*x,*f;
352 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
354 __m128 fscal,rcutoff,rcutoff2,jidxall;
356 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
357 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
358 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
359 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
360 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
362 __m128 dummy_mask,cutoff_mask;
363 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
364 __m128 one = _mm_set1_ps(1.0);
365 __m128 two = _mm_set1_ps(2.0);
371 jindex = nlist->jindex;
373 shiftidx = nlist->shift;
375 shiftvec = fr->shift_vec[0];
376 fshift = fr->fshift[0];
377 facel = _mm_set1_ps(fr->epsfac);
378 charge = mdatoms->chargeA;
379 krf = _mm_set1_ps(fr->ic->k_rf);
380 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
381 crf = _mm_set1_ps(fr->ic->c_rf);
383 /* Avoid stupid compiler warnings */
384 jnrA = jnrB = jnrC = jnrD = 0;
393 for(iidx=0;iidx<4*DIM;iidx++)
398 /* Start outer loop over neighborlists */
399 for(iidx=0; iidx<nri; iidx++)
401 /* Load shift vector for this list */
402 i_shift_offset = DIM*shiftidx[iidx];
404 /* Load limits for loop over neighbors */
405 j_index_start = jindex[iidx];
406 j_index_end = jindex[iidx+1];
408 /* Get outer coordinate index */
410 i_coord_offset = DIM*inr;
412 /* Load i particle coords and add shift vector */
413 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
415 fix0 = _mm_setzero_ps();
416 fiy0 = _mm_setzero_ps();
417 fiz0 = _mm_setzero_ps();
419 /* Load parameters for i particles */
420 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
422 /* Start inner kernel loop */
423 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
426 /* Get j neighbor index, and coordinate index */
431 j_coord_offsetA = DIM*jnrA;
432 j_coord_offsetB = DIM*jnrB;
433 j_coord_offsetC = DIM*jnrC;
434 j_coord_offsetD = DIM*jnrD;
436 /* load j atom coordinates */
437 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
438 x+j_coord_offsetC,x+j_coord_offsetD,
441 /* Calculate displacement vector */
442 dx00 = _mm_sub_ps(ix0,jx0);
443 dy00 = _mm_sub_ps(iy0,jy0);
444 dz00 = _mm_sub_ps(iz0,jz0);
446 /* Calculate squared distance and things based on it */
447 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
449 rinv00 = gmx_mm_invsqrt_ps(rsq00);
451 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
453 /* Load parameters for j particles */
454 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
455 charge+jnrC+0,charge+jnrD+0);
457 /**************************
458 * CALCULATE INTERACTIONS *
459 **************************/
461 /* Compute parameters for interactions between i and j atoms */
462 qq00 = _mm_mul_ps(iq0,jq0);
464 /* REACTION-FIELD ELECTROSTATICS */
465 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
469 /* Update vectorial force */
470 fix0 = _mm_macc_ps(dx00,fscal,fix0);
471 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
472 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
474 fjptrA = f+j_coord_offsetA;
475 fjptrB = f+j_coord_offsetB;
476 fjptrC = f+j_coord_offsetC;
477 fjptrD = f+j_coord_offsetD;
478 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
479 _mm_mul_ps(dx00,fscal),
480 _mm_mul_ps(dy00,fscal),
481 _mm_mul_ps(dz00,fscal));
483 /* Inner loop uses 30 flops */
489 /* Get j neighbor index, and coordinate index */
490 jnrlistA = jjnr[jidx];
491 jnrlistB = jjnr[jidx+1];
492 jnrlistC = jjnr[jidx+2];
493 jnrlistD = jjnr[jidx+3];
494 /* Sign of each element will be negative for non-real atoms.
495 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
496 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
498 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
499 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
500 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
501 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
502 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
503 j_coord_offsetA = DIM*jnrA;
504 j_coord_offsetB = DIM*jnrB;
505 j_coord_offsetC = DIM*jnrC;
506 j_coord_offsetD = DIM*jnrD;
508 /* load j atom coordinates */
509 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
510 x+j_coord_offsetC,x+j_coord_offsetD,
513 /* Calculate displacement vector */
514 dx00 = _mm_sub_ps(ix0,jx0);
515 dy00 = _mm_sub_ps(iy0,jy0);
516 dz00 = _mm_sub_ps(iz0,jz0);
518 /* Calculate squared distance and things based on it */
519 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
521 rinv00 = gmx_mm_invsqrt_ps(rsq00);
523 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
525 /* Load parameters for j particles */
526 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
527 charge+jnrC+0,charge+jnrD+0);
529 /**************************
530 * CALCULATE INTERACTIONS *
531 **************************/
533 /* Compute parameters for interactions between i and j atoms */
534 qq00 = _mm_mul_ps(iq0,jq0);
536 /* REACTION-FIELD ELECTROSTATICS */
537 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
541 fscal = _mm_andnot_ps(dummy_mask,fscal);
543 /* Update vectorial force */
544 fix0 = _mm_macc_ps(dx00,fscal,fix0);
545 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
546 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
548 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
549 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
550 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
551 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
552 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
553 _mm_mul_ps(dx00,fscal),
554 _mm_mul_ps(dy00,fscal),
555 _mm_mul_ps(dz00,fscal));
557 /* Inner loop uses 30 flops */
560 /* End of innermost loop */
562 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
563 f+i_coord_offset,fshift+i_shift_offset);
565 /* Increment number of inner iterations */
566 inneriter += j_index_end - j_index_start;
568 /* Outer loop uses 7 flops */
571 /* Increment number of outer iterations */
574 /* Update outer/inner flops */
576 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*30);