2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomW4P1_VF_avx_128_fma_single
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: None
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCoul_VdwNone_GeomW4P1_VF_avx_128_fma_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
91 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
92 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
93 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
95 __m128 dummy_mask,cutoff_mask;
96 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
97 __m128 one = _mm_set1_ps(1.0);
98 __m128 two = _mm_set1_ps(2.0);
104 jindex = nlist->jindex;
106 shiftidx = nlist->shift;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm_set1_ps(fr->ic->epsfac);
111 charge = mdatoms->chargeA;
113 /* Setup water-specific parameters */
114 inr = nlist->iinr[0];
115 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
116 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
117 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
119 /* Avoid stupid compiler warnings */
120 jnrA = jnrB = jnrC = jnrD = 0;
129 for(iidx=0;iidx<4*DIM;iidx++)
134 /* Start outer loop over neighborlists */
135 for(iidx=0; iidx<nri; iidx++)
137 /* Load shift vector for this list */
138 i_shift_offset = DIM*shiftidx[iidx];
140 /* Load limits for loop over neighbors */
141 j_index_start = jindex[iidx];
142 j_index_end = jindex[iidx+1];
144 /* Get outer coordinate index */
146 i_coord_offset = DIM*inr;
148 /* Load i particle coords and add shift vector */
149 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
150 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
152 fix1 = _mm_setzero_ps();
153 fiy1 = _mm_setzero_ps();
154 fiz1 = _mm_setzero_ps();
155 fix2 = _mm_setzero_ps();
156 fiy2 = _mm_setzero_ps();
157 fiz2 = _mm_setzero_ps();
158 fix3 = _mm_setzero_ps();
159 fiy3 = _mm_setzero_ps();
160 fiz3 = _mm_setzero_ps();
162 /* Reset potential sums */
163 velecsum = _mm_setzero_ps();
165 /* Start inner kernel loop */
166 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
169 /* Get j neighbor index, and coordinate index */
174 j_coord_offsetA = DIM*jnrA;
175 j_coord_offsetB = DIM*jnrB;
176 j_coord_offsetC = DIM*jnrC;
177 j_coord_offsetD = DIM*jnrD;
179 /* load j atom coordinates */
180 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
181 x+j_coord_offsetC,x+j_coord_offsetD,
184 /* Calculate displacement vector */
185 dx10 = _mm_sub_ps(ix1,jx0);
186 dy10 = _mm_sub_ps(iy1,jy0);
187 dz10 = _mm_sub_ps(iz1,jz0);
188 dx20 = _mm_sub_ps(ix2,jx0);
189 dy20 = _mm_sub_ps(iy2,jy0);
190 dz20 = _mm_sub_ps(iz2,jz0);
191 dx30 = _mm_sub_ps(ix3,jx0);
192 dy30 = _mm_sub_ps(iy3,jy0);
193 dz30 = _mm_sub_ps(iz3,jz0);
195 /* Calculate squared distance and things based on it */
196 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
197 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
198 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
200 rinv10 = avx128fma_invsqrt_f(rsq10);
201 rinv20 = avx128fma_invsqrt_f(rsq20);
202 rinv30 = avx128fma_invsqrt_f(rsq30);
204 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
205 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
206 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
208 /* Load parameters for j particles */
209 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
210 charge+jnrC+0,charge+jnrD+0);
212 fjx0 = _mm_setzero_ps();
213 fjy0 = _mm_setzero_ps();
214 fjz0 = _mm_setzero_ps();
216 /**************************
217 * CALCULATE INTERACTIONS *
218 **************************/
220 /* Compute parameters for interactions between i and j atoms */
221 qq10 = _mm_mul_ps(iq1,jq0);
223 /* COULOMB ELECTROSTATICS */
224 velec = _mm_mul_ps(qq10,rinv10);
225 felec = _mm_mul_ps(velec,rinvsq10);
227 /* Update potential sum for this i atom from the interaction with this j atom. */
228 velecsum = _mm_add_ps(velecsum,velec);
232 /* Update vectorial force */
233 fix1 = _mm_macc_ps(dx10,fscal,fix1);
234 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
235 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
237 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
238 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
239 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
241 /**************************
242 * CALCULATE INTERACTIONS *
243 **************************/
245 /* Compute parameters for interactions between i and j atoms */
246 qq20 = _mm_mul_ps(iq2,jq0);
248 /* COULOMB ELECTROSTATICS */
249 velec = _mm_mul_ps(qq20,rinv20);
250 felec = _mm_mul_ps(velec,rinvsq20);
252 /* Update potential sum for this i atom from the interaction with this j atom. */
253 velecsum = _mm_add_ps(velecsum,velec);
257 /* Update vectorial force */
258 fix2 = _mm_macc_ps(dx20,fscal,fix2);
259 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
260 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
262 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
263 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
264 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
266 /**************************
267 * CALCULATE INTERACTIONS *
268 **************************/
270 /* Compute parameters for interactions between i and j atoms */
271 qq30 = _mm_mul_ps(iq3,jq0);
273 /* COULOMB ELECTROSTATICS */
274 velec = _mm_mul_ps(qq30,rinv30);
275 felec = _mm_mul_ps(velec,rinvsq30);
277 /* Update potential sum for this i atom from the interaction with this j atom. */
278 velecsum = _mm_add_ps(velecsum,velec);
282 /* Update vectorial force */
283 fix3 = _mm_macc_ps(dx30,fscal,fix3);
284 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
285 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
287 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
288 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
289 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
291 fjptrA = f+j_coord_offsetA;
292 fjptrB = f+j_coord_offsetB;
293 fjptrC = f+j_coord_offsetC;
294 fjptrD = f+j_coord_offsetD;
296 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
298 /* Inner loop uses 93 flops */
304 /* Get j neighbor index, and coordinate index */
305 jnrlistA = jjnr[jidx];
306 jnrlistB = jjnr[jidx+1];
307 jnrlistC = jjnr[jidx+2];
308 jnrlistD = jjnr[jidx+3];
309 /* Sign of each element will be negative for non-real atoms.
310 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
311 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
313 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
314 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
315 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
316 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
317 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
318 j_coord_offsetA = DIM*jnrA;
319 j_coord_offsetB = DIM*jnrB;
320 j_coord_offsetC = DIM*jnrC;
321 j_coord_offsetD = DIM*jnrD;
323 /* load j atom coordinates */
324 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
325 x+j_coord_offsetC,x+j_coord_offsetD,
328 /* Calculate displacement vector */
329 dx10 = _mm_sub_ps(ix1,jx0);
330 dy10 = _mm_sub_ps(iy1,jy0);
331 dz10 = _mm_sub_ps(iz1,jz0);
332 dx20 = _mm_sub_ps(ix2,jx0);
333 dy20 = _mm_sub_ps(iy2,jy0);
334 dz20 = _mm_sub_ps(iz2,jz0);
335 dx30 = _mm_sub_ps(ix3,jx0);
336 dy30 = _mm_sub_ps(iy3,jy0);
337 dz30 = _mm_sub_ps(iz3,jz0);
339 /* Calculate squared distance and things based on it */
340 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
341 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
342 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
344 rinv10 = avx128fma_invsqrt_f(rsq10);
345 rinv20 = avx128fma_invsqrt_f(rsq20);
346 rinv30 = avx128fma_invsqrt_f(rsq30);
348 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
349 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
350 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
352 /* Load parameters for j particles */
353 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
354 charge+jnrC+0,charge+jnrD+0);
356 fjx0 = _mm_setzero_ps();
357 fjy0 = _mm_setzero_ps();
358 fjz0 = _mm_setzero_ps();
360 /**************************
361 * CALCULATE INTERACTIONS *
362 **************************/
364 /* Compute parameters for interactions between i and j atoms */
365 qq10 = _mm_mul_ps(iq1,jq0);
367 /* COULOMB ELECTROSTATICS */
368 velec = _mm_mul_ps(qq10,rinv10);
369 felec = _mm_mul_ps(velec,rinvsq10);
371 /* Update potential sum for this i atom from the interaction with this j atom. */
372 velec = _mm_andnot_ps(dummy_mask,velec);
373 velecsum = _mm_add_ps(velecsum,velec);
377 fscal = _mm_andnot_ps(dummy_mask,fscal);
379 /* Update vectorial force */
380 fix1 = _mm_macc_ps(dx10,fscal,fix1);
381 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
382 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
384 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
385 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
386 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
388 /**************************
389 * CALCULATE INTERACTIONS *
390 **************************/
392 /* Compute parameters for interactions between i and j atoms */
393 qq20 = _mm_mul_ps(iq2,jq0);
395 /* COULOMB ELECTROSTATICS */
396 velec = _mm_mul_ps(qq20,rinv20);
397 felec = _mm_mul_ps(velec,rinvsq20);
399 /* Update potential sum for this i atom from the interaction with this j atom. */
400 velec = _mm_andnot_ps(dummy_mask,velec);
401 velecsum = _mm_add_ps(velecsum,velec);
405 fscal = _mm_andnot_ps(dummy_mask,fscal);
407 /* Update vectorial force */
408 fix2 = _mm_macc_ps(dx20,fscal,fix2);
409 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
410 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
412 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
413 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
414 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
416 /**************************
417 * CALCULATE INTERACTIONS *
418 **************************/
420 /* Compute parameters for interactions between i and j atoms */
421 qq30 = _mm_mul_ps(iq3,jq0);
423 /* COULOMB ELECTROSTATICS */
424 velec = _mm_mul_ps(qq30,rinv30);
425 felec = _mm_mul_ps(velec,rinvsq30);
427 /* Update potential sum for this i atom from the interaction with this j atom. */
428 velec = _mm_andnot_ps(dummy_mask,velec);
429 velecsum = _mm_add_ps(velecsum,velec);
433 fscal = _mm_andnot_ps(dummy_mask,fscal);
435 /* Update vectorial force */
436 fix3 = _mm_macc_ps(dx30,fscal,fix3);
437 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
438 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
440 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
441 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
442 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
444 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
445 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
446 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
447 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
449 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
451 /* Inner loop uses 93 flops */
454 /* End of innermost loop */
456 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
457 f+i_coord_offset+DIM,fshift+i_shift_offset);
460 /* Update potential energies */
461 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
463 /* Increment number of inner iterations */
464 inneriter += j_index_end - j_index_start;
466 /* Outer loop uses 19 flops */
469 /* Increment number of outer iterations */
472 /* Update outer/inner flops */
474 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*93);
477 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomW4P1_F_avx_128_fma_single
478 * Electrostatics interaction: Coulomb
479 * VdW interaction: None
480 * Geometry: Water4-Particle
481 * Calculate force/pot: Force
484 nb_kernel_ElecCoul_VdwNone_GeomW4P1_F_avx_128_fma_single
485 (t_nblist * gmx_restrict nlist,
486 rvec * gmx_restrict xx,
487 rvec * gmx_restrict ff,
488 struct t_forcerec * gmx_restrict fr,
489 t_mdatoms * gmx_restrict mdatoms,
490 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
491 t_nrnb * gmx_restrict nrnb)
493 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
494 * just 0 for non-waters.
495 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
496 * jnr indices corresponding to data put in the four positions in the SIMD register.
498 int i_shift_offset,i_coord_offset,outeriter,inneriter;
499 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
500 int jnrA,jnrB,jnrC,jnrD;
501 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
502 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
503 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
505 real *shiftvec,*fshift,*x,*f;
506 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
508 __m128 fscal,rcutoff,rcutoff2,jidxall;
510 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
512 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
514 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
515 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
516 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
517 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
518 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
519 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
520 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
522 __m128 dummy_mask,cutoff_mask;
523 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
524 __m128 one = _mm_set1_ps(1.0);
525 __m128 two = _mm_set1_ps(2.0);
531 jindex = nlist->jindex;
533 shiftidx = nlist->shift;
535 shiftvec = fr->shift_vec[0];
536 fshift = fr->fshift[0];
537 facel = _mm_set1_ps(fr->ic->epsfac);
538 charge = mdatoms->chargeA;
540 /* Setup water-specific parameters */
541 inr = nlist->iinr[0];
542 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
543 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
544 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
546 /* Avoid stupid compiler warnings */
547 jnrA = jnrB = jnrC = jnrD = 0;
556 for(iidx=0;iidx<4*DIM;iidx++)
561 /* Start outer loop over neighborlists */
562 for(iidx=0; iidx<nri; iidx++)
564 /* Load shift vector for this list */
565 i_shift_offset = DIM*shiftidx[iidx];
567 /* Load limits for loop over neighbors */
568 j_index_start = jindex[iidx];
569 j_index_end = jindex[iidx+1];
571 /* Get outer coordinate index */
573 i_coord_offset = DIM*inr;
575 /* Load i particle coords and add shift vector */
576 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
577 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
579 fix1 = _mm_setzero_ps();
580 fiy1 = _mm_setzero_ps();
581 fiz1 = _mm_setzero_ps();
582 fix2 = _mm_setzero_ps();
583 fiy2 = _mm_setzero_ps();
584 fiz2 = _mm_setzero_ps();
585 fix3 = _mm_setzero_ps();
586 fiy3 = _mm_setzero_ps();
587 fiz3 = _mm_setzero_ps();
589 /* Start inner kernel loop */
590 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
593 /* Get j neighbor index, and coordinate index */
598 j_coord_offsetA = DIM*jnrA;
599 j_coord_offsetB = DIM*jnrB;
600 j_coord_offsetC = DIM*jnrC;
601 j_coord_offsetD = DIM*jnrD;
603 /* load j atom coordinates */
604 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
605 x+j_coord_offsetC,x+j_coord_offsetD,
608 /* Calculate displacement vector */
609 dx10 = _mm_sub_ps(ix1,jx0);
610 dy10 = _mm_sub_ps(iy1,jy0);
611 dz10 = _mm_sub_ps(iz1,jz0);
612 dx20 = _mm_sub_ps(ix2,jx0);
613 dy20 = _mm_sub_ps(iy2,jy0);
614 dz20 = _mm_sub_ps(iz2,jz0);
615 dx30 = _mm_sub_ps(ix3,jx0);
616 dy30 = _mm_sub_ps(iy3,jy0);
617 dz30 = _mm_sub_ps(iz3,jz0);
619 /* Calculate squared distance and things based on it */
620 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
621 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
622 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
624 rinv10 = avx128fma_invsqrt_f(rsq10);
625 rinv20 = avx128fma_invsqrt_f(rsq20);
626 rinv30 = avx128fma_invsqrt_f(rsq30);
628 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
629 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
630 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
632 /* Load parameters for j particles */
633 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
634 charge+jnrC+0,charge+jnrD+0);
636 fjx0 = _mm_setzero_ps();
637 fjy0 = _mm_setzero_ps();
638 fjz0 = _mm_setzero_ps();
640 /**************************
641 * CALCULATE INTERACTIONS *
642 **************************/
644 /* Compute parameters for interactions between i and j atoms */
645 qq10 = _mm_mul_ps(iq1,jq0);
647 /* COULOMB ELECTROSTATICS */
648 velec = _mm_mul_ps(qq10,rinv10);
649 felec = _mm_mul_ps(velec,rinvsq10);
653 /* Update vectorial force */
654 fix1 = _mm_macc_ps(dx10,fscal,fix1);
655 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
656 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
658 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
659 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
660 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
662 /**************************
663 * CALCULATE INTERACTIONS *
664 **************************/
666 /* Compute parameters for interactions between i and j atoms */
667 qq20 = _mm_mul_ps(iq2,jq0);
669 /* COULOMB ELECTROSTATICS */
670 velec = _mm_mul_ps(qq20,rinv20);
671 felec = _mm_mul_ps(velec,rinvsq20);
675 /* Update vectorial force */
676 fix2 = _mm_macc_ps(dx20,fscal,fix2);
677 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
678 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
680 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
681 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
682 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
684 /**************************
685 * CALCULATE INTERACTIONS *
686 **************************/
688 /* Compute parameters for interactions between i and j atoms */
689 qq30 = _mm_mul_ps(iq3,jq0);
691 /* COULOMB ELECTROSTATICS */
692 velec = _mm_mul_ps(qq30,rinv30);
693 felec = _mm_mul_ps(velec,rinvsq30);
697 /* Update vectorial force */
698 fix3 = _mm_macc_ps(dx30,fscal,fix3);
699 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
700 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
702 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
703 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
704 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
706 fjptrA = f+j_coord_offsetA;
707 fjptrB = f+j_coord_offsetB;
708 fjptrC = f+j_coord_offsetC;
709 fjptrD = f+j_coord_offsetD;
711 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
713 /* Inner loop uses 90 flops */
719 /* Get j neighbor index, and coordinate index */
720 jnrlistA = jjnr[jidx];
721 jnrlistB = jjnr[jidx+1];
722 jnrlistC = jjnr[jidx+2];
723 jnrlistD = jjnr[jidx+3];
724 /* Sign of each element will be negative for non-real atoms.
725 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
726 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
728 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
729 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
730 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
731 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
732 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
733 j_coord_offsetA = DIM*jnrA;
734 j_coord_offsetB = DIM*jnrB;
735 j_coord_offsetC = DIM*jnrC;
736 j_coord_offsetD = DIM*jnrD;
738 /* load j atom coordinates */
739 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
740 x+j_coord_offsetC,x+j_coord_offsetD,
743 /* Calculate displacement vector */
744 dx10 = _mm_sub_ps(ix1,jx0);
745 dy10 = _mm_sub_ps(iy1,jy0);
746 dz10 = _mm_sub_ps(iz1,jz0);
747 dx20 = _mm_sub_ps(ix2,jx0);
748 dy20 = _mm_sub_ps(iy2,jy0);
749 dz20 = _mm_sub_ps(iz2,jz0);
750 dx30 = _mm_sub_ps(ix3,jx0);
751 dy30 = _mm_sub_ps(iy3,jy0);
752 dz30 = _mm_sub_ps(iz3,jz0);
754 /* Calculate squared distance and things based on it */
755 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
756 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
757 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
759 rinv10 = avx128fma_invsqrt_f(rsq10);
760 rinv20 = avx128fma_invsqrt_f(rsq20);
761 rinv30 = avx128fma_invsqrt_f(rsq30);
763 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
764 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
765 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
767 /* Load parameters for j particles */
768 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
769 charge+jnrC+0,charge+jnrD+0);
771 fjx0 = _mm_setzero_ps();
772 fjy0 = _mm_setzero_ps();
773 fjz0 = _mm_setzero_ps();
775 /**************************
776 * CALCULATE INTERACTIONS *
777 **************************/
779 /* Compute parameters for interactions between i and j atoms */
780 qq10 = _mm_mul_ps(iq1,jq0);
782 /* COULOMB ELECTROSTATICS */
783 velec = _mm_mul_ps(qq10,rinv10);
784 felec = _mm_mul_ps(velec,rinvsq10);
788 fscal = _mm_andnot_ps(dummy_mask,fscal);
790 /* Update vectorial force */
791 fix1 = _mm_macc_ps(dx10,fscal,fix1);
792 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
793 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
795 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
796 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
797 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
799 /**************************
800 * CALCULATE INTERACTIONS *
801 **************************/
803 /* Compute parameters for interactions between i and j atoms */
804 qq20 = _mm_mul_ps(iq2,jq0);
806 /* COULOMB ELECTROSTATICS */
807 velec = _mm_mul_ps(qq20,rinv20);
808 felec = _mm_mul_ps(velec,rinvsq20);
812 fscal = _mm_andnot_ps(dummy_mask,fscal);
814 /* Update vectorial force */
815 fix2 = _mm_macc_ps(dx20,fscal,fix2);
816 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
817 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
819 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
820 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
821 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
823 /**************************
824 * CALCULATE INTERACTIONS *
825 **************************/
827 /* Compute parameters for interactions between i and j atoms */
828 qq30 = _mm_mul_ps(iq3,jq0);
830 /* COULOMB ELECTROSTATICS */
831 velec = _mm_mul_ps(qq30,rinv30);
832 felec = _mm_mul_ps(velec,rinvsq30);
836 fscal = _mm_andnot_ps(dummy_mask,fscal);
838 /* Update vectorial force */
839 fix3 = _mm_macc_ps(dx30,fscal,fix3);
840 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
841 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
843 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
844 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
845 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
847 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
848 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
849 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
850 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
852 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
854 /* Inner loop uses 90 flops */
857 /* End of innermost loop */
859 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
860 f+i_coord_offset+DIM,fshift+i_shift_offset);
862 /* Increment number of inner iterations */
863 inneriter += j_index_end - j_index_start;
865 /* Outer loop uses 18 flops */
868 /* Increment number of outer iterations */
871 /* Update outer/inner flops */
873 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*90);