2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_double
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_avx_128_fma_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 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
84 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
87 int vdwjidx0A,vdwjidx0B;
88 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
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;
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->ic->epsfac);
117 charge = mdatoms->chargeA;
118 nvdwtype = fr->ntype;
120 vdwtype = mdatoms->typeA;
122 /* Setup water-specific parameters */
123 inr = nlist->iinr[0];
124 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
125 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
126 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
127 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
129 /* Avoid stupid compiler warnings */
137 /* Start outer loop over neighborlists */
138 for(iidx=0; iidx<nri; iidx++)
140 /* Load shift vector for this list */
141 i_shift_offset = DIM*shiftidx[iidx];
143 /* Load limits for loop over neighbors */
144 j_index_start = jindex[iidx];
145 j_index_end = jindex[iidx+1];
147 /* Get outer coordinate index */
149 i_coord_offset = DIM*inr;
151 /* Load i particle coords and add shift vector */
152 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
153 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
155 fix0 = _mm_setzero_pd();
156 fiy0 = _mm_setzero_pd();
157 fiz0 = _mm_setzero_pd();
158 fix1 = _mm_setzero_pd();
159 fiy1 = _mm_setzero_pd();
160 fiz1 = _mm_setzero_pd();
161 fix2 = _mm_setzero_pd();
162 fiy2 = _mm_setzero_pd();
163 fiz2 = _mm_setzero_pd();
164 fix3 = _mm_setzero_pd();
165 fiy3 = _mm_setzero_pd();
166 fiz3 = _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);
196 dx30 = _mm_sub_pd(ix3,jx0);
197 dy30 = _mm_sub_pd(iy3,jy0);
198 dz30 = _mm_sub_pd(iz3,jz0);
200 /* Calculate squared distance and things based on it */
201 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
202 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
203 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
204 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
206 rinv10 = avx128fma_invsqrt_d(rsq10);
207 rinv20 = avx128fma_invsqrt_d(rsq20);
208 rinv30 = avx128fma_invsqrt_d(rsq30);
210 rinvsq00 = avx128fma_inv_d(rsq00);
211 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
212 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
213 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
215 /* Load parameters for j particles */
216 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
217 vdwjidx0A = 2*vdwtype[jnrA+0];
218 vdwjidx0B = 2*vdwtype[jnrB+0];
220 fjx0 = _mm_setzero_pd();
221 fjy0 = _mm_setzero_pd();
222 fjz0 = _mm_setzero_pd();
224 /**************************
225 * CALCULATE INTERACTIONS *
226 **************************/
228 /* Compute parameters for interactions between i and j atoms */
229 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
230 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
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 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
245 /* Update vectorial force */
246 fix0 = _mm_macc_pd(dx00,fscal,fix0);
247 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
248 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
250 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
251 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
252 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
254 /**************************
255 * CALCULATE INTERACTIONS *
256 **************************/
258 /* Compute parameters for interactions between i and j atoms */
259 qq10 = _mm_mul_pd(iq1,jq0);
261 /* COULOMB ELECTROSTATICS */
262 velec = _mm_mul_pd(qq10,rinv10);
263 felec = _mm_mul_pd(velec,rinvsq10);
265 /* Update potential sum for this i atom from the interaction with this j atom. */
266 velecsum = _mm_add_pd(velecsum,velec);
270 /* Update vectorial force */
271 fix1 = _mm_macc_pd(dx10,fscal,fix1);
272 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
273 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
275 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
276 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
277 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
279 /**************************
280 * CALCULATE INTERACTIONS *
281 **************************/
283 /* Compute parameters for interactions between i and j atoms */
284 qq20 = _mm_mul_pd(iq2,jq0);
286 /* COULOMB ELECTROSTATICS */
287 velec = _mm_mul_pd(qq20,rinv20);
288 felec = _mm_mul_pd(velec,rinvsq20);
290 /* Update potential sum for this i atom from the interaction with this j atom. */
291 velecsum = _mm_add_pd(velecsum,velec);
295 /* Update vectorial force */
296 fix2 = _mm_macc_pd(dx20,fscal,fix2);
297 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
298 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
300 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
301 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
302 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
304 /**************************
305 * CALCULATE INTERACTIONS *
306 **************************/
308 /* Compute parameters for interactions between i and j atoms */
309 qq30 = _mm_mul_pd(iq3,jq0);
311 /* COULOMB ELECTROSTATICS */
312 velec = _mm_mul_pd(qq30,rinv30);
313 felec = _mm_mul_pd(velec,rinvsq30);
315 /* Update potential sum for this i atom from the interaction with this j atom. */
316 velecsum = _mm_add_pd(velecsum,velec);
320 /* Update vectorial force */
321 fix3 = _mm_macc_pd(dx30,fscal,fix3);
322 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
323 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
325 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
326 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
327 fjz0 = _mm_macc_pd(dz30,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 131 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);
354 dx30 = _mm_sub_pd(ix3,jx0);
355 dy30 = _mm_sub_pd(iy3,jy0);
356 dz30 = _mm_sub_pd(iz3,jz0);
358 /* Calculate squared distance and things based on it */
359 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
360 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
361 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
362 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
364 rinv10 = avx128fma_invsqrt_d(rsq10);
365 rinv20 = avx128fma_invsqrt_d(rsq20);
366 rinv30 = avx128fma_invsqrt_d(rsq30);
368 rinvsq00 = avx128fma_inv_d(rsq00);
369 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
370 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
371 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
373 /* Load parameters for j particles */
374 jq0 = _mm_load_sd(charge+jnrA+0);
375 vdwjidx0A = 2*vdwtype[jnrA+0];
377 fjx0 = _mm_setzero_pd();
378 fjy0 = _mm_setzero_pd();
379 fjz0 = _mm_setzero_pd();
381 /**************************
382 * CALCULATE INTERACTIONS *
383 **************************/
385 /* Compute parameters for interactions between i and j atoms */
386 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
388 /* LENNARD-JONES DISPERSION/REPULSION */
390 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
391 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
392 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
393 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
394 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
396 /* Update potential sum for this i atom from the interaction with this j atom. */
397 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
398 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
402 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
404 /* Update vectorial force */
405 fix0 = _mm_macc_pd(dx00,fscal,fix0);
406 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
407 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
409 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
410 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
411 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
413 /**************************
414 * CALCULATE INTERACTIONS *
415 **************************/
417 /* Compute parameters for interactions between i and j atoms */
418 qq10 = _mm_mul_pd(iq1,jq0);
420 /* COULOMB ELECTROSTATICS */
421 velec = _mm_mul_pd(qq10,rinv10);
422 felec = _mm_mul_pd(velec,rinvsq10);
424 /* Update potential sum for this i atom from the interaction with this j atom. */
425 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
426 velecsum = _mm_add_pd(velecsum,velec);
430 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
432 /* Update vectorial force */
433 fix1 = _mm_macc_pd(dx10,fscal,fix1);
434 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
435 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
437 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
438 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
439 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
441 /**************************
442 * CALCULATE INTERACTIONS *
443 **************************/
445 /* Compute parameters for interactions between i and j atoms */
446 qq20 = _mm_mul_pd(iq2,jq0);
448 /* COULOMB ELECTROSTATICS */
449 velec = _mm_mul_pd(qq20,rinv20);
450 felec = _mm_mul_pd(velec,rinvsq20);
452 /* Update potential sum for this i atom from the interaction with this j atom. */
453 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
454 velecsum = _mm_add_pd(velecsum,velec);
458 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
460 /* Update vectorial force */
461 fix2 = _mm_macc_pd(dx20,fscal,fix2);
462 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
463 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
465 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
466 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
467 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
469 /**************************
470 * CALCULATE INTERACTIONS *
471 **************************/
473 /* Compute parameters for interactions between i and j atoms */
474 qq30 = _mm_mul_pd(iq3,jq0);
476 /* COULOMB ELECTROSTATICS */
477 velec = _mm_mul_pd(qq30,rinv30);
478 felec = _mm_mul_pd(velec,rinvsq30);
480 /* Update potential sum for this i atom from the interaction with this j atom. */
481 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
482 velecsum = _mm_add_pd(velecsum,velec);
486 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
488 /* Update vectorial force */
489 fix3 = _mm_macc_pd(dx30,fscal,fix3);
490 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
491 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
493 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
494 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
495 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
497 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
499 /* Inner loop uses 131 flops */
502 /* End of innermost loop */
504 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
505 f+i_coord_offset,fshift+i_shift_offset);
508 /* Update potential energies */
509 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
510 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
512 /* Increment number of inner iterations */
513 inneriter += j_index_end - j_index_start;
515 /* Outer loop uses 26 flops */
518 /* Increment number of outer iterations */
521 /* Update outer/inner flops */
523 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*131);
526 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_double
527 * Electrostatics interaction: Coulomb
528 * VdW interaction: LennardJones
529 * Geometry: Water4-Particle
530 * Calculate force/pot: Force
533 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_avx_128_fma_double
534 (t_nblist * gmx_restrict nlist,
535 rvec * gmx_restrict xx,
536 rvec * gmx_restrict ff,
537 struct t_forcerec * gmx_restrict fr,
538 t_mdatoms * gmx_restrict mdatoms,
539 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
540 t_nrnb * gmx_restrict nrnb)
542 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
543 * just 0 for non-waters.
544 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
545 * jnr indices corresponding to data put in the four positions in the SIMD register.
547 int i_shift_offset,i_coord_offset,outeriter,inneriter;
548 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
550 int j_coord_offsetA,j_coord_offsetB;
551 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
553 real *shiftvec,*fshift,*x,*f;
554 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
556 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
558 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
560 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
562 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
563 int vdwjidx0A,vdwjidx0B;
564 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
565 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
566 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
567 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
568 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
569 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
572 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
575 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
576 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
577 __m128d dummy_mask,cutoff_mask;
578 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
579 __m128d one = _mm_set1_pd(1.0);
580 __m128d two = _mm_set1_pd(2.0);
586 jindex = nlist->jindex;
588 shiftidx = nlist->shift;
590 shiftvec = fr->shift_vec[0];
591 fshift = fr->fshift[0];
592 facel = _mm_set1_pd(fr->ic->epsfac);
593 charge = mdatoms->chargeA;
594 nvdwtype = fr->ntype;
596 vdwtype = mdatoms->typeA;
598 /* Setup water-specific parameters */
599 inr = nlist->iinr[0];
600 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
601 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
602 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
603 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
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_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
629 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
631 fix0 = _mm_setzero_pd();
632 fiy0 = _mm_setzero_pd();
633 fiz0 = _mm_setzero_pd();
634 fix1 = _mm_setzero_pd();
635 fiy1 = _mm_setzero_pd();
636 fiz1 = _mm_setzero_pd();
637 fix2 = _mm_setzero_pd();
638 fiy2 = _mm_setzero_pd();
639 fiz2 = _mm_setzero_pd();
640 fix3 = _mm_setzero_pd();
641 fiy3 = _mm_setzero_pd();
642 fiz3 = _mm_setzero_pd();
644 /* Start inner kernel loop */
645 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
648 /* Get j neighbor index, and coordinate index */
651 j_coord_offsetA = DIM*jnrA;
652 j_coord_offsetB = DIM*jnrB;
654 /* load j atom coordinates */
655 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
658 /* Calculate displacement vector */
659 dx00 = _mm_sub_pd(ix0,jx0);
660 dy00 = _mm_sub_pd(iy0,jy0);
661 dz00 = _mm_sub_pd(iz0,jz0);
662 dx10 = _mm_sub_pd(ix1,jx0);
663 dy10 = _mm_sub_pd(iy1,jy0);
664 dz10 = _mm_sub_pd(iz1,jz0);
665 dx20 = _mm_sub_pd(ix2,jx0);
666 dy20 = _mm_sub_pd(iy2,jy0);
667 dz20 = _mm_sub_pd(iz2,jz0);
668 dx30 = _mm_sub_pd(ix3,jx0);
669 dy30 = _mm_sub_pd(iy3,jy0);
670 dz30 = _mm_sub_pd(iz3,jz0);
672 /* Calculate squared distance and things based on it */
673 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
674 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
675 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
676 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
678 rinv10 = avx128fma_invsqrt_d(rsq10);
679 rinv20 = avx128fma_invsqrt_d(rsq20);
680 rinv30 = avx128fma_invsqrt_d(rsq30);
682 rinvsq00 = avx128fma_inv_d(rsq00);
683 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
684 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
685 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
687 /* Load parameters for j particles */
688 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
689 vdwjidx0A = 2*vdwtype[jnrA+0];
690 vdwjidx0B = 2*vdwtype[jnrB+0];
692 fjx0 = _mm_setzero_pd();
693 fjy0 = _mm_setzero_pd();
694 fjz0 = _mm_setzero_pd();
696 /**************************
697 * CALCULATE INTERACTIONS *
698 **************************/
700 /* Compute parameters for interactions between i and j atoms */
701 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
702 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
704 /* LENNARD-JONES DISPERSION/REPULSION */
706 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
707 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
711 /* Update vectorial force */
712 fix0 = _mm_macc_pd(dx00,fscal,fix0);
713 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
714 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
716 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
717 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
718 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
720 /**************************
721 * CALCULATE INTERACTIONS *
722 **************************/
724 /* Compute parameters for interactions between i and j atoms */
725 qq10 = _mm_mul_pd(iq1,jq0);
727 /* COULOMB ELECTROSTATICS */
728 velec = _mm_mul_pd(qq10,rinv10);
729 felec = _mm_mul_pd(velec,rinvsq10);
733 /* Update vectorial force */
734 fix1 = _mm_macc_pd(dx10,fscal,fix1);
735 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
736 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
738 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
739 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
740 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
742 /**************************
743 * CALCULATE INTERACTIONS *
744 **************************/
746 /* Compute parameters for interactions between i and j atoms */
747 qq20 = _mm_mul_pd(iq2,jq0);
749 /* COULOMB ELECTROSTATICS */
750 velec = _mm_mul_pd(qq20,rinv20);
751 felec = _mm_mul_pd(velec,rinvsq20);
755 /* Update vectorial force */
756 fix2 = _mm_macc_pd(dx20,fscal,fix2);
757 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
758 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
760 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
761 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
762 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
764 /**************************
765 * CALCULATE INTERACTIONS *
766 **************************/
768 /* Compute parameters for interactions between i and j atoms */
769 qq30 = _mm_mul_pd(iq3,jq0);
771 /* COULOMB ELECTROSTATICS */
772 velec = _mm_mul_pd(qq30,rinv30);
773 felec = _mm_mul_pd(velec,rinvsq30);
777 /* Update vectorial force */
778 fix3 = _mm_macc_pd(dx30,fscal,fix3);
779 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
780 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
782 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
783 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
784 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
786 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
788 /* Inner loop uses 123 flops */
795 j_coord_offsetA = DIM*jnrA;
797 /* load j atom coordinates */
798 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
801 /* Calculate displacement vector */
802 dx00 = _mm_sub_pd(ix0,jx0);
803 dy00 = _mm_sub_pd(iy0,jy0);
804 dz00 = _mm_sub_pd(iz0,jz0);
805 dx10 = _mm_sub_pd(ix1,jx0);
806 dy10 = _mm_sub_pd(iy1,jy0);
807 dz10 = _mm_sub_pd(iz1,jz0);
808 dx20 = _mm_sub_pd(ix2,jx0);
809 dy20 = _mm_sub_pd(iy2,jy0);
810 dz20 = _mm_sub_pd(iz2,jz0);
811 dx30 = _mm_sub_pd(ix3,jx0);
812 dy30 = _mm_sub_pd(iy3,jy0);
813 dz30 = _mm_sub_pd(iz3,jz0);
815 /* Calculate squared distance and things based on it */
816 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
817 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
818 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
819 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
821 rinv10 = avx128fma_invsqrt_d(rsq10);
822 rinv20 = avx128fma_invsqrt_d(rsq20);
823 rinv30 = avx128fma_invsqrt_d(rsq30);
825 rinvsq00 = avx128fma_inv_d(rsq00);
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);
832 vdwjidx0A = 2*vdwtype[jnrA+0];
834 fjx0 = _mm_setzero_pd();
835 fjy0 = _mm_setzero_pd();
836 fjz0 = _mm_setzero_pd();
838 /**************************
839 * CALCULATE INTERACTIONS *
840 **************************/
842 /* Compute parameters for interactions between i and j atoms */
843 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
845 /* LENNARD-JONES DISPERSION/REPULSION */
847 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
848 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
852 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
854 /* Update vectorial force */
855 fix0 = _mm_macc_pd(dx00,fscal,fix0);
856 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
857 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
859 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
860 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
861 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
863 /**************************
864 * CALCULATE INTERACTIONS *
865 **************************/
867 /* Compute parameters for interactions between i and j atoms */
868 qq10 = _mm_mul_pd(iq1,jq0);
870 /* COULOMB ELECTROSTATICS */
871 velec = _mm_mul_pd(qq10,rinv10);
872 felec = _mm_mul_pd(velec,rinvsq10);
876 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
878 /* Update vectorial force */
879 fix1 = _mm_macc_pd(dx10,fscal,fix1);
880 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
881 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
883 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
884 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
885 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
887 /**************************
888 * CALCULATE INTERACTIONS *
889 **************************/
891 /* Compute parameters for interactions between i and j atoms */
892 qq20 = _mm_mul_pd(iq2,jq0);
894 /* COULOMB ELECTROSTATICS */
895 velec = _mm_mul_pd(qq20,rinv20);
896 felec = _mm_mul_pd(velec,rinvsq20);
900 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
902 /* Update vectorial force */
903 fix2 = _mm_macc_pd(dx20,fscal,fix2);
904 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
905 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
907 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
908 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
909 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
911 /**************************
912 * CALCULATE INTERACTIONS *
913 **************************/
915 /* Compute parameters for interactions between i and j atoms */
916 qq30 = _mm_mul_pd(iq3,jq0);
918 /* COULOMB ELECTROSTATICS */
919 velec = _mm_mul_pd(qq30,rinv30);
920 felec = _mm_mul_pd(velec,rinvsq30);
924 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
926 /* Update vectorial force */
927 fix3 = _mm_macc_pd(dx30,fscal,fix3);
928 fiy3 = _mm_macc_pd(dy30,fscal,fiy3);
929 fiz3 = _mm_macc_pd(dz30,fscal,fiz3);
931 fjx0 = _mm_macc_pd(dx30,fscal,fjx0);
932 fjy0 = _mm_macc_pd(dy30,fscal,fjy0);
933 fjz0 = _mm_macc_pd(dz30,fscal,fjz0);
935 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
937 /* Inner loop uses 123 flops */
940 /* End of innermost loop */
942 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
943 f+i_coord_offset,fshift+i_shift_offset);
945 /* Increment number of inner iterations */
946 inneriter += j_index_end - j_index_start;
948 /* Outer loop uses 24 flops */
951 /* Increment number of outer iterations */
954 /* Update outer/inner flops */
956 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*123);