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 sse2_double kernel generator.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_sse2_double.h"
48 #include "kernelutil_x86_sse2_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_sse2_double
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_VF_sse2_double
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
87 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx0A,vdwjidx0B;
89 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128d 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 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
97 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
100 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
101 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
102 __m128d dummy_mask,cutoff_mask;
103 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
104 __m128d one = _mm_set1_pd(1.0);
105 __m128d two = _mm_set1_pd(2.0);
111 jindex = nlist->jindex;
113 shiftidx = nlist->shift;
115 shiftvec = fr->shift_vec[0];
116 fshift = fr->fshift[0];
117 facel = _mm_set1_pd(fr->epsfac);
118 charge = mdatoms->chargeA;
119 nvdwtype = fr->ntype;
121 vdwtype = mdatoms->typeA;
123 /* Setup water-specific parameters */
124 inr = nlist->iinr[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 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
128 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
130 /* Avoid stupid compiler warnings */
138 /* Start outer loop over neighborlists */
139 for(iidx=0; iidx<nri; iidx++)
141 /* Load shift vector for this list */
142 i_shift_offset = DIM*shiftidx[iidx];
144 /* Load limits for loop over neighbors */
145 j_index_start = jindex[iidx];
146 j_index_end = jindex[iidx+1];
148 /* Get outer coordinate index */
150 i_coord_offset = DIM*inr;
152 /* Load i particle coords and add shift vector */
153 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
154 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
156 fix0 = _mm_setzero_pd();
157 fiy0 = _mm_setzero_pd();
158 fiz0 = _mm_setzero_pd();
159 fix1 = _mm_setzero_pd();
160 fiy1 = _mm_setzero_pd();
161 fiz1 = _mm_setzero_pd();
162 fix2 = _mm_setzero_pd();
163 fiy2 = _mm_setzero_pd();
164 fiz2 = _mm_setzero_pd();
165 fix3 = _mm_setzero_pd();
166 fiy3 = _mm_setzero_pd();
167 fiz3 = _mm_setzero_pd();
169 /* Reset potential sums */
170 velecsum = _mm_setzero_pd();
171 vvdwsum = _mm_setzero_pd();
173 /* Start inner kernel loop */
174 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
177 /* Get j neighbor index, and coordinate index */
180 j_coord_offsetA = DIM*jnrA;
181 j_coord_offsetB = DIM*jnrB;
183 /* load j atom coordinates */
184 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
187 /* Calculate displacement vector */
188 dx00 = _mm_sub_pd(ix0,jx0);
189 dy00 = _mm_sub_pd(iy0,jy0);
190 dz00 = _mm_sub_pd(iz0,jz0);
191 dx10 = _mm_sub_pd(ix1,jx0);
192 dy10 = _mm_sub_pd(iy1,jy0);
193 dz10 = _mm_sub_pd(iz1,jz0);
194 dx20 = _mm_sub_pd(ix2,jx0);
195 dy20 = _mm_sub_pd(iy2,jy0);
196 dz20 = _mm_sub_pd(iz2,jz0);
197 dx30 = _mm_sub_pd(ix3,jx0);
198 dy30 = _mm_sub_pd(iy3,jy0);
199 dz30 = _mm_sub_pd(iz3,jz0);
201 /* Calculate squared distance and things based on it */
202 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
203 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
204 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
205 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
207 rinv10 = gmx_mm_invsqrt_pd(rsq10);
208 rinv20 = gmx_mm_invsqrt_pd(rsq20);
209 rinv30 = gmx_mm_invsqrt_pd(rsq30);
211 rinvsq00 = gmx_mm_inv_pd(rsq00);
212 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
213 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
214 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
216 /* Load parameters for j particles */
217 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
218 vdwjidx0A = 2*vdwtype[jnrA+0];
219 vdwjidx0B = 2*vdwtype[jnrB+0];
221 fjx0 = _mm_setzero_pd();
222 fjy0 = _mm_setzero_pd();
223 fjz0 = _mm_setzero_pd();
225 /**************************
226 * CALCULATE INTERACTIONS *
227 **************************/
229 /* Compute parameters for interactions between i and j atoms */
230 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
231 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
233 /* LENNARD-JONES DISPERSION/REPULSION */
235 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
236 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
237 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
238 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
239 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
241 /* Update potential sum for this i atom from the interaction with this j atom. */
242 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
246 /* Calculate temporary vectorial force */
247 tx = _mm_mul_pd(fscal,dx00);
248 ty = _mm_mul_pd(fscal,dy00);
249 tz = _mm_mul_pd(fscal,dz00);
251 /* Update vectorial force */
252 fix0 = _mm_add_pd(fix0,tx);
253 fiy0 = _mm_add_pd(fiy0,ty);
254 fiz0 = _mm_add_pd(fiz0,tz);
256 fjx0 = _mm_add_pd(fjx0,tx);
257 fjy0 = _mm_add_pd(fjy0,ty);
258 fjz0 = _mm_add_pd(fjz0,tz);
260 /**************************
261 * CALCULATE INTERACTIONS *
262 **************************/
264 /* Compute parameters for interactions between i and j atoms */
265 qq10 = _mm_mul_pd(iq1,jq0);
267 /* COULOMB ELECTROSTATICS */
268 velec = _mm_mul_pd(qq10,rinv10);
269 felec = _mm_mul_pd(velec,rinvsq10);
271 /* Update potential sum for this i atom from the interaction with this j atom. */
272 velecsum = _mm_add_pd(velecsum,velec);
276 /* Calculate temporary vectorial force */
277 tx = _mm_mul_pd(fscal,dx10);
278 ty = _mm_mul_pd(fscal,dy10);
279 tz = _mm_mul_pd(fscal,dz10);
281 /* Update vectorial force */
282 fix1 = _mm_add_pd(fix1,tx);
283 fiy1 = _mm_add_pd(fiy1,ty);
284 fiz1 = _mm_add_pd(fiz1,tz);
286 fjx0 = _mm_add_pd(fjx0,tx);
287 fjy0 = _mm_add_pd(fjy0,ty);
288 fjz0 = _mm_add_pd(fjz0,tz);
290 /**************************
291 * CALCULATE INTERACTIONS *
292 **************************/
294 /* Compute parameters for interactions between i and j atoms */
295 qq20 = _mm_mul_pd(iq2,jq0);
297 /* COULOMB ELECTROSTATICS */
298 velec = _mm_mul_pd(qq20,rinv20);
299 felec = _mm_mul_pd(velec,rinvsq20);
301 /* Update potential sum for this i atom from the interaction with this j atom. */
302 velecsum = _mm_add_pd(velecsum,velec);
306 /* Calculate temporary vectorial force */
307 tx = _mm_mul_pd(fscal,dx20);
308 ty = _mm_mul_pd(fscal,dy20);
309 tz = _mm_mul_pd(fscal,dz20);
311 /* Update vectorial force */
312 fix2 = _mm_add_pd(fix2,tx);
313 fiy2 = _mm_add_pd(fiy2,ty);
314 fiz2 = _mm_add_pd(fiz2,tz);
316 fjx0 = _mm_add_pd(fjx0,tx);
317 fjy0 = _mm_add_pd(fjy0,ty);
318 fjz0 = _mm_add_pd(fjz0,tz);
320 /**************************
321 * CALCULATE INTERACTIONS *
322 **************************/
324 /* Compute parameters for interactions between i and j atoms */
325 qq30 = _mm_mul_pd(iq3,jq0);
327 /* COULOMB ELECTROSTATICS */
328 velec = _mm_mul_pd(qq30,rinv30);
329 felec = _mm_mul_pd(velec,rinvsq30);
331 /* Update potential sum for this i atom from the interaction with this j atom. */
332 velecsum = _mm_add_pd(velecsum,velec);
336 /* Calculate temporary vectorial force */
337 tx = _mm_mul_pd(fscal,dx30);
338 ty = _mm_mul_pd(fscal,dy30);
339 tz = _mm_mul_pd(fscal,dz30);
341 /* Update vectorial force */
342 fix3 = _mm_add_pd(fix3,tx);
343 fiy3 = _mm_add_pd(fiy3,ty);
344 fiz3 = _mm_add_pd(fiz3,tz);
346 fjx0 = _mm_add_pd(fjx0,tx);
347 fjy0 = _mm_add_pd(fjy0,ty);
348 fjz0 = _mm_add_pd(fjz0,tz);
350 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
352 /* Inner loop uses 119 flops */
359 j_coord_offsetA = DIM*jnrA;
361 /* load j atom coordinates */
362 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
365 /* Calculate displacement vector */
366 dx00 = _mm_sub_pd(ix0,jx0);
367 dy00 = _mm_sub_pd(iy0,jy0);
368 dz00 = _mm_sub_pd(iz0,jz0);
369 dx10 = _mm_sub_pd(ix1,jx0);
370 dy10 = _mm_sub_pd(iy1,jy0);
371 dz10 = _mm_sub_pd(iz1,jz0);
372 dx20 = _mm_sub_pd(ix2,jx0);
373 dy20 = _mm_sub_pd(iy2,jy0);
374 dz20 = _mm_sub_pd(iz2,jz0);
375 dx30 = _mm_sub_pd(ix3,jx0);
376 dy30 = _mm_sub_pd(iy3,jy0);
377 dz30 = _mm_sub_pd(iz3,jz0);
379 /* Calculate squared distance and things based on it */
380 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
381 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
382 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
383 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
385 rinv10 = gmx_mm_invsqrt_pd(rsq10);
386 rinv20 = gmx_mm_invsqrt_pd(rsq20);
387 rinv30 = gmx_mm_invsqrt_pd(rsq30);
389 rinvsq00 = gmx_mm_inv_pd(rsq00);
390 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
391 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
392 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
394 /* Load parameters for j particles */
395 jq0 = _mm_load_sd(charge+jnrA+0);
396 vdwjidx0A = 2*vdwtype[jnrA+0];
398 fjx0 = _mm_setzero_pd();
399 fjy0 = _mm_setzero_pd();
400 fjz0 = _mm_setzero_pd();
402 /**************************
403 * CALCULATE INTERACTIONS *
404 **************************/
406 /* Compute parameters for interactions between i and j atoms */
407 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
409 /* LENNARD-JONES DISPERSION/REPULSION */
411 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
412 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
413 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
414 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
415 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
417 /* Update potential sum for this i atom from the interaction with this j atom. */
418 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
419 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
423 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
425 /* Calculate temporary vectorial force */
426 tx = _mm_mul_pd(fscal,dx00);
427 ty = _mm_mul_pd(fscal,dy00);
428 tz = _mm_mul_pd(fscal,dz00);
430 /* Update vectorial force */
431 fix0 = _mm_add_pd(fix0,tx);
432 fiy0 = _mm_add_pd(fiy0,ty);
433 fiz0 = _mm_add_pd(fiz0,tz);
435 fjx0 = _mm_add_pd(fjx0,tx);
436 fjy0 = _mm_add_pd(fjy0,ty);
437 fjz0 = _mm_add_pd(fjz0,tz);
439 /**************************
440 * CALCULATE INTERACTIONS *
441 **************************/
443 /* Compute parameters for interactions between i and j atoms */
444 qq10 = _mm_mul_pd(iq1,jq0);
446 /* COULOMB ELECTROSTATICS */
447 velec = _mm_mul_pd(qq10,rinv10);
448 felec = _mm_mul_pd(velec,rinvsq10);
450 /* Update potential sum for this i atom from the interaction with this j atom. */
451 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
452 velecsum = _mm_add_pd(velecsum,velec);
456 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
458 /* Calculate temporary vectorial force */
459 tx = _mm_mul_pd(fscal,dx10);
460 ty = _mm_mul_pd(fscal,dy10);
461 tz = _mm_mul_pd(fscal,dz10);
463 /* Update vectorial force */
464 fix1 = _mm_add_pd(fix1,tx);
465 fiy1 = _mm_add_pd(fiy1,ty);
466 fiz1 = _mm_add_pd(fiz1,tz);
468 fjx0 = _mm_add_pd(fjx0,tx);
469 fjy0 = _mm_add_pd(fjy0,ty);
470 fjz0 = _mm_add_pd(fjz0,tz);
472 /**************************
473 * CALCULATE INTERACTIONS *
474 **************************/
476 /* Compute parameters for interactions between i and j atoms */
477 qq20 = _mm_mul_pd(iq2,jq0);
479 /* COULOMB ELECTROSTATICS */
480 velec = _mm_mul_pd(qq20,rinv20);
481 felec = _mm_mul_pd(velec,rinvsq20);
483 /* Update potential sum for this i atom from the interaction with this j atom. */
484 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
485 velecsum = _mm_add_pd(velecsum,velec);
489 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
491 /* Calculate temporary vectorial force */
492 tx = _mm_mul_pd(fscal,dx20);
493 ty = _mm_mul_pd(fscal,dy20);
494 tz = _mm_mul_pd(fscal,dz20);
496 /* Update vectorial force */
497 fix2 = _mm_add_pd(fix2,tx);
498 fiy2 = _mm_add_pd(fiy2,ty);
499 fiz2 = _mm_add_pd(fiz2,tz);
501 fjx0 = _mm_add_pd(fjx0,tx);
502 fjy0 = _mm_add_pd(fjy0,ty);
503 fjz0 = _mm_add_pd(fjz0,tz);
505 /**************************
506 * CALCULATE INTERACTIONS *
507 **************************/
509 /* Compute parameters for interactions between i and j atoms */
510 qq30 = _mm_mul_pd(iq3,jq0);
512 /* COULOMB ELECTROSTATICS */
513 velec = _mm_mul_pd(qq30,rinv30);
514 felec = _mm_mul_pd(velec,rinvsq30);
516 /* Update potential sum for this i atom from the interaction with this j atom. */
517 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
518 velecsum = _mm_add_pd(velecsum,velec);
522 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
524 /* Calculate temporary vectorial force */
525 tx = _mm_mul_pd(fscal,dx30);
526 ty = _mm_mul_pd(fscal,dy30);
527 tz = _mm_mul_pd(fscal,dz30);
529 /* Update vectorial force */
530 fix3 = _mm_add_pd(fix3,tx);
531 fiy3 = _mm_add_pd(fiy3,ty);
532 fiz3 = _mm_add_pd(fiz3,tz);
534 fjx0 = _mm_add_pd(fjx0,tx);
535 fjy0 = _mm_add_pd(fjy0,ty);
536 fjz0 = _mm_add_pd(fjz0,tz);
538 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
540 /* Inner loop uses 119 flops */
543 /* End of innermost loop */
545 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
546 f+i_coord_offset,fshift+i_shift_offset);
549 /* Update potential energies */
550 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
551 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
553 /* Increment number of inner iterations */
554 inneriter += j_index_end - j_index_start;
556 /* Outer loop uses 26 flops */
559 /* Increment number of outer iterations */
562 /* Update outer/inner flops */
564 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*119);
567 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_sse2_double
568 * Electrostatics interaction: Coulomb
569 * VdW interaction: LennardJones
570 * Geometry: Water4-Particle
571 * Calculate force/pot: Force
574 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_sse2_double
575 (t_nblist * gmx_restrict nlist,
576 rvec * gmx_restrict xx,
577 rvec * gmx_restrict ff,
578 t_forcerec * gmx_restrict fr,
579 t_mdatoms * gmx_restrict mdatoms,
580 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
581 t_nrnb * gmx_restrict nrnb)
583 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
584 * just 0 for non-waters.
585 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
586 * jnr indices corresponding to data put in the four positions in the SIMD register.
588 int i_shift_offset,i_coord_offset,outeriter,inneriter;
589 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
591 int j_coord_offsetA,j_coord_offsetB;
592 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
594 real *shiftvec,*fshift,*x,*f;
595 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
597 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
599 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
601 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
603 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
604 int vdwjidx0A,vdwjidx0B;
605 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
606 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
607 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
608 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
609 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
610 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
613 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
616 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
617 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
618 __m128d dummy_mask,cutoff_mask;
619 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
620 __m128d one = _mm_set1_pd(1.0);
621 __m128d two = _mm_set1_pd(2.0);
627 jindex = nlist->jindex;
629 shiftidx = nlist->shift;
631 shiftvec = fr->shift_vec[0];
632 fshift = fr->fshift[0];
633 facel = _mm_set1_pd(fr->epsfac);
634 charge = mdatoms->chargeA;
635 nvdwtype = fr->ntype;
637 vdwtype = mdatoms->typeA;
639 /* Setup water-specific parameters */
640 inr = nlist->iinr[0];
641 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
642 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
643 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
644 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
646 /* Avoid stupid compiler warnings */
654 /* Start outer loop over neighborlists */
655 for(iidx=0; iidx<nri; iidx++)
657 /* Load shift vector for this list */
658 i_shift_offset = DIM*shiftidx[iidx];
660 /* Load limits for loop over neighbors */
661 j_index_start = jindex[iidx];
662 j_index_end = jindex[iidx+1];
664 /* Get outer coordinate index */
666 i_coord_offset = DIM*inr;
668 /* Load i particle coords and add shift vector */
669 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
670 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
672 fix0 = _mm_setzero_pd();
673 fiy0 = _mm_setzero_pd();
674 fiz0 = _mm_setzero_pd();
675 fix1 = _mm_setzero_pd();
676 fiy1 = _mm_setzero_pd();
677 fiz1 = _mm_setzero_pd();
678 fix2 = _mm_setzero_pd();
679 fiy2 = _mm_setzero_pd();
680 fiz2 = _mm_setzero_pd();
681 fix3 = _mm_setzero_pd();
682 fiy3 = _mm_setzero_pd();
683 fiz3 = _mm_setzero_pd();
685 /* Start inner kernel loop */
686 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
689 /* Get j neighbor index, and coordinate index */
692 j_coord_offsetA = DIM*jnrA;
693 j_coord_offsetB = DIM*jnrB;
695 /* load j atom coordinates */
696 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
699 /* Calculate displacement vector */
700 dx00 = _mm_sub_pd(ix0,jx0);
701 dy00 = _mm_sub_pd(iy0,jy0);
702 dz00 = _mm_sub_pd(iz0,jz0);
703 dx10 = _mm_sub_pd(ix1,jx0);
704 dy10 = _mm_sub_pd(iy1,jy0);
705 dz10 = _mm_sub_pd(iz1,jz0);
706 dx20 = _mm_sub_pd(ix2,jx0);
707 dy20 = _mm_sub_pd(iy2,jy0);
708 dz20 = _mm_sub_pd(iz2,jz0);
709 dx30 = _mm_sub_pd(ix3,jx0);
710 dy30 = _mm_sub_pd(iy3,jy0);
711 dz30 = _mm_sub_pd(iz3,jz0);
713 /* Calculate squared distance and things based on it */
714 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
715 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
716 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
717 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
719 rinv10 = gmx_mm_invsqrt_pd(rsq10);
720 rinv20 = gmx_mm_invsqrt_pd(rsq20);
721 rinv30 = gmx_mm_invsqrt_pd(rsq30);
723 rinvsq00 = gmx_mm_inv_pd(rsq00);
724 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
725 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
726 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
728 /* Load parameters for j particles */
729 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
730 vdwjidx0A = 2*vdwtype[jnrA+0];
731 vdwjidx0B = 2*vdwtype[jnrB+0];
733 fjx0 = _mm_setzero_pd();
734 fjy0 = _mm_setzero_pd();
735 fjz0 = _mm_setzero_pd();
737 /**************************
738 * CALCULATE INTERACTIONS *
739 **************************/
741 /* Compute parameters for interactions between i and j atoms */
742 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
743 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
745 /* LENNARD-JONES DISPERSION/REPULSION */
747 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
748 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
752 /* Calculate temporary vectorial force */
753 tx = _mm_mul_pd(fscal,dx00);
754 ty = _mm_mul_pd(fscal,dy00);
755 tz = _mm_mul_pd(fscal,dz00);
757 /* Update vectorial force */
758 fix0 = _mm_add_pd(fix0,tx);
759 fiy0 = _mm_add_pd(fiy0,ty);
760 fiz0 = _mm_add_pd(fiz0,tz);
762 fjx0 = _mm_add_pd(fjx0,tx);
763 fjy0 = _mm_add_pd(fjy0,ty);
764 fjz0 = _mm_add_pd(fjz0,tz);
766 /**************************
767 * CALCULATE INTERACTIONS *
768 **************************/
770 /* Compute parameters for interactions between i and j atoms */
771 qq10 = _mm_mul_pd(iq1,jq0);
773 /* COULOMB ELECTROSTATICS */
774 velec = _mm_mul_pd(qq10,rinv10);
775 felec = _mm_mul_pd(velec,rinvsq10);
779 /* Calculate temporary vectorial force */
780 tx = _mm_mul_pd(fscal,dx10);
781 ty = _mm_mul_pd(fscal,dy10);
782 tz = _mm_mul_pd(fscal,dz10);
784 /* Update vectorial force */
785 fix1 = _mm_add_pd(fix1,tx);
786 fiy1 = _mm_add_pd(fiy1,ty);
787 fiz1 = _mm_add_pd(fiz1,tz);
789 fjx0 = _mm_add_pd(fjx0,tx);
790 fjy0 = _mm_add_pd(fjy0,ty);
791 fjz0 = _mm_add_pd(fjz0,tz);
793 /**************************
794 * CALCULATE INTERACTIONS *
795 **************************/
797 /* Compute parameters for interactions between i and j atoms */
798 qq20 = _mm_mul_pd(iq2,jq0);
800 /* COULOMB ELECTROSTATICS */
801 velec = _mm_mul_pd(qq20,rinv20);
802 felec = _mm_mul_pd(velec,rinvsq20);
806 /* Calculate temporary vectorial force */
807 tx = _mm_mul_pd(fscal,dx20);
808 ty = _mm_mul_pd(fscal,dy20);
809 tz = _mm_mul_pd(fscal,dz20);
811 /* Update vectorial force */
812 fix2 = _mm_add_pd(fix2,tx);
813 fiy2 = _mm_add_pd(fiy2,ty);
814 fiz2 = _mm_add_pd(fiz2,tz);
816 fjx0 = _mm_add_pd(fjx0,tx);
817 fjy0 = _mm_add_pd(fjy0,ty);
818 fjz0 = _mm_add_pd(fjz0,tz);
820 /**************************
821 * CALCULATE INTERACTIONS *
822 **************************/
824 /* Compute parameters for interactions between i and j atoms */
825 qq30 = _mm_mul_pd(iq3,jq0);
827 /* COULOMB ELECTROSTATICS */
828 velec = _mm_mul_pd(qq30,rinv30);
829 felec = _mm_mul_pd(velec,rinvsq30);
833 /* Calculate temporary vectorial force */
834 tx = _mm_mul_pd(fscal,dx30);
835 ty = _mm_mul_pd(fscal,dy30);
836 tz = _mm_mul_pd(fscal,dz30);
838 /* Update vectorial force */
839 fix3 = _mm_add_pd(fix3,tx);
840 fiy3 = _mm_add_pd(fiy3,ty);
841 fiz3 = _mm_add_pd(fiz3,tz);
843 fjx0 = _mm_add_pd(fjx0,tx);
844 fjy0 = _mm_add_pd(fjy0,ty);
845 fjz0 = _mm_add_pd(fjz0,tz);
847 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
849 /* Inner loop uses 111 flops */
856 j_coord_offsetA = DIM*jnrA;
858 /* load j atom coordinates */
859 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
862 /* Calculate displacement vector */
863 dx00 = _mm_sub_pd(ix0,jx0);
864 dy00 = _mm_sub_pd(iy0,jy0);
865 dz00 = _mm_sub_pd(iz0,jz0);
866 dx10 = _mm_sub_pd(ix1,jx0);
867 dy10 = _mm_sub_pd(iy1,jy0);
868 dz10 = _mm_sub_pd(iz1,jz0);
869 dx20 = _mm_sub_pd(ix2,jx0);
870 dy20 = _mm_sub_pd(iy2,jy0);
871 dz20 = _mm_sub_pd(iz2,jz0);
872 dx30 = _mm_sub_pd(ix3,jx0);
873 dy30 = _mm_sub_pd(iy3,jy0);
874 dz30 = _mm_sub_pd(iz3,jz0);
876 /* Calculate squared distance and things based on it */
877 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
878 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
879 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
880 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
882 rinv10 = gmx_mm_invsqrt_pd(rsq10);
883 rinv20 = gmx_mm_invsqrt_pd(rsq20);
884 rinv30 = gmx_mm_invsqrt_pd(rsq30);
886 rinvsq00 = gmx_mm_inv_pd(rsq00);
887 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
888 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
889 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
891 /* Load parameters for j particles */
892 jq0 = _mm_load_sd(charge+jnrA+0);
893 vdwjidx0A = 2*vdwtype[jnrA+0];
895 fjx0 = _mm_setzero_pd();
896 fjy0 = _mm_setzero_pd();
897 fjz0 = _mm_setzero_pd();
899 /**************************
900 * CALCULATE INTERACTIONS *
901 **************************/
903 /* Compute parameters for interactions between i and j atoms */
904 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
906 /* LENNARD-JONES DISPERSION/REPULSION */
908 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
909 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
913 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
915 /* Calculate temporary vectorial force */
916 tx = _mm_mul_pd(fscal,dx00);
917 ty = _mm_mul_pd(fscal,dy00);
918 tz = _mm_mul_pd(fscal,dz00);
920 /* Update vectorial force */
921 fix0 = _mm_add_pd(fix0,tx);
922 fiy0 = _mm_add_pd(fiy0,ty);
923 fiz0 = _mm_add_pd(fiz0,tz);
925 fjx0 = _mm_add_pd(fjx0,tx);
926 fjy0 = _mm_add_pd(fjy0,ty);
927 fjz0 = _mm_add_pd(fjz0,tz);
929 /**************************
930 * CALCULATE INTERACTIONS *
931 **************************/
933 /* Compute parameters for interactions between i and j atoms */
934 qq10 = _mm_mul_pd(iq1,jq0);
936 /* COULOMB ELECTROSTATICS */
937 velec = _mm_mul_pd(qq10,rinv10);
938 felec = _mm_mul_pd(velec,rinvsq10);
942 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
944 /* Calculate temporary vectorial force */
945 tx = _mm_mul_pd(fscal,dx10);
946 ty = _mm_mul_pd(fscal,dy10);
947 tz = _mm_mul_pd(fscal,dz10);
949 /* Update vectorial force */
950 fix1 = _mm_add_pd(fix1,tx);
951 fiy1 = _mm_add_pd(fiy1,ty);
952 fiz1 = _mm_add_pd(fiz1,tz);
954 fjx0 = _mm_add_pd(fjx0,tx);
955 fjy0 = _mm_add_pd(fjy0,ty);
956 fjz0 = _mm_add_pd(fjz0,tz);
958 /**************************
959 * CALCULATE INTERACTIONS *
960 **************************/
962 /* Compute parameters for interactions between i and j atoms */
963 qq20 = _mm_mul_pd(iq2,jq0);
965 /* COULOMB ELECTROSTATICS */
966 velec = _mm_mul_pd(qq20,rinv20);
967 felec = _mm_mul_pd(velec,rinvsq20);
971 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
973 /* Calculate temporary vectorial force */
974 tx = _mm_mul_pd(fscal,dx20);
975 ty = _mm_mul_pd(fscal,dy20);
976 tz = _mm_mul_pd(fscal,dz20);
978 /* Update vectorial force */
979 fix2 = _mm_add_pd(fix2,tx);
980 fiy2 = _mm_add_pd(fiy2,ty);
981 fiz2 = _mm_add_pd(fiz2,tz);
983 fjx0 = _mm_add_pd(fjx0,tx);
984 fjy0 = _mm_add_pd(fjy0,ty);
985 fjz0 = _mm_add_pd(fjz0,tz);
987 /**************************
988 * CALCULATE INTERACTIONS *
989 **************************/
991 /* Compute parameters for interactions between i and j atoms */
992 qq30 = _mm_mul_pd(iq3,jq0);
994 /* COULOMB ELECTROSTATICS */
995 velec = _mm_mul_pd(qq30,rinv30);
996 felec = _mm_mul_pd(velec,rinvsq30);
1000 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1002 /* Calculate temporary vectorial force */
1003 tx = _mm_mul_pd(fscal,dx30);
1004 ty = _mm_mul_pd(fscal,dy30);
1005 tz = _mm_mul_pd(fscal,dz30);
1007 /* Update vectorial force */
1008 fix3 = _mm_add_pd(fix3,tx);
1009 fiy3 = _mm_add_pd(fiy3,ty);
1010 fiz3 = _mm_add_pd(fiz3,tz);
1012 fjx0 = _mm_add_pd(fjx0,tx);
1013 fjy0 = _mm_add_pd(fjy0,ty);
1014 fjz0 = _mm_add_pd(fjz0,tz);
1016 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1018 /* Inner loop uses 111 flops */
1021 /* End of innermost loop */
1023 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1024 f+i_coord_offset,fshift+i_shift_offset);
1026 /* Increment number of inner iterations */
1027 inneriter += j_index_end - j_index_start;
1029 /* Outer loop uses 24 flops */
1032 /* Increment number of outer iterations */
1035 /* Update outer/inner flops */
1037 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*111);