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_GeomW4P1_VF_sse4_1_double
54 * Electrostatics interaction: Coulomb
55 * VdW interaction: LennardJones
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_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;
89 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
90 int vdwjidx0A,vdwjidx0B;
91 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
99 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
102 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
103 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
104 __m128d dummy_mask,cutoff_mask;
105 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
106 __m128d one = _mm_set1_pd(1.0);
107 __m128d two = _mm_set1_pd(2.0);
113 jindex = nlist->jindex;
115 shiftidx = nlist->shift;
117 shiftvec = fr->shift_vec[0];
118 fshift = fr->fshift[0];
119 facel = _mm_set1_pd(fr->epsfac);
120 charge = mdatoms->chargeA;
121 nvdwtype = fr->ntype;
123 vdwtype = mdatoms->typeA;
125 /* Setup water-specific parameters */
126 inr = nlist->iinr[0];
127 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
128 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
129 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
130 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
132 /* Avoid stupid compiler warnings */
140 /* Start outer loop over neighborlists */
141 for(iidx=0; iidx<nri; iidx++)
143 /* Load shift vector for this list */
144 i_shift_offset = DIM*shiftidx[iidx];
146 /* Load limits for loop over neighbors */
147 j_index_start = jindex[iidx];
148 j_index_end = jindex[iidx+1];
150 /* Get outer coordinate index */
152 i_coord_offset = DIM*inr;
154 /* Load i particle coords and add shift vector */
155 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
156 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
158 fix0 = _mm_setzero_pd();
159 fiy0 = _mm_setzero_pd();
160 fiz0 = _mm_setzero_pd();
161 fix1 = _mm_setzero_pd();
162 fiy1 = _mm_setzero_pd();
163 fiz1 = _mm_setzero_pd();
164 fix2 = _mm_setzero_pd();
165 fiy2 = _mm_setzero_pd();
166 fiz2 = _mm_setzero_pd();
167 fix3 = _mm_setzero_pd();
168 fiy3 = _mm_setzero_pd();
169 fiz3 = _mm_setzero_pd();
171 /* Reset potential sums */
172 velecsum = _mm_setzero_pd();
173 vvdwsum = _mm_setzero_pd();
175 /* Start inner kernel loop */
176 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
179 /* Get j neighbor index, and coordinate index */
182 j_coord_offsetA = DIM*jnrA;
183 j_coord_offsetB = DIM*jnrB;
185 /* load j atom coordinates */
186 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
189 /* Calculate displacement vector */
190 dx00 = _mm_sub_pd(ix0,jx0);
191 dy00 = _mm_sub_pd(iy0,jy0);
192 dz00 = _mm_sub_pd(iz0,jz0);
193 dx10 = _mm_sub_pd(ix1,jx0);
194 dy10 = _mm_sub_pd(iy1,jy0);
195 dz10 = _mm_sub_pd(iz1,jz0);
196 dx20 = _mm_sub_pd(ix2,jx0);
197 dy20 = _mm_sub_pd(iy2,jy0);
198 dz20 = _mm_sub_pd(iz2,jz0);
199 dx30 = _mm_sub_pd(ix3,jx0);
200 dy30 = _mm_sub_pd(iy3,jy0);
201 dz30 = _mm_sub_pd(iz3,jz0);
203 /* Calculate squared distance and things based on it */
204 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
205 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
206 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
207 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
209 rinv10 = gmx_mm_invsqrt_pd(rsq10);
210 rinv20 = gmx_mm_invsqrt_pd(rsq20);
211 rinv30 = gmx_mm_invsqrt_pd(rsq30);
213 rinvsq00 = gmx_mm_inv_pd(rsq00);
214 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
215 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
216 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
218 /* Load parameters for j particles */
219 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
220 vdwjidx0A = 2*vdwtype[jnrA+0];
221 vdwjidx0B = 2*vdwtype[jnrB+0];
223 fjx0 = _mm_setzero_pd();
224 fjy0 = _mm_setzero_pd();
225 fjz0 = _mm_setzero_pd();
227 /**************************
228 * CALCULATE INTERACTIONS *
229 **************************/
231 /* Compute parameters for interactions between i and j atoms */
232 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
233 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
235 /* LENNARD-JONES DISPERSION/REPULSION */
237 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
238 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
239 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
240 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
241 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
243 /* Update potential sum for this i atom from the interaction with this j atom. */
244 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
248 /* Calculate temporary vectorial force */
249 tx = _mm_mul_pd(fscal,dx00);
250 ty = _mm_mul_pd(fscal,dy00);
251 tz = _mm_mul_pd(fscal,dz00);
253 /* Update vectorial force */
254 fix0 = _mm_add_pd(fix0,tx);
255 fiy0 = _mm_add_pd(fiy0,ty);
256 fiz0 = _mm_add_pd(fiz0,tz);
258 fjx0 = _mm_add_pd(fjx0,tx);
259 fjy0 = _mm_add_pd(fjy0,ty);
260 fjz0 = _mm_add_pd(fjz0,tz);
262 /**************************
263 * CALCULATE INTERACTIONS *
264 **************************/
266 /* Compute parameters for interactions between i and j atoms */
267 qq10 = _mm_mul_pd(iq1,jq0);
269 /* COULOMB ELECTROSTATICS */
270 velec = _mm_mul_pd(qq10,rinv10);
271 felec = _mm_mul_pd(velec,rinvsq10);
273 /* Update potential sum for this i atom from the interaction with this j atom. */
274 velecsum = _mm_add_pd(velecsum,velec);
278 /* Calculate temporary vectorial force */
279 tx = _mm_mul_pd(fscal,dx10);
280 ty = _mm_mul_pd(fscal,dy10);
281 tz = _mm_mul_pd(fscal,dz10);
283 /* Update vectorial force */
284 fix1 = _mm_add_pd(fix1,tx);
285 fiy1 = _mm_add_pd(fiy1,ty);
286 fiz1 = _mm_add_pd(fiz1,tz);
288 fjx0 = _mm_add_pd(fjx0,tx);
289 fjy0 = _mm_add_pd(fjy0,ty);
290 fjz0 = _mm_add_pd(fjz0,tz);
292 /**************************
293 * CALCULATE INTERACTIONS *
294 **************************/
296 /* Compute parameters for interactions between i and j atoms */
297 qq20 = _mm_mul_pd(iq2,jq0);
299 /* COULOMB ELECTROSTATICS */
300 velec = _mm_mul_pd(qq20,rinv20);
301 felec = _mm_mul_pd(velec,rinvsq20);
303 /* Update potential sum for this i atom from the interaction with this j atom. */
304 velecsum = _mm_add_pd(velecsum,velec);
308 /* Calculate temporary vectorial force */
309 tx = _mm_mul_pd(fscal,dx20);
310 ty = _mm_mul_pd(fscal,dy20);
311 tz = _mm_mul_pd(fscal,dz20);
313 /* Update vectorial force */
314 fix2 = _mm_add_pd(fix2,tx);
315 fiy2 = _mm_add_pd(fiy2,ty);
316 fiz2 = _mm_add_pd(fiz2,tz);
318 fjx0 = _mm_add_pd(fjx0,tx);
319 fjy0 = _mm_add_pd(fjy0,ty);
320 fjz0 = _mm_add_pd(fjz0,tz);
322 /**************************
323 * CALCULATE INTERACTIONS *
324 **************************/
326 /* Compute parameters for interactions between i and j atoms */
327 qq30 = _mm_mul_pd(iq3,jq0);
329 /* COULOMB ELECTROSTATICS */
330 velec = _mm_mul_pd(qq30,rinv30);
331 felec = _mm_mul_pd(velec,rinvsq30);
333 /* Update potential sum for this i atom from the interaction with this j atom. */
334 velecsum = _mm_add_pd(velecsum,velec);
338 /* Calculate temporary vectorial force */
339 tx = _mm_mul_pd(fscal,dx30);
340 ty = _mm_mul_pd(fscal,dy30);
341 tz = _mm_mul_pd(fscal,dz30);
343 /* Update vectorial force */
344 fix3 = _mm_add_pd(fix3,tx);
345 fiy3 = _mm_add_pd(fiy3,ty);
346 fiz3 = _mm_add_pd(fiz3,tz);
348 fjx0 = _mm_add_pd(fjx0,tx);
349 fjy0 = _mm_add_pd(fjy0,ty);
350 fjz0 = _mm_add_pd(fjz0,tz);
352 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
354 /* Inner loop uses 119 flops */
361 j_coord_offsetA = DIM*jnrA;
363 /* load j atom coordinates */
364 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
367 /* Calculate displacement vector */
368 dx00 = _mm_sub_pd(ix0,jx0);
369 dy00 = _mm_sub_pd(iy0,jy0);
370 dz00 = _mm_sub_pd(iz0,jz0);
371 dx10 = _mm_sub_pd(ix1,jx0);
372 dy10 = _mm_sub_pd(iy1,jy0);
373 dz10 = _mm_sub_pd(iz1,jz0);
374 dx20 = _mm_sub_pd(ix2,jx0);
375 dy20 = _mm_sub_pd(iy2,jy0);
376 dz20 = _mm_sub_pd(iz2,jz0);
377 dx30 = _mm_sub_pd(ix3,jx0);
378 dy30 = _mm_sub_pd(iy3,jy0);
379 dz30 = _mm_sub_pd(iz3,jz0);
381 /* Calculate squared distance and things based on it */
382 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
383 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
384 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
385 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
387 rinv10 = gmx_mm_invsqrt_pd(rsq10);
388 rinv20 = gmx_mm_invsqrt_pd(rsq20);
389 rinv30 = gmx_mm_invsqrt_pd(rsq30);
391 rinvsq00 = gmx_mm_inv_pd(rsq00);
392 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
393 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
394 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
396 /* Load parameters for j particles */
397 jq0 = _mm_load_sd(charge+jnrA+0);
398 vdwjidx0A = 2*vdwtype[jnrA+0];
400 fjx0 = _mm_setzero_pd();
401 fjy0 = _mm_setzero_pd();
402 fjz0 = _mm_setzero_pd();
404 /**************************
405 * CALCULATE INTERACTIONS *
406 **************************/
408 /* Compute parameters for interactions between i and j atoms */
409 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
411 /* LENNARD-JONES DISPERSION/REPULSION */
413 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
414 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
415 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
416 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
417 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
419 /* Update potential sum for this i atom from the interaction with this j atom. */
420 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
421 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
425 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
427 /* Calculate temporary vectorial force */
428 tx = _mm_mul_pd(fscal,dx00);
429 ty = _mm_mul_pd(fscal,dy00);
430 tz = _mm_mul_pd(fscal,dz00);
432 /* Update vectorial force */
433 fix0 = _mm_add_pd(fix0,tx);
434 fiy0 = _mm_add_pd(fiy0,ty);
435 fiz0 = _mm_add_pd(fiz0,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 qq10 = _mm_mul_pd(iq1,jq0);
448 /* COULOMB ELECTROSTATICS */
449 velec = _mm_mul_pd(qq10,rinv10);
450 felec = _mm_mul_pd(velec,rinvsq10);
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,dx10);
462 ty = _mm_mul_pd(fscal,dy10);
463 tz = _mm_mul_pd(fscal,dz10);
465 /* Update vectorial force */
466 fix1 = _mm_add_pd(fix1,tx);
467 fiy1 = _mm_add_pd(fiy1,ty);
468 fiz1 = _mm_add_pd(fiz1,tz);
470 fjx0 = _mm_add_pd(fjx0,tx);
471 fjy0 = _mm_add_pd(fjy0,ty);
472 fjz0 = _mm_add_pd(fjz0,tz);
474 /**************************
475 * CALCULATE INTERACTIONS *
476 **************************/
478 /* Compute parameters for interactions between i and j atoms */
479 qq20 = _mm_mul_pd(iq2,jq0);
481 /* COULOMB ELECTROSTATICS */
482 velec = _mm_mul_pd(qq20,rinv20);
483 felec = _mm_mul_pd(velec,rinvsq20);
485 /* Update potential sum for this i atom from the interaction with this j atom. */
486 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
487 velecsum = _mm_add_pd(velecsum,velec);
491 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
493 /* Calculate temporary vectorial force */
494 tx = _mm_mul_pd(fscal,dx20);
495 ty = _mm_mul_pd(fscal,dy20);
496 tz = _mm_mul_pd(fscal,dz20);
498 /* Update vectorial force */
499 fix2 = _mm_add_pd(fix2,tx);
500 fiy2 = _mm_add_pd(fiy2,ty);
501 fiz2 = _mm_add_pd(fiz2,tz);
503 fjx0 = _mm_add_pd(fjx0,tx);
504 fjy0 = _mm_add_pd(fjy0,ty);
505 fjz0 = _mm_add_pd(fjz0,tz);
507 /**************************
508 * CALCULATE INTERACTIONS *
509 **************************/
511 /* Compute parameters for interactions between i and j atoms */
512 qq30 = _mm_mul_pd(iq3,jq0);
514 /* COULOMB ELECTROSTATICS */
515 velec = _mm_mul_pd(qq30,rinv30);
516 felec = _mm_mul_pd(velec,rinvsq30);
518 /* Update potential sum for this i atom from the interaction with this j atom. */
519 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
520 velecsum = _mm_add_pd(velecsum,velec);
524 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
526 /* Calculate temporary vectorial force */
527 tx = _mm_mul_pd(fscal,dx30);
528 ty = _mm_mul_pd(fscal,dy30);
529 tz = _mm_mul_pd(fscal,dz30);
531 /* Update vectorial force */
532 fix3 = _mm_add_pd(fix3,tx);
533 fiy3 = _mm_add_pd(fiy3,ty);
534 fiz3 = _mm_add_pd(fiz3,tz);
536 fjx0 = _mm_add_pd(fjx0,tx);
537 fjy0 = _mm_add_pd(fjy0,ty);
538 fjz0 = _mm_add_pd(fjz0,tz);
540 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
542 /* Inner loop uses 119 flops */
545 /* End of innermost loop */
547 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
548 f+i_coord_offset,fshift+i_shift_offset);
551 /* Update potential energies */
552 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
553 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
555 /* Increment number of inner iterations */
556 inneriter += j_index_end - j_index_start;
558 /* Outer loop uses 26 flops */
561 /* Increment number of outer iterations */
564 /* Update outer/inner flops */
566 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*119);
569 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_sse4_1_double
570 * Electrostatics interaction: Coulomb
571 * VdW interaction: LennardJones
572 * Geometry: Water4-Particle
573 * Calculate force/pot: Force
576 nb_kernel_ElecCoul_VdwLJ_GeomW4P1_F_sse4_1_double
577 (t_nblist * gmx_restrict nlist,
578 rvec * gmx_restrict xx,
579 rvec * gmx_restrict ff,
580 t_forcerec * gmx_restrict fr,
581 t_mdatoms * gmx_restrict mdatoms,
582 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
583 t_nrnb * gmx_restrict nrnb)
585 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
586 * just 0 for non-waters.
587 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
588 * jnr indices corresponding to data put in the four positions in the SIMD register.
590 int i_shift_offset,i_coord_offset,outeriter,inneriter;
591 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
593 int j_coord_offsetA,j_coord_offsetB;
594 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
596 real *shiftvec,*fshift,*x,*f;
597 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
599 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
601 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
603 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
605 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
606 int vdwjidx0A,vdwjidx0B;
607 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
608 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
609 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
610 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
611 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
612 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
615 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
618 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
619 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
620 __m128d dummy_mask,cutoff_mask;
621 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
622 __m128d one = _mm_set1_pd(1.0);
623 __m128d two = _mm_set1_pd(2.0);
629 jindex = nlist->jindex;
631 shiftidx = nlist->shift;
633 shiftvec = fr->shift_vec[0];
634 fshift = fr->fshift[0];
635 facel = _mm_set1_pd(fr->epsfac);
636 charge = mdatoms->chargeA;
637 nvdwtype = fr->ntype;
639 vdwtype = mdatoms->typeA;
641 /* Setup water-specific parameters */
642 inr = nlist->iinr[0];
643 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
644 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
645 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
646 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
648 /* Avoid stupid compiler warnings */
656 /* Start outer loop over neighborlists */
657 for(iidx=0; iidx<nri; iidx++)
659 /* Load shift vector for this list */
660 i_shift_offset = DIM*shiftidx[iidx];
662 /* Load limits for loop over neighbors */
663 j_index_start = jindex[iidx];
664 j_index_end = jindex[iidx+1];
666 /* Get outer coordinate index */
668 i_coord_offset = DIM*inr;
670 /* Load i particle coords and add shift vector */
671 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
672 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
674 fix0 = _mm_setzero_pd();
675 fiy0 = _mm_setzero_pd();
676 fiz0 = _mm_setzero_pd();
677 fix1 = _mm_setzero_pd();
678 fiy1 = _mm_setzero_pd();
679 fiz1 = _mm_setzero_pd();
680 fix2 = _mm_setzero_pd();
681 fiy2 = _mm_setzero_pd();
682 fiz2 = _mm_setzero_pd();
683 fix3 = _mm_setzero_pd();
684 fiy3 = _mm_setzero_pd();
685 fiz3 = _mm_setzero_pd();
687 /* Start inner kernel loop */
688 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
691 /* Get j neighbor index, and coordinate index */
694 j_coord_offsetA = DIM*jnrA;
695 j_coord_offsetB = DIM*jnrB;
697 /* load j atom coordinates */
698 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
701 /* Calculate displacement vector */
702 dx00 = _mm_sub_pd(ix0,jx0);
703 dy00 = _mm_sub_pd(iy0,jy0);
704 dz00 = _mm_sub_pd(iz0,jz0);
705 dx10 = _mm_sub_pd(ix1,jx0);
706 dy10 = _mm_sub_pd(iy1,jy0);
707 dz10 = _mm_sub_pd(iz1,jz0);
708 dx20 = _mm_sub_pd(ix2,jx0);
709 dy20 = _mm_sub_pd(iy2,jy0);
710 dz20 = _mm_sub_pd(iz2,jz0);
711 dx30 = _mm_sub_pd(ix3,jx0);
712 dy30 = _mm_sub_pd(iy3,jy0);
713 dz30 = _mm_sub_pd(iz3,jz0);
715 /* Calculate squared distance and things based on it */
716 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
717 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
718 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
719 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
721 rinv10 = gmx_mm_invsqrt_pd(rsq10);
722 rinv20 = gmx_mm_invsqrt_pd(rsq20);
723 rinv30 = gmx_mm_invsqrt_pd(rsq30);
725 rinvsq00 = gmx_mm_inv_pd(rsq00);
726 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
727 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
728 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
730 /* Load parameters for j particles */
731 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
732 vdwjidx0A = 2*vdwtype[jnrA+0];
733 vdwjidx0B = 2*vdwtype[jnrB+0];
735 fjx0 = _mm_setzero_pd();
736 fjy0 = _mm_setzero_pd();
737 fjz0 = _mm_setzero_pd();
739 /**************************
740 * CALCULATE INTERACTIONS *
741 **************************/
743 /* Compute parameters for interactions between i and j atoms */
744 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
745 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
747 /* LENNARD-JONES DISPERSION/REPULSION */
749 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
750 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
754 /* Calculate temporary vectorial force */
755 tx = _mm_mul_pd(fscal,dx00);
756 ty = _mm_mul_pd(fscal,dy00);
757 tz = _mm_mul_pd(fscal,dz00);
759 /* Update vectorial force */
760 fix0 = _mm_add_pd(fix0,tx);
761 fiy0 = _mm_add_pd(fiy0,ty);
762 fiz0 = _mm_add_pd(fiz0,tz);
764 fjx0 = _mm_add_pd(fjx0,tx);
765 fjy0 = _mm_add_pd(fjy0,ty);
766 fjz0 = _mm_add_pd(fjz0,tz);
768 /**************************
769 * CALCULATE INTERACTIONS *
770 **************************/
772 /* Compute parameters for interactions between i and j atoms */
773 qq10 = _mm_mul_pd(iq1,jq0);
775 /* COULOMB ELECTROSTATICS */
776 velec = _mm_mul_pd(qq10,rinv10);
777 felec = _mm_mul_pd(velec,rinvsq10);
781 /* Calculate temporary vectorial force */
782 tx = _mm_mul_pd(fscal,dx10);
783 ty = _mm_mul_pd(fscal,dy10);
784 tz = _mm_mul_pd(fscal,dz10);
786 /* Update vectorial force */
787 fix1 = _mm_add_pd(fix1,tx);
788 fiy1 = _mm_add_pd(fiy1,ty);
789 fiz1 = _mm_add_pd(fiz1,tz);
791 fjx0 = _mm_add_pd(fjx0,tx);
792 fjy0 = _mm_add_pd(fjy0,ty);
793 fjz0 = _mm_add_pd(fjz0,tz);
795 /**************************
796 * CALCULATE INTERACTIONS *
797 **************************/
799 /* Compute parameters for interactions between i and j atoms */
800 qq20 = _mm_mul_pd(iq2,jq0);
802 /* COULOMB ELECTROSTATICS */
803 velec = _mm_mul_pd(qq20,rinv20);
804 felec = _mm_mul_pd(velec,rinvsq20);
808 /* Calculate temporary vectorial force */
809 tx = _mm_mul_pd(fscal,dx20);
810 ty = _mm_mul_pd(fscal,dy20);
811 tz = _mm_mul_pd(fscal,dz20);
813 /* Update vectorial force */
814 fix2 = _mm_add_pd(fix2,tx);
815 fiy2 = _mm_add_pd(fiy2,ty);
816 fiz2 = _mm_add_pd(fiz2,tz);
818 fjx0 = _mm_add_pd(fjx0,tx);
819 fjy0 = _mm_add_pd(fjy0,ty);
820 fjz0 = _mm_add_pd(fjz0,tz);
822 /**************************
823 * CALCULATE INTERACTIONS *
824 **************************/
826 /* Compute parameters for interactions between i and j atoms */
827 qq30 = _mm_mul_pd(iq3,jq0);
829 /* COULOMB ELECTROSTATICS */
830 velec = _mm_mul_pd(qq30,rinv30);
831 felec = _mm_mul_pd(velec,rinvsq30);
835 /* Calculate temporary vectorial force */
836 tx = _mm_mul_pd(fscal,dx30);
837 ty = _mm_mul_pd(fscal,dy30);
838 tz = _mm_mul_pd(fscal,dz30);
840 /* Update vectorial force */
841 fix3 = _mm_add_pd(fix3,tx);
842 fiy3 = _mm_add_pd(fiy3,ty);
843 fiz3 = _mm_add_pd(fiz3,tz);
845 fjx0 = _mm_add_pd(fjx0,tx);
846 fjy0 = _mm_add_pd(fjy0,ty);
847 fjz0 = _mm_add_pd(fjz0,tz);
849 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
851 /* Inner loop uses 111 flops */
858 j_coord_offsetA = DIM*jnrA;
860 /* load j atom coordinates */
861 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
864 /* Calculate displacement vector */
865 dx00 = _mm_sub_pd(ix0,jx0);
866 dy00 = _mm_sub_pd(iy0,jy0);
867 dz00 = _mm_sub_pd(iz0,jz0);
868 dx10 = _mm_sub_pd(ix1,jx0);
869 dy10 = _mm_sub_pd(iy1,jy0);
870 dz10 = _mm_sub_pd(iz1,jz0);
871 dx20 = _mm_sub_pd(ix2,jx0);
872 dy20 = _mm_sub_pd(iy2,jy0);
873 dz20 = _mm_sub_pd(iz2,jz0);
874 dx30 = _mm_sub_pd(ix3,jx0);
875 dy30 = _mm_sub_pd(iy3,jy0);
876 dz30 = _mm_sub_pd(iz3,jz0);
878 /* Calculate squared distance and things based on it */
879 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
880 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
881 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
882 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
884 rinv10 = gmx_mm_invsqrt_pd(rsq10);
885 rinv20 = gmx_mm_invsqrt_pd(rsq20);
886 rinv30 = gmx_mm_invsqrt_pd(rsq30);
888 rinvsq00 = gmx_mm_inv_pd(rsq00);
889 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
890 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
891 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
893 /* Load parameters for j particles */
894 jq0 = _mm_load_sd(charge+jnrA+0);
895 vdwjidx0A = 2*vdwtype[jnrA+0];
897 fjx0 = _mm_setzero_pd();
898 fjy0 = _mm_setzero_pd();
899 fjz0 = _mm_setzero_pd();
901 /**************************
902 * CALCULATE INTERACTIONS *
903 **************************/
905 /* Compute parameters for interactions between i and j atoms */
906 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
908 /* LENNARD-JONES DISPERSION/REPULSION */
910 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
911 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
915 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
917 /* Calculate temporary vectorial force */
918 tx = _mm_mul_pd(fscal,dx00);
919 ty = _mm_mul_pd(fscal,dy00);
920 tz = _mm_mul_pd(fscal,dz00);
922 /* Update vectorial force */
923 fix0 = _mm_add_pd(fix0,tx);
924 fiy0 = _mm_add_pd(fiy0,ty);
925 fiz0 = _mm_add_pd(fiz0,tz);
927 fjx0 = _mm_add_pd(fjx0,tx);
928 fjy0 = _mm_add_pd(fjy0,ty);
929 fjz0 = _mm_add_pd(fjz0,tz);
931 /**************************
932 * CALCULATE INTERACTIONS *
933 **************************/
935 /* Compute parameters for interactions between i and j atoms */
936 qq10 = _mm_mul_pd(iq1,jq0);
938 /* COULOMB ELECTROSTATICS */
939 velec = _mm_mul_pd(qq10,rinv10);
940 felec = _mm_mul_pd(velec,rinvsq10);
944 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
946 /* Calculate temporary vectorial force */
947 tx = _mm_mul_pd(fscal,dx10);
948 ty = _mm_mul_pd(fscal,dy10);
949 tz = _mm_mul_pd(fscal,dz10);
951 /* Update vectorial force */
952 fix1 = _mm_add_pd(fix1,tx);
953 fiy1 = _mm_add_pd(fiy1,ty);
954 fiz1 = _mm_add_pd(fiz1,tz);
956 fjx0 = _mm_add_pd(fjx0,tx);
957 fjy0 = _mm_add_pd(fjy0,ty);
958 fjz0 = _mm_add_pd(fjz0,tz);
960 /**************************
961 * CALCULATE INTERACTIONS *
962 **************************/
964 /* Compute parameters for interactions between i and j atoms */
965 qq20 = _mm_mul_pd(iq2,jq0);
967 /* COULOMB ELECTROSTATICS */
968 velec = _mm_mul_pd(qq20,rinv20);
969 felec = _mm_mul_pd(velec,rinvsq20);
973 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
975 /* Calculate temporary vectorial force */
976 tx = _mm_mul_pd(fscal,dx20);
977 ty = _mm_mul_pd(fscal,dy20);
978 tz = _mm_mul_pd(fscal,dz20);
980 /* Update vectorial force */
981 fix2 = _mm_add_pd(fix2,tx);
982 fiy2 = _mm_add_pd(fiy2,ty);
983 fiz2 = _mm_add_pd(fiz2,tz);
985 fjx0 = _mm_add_pd(fjx0,tx);
986 fjy0 = _mm_add_pd(fjy0,ty);
987 fjz0 = _mm_add_pd(fjz0,tz);
989 /**************************
990 * CALCULATE INTERACTIONS *
991 **************************/
993 /* Compute parameters for interactions between i and j atoms */
994 qq30 = _mm_mul_pd(iq3,jq0);
996 /* COULOMB ELECTROSTATICS */
997 velec = _mm_mul_pd(qq30,rinv30);
998 felec = _mm_mul_pd(velec,rinvsq30);
1002 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1004 /* Calculate temporary vectorial force */
1005 tx = _mm_mul_pd(fscal,dx30);
1006 ty = _mm_mul_pd(fscal,dy30);
1007 tz = _mm_mul_pd(fscal,dz30);
1009 /* Update vectorial force */
1010 fix3 = _mm_add_pd(fix3,tx);
1011 fiy3 = _mm_add_pd(fiy3,ty);
1012 fiz3 = _mm_add_pd(fiz3,tz);
1014 fjx0 = _mm_add_pd(fjx0,tx);
1015 fjy0 = _mm_add_pd(fjy0,ty);
1016 fjz0 = _mm_add_pd(fjz0,tz);
1018 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1020 /* Inner loop uses 111 flops */
1023 /* End of innermost loop */
1025 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1026 f+i_coord_offset,fshift+i_shift_offset);
1028 /* Increment number of inner iterations */
1029 inneriter += j_index_end - j_index_start;
1031 /* Outer loop uses 24 flops */
1034 /* Increment number of outer iterations */
1037 /* Update outer/inner flops */
1039 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*111);