2 * Note: this file was generated by the Gromacs sse2_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_sse2_single.h"
34 #include "kernelutil_x86_sse2_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_sse2_single
38 * Electrostatics interaction: None
39 * VdW interaction: LennardJones
40 * Geometry: Particle-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_sse2_single
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
62 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
63 real shX,shY,shZ,rcutoff_scalar;
64 real *shiftvec,*fshift,*x,*f;
65 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
67 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
68 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
69 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
70 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
72 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
75 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
76 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
77 __m128 dummy_mask,cutoff_mask;
78 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
79 __m128 one = _mm_set1_ps(1.0);
80 __m128 two = _mm_set1_ps(2.0);
86 jindex = nlist->jindex;
88 shiftidx = nlist->shift;
90 shiftvec = fr->shift_vec[0];
91 fshift = fr->fshift[0];
94 vdwtype = mdatoms->typeA;
96 /* Avoid stupid compiler warnings */
97 jnrA = jnrB = jnrC = jnrD = 0;
106 /* Start outer loop over neighborlists */
107 for(iidx=0; iidx<nri; iidx++)
109 /* Load shift vector for this list */
110 i_shift_offset = DIM*shiftidx[iidx];
111 shX = shiftvec[i_shift_offset+XX];
112 shY = shiftvec[i_shift_offset+YY];
113 shZ = shiftvec[i_shift_offset+ZZ];
115 /* Load limits for loop over neighbors */
116 j_index_start = jindex[iidx];
117 j_index_end = jindex[iidx+1];
119 /* Get outer coordinate index */
121 i_coord_offset = DIM*inr;
123 /* Load i particle coords and add shift vector */
124 ix0 = _mm_set1_ps(shX + x[i_coord_offset+DIM*0+XX]);
125 iy0 = _mm_set1_ps(shY + x[i_coord_offset+DIM*0+YY]);
126 iz0 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*0+ZZ]);
128 fix0 = _mm_setzero_ps();
129 fiy0 = _mm_setzero_ps();
130 fiz0 = _mm_setzero_ps();
132 /* Load parameters for i particles */
133 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
135 /* Reset potential sums */
136 vvdwsum = _mm_setzero_ps();
138 /* Start inner kernel loop */
139 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
142 /* Get j neighbor index, and coordinate index */
148 j_coord_offsetA = DIM*jnrA;
149 j_coord_offsetB = DIM*jnrB;
150 j_coord_offsetC = DIM*jnrC;
151 j_coord_offsetD = DIM*jnrD;
153 /* load j atom coordinates */
154 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
155 x+j_coord_offsetC,x+j_coord_offsetD,
158 /* Calculate displacement vector */
159 dx00 = _mm_sub_ps(ix0,jx0);
160 dy00 = _mm_sub_ps(iy0,jy0);
161 dz00 = _mm_sub_ps(iz0,jz0);
163 /* Calculate squared distance and things based on it */
164 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
166 rinvsq00 = gmx_mm_inv_ps(rsq00);
168 /* Load parameters for j particles */
169 vdwjidx0A = 2*vdwtype[jnrA+0];
170 vdwjidx0B = 2*vdwtype[jnrB+0];
171 vdwjidx0C = 2*vdwtype[jnrC+0];
172 vdwjidx0D = 2*vdwtype[jnrD+0];
174 /**************************
175 * CALCULATE INTERACTIONS *
176 **************************/
178 /* Compute parameters for interactions between i and j atoms */
179 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
180 vdwparam+vdwioffset0+vdwjidx0B,
181 vdwparam+vdwioffset0+vdwjidx0C,
182 vdwparam+vdwioffset0+vdwjidx0D,
185 /* LENNARD-JONES DISPERSION/REPULSION */
187 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
188 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
189 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
190 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
191 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
193 /* Update potential sum for this i atom from the interaction with this j atom. */
194 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
198 /* Calculate temporary vectorial force */
199 tx = _mm_mul_ps(fscal,dx00);
200 ty = _mm_mul_ps(fscal,dy00);
201 tz = _mm_mul_ps(fscal,dz00);
203 /* Update vectorial force */
204 fix0 = _mm_add_ps(fix0,tx);
205 fiy0 = _mm_add_ps(fiy0,ty);
206 fiz0 = _mm_add_ps(fiz0,tz);
208 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
209 f+j_coord_offsetC,f+j_coord_offsetD,
212 /* Inner loop uses 32 flops */
218 /* Get j neighbor index, and coordinate index */
224 /* Sign of each element will be negative for non-real atoms.
225 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
226 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
228 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
229 jnrA = (jnrA>=0) ? jnrA : 0;
230 jnrB = (jnrB>=0) ? jnrB : 0;
231 jnrC = (jnrC>=0) ? jnrC : 0;
232 jnrD = (jnrD>=0) ? jnrD : 0;
234 j_coord_offsetA = DIM*jnrA;
235 j_coord_offsetB = DIM*jnrB;
236 j_coord_offsetC = DIM*jnrC;
237 j_coord_offsetD = DIM*jnrD;
239 /* load j atom coordinates */
240 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
241 x+j_coord_offsetC,x+j_coord_offsetD,
244 /* Calculate displacement vector */
245 dx00 = _mm_sub_ps(ix0,jx0);
246 dy00 = _mm_sub_ps(iy0,jy0);
247 dz00 = _mm_sub_ps(iz0,jz0);
249 /* Calculate squared distance and things based on it */
250 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
252 rinvsq00 = gmx_mm_inv_ps(rsq00);
254 /* Load parameters for j particles */
255 vdwjidx0A = 2*vdwtype[jnrA+0];
256 vdwjidx0B = 2*vdwtype[jnrB+0];
257 vdwjidx0C = 2*vdwtype[jnrC+0];
258 vdwjidx0D = 2*vdwtype[jnrD+0];
260 /**************************
261 * CALCULATE INTERACTIONS *
262 **************************/
264 /* Compute parameters for interactions between i and j atoms */
265 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
266 vdwparam+vdwioffset0+vdwjidx0B,
267 vdwparam+vdwioffset0+vdwjidx0C,
268 vdwparam+vdwioffset0+vdwjidx0D,
271 /* LENNARD-JONES DISPERSION/REPULSION */
273 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
274 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
275 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
276 vvdw = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
277 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
279 /* Update potential sum for this i atom from the interaction with this j atom. */
280 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
281 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
285 fscal = _mm_andnot_ps(dummy_mask,fscal);
287 /* Calculate temporary vectorial force */
288 tx = _mm_mul_ps(fscal,dx00);
289 ty = _mm_mul_ps(fscal,dy00);
290 tz = _mm_mul_ps(fscal,dz00);
292 /* Update vectorial force */
293 fix0 = _mm_add_ps(fix0,tx);
294 fiy0 = _mm_add_ps(fiy0,ty);
295 fiz0 = _mm_add_ps(fiz0,tz);
297 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
298 f+j_coord_offsetC,f+j_coord_offsetD,
301 /* Inner loop uses 32 flops */
304 /* End of innermost loop */
306 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
307 f+i_coord_offset,fshift+i_shift_offset);
310 /* Update potential energies */
311 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
313 /* Increment number of inner iterations */
314 inneriter += j_index_end - j_index_start;
316 /* Outer loop uses 10 flops */
319 /* Increment number of outer iterations */
322 /* Update outer/inner flops */
324 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*10 + inneriter*32);
327 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_sse2_single
328 * Electrostatics interaction: None
329 * VdW interaction: LennardJones
330 * Geometry: Particle-Particle
331 * Calculate force/pot: Force
334 nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_sse2_single
335 (t_nblist * gmx_restrict nlist,
336 rvec * gmx_restrict xx,
337 rvec * gmx_restrict ff,
338 t_forcerec * gmx_restrict fr,
339 t_mdatoms * gmx_restrict mdatoms,
340 nb_kernel_data_t * gmx_restrict kernel_data,
341 t_nrnb * gmx_restrict nrnb)
343 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
344 * just 0 for non-waters.
345 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
346 * jnr indices corresponding to data put in the four positions in the SIMD register.
348 int i_shift_offset,i_coord_offset,outeriter,inneriter;
349 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
350 int jnrA,jnrB,jnrC,jnrD;
351 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
352 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
353 real shX,shY,shZ,rcutoff_scalar;
354 real *shiftvec,*fshift,*x,*f;
355 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
357 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
358 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
359 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
360 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
362 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
365 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
366 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
367 __m128 dummy_mask,cutoff_mask;
368 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
369 __m128 one = _mm_set1_ps(1.0);
370 __m128 two = _mm_set1_ps(2.0);
376 jindex = nlist->jindex;
378 shiftidx = nlist->shift;
380 shiftvec = fr->shift_vec[0];
381 fshift = fr->fshift[0];
382 nvdwtype = fr->ntype;
384 vdwtype = mdatoms->typeA;
386 /* Avoid stupid compiler warnings */
387 jnrA = jnrB = jnrC = jnrD = 0;
396 /* Start outer loop over neighborlists */
397 for(iidx=0; iidx<nri; iidx++)
399 /* Load shift vector for this list */
400 i_shift_offset = DIM*shiftidx[iidx];
401 shX = shiftvec[i_shift_offset+XX];
402 shY = shiftvec[i_shift_offset+YY];
403 shZ = shiftvec[i_shift_offset+ZZ];
405 /* Load limits for loop over neighbors */
406 j_index_start = jindex[iidx];
407 j_index_end = jindex[iidx+1];
409 /* Get outer coordinate index */
411 i_coord_offset = DIM*inr;
413 /* Load i particle coords and add shift vector */
414 ix0 = _mm_set1_ps(shX + x[i_coord_offset+DIM*0+XX]);
415 iy0 = _mm_set1_ps(shY + x[i_coord_offset+DIM*0+YY]);
416 iz0 = _mm_set1_ps(shZ + x[i_coord_offset+DIM*0+ZZ]);
418 fix0 = _mm_setzero_ps();
419 fiy0 = _mm_setzero_ps();
420 fiz0 = _mm_setzero_ps();
422 /* Load parameters for i particles */
423 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
425 /* Start inner kernel loop */
426 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
429 /* Get j neighbor index, and coordinate index */
435 j_coord_offsetA = DIM*jnrA;
436 j_coord_offsetB = DIM*jnrB;
437 j_coord_offsetC = DIM*jnrC;
438 j_coord_offsetD = DIM*jnrD;
440 /* load j atom coordinates */
441 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
442 x+j_coord_offsetC,x+j_coord_offsetD,
445 /* Calculate displacement vector */
446 dx00 = _mm_sub_ps(ix0,jx0);
447 dy00 = _mm_sub_ps(iy0,jy0);
448 dz00 = _mm_sub_ps(iz0,jz0);
450 /* Calculate squared distance and things based on it */
451 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
453 rinvsq00 = gmx_mm_inv_ps(rsq00);
455 /* Load parameters for j particles */
456 vdwjidx0A = 2*vdwtype[jnrA+0];
457 vdwjidx0B = 2*vdwtype[jnrB+0];
458 vdwjidx0C = 2*vdwtype[jnrC+0];
459 vdwjidx0D = 2*vdwtype[jnrD+0];
461 /**************************
462 * CALCULATE INTERACTIONS *
463 **************************/
465 /* Compute parameters for interactions between i and j atoms */
466 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
467 vdwparam+vdwioffset0+vdwjidx0B,
468 vdwparam+vdwioffset0+vdwjidx0C,
469 vdwparam+vdwioffset0+vdwjidx0D,
472 /* LENNARD-JONES DISPERSION/REPULSION */
474 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
475 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
479 /* Calculate temporary vectorial force */
480 tx = _mm_mul_ps(fscal,dx00);
481 ty = _mm_mul_ps(fscal,dy00);
482 tz = _mm_mul_ps(fscal,dz00);
484 /* Update vectorial force */
485 fix0 = _mm_add_ps(fix0,tx);
486 fiy0 = _mm_add_ps(fiy0,ty);
487 fiz0 = _mm_add_ps(fiz0,tz);
489 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
490 f+j_coord_offsetC,f+j_coord_offsetD,
493 /* Inner loop uses 27 flops */
499 /* Get j neighbor index, and coordinate index */
505 /* Sign of each element will be negative for non-real atoms.
506 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
507 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
509 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
510 jnrA = (jnrA>=0) ? jnrA : 0;
511 jnrB = (jnrB>=0) ? jnrB : 0;
512 jnrC = (jnrC>=0) ? jnrC : 0;
513 jnrD = (jnrD>=0) ? jnrD : 0;
515 j_coord_offsetA = DIM*jnrA;
516 j_coord_offsetB = DIM*jnrB;
517 j_coord_offsetC = DIM*jnrC;
518 j_coord_offsetD = DIM*jnrD;
520 /* load j atom coordinates */
521 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
522 x+j_coord_offsetC,x+j_coord_offsetD,
525 /* Calculate displacement vector */
526 dx00 = _mm_sub_ps(ix0,jx0);
527 dy00 = _mm_sub_ps(iy0,jy0);
528 dz00 = _mm_sub_ps(iz0,jz0);
530 /* Calculate squared distance and things based on it */
531 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
533 rinvsq00 = gmx_mm_inv_ps(rsq00);
535 /* Load parameters for j particles */
536 vdwjidx0A = 2*vdwtype[jnrA+0];
537 vdwjidx0B = 2*vdwtype[jnrB+0];
538 vdwjidx0C = 2*vdwtype[jnrC+0];
539 vdwjidx0D = 2*vdwtype[jnrD+0];
541 /**************************
542 * CALCULATE INTERACTIONS *
543 **************************/
545 /* Compute parameters for interactions between i and j atoms */
546 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
547 vdwparam+vdwioffset0+vdwjidx0B,
548 vdwparam+vdwioffset0+vdwjidx0C,
549 vdwparam+vdwioffset0+vdwjidx0D,
552 /* LENNARD-JONES DISPERSION/REPULSION */
554 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
555 fvdw = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
559 fscal = _mm_andnot_ps(dummy_mask,fscal);
561 /* Calculate temporary vectorial force */
562 tx = _mm_mul_ps(fscal,dx00);
563 ty = _mm_mul_ps(fscal,dy00);
564 tz = _mm_mul_ps(fscal,dz00);
566 /* Update vectorial force */
567 fix0 = _mm_add_ps(fix0,tx);
568 fiy0 = _mm_add_ps(fiy0,ty);
569 fiz0 = _mm_add_ps(fiz0,tz);
571 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
572 f+j_coord_offsetC,f+j_coord_offsetD,
575 /* Inner loop uses 27 flops */
578 /* End of innermost loop */
580 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
581 f+i_coord_offset,fshift+i_shift_offset);
583 /* Increment number of inner iterations */
584 inneriter += j_index_end - j_index_start;
586 /* Outer loop uses 9 flops */
589 /* Increment number of outer iterations */
592 /* Update outer/inner flops */
594 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*9 + inneriter*27);