2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse4_1_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_sse4_1_single
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: LennardJones
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_sse4_1_single
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,C,D refer to j loop unrolling done with SSE, e.g. for the four 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;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
99 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
100 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
101 __m128 dummy_mask,cutoff_mask;
102 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
103 __m128 one = _mm_set1_ps(1.0);
104 __m128 two = _mm_set1_ps(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_ps(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 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
125 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
126 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
127 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
129 /* Avoid stupid compiler warnings */
130 jnrA = jnrB = jnrC = jnrD = 0;
139 for(iidx=0;iidx<4*DIM;iidx++)
144 /* Start outer loop over neighborlists */
145 for(iidx=0; iidx<nri; iidx++)
147 /* Load shift vector for this list */
148 i_shift_offset = DIM*shiftidx[iidx];
150 /* Load limits for loop over neighbors */
151 j_index_start = jindex[iidx];
152 j_index_end = jindex[iidx+1];
154 /* Get outer coordinate index */
156 i_coord_offset = DIM*inr;
158 /* Load i particle coords and add shift vector */
159 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
160 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
162 fix0 = _mm_setzero_ps();
163 fiy0 = _mm_setzero_ps();
164 fiz0 = _mm_setzero_ps();
165 fix1 = _mm_setzero_ps();
166 fiy1 = _mm_setzero_ps();
167 fiz1 = _mm_setzero_ps();
168 fix2 = _mm_setzero_ps();
169 fiy2 = _mm_setzero_ps();
170 fiz2 = _mm_setzero_ps();
172 /* Reset potential sums */
173 velecsum = _mm_setzero_ps();
174 vvdwsum = _mm_setzero_ps();
176 /* Start inner kernel loop */
177 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
180 /* Get j neighbor index, and coordinate index */
185 j_coord_offsetA = DIM*jnrA;
186 j_coord_offsetB = DIM*jnrB;
187 j_coord_offsetC = DIM*jnrC;
188 j_coord_offsetD = DIM*jnrD;
190 /* load j atom coordinates */
191 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
192 x+j_coord_offsetC,x+j_coord_offsetD,
195 /* Calculate displacement vector */
196 dx00 = _mm_sub_ps(ix0,jx0);
197 dy00 = _mm_sub_ps(iy0,jy0);
198 dz00 = _mm_sub_ps(iz0,jz0);
199 dx10 = _mm_sub_ps(ix1,jx0);
200 dy10 = _mm_sub_ps(iy1,jy0);
201 dz10 = _mm_sub_ps(iz1,jz0);
202 dx20 = _mm_sub_ps(ix2,jx0);
203 dy20 = _mm_sub_ps(iy2,jy0);
204 dz20 = _mm_sub_ps(iz2,jz0);
206 /* Calculate squared distance and things based on it */
207 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
208 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
209 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
211 rinv00 = sse41_invsqrt_f(rsq00);
212 rinv10 = sse41_invsqrt_f(rsq10);
213 rinv20 = sse41_invsqrt_f(rsq20);
215 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
216 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
217 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
219 /* Load parameters for j particles */
220 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
221 charge+jnrC+0,charge+jnrD+0);
222 vdwjidx0A = 2*vdwtype[jnrA+0];
223 vdwjidx0B = 2*vdwtype[jnrB+0];
224 vdwjidx0C = 2*vdwtype[jnrC+0];
225 vdwjidx0D = 2*vdwtype[jnrD+0];
227 fjx0 = _mm_setzero_ps();
228 fjy0 = _mm_setzero_ps();
229 fjz0 = _mm_setzero_ps();
231 /**************************
232 * CALCULATE INTERACTIONS *
233 **************************/
235 /* Compute parameters for interactions between i and j atoms */
236 qq00 = _mm_mul_ps(iq0,jq0);
237 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
238 vdwparam+vdwioffset0+vdwjidx0B,
239 vdwparam+vdwioffset0+vdwjidx0C,
240 vdwparam+vdwioffset0+vdwjidx0D,
243 /* COULOMB ELECTROSTATICS */
244 velec = _mm_mul_ps(qq00,rinv00);
245 felec = _mm_mul_ps(velec,rinvsq00);
247 /* LENNARD-JONES DISPERSION/REPULSION */
249 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
250 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
251 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
252 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
253 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
255 /* Update potential sum for this i atom from the interaction with this j atom. */
256 velecsum = _mm_add_ps(velecsum,velec);
257 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
259 fscal = _mm_add_ps(felec,fvdw);
261 /* Calculate temporary vectorial force */
262 tx = _mm_mul_ps(fscal,dx00);
263 ty = _mm_mul_ps(fscal,dy00);
264 tz = _mm_mul_ps(fscal,dz00);
266 /* Update vectorial force */
267 fix0 = _mm_add_ps(fix0,tx);
268 fiy0 = _mm_add_ps(fiy0,ty);
269 fiz0 = _mm_add_ps(fiz0,tz);
271 fjx0 = _mm_add_ps(fjx0,tx);
272 fjy0 = _mm_add_ps(fjy0,ty);
273 fjz0 = _mm_add_ps(fjz0,tz);
275 /**************************
276 * CALCULATE INTERACTIONS *
277 **************************/
279 /* Compute parameters for interactions between i and j atoms */
280 qq10 = _mm_mul_ps(iq1,jq0);
282 /* COULOMB ELECTROSTATICS */
283 velec = _mm_mul_ps(qq10,rinv10);
284 felec = _mm_mul_ps(velec,rinvsq10);
286 /* Update potential sum for this i atom from the interaction with this j atom. */
287 velecsum = _mm_add_ps(velecsum,velec);
291 /* Calculate temporary vectorial force */
292 tx = _mm_mul_ps(fscal,dx10);
293 ty = _mm_mul_ps(fscal,dy10);
294 tz = _mm_mul_ps(fscal,dz10);
296 /* Update vectorial force */
297 fix1 = _mm_add_ps(fix1,tx);
298 fiy1 = _mm_add_ps(fiy1,ty);
299 fiz1 = _mm_add_ps(fiz1,tz);
301 fjx0 = _mm_add_ps(fjx0,tx);
302 fjy0 = _mm_add_ps(fjy0,ty);
303 fjz0 = _mm_add_ps(fjz0,tz);
305 /**************************
306 * CALCULATE INTERACTIONS *
307 **************************/
309 /* Compute parameters for interactions between i and j atoms */
310 qq20 = _mm_mul_ps(iq2,jq0);
312 /* COULOMB ELECTROSTATICS */
313 velec = _mm_mul_ps(qq20,rinv20);
314 felec = _mm_mul_ps(velec,rinvsq20);
316 /* Update potential sum for this i atom from the interaction with this j atom. */
317 velecsum = _mm_add_ps(velecsum,velec);
321 /* Calculate temporary vectorial force */
322 tx = _mm_mul_ps(fscal,dx20);
323 ty = _mm_mul_ps(fscal,dy20);
324 tz = _mm_mul_ps(fscal,dz20);
326 /* Update vectorial force */
327 fix2 = _mm_add_ps(fix2,tx);
328 fiy2 = _mm_add_ps(fiy2,ty);
329 fiz2 = _mm_add_ps(fiz2,tz);
331 fjx0 = _mm_add_ps(fjx0,tx);
332 fjy0 = _mm_add_ps(fjy0,ty);
333 fjz0 = _mm_add_ps(fjz0,tz);
335 fjptrA = f+j_coord_offsetA;
336 fjptrB = f+j_coord_offsetB;
337 fjptrC = f+j_coord_offsetC;
338 fjptrD = f+j_coord_offsetD;
340 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
342 /* Inner loop uses 96 flops */
348 /* Get j neighbor index, and coordinate index */
349 jnrlistA = jjnr[jidx];
350 jnrlistB = jjnr[jidx+1];
351 jnrlistC = jjnr[jidx+2];
352 jnrlistD = jjnr[jidx+3];
353 /* Sign of each element will be negative for non-real atoms.
354 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
355 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
357 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
358 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
359 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
360 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
361 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
362 j_coord_offsetA = DIM*jnrA;
363 j_coord_offsetB = DIM*jnrB;
364 j_coord_offsetC = DIM*jnrC;
365 j_coord_offsetD = DIM*jnrD;
367 /* load j atom coordinates */
368 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
369 x+j_coord_offsetC,x+j_coord_offsetD,
372 /* Calculate displacement vector */
373 dx00 = _mm_sub_ps(ix0,jx0);
374 dy00 = _mm_sub_ps(iy0,jy0);
375 dz00 = _mm_sub_ps(iz0,jz0);
376 dx10 = _mm_sub_ps(ix1,jx0);
377 dy10 = _mm_sub_ps(iy1,jy0);
378 dz10 = _mm_sub_ps(iz1,jz0);
379 dx20 = _mm_sub_ps(ix2,jx0);
380 dy20 = _mm_sub_ps(iy2,jy0);
381 dz20 = _mm_sub_ps(iz2,jz0);
383 /* Calculate squared distance and things based on it */
384 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
385 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
386 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
388 rinv00 = sse41_invsqrt_f(rsq00);
389 rinv10 = sse41_invsqrt_f(rsq10);
390 rinv20 = sse41_invsqrt_f(rsq20);
392 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
393 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
394 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
396 /* Load parameters for j particles */
397 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
398 charge+jnrC+0,charge+jnrD+0);
399 vdwjidx0A = 2*vdwtype[jnrA+0];
400 vdwjidx0B = 2*vdwtype[jnrB+0];
401 vdwjidx0C = 2*vdwtype[jnrC+0];
402 vdwjidx0D = 2*vdwtype[jnrD+0];
404 fjx0 = _mm_setzero_ps();
405 fjy0 = _mm_setzero_ps();
406 fjz0 = _mm_setzero_ps();
408 /**************************
409 * CALCULATE INTERACTIONS *
410 **************************/
412 /* Compute parameters for interactions between i and j atoms */
413 qq00 = _mm_mul_ps(iq0,jq0);
414 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
415 vdwparam+vdwioffset0+vdwjidx0B,
416 vdwparam+vdwioffset0+vdwjidx0C,
417 vdwparam+vdwioffset0+vdwjidx0D,
420 /* COULOMB ELECTROSTATICS */
421 velec = _mm_mul_ps(qq00,rinv00);
422 felec = _mm_mul_ps(velec,rinvsq00);
424 /* LENNARD-JONES DISPERSION/REPULSION */
426 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
427 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
428 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
429 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
430 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
432 /* Update potential sum for this i atom from the interaction with this j atom. */
433 velec = _mm_andnot_ps(dummy_mask,velec);
434 velecsum = _mm_add_ps(velecsum,velec);
435 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
436 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
438 fscal = _mm_add_ps(felec,fvdw);
440 fscal = _mm_andnot_ps(dummy_mask,fscal);
442 /* Calculate temporary vectorial force */
443 tx = _mm_mul_ps(fscal,dx00);
444 ty = _mm_mul_ps(fscal,dy00);
445 tz = _mm_mul_ps(fscal,dz00);
447 /* Update vectorial force */
448 fix0 = _mm_add_ps(fix0,tx);
449 fiy0 = _mm_add_ps(fiy0,ty);
450 fiz0 = _mm_add_ps(fiz0,tz);
452 fjx0 = _mm_add_ps(fjx0,tx);
453 fjy0 = _mm_add_ps(fjy0,ty);
454 fjz0 = _mm_add_ps(fjz0,tz);
456 /**************************
457 * CALCULATE INTERACTIONS *
458 **************************/
460 /* Compute parameters for interactions between i and j atoms */
461 qq10 = _mm_mul_ps(iq1,jq0);
463 /* COULOMB ELECTROSTATICS */
464 velec = _mm_mul_ps(qq10,rinv10);
465 felec = _mm_mul_ps(velec,rinvsq10);
467 /* Update potential sum for this i atom from the interaction with this j atom. */
468 velec = _mm_andnot_ps(dummy_mask,velec);
469 velecsum = _mm_add_ps(velecsum,velec);
473 fscal = _mm_andnot_ps(dummy_mask,fscal);
475 /* Calculate temporary vectorial force */
476 tx = _mm_mul_ps(fscal,dx10);
477 ty = _mm_mul_ps(fscal,dy10);
478 tz = _mm_mul_ps(fscal,dz10);
480 /* Update vectorial force */
481 fix1 = _mm_add_ps(fix1,tx);
482 fiy1 = _mm_add_ps(fiy1,ty);
483 fiz1 = _mm_add_ps(fiz1,tz);
485 fjx0 = _mm_add_ps(fjx0,tx);
486 fjy0 = _mm_add_ps(fjy0,ty);
487 fjz0 = _mm_add_ps(fjz0,tz);
489 /**************************
490 * CALCULATE INTERACTIONS *
491 **************************/
493 /* Compute parameters for interactions between i and j atoms */
494 qq20 = _mm_mul_ps(iq2,jq0);
496 /* COULOMB ELECTROSTATICS */
497 velec = _mm_mul_ps(qq20,rinv20);
498 felec = _mm_mul_ps(velec,rinvsq20);
500 /* Update potential sum for this i atom from the interaction with this j atom. */
501 velec = _mm_andnot_ps(dummy_mask,velec);
502 velecsum = _mm_add_ps(velecsum,velec);
506 fscal = _mm_andnot_ps(dummy_mask,fscal);
508 /* Calculate temporary vectorial force */
509 tx = _mm_mul_ps(fscal,dx20);
510 ty = _mm_mul_ps(fscal,dy20);
511 tz = _mm_mul_ps(fscal,dz20);
513 /* Update vectorial force */
514 fix2 = _mm_add_ps(fix2,tx);
515 fiy2 = _mm_add_ps(fiy2,ty);
516 fiz2 = _mm_add_ps(fiz2,tz);
518 fjx0 = _mm_add_ps(fjx0,tx);
519 fjy0 = _mm_add_ps(fjy0,ty);
520 fjz0 = _mm_add_ps(fjz0,tz);
522 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
523 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
524 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
525 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
527 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
529 /* Inner loop uses 96 flops */
532 /* End of innermost loop */
534 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
535 f+i_coord_offset,fshift+i_shift_offset);
538 /* Update potential energies */
539 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
540 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
542 /* Increment number of inner iterations */
543 inneriter += j_index_end - j_index_start;
545 /* Outer loop uses 20 flops */
548 /* Increment number of outer iterations */
551 /* Update outer/inner flops */
553 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*96);
556 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_sse4_1_single
557 * Electrostatics interaction: Coulomb
558 * VdW interaction: LennardJones
559 * Geometry: Water3-Particle
560 * Calculate force/pot: Force
563 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_sse4_1_single
564 (t_nblist * gmx_restrict nlist,
565 rvec * gmx_restrict xx,
566 rvec * gmx_restrict ff,
567 struct t_forcerec * gmx_restrict fr,
568 t_mdatoms * gmx_restrict mdatoms,
569 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
570 t_nrnb * gmx_restrict nrnb)
572 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
573 * just 0 for non-waters.
574 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
575 * jnr indices corresponding to data put in the four positions in the SIMD register.
577 int i_shift_offset,i_coord_offset,outeriter,inneriter;
578 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
579 int jnrA,jnrB,jnrC,jnrD;
580 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
581 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
582 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
584 real *shiftvec,*fshift,*x,*f;
585 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
587 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
589 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
591 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
593 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
594 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
595 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
596 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
597 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
598 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
599 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
602 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
605 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
606 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
607 __m128 dummy_mask,cutoff_mask;
608 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
609 __m128 one = _mm_set1_ps(1.0);
610 __m128 two = _mm_set1_ps(2.0);
616 jindex = nlist->jindex;
618 shiftidx = nlist->shift;
620 shiftvec = fr->shift_vec[0];
621 fshift = fr->fshift[0];
622 facel = _mm_set1_ps(fr->ic->epsfac);
623 charge = mdatoms->chargeA;
624 nvdwtype = fr->ntype;
626 vdwtype = mdatoms->typeA;
628 /* Setup water-specific parameters */
629 inr = nlist->iinr[0];
630 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
631 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
632 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
633 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
635 /* Avoid stupid compiler warnings */
636 jnrA = jnrB = jnrC = jnrD = 0;
645 for(iidx=0;iidx<4*DIM;iidx++)
650 /* Start outer loop over neighborlists */
651 for(iidx=0; iidx<nri; iidx++)
653 /* Load shift vector for this list */
654 i_shift_offset = DIM*shiftidx[iidx];
656 /* Load limits for loop over neighbors */
657 j_index_start = jindex[iidx];
658 j_index_end = jindex[iidx+1];
660 /* Get outer coordinate index */
662 i_coord_offset = DIM*inr;
664 /* Load i particle coords and add shift vector */
665 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
666 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
668 fix0 = _mm_setzero_ps();
669 fiy0 = _mm_setzero_ps();
670 fiz0 = _mm_setzero_ps();
671 fix1 = _mm_setzero_ps();
672 fiy1 = _mm_setzero_ps();
673 fiz1 = _mm_setzero_ps();
674 fix2 = _mm_setzero_ps();
675 fiy2 = _mm_setzero_ps();
676 fiz2 = _mm_setzero_ps();
678 /* Start inner kernel loop */
679 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
682 /* Get j neighbor index, and coordinate index */
687 j_coord_offsetA = DIM*jnrA;
688 j_coord_offsetB = DIM*jnrB;
689 j_coord_offsetC = DIM*jnrC;
690 j_coord_offsetD = DIM*jnrD;
692 /* load j atom coordinates */
693 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
694 x+j_coord_offsetC,x+j_coord_offsetD,
697 /* Calculate displacement vector */
698 dx00 = _mm_sub_ps(ix0,jx0);
699 dy00 = _mm_sub_ps(iy0,jy0);
700 dz00 = _mm_sub_ps(iz0,jz0);
701 dx10 = _mm_sub_ps(ix1,jx0);
702 dy10 = _mm_sub_ps(iy1,jy0);
703 dz10 = _mm_sub_ps(iz1,jz0);
704 dx20 = _mm_sub_ps(ix2,jx0);
705 dy20 = _mm_sub_ps(iy2,jy0);
706 dz20 = _mm_sub_ps(iz2,jz0);
708 /* Calculate squared distance and things based on it */
709 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
710 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
711 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
713 rinv00 = sse41_invsqrt_f(rsq00);
714 rinv10 = sse41_invsqrt_f(rsq10);
715 rinv20 = sse41_invsqrt_f(rsq20);
717 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
718 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
719 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
721 /* Load parameters for j particles */
722 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
723 charge+jnrC+0,charge+jnrD+0);
724 vdwjidx0A = 2*vdwtype[jnrA+0];
725 vdwjidx0B = 2*vdwtype[jnrB+0];
726 vdwjidx0C = 2*vdwtype[jnrC+0];
727 vdwjidx0D = 2*vdwtype[jnrD+0];
729 fjx0 = _mm_setzero_ps();
730 fjy0 = _mm_setzero_ps();
731 fjz0 = _mm_setzero_ps();
733 /**************************
734 * CALCULATE INTERACTIONS *
735 **************************/
737 /* Compute parameters for interactions between i and j atoms */
738 qq00 = _mm_mul_ps(iq0,jq0);
739 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
740 vdwparam+vdwioffset0+vdwjidx0B,
741 vdwparam+vdwioffset0+vdwjidx0C,
742 vdwparam+vdwioffset0+vdwjidx0D,
745 /* COULOMB ELECTROSTATICS */
746 velec = _mm_mul_ps(qq00,rinv00);
747 felec = _mm_mul_ps(velec,rinvsq00);
749 /* LENNARD-JONES DISPERSION/REPULSION */
751 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
752 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
754 fscal = _mm_add_ps(felec,fvdw);
756 /* Calculate temporary vectorial force */
757 tx = _mm_mul_ps(fscal,dx00);
758 ty = _mm_mul_ps(fscal,dy00);
759 tz = _mm_mul_ps(fscal,dz00);
761 /* Update vectorial force */
762 fix0 = _mm_add_ps(fix0,tx);
763 fiy0 = _mm_add_ps(fiy0,ty);
764 fiz0 = _mm_add_ps(fiz0,tz);
766 fjx0 = _mm_add_ps(fjx0,tx);
767 fjy0 = _mm_add_ps(fjy0,ty);
768 fjz0 = _mm_add_ps(fjz0,tz);
770 /**************************
771 * CALCULATE INTERACTIONS *
772 **************************/
774 /* Compute parameters for interactions between i and j atoms */
775 qq10 = _mm_mul_ps(iq1,jq0);
777 /* COULOMB ELECTROSTATICS */
778 velec = _mm_mul_ps(qq10,rinv10);
779 felec = _mm_mul_ps(velec,rinvsq10);
783 /* Calculate temporary vectorial force */
784 tx = _mm_mul_ps(fscal,dx10);
785 ty = _mm_mul_ps(fscal,dy10);
786 tz = _mm_mul_ps(fscal,dz10);
788 /* Update vectorial force */
789 fix1 = _mm_add_ps(fix1,tx);
790 fiy1 = _mm_add_ps(fiy1,ty);
791 fiz1 = _mm_add_ps(fiz1,tz);
793 fjx0 = _mm_add_ps(fjx0,tx);
794 fjy0 = _mm_add_ps(fjy0,ty);
795 fjz0 = _mm_add_ps(fjz0,tz);
797 /**************************
798 * CALCULATE INTERACTIONS *
799 **************************/
801 /* Compute parameters for interactions between i and j atoms */
802 qq20 = _mm_mul_ps(iq2,jq0);
804 /* COULOMB ELECTROSTATICS */
805 velec = _mm_mul_ps(qq20,rinv20);
806 felec = _mm_mul_ps(velec,rinvsq20);
810 /* Calculate temporary vectorial force */
811 tx = _mm_mul_ps(fscal,dx20);
812 ty = _mm_mul_ps(fscal,dy20);
813 tz = _mm_mul_ps(fscal,dz20);
815 /* Update vectorial force */
816 fix2 = _mm_add_ps(fix2,tx);
817 fiy2 = _mm_add_ps(fiy2,ty);
818 fiz2 = _mm_add_ps(fiz2,tz);
820 fjx0 = _mm_add_ps(fjx0,tx);
821 fjy0 = _mm_add_ps(fjy0,ty);
822 fjz0 = _mm_add_ps(fjz0,tz);
824 fjptrA = f+j_coord_offsetA;
825 fjptrB = f+j_coord_offsetB;
826 fjptrC = f+j_coord_offsetC;
827 fjptrD = f+j_coord_offsetD;
829 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
831 /* Inner loop uses 88 flops */
837 /* Get j neighbor index, and coordinate index */
838 jnrlistA = jjnr[jidx];
839 jnrlistB = jjnr[jidx+1];
840 jnrlistC = jjnr[jidx+2];
841 jnrlistD = jjnr[jidx+3];
842 /* Sign of each element will be negative for non-real atoms.
843 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
844 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
846 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
847 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
848 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
849 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
850 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
851 j_coord_offsetA = DIM*jnrA;
852 j_coord_offsetB = DIM*jnrB;
853 j_coord_offsetC = DIM*jnrC;
854 j_coord_offsetD = DIM*jnrD;
856 /* load j atom coordinates */
857 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
858 x+j_coord_offsetC,x+j_coord_offsetD,
861 /* Calculate displacement vector */
862 dx00 = _mm_sub_ps(ix0,jx0);
863 dy00 = _mm_sub_ps(iy0,jy0);
864 dz00 = _mm_sub_ps(iz0,jz0);
865 dx10 = _mm_sub_ps(ix1,jx0);
866 dy10 = _mm_sub_ps(iy1,jy0);
867 dz10 = _mm_sub_ps(iz1,jz0);
868 dx20 = _mm_sub_ps(ix2,jx0);
869 dy20 = _mm_sub_ps(iy2,jy0);
870 dz20 = _mm_sub_ps(iz2,jz0);
872 /* Calculate squared distance and things based on it */
873 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
874 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
875 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
877 rinv00 = sse41_invsqrt_f(rsq00);
878 rinv10 = sse41_invsqrt_f(rsq10);
879 rinv20 = sse41_invsqrt_f(rsq20);
881 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
882 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
883 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
885 /* Load parameters for j particles */
886 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
887 charge+jnrC+0,charge+jnrD+0);
888 vdwjidx0A = 2*vdwtype[jnrA+0];
889 vdwjidx0B = 2*vdwtype[jnrB+0];
890 vdwjidx0C = 2*vdwtype[jnrC+0];
891 vdwjidx0D = 2*vdwtype[jnrD+0];
893 fjx0 = _mm_setzero_ps();
894 fjy0 = _mm_setzero_ps();
895 fjz0 = _mm_setzero_ps();
897 /**************************
898 * CALCULATE INTERACTIONS *
899 **************************/
901 /* Compute parameters for interactions between i and j atoms */
902 qq00 = _mm_mul_ps(iq0,jq0);
903 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
904 vdwparam+vdwioffset0+vdwjidx0B,
905 vdwparam+vdwioffset0+vdwjidx0C,
906 vdwparam+vdwioffset0+vdwjidx0D,
909 /* COULOMB ELECTROSTATICS */
910 velec = _mm_mul_ps(qq00,rinv00);
911 felec = _mm_mul_ps(velec,rinvsq00);
913 /* LENNARD-JONES DISPERSION/REPULSION */
915 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
916 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
918 fscal = _mm_add_ps(felec,fvdw);
920 fscal = _mm_andnot_ps(dummy_mask,fscal);
922 /* Calculate temporary vectorial force */
923 tx = _mm_mul_ps(fscal,dx00);
924 ty = _mm_mul_ps(fscal,dy00);
925 tz = _mm_mul_ps(fscal,dz00);
927 /* Update vectorial force */
928 fix0 = _mm_add_ps(fix0,tx);
929 fiy0 = _mm_add_ps(fiy0,ty);
930 fiz0 = _mm_add_ps(fiz0,tz);
932 fjx0 = _mm_add_ps(fjx0,tx);
933 fjy0 = _mm_add_ps(fjy0,ty);
934 fjz0 = _mm_add_ps(fjz0,tz);
936 /**************************
937 * CALCULATE INTERACTIONS *
938 **************************/
940 /* Compute parameters for interactions between i and j atoms */
941 qq10 = _mm_mul_ps(iq1,jq0);
943 /* COULOMB ELECTROSTATICS */
944 velec = _mm_mul_ps(qq10,rinv10);
945 felec = _mm_mul_ps(velec,rinvsq10);
949 fscal = _mm_andnot_ps(dummy_mask,fscal);
951 /* Calculate temporary vectorial force */
952 tx = _mm_mul_ps(fscal,dx10);
953 ty = _mm_mul_ps(fscal,dy10);
954 tz = _mm_mul_ps(fscal,dz10);
956 /* Update vectorial force */
957 fix1 = _mm_add_ps(fix1,tx);
958 fiy1 = _mm_add_ps(fiy1,ty);
959 fiz1 = _mm_add_ps(fiz1,tz);
961 fjx0 = _mm_add_ps(fjx0,tx);
962 fjy0 = _mm_add_ps(fjy0,ty);
963 fjz0 = _mm_add_ps(fjz0,tz);
965 /**************************
966 * CALCULATE INTERACTIONS *
967 **************************/
969 /* Compute parameters for interactions between i and j atoms */
970 qq20 = _mm_mul_ps(iq2,jq0);
972 /* COULOMB ELECTROSTATICS */
973 velec = _mm_mul_ps(qq20,rinv20);
974 felec = _mm_mul_ps(velec,rinvsq20);
978 fscal = _mm_andnot_ps(dummy_mask,fscal);
980 /* Calculate temporary vectorial force */
981 tx = _mm_mul_ps(fscal,dx20);
982 ty = _mm_mul_ps(fscal,dy20);
983 tz = _mm_mul_ps(fscal,dz20);
985 /* Update vectorial force */
986 fix2 = _mm_add_ps(fix2,tx);
987 fiy2 = _mm_add_ps(fiy2,ty);
988 fiz2 = _mm_add_ps(fiz2,tz);
990 fjx0 = _mm_add_ps(fjx0,tx);
991 fjy0 = _mm_add_ps(fjy0,ty);
992 fjz0 = _mm_add_ps(fjz0,tz);
994 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
995 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
996 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
997 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
999 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1001 /* Inner loop uses 88 flops */
1004 /* End of innermost loop */
1006 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1007 f+i_coord_offset,fshift+i_shift_offset);
1009 /* Increment number of inner iterations */
1010 inneriter += j_index_end - j_index_start;
1012 /* Outer loop uses 18 flops */
1015 /* Increment number of outer iterations */
1018 /* Update outer/inner flops */
1020 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*88);