2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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 sse4_1_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse4_1_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_sse4_1_double
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: None
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_sse4_1_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
74 int j_coord_offsetA,j_coord_offsetB;
75 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real *shiftvec,*fshift,*x,*f;
78 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
82 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
84 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
85 int vdwjidx0A,vdwjidx0B;
86 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
88 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
89 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
90 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
92 __m128d dummy_mask,cutoff_mask;
93 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
94 __m128d one = _mm_set1_pd(1.0);
95 __m128d two = _mm_set1_pd(2.0);
101 jindex = nlist->jindex;
103 shiftidx = nlist->shift;
105 shiftvec = fr->shift_vec[0];
106 fshift = fr->fshift[0];
107 facel = _mm_set1_pd(fr->ic->epsfac);
108 charge = mdatoms->chargeA;
109 krf = _mm_set1_pd(fr->ic->k_rf);
110 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
111 crf = _mm_set1_pd(fr->ic->c_rf);
113 /* Setup water-specific parameters */
114 inr = nlist->iinr[0];
115 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
116 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
117 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
119 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
120 rcutoff_scalar = fr->ic->rcoulomb;
121 rcutoff = _mm_set1_pd(rcutoff_scalar);
122 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
124 /* Avoid stupid compiler warnings */
132 /* Start outer loop over neighborlists */
133 for(iidx=0; iidx<nri; iidx++)
135 /* Load shift vector for this list */
136 i_shift_offset = DIM*shiftidx[iidx];
138 /* Load limits for loop over neighbors */
139 j_index_start = jindex[iidx];
140 j_index_end = jindex[iidx+1];
142 /* Get outer coordinate index */
144 i_coord_offset = DIM*inr;
146 /* Load i particle coords and add shift vector */
147 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
148 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
150 fix1 = _mm_setzero_pd();
151 fiy1 = _mm_setzero_pd();
152 fiz1 = _mm_setzero_pd();
153 fix2 = _mm_setzero_pd();
154 fiy2 = _mm_setzero_pd();
155 fiz2 = _mm_setzero_pd();
156 fix3 = _mm_setzero_pd();
157 fiy3 = _mm_setzero_pd();
158 fiz3 = _mm_setzero_pd();
160 /* Reset potential sums */
161 velecsum = _mm_setzero_pd();
163 /* Start inner kernel loop */
164 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
167 /* Get j neighbor index, and coordinate index */
170 j_coord_offsetA = DIM*jnrA;
171 j_coord_offsetB = DIM*jnrB;
173 /* load j atom coordinates */
174 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
177 /* Calculate displacement vector */
178 dx10 = _mm_sub_pd(ix1,jx0);
179 dy10 = _mm_sub_pd(iy1,jy0);
180 dz10 = _mm_sub_pd(iz1,jz0);
181 dx20 = _mm_sub_pd(ix2,jx0);
182 dy20 = _mm_sub_pd(iy2,jy0);
183 dz20 = _mm_sub_pd(iz2,jz0);
184 dx30 = _mm_sub_pd(ix3,jx0);
185 dy30 = _mm_sub_pd(iy3,jy0);
186 dz30 = _mm_sub_pd(iz3,jz0);
188 /* Calculate squared distance and things based on it */
189 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
190 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
191 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
193 rinv10 = sse41_invsqrt_d(rsq10);
194 rinv20 = sse41_invsqrt_d(rsq20);
195 rinv30 = sse41_invsqrt_d(rsq30);
197 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
198 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
199 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
201 /* Load parameters for j particles */
202 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
204 fjx0 = _mm_setzero_pd();
205 fjy0 = _mm_setzero_pd();
206 fjz0 = _mm_setzero_pd();
208 /**************************
209 * CALCULATE INTERACTIONS *
210 **************************/
212 if (gmx_mm_any_lt(rsq10,rcutoff2))
215 /* Compute parameters for interactions between i and j atoms */
216 qq10 = _mm_mul_pd(iq1,jq0);
218 /* REACTION-FIELD ELECTROSTATICS */
219 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_add_pd(rinv10,_mm_mul_pd(krf,rsq10)),crf));
220 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
222 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
224 /* Update potential sum for this i atom from the interaction with this j atom. */
225 velec = _mm_and_pd(velec,cutoff_mask);
226 velecsum = _mm_add_pd(velecsum,velec);
230 fscal = _mm_and_pd(fscal,cutoff_mask);
232 /* Calculate temporary vectorial force */
233 tx = _mm_mul_pd(fscal,dx10);
234 ty = _mm_mul_pd(fscal,dy10);
235 tz = _mm_mul_pd(fscal,dz10);
237 /* Update vectorial force */
238 fix1 = _mm_add_pd(fix1,tx);
239 fiy1 = _mm_add_pd(fiy1,ty);
240 fiz1 = _mm_add_pd(fiz1,tz);
242 fjx0 = _mm_add_pd(fjx0,tx);
243 fjy0 = _mm_add_pd(fjy0,ty);
244 fjz0 = _mm_add_pd(fjz0,tz);
248 /**************************
249 * CALCULATE INTERACTIONS *
250 **************************/
252 if (gmx_mm_any_lt(rsq20,rcutoff2))
255 /* Compute parameters for interactions between i and j atoms */
256 qq20 = _mm_mul_pd(iq2,jq0);
258 /* REACTION-FIELD ELECTROSTATICS */
259 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_add_pd(rinv20,_mm_mul_pd(krf,rsq20)),crf));
260 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
262 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
264 /* Update potential sum for this i atom from the interaction with this j atom. */
265 velec = _mm_and_pd(velec,cutoff_mask);
266 velecsum = _mm_add_pd(velecsum,velec);
270 fscal = _mm_and_pd(fscal,cutoff_mask);
272 /* Calculate temporary vectorial force */
273 tx = _mm_mul_pd(fscal,dx20);
274 ty = _mm_mul_pd(fscal,dy20);
275 tz = _mm_mul_pd(fscal,dz20);
277 /* Update vectorial force */
278 fix2 = _mm_add_pd(fix2,tx);
279 fiy2 = _mm_add_pd(fiy2,ty);
280 fiz2 = _mm_add_pd(fiz2,tz);
282 fjx0 = _mm_add_pd(fjx0,tx);
283 fjy0 = _mm_add_pd(fjy0,ty);
284 fjz0 = _mm_add_pd(fjz0,tz);
288 /**************************
289 * CALCULATE INTERACTIONS *
290 **************************/
292 if (gmx_mm_any_lt(rsq30,rcutoff2))
295 /* Compute parameters for interactions between i and j atoms */
296 qq30 = _mm_mul_pd(iq3,jq0);
298 /* REACTION-FIELD ELECTROSTATICS */
299 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_add_pd(rinv30,_mm_mul_pd(krf,rsq30)),crf));
300 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
302 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
304 /* Update potential sum for this i atom from the interaction with this j atom. */
305 velec = _mm_and_pd(velec,cutoff_mask);
306 velecsum = _mm_add_pd(velecsum,velec);
310 fscal = _mm_and_pd(fscal,cutoff_mask);
312 /* Calculate temporary vectorial force */
313 tx = _mm_mul_pd(fscal,dx30);
314 ty = _mm_mul_pd(fscal,dy30);
315 tz = _mm_mul_pd(fscal,dz30);
317 /* Update vectorial force */
318 fix3 = _mm_add_pd(fix3,tx);
319 fiy3 = _mm_add_pd(fiy3,ty);
320 fiz3 = _mm_add_pd(fiz3,tz);
322 fjx0 = _mm_add_pd(fjx0,tx);
323 fjy0 = _mm_add_pd(fjy0,ty);
324 fjz0 = _mm_add_pd(fjz0,tz);
328 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
330 /* Inner loop uses 111 flops */
337 j_coord_offsetA = DIM*jnrA;
339 /* load j atom coordinates */
340 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
343 /* Calculate displacement vector */
344 dx10 = _mm_sub_pd(ix1,jx0);
345 dy10 = _mm_sub_pd(iy1,jy0);
346 dz10 = _mm_sub_pd(iz1,jz0);
347 dx20 = _mm_sub_pd(ix2,jx0);
348 dy20 = _mm_sub_pd(iy2,jy0);
349 dz20 = _mm_sub_pd(iz2,jz0);
350 dx30 = _mm_sub_pd(ix3,jx0);
351 dy30 = _mm_sub_pd(iy3,jy0);
352 dz30 = _mm_sub_pd(iz3,jz0);
354 /* Calculate squared distance and things based on it */
355 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
356 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
357 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
359 rinv10 = sse41_invsqrt_d(rsq10);
360 rinv20 = sse41_invsqrt_d(rsq20);
361 rinv30 = sse41_invsqrt_d(rsq30);
363 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
364 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
365 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
367 /* Load parameters for j particles */
368 jq0 = _mm_load_sd(charge+jnrA+0);
370 fjx0 = _mm_setzero_pd();
371 fjy0 = _mm_setzero_pd();
372 fjz0 = _mm_setzero_pd();
374 /**************************
375 * CALCULATE INTERACTIONS *
376 **************************/
378 if (gmx_mm_any_lt(rsq10,rcutoff2))
381 /* Compute parameters for interactions between i and j atoms */
382 qq10 = _mm_mul_pd(iq1,jq0);
384 /* REACTION-FIELD ELECTROSTATICS */
385 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_add_pd(rinv10,_mm_mul_pd(krf,rsq10)),crf));
386 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
388 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
390 /* Update potential sum for this i atom from the interaction with this j atom. */
391 velec = _mm_and_pd(velec,cutoff_mask);
392 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
393 velecsum = _mm_add_pd(velecsum,velec);
397 fscal = _mm_and_pd(fscal,cutoff_mask);
399 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
401 /* Calculate temporary vectorial force */
402 tx = _mm_mul_pd(fscal,dx10);
403 ty = _mm_mul_pd(fscal,dy10);
404 tz = _mm_mul_pd(fscal,dz10);
406 /* Update vectorial force */
407 fix1 = _mm_add_pd(fix1,tx);
408 fiy1 = _mm_add_pd(fiy1,ty);
409 fiz1 = _mm_add_pd(fiz1,tz);
411 fjx0 = _mm_add_pd(fjx0,tx);
412 fjy0 = _mm_add_pd(fjy0,ty);
413 fjz0 = _mm_add_pd(fjz0,tz);
417 /**************************
418 * CALCULATE INTERACTIONS *
419 **************************/
421 if (gmx_mm_any_lt(rsq20,rcutoff2))
424 /* Compute parameters for interactions between i and j atoms */
425 qq20 = _mm_mul_pd(iq2,jq0);
427 /* REACTION-FIELD ELECTROSTATICS */
428 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_add_pd(rinv20,_mm_mul_pd(krf,rsq20)),crf));
429 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
431 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
433 /* Update potential sum for this i atom from the interaction with this j atom. */
434 velec = _mm_and_pd(velec,cutoff_mask);
435 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
436 velecsum = _mm_add_pd(velecsum,velec);
440 fscal = _mm_and_pd(fscal,cutoff_mask);
442 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
444 /* Calculate temporary vectorial force */
445 tx = _mm_mul_pd(fscal,dx20);
446 ty = _mm_mul_pd(fscal,dy20);
447 tz = _mm_mul_pd(fscal,dz20);
449 /* Update vectorial force */
450 fix2 = _mm_add_pd(fix2,tx);
451 fiy2 = _mm_add_pd(fiy2,ty);
452 fiz2 = _mm_add_pd(fiz2,tz);
454 fjx0 = _mm_add_pd(fjx0,tx);
455 fjy0 = _mm_add_pd(fjy0,ty);
456 fjz0 = _mm_add_pd(fjz0,tz);
460 /**************************
461 * CALCULATE INTERACTIONS *
462 **************************/
464 if (gmx_mm_any_lt(rsq30,rcutoff2))
467 /* Compute parameters for interactions between i and j atoms */
468 qq30 = _mm_mul_pd(iq3,jq0);
470 /* REACTION-FIELD ELECTROSTATICS */
471 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_add_pd(rinv30,_mm_mul_pd(krf,rsq30)),crf));
472 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
474 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
476 /* Update potential sum for this i atom from the interaction with this j atom. */
477 velec = _mm_and_pd(velec,cutoff_mask);
478 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
479 velecsum = _mm_add_pd(velecsum,velec);
483 fscal = _mm_and_pd(fscal,cutoff_mask);
485 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
487 /* Calculate temporary vectorial force */
488 tx = _mm_mul_pd(fscal,dx30);
489 ty = _mm_mul_pd(fscal,dy30);
490 tz = _mm_mul_pd(fscal,dz30);
492 /* Update vectorial force */
493 fix3 = _mm_add_pd(fix3,tx);
494 fiy3 = _mm_add_pd(fiy3,ty);
495 fiz3 = _mm_add_pd(fiz3,tz);
497 fjx0 = _mm_add_pd(fjx0,tx);
498 fjy0 = _mm_add_pd(fjy0,ty);
499 fjz0 = _mm_add_pd(fjz0,tz);
503 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
505 /* Inner loop uses 111 flops */
508 /* End of innermost loop */
510 gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
511 f+i_coord_offset+DIM,fshift+i_shift_offset);
514 /* Update potential energies */
515 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
517 /* Increment number of inner iterations */
518 inneriter += j_index_end - j_index_start;
520 /* Outer loop uses 19 flops */
523 /* Increment number of outer iterations */
526 /* Update outer/inner flops */
528 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*111);
531 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_sse4_1_double
532 * Electrostatics interaction: ReactionField
533 * VdW interaction: None
534 * Geometry: Water4-Particle
535 * Calculate force/pot: Force
538 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_sse4_1_double
539 (t_nblist * gmx_restrict nlist,
540 rvec * gmx_restrict xx,
541 rvec * gmx_restrict ff,
542 struct t_forcerec * gmx_restrict fr,
543 t_mdatoms * gmx_restrict mdatoms,
544 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
545 t_nrnb * gmx_restrict nrnb)
547 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
548 * just 0 for non-waters.
549 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
550 * jnr indices corresponding to data put in the four positions in the SIMD register.
552 int i_shift_offset,i_coord_offset,outeriter,inneriter;
553 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
555 int j_coord_offsetA,j_coord_offsetB;
556 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
558 real *shiftvec,*fshift,*x,*f;
559 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
561 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
563 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
565 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
566 int vdwjidx0A,vdwjidx0B;
567 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
568 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
569 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
570 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
571 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
573 __m128d dummy_mask,cutoff_mask;
574 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
575 __m128d one = _mm_set1_pd(1.0);
576 __m128d two = _mm_set1_pd(2.0);
582 jindex = nlist->jindex;
584 shiftidx = nlist->shift;
586 shiftvec = fr->shift_vec[0];
587 fshift = fr->fshift[0];
588 facel = _mm_set1_pd(fr->ic->epsfac);
589 charge = mdatoms->chargeA;
590 krf = _mm_set1_pd(fr->ic->k_rf);
591 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
592 crf = _mm_set1_pd(fr->ic->c_rf);
594 /* Setup water-specific parameters */
595 inr = nlist->iinr[0];
596 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
597 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
598 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
600 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
601 rcutoff_scalar = fr->ic->rcoulomb;
602 rcutoff = _mm_set1_pd(rcutoff_scalar);
603 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
605 /* Avoid stupid compiler warnings */
613 /* Start outer loop over neighborlists */
614 for(iidx=0; iidx<nri; iidx++)
616 /* Load shift vector for this list */
617 i_shift_offset = DIM*shiftidx[iidx];
619 /* Load limits for loop over neighbors */
620 j_index_start = jindex[iidx];
621 j_index_end = jindex[iidx+1];
623 /* Get outer coordinate index */
625 i_coord_offset = DIM*inr;
627 /* Load i particle coords and add shift vector */
628 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
629 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
631 fix1 = _mm_setzero_pd();
632 fiy1 = _mm_setzero_pd();
633 fiz1 = _mm_setzero_pd();
634 fix2 = _mm_setzero_pd();
635 fiy2 = _mm_setzero_pd();
636 fiz2 = _mm_setzero_pd();
637 fix3 = _mm_setzero_pd();
638 fiy3 = _mm_setzero_pd();
639 fiz3 = _mm_setzero_pd();
641 /* Start inner kernel loop */
642 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
645 /* Get j neighbor index, and coordinate index */
648 j_coord_offsetA = DIM*jnrA;
649 j_coord_offsetB = DIM*jnrB;
651 /* load j atom coordinates */
652 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
655 /* Calculate displacement vector */
656 dx10 = _mm_sub_pd(ix1,jx0);
657 dy10 = _mm_sub_pd(iy1,jy0);
658 dz10 = _mm_sub_pd(iz1,jz0);
659 dx20 = _mm_sub_pd(ix2,jx0);
660 dy20 = _mm_sub_pd(iy2,jy0);
661 dz20 = _mm_sub_pd(iz2,jz0);
662 dx30 = _mm_sub_pd(ix3,jx0);
663 dy30 = _mm_sub_pd(iy3,jy0);
664 dz30 = _mm_sub_pd(iz3,jz0);
666 /* Calculate squared distance and things based on it */
667 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
668 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
669 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
671 rinv10 = sse41_invsqrt_d(rsq10);
672 rinv20 = sse41_invsqrt_d(rsq20);
673 rinv30 = sse41_invsqrt_d(rsq30);
675 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
676 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
677 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
679 /* Load parameters for j particles */
680 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
682 fjx0 = _mm_setzero_pd();
683 fjy0 = _mm_setzero_pd();
684 fjz0 = _mm_setzero_pd();
686 /**************************
687 * CALCULATE INTERACTIONS *
688 **************************/
690 if (gmx_mm_any_lt(rsq10,rcutoff2))
693 /* Compute parameters for interactions between i and j atoms */
694 qq10 = _mm_mul_pd(iq1,jq0);
696 /* REACTION-FIELD ELECTROSTATICS */
697 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
699 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
703 fscal = _mm_and_pd(fscal,cutoff_mask);
705 /* Calculate temporary vectorial force */
706 tx = _mm_mul_pd(fscal,dx10);
707 ty = _mm_mul_pd(fscal,dy10);
708 tz = _mm_mul_pd(fscal,dz10);
710 /* Update vectorial force */
711 fix1 = _mm_add_pd(fix1,tx);
712 fiy1 = _mm_add_pd(fiy1,ty);
713 fiz1 = _mm_add_pd(fiz1,tz);
715 fjx0 = _mm_add_pd(fjx0,tx);
716 fjy0 = _mm_add_pd(fjy0,ty);
717 fjz0 = _mm_add_pd(fjz0,tz);
721 /**************************
722 * CALCULATE INTERACTIONS *
723 **************************/
725 if (gmx_mm_any_lt(rsq20,rcutoff2))
728 /* Compute parameters for interactions between i and j atoms */
729 qq20 = _mm_mul_pd(iq2,jq0);
731 /* REACTION-FIELD ELECTROSTATICS */
732 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
734 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
738 fscal = _mm_and_pd(fscal,cutoff_mask);
740 /* Calculate temporary vectorial force */
741 tx = _mm_mul_pd(fscal,dx20);
742 ty = _mm_mul_pd(fscal,dy20);
743 tz = _mm_mul_pd(fscal,dz20);
745 /* Update vectorial force */
746 fix2 = _mm_add_pd(fix2,tx);
747 fiy2 = _mm_add_pd(fiy2,ty);
748 fiz2 = _mm_add_pd(fiz2,tz);
750 fjx0 = _mm_add_pd(fjx0,tx);
751 fjy0 = _mm_add_pd(fjy0,ty);
752 fjz0 = _mm_add_pd(fjz0,tz);
756 /**************************
757 * CALCULATE INTERACTIONS *
758 **************************/
760 if (gmx_mm_any_lt(rsq30,rcutoff2))
763 /* Compute parameters for interactions between i and j atoms */
764 qq30 = _mm_mul_pd(iq3,jq0);
766 /* REACTION-FIELD ELECTROSTATICS */
767 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
769 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
773 fscal = _mm_and_pd(fscal,cutoff_mask);
775 /* Calculate temporary vectorial force */
776 tx = _mm_mul_pd(fscal,dx30);
777 ty = _mm_mul_pd(fscal,dy30);
778 tz = _mm_mul_pd(fscal,dz30);
780 /* Update vectorial force */
781 fix3 = _mm_add_pd(fix3,tx);
782 fiy3 = _mm_add_pd(fiy3,ty);
783 fiz3 = _mm_add_pd(fiz3,tz);
785 fjx0 = _mm_add_pd(fjx0,tx);
786 fjy0 = _mm_add_pd(fjy0,ty);
787 fjz0 = _mm_add_pd(fjz0,tz);
791 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
793 /* Inner loop uses 93 flops */
800 j_coord_offsetA = DIM*jnrA;
802 /* load j atom coordinates */
803 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
806 /* Calculate displacement vector */
807 dx10 = _mm_sub_pd(ix1,jx0);
808 dy10 = _mm_sub_pd(iy1,jy0);
809 dz10 = _mm_sub_pd(iz1,jz0);
810 dx20 = _mm_sub_pd(ix2,jx0);
811 dy20 = _mm_sub_pd(iy2,jy0);
812 dz20 = _mm_sub_pd(iz2,jz0);
813 dx30 = _mm_sub_pd(ix3,jx0);
814 dy30 = _mm_sub_pd(iy3,jy0);
815 dz30 = _mm_sub_pd(iz3,jz0);
817 /* Calculate squared distance and things based on it */
818 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
819 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
820 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
822 rinv10 = sse41_invsqrt_d(rsq10);
823 rinv20 = sse41_invsqrt_d(rsq20);
824 rinv30 = sse41_invsqrt_d(rsq30);
826 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
827 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
828 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
830 /* Load parameters for j particles */
831 jq0 = _mm_load_sd(charge+jnrA+0);
833 fjx0 = _mm_setzero_pd();
834 fjy0 = _mm_setzero_pd();
835 fjz0 = _mm_setzero_pd();
837 /**************************
838 * CALCULATE INTERACTIONS *
839 **************************/
841 if (gmx_mm_any_lt(rsq10,rcutoff2))
844 /* Compute parameters for interactions between i and j atoms */
845 qq10 = _mm_mul_pd(iq1,jq0);
847 /* REACTION-FIELD ELECTROSTATICS */
848 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
850 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
854 fscal = _mm_and_pd(fscal,cutoff_mask);
856 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
858 /* Calculate temporary vectorial force */
859 tx = _mm_mul_pd(fscal,dx10);
860 ty = _mm_mul_pd(fscal,dy10);
861 tz = _mm_mul_pd(fscal,dz10);
863 /* Update vectorial force */
864 fix1 = _mm_add_pd(fix1,tx);
865 fiy1 = _mm_add_pd(fiy1,ty);
866 fiz1 = _mm_add_pd(fiz1,tz);
868 fjx0 = _mm_add_pd(fjx0,tx);
869 fjy0 = _mm_add_pd(fjy0,ty);
870 fjz0 = _mm_add_pd(fjz0,tz);
874 /**************************
875 * CALCULATE INTERACTIONS *
876 **************************/
878 if (gmx_mm_any_lt(rsq20,rcutoff2))
881 /* Compute parameters for interactions between i and j atoms */
882 qq20 = _mm_mul_pd(iq2,jq0);
884 /* REACTION-FIELD ELECTROSTATICS */
885 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
887 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
891 fscal = _mm_and_pd(fscal,cutoff_mask);
893 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
895 /* Calculate temporary vectorial force */
896 tx = _mm_mul_pd(fscal,dx20);
897 ty = _mm_mul_pd(fscal,dy20);
898 tz = _mm_mul_pd(fscal,dz20);
900 /* Update vectorial force */
901 fix2 = _mm_add_pd(fix2,tx);
902 fiy2 = _mm_add_pd(fiy2,ty);
903 fiz2 = _mm_add_pd(fiz2,tz);
905 fjx0 = _mm_add_pd(fjx0,tx);
906 fjy0 = _mm_add_pd(fjy0,ty);
907 fjz0 = _mm_add_pd(fjz0,tz);
911 /**************************
912 * CALCULATE INTERACTIONS *
913 **************************/
915 if (gmx_mm_any_lt(rsq30,rcutoff2))
918 /* Compute parameters for interactions between i and j atoms */
919 qq30 = _mm_mul_pd(iq3,jq0);
921 /* REACTION-FIELD ELECTROSTATICS */
922 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
924 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
928 fscal = _mm_and_pd(fscal,cutoff_mask);
930 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
932 /* Calculate temporary vectorial force */
933 tx = _mm_mul_pd(fscal,dx30);
934 ty = _mm_mul_pd(fscal,dy30);
935 tz = _mm_mul_pd(fscal,dz30);
937 /* Update vectorial force */
938 fix3 = _mm_add_pd(fix3,tx);
939 fiy3 = _mm_add_pd(fiy3,ty);
940 fiz3 = _mm_add_pd(fiz3,tz);
942 fjx0 = _mm_add_pd(fjx0,tx);
943 fjy0 = _mm_add_pd(fjy0,ty);
944 fjz0 = _mm_add_pd(fjz0,tz);
948 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
950 /* Inner loop uses 93 flops */
953 /* End of innermost loop */
955 gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
956 f+i_coord_offset+DIM,fshift+i_shift_offset);
958 /* Increment number of inner iterations */
959 inneriter += j_index_end - j_index_start;
961 /* Outer loop uses 18 flops */
964 /* Increment number of outer iterations */
967 /* Update outer/inner flops */
969 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*93);