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_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: None
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_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;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128 dummy_mask,cutoff_mask;
97 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
98 __m128 one = _mm_set1_ps(1.0);
99 __m128 two = _mm_set1_ps(2.0);
105 jindex = nlist->jindex;
107 shiftidx = nlist->shift;
109 shiftvec = fr->shift_vec[0];
110 fshift = fr->fshift[0];
111 facel = _mm_set1_ps(fr->epsfac);
112 charge = mdatoms->chargeA;
113 krf = _mm_set1_ps(fr->ic->k_rf);
114 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
115 crf = _mm_set1_ps(fr->ic->c_rf);
117 /* Setup water-specific parameters */
118 inr = nlist->iinr[0];
119 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
120 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
121 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
123 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
124 rcutoff_scalar = fr->rcoulomb;
125 rcutoff = _mm_set1_ps(rcutoff_scalar);
126 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
128 /* Avoid stupid compiler warnings */
129 jnrA = jnrB = jnrC = jnrD = 0;
138 for(iidx=0;iidx<4*DIM;iidx++)
143 /* Start outer loop over neighborlists */
144 for(iidx=0; iidx<nri; iidx++)
146 /* Load shift vector for this list */
147 i_shift_offset = DIM*shiftidx[iidx];
149 /* Load limits for loop over neighbors */
150 j_index_start = jindex[iidx];
151 j_index_end = jindex[iidx+1];
153 /* Get outer coordinate index */
155 i_coord_offset = DIM*inr;
157 /* Load i particle coords and add shift vector */
158 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
159 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
161 fix0 = _mm_setzero_ps();
162 fiy0 = _mm_setzero_ps();
163 fiz0 = _mm_setzero_ps();
164 fix1 = _mm_setzero_ps();
165 fiy1 = _mm_setzero_ps();
166 fiz1 = _mm_setzero_ps();
167 fix2 = _mm_setzero_ps();
168 fiy2 = _mm_setzero_ps();
169 fiz2 = _mm_setzero_ps();
171 /* Reset potential sums */
172 velecsum = _mm_setzero_ps();
174 /* Start inner kernel loop */
175 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
178 /* Get j neighbor index, and coordinate index */
183 j_coord_offsetA = DIM*jnrA;
184 j_coord_offsetB = DIM*jnrB;
185 j_coord_offsetC = DIM*jnrC;
186 j_coord_offsetD = DIM*jnrD;
188 /* load j atom coordinates */
189 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
190 x+j_coord_offsetC,x+j_coord_offsetD,
193 /* Calculate displacement vector */
194 dx00 = _mm_sub_ps(ix0,jx0);
195 dy00 = _mm_sub_ps(iy0,jy0);
196 dz00 = _mm_sub_ps(iz0,jz0);
197 dx10 = _mm_sub_ps(ix1,jx0);
198 dy10 = _mm_sub_ps(iy1,jy0);
199 dz10 = _mm_sub_ps(iz1,jz0);
200 dx20 = _mm_sub_ps(ix2,jx0);
201 dy20 = _mm_sub_ps(iy2,jy0);
202 dz20 = _mm_sub_ps(iz2,jz0);
204 /* Calculate squared distance and things based on it */
205 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
206 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
207 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
209 rinv00 = gmx_mm_invsqrt_ps(rsq00);
210 rinv10 = gmx_mm_invsqrt_ps(rsq10);
211 rinv20 = gmx_mm_invsqrt_ps(rsq20);
213 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
214 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
215 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
217 /* Load parameters for j particles */
218 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
219 charge+jnrC+0,charge+jnrD+0);
221 fjx0 = _mm_setzero_ps();
222 fjy0 = _mm_setzero_ps();
223 fjz0 = _mm_setzero_ps();
225 /**************************
226 * CALCULATE INTERACTIONS *
227 **************************/
229 if (gmx_mm_any_lt(rsq00,rcutoff2))
232 /* Compute parameters for interactions between i and j atoms */
233 qq00 = _mm_mul_ps(iq0,jq0);
235 /* REACTION-FIELD ELECTROSTATICS */
236 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
237 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
239 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
241 /* Update potential sum for this i atom from the interaction with this j atom. */
242 velec = _mm_and_ps(velec,cutoff_mask);
243 velecsum = _mm_add_ps(velecsum,velec);
247 fscal = _mm_and_ps(fscal,cutoff_mask);
249 /* Update vectorial force */
250 fix0 = _mm_macc_ps(dx00,fscal,fix0);
251 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
252 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
254 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
255 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
256 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
260 /**************************
261 * CALCULATE INTERACTIONS *
262 **************************/
264 if (gmx_mm_any_lt(rsq10,rcutoff2))
267 /* Compute parameters for interactions between i and j atoms */
268 qq10 = _mm_mul_ps(iq1,jq0);
270 /* REACTION-FIELD ELECTROSTATICS */
271 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
272 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
274 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
276 /* Update potential sum for this i atom from the interaction with this j atom. */
277 velec = _mm_and_ps(velec,cutoff_mask);
278 velecsum = _mm_add_ps(velecsum,velec);
282 fscal = _mm_and_ps(fscal,cutoff_mask);
284 /* Update vectorial force */
285 fix1 = _mm_macc_ps(dx10,fscal,fix1);
286 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
287 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
289 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
290 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
291 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
295 /**************************
296 * CALCULATE INTERACTIONS *
297 **************************/
299 if (gmx_mm_any_lt(rsq20,rcutoff2))
302 /* Compute parameters for interactions between i and j atoms */
303 qq20 = _mm_mul_ps(iq2,jq0);
305 /* REACTION-FIELD ELECTROSTATICS */
306 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
307 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
309 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
311 /* Update potential sum for this i atom from the interaction with this j atom. */
312 velec = _mm_and_ps(velec,cutoff_mask);
313 velecsum = _mm_add_ps(velecsum,velec);
317 fscal = _mm_and_ps(fscal,cutoff_mask);
319 /* Update vectorial force */
320 fix2 = _mm_macc_ps(dx20,fscal,fix2);
321 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
322 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
324 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
325 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
326 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
330 fjptrA = f+j_coord_offsetA;
331 fjptrB = f+j_coord_offsetB;
332 fjptrC = f+j_coord_offsetC;
333 fjptrD = f+j_coord_offsetD;
335 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
337 /* Inner loop uses 117 flops */
343 /* Get j neighbor index, and coordinate index */
344 jnrlistA = jjnr[jidx];
345 jnrlistB = jjnr[jidx+1];
346 jnrlistC = jjnr[jidx+2];
347 jnrlistD = jjnr[jidx+3];
348 /* Sign of each element will be negative for non-real atoms.
349 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
350 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
352 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
353 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
354 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
355 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
356 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
357 j_coord_offsetA = DIM*jnrA;
358 j_coord_offsetB = DIM*jnrB;
359 j_coord_offsetC = DIM*jnrC;
360 j_coord_offsetD = DIM*jnrD;
362 /* load j atom coordinates */
363 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
364 x+j_coord_offsetC,x+j_coord_offsetD,
367 /* Calculate displacement vector */
368 dx00 = _mm_sub_ps(ix0,jx0);
369 dy00 = _mm_sub_ps(iy0,jy0);
370 dz00 = _mm_sub_ps(iz0,jz0);
371 dx10 = _mm_sub_ps(ix1,jx0);
372 dy10 = _mm_sub_ps(iy1,jy0);
373 dz10 = _mm_sub_ps(iz1,jz0);
374 dx20 = _mm_sub_ps(ix2,jx0);
375 dy20 = _mm_sub_ps(iy2,jy0);
376 dz20 = _mm_sub_ps(iz2,jz0);
378 /* Calculate squared distance and things based on it */
379 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
380 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
381 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
383 rinv00 = gmx_mm_invsqrt_ps(rsq00);
384 rinv10 = gmx_mm_invsqrt_ps(rsq10);
385 rinv20 = gmx_mm_invsqrt_ps(rsq20);
387 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
388 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
389 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
391 /* Load parameters for j particles */
392 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
393 charge+jnrC+0,charge+jnrD+0);
395 fjx0 = _mm_setzero_ps();
396 fjy0 = _mm_setzero_ps();
397 fjz0 = _mm_setzero_ps();
399 /**************************
400 * CALCULATE INTERACTIONS *
401 **************************/
403 if (gmx_mm_any_lt(rsq00,rcutoff2))
406 /* Compute parameters for interactions between i and j atoms */
407 qq00 = _mm_mul_ps(iq0,jq0);
409 /* REACTION-FIELD ELECTROSTATICS */
410 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
411 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
413 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
415 /* Update potential sum for this i atom from the interaction with this j atom. */
416 velec = _mm_and_ps(velec,cutoff_mask);
417 velec = _mm_andnot_ps(dummy_mask,velec);
418 velecsum = _mm_add_ps(velecsum,velec);
422 fscal = _mm_and_ps(fscal,cutoff_mask);
424 fscal = _mm_andnot_ps(dummy_mask,fscal);
426 /* Update vectorial force */
427 fix0 = _mm_macc_ps(dx00,fscal,fix0);
428 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
429 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
431 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
432 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
433 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
437 /**************************
438 * CALCULATE INTERACTIONS *
439 **************************/
441 if (gmx_mm_any_lt(rsq10,rcutoff2))
444 /* Compute parameters for interactions between i and j atoms */
445 qq10 = _mm_mul_ps(iq1,jq0);
447 /* REACTION-FIELD ELECTROSTATICS */
448 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
449 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
451 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
453 /* Update potential sum for this i atom from the interaction with this j atom. */
454 velec = _mm_and_ps(velec,cutoff_mask);
455 velec = _mm_andnot_ps(dummy_mask,velec);
456 velecsum = _mm_add_ps(velecsum,velec);
460 fscal = _mm_and_ps(fscal,cutoff_mask);
462 fscal = _mm_andnot_ps(dummy_mask,fscal);
464 /* Update vectorial force */
465 fix1 = _mm_macc_ps(dx10,fscal,fix1);
466 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
467 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
469 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
470 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
471 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
475 /**************************
476 * CALCULATE INTERACTIONS *
477 **************************/
479 if (gmx_mm_any_lt(rsq20,rcutoff2))
482 /* Compute parameters for interactions between i and j atoms */
483 qq20 = _mm_mul_ps(iq2,jq0);
485 /* REACTION-FIELD ELECTROSTATICS */
486 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
487 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
489 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
491 /* Update potential sum for this i atom from the interaction with this j atom. */
492 velec = _mm_and_ps(velec,cutoff_mask);
493 velec = _mm_andnot_ps(dummy_mask,velec);
494 velecsum = _mm_add_ps(velecsum,velec);
498 fscal = _mm_and_ps(fscal,cutoff_mask);
500 fscal = _mm_andnot_ps(dummy_mask,fscal);
502 /* Update vectorial force */
503 fix2 = _mm_macc_ps(dx20,fscal,fix2);
504 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
505 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
507 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
508 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
509 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
513 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
514 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
515 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
516 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
518 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
520 /* Inner loop uses 117 flops */
523 /* End of innermost loop */
525 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
526 f+i_coord_offset,fshift+i_shift_offset);
529 /* Update potential energies */
530 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
532 /* Increment number of inner iterations */
533 inneriter += j_index_end - j_index_start;
535 /* Outer loop uses 19 flops */
538 /* Increment number of outer iterations */
541 /* Update outer/inner flops */
543 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*117);
546 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
547 * Electrostatics interaction: ReactionField
548 * VdW interaction: None
549 * Geometry: Water3-Particle
550 * Calculate force/pot: Force
553 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
554 (t_nblist * gmx_restrict nlist,
555 rvec * gmx_restrict xx,
556 rvec * gmx_restrict ff,
557 t_forcerec * gmx_restrict fr,
558 t_mdatoms * gmx_restrict mdatoms,
559 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
560 t_nrnb * gmx_restrict nrnb)
562 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
563 * just 0 for non-waters.
564 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
565 * jnr indices corresponding to data put in the four positions in the SIMD register.
567 int i_shift_offset,i_coord_offset,outeriter,inneriter;
568 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
569 int jnrA,jnrB,jnrC,jnrD;
570 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
571 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
572 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
574 real *shiftvec,*fshift,*x,*f;
575 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
577 __m128 fscal,rcutoff,rcutoff2,jidxall;
579 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
581 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
583 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
584 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
585 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
586 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
587 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
588 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
589 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
591 __m128 dummy_mask,cutoff_mask;
592 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
593 __m128 one = _mm_set1_ps(1.0);
594 __m128 two = _mm_set1_ps(2.0);
600 jindex = nlist->jindex;
602 shiftidx = nlist->shift;
604 shiftvec = fr->shift_vec[0];
605 fshift = fr->fshift[0];
606 facel = _mm_set1_ps(fr->epsfac);
607 charge = mdatoms->chargeA;
608 krf = _mm_set1_ps(fr->ic->k_rf);
609 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
610 crf = _mm_set1_ps(fr->ic->c_rf);
612 /* Setup water-specific parameters */
613 inr = nlist->iinr[0];
614 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
615 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
616 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
618 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
619 rcutoff_scalar = fr->rcoulomb;
620 rcutoff = _mm_set1_ps(rcutoff_scalar);
621 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
623 /* Avoid stupid compiler warnings */
624 jnrA = jnrB = jnrC = jnrD = 0;
633 for(iidx=0;iidx<4*DIM;iidx++)
638 /* Start outer loop over neighborlists */
639 for(iidx=0; iidx<nri; iidx++)
641 /* Load shift vector for this list */
642 i_shift_offset = DIM*shiftidx[iidx];
644 /* Load limits for loop over neighbors */
645 j_index_start = jindex[iidx];
646 j_index_end = jindex[iidx+1];
648 /* Get outer coordinate index */
650 i_coord_offset = DIM*inr;
652 /* Load i particle coords and add shift vector */
653 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
654 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
656 fix0 = _mm_setzero_ps();
657 fiy0 = _mm_setzero_ps();
658 fiz0 = _mm_setzero_ps();
659 fix1 = _mm_setzero_ps();
660 fiy1 = _mm_setzero_ps();
661 fiz1 = _mm_setzero_ps();
662 fix2 = _mm_setzero_ps();
663 fiy2 = _mm_setzero_ps();
664 fiz2 = _mm_setzero_ps();
666 /* Start inner kernel loop */
667 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
670 /* Get j neighbor index, and coordinate index */
675 j_coord_offsetA = DIM*jnrA;
676 j_coord_offsetB = DIM*jnrB;
677 j_coord_offsetC = DIM*jnrC;
678 j_coord_offsetD = DIM*jnrD;
680 /* load j atom coordinates */
681 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
682 x+j_coord_offsetC,x+j_coord_offsetD,
685 /* Calculate displacement vector */
686 dx00 = _mm_sub_ps(ix0,jx0);
687 dy00 = _mm_sub_ps(iy0,jy0);
688 dz00 = _mm_sub_ps(iz0,jz0);
689 dx10 = _mm_sub_ps(ix1,jx0);
690 dy10 = _mm_sub_ps(iy1,jy0);
691 dz10 = _mm_sub_ps(iz1,jz0);
692 dx20 = _mm_sub_ps(ix2,jx0);
693 dy20 = _mm_sub_ps(iy2,jy0);
694 dz20 = _mm_sub_ps(iz2,jz0);
696 /* Calculate squared distance and things based on it */
697 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
698 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
699 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
701 rinv00 = gmx_mm_invsqrt_ps(rsq00);
702 rinv10 = gmx_mm_invsqrt_ps(rsq10);
703 rinv20 = gmx_mm_invsqrt_ps(rsq20);
705 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
706 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
707 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
709 /* Load parameters for j particles */
710 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
711 charge+jnrC+0,charge+jnrD+0);
713 fjx0 = _mm_setzero_ps();
714 fjy0 = _mm_setzero_ps();
715 fjz0 = _mm_setzero_ps();
717 /**************************
718 * CALCULATE INTERACTIONS *
719 **************************/
721 if (gmx_mm_any_lt(rsq00,rcutoff2))
724 /* Compute parameters for interactions between i and j atoms */
725 qq00 = _mm_mul_ps(iq0,jq0);
727 /* REACTION-FIELD ELECTROSTATICS */
728 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
730 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
734 fscal = _mm_and_ps(fscal,cutoff_mask);
736 /* Update vectorial force */
737 fix0 = _mm_macc_ps(dx00,fscal,fix0);
738 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
739 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
741 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
742 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
743 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
747 /**************************
748 * CALCULATE INTERACTIONS *
749 **************************/
751 if (gmx_mm_any_lt(rsq10,rcutoff2))
754 /* Compute parameters for interactions between i and j atoms */
755 qq10 = _mm_mul_ps(iq1,jq0);
757 /* REACTION-FIELD ELECTROSTATICS */
758 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
760 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
764 fscal = _mm_and_ps(fscal,cutoff_mask);
766 /* Update vectorial force */
767 fix1 = _mm_macc_ps(dx10,fscal,fix1);
768 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
769 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
771 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
772 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
773 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
777 /**************************
778 * CALCULATE INTERACTIONS *
779 **************************/
781 if (gmx_mm_any_lt(rsq20,rcutoff2))
784 /* Compute parameters for interactions between i and j atoms */
785 qq20 = _mm_mul_ps(iq2,jq0);
787 /* REACTION-FIELD ELECTROSTATICS */
788 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
790 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
794 fscal = _mm_and_ps(fscal,cutoff_mask);
796 /* Update vectorial force */
797 fix2 = _mm_macc_ps(dx20,fscal,fix2);
798 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
799 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
801 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
802 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
803 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
807 fjptrA = f+j_coord_offsetA;
808 fjptrB = f+j_coord_offsetB;
809 fjptrC = f+j_coord_offsetC;
810 fjptrD = f+j_coord_offsetD;
812 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
814 /* Inner loop uses 99 flops */
820 /* Get j neighbor index, and coordinate index */
821 jnrlistA = jjnr[jidx];
822 jnrlistB = jjnr[jidx+1];
823 jnrlistC = jjnr[jidx+2];
824 jnrlistD = jjnr[jidx+3];
825 /* Sign of each element will be negative for non-real atoms.
826 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
827 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
829 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
830 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
831 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
832 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
833 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
834 j_coord_offsetA = DIM*jnrA;
835 j_coord_offsetB = DIM*jnrB;
836 j_coord_offsetC = DIM*jnrC;
837 j_coord_offsetD = DIM*jnrD;
839 /* load j atom coordinates */
840 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
841 x+j_coord_offsetC,x+j_coord_offsetD,
844 /* Calculate displacement vector */
845 dx00 = _mm_sub_ps(ix0,jx0);
846 dy00 = _mm_sub_ps(iy0,jy0);
847 dz00 = _mm_sub_ps(iz0,jz0);
848 dx10 = _mm_sub_ps(ix1,jx0);
849 dy10 = _mm_sub_ps(iy1,jy0);
850 dz10 = _mm_sub_ps(iz1,jz0);
851 dx20 = _mm_sub_ps(ix2,jx0);
852 dy20 = _mm_sub_ps(iy2,jy0);
853 dz20 = _mm_sub_ps(iz2,jz0);
855 /* Calculate squared distance and things based on it */
856 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
857 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
858 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
860 rinv00 = gmx_mm_invsqrt_ps(rsq00);
861 rinv10 = gmx_mm_invsqrt_ps(rsq10);
862 rinv20 = gmx_mm_invsqrt_ps(rsq20);
864 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
865 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
866 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
868 /* Load parameters for j particles */
869 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
870 charge+jnrC+0,charge+jnrD+0);
872 fjx0 = _mm_setzero_ps();
873 fjy0 = _mm_setzero_ps();
874 fjz0 = _mm_setzero_ps();
876 /**************************
877 * CALCULATE INTERACTIONS *
878 **************************/
880 if (gmx_mm_any_lt(rsq00,rcutoff2))
883 /* Compute parameters for interactions between i and j atoms */
884 qq00 = _mm_mul_ps(iq0,jq0);
886 /* REACTION-FIELD ELECTROSTATICS */
887 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
889 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
893 fscal = _mm_and_ps(fscal,cutoff_mask);
895 fscal = _mm_andnot_ps(dummy_mask,fscal);
897 /* Update vectorial force */
898 fix0 = _mm_macc_ps(dx00,fscal,fix0);
899 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
900 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
902 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
903 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
904 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
908 /**************************
909 * CALCULATE INTERACTIONS *
910 **************************/
912 if (gmx_mm_any_lt(rsq10,rcutoff2))
915 /* Compute parameters for interactions between i and j atoms */
916 qq10 = _mm_mul_ps(iq1,jq0);
918 /* REACTION-FIELD ELECTROSTATICS */
919 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
921 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
925 fscal = _mm_and_ps(fscal,cutoff_mask);
927 fscal = _mm_andnot_ps(dummy_mask,fscal);
929 /* Update vectorial force */
930 fix1 = _mm_macc_ps(dx10,fscal,fix1);
931 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
932 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
934 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
935 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
936 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
940 /**************************
941 * CALCULATE INTERACTIONS *
942 **************************/
944 if (gmx_mm_any_lt(rsq20,rcutoff2))
947 /* Compute parameters for interactions between i and j atoms */
948 qq20 = _mm_mul_ps(iq2,jq0);
950 /* REACTION-FIELD ELECTROSTATICS */
951 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
953 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
957 fscal = _mm_and_ps(fscal,cutoff_mask);
959 fscal = _mm_andnot_ps(dummy_mask,fscal);
961 /* Update vectorial force */
962 fix2 = _mm_macc_ps(dx20,fscal,fix2);
963 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
964 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
966 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
967 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
968 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
972 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
973 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
974 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
975 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
977 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
979 /* Inner loop uses 99 flops */
982 /* End of innermost loop */
984 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
985 f+i_coord_offset,fshift+i_shift_offset);
987 /* Increment number of inner iterations */
988 inneriter += j_index_end - j_index_start;
990 /* Outer loop uses 18 flops */
993 /* Increment number of outer iterations */
996 /* Update outer/inner flops */
998 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*99);