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_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_avx_128_fma_double
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_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
77 int j_coord_offsetA,j_coord_offsetB;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
80 real *shiftvec,*fshift,*x,*f;
81 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
91 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
92 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
93 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
95 __m128d dummy_mask,cutoff_mask;
96 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
97 __m128d one = _mm_set1_pd(1.0);
98 __m128d two = _mm_set1_pd(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_pd(fr->epsfac);
111 charge = mdatoms->chargeA;
112 krf = _mm_set1_pd(fr->ic->k_rf);
113 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
114 crf = _mm_set1_pd(fr->ic->c_rf);
116 /* Setup water-specific parameters */
117 inr = nlist->iinr[0];
118 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
119 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
120 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
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->rcoulomb;
124 rcutoff = _mm_set1_pd(rcutoff_scalar);
125 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
127 /* Avoid stupid compiler warnings */
135 /* Start outer loop over neighborlists */
136 for(iidx=0; iidx<nri; iidx++)
138 /* Load shift vector for this list */
139 i_shift_offset = DIM*shiftidx[iidx];
141 /* Load limits for loop over neighbors */
142 j_index_start = jindex[iidx];
143 j_index_end = jindex[iidx+1];
145 /* Get outer coordinate index */
147 i_coord_offset = DIM*inr;
149 /* Load i particle coords and add shift vector */
150 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
151 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
153 fix1 = _mm_setzero_pd();
154 fiy1 = _mm_setzero_pd();
155 fiz1 = _mm_setzero_pd();
156 fix2 = _mm_setzero_pd();
157 fiy2 = _mm_setzero_pd();
158 fiz2 = _mm_setzero_pd();
159 fix3 = _mm_setzero_pd();
160 fiy3 = _mm_setzero_pd();
161 fiz3 = _mm_setzero_pd();
163 /* Reset potential sums */
164 velecsum = _mm_setzero_pd();
166 /* Start inner kernel loop */
167 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
170 /* Get j neighbor index, and coordinate index */
173 j_coord_offsetA = DIM*jnrA;
174 j_coord_offsetB = DIM*jnrB;
176 /* load j atom coordinates */
177 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
180 /* Calculate displacement vector */
181 dx10 = _mm_sub_pd(ix1,jx0);
182 dy10 = _mm_sub_pd(iy1,jy0);
183 dz10 = _mm_sub_pd(iz1,jz0);
184 dx20 = _mm_sub_pd(ix2,jx0);
185 dy20 = _mm_sub_pd(iy2,jy0);
186 dz20 = _mm_sub_pd(iz2,jz0);
187 dx30 = _mm_sub_pd(ix3,jx0);
188 dy30 = _mm_sub_pd(iy3,jy0);
189 dz30 = _mm_sub_pd(iz3,jz0);
191 /* Calculate squared distance and things based on it */
192 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
193 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
194 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
196 rinv10 = gmx_mm_invsqrt_pd(rsq10);
197 rinv20 = gmx_mm_invsqrt_pd(rsq20);
198 rinv30 = gmx_mm_invsqrt_pd(rsq30);
200 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
201 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
202 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
204 /* Load parameters for j particles */
205 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
207 fjx0 = _mm_setzero_pd();
208 fjy0 = _mm_setzero_pd();
209 fjz0 = _mm_setzero_pd();
211 /**************************
212 * CALCULATE INTERACTIONS *
213 **************************/
215 if (gmx_mm_any_lt(rsq10,rcutoff2))
218 /* Compute parameters for interactions between i and j atoms */
219 qq10 = _mm_mul_pd(iq1,jq0);
221 /* REACTION-FIELD ELECTROSTATICS */
222 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
223 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
225 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
227 /* Update potential sum for this i atom from the interaction with this j atom. */
228 velec = _mm_and_pd(velec,cutoff_mask);
229 velecsum = _mm_add_pd(velecsum,velec);
233 fscal = _mm_and_pd(fscal,cutoff_mask);
235 /* Update vectorial force */
236 fix1 = _mm_macc_pd(dx10,fscal,fix1);
237 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
238 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
240 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
241 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
242 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
246 /**************************
247 * CALCULATE INTERACTIONS *
248 **************************/
250 if (gmx_mm_any_lt(rsq20,rcutoff2))
253 /* Compute parameters for interactions between i and j atoms */
254 qq20 = _mm_mul_pd(iq2,jq0);
256 /* REACTION-FIELD ELECTROSTATICS */
257 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
258 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
260 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
262 /* Update potential sum for this i atom from the interaction with this j atom. */
263 velec = _mm_and_pd(velec,cutoff_mask);
264 velecsum = _mm_add_pd(velecsum,velec);
268 fscal = _mm_and_pd(fscal,cutoff_mask);
270 /* Update vectorial force */
271 fix2 = _mm_macc_pd(dx20,fscal,fix2);
272 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
273 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
275 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
276 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
277 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
281 /**************************
282 * CALCULATE INTERACTIONS *
283 **************************/
285 if (gmx_mm_any_lt(rsq30,rcutoff2))
288 /* Compute parameters for interactions between i and j atoms */
289 qq30 = _mm_mul_pd(iq3,jq0);
291 /* REACTION-FIELD ELECTROSTATICS */
292 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
293 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
295 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
297 /* Update potential sum for this i atom from the interaction with this j atom. */
298 velec = _mm_and_pd(velec,cutoff_mask);
299 velecsum = _mm_add_pd(velecsum,velec);
303 fscal = _mm_and_pd(fscal,cutoff_mask);
305 /* Update vectorial force */
306 fix3 = _mm_macc_pd(dx30,fscal,fix3);
307 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
308 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
310 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
311 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
312 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
316 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
318 /* Inner loop uses 120 flops */
325 j_coord_offsetA = DIM*jnrA;
327 /* load j atom coordinates */
328 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
331 /* Calculate displacement vector */
332 dx10 = _mm_sub_pd(ix1,jx0);
333 dy10 = _mm_sub_pd(iy1,jy0);
334 dz10 = _mm_sub_pd(iz1,jz0);
335 dx20 = _mm_sub_pd(ix2,jx0);
336 dy20 = _mm_sub_pd(iy2,jy0);
337 dz20 = _mm_sub_pd(iz2,jz0);
338 dx30 = _mm_sub_pd(ix3,jx0);
339 dy30 = _mm_sub_pd(iy3,jy0);
340 dz30 = _mm_sub_pd(iz3,jz0);
342 /* Calculate squared distance and things based on it */
343 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
344 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
345 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
347 rinv10 = gmx_mm_invsqrt_pd(rsq10);
348 rinv20 = gmx_mm_invsqrt_pd(rsq20);
349 rinv30 = gmx_mm_invsqrt_pd(rsq30);
351 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
352 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
353 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
355 /* Load parameters for j particles */
356 jq0 = _mm_load_sd(charge+jnrA+0);
358 fjx0 = _mm_setzero_pd();
359 fjy0 = _mm_setzero_pd();
360 fjz0 = _mm_setzero_pd();
362 /**************************
363 * CALCULATE INTERACTIONS *
364 **************************/
366 if (gmx_mm_any_lt(rsq10,rcutoff2))
369 /* Compute parameters for interactions between i and j atoms */
370 qq10 = _mm_mul_pd(iq1,jq0);
372 /* REACTION-FIELD ELECTROSTATICS */
373 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
374 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
376 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
378 /* Update potential sum for this i atom from the interaction with this j atom. */
379 velec = _mm_and_pd(velec,cutoff_mask);
380 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
381 velecsum = _mm_add_pd(velecsum,velec);
385 fscal = _mm_and_pd(fscal,cutoff_mask);
387 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
389 /* Update vectorial force */
390 fix1 = _mm_macc_pd(dx10,fscal,fix1);
391 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
392 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
394 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
395 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
396 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
400 /**************************
401 * CALCULATE INTERACTIONS *
402 **************************/
404 if (gmx_mm_any_lt(rsq20,rcutoff2))
407 /* Compute parameters for interactions between i and j atoms */
408 qq20 = _mm_mul_pd(iq2,jq0);
410 /* REACTION-FIELD ELECTROSTATICS */
411 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
412 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
414 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
416 /* Update potential sum for this i atom from the interaction with this j atom. */
417 velec = _mm_and_pd(velec,cutoff_mask);
418 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
419 velecsum = _mm_add_pd(velecsum,velec);
423 fscal = _mm_and_pd(fscal,cutoff_mask);
425 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
427 /* Update vectorial force */
428 fix2 = _mm_macc_pd(dx20,fscal,fix2);
429 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
430 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
432 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
433 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
434 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
438 /**************************
439 * CALCULATE INTERACTIONS *
440 **************************/
442 if (gmx_mm_any_lt(rsq30,rcutoff2))
445 /* Compute parameters for interactions between i and j atoms */
446 qq30 = _mm_mul_pd(iq3,jq0);
448 /* REACTION-FIELD ELECTROSTATICS */
449 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
450 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
452 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
454 /* Update potential sum for this i atom from the interaction with this j atom. */
455 velec = _mm_and_pd(velec,cutoff_mask);
456 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
457 velecsum = _mm_add_pd(velecsum,velec);
461 fscal = _mm_and_pd(fscal,cutoff_mask);
463 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
465 /* Update vectorial force */
466 fix3 = _mm_macc_pd(dx30,fscal,fix3);
467 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
468 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
470 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
471 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
472 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
476 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
478 /* Inner loop uses 120 flops */
481 /* End of innermost loop */
483 gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
484 f+i_coord_offset+DIM,fshift+i_shift_offset);
487 /* Update potential energies */
488 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
490 /* Increment number of inner iterations */
491 inneriter += j_index_end - j_index_start;
493 /* Outer loop uses 19 flops */
496 /* Increment number of outer iterations */
499 /* Update outer/inner flops */
501 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*120);
504 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_avx_128_fma_double
505 * Electrostatics interaction: ReactionField
506 * VdW interaction: None
507 * Geometry: Water4-Particle
508 * Calculate force/pot: Force
511 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_avx_128_fma_double
512 (t_nblist * gmx_restrict nlist,
513 rvec * gmx_restrict xx,
514 rvec * gmx_restrict ff,
515 t_forcerec * gmx_restrict fr,
516 t_mdatoms * gmx_restrict mdatoms,
517 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
518 t_nrnb * gmx_restrict nrnb)
520 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
521 * just 0 for non-waters.
522 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
523 * jnr indices corresponding to data put in the four positions in the SIMD register.
525 int i_shift_offset,i_coord_offset,outeriter,inneriter;
526 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
528 int j_coord_offsetA,j_coord_offsetB;
529 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
531 real *shiftvec,*fshift,*x,*f;
532 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
534 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
536 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
538 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
539 int vdwjidx0A,vdwjidx0B;
540 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
541 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
542 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
543 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
544 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
546 __m128d dummy_mask,cutoff_mask;
547 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
548 __m128d one = _mm_set1_pd(1.0);
549 __m128d two = _mm_set1_pd(2.0);
555 jindex = nlist->jindex;
557 shiftidx = nlist->shift;
559 shiftvec = fr->shift_vec[0];
560 fshift = fr->fshift[0];
561 facel = _mm_set1_pd(fr->epsfac);
562 charge = mdatoms->chargeA;
563 krf = _mm_set1_pd(fr->ic->k_rf);
564 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
565 crf = _mm_set1_pd(fr->ic->c_rf);
567 /* Setup water-specific parameters */
568 inr = nlist->iinr[0];
569 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
570 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
571 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
573 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
574 rcutoff_scalar = fr->rcoulomb;
575 rcutoff = _mm_set1_pd(rcutoff_scalar);
576 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
578 /* Avoid stupid compiler warnings */
586 /* Start outer loop over neighborlists */
587 for(iidx=0; iidx<nri; iidx++)
589 /* Load shift vector for this list */
590 i_shift_offset = DIM*shiftidx[iidx];
592 /* Load limits for loop over neighbors */
593 j_index_start = jindex[iidx];
594 j_index_end = jindex[iidx+1];
596 /* Get outer coordinate index */
598 i_coord_offset = DIM*inr;
600 /* Load i particle coords and add shift vector */
601 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
602 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
604 fix1 = _mm_setzero_pd();
605 fiy1 = _mm_setzero_pd();
606 fiz1 = _mm_setzero_pd();
607 fix2 = _mm_setzero_pd();
608 fiy2 = _mm_setzero_pd();
609 fiz2 = _mm_setzero_pd();
610 fix3 = _mm_setzero_pd();
611 fiy3 = _mm_setzero_pd();
612 fiz3 = _mm_setzero_pd();
614 /* Start inner kernel loop */
615 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
618 /* Get j neighbor index, and coordinate index */
621 j_coord_offsetA = DIM*jnrA;
622 j_coord_offsetB = DIM*jnrB;
624 /* load j atom coordinates */
625 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
628 /* Calculate displacement vector */
629 dx10 = _mm_sub_pd(ix1,jx0);
630 dy10 = _mm_sub_pd(iy1,jy0);
631 dz10 = _mm_sub_pd(iz1,jz0);
632 dx20 = _mm_sub_pd(ix2,jx0);
633 dy20 = _mm_sub_pd(iy2,jy0);
634 dz20 = _mm_sub_pd(iz2,jz0);
635 dx30 = _mm_sub_pd(ix3,jx0);
636 dy30 = _mm_sub_pd(iy3,jy0);
637 dz30 = _mm_sub_pd(iz3,jz0);
639 /* Calculate squared distance and things based on it */
640 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
641 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
642 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
644 rinv10 = gmx_mm_invsqrt_pd(rsq10);
645 rinv20 = gmx_mm_invsqrt_pd(rsq20);
646 rinv30 = gmx_mm_invsqrt_pd(rsq30);
648 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
649 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
650 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
652 /* Load parameters for j particles */
653 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
655 fjx0 = _mm_setzero_pd();
656 fjy0 = _mm_setzero_pd();
657 fjz0 = _mm_setzero_pd();
659 /**************************
660 * CALCULATE INTERACTIONS *
661 **************************/
663 if (gmx_mm_any_lt(rsq10,rcutoff2))
666 /* Compute parameters for interactions between i and j atoms */
667 qq10 = _mm_mul_pd(iq1,jq0);
669 /* REACTION-FIELD ELECTROSTATICS */
670 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
672 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
676 fscal = _mm_and_pd(fscal,cutoff_mask);
678 /* Update vectorial force */
679 fix1 = _mm_macc_pd(dx10,fscal,fix1);
680 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
681 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
683 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
684 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
685 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
689 /**************************
690 * CALCULATE INTERACTIONS *
691 **************************/
693 if (gmx_mm_any_lt(rsq20,rcutoff2))
696 /* Compute parameters for interactions between i and j atoms */
697 qq20 = _mm_mul_pd(iq2,jq0);
699 /* REACTION-FIELD ELECTROSTATICS */
700 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
702 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
706 fscal = _mm_and_pd(fscal,cutoff_mask);
708 /* Update vectorial force */
709 fix2 = _mm_macc_pd(dx20,fscal,fix2);
710 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
711 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
713 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
714 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
715 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
719 /**************************
720 * CALCULATE INTERACTIONS *
721 **************************/
723 if (gmx_mm_any_lt(rsq30,rcutoff2))
726 /* Compute parameters for interactions between i and j atoms */
727 qq30 = _mm_mul_pd(iq3,jq0);
729 /* REACTION-FIELD ELECTROSTATICS */
730 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
732 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
736 fscal = _mm_and_pd(fscal,cutoff_mask);
738 /* Update vectorial force */
739 fix3 = _mm_macc_pd(dx30,fscal,fix3);
740 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
741 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
743 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
744 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
745 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
749 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
751 /* Inner loop uses 102 flops */
758 j_coord_offsetA = DIM*jnrA;
760 /* load j atom coordinates */
761 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
764 /* Calculate displacement vector */
765 dx10 = _mm_sub_pd(ix1,jx0);
766 dy10 = _mm_sub_pd(iy1,jy0);
767 dz10 = _mm_sub_pd(iz1,jz0);
768 dx20 = _mm_sub_pd(ix2,jx0);
769 dy20 = _mm_sub_pd(iy2,jy0);
770 dz20 = _mm_sub_pd(iz2,jz0);
771 dx30 = _mm_sub_pd(ix3,jx0);
772 dy30 = _mm_sub_pd(iy3,jy0);
773 dz30 = _mm_sub_pd(iz3,jz0);
775 /* Calculate squared distance and things based on it */
776 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
777 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
778 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
780 rinv10 = gmx_mm_invsqrt_pd(rsq10);
781 rinv20 = gmx_mm_invsqrt_pd(rsq20);
782 rinv30 = gmx_mm_invsqrt_pd(rsq30);
784 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
785 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
786 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
788 /* Load parameters for j particles */
789 jq0 = _mm_load_sd(charge+jnrA+0);
791 fjx0 = _mm_setzero_pd();
792 fjy0 = _mm_setzero_pd();
793 fjz0 = _mm_setzero_pd();
795 /**************************
796 * CALCULATE INTERACTIONS *
797 **************************/
799 if (gmx_mm_any_lt(rsq10,rcutoff2))
802 /* Compute parameters for interactions between i and j atoms */
803 qq10 = _mm_mul_pd(iq1,jq0);
805 /* REACTION-FIELD ELECTROSTATICS */
806 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
808 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
812 fscal = _mm_and_pd(fscal,cutoff_mask);
814 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
816 /* Update vectorial force */
817 fix1 = _mm_macc_pd(dx10,fscal,fix1);
818 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
819 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
821 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
822 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
823 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
827 /**************************
828 * CALCULATE INTERACTIONS *
829 **************************/
831 if (gmx_mm_any_lt(rsq20,rcutoff2))
834 /* Compute parameters for interactions between i and j atoms */
835 qq20 = _mm_mul_pd(iq2,jq0);
837 /* REACTION-FIELD ELECTROSTATICS */
838 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
840 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
844 fscal = _mm_and_pd(fscal,cutoff_mask);
846 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
848 /* Update vectorial force */
849 fix2 = _mm_macc_pd(dx20,fscal,fix2);
850 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
851 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
853 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
854 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
855 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
859 /**************************
860 * CALCULATE INTERACTIONS *
861 **************************/
863 if (gmx_mm_any_lt(rsq30,rcutoff2))
866 /* Compute parameters for interactions between i and j atoms */
867 qq30 = _mm_mul_pd(iq3,jq0);
869 /* REACTION-FIELD ELECTROSTATICS */
870 felec = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
872 cutoff_mask = _mm_cmplt_pd(rsq30,rcutoff2);
876 fscal = _mm_and_pd(fscal,cutoff_mask);
878 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
880 /* Update vectorial force */
881 fix3 = _mm_macc_pd(dx30,fscal,fix3);
882 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
883 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
885 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
886 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
887 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
891 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
893 /* Inner loop uses 102 flops */
896 /* End of innermost loop */
898 gmx_mm_update_iforce_3atom_swizzle_pd(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
899 f+i_coord_offset+DIM,fshift+i_shift_offset);
901 /* Increment number of inner iterations */
902 inneriter += j_index_end - j_index_start;
904 /* Outer loop uses 18 flops */
907 /* Increment number of outer iterations */
910 /* Update outer/inner flops */
912 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*102);