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_double kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.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_ElecRF_VdwLJ_GeomW3P1_VF_avx_128_fma_double
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Water3-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRF_VdwLJ_GeomW3P1_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 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
99 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
100 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
101 __m128d dummy_mask,cutoff_mask;
102 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
103 __m128d one = _mm_set1_pd(1.0);
104 __m128d two = _mm_set1_pd(2.0);
110 jindex = nlist->jindex;
112 shiftidx = nlist->shift;
114 shiftvec = fr->shift_vec[0];
115 fshift = fr->fshift[0];
116 facel = _mm_set1_pd(fr->epsfac);
117 charge = mdatoms->chargeA;
118 krf = _mm_set1_pd(fr->ic->k_rf);
119 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
120 crf = _mm_set1_pd(fr->ic->c_rf);
121 nvdwtype = fr->ntype;
123 vdwtype = mdatoms->typeA;
125 /* Setup water-specific parameters */
126 inr = nlist->iinr[0];
127 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
128 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
129 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
130 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
132 /* Avoid stupid compiler warnings */
140 /* Start outer loop over neighborlists */
141 for(iidx=0; iidx<nri; iidx++)
143 /* Load shift vector for this list */
144 i_shift_offset = DIM*shiftidx[iidx];
146 /* Load limits for loop over neighbors */
147 j_index_start = jindex[iidx];
148 j_index_end = jindex[iidx+1];
150 /* Get outer coordinate index */
152 i_coord_offset = DIM*inr;
154 /* Load i particle coords and add shift vector */
155 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
156 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
158 fix0 = _mm_setzero_pd();
159 fiy0 = _mm_setzero_pd();
160 fiz0 = _mm_setzero_pd();
161 fix1 = _mm_setzero_pd();
162 fiy1 = _mm_setzero_pd();
163 fiz1 = _mm_setzero_pd();
164 fix2 = _mm_setzero_pd();
165 fiy2 = _mm_setzero_pd();
166 fiz2 = _mm_setzero_pd();
168 /* Reset potential sums */
169 velecsum = _mm_setzero_pd();
170 vvdwsum = _mm_setzero_pd();
172 /* Start inner kernel loop */
173 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
176 /* Get j neighbor index, and coordinate index */
179 j_coord_offsetA = DIM*jnrA;
180 j_coord_offsetB = DIM*jnrB;
182 /* load j atom coordinates */
183 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
186 /* Calculate displacement vector */
187 dx00 = _mm_sub_pd(ix0,jx0);
188 dy00 = _mm_sub_pd(iy0,jy0);
189 dz00 = _mm_sub_pd(iz0,jz0);
190 dx10 = _mm_sub_pd(ix1,jx0);
191 dy10 = _mm_sub_pd(iy1,jy0);
192 dz10 = _mm_sub_pd(iz1,jz0);
193 dx20 = _mm_sub_pd(ix2,jx0);
194 dy20 = _mm_sub_pd(iy2,jy0);
195 dz20 = _mm_sub_pd(iz2,jz0);
197 /* Calculate squared distance and things based on it */
198 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
199 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
200 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
202 rinv00 = gmx_mm_invsqrt_pd(rsq00);
203 rinv10 = gmx_mm_invsqrt_pd(rsq10);
204 rinv20 = gmx_mm_invsqrt_pd(rsq20);
206 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
207 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
208 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
210 /* Load parameters for j particles */
211 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
212 vdwjidx0A = 2*vdwtype[jnrA+0];
213 vdwjidx0B = 2*vdwtype[jnrB+0];
215 fjx0 = _mm_setzero_pd();
216 fjy0 = _mm_setzero_pd();
217 fjz0 = _mm_setzero_pd();
219 /**************************
220 * CALCULATE INTERACTIONS *
221 **************************/
223 /* Compute parameters for interactions between i and j atoms */
224 qq00 = _mm_mul_pd(iq0,jq0);
225 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
226 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
228 /* REACTION-FIELD ELECTROSTATICS */
229 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
230 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
232 /* LENNARD-JONES DISPERSION/REPULSION */
234 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
235 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
236 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
237 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
238 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
240 /* Update potential sum for this i atom from the interaction with this j atom. */
241 velecsum = _mm_add_pd(velecsum,velec);
242 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
244 fscal = _mm_add_pd(felec,fvdw);
246 /* Update vectorial force */
247 fix0 = _mm_macc_pd(dx00,fscal,fix0);
248 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
249 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
251 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
252 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
253 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
255 /**************************
256 * CALCULATE INTERACTIONS *
257 **************************/
259 /* Compute parameters for interactions between i and j atoms */
260 qq10 = _mm_mul_pd(iq1,jq0);
262 /* REACTION-FIELD ELECTROSTATICS */
263 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
264 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
266 /* Update potential sum for this i atom from the interaction with this j atom. */
267 velecsum = _mm_add_pd(velecsum,velec);
271 /* Update vectorial force */
272 fix1 = _mm_macc_pd(dx10,fscal,fix1);
273 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
274 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
276 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
277 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
278 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
280 /**************************
281 * CALCULATE INTERACTIONS *
282 **************************/
284 /* Compute parameters for interactions between i and j atoms */
285 qq20 = _mm_mul_pd(iq2,jq0);
287 /* REACTION-FIELD ELECTROSTATICS */
288 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
289 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
291 /* Update potential sum for this i atom from the interaction with this j atom. */
292 velecsum = _mm_add_pd(velecsum,velec);
296 /* Update vectorial force */
297 fix2 = _mm_macc_pd(dx20,fscal,fix2);
298 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
299 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
301 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
302 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
303 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
305 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
307 /* Inner loop uses 120 flops */
314 j_coord_offsetA = DIM*jnrA;
316 /* load j atom coordinates */
317 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
320 /* Calculate displacement vector */
321 dx00 = _mm_sub_pd(ix0,jx0);
322 dy00 = _mm_sub_pd(iy0,jy0);
323 dz00 = _mm_sub_pd(iz0,jz0);
324 dx10 = _mm_sub_pd(ix1,jx0);
325 dy10 = _mm_sub_pd(iy1,jy0);
326 dz10 = _mm_sub_pd(iz1,jz0);
327 dx20 = _mm_sub_pd(ix2,jx0);
328 dy20 = _mm_sub_pd(iy2,jy0);
329 dz20 = _mm_sub_pd(iz2,jz0);
331 /* Calculate squared distance and things based on it */
332 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
333 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
334 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
336 rinv00 = gmx_mm_invsqrt_pd(rsq00);
337 rinv10 = gmx_mm_invsqrt_pd(rsq10);
338 rinv20 = gmx_mm_invsqrt_pd(rsq20);
340 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
341 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
342 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
344 /* Load parameters for j particles */
345 jq0 = _mm_load_sd(charge+jnrA+0);
346 vdwjidx0A = 2*vdwtype[jnrA+0];
348 fjx0 = _mm_setzero_pd();
349 fjy0 = _mm_setzero_pd();
350 fjz0 = _mm_setzero_pd();
352 /**************************
353 * CALCULATE INTERACTIONS *
354 **************************/
356 /* Compute parameters for interactions between i and j atoms */
357 qq00 = _mm_mul_pd(iq0,jq0);
358 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
360 /* REACTION-FIELD ELECTROSTATICS */
361 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
362 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
364 /* LENNARD-JONES DISPERSION/REPULSION */
366 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
367 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
368 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
369 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
370 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
372 /* Update potential sum for this i atom from the interaction with this j atom. */
373 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
374 velecsum = _mm_add_pd(velecsum,velec);
375 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
376 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
378 fscal = _mm_add_pd(felec,fvdw);
380 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
382 /* Update vectorial force */
383 fix0 = _mm_macc_pd(dx00,fscal,fix0);
384 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
385 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
387 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
388 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
389 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
391 /**************************
392 * CALCULATE INTERACTIONS *
393 **************************/
395 /* Compute parameters for interactions between i and j atoms */
396 qq10 = _mm_mul_pd(iq1,jq0);
398 /* REACTION-FIELD ELECTROSTATICS */
399 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
400 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
402 /* Update potential sum for this i atom from the interaction with this j atom. */
403 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
404 velecsum = _mm_add_pd(velecsum,velec);
408 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
410 /* Update vectorial force */
411 fix1 = _mm_macc_pd(dx10,fscal,fix1);
412 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
413 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
415 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
416 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
417 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
419 /**************************
420 * CALCULATE INTERACTIONS *
421 **************************/
423 /* Compute parameters for interactions between i and j atoms */
424 qq20 = _mm_mul_pd(iq2,jq0);
426 /* REACTION-FIELD ELECTROSTATICS */
427 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
428 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
430 /* Update potential sum for this i atom from the interaction with this j atom. */
431 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
432 velecsum = _mm_add_pd(velecsum,velec);
436 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
438 /* Update vectorial force */
439 fix2 = _mm_macc_pd(dx20,fscal,fix2);
440 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
441 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
443 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
444 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
445 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
447 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
449 /* Inner loop uses 120 flops */
452 /* End of innermost loop */
454 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
455 f+i_coord_offset,fshift+i_shift_offset);
458 /* Update potential energies */
459 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
460 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
462 /* Increment number of inner iterations */
463 inneriter += j_index_end - j_index_start;
465 /* Outer loop uses 20 flops */
468 /* Increment number of outer iterations */
471 /* Update outer/inner flops */
473 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*120);
476 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_double
477 * Electrostatics interaction: ReactionField
478 * VdW interaction: LennardJones
479 * Geometry: Water3-Particle
480 * Calculate force/pot: Force
483 nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_double
484 (t_nblist * gmx_restrict nlist,
485 rvec * gmx_restrict xx,
486 rvec * gmx_restrict ff,
487 t_forcerec * gmx_restrict fr,
488 t_mdatoms * gmx_restrict mdatoms,
489 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
490 t_nrnb * gmx_restrict nrnb)
492 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
493 * just 0 for non-waters.
494 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
495 * jnr indices corresponding to data put in the four positions in the SIMD register.
497 int i_shift_offset,i_coord_offset,outeriter,inneriter;
498 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
500 int j_coord_offsetA,j_coord_offsetB;
501 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
503 real *shiftvec,*fshift,*x,*f;
504 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
506 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
508 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
510 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
511 int vdwjidx0A,vdwjidx0B;
512 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
513 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
514 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
515 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
516 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
519 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
522 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
523 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
524 __m128d dummy_mask,cutoff_mask;
525 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
526 __m128d one = _mm_set1_pd(1.0);
527 __m128d two = _mm_set1_pd(2.0);
533 jindex = nlist->jindex;
535 shiftidx = nlist->shift;
537 shiftvec = fr->shift_vec[0];
538 fshift = fr->fshift[0];
539 facel = _mm_set1_pd(fr->epsfac);
540 charge = mdatoms->chargeA;
541 krf = _mm_set1_pd(fr->ic->k_rf);
542 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
543 crf = _mm_set1_pd(fr->ic->c_rf);
544 nvdwtype = fr->ntype;
546 vdwtype = mdatoms->typeA;
548 /* Setup water-specific parameters */
549 inr = nlist->iinr[0];
550 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
551 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
552 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
553 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
555 /* Avoid stupid compiler warnings */
563 /* Start outer loop over neighborlists */
564 for(iidx=0; iidx<nri; iidx++)
566 /* Load shift vector for this list */
567 i_shift_offset = DIM*shiftidx[iidx];
569 /* Load limits for loop over neighbors */
570 j_index_start = jindex[iidx];
571 j_index_end = jindex[iidx+1];
573 /* Get outer coordinate index */
575 i_coord_offset = DIM*inr;
577 /* Load i particle coords and add shift vector */
578 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
579 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
581 fix0 = _mm_setzero_pd();
582 fiy0 = _mm_setzero_pd();
583 fiz0 = _mm_setzero_pd();
584 fix1 = _mm_setzero_pd();
585 fiy1 = _mm_setzero_pd();
586 fiz1 = _mm_setzero_pd();
587 fix2 = _mm_setzero_pd();
588 fiy2 = _mm_setzero_pd();
589 fiz2 = _mm_setzero_pd();
591 /* Start inner kernel loop */
592 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
595 /* Get j neighbor index, and coordinate index */
598 j_coord_offsetA = DIM*jnrA;
599 j_coord_offsetB = DIM*jnrB;
601 /* load j atom coordinates */
602 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
605 /* Calculate displacement vector */
606 dx00 = _mm_sub_pd(ix0,jx0);
607 dy00 = _mm_sub_pd(iy0,jy0);
608 dz00 = _mm_sub_pd(iz0,jz0);
609 dx10 = _mm_sub_pd(ix1,jx0);
610 dy10 = _mm_sub_pd(iy1,jy0);
611 dz10 = _mm_sub_pd(iz1,jz0);
612 dx20 = _mm_sub_pd(ix2,jx0);
613 dy20 = _mm_sub_pd(iy2,jy0);
614 dz20 = _mm_sub_pd(iz2,jz0);
616 /* Calculate squared distance and things based on it */
617 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
618 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
619 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
621 rinv00 = gmx_mm_invsqrt_pd(rsq00);
622 rinv10 = gmx_mm_invsqrt_pd(rsq10);
623 rinv20 = gmx_mm_invsqrt_pd(rsq20);
625 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
626 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
627 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
629 /* Load parameters for j particles */
630 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
631 vdwjidx0A = 2*vdwtype[jnrA+0];
632 vdwjidx0B = 2*vdwtype[jnrB+0];
634 fjx0 = _mm_setzero_pd();
635 fjy0 = _mm_setzero_pd();
636 fjz0 = _mm_setzero_pd();
638 /**************************
639 * CALCULATE INTERACTIONS *
640 **************************/
642 /* Compute parameters for interactions between i and j atoms */
643 qq00 = _mm_mul_pd(iq0,jq0);
644 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
645 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
647 /* REACTION-FIELD ELECTROSTATICS */
648 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
650 /* LENNARD-JONES DISPERSION/REPULSION */
652 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
653 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
655 fscal = _mm_add_pd(felec,fvdw);
657 /* Update vectorial force */
658 fix0 = _mm_macc_pd(dx00,fscal,fix0);
659 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
660 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
662 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
663 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
664 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
666 /**************************
667 * CALCULATE INTERACTIONS *
668 **************************/
670 /* Compute parameters for interactions between i and j atoms */
671 qq10 = _mm_mul_pd(iq1,jq0);
673 /* REACTION-FIELD ELECTROSTATICS */
674 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
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);
687 /**************************
688 * CALCULATE INTERACTIONS *
689 **************************/
691 /* Compute parameters for interactions between i and j atoms */
692 qq20 = _mm_mul_pd(iq2,jq0);
694 /* REACTION-FIELD ELECTROSTATICS */
695 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
699 /* Update vectorial force */
700 fix2 = _mm_macc_pd(dx20,fscal,fix2);
701 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
702 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
704 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
705 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
706 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
708 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
710 /* Inner loop uses 100 flops */
717 j_coord_offsetA = DIM*jnrA;
719 /* load j atom coordinates */
720 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
723 /* Calculate displacement vector */
724 dx00 = _mm_sub_pd(ix0,jx0);
725 dy00 = _mm_sub_pd(iy0,jy0);
726 dz00 = _mm_sub_pd(iz0,jz0);
727 dx10 = _mm_sub_pd(ix1,jx0);
728 dy10 = _mm_sub_pd(iy1,jy0);
729 dz10 = _mm_sub_pd(iz1,jz0);
730 dx20 = _mm_sub_pd(ix2,jx0);
731 dy20 = _mm_sub_pd(iy2,jy0);
732 dz20 = _mm_sub_pd(iz2,jz0);
734 /* Calculate squared distance and things based on it */
735 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
736 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
737 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
739 rinv00 = gmx_mm_invsqrt_pd(rsq00);
740 rinv10 = gmx_mm_invsqrt_pd(rsq10);
741 rinv20 = gmx_mm_invsqrt_pd(rsq20);
743 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
744 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
745 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
747 /* Load parameters for j particles */
748 jq0 = _mm_load_sd(charge+jnrA+0);
749 vdwjidx0A = 2*vdwtype[jnrA+0];
751 fjx0 = _mm_setzero_pd();
752 fjy0 = _mm_setzero_pd();
753 fjz0 = _mm_setzero_pd();
755 /**************************
756 * CALCULATE INTERACTIONS *
757 **************************/
759 /* Compute parameters for interactions between i and j atoms */
760 qq00 = _mm_mul_pd(iq0,jq0);
761 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
763 /* REACTION-FIELD ELECTROSTATICS */
764 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
766 /* LENNARD-JONES DISPERSION/REPULSION */
768 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
769 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
771 fscal = _mm_add_pd(felec,fvdw);
773 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
775 /* Update vectorial force */
776 fix0 = _mm_macc_pd(dx00,fscal,fix0);
777 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
778 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
780 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
781 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
782 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
784 /**************************
785 * CALCULATE INTERACTIONS *
786 **************************/
788 /* Compute parameters for interactions between i and j atoms */
789 qq10 = _mm_mul_pd(iq1,jq0);
791 /* REACTION-FIELD ELECTROSTATICS */
792 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
796 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
798 /* Update vectorial force */
799 fix1 = _mm_macc_pd(dx10,fscal,fix1);
800 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
801 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
803 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
804 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
805 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
807 /**************************
808 * CALCULATE INTERACTIONS *
809 **************************/
811 /* Compute parameters for interactions between i and j atoms */
812 qq20 = _mm_mul_pd(iq2,jq0);
814 /* REACTION-FIELD ELECTROSTATICS */
815 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
819 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
821 /* Update vectorial force */
822 fix2 = _mm_macc_pd(dx20,fscal,fix2);
823 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
824 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
826 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
827 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
828 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
830 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
832 /* Inner loop uses 100 flops */
835 /* End of innermost loop */
837 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
838 f+i_coord_offset,fshift+i_shift_offset);
840 /* Increment number of inner iterations */
841 inneriter += j_index_end - j_index_start;
843 /* Outer loop uses 18 flops */
846 /* Increment number of outer iterations */
849 /* Update outer/inner flops */
851 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*100);