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 sse4_1_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_sse4_1_double.h"
50 #include "kernelutil_x86_sse4_1_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_sse4_1_double
54 * Electrostatics interaction: Coulomb
55 * VdW interaction: LennardJones
56 * Geometry: Water3-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_sse4_1_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 nvdwtype = fr->ntype;
120 vdwtype = mdatoms->typeA;
122 /* Setup water-specific parameters */
123 inr = nlist->iinr[0];
124 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
125 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
126 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
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_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
153 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
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();
165 /* Reset potential sums */
166 velecsum = _mm_setzero_pd();
167 vvdwsum = _mm_setzero_pd();
169 /* Start inner kernel loop */
170 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
173 /* Get j neighbor index, and coordinate index */
176 j_coord_offsetA = DIM*jnrA;
177 j_coord_offsetB = DIM*jnrB;
179 /* load j atom coordinates */
180 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
183 /* Calculate displacement vector */
184 dx00 = _mm_sub_pd(ix0,jx0);
185 dy00 = _mm_sub_pd(iy0,jy0);
186 dz00 = _mm_sub_pd(iz0,jz0);
187 dx10 = _mm_sub_pd(ix1,jx0);
188 dy10 = _mm_sub_pd(iy1,jy0);
189 dz10 = _mm_sub_pd(iz1,jz0);
190 dx20 = _mm_sub_pd(ix2,jx0);
191 dy20 = _mm_sub_pd(iy2,jy0);
192 dz20 = _mm_sub_pd(iz2,jz0);
194 /* Calculate squared distance and things based on it */
195 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
196 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
197 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
199 rinv00 = gmx_mm_invsqrt_pd(rsq00);
200 rinv10 = gmx_mm_invsqrt_pd(rsq10);
201 rinv20 = gmx_mm_invsqrt_pd(rsq20);
203 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
204 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
205 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
207 /* Load parameters for j particles */
208 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
209 vdwjidx0A = 2*vdwtype[jnrA+0];
210 vdwjidx0B = 2*vdwtype[jnrB+0];
212 fjx0 = _mm_setzero_pd();
213 fjy0 = _mm_setzero_pd();
214 fjz0 = _mm_setzero_pd();
216 /**************************
217 * CALCULATE INTERACTIONS *
218 **************************/
220 /* Compute parameters for interactions between i and j atoms */
221 qq00 = _mm_mul_pd(iq0,jq0);
222 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
223 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
225 /* COULOMB ELECTROSTATICS */
226 velec = _mm_mul_pd(qq00,rinv00);
227 felec = _mm_mul_pd(velec,rinvsq00);
229 /* LENNARD-JONES DISPERSION/REPULSION */
231 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
232 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
233 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
234 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
235 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
237 /* Update potential sum for this i atom from the interaction with this j atom. */
238 velecsum = _mm_add_pd(velecsum,velec);
239 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
241 fscal = _mm_add_pd(felec,fvdw);
243 /* Calculate temporary vectorial force */
244 tx = _mm_mul_pd(fscal,dx00);
245 ty = _mm_mul_pd(fscal,dy00);
246 tz = _mm_mul_pd(fscal,dz00);
248 /* Update vectorial force */
249 fix0 = _mm_add_pd(fix0,tx);
250 fiy0 = _mm_add_pd(fiy0,ty);
251 fiz0 = _mm_add_pd(fiz0,tz);
253 fjx0 = _mm_add_pd(fjx0,tx);
254 fjy0 = _mm_add_pd(fjy0,ty);
255 fjz0 = _mm_add_pd(fjz0,tz);
257 /**************************
258 * CALCULATE INTERACTIONS *
259 **************************/
261 /* Compute parameters for interactions between i and j atoms */
262 qq10 = _mm_mul_pd(iq1,jq0);
264 /* COULOMB ELECTROSTATICS */
265 velec = _mm_mul_pd(qq10,rinv10);
266 felec = _mm_mul_pd(velec,rinvsq10);
268 /* Update potential sum for this i atom from the interaction with this j atom. */
269 velecsum = _mm_add_pd(velecsum,velec);
273 /* Calculate temporary vectorial force */
274 tx = _mm_mul_pd(fscal,dx10);
275 ty = _mm_mul_pd(fscal,dy10);
276 tz = _mm_mul_pd(fscal,dz10);
278 /* Update vectorial force */
279 fix1 = _mm_add_pd(fix1,tx);
280 fiy1 = _mm_add_pd(fiy1,ty);
281 fiz1 = _mm_add_pd(fiz1,tz);
283 fjx0 = _mm_add_pd(fjx0,tx);
284 fjy0 = _mm_add_pd(fjy0,ty);
285 fjz0 = _mm_add_pd(fjz0,tz);
287 /**************************
288 * CALCULATE INTERACTIONS *
289 **************************/
291 /* Compute parameters for interactions between i and j atoms */
292 qq20 = _mm_mul_pd(iq2,jq0);
294 /* COULOMB ELECTROSTATICS */
295 velec = _mm_mul_pd(qq20,rinv20);
296 felec = _mm_mul_pd(velec,rinvsq20);
298 /* Update potential sum for this i atom from the interaction with this j atom. */
299 velecsum = _mm_add_pd(velecsum,velec);
303 /* Calculate temporary vectorial force */
304 tx = _mm_mul_pd(fscal,dx20);
305 ty = _mm_mul_pd(fscal,dy20);
306 tz = _mm_mul_pd(fscal,dz20);
308 /* Update vectorial force */
309 fix2 = _mm_add_pd(fix2,tx);
310 fiy2 = _mm_add_pd(fiy2,ty);
311 fiz2 = _mm_add_pd(fiz2,tz);
313 fjx0 = _mm_add_pd(fjx0,tx);
314 fjy0 = _mm_add_pd(fjy0,ty);
315 fjz0 = _mm_add_pd(fjz0,tz);
317 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
319 /* Inner loop uses 99 flops */
326 j_coord_offsetA = DIM*jnrA;
328 /* load j atom coordinates */
329 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
332 /* Calculate displacement vector */
333 dx00 = _mm_sub_pd(ix0,jx0);
334 dy00 = _mm_sub_pd(iy0,jy0);
335 dz00 = _mm_sub_pd(iz0,jz0);
336 dx10 = _mm_sub_pd(ix1,jx0);
337 dy10 = _mm_sub_pd(iy1,jy0);
338 dz10 = _mm_sub_pd(iz1,jz0);
339 dx20 = _mm_sub_pd(ix2,jx0);
340 dy20 = _mm_sub_pd(iy2,jy0);
341 dz20 = _mm_sub_pd(iz2,jz0);
343 /* Calculate squared distance and things based on it */
344 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
345 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
346 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
348 rinv00 = gmx_mm_invsqrt_pd(rsq00);
349 rinv10 = gmx_mm_invsqrt_pd(rsq10);
350 rinv20 = gmx_mm_invsqrt_pd(rsq20);
352 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
353 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
354 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
356 /* Load parameters for j particles */
357 jq0 = _mm_load_sd(charge+jnrA+0);
358 vdwjidx0A = 2*vdwtype[jnrA+0];
360 fjx0 = _mm_setzero_pd();
361 fjy0 = _mm_setzero_pd();
362 fjz0 = _mm_setzero_pd();
364 /**************************
365 * CALCULATE INTERACTIONS *
366 **************************/
368 /* Compute parameters for interactions between i and j atoms */
369 qq00 = _mm_mul_pd(iq0,jq0);
370 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
372 /* COULOMB ELECTROSTATICS */
373 velec = _mm_mul_pd(qq00,rinv00);
374 felec = _mm_mul_pd(velec,rinvsq00);
376 /* LENNARD-JONES DISPERSION/REPULSION */
378 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
379 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
380 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
381 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
382 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
384 /* Update potential sum for this i atom from the interaction with this j atom. */
385 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
386 velecsum = _mm_add_pd(velecsum,velec);
387 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
388 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
390 fscal = _mm_add_pd(felec,fvdw);
392 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
394 /* Calculate temporary vectorial force */
395 tx = _mm_mul_pd(fscal,dx00);
396 ty = _mm_mul_pd(fscal,dy00);
397 tz = _mm_mul_pd(fscal,dz00);
399 /* Update vectorial force */
400 fix0 = _mm_add_pd(fix0,tx);
401 fiy0 = _mm_add_pd(fiy0,ty);
402 fiz0 = _mm_add_pd(fiz0,tz);
404 fjx0 = _mm_add_pd(fjx0,tx);
405 fjy0 = _mm_add_pd(fjy0,ty);
406 fjz0 = _mm_add_pd(fjz0,tz);
408 /**************************
409 * CALCULATE INTERACTIONS *
410 **************************/
412 /* Compute parameters for interactions between i and j atoms */
413 qq10 = _mm_mul_pd(iq1,jq0);
415 /* COULOMB ELECTROSTATICS */
416 velec = _mm_mul_pd(qq10,rinv10);
417 felec = _mm_mul_pd(velec,rinvsq10);
419 /* Update potential sum for this i atom from the interaction with this j atom. */
420 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
421 velecsum = _mm_add_pd(velecsum,velec);
425 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
427 /* Calculate temporary vectorial force */
428 tx = _mm_mul_pd(fscal,dx10);
429 ty = _mm_mul_pd(fscal,dy10);
430 tz = _mm_mul_pd(fscal,dz10);
432 /* Update vectorial force */
433 fix1 = _mm_add_pd(fix1,tx);
434 fiy1 = _mm_add_pd(fiy1,ty);
435 fiz1 = _mm_add_pd(fiz1,tz);
437 fjx0 = _mm_add_pd(fjx0,tx);
438 fjy0 = _mm_add_pd(fjy0,ty);
439 fjz0 = _mm_add_pd(fjz0,tz);
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 /* Calculate temporary vectorial force */
461 tx = _mm_mul_pd(fscal,dx20);
462 ty = _mm_mul_pd(fscal,dy20);
463 tz = _mm_mul_pd(fscal,dz20);
465 /* Update vectorial force */
466 fix2 = _mm_add_pd(fix2,tx);
467 fiy2 = _mm_add_pd(fiy2,ty);
468 fiz2 = _mm_add_pd(fiz2,tz);
470 fjx0 = _mm_add_pd(fjx0,tx);
471 fjy0 = _mm_add_pd(fjy0,ty);
472 fjz0 = _mm_add_pd(fjz0,tz);
474 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
476 /* Inner loop uses 99 flops */
479 /* End of innermost loop */
481 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
482 f+i_coord_offset,fshift+i_shift_offset);
485 /* Update potential energies */
486 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
487 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
489 /* Increment number of inner iterations */
490 inneriter += j_index_end - j_index_start;
492 /* Outer loop uses 20 flops */
495 /* Increment number of outer iterations */
498 /* Update outer/inner flops */
500 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*99);
503 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_sse4_1_double
504 * Electrostatics interaction: Coulomb
505 * VdW interaction: LennardJones
506 * Geometry: Water3-Particle
507 * Calculate force/pot: Force
510 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_sse4_1_double
511 (t_nblist * gmx_restrict nlist,
512 rvec * gmx_restrict xx,
513 rvec * gmx_restrict ff,
514 t_forcerec * gmx_restrict fr,
515 t_mdatoms * gmx_restrict mdatoms,
516 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
517 t_nrnb * gmx_restrict nrnb)
519 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
520 * just 0 for non-waters.
521 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
522 * jnr indices corresponding to data put in the four positions in the SIMD register.
524 int i_shift_offset,i_coord_offset,outeriter,inneriter;
525 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
527 int j_coord_offsetA,j_coord_offsetB;
528 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
530 real *shiftvec,*fshift,*x,*f;
531 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
533 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
535 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
537 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
538 int vdwjidx0A,vdwjidx0B;
539 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
540 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
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 velec,felec,velecsum,facel,crf,krf,krf2;
546 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
549 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
550 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
551 __m128d dummy_mask,cutoff_mask;
552 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
553 __m128d one = _mm_set1_pd(1.0);
554 __m128d two = _mm_set1_pd(2.0);
560 jindex = nlist->jindex;
562 shiftidx = nlist->shift;
564 shiftvec = fr->shift_vec[0];
565 fshift = fr->fshift[0];
566 facel = _mm_set1_pd(fr->epsfac);
567 charge = mdatoms->chargeA;
568 nvdwtype = fr->ntype;
570 vdwtype = mdatoms->typeA;
572 /* Setup water-specific parameters */
573 inr = nlist->iinr[0];
574 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
575 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
576 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
577 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
579 /* Avoid stupid compiler warnings */
587 /* Start outer loop over neighborlists */
588 for(iidx=0; iidx<nri; iidx++)
590 /* Load shift vector for this list */
591 i_shift_offset = DIM*shiftidx[iidx];
593 /* Load limits for loop over neighbors */
594 j_index_start = jindex[iidx];
595 j_index_end = jindex[iidx+1];
597 /* Get outer coordinate index */
599 i_coord_offset = DIM*inr;
601 /* Load i particle coords and add shift vector */
602 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
603 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
605 fix0 = _mm_setzero_pd();
606 fiy0 = _mm_setzero_pd();
607 fiz0 = _mm_setzero_pd();
608 fix1 = _mm_setzero_pd();
609 fiy1 = _mm_setzero_pd();
610 fiz1 = _mm_setzero_pd();
611 fix2 = _mm_setzero_pd();
612 fiy2 = _mm_setzero_pd();
613 fiz2 = _mm_setzero_pd();
615 /* Start inner kernel loop */
616 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
619 /* Get j neighbor index, and coordinate index */
622 j_coord_offsetA = DIM*jnrA;
623 j_coord_offsetB = DIM*jnrB;
625 /* load j atom coordinates */
626 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
629 /* Calculate displacement vector */
630 dx00 = _mm_sub_pd(ix0,jx0);
631 dy00 = _mm_sub_pd(iy0,jy0);
632 dz00 = _mm_sub_pd(iz0,jz0);
633 dx10 = _mm_sub_pd(ix1,jx0);
634 dy10 = _mm_sub_pd(iy1,jy0);
635 dz10 = _mm_sub_pd(iz1,jz0);
636 dx20 = _mm_sub_pd(ix2,jx0);
637 dy20 = _mm_sub_pd(iy2,jy0);
638 dz20 = _mm_sub_pd(iz2,jz0);
640 /* Calculate squared distance and things based on it */
641 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
642 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
643 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
645 rinv00 = gmx_mm_invsqrt_pd(rsq00);
646 rinv10 = gmx_mm_invsqrt_pd(rsq10);
647 rinv20 = gmx_mm_invsqrt_pd(rsq20);
649 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
650 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
651 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
653 /* Load parameters for j particles */
654 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
655 vdwjidx0A = 2*vdwtype[jnrA+0];
656 vdwjidx0B = 2*vdwtype[jnrB+0];
658 fjx0 = _mm_setzero_pd();
659 fjy0 = _mm_setzero_pd();
660 fjz0 = _mm_setzero_pd();
662 /**************************
663 * CALCULATE INTERACTIONS *
664 **************************/
666 /* Compute parameters for interactions between i and j atoms */
667 qq00 = _mm_mul_pd(iq0,jq0);
668 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
669 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
671 /* COULOMB ELECTROSTATICS */
672 velec = _mm_mul_pd(qq00,rinv00);
673 felec = _mm_mul_pd(velec,rinvsq00);
675 /* LENNARD-JONES DISPERSION/REPULSION */
677 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
678 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
680 fscal = _mm_add_pd(felec,fvdw);
682 /* Calculate temporary vectorial force */
683 tx = _mm_mul_pd(fscal,dx00);
684 ty = _mm_mul_pd(fscal,dy00);
685 tz = _mm_mul_pd(fscal,dz00);
687 /* Update vectorial force */
688 fix0 = _mm_add_pd(fix0,tx);
689 fiy0 = _mm_add_pd(fiy0,ty);
690 fiz0 = _mm_add_pd(fiz0,tz);
692 fjx0 = _mm_add_pd(fjx0,tx);
693 fjy0 = _mm_add_pd(fjy0,ty);
694 fjz0 = _mm_add_pd(fjz0,tz);
696 /**************************
697 * CALCULATE INTERACTIONS *
698 **************************/
700 /* Compute parameters for interactions between i and j atoms */
701 qq10 = _mm_mul_pd(iq1,jq0);
703 /* COULOMB ELECTROSTATICS */
704 velec = _mm_mul_pd(qq10,rinv10);
705 felec = _mm_mul_pd(velec,rinvsq10);
709 /* Calculate temporary vectorial force */
710 tx = _mm_mul_pd(fscal,dx10);
711 ty = _mm_mul_pd(fscal,dy10);
712 tz = _mm_mul_pd(fscal,dz10);
714 /* Update vectorial force */
715 fix1 = _mm_add_pd(fix1,tx);
716 fiy1 = _mm_add_pd(fiy1,ty);
717 fiz1 = _mm_add_pd(fiz1,tz);
719 fjx0 = _mm_add_pd(fjx0,tx);
720 fjy0 = _mm_add_pd(fjy0,ty);
721 fjz0 = _mm_add_pd(fjz0,tz);
723 /**************************
724 * CALCULATE INTERACTIONS *
725 **************************/
727 /* Compute parameters for interactions between i and j atoms */
728 qq20 = _mm_mul_pd(iq2,jq0);
730 /* COULOMB ELECTROSTATICS */
731 velec = _mm_mul_pd(qq20,rinv20);
732 felec = _mm_mul_pd(velec,rinvsq20);
736 /* Calculate temporary vectorial force */
737 tx = _mm_mul_pd(fscal,dx20);
738 ty = _mm_mul_pd(fscal,dy20);
739 tz = _mm_mul_pd(fscal,dz20);
741 /* Update vectorial force */
742 fix2 = _mm_add_pd(fix2,tx);
743 fiy2 = _mm_add_pd(fiy2,ty);
744 fiz2 = _mm_add_pd(fiz2,tz);
746 fjx0 = _mm_add_pd(fjx0,tx);
747 fjy0 = _mm_add_pd(fjy0,ty);
748 fjz0 = _mm_add_pd(fjz0,tz);
750 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
752 /* Inner loop uses 91 flops */
759 j_coord_offsetA = DIM*jnrA;
761 /* load j atom coordinates */
762 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
765 /* Calculate displacement vector */
766 dx00 = _mm_sub_pd(ix0,jx0);
767 dy00 = _mm_sub_pd(iy0,jy0);
768 dz00 = _mm_sub_pd(iz0,jz0);
769 dx10 = _mm_sub_pd(ix1,jx0);
770 dy10 = _mm_sub_pd(iy1,jy0);
771 dz10 = _mm_sub_pd(iz1,jz0);
772 dx20 = _mm_sub_pd(ix2,jx0);
773 dy20 = _mm_sub_pd(iy2,jy0);
774 dz20 = _mm_sub_pd(iz2,jz0);
776 /* Calculate squared distance and things based on it */
777 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
778 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
779 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
781 rinv00 = gmx_mm_invsqrt_pd(rsq00);
782 rinv10 = gmx_mm_invsqrt_pd(rsq10);
783 rinv20 = gmx_mm_invsqrt_pd(rsq20);
785 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
786 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
787 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
789 /* Load parameters for j particles */
790 jq0 = _mm_load_sd(charge+jnrA+0);
791 vdwjidx0A = 2*vdwtype[jnrA+0];
793 fjx0 = _mm_setzero_pd();
794 fjy0 = _mm_setzero_pd();
795 fjz0 = _mm_setzero_pd();
797 /**************************
798 * CALCULATE INTERACTIONS *
799 **************************/
801 /* Compute parameters for interactions between i and j atoms */
802 qq00 = _mm_mul_pd(iq0,jq0);
803 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
805 /* COULOMB ELECTROSTATICS */
806 velec = _mm_mul_pd(qq00,rinv00);
807 felec = _mm_mul_pd(velec,rinvsq00);
809 /* LENNARD-JONES DISPERSION/REPULSION */
811 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
812 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
814 fscal = _mm_add_pd(felec,fvdw);
816 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
818 /* Calculate temporary vectorial force */
819 tx = _mm_mul_pd(fscal,dx00);
820 ty = _mm_mul_pd(fscal,dy00);
821 tz = _mm_mul_pd(fscal,dz00);
823 /* Update vectorial force */
824 fix0 = _mm_add_pd(fix0,tx);
825 fiy0 = _mm_add_pd(fiy0,ty);
826 fiz0 = _mm_add_pd(fiz0,tz);
828 fjx0 = _mm_add_pd(fjx0,tx);
829 fjy0 = _mm_add_pd(fjy0,ty);
830 fjz0 = _mm_add_pd(fjz0,tz);
832 /**************************
833 * CALCULATE INTERACTIONS *
834 **************************/
836 /* Compute parameters for interactions between i and j atoms */
837 qq10 = _mm_mul_pd(iq1,jq0);
839 /* COULOMB ELECTROSTATICS */
840 velec = _mm_mul_pd(qq10,rinv10);
841 felec = _mm_mul_pd(velec,rinvsq10);
845 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
847 /* Calculate temporary vectorial force */
848 tx = _mm_mul_pd(fscal,dx10);
849 ty = _mm_mul_pd(fscal,dy10);
850 tz = _mm_mul_pd(fscal,dz10);
852 /* Update vectorial force */
853 fix1 = _mm_add_pd(fix1,tx);
854 fiy1 = _mm_add_pd(fiy1,ty);
855 fiz1 = _mm_add_pd(fiz1,tz);
857 fjx0 = _mm_add_pd(fjx0,tx);
858 fjy0 = _mm_add_pd(fjy0,ty);
859 fjz0 = _mm_add_pd(fjz0,tz);
861 /**************************
862 * CALCULATE INTERACTIONS *
863 **************************/
865 /* Compute parameters for interactions between i and j atoms */
866 qq20 = _mm_mul_pd(iq2,jq0);
868 /* COULOMB ELECTROSTATICS */
869 velec = _mm_mul_pd(qq20,rinv20);
870 felec = _mm_mul_pd(velec,rinvsq20);
874 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
876 /* Calculate temporary vectorial force */
877 tx = _mm_mul_pd(fscal,dx20);
878 ty = _mm_mul_pd(fscal,dy20);
879 tz = _mm_mul_pd(fscal,dz20);
881 /* Update vectorial force */
882 fix2 = _mm_add_pd(fix2,tx);
883 fiy2 = _mm_add_pd(fiy2,ty);
884 fiz2 = _mm_add_pd(fiz2,tz);
886 fjx0 = _mm_add_pd(fjx0,tx);
887 fjy0 = _mm_add_pd(fjy0,ty);
888 fjz0 = _mm_add_pd(fjz0,tz);
890 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
892 /* Inner loop uses 91 flops */
895 /* End of innermost loop */
897 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
898 f+i_coord_offset,fshift+i_shift_offset);
900 /* Increment number of inner iterations */
901 inneriter += j_index_end - j_index_start;
903 /* Outer loop uses 18 flops */
906 /* Increment number of outer iterations */
909 /* Update outer/inner flops */
911 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*91);