2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_avx_128_fma_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: None
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_avx_128_fma_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
98 __m128 dummy_mask,cutoff_mask;
99 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
100 __m128 one = _mm_set1_ps(1.0);
101 __m128 two = _mm_set1_ps(2.0);
107 jindex = nlist->jindex;
109 shiftidx = nlist->shift;
111 shiftvec = fr->shift_vec[0];
112 fshift = fr->fshift[0];
113 facel = _mm_set1_ps(fr->epsfac);
114 charge = mdatoms->chargeA;
115 krf = _mm_set1_ps(fr->ic->k_rf);
116 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
117 crf = _mm_set1_ps(fr->ic->c_rf);
119 /* Setup water-specific parameters */
120 inr = nlist->iinr[0];
121 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
122 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
123 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
125 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
126 rcutoff_scalar = fr->rcoulomb;
127 rcutoff = _mm_set1_ps(rcutoff_scalar);
128 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
130 /* Avoid stupid compiler warnings */
131 jnrA = jnrB = jnrC = jnrD = 0;
140 for(iidx=0;iidx<4*DIM;iidx++)
145 /* Start outer loop over neighborlists */
146 for(iidx=0; iidx<nri; iidx++)
148 /* Load shift vector for this list */
149 i_shift_offset = DIM*shiftidx[iidx];
151 /* Load limits for loop over neighbors */
152 j_index_start = jindex[iidx];
153 j_index_end = jindex[iidx+1];
155 /* Get outer coordinate index */
157 i_coord_offset = DIM*inr;
159 /* Load i particle coords and add shift vector */
160 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
161 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
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();
169 fix3 = _mm_setzero_ps();
170 fiy3 = _mm_setzero_ps();
171 fiz3 = _mm_setzero_ps();
173 /* Reset potential sums */
174 velecsum = _mm_setzero_ps();
176 /* Start inner kernel loop */
177 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
180 /* Get j neighbor index, and coordinate index */
185 j_coord_offsetA = DIM*jnrA;
186 j_coord_offsetB = DIM*jnrB;
187 j_coord_offsetC = DIM*jnrC;
188 j_coord_offsetD = DIM*jnrD;
190 /* load j atom coordinates */
191 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
192 x+j_coord_offsetC,x+j_coord_offsetD,
195 /* Calculate displacement vector */
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);
202 dx30 = _mm_sub_ps(ix3,jx0);
203 dy30 = _mm_sub_ps(iy3,jy0);
204 dz30 = _mm_sub_ps(iz3,jz0);
206 /* Calculate squared distance and things based on it */
207 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
208 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
209 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
211 rinv10 = gmx_mm_invsqrt_ps(rsq10);
212 rinv20 = gmx_mm_invsqrt_ps(rsq20);
213 rinv30 = gmx_mm_invsqrt_ps(rsq30);
215 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
216 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
217 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
219 /* Load parameters for j particles */
220 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
221 charge+jnrC+0,charge+jnrD+0);
223 fjx0 = _mm_setzero_ps();
224 fjy0 = _mm_setzero_ps();
225 fjz0 = _mm_setzero_ps();
227 /**************************
228 * CALCULATE INTERACTIONS *
229 **************************/
231 if (gmx_mm_any_lt(rsq10,rcutoff2))
234 /* Compute parameters for interactions between i and j atoms */
235 qq10 = _mm_mul_ps(iq1,jq0);
237 /* REACTION-FIELD ELECTROSTATICS */
238 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
239 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
241 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
243 /* Update potential sum for this i atom from the interaction with this j atom. */
244 velec = _mm_and_ps(velec,cutoff_mask);
245 velecsum = _mm_add_ps(velecsum,velec);
249 fscal = _mm_and_ps(fscal,cutoff_mask);
251 /* Update vectorial force */
252 fix1 = _mm_macc_ps(dx10,fscal,fix1);
253 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
254 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
256 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
257 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
258 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
262 /**************************
263 * CALCULATE INTERACTIONS *
264 **************************/
266 if (gmx_mm_any_lt(rsq20,rcutoff2))
269 /* Compute parameters for interactions between i and j atoms */
270 qq20 = _mm_mul_ps(iq2,jq0);
272 /* REACTION-FIELD ELECTROSTATICS */
273 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
274 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
276 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
278 /* Update potential sum for this i atom from the interaction with this j atom. */
279 velec = _mm_and_ps(velec,cutoff_mask);
280 velecsum = _mm_add_ps(velecsum,velec);
284 fscal = _mm_and_ps(fscal,cutoff_mask);
286 /* Update vectorial force */
287 fix2 = _mm_macc_ps(dx20,fscal,fix2);
288 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
289 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
291 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
292 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
293 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
297 /**************************
298 * CALCULATE INTERACTIONS *
299 **************************/
301 if (gmx_mm_any_lt(rsq30,rcutoff2))
304 /* Compute parameters for interactions between i and j atoms */
305 qq30 = _mm_mul_ps(iq3,jq0);
307 /* REACTION-FIELD ELECTROSTATICS */
308 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
309 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
311 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
313 /* Update potential sum for this i atom from the interaction with this j atom. */
314 velec = _mm_and_ps(velec,cutoff_mask);
315 velecsum = _mm_add_ps(velecsum,velec);
319 fscal = _mm_and_ps(fscal,cutoff_mask);
321 /* Update vectorial force */
322 fix3 = _mm_macc_ps(dx30,fscal,fix3);
323 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
324 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
326 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
327 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
328 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
332 fjptrA = f+j_coord_offsetA;
333 fjptrB = f+j_coord_offsetB;
334 fjptrC = f+j_coord_offsetC;
335 fjptrD = f+j_coord_offsetD;
337 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
339 /* Inner loop uses 117 flops */
345 /* Get j neighbor index, and coordinate index */
346 jnrlistA = jjnr[jidx];
347 jnrlistB = jjnr[jidx+1];
348 jnrlistC = jjnr[jidx+2];
349 jnrlistD = jjnr[jidx+3];
350 /* Sign of each element will be negative for non-real atoms.
351 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
352 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
354 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
355 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
356 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
357 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
358 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
359 j_coord_offsetA = DIM*jnrA;
360 j_coord_offsetB = DIM*jnrB;
361 j_coord_offsetC = DIM*jnrC;
362 j_coord_offsetD = DIM*jnrD;
364 /* load j atom coordinates */
365 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
366 x+j_coord_offsetC,x+j_coord_offsetD,
369 /* Calculate displacement vector */
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);
376 dx30 = _mm_sub_ps(ix3,jx0);
377 dy30 = _mm_sub_ps(iy3,jy0);
378 dz30 = _mm_sub_ps(iz3,jz0);
380 /* Calculate squared distance and things based on it */
381 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
382 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
383 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
385 rinv10 = gmx_mm_invsqrt_ps(rsq10);
386 rinv20 = gmx_mm_invsqrt_ps(rsq20);
387 rinv30 = gmx_mm_invsqrt_ps(rsq30);
389 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
390 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
391 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
393 /* Load parameters for j particles */
394 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
395 charge+jnrC+0,charge+jnrD+0);
397 fjx0 = _mm_setzero_ps();
398 fjy0 = _mm_setzero_ps();
399 fjz0 = _mm_setzero_ps();
401 /**************************
402 * CALCULATE INTERACTIONS *
403 **************************/
405 if (gmx_mm_any_lt(rsq10,rcutoff2))
408 /* Compute parameters for interactions between i and j atoms */
409 qq10 = _mm_mul_ps(iq1,jq0);
411 /* REACTION-FIELD ELECTROSTATICS */
412 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
413 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
415 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
417 /* Update potential sum for this i atom from the interaction with this j atom. */
418 velec = _mm_and_ps(velec,cutoff_mask);
419 velec = _mm_andnot_ps(dummy_mask,velec);
420 velecsum = _mm_add_ps(velecsum,velec);
424 fscal = _mm_and_ps(fscal,cutoff_mask);
426 fscal = _mm_andnot_ps(dummy_mask,fscal);
428 /* Update vectorial force */
429 fix1 = _mm_macc_ps(dx10,fscal,fix1);
430 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
431 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
433 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
434 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
435 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
439 /**************************
440 * CALCULATE INTERACTIONS *
441 **************************/
443 if (gmx_mm_any_lt(rsq20,rcutoff2))
446 /* Compute parameters for interactions between i and j atoms */
447 qq20 = _mm_mul_ps(iq2,jq0);
449 /* REACTION-FIELD ELECTROSTATICS */
450 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
451 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
453 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
455 /* Update potential sum for this i atom from the interaction with this j atom. */
456 velec = _mm_and_ps(velec,cutoff_mask);
457 velec = _mm_andnot_ps(dummy_mask,velec);
458 velecsum = _mm_add_ps(velecsum,velec);
462 fscal = _mm_and_ps(fscal,cutoff_mask);
464 fscal = _mm_andnot_ps(dummy_mask,fscal);
466 /* Update vectorial force */
467 fix2 = _mm_macc_ps(dx20,fscal,fix2);
468 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
469 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
471 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
472 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
473 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
477 /**************************
478 * CALCULATE INTERACTIONS *
479 **************************/
481 if (gmx_mm_any_lt(rsq30,rcutoff2))
484 /* Compute parameters for interactions between i and j atoms */
485 qq30 = _mm_mul_ps(iq3,jq0);
487 /* REACTION-FIELD ELECTROSTATICS */
488 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
489 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
491 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
493 /* Update potential sum for this i atom from the interaction with this j atom. */
494 velec = _mm_and_ps(velec,cutoff_mask);
495 velec = _mm_andnot_ps(dummy_mask,velec);
496 velecsum = _mm_add_ps(velecsum,velec);
500 fscal = _mm_and_ps(fscal,cutoff_mask);
502 fscal = _mm_andnot_ps(dummy_mask,fscal);
504 /* Update vectorial force */
505 fix3 = _mm_macc_ps(dx30,fscal,fix3);
506 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
507 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
509 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
510 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
511 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
515 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
516 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
517 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
518 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
520 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
522 /* Inner loop uses 117 flops */
525 /* End of innermost loop */
527 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
528 f+i_coord_offset+DIM,fshift+i_shift_offset);
531 /* Update potential energies */
532 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
534 /* Increment number of inner iterations */
535 inneriter += j_index_end - j_index_start;
537 /* Outer loop uses 19 flops */
540 /* Increment number of outer iterations */
543 /* Update outer/inner flops */
545 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*117);
548 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_avx_128_fma_single
549 * Electrostatics interaction: ReactionField
550 * VdW interaction: None
551 * Geometry: Water4-Particle
552 * Calculate force/pot: Force
555 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_avx_128_fma_single
556 (t_nblist * gmx_restrict nlist,
557 rvec * gmx_restrict xx,
558 rvec * gmx_restrict ff,
559 t_forcerec * gmx_restrict fr,
560 t_mdatoms * gmx_restrict mdatoms,
561 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
562 t_nrnb * gmx_restrict nrnb)
564 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
565 * just 0 for non-waters.
566 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
567 * jnr indices corresponding to data put in the four positions in the SIMD register.
569 int i_shift_offset,i_coord_offset,outeriter,inneriter;
570 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
571 int jnrA,jnrB,jnrC,jnrD;
572 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
573 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
574 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
576 real *shiftvec,*fshift,*x,*f;
577 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
579 __m128 fscal,rcutoff,rcutoff2,jidxall;
581 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
583 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
585 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
586 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
587 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
588 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
589 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
590 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
591 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
593 __m128 dummy_mask,cutoff_mask;
594 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
595 __m128 one = _mm_set1_ps(1.0);
596 __m128 two = _mm_set1_ps(2.0);
602 jindex = nlist->jindex;
604 shiftidx = nlist->shift;
606 shiftvec = fr->shift_vec[0];
607 fshift = fr->fshift[0];
608 facel = _mm_set1_ps(fr->epsfac);
609 charge = mdatoms->chargeA;
610 krf = _mm_set1_ps(fr->ic->k_rf);
611 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
612 crf = _mm_set1_ps(fr->ic->c_rf);
614 /* Setup water-specific parameters */
615 inr = nlist->iinr[0];
616 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
617 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
618 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
620 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
621 rcutoff_scalar = fr->rcoulomb;
622 rcutoff = _mm_set1_ps(rcutoff_scalar);
623 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
625 /* Avoid stupid compiler warnings */
626 jnrA = jnrB = jnrC = jnrD = 0;
635 for(iidx=0;iidx<4*DIM;iidx++)
640 /* Start outer loop over neighborlists */
641 for(iidx=0; iidx<nri; iidx++)
643 /* Load shift vector for this list */
644 i_shift_offset = DIM*shiftidx[iidx];
646 /* Load limits for loop over neighbors */
647 j_index_start = jindex[iidx];
648 j_index_end = jindex[iidx+1];
650 /* Get outer coordinate index */
652 i_coord_offset = DIM*inr;
654 /* Load i particle coords and add shift vector */
655 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
656 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
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();
664 fix3 = _mm_setzero_ps();
665 fiy3 = _mm_setzero_ps();
666 fiz3 = _mm_setzero_ps();
668 /* Start inner kernel loop */
669 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
672 /* Get j neighbor index, and coordinate index */
677 j_coord_offsetA = DIM*jnrA;
678 j_coord_offsetB = DIM*jnrB;
679 j_coord_offsetC = DIM*jnrC;
680 j_coord_offsetD = DIM*jnrD;
682 /* load j atom coordinates */
683 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
684 x+j_coord_offsetC,x+j_coord_offsetD,
687 /* Calculate displacement vector */
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);
694 dx30 = _mm_sub_ps(ix3,jx0);
695 dy30 = _mm_sub_ps(iy3,jy0);
696 dz30 = _mm_sub_ps(iz3,jz0);
698 /* Calculate squared distance and things based on it */
699 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
700 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
701 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
703 rinv10 = gmx_mm_invsqrt_ps(rsq10);
704 rinv20 = gmx_mm_invsqrt_ps(rsq20);
705 rinv30 = gmx_mm_invsqrt_ps(rsq30);
707 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
708 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
709 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
711 /* Load parameters for j particles */
712 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
713 charge+jnrC+0,charge+jnrD+0);
715 fjx0 = _mm_setzero_ps();
716 fjy0 = _mm_setzero_ps();
717 fjz0 = _mm_setzero_ps();
719 /**************************
720 * CALCULATE INTERACTIONS *
721 **************************/
723 if (gmx_mm_any_lt(rsq10,rcutoff2))
726 /* Compute parameters for interactions between i and j atoms */
727 qq10 = _mm_mul_ps(iq1,jq0);
729 /* REACTION-FIELD ELECTROSTATICS */
730 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
732 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
736 fscal = _mm_and_ps(fscal,cutoff_mask);
738 /* Update vectorial force */
739 fix1 = _mm_macc_ps(dx10,fscal,fix1);
740 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
741 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
743 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
744 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
745 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
749 /**************************
750 * CALCULATE INTERACTIONS *
751 **************************/
753 if (gmx_mm_any_lt(rsq20,rcutoff2))
756 /* Compute parameters for interactions between i and j atoms */
757 qq20 = _mm_mul_ps(iq2,jq0);
759 /* REACTION-FIELD ELECTROSTATICS */
760 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
762 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
766 fscal = _mm_and_ps(fscal,cutoff_mask);
768 /* Update vectorial force */
769 fix2 = _mm_macc_ps(dx20,fscal,fix2);
770 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
771 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
773 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
774 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
775 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
779 /**************************
780 * CALCULATE INTERACTIONS *
781 **************************/
783 if (gmx_mm_any_lt(rsq30,rcutoff2))
786 /* Compute parameters for interactions between i and j atoms */
787 qq30 = _mm_mul_ps(iq3,jq0);
789 /* REACTION-FIELD ELECTROSTATICS */
790 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
792 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
796 fscal = _mm_and_ps(fscal,cutoff_mask);
798 /* Update vectorial force */
799 fix3 = _mm_macc_ps(dx30,fscal,fix3);
800 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
801 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
803 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
804 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
805 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
809 fjptrA = f+j_coord_offsetA;
810 fjptrB = f+j_coord_offsetB;
811 fjptrC = f+j_coord_offsetC;
812 fjptrD = f+j_coord_offsetD;
814 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
816 /* Inner loop uses 99 flops */
822 /* Get j neighbor index, and coordinate index */
823 jnrlistA = jjnr[jidx];
824 jnrlistB = jjnr[jidx+1];
825 jnrlistC = jjnr[jidx+2];
826 jnrlistD = jjnr[jidx+3];
827 /* Sign of each element will be negative for non-real atoms.
828 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
829 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
831 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
832 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
833 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
834 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
835 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
836 j_coord_offsetA = DIM*jnrA;
837 j_coord_offsetB = DIM*jnrB;
838 j_coord_offsetC = DIM*jnrC;
839 j_coord_offsetD = DIM*jnrD;
841 /* load j atom coordinates */
842 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
843 x+j_coord_offsetC,x+j_coord_offsetD,
846 /* Calculate displacement vector */
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);
853 dx30 = _mm_sub_ps(ix3,jx0);
854 dy30 = _mm_sub_ps(iy3,jy0);
855 dz30 = _mm_sub_ps(iz3,jz0);
857 /* Calculate squared distance and things based on it */
858 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
859 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
860 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
862 rinv10 = gmx_mm_invsqrt_ps(rsq10);
863 rinv20 = gmx_mm_invsqrt_ps(rsq20);
864 rinv30 = gmx_mm_invsqrt_ps(rsq30);
866 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
867 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
868 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
870 /* Load parameters for j particles */
871 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
872 charge+jnrC+0,charge+jnrD+0);
874 fjx0 = _mm_setzero_ps();
875 fjy0 = _mm_setzero_ps();
876 fjz0 = _mm_setzero_ps();
878 /**************************
879 * CALCULATE INTERACTIONS *
880 **************************/
882 if (gmx_mm_any_lt(rsq10,rcutoff2))
885 /* Compute parameters for interactions between i and j atoms */
886 qq10 = _mm_mul_ps(iq1,jq0);
888 /* REACTION-FIELD ELECTROSTATICS */
889 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
891 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
895 fscal = _mm_and_ps(fscal,cutoff_mask);
897 fscal = _mm_andnot_ps(dummy_mask,fscal);
899 /* Update vectorial force */
900 fix1 = _mm_macc_ps(dx10,fscal,fix1);
901 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
902 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
904 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
905 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
906 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
910 /**************************
911 * CALCULATE INTERACTIONS *
912 **************************/
914 if (gmx_mm_any_lt(rsq20,rcutoff2))
917 /* Compute parameters for interactions between i and j atoms */
918 qq20 = _mm_mul_ps(iq2,jq0);
920 /* REACTION-FIELD ELECTROSTATICS */
921 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
923 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
927 fscal = _mm_and_ps(fscal,cutoff_mask);
929 fscal = _mm_andnot_ps(dummy_mask,fscal);
931 /* Update vectorial force */
932 fix2 = _mm_macc_ps(dx20,fscal,fix2);
933 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
934 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
936 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
937 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
938 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
942 /**************************
943 * CALCULATE INTERACTIONS *
944 **************************/
946 if (gmx_mm_any_lt(rsq30,rcutoff2))
949 /* Compute parameters for interactions between i and j atoms */
950 qq30 = _mm_mul_ps(iq3,jq0);
952 /* REACTION-FIELD ELECTROSTATICS */
953 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
955 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
959 fscal = _mm_and_ps(fscal,cutoff_mask);
961 fscal = _mm_andnot_ps(dummy_mask,fscal);
963 /* Update vectorial force */
964 fix3 = _mm_macc_ps(dx30,fscal,fix3);
965 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
966 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
968 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
969 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
970 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
974 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
975 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
976 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
977 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
979 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
981 /* Inner loop uses 99 flops */
984 /* End of innermost loop */
986 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
987 f+i_coord_offset+DIM,fshift+i_shift_offset);
989 /* Increment number of inner iterations */
990 inneriter += j_index_end - j_index_start;
992 /* Outer loop uses 18 flops */
995 /* Increment number of outer iterations */
998 /* Update outer/inner flops */
1000 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*99);