2 * Note: this file was generated by the Gromacs avx_128_fma_double kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_128_fma_double.h"
34 #include "kernelutil_x86_avx_128_fma_double.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_VF_avx_128_fma_double
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: LennardJones
40 * Geometry: Water3-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_VF_avx_128_fma_double
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
61 int j_coord_offsetA,j_coord_offsetB;
62 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
64 real *shiftvec,*fshift,*x,*f;
65 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
67 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
69 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
71 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
72 int vdwjidx0A,vdwjidx0B;
73 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
74 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
75 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
76 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
77 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
80 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
83 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
84 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
85 __m128d dummy_mask,cutoff_mask;
86 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
87 __m128d one = _mm_set1_pd(1.0);
88 __m128d two = _mm_set1_pd(2.0);
94 jindex = nlist->jindex;
96 shiftidx = nlist->shift;
98 shiftvec = fr->shift_vec[0];
99 fshift = fr->fshift[0];
100 facel = _mm_set1_pd(fr->epsfac);
101 charge = mdatoms->chargeA;
102 krf = _mm_set1_pd(fr->ic->k_rf);
103 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
104 crf = _mm_set1_pd(fr->ic->c_rf);
105 nvdwtype = fr->ntype;
107 vdwtype = mdatoms->typeA;
109 /* Setup water-specific parameters */
110 inr = nlist->iinr[0];
111 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
112 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
113 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
114 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
116 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
117 rcutoff_scalar = fr->rcoulomb;
118 rcutoff = _mm_set1_pd(rcutoff_scalar);
119 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
121 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
122 rvdw = _mm_set1_pd(fr->rvdw);
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,
148 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
150 fix0 = _mm_setzero_pd();
151 fiy0 = _mm_setzero_pd();
152 fiz0 = _mm_setzero_pd();
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();
160 /* Reset potential sums */
161 velecsum = _mm_setzero_pd();
162 vvdwsum = _mm_setzero_pd();
164 /* Start inner kernel loop */
165 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
168 /* Get j neighbor index, and coordinate index */
171 j_coord_offsetA = DIM*jnrA;
172 j_coord_offsetB = DIM*jnrB;
174 /* load j atom coordinates */
175 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
178 /* Calculate displacement vector */
179 dx00 = _mm_sub_pd(ix0,jx0);
180 dy00 = _mm_sub_pd(iy0,jy0);
181 dz00 = _mm_sub_pd(iz0,jz0);
182 dx10 = _mm_sub_pd(ix1,jx0);
183 dy10 = _mm_sub_pd(iy1,jy0);
184 dz10 = _mm_sub_pd(iz1,jz0);
185 dx20 = _mm_sub_pd(ix2,jx0);
186 dy20 = _mm_sub_pd(iy2,jy0);
187 dz20 = _mm_sub_pd(iz2,jz0);
189 /* Calculate squared distance and things based on it */
190 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
191 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
192 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
194 rinv00 = gmx_mm_invsqrt_pd(rsq00);
195 rinv10 = gmx_mm_invsqrt_pd(rsq10);
196 rinv20 = gmx_mm_invsqrt_pd(rsq20);
198 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
199 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
200 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
202 /* Load parameters for j particles */
203 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
204 vdwjidx0A = 2*vdwtype[jnrA+0];
205 vdwjidx0B = 2*vdwtype[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(rsq00,rcutoff2))
218 /* Compute parameters for interactions between i and j atoms */
219 qq00 = _mm_mul_pd(iq0,jq0);
220 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
221 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
223 /* REACTION-FIELD ELECTROSTATICS */
224 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
225 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
227 /* LENNARD-JONES DISPERSION/REPULSION */
229 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
230 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
231 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
232 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
233 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
234 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
236 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
238 /* Update potential sum for this i atom from the interaction with this j atom. */
239 velec = _mm_and_pd(velec,cutoff_mask);
240 velecsum = _mm_add_pd(velecsum,velec);
241 vvdw = _mm_and_pd(vvdw,cutoff_mask);
242 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
244 fscal = _mm_add_pd(felec,fvdw);
246 fscal = _mm_and_pd(fscal,cutoff_mask);
248 /* Update vectorial force */
249 fix0 = _mm_macc_pd(dx00,fscal,fix0);
250 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
251 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
253 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
254 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
255 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
259 /**************************
260 * CALCULATE INTERACTIONS *
261 **************************/
263 if (gmx_mm_any_lt(rsq10,rcutoff2))
266 /* Compute parameters for interactions between i and j atoms */
267 qq10 = _mm_mul_pd(iq1,jq0);
269 /* REACTION-FIELD ELECTROSTATICS */
270 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
271 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
273 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
275 /* Update potential sum for this i atom from the interaction with this j atom. */
276 velec = _mm_and_pd(velec,cutoff_mask);
277 velecsum = _mm_add_pd(velecsum,velec);
281 fscal = _mm_and_pd(fscal,cutoff_mask);
283 /* Update vectorial force */
284 fix1 = _mm_macc_pd(dx10,fscal,fix1);
285 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
286 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
288 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
289 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
290 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
294 /**************************
295 * CALCULATE INTERACTIONS *
296 **************************/
298 if (gmx_mm_any_lt(rsq20,rcutoff2))
301 /* Compute parameters for interactions between i and j atoms */
302 qq20 = _mm_mul_pd(iq2,jq0);
304 /* REACTION-FIELD ELECTROSTATICS */
305 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
306 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
308 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
310 /* Update potential sum for this i atom from the interaction with this j atom. */
311 velec = _mm_and_pd(velec,cutoff_mask);
312 velecsum = _mm_add_pd(velecsum,velec);
316 fscal = _mm_and_pd(fscal,cutoff_mask);
318 /* Update vectorial force */
319 fix2 = _mm_macc_pd(dx20,fscal,fix2);
320 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
321 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
323 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
324 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
325 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
329 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
331 /* Inner loop uses 138 flops */
338 j_coord_offsetA = DIM*jnrA;
340 /* load j atom coordinates */
341 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
344 /* Calculate displacement vector */
345 dx00 = _mm_sub_pd(ix0,jx0);
346 dy00 = _mm_sub_pd(iy0,jy0);
347 dz00 = _mm_sub_pd(iz0,jz0);
348 dx10 = _mm_sub_pd(ix1,jx0);
349 dy10 = _mm_sub_pd(iy1,jy0);
350 dz10 = _mm_sub_pd(iz1,jz0);
351 dx20 = _mm_sub_pd(ix2,jx0);
352 dy20 = _mm_sub_pd(iy2,jy0);
353 dz20 = _mm_sub_pd(iz2,jz0);
355 /* Calculate squared distance and things based on it */
356 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
357 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
358 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
360 rinv00 = gmx_mm_invsqrt_pd(rsq00);
361 rinv10 = gmx_mm_invsqrt_pd(rsq10);
362 rinv20 = gmx_mm_invsqrt_pd(rsq20);
364 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
365 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
366 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
368 /* Load parameters for j particles */
369 jq0 = _mm_load_sd(charge+jnrA+0);
370 vdwjidx0A = 2*vdwtype[jnrA+0];
372 fjx0 = _mm_setzero_pd();
373 fjy0 = _mm_setzero_pd();
374 fjz0 = _mm_setzero_pd();
376 /**************************
377 * CALCULATE INTERACTIONS *
378 **************************/
380 if (gmx_mm_any_lt(rsq00,rcutoff2))
383 /* Compute parameters for interactions between i and j atoms */
384 qq00 = _mm_mul_pd(iq0,jq0);
385 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
387 /* REACTION-FIELD ELECTROSTATICS */
388 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
389 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
391 /* LENNARD-JONES DISPERSION/REPULSION */
393 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
394 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
395 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
396 vvdw = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
397 _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
398 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
400 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
402 /* Update potential sum for this i atom from the interaction with this j atom. */
403 velec = _mm_and_pd(velec,cutoff_mask);
404 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
405 velecsum = _mm_add_pd(velecsum,velec);
406 vvdw = _mm_and_pd(vvdw,cutoff_mask);
407 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
408 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
410 fscal = _mm_add_pd(felec,fvdw);
412 fscal = _mm_and_pd(fscal,cutoff_mask);
414 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
416 /* Update vectorial force */
417 fix0 = _mm_macc_pd(dx00,fscal,fix0);
418 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
419 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
421 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
422 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
423 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
427 /**************************
428 * CALCULATE INTERACTIONS *
429 **************************/
431 if (gmx_mm_any_lt(rsq10,rcutoff2))
434 /* Compute parameters for interactions between i and j atoms */
435 qq10 = _mm_mul_pd(iq1,jq0);
437 /* REACTION-FIELD ELECTROSTATICS */
438 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
439 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
441 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
443 /* Update potential sum for this i atom from the interaction with this j atom. */
444 velec = _mm_and_pd(velec,cutoff_mask);
445 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
446 velecsum = _mm_add_pd(velecsum,velec);
450 fscal = _mm_and_pd(fscal,cutoff_mask);
452 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
454 /* Update vectorial force */
455 fix1 = _mm_macc_pd(dx10,fscal,fix1);
456 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
457 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
459 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
460 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
461 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
465 /**************************
466 * CALCULATE INTERACTIONS *
467 **************************/
469 if (gmx_mm_any_lt(rsq20,rcutoff2))
472 /* Compute parameters for interactions between i and j atoms */
473 qq20 = _mm_mul_pd(iq2,jq0);
475 /* REACTION-FIELD ELECTROSTATICS */
476 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
477 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
479 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
481 /* Update potential sum for this i atom from the interaction with this j atom. */
482 velec = _mm_and_pd(velec,cutoff_mask);
483 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
484 velecsum = _mm_add_pd(velecsum,velec);
488 fscal = _mm_and_pd(fscal,cutoff_mask);
490 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
492 /* Update vectorial force */
493 fix2 = _mm_macc_pd(dx20,fscal,fix2);
494 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
495 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
497 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
498 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
499 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
503 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
505 /* Inner loop uses 138 flops */
508 /* End of innermost loop */
510 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
511 f+i_coord_offset,fshift+i_shift_offset);
514 /* Update potential energies */
515 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
516 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
518 /* Increment number of inner iterations */
519 inneriter += j_index_end - j_index_start;
521 /* Outer loop uses 20 flops */
524 /* Increment number of outer iterations */
527 /* Update outer/inner flops */
529 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*138);
532 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
533 * Electrostatics interaction: ReactionField
534 * VdW interaction: LennardJones
535 * Geometry: Water3-Particle
536 * Calculate force/pot: Force
539 nb_kernel_ElecRFCut_VdwLJSh_GeomW3P1_F_avx_128_fma_double
540 (t_nblist * gmx_restrict nlist,
541 rvec * gmx_restrict xx,
542 rvec * gmx_restrict ff,
543 t_forcerec * gmx_restrict fr,
544 t_mdatoms * gmx_restrict mdatoms,
545 nb_kernel_data_t * gmx_restrict kernel_data,
546 t_nrnb * gmx_restrict nrnb)
548 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
549 * just 0 for non-waters.
550 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
551 * jnr indices corresponding to data put in the four positions in the SIMD register.
553 int i_shift_offset,i_coord_offset,outeriter,inneriter;
554 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
556 int j_coord_offsetA,j_coord_offsetB;
557 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
559 real *shiftvec,*fshift,*x,*f;
560 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
562 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
564 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
566 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
567 int vdwjidx0A,vdwjidx0B;
568 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
569 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
570 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
571 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
572 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
575 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
578 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
579 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
580 __m128d dummy_mask,cutoff_mask;
581 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
582 __m128d one = _mm_set1_pd(1.0);
583 __m128d two = _mm_set1_pd(2.0);
589 jindex = nlist->jindex;
591 shiftidx = nlist->shift;
593 shiftvec = fr->shift_vec[0];
594 fshift = fr->fshift[0];
595 facel = _mm_set1_pd(fr->epsfac);
596 charge = mdatoms->chargeA;
597 krf = _mm_set1_pd(fr->ic->k_rf);
598 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
599 crf = _mm_set1_pd(fr->ic->c_rf);
600 nvdwtype = fr->ntype;
602 vdwtype = mdatoms->typeA;
604 /* Setup water-specific parameters */
605 inr = nlist->iinr[0];
606 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
607 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
608 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
609 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
611 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
612 rcutoff_scalar = fr->rcoulomb;
613 rcutoff = _mm_set1_pd(rcutoff_scalar);
614 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
616 sh_vdw_invrcut6 = _mm_set1_pd(fr->ic->sh_invrc6);
617 rvdw = _mm_set1_pd(fr->rvdw);
619 /* Avoid stupid compiler warnings */
627 /* Start outer loop over neighborlists */
628 for(iidx=0; iidx<nri; iidx++)
630 /* Load shift vector for this list */
631 i_shift_offset = DIM*shiftidx[iidx];
633 /* Load limits for loop over neighbors */
634 j_index_start = jindex[iidx];
635 j_index_end = jindex[iidx+1];
637 /* Get outer coordinate index */
639 i_coord_offset = DIM*inr;
641 /* Load i particle coords and add shift vector */
642 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
643 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
645 fix0 = _mm_setzero_pd();
646 fiy0 = _mm_setzero_pd();
647 fiz0 = _mm_setzero_pd();
648 fix1 = _mm_setzero_pd();
649 fiy1 = _mm_setzero_pd();
650 fiz1 = _mm_setzero_pd();
651 fix2 = _mm_setzero_pd();
652 fiy2 = _mm_setzero_pd();
653 fiz2 = _mm_setzero_pd();
655 /* Start inner kernel loop */
656 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
659 /* Get j neighbor index, and coordinate index */
662 j_coord_offsetA = DIM*jnrA;
663 j_coord_offsetB = DIM*jnrB;
665 /* load j atom coordinates */
666 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
669 /* Calculate displacement vector */
670 dx00 = _mm_sub_pd(ix0,jx0);
671 dy00 = _mm_sub_pd(iy0,jy0);
672 dz00 = _mm_sub_pd(iz0,jz0);
673 dx10 = _mm_sub_pd(ix1,jx0);
674 dy10 = _mm_sub_pd(iy1,jy0);
675 dz10 = _mm_sub_pd(iz1,jz0);
676 dx20 = _mm_sub_pd(ix2,jx0);
677 dy20 = _mm_sub_pd(iy2,jy0);
678 dz20 = _mm_sub_pd(iz2,jz0);
680 /* Calculate squared distance and things based on it */
681 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
682 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
683 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
685 rinv00 = gmx_mm_invsqrt_pd(rsq00);
686 rinv10 = gmx_mm_invsqrt_pd(rsq10);
687 rinv20 = gmx_mm_invsqrt_pd(rsq20);
689 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
690 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
691 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
693 /* Load parameters for j particles */
694 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
695 vdwjidx0A = 2*vdwtype[jnrA+0];
696 vdwjidx0B = 2*vdwtype[jnrB+0];
698 fjx0 = _mm_setzero_pd();
699 fjy0 = _mm_setzero_pd();
700 fjz0 = _mm_setzero_pd();
702 /**************************
703 * CALCULATE INTERACTIONS *
704 **************************/
706 if (gmx_mm_any_lt(rsq00,rcutoff2))
709 /* Compute parameters for interactions between i and j atoms */
710 qq00 = _mm_mul_pd(iq0,jq0);
711 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
712 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
714 /* REACTION-FIELD ELECTROSTATICS */
715 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
717 /* LENNARD-JONES DISPERSION/REPULSION */
719 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
720 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
722 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
724 fscal = _mm_add_pd(felec,fvdw);
726 fscal = _mm_and_pd(fscal,cutoff_mask);
728 /* Update vectorial force */
729 fix0 = _mm_macc_pd(dx00,fscal,fix0);
730 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
731 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
733 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
734 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
735 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
739 /**************************
740 * CALCULATE INTERACTIONS *
741 **************************/
743 if (gmx_mm_any_lt(rsq10,rcutoff2))
746 /* Compute parameters for interactions between i and j atoms */
747 qq10 = _mm_mul_pd(iq1,jq0);
749 /* REACTION-FIELD ELECTROSTATICS */
750 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
752 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
756 fscal = _mm_and_pd(fscal,cutoff_mask);
758 /* Update vectorial force */
759 fix1 = _mm_macc_pd(dx10,fscal,fix1);
760 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
761 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
763 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
764 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
765 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
769 /**************************
770 * CALCULATE INTERACTIONS *
771 **************************/
773 if (gmx_mm_any_lt(rsq20,rcutoff2))
776 /* Compute parameters for interactions between i and j atoms */
777 qq20 = _mm_mul_pd(iq2,jq0);
779 /* REACTION-FIELD ELECTROSTATICS */
780 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
782 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
786 fscal = _mm_and_pd(fscal,cutoff_mask);
788 /* Update vectorial force */
789 fix2 = _mm_macc_pd(dx20,fscal,fix2);
790 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
791 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
793 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
794 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
795 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
799 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
801 /* Inner loop uses 109 flops */
808 j_coord_offsetA = DIM*jnrA;
810 /* load j atom coordinates */
811 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
814 /* Calculate displacement vector */
815 dx00 = _mm_sub_pd(ix0,jx0);
816 dy00 = _mm_sub_pd(iy0,jy0);
817 dz00 = _mm_sub_pd(iz0,jz0);
818 dx10 = _mm_sub_pd(ix1,jx0);
819 dy10 = _mm_sub_pd(iy1,jy0);
820 dz10 = _mm_sub_pd(iz1,jz0);
821 dx20 = _mm_sub_pd(ix2,jx0);
822 dy20 = _mm_sub_pd(iy2,jy0);
823 dz20 = _mm_sub_pd(iz2,jz0);
825 /* Calculate squared distance and things based on it */
826 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
827 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
828 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
830 rinv00 = gmx_mm_invsqrt_pd(rsq00);
831 rinv10 = gmx_mm_invsqrt_pd(rsq10);
832 rinv20 = gmx_mm_invsqrt_pd(rsq20);
834 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
835 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
836 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
838 /* Load parameters for j particles */
839 jq0 = _mm_load_sd(charge+jnrA+0);
840 vdwjidx0A = 2*vdwtype[jnrA+0];
842 fjx0 = _mm_setzero_pd();
843 fjy0 = _mm_setzero_pd();
844 fjz0 = _mm_setzero_pd();
846 /**************************
847 * CALCULATE INTERACTIONS *
848 **************************/
850 if (gmx_mm_any_lt(rsq00,rcutoff2))
853 /* Compute parameters for interactions between i and j atoms */
854 qq00 = _mm_mul_pd(iq0,jq0);
855 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
857 /* REACTION-FIELD ELECTROSTATICS */
858 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
860 /* LENNARD-JONES DISPERSION/REPULSION */
862 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
863 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
865 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
867 fscal = _mm_add_pd(felec,fvdw);
869 fscal = _mm_and_pd(fscal,cutoff_mask);
871 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
873 /* Update vectorial force */
874 fix0 = _mm_macc_pd(dx00,fscal,fix0);
875 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
876 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
878 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
879 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
880 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
884 /**************************
885 * CALCULATE INTERACTIONS *
886 **************************/
888 if (gmx_mm_any_lt(rsq10,rcutoff2))
891 /* Compute parameters for interactions between i and j atoms */
892 qq10 = _mm_mul_pd(iq1,jq0);
894 /* REACTION-FIELD ELECTROSTATICS */
895 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
897 cutoff_mask = _mm_cmplt_pd(rsq10,rcutoff2);
901 fscal = _mm_and_pd(fscal,cutoff_mask);
903 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
905 /* Update vectorial force */
906 fix1 = _mm_macc_pd(dx10,fscal,fix1);
907 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
908 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
910 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
911 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
912 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
916 /**************************
917 * CALCULATE INTERACTIONS *
918 **************************/
920 if (gmx_mm_any_lt(rsq20,rcutoff2))
923 /* Compute parameters for interactions between i and j atoms */
924 qq20 = _mm_mul_pd(iq2,jq0);
926 /* REACTION-FIELD ELECTROSTATICS */
927 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
929 cutoff_mask = _mm_cmplt_pd(rsq20,rcutoff2);
933 fscal = _mm_and_pd(fscal,cutoff_mask);
935 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
937 /* Update vectorial force */
938 fix2 = _mm_macc_pd(dx20,fscal,fix2);
939 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
940 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
942 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
943 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
944 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
948 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
950 /* Inner loop uses 109 flops */
953 /* End of innermost loop */
955 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
956 f+i_coord_offset,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_VDW_W3_F,outeriter*18 + inneriter*109);