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_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: None
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_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 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
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;
112 krf = _mm_set1_ps(fr->ic->k_rf);
113 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
114 crf = _mm_set1_ps(fr->ic->c_rf);
116 /* Setup water-specific parameters */
117 inr = nlist->iinr[0];
118 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
119 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
120 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
122 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
123 rcutoff_scalar = fr->ic->rcoulomb;
124 rcutoff = _mm_set1_ps(rcutoff_scalar);
125 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
127 /* Avoid stupid compiler warnings */
128 jnrA = jnrB = jnrC = jnrD = 0;
137 for(iidx=0;iidx<4*DIM;iidx++)
142 /* Start outer loop over neighborlists */
143 for(iidx=0; iidx<nri; iidx++)
145 /* Load shift vector for this list */
146 i_shift_offset = DIM*shiftidx[iidx];
148 /* Load limits for loop over neighbors */
149 j_index_start = jindex[iidx];
150 j_index_end = jindex[iidx+1];
152 /* Get outer coordinate index */
154 i_coord_offset = DIM*inr;
156 /* Load i particle coords and add shift vector */
157 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
158 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
160 fix0 = _mm_setzero_ps();
161 fiy0 = _mm_setzero_ps();
162 fiz0 = _mm_setzero_ps();
163 fix1 = _mm_setzero_ps();
164 fiy1 = _mm_setzero_ps();
165 fiz1 = _mm_setzero_ps();
166 fix2 = _mm_setzero_ps();
167 fiy2 = _mm_setzero_ps();
168 fiz2 = _mm_setzero_ps();
170 /* Reset potential sums */
171 velecsum = _mm_setzero_ps();
173 /* Start inner kernel loop */
174 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
177 /* Get j neighbor index, and coordinate index */
182 j_coord_offsetA = DIM*jnrA;
183 j_coord_offsetB = DIM*jnrB;
184 j_coord_offsetC = DIM*jnrC;
185 j_coord_offsetD = DIM*jnrD;
187 /* load j atom coordinates */
188 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
189 x+j_coord_offsetC,x+j_coord_offsetD,
192 /* Calculate displacement vector */
193 dx00 = _mm_sub_ps(ix0,jx0);
194 dy00 = _mm_sub_ps(iy0,jy0);
195 dz00 = _mm_sub_ps(iz0,jz0);
196 dx10 = _mm_sub_ps(ix1,jx0);
197 dy10 = _mm_sub_ps(iy1,jy0);
198 dz10 = _mm_sub_ps(iz1,jz0);
199 dx20 = _mm_sub_ps(ix2,jx0);
200 dy20 = _mm_sub_ps(iy2,jy0);
201 dz20 = _mm_sub_ps(iz2,jz0);
203 /* Calculate squared distance and things based on it */
204 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
205 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
206 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
208 rinv00 = avx128fma_invsqrt_f(rsq00);
209 rinv10 = avx128fma_invsqrt_f(rsq10);
210 rinv20 = avx128fma_invsqrt_f(rsq20);
212 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
213 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
214 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
216 /* Load parameters for j particles */
217 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
218 charge+jnrC+0,charge+jnrD+0);
220 fjx0 = _mm_setzero_ps();
221 fjy0 = _mm_setzero_ps();
222 fjz0 = _mm_setzero_ps();
224 /**************************
225 * CALCULATE INTERACTIONS *
226 **************************/
228 if (gmx_mm_any_lt(rsq00,rcutoff2))
231 /* Compute parameters for interactions between i and j atoms */
232 qq00 = _mm_mul_ps(iq0,jq0);
234 /* REACTION-FIELD ELECTROSTATICS */
235 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
236 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
238 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
240 /* Update potential sum for this i atom from the interaction with this j atom. */
241 velec = _mm_and_ps(velec,cutoff_mask);
242 velecsum = _mm_add_ps(velecsum,velec);
246 fscal = _mm_and_ps(fscal,cutoff_mask);
248 /* Update vectorial force */
249 fix0 = _mm_macc_ps(dx00,fscal,fix0);
250 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
251 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
253 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
254 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
255 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
259 /**************************
260 * CALCULATE INTERACTIONS *
261 **************************/
263 if (gmx_mm_any_lt(rsq10,rcutoff2))
266 /* Compute parameters for interactions between i and j atoms */
267 qq10 = _mm_mul_ps(iq1,jq0);
269 /* REACTION-FIELD ELECTROSTATICS */
270 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
271 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
273 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
275 /* Update potential sum for this i atom from the interaction with this j atom. */
276 velec = _mm_and_ps(velec,cutoff_mask);
277 velecsum = _mm_add_ps(velecsum,velec);
281 fscal = _mm_and_ps(fscal,cutoff_mask);
283 /* Update vectorial force */
284 fix1 = _mm_macc_ps(dx10,fscal,fix1);
285 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
286 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
288 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
289 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
290 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
294 /**************************
295 * CALCULATE INTERACTIONS *
296 **************************/
298 if (gmx_mm_any_lt(rsq20,rcutoff2))
301 /* Compute parameters for interactions between i and j atoms */
302 qq20 = _mm_mul_ps(iq2,jq0);
304 /* REACTION-FIELD ELECTROSTATICS */
305 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
306 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
308 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
310 /* Update potential sum for this i atom from the interaction with this j atom. */
311 velec = _mm_and_ps(velec,cutoff_mask);
312 velecsum = _mm_add_ps(velecsum,velec);
316 fscal = _mm_and_ps(fscal,cutoff_mask);
318 /* Update vectorial force */
319 fix2 = _mm_macc_ps(dx20,fscal,fix2);
320 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
321 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
323 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
324 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
325 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
329 fjptrA = f+j_coord_offsetA;
330 fjptrB = f+j_coord_offsetB;
331 fjptrC = f+j_coord_offsetC;
332 fjptrD = f+j_coord_offsetD;
334 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
336 /* Inner loop uses 117 flops */
342 /* Get j neighbor index, and coordinate index */
343 jnrlistA = jjnr[jidx];
344 jnrlistB = jjnr[jidx+1];
345 jnrlistC = jjnr[jidx+2];
346 jnrlistD = jjnr[jidx+3];
347 /* Sign of each element will be negative for non-real atoms.
348 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
349 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
351 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
352 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
353 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
354 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
355 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
356 j_coord_offsetA = DIM*jnrA;
357 j_coord_offsetB = DIM*jnrB;
358 j_coord_offsetC = DIM*jnrC;
359 j_coord_offsetD = DIM*jnrD;
361 /* load j atom coordinates */
362 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
363 x+j_coord_offsetC,x+j_coord_offsetD,
366 /* Calculate displacement vector */
367 dx00 = _mm_sub_ps(ix0,jx0);
368 dy00 = _mm_sub_ps(iy0,jy0);
369 dz00 = _mm_sub_ps(iz0,jz0);
370 dx10 = _mm_sub_ps(ix1,jx0);
371 dy10 = _mm_sub_ps(iy1,jy0);
372 dz10 = _mm_sub_ps(iz1,jz0);
373 dx20 = _mm_sub_ps(ix2,jx0);
374 dy20 = _mm_sub_ps(iy2,jy0);
375 dz20 = _mm_sub_ps(iz2,jz0);
377 /* Calculate squared distance and things based on it */
378 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
379 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
380 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
382 rinv00 = avx128fma_invsqrt_f(rsq00);
383 rinv10 = avx128fma_invsqrt_f(rsq10);
384 rinv20 = avx128fma_invsqrt_f(rsq20);
386 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
387 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
388 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
390 /* Load parameters for j particles */
391 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
392 charge+jnrC+0,charge+jnrD+0);
394 fjx0 = _mm_setzero_ps();
395 fjy0 = _mm_setzero_ps();
396 fjz0 = _mm_setzero_ps();
398 /**************************
399 * CALCULATE INTERACTIONS *
400 **************************/
402 if (gmx_mm_any_lt(rsq00,rcutoff2))
405 /* Compute parameters for interactions between i and j atoms */
406 qq00 = _mm_mul_ps(iq0,jq0);
408 /* REACTION-FIELD ELECTROSTATICS */
409 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
410 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
412 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
414 /* Update potential sum for this i atom from the interaction with this j atom. */
415 velec = _mm_and_ps(velec,cutoff_mask);
416 velec = _mm_andnot_ps(dummy_mask,velec);
417 velecsum = _mm_add_ps(velecsum,velec);
421 fscal = _mm_and_ps(fscal,cutoff_mask);
423 fscal = _mm_andnot_ps(dummy_mask,fscal);
425 /* Update vectorial force */
426 fix0 = _mm_macc_ps(dx00,fscal,fix0);
427 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
428 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
430 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
431 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
432 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
436 /**************************
437 * CALCULATE INTERACTIONS *
438 **************************/
440 if (gmx_mm_any_lt(rsq10,rcutoff2))
443 /* Compute parameters for interactions between i and j atoms */
444 qq10 = _mm_mul_ps(iq1,jq0);
446 /* REACTION-FIELD ELECTROSTATICS */
447 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
448 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
450 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
452 /* Update potential sum for this i atom from the interaction with this j atom. */
453 velec = _mm_and_ps(velec,cutoff_mask);
454 velec = _mm_andnot_ps(dummy_mask,velec);
455 velecsum = _mm_add_ps(velecsum,velec);
459 fscal = _mm_and_ps(fscal,cutoff_mask);
461 fscal = _mm_andnot_ps(dummy_mask,fscal);
463 /* Update vectorial force */
464 fix1 = _mm_macc_ps(dx10,fscal,fix1);
465 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
466 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
468 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
469 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
470 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
474 /**************************
475 * CALCULATE INTERACTIONS *
476 **************************/
478 if (gmx_mm_any_lt(rsq20,rcutoff2))
481 /* Compute parameters for interactions between i and j atoms */
482 qq20 = _mm_mul_ps(iq2,jq0);
484 /* REACTION-FIELD ELECTROSTATICS */
485 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
486 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
488 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
490 /* Update potential sum for this i atom from the interaction with this j atom. */
491 velec = _mm_and_ps(velec,cutoff_mask);
492 velec = _mm_andnot_ps(dummy_mask,velec);
493 velecsum = _mm_add_ps(velecsum,velec);
497 fscal = _mm_and_ps(fscal,cutoff_mask);
499 fscal = _mm_andnot_ps(dummy_mask,fscal);
501 /* Update vectorial force */
502 fix2 = _mm_macc_ps(dx20,fscal,fix2);
503 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
504 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
506 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
507 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
508 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
512 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
513 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
514 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
515 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
517 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
519 /* Inner loop uses 117 flops */
522 /* End of innermost loop */
524 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
525 f+i_coord_offset,fshift+i_shift_offset);
528 /* Update potential energies */
529 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
531 /* Increment number of inner iterations */
532 inneriter += j_index_end - j_index_start;
534 /* Outer loop uses 19 flops */
537 /* Increment number of outer iterations */
540 /* Update outer/inner flops */
542 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*117);
545 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
546 * Electrostatics interaction: ReactionField
547 * VdW interaction: None
548 * Geometry: Water3-Particle
549 * Calculate force/pot: Force
552 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
553 (t_nblist * gmx_restrict nlist,
554 rvec * gmx_restrict xx,
555 rvec * gmx_restrict ff,
556 struct t_forcerec * gmx_restrict fr,
557 t_mdatoms * gmx_restrict mdatoms,
558 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
559 t_nrnb * gmx_restrict nrnb)
561 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
562 * just 0 for non-waters.
563 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
564 * jnr indices corresponding to data put in the four positions in the SIMD register.
566 int i_shift_offset,i_coord_offset,outeriter,inneriter;
567 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
568 int jnrA,jnrB,jnrC,jnrD;
569 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
570 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
571 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
573 real *shiftvec,*fshift,*x,*f;
574 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
576 __m128 fscal,rcutoff,rcutoff2,jidxall;
578 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
580 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
582 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
583 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
584 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
585 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
586 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
587 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
588 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
590 __m128 dummy_mask,cutoff_mask;
591 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
592 __m128 one = _mm_set1_ps(1.0);
593 __m128 two = _mm_set1_ps(2.0);
599 jindex = nlist->jindex;
601 shiftidx = nlist->shift;
603 shiftvec = fr->shift_vec[0];
604 fshift = fr->fshift[0];
605 facel = _mm_set1_ps(fr->ic->epsfac);
606 charge = mdatoms->chargeA;
607 krf = _mm_set1_ps(fr->ic->k_rf);
608 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
609 crf = _mm_set1_ps(fr->ic->c_rf);
611 /* Setup water-specific parameters */
612 inr = nlist->iinr[0];
613 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
614 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
615 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
617 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
618 rcutoff_scalar = fr->ic->rcoulomb;
619 rcutoff = _mm_set1_ps(rcutoff_scalar);
620 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
622 /* Avoid stupid compiler warnings */
623 jnrA = jnrB = jnrC = jnrD = 0;
632 for(iidx=0;iidx<4*DIM;iidx++)
637 /* Start outer loop over neighborlists */
638 for(iidx=0; iidx<nri; iidx++)
640 /* Load shift vector for this list */
641 i_shift_offset = DIM*shiftidx[iidx];
643 /* Load limits for loop over neighbors */
644 j_index_start = jindex[iidx];
645 j_index_end = jindex[iidx+1];
647 /* Get outer coordinate index */
649 i_coord_offset = DIM*inr;
651 /* Load i particle coords and add shift vector */
652 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
653 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
655 fix0 = _mm_setzero_ps();
656 fiy0 = _mm_setzero_ps();
657 fiz0 = _mm_setzero_ps();
658 fix1 = _mm_setzero_ps();
659 fiy1 = _mm_setzero_ps();
660 fiz1 = _mm_setzero_ps();
661 fix2 = _mm_setzero_ps();
662 fiy2 = _mm_setzero_ps();
663 fiz2 = _mm_setzero_ps();
665 /* Start inner kernel loop */
666 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
669 /* Get j neighbor index, and coordinate index */
674 j_coord_offsetA = DIM*jnrA;
675 j_coord_offsetB = DIM*jnrB;
676 j_coord_offsetC = DIM*jnrC;
677 j_coord_offsetD = DIM*jnrD;
679 /* load j atom coordinates */
680 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
681 x+j_coord_offsetC,x+j_coord_offsetD,
684 /* Calculate displacement vector */
685 dx00 = _mm_sub_ps(ix0,jx0);
686 dy00 = _mm_sub_ps(iy0,jy0);
687 dz00 = _mm_sub_ps(iz0,jz0);
688 dx10 = _mm_sub_ps(ix1,jx0);
689 dy10 = _mm_sub_ps(iy1,jy0);
690 dz10 = _mm_sub_ps(iz1,jz0);
691 dx20 = _mm_sub_ps(ix2,jx0);
692 dy20 = _mm_sub_ps(iy2,jy0);
693 dz20 = _mm_sub_ps(iz2,jz0);
695 /* Calculate squared distance and things based on it */
696 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
697 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
698 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
700 rinv00 = avx128fma_invsqrt_f(rsq00);
701 rinv10 = avx128fma_invsqrt_f(rsq10);
702 rinv20 = avx128fma_invsqrt_f(rsq20);
704 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
705 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
706 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
708 /* Load parameters for j particles */
709 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
710 charge+jnrC+0,charge+jnrD+0);
712 fjx0 = _mm_setzero_ps();
713 fjy0 = _mm_setzero_ps();
714 fjz0 = _mm_setzero_ps();
716 /**************************
717 * CALCULATE INTERACTIONS *
718 **************************/
720 if (gmx_mm_any_lt(rsq00,rcutoff2))
723 /* Compute parameters for interactions between i and j atoms */
724 qq00 = _mm_mul_ps(iq0,jq0);
726 /* REACTION-FIELD ELECTROSTATICS */
727 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
729 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
733 fscal = _mm_and_ps(fscal,cutoff_mask);
735 /* Update vectorial force */
736 fix0 = _mm_macc_ps(dx00,fscal,fix0);
737 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
738 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
740 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
741 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
742 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
746 /**************************
747 * CALCULATE INTERACTIONS *
748 **************************/
750 if (gmx_mm_any_lt(rsq10,rcutoff2))
753 /* Compute parameters for interactions between i and j atoms */
754 qq10 = _mm_mul_ps(iq1,jq0);
756 /* REACTION-FIELD ELECTROSTATICS */
757 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
759 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
763 fscal = _mm_and_ps(fscal,cutoff_mask);
765 /* Update vectorial force */
766 fix1 = _mm_macc_ps(dx10,fscal,fix1);
767 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
768 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
770 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
771 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
772 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
776 /**************************
777 * CALCULATE INTERACTIONS *
778 **************************/
780 if (gmx_mm_any_lt(rsq20,rcutoff2))
783 /* Compute parameters for interactions between i and j atoms */
784 qq20 = _mm_mul_ps(iq2,jq0);
786 /* REACTION-FIELD ELECTROSTATICS */
787 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
789 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
793 fscal = _mm_and_ps(fscal,cutoff_mask);
795 /* Update vectorial force */
796 fix2 = _mm_macc_ps(dx20,fscal,fix2);
797 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
798 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
800 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
801 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
802 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
806 fjptrA = f+j_coord_offsetA;
807 fjptrB = f+j_coord_offsetB;
808 fjptrC = f+j_coord_offsetC;
809 fjptrD = f+j_coord_offsetD;
811 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
813 /* Inner loop uses 99 flops */
819 /* Get j neighbor index, and coordinate index */
820 jnrlistA = jjnr[jidx];
821 jnrlistB = jjnr[jidx+1];
822 jnrlistC = jjnr[jidx+2];
823 jnrlistD = jjnr[jidx+3];
824 /* Sign of each element will be negative for non-real atoms.
825 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
826 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
828 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
829 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
830 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
831 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
832 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
833 j_coord_offsetA = DIM*jnrA;
834 j_coord_offsetB = DIM*jnrB;
835 j_coord_offsetC = DIM*jnrC;
836 j_coord_offsetD = DIM*jnrD;
838 /* load j atom coordinates */
839 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
840 x+j_coord_offsetC,x+j_coord_offsetD,
843 /* Calculate displacement vector */
844 dx00 = _mm_sub_ps(ix0,jx0);
845 dy00 = _mm_sub_ps(iy0,jy0);
846 dz00 = _mm_sub_ps(iz0,jz0);
847 dx10 = _mm_sub_ps(ix1,jx0);
848 dy10 = _mm_sub_ps(iy1,jy0);
849 dz10 = _mm_sub_ps(iz1,jz0);
850 dx20 = _mm_sub_ps(ix2,jx0);
851 dy20 = _mm_sub_ps(iy2,jy0);
852 dz20 = _mm_sub_ps(iz2,jz0);
854 /* Calculate squared distance and things based on it */
855 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
856 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
857 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
859 rinv00 = avx128fma_invsqrt_f(rsq00);
860 rinv10 = avx128fma_invsqrt_f(rsq10);
861 rinv20 = avx128fma_invsqrt_f(rsq20);
863 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
864 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
865 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
867 /* Load parameters for j particles */
868 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
869 charge+jnrC+0,charge+jnrD+0);
871 fjx0 = _mm_setzero_ps();
872 fjy0 = _mm_setzero_ps();
873 fjz0 = _mm_setzero_ps();
875 /**************************
876 * CALCULATE INTERACTIONS *
877 **************************/
879 if (gmx_mm_any_lt(rsq00,rcutoff2))
882 /* Compute parameters for interactions between i and j atoms */
883 qq00 = _mm_mul_ps(iq0,jq0);
885 /* REACTION-FIELD ELECTROSTATICS */
886 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
888 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
892 fscal = _mm_and_ps(fscal,cutoff_mask);
894 fscal = _mm_andnot_ps(dummy_mask,fscal);
896 /* Update vectorial force */
897 fix0 = _mm_macc_ps(dx00,fscal,fix0);
898 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
899 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
901 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
902 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
903 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
907 /**************************
908 * CALCULATE INTERACTIONS *
909 **************************/
911 if (gmx_mm_any_lt(rsq10,rcutoff2))
914 /* Compute parameters for interactions between i and j atoms */
915 qq10 = _mm_mul_ps(iq1,jq0);
917 /* REACTION-FIELD ELECTROSTATICS */
918 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
920 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
924 fscal = _mm_and_ps(fscal,cutoff_mask);
926 fscal = _mm_andnot_ps(dummy_mask,fscal);
928 /* Update vectorial force */
929 fix1 = _mm_macc_ps(dx10,fscal,fix1);
930 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
931 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
933 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
934 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
935 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
939 /**************************
940 * CALCULATE INTERACTIONS *
941 **************************/
943 if (gmx_mm_any_lt(rsq20,rcutoff2))
946 /* Compute parameters for interactions between i and j atoms */
947 qq20 = _mm_mul_ps(iq2,jq0);
949 /* REACTION-FIELD ELECTROSTATICS */
950 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
952 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
956 fscal = _mm_and_ps(fscal,cutoff_mask);
958 fscal = _mm_andnot_ps(dummy_mask,fscal);
960 /* Update vectorial force */
961 fix2 = _mm_macc_ps(dx20,fscal,fix2);
962 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
963 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
965 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
966 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
967 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
971 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
972 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
973 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
974 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
976 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
978 /* Inner loop uses 99 flops */
981 /* End of innermost loop */
983 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
984 f+i_coord_offset,fshift+i_shift_offset);
986 /* Increment number of inner iterations */
987 inneriter += j_index_end - j_index_start;
989 /* Outer loop uses 18 flops */
992 /* Increment number of outer iterations */
995 /* Update outer/inner flops */
997 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*99);