Removed simple.h from nb_kernel_sse2_XX
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_double / nb_kernel_ElecNone_VdwLJ_GeomP1P1_sse2_double.c
blobebbb770054f127b471ec61b49b77a2921ee4c744
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015, 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.
38 #include "gmxpre.h"
40 #include "config.h"
42 #include <math.h>
44 #include "../nb_kernel.h"
45 #include "gromacs/math/vec.h"
46 #include "gromacs/legacyheaders/nrnb.h"
48 #include "gromacs/simd/math_x86_sse2_double.h"
49 #include "kernelutil_x86_sse2_double.h"
52 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_sse2_double
53 * Electrostatics interaction: None
54 * VdW interaction: LennardJones
55 * Geometry: Particle-Particle
56 * Calculate force/pot: PotentialAndForce
58 void
59 nb_kernel_ElecNone_VdwLJ_GeomP1P1_VF_sse2_double
60 (t_nblist * gmx_restrict nlist,
61 rvec * gmx_restrict xx,
62 rvec * gmx_restrict ff,
63 t_forcerec * gmx_restrict fr,
64 t_mdatoms * gmx_restrict mdatoms,
65 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
66 t_nrnb * gmx_restrict nrnb)
68 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
69 * just 0 for non-waters.
70 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
71 * jnr indices corresponding to data put in the four positions in the SIMD register.
73 int i_shift_offset,i_coord_offset,outeriter,inneriter;
74 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75 int jnrA,jnrB;
76 int j_coord_offsetA,j_coord_offsetB;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real rcutoff_scalar;
79 real *shiftvec,*fshift,*x,*f;
80 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 int vdwioffset0;
82 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
83 int vdwjidx0A,vdwjidx0B;
84 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
85 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
86 int nvdwtype;
87 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
88 int *vdwtype;
89 real *vdwparam;
90 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
91 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
92 __m128d dummy_mask,cutoff_mask;
93 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
94 __m128d one = _mm_set1_pd(1.0);
95 __m128d two = _mm_set1_pd(2.0);
96 x = xx[0];
97 f = ff[0];
99 nri = nlist->nri;
100 iinr = nlist->iinr;
101 jindex = nlist->jindex;
102 jjnr = nlist->jjnr;
103 shiftidx = nlist->shift;
104 gid = nlist->gid;
105 shiftvec = fr->shift_vec[0];
106 fshift = fr->fshift[0];
107 nvdwtype = fr->ntype;
108 vdwparam = fr->nbfp;
109 vdwtype = mdatoms->typeA;
111 /* Avoid stupid compiler warnings */
112 jnrA = jnrB = 0;
113 j_coord_offsetA = 0;
114 j_coord_offsetB = 0;
116 outeriter = 0;
117 inneriter = 0;
119 /* Start outer loop over neighborlists */
120 for(iidx=0; iidx<nri; iidx++)
122 /* Load shift vector for this list */
123 i_shift_offset = DIM*shiftidx[iidx];
125 /* Load limits for loop over neighbors */
126 j_index_start = jindex[iidx];
127 j_index_end = jindex[iidx+1];
129 /* Get outer coordinate index */
130 inr = iinr[iidx];
131 i_coord_offset = DIM*inr;
133 /* Load i particle coords and add shift vector */
134 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
136 fix0 = _mm_setzero_pd();
137 fiy0 = _mm_setzero_pd();
138 fiz0 = _mm_setzero_pd();
140 /* Load parameters for i particles */
141 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
143 /* Reset potential sums */
144 vvdwsum = _mm_setzero_pd();
146 /* Start inner kernel loop */
147 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
150 /* Get j neighbor index, and coordinate index */
151 jnrA = jjnr[jidx];
152 jnrB = jjnr[jidx+1];
153 j_coord_offsetA = DIM*jnrA;
154 j_coord_offsetB = DIM*jnrB;
156 /* load j atom coordinates */
157 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
158 &jx0,&jy0,&jz0);
160 /* Calculate displacement vector */
161 dx00 = _mm_sub_pd(ix0,jx0);
162 dy00 = _mm_sub_pd(iy0,jy0);
163 dz00 = _mm_sub_pd(iz0,jz0);
165 /* Calculate squared distance and things based on it */
166 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
168 rinvsq00 = gmx_mm_inv_pd(rsq00);
170 /* Load parameters for j particles */
171 vdwjidx0A = 2*vdwtype[jnrA+0];
172 vdwjidx0B = 2*vdwtype[jnrB+0];
174 /**************************
175 * CALCULATE INTERACTIONS *
176 **************************/
178 /* Compute parameters for interactions between i and j atoms */
179 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
180 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
182 /* LENNARD-JONES DISPERSION/REPULSION */
184 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
185 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
186 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
187 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
188 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
190 /* Update potential sum for this i atom from the interaction with this j atom. */
191 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
193 fscal = fvdw;
195 /* Calculate temporary vectorial force */
196 tx = _mm_mul_pd(fscal,dx00);
197 ty = _mm_mul_pd(fscal,dy00);
198 tz = _mm_mul_pd(fscal,dz00);
200 /* Update vectorial force */
201 fix0 = _mm_add_pd(fix0,tx);
202 fiy0 = _mm_add_pd(fiy0,ty);
203 fiz0 = _mm_add_pd(fiz0,tz);
205 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
207 /* Inner loop uses 32 flops */
210 if(jidx<j_index_end)
213 jnrA = jjnr[jidx];
214 j_coord_offsetA = DIM*jnrA;
216 /* load j atom coordinates */
217 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
218 &jx0,&jy0,&jz0);
220 /* Calculate displacement vector */
221 dx00 = _mm_sub_pd(ix0,jx0);
222 dy00 = _mm_sub_pd(iy0,jy0);
223 dz00 = _mm_sub_pd(iz0,jz0);
225 /* Calculate squared distance and things based on it */
226 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
228 rinvsq00 = gmx_mm_inv_pd(rsq00);
230 /* Load parameters for j particles */
231 vdwjidx0A = 2*vdwtype[jnrA+0];
233 /**************************
234 * CALCULATE INTERACTIONS *
235 **************************/
237 /* Compute parameters for interactions between i and j atoms */
238 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
240 /* LENNARD-JONES DISPERSION/REPULSION */
242 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
243 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
244 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
245 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
246 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
248 /* Update potential sum for this i atom from the interaction with this j atom. */
249 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
250 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
252 fscal = fvdw;
254 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
256 /* Calculate temporary vectorial force */
257 tx = _mm_mul_pd(fscal,dx00);
258 ty = _mm_mul_pd(fscal,dy00);
259 tz = _mm_mul_pd(fscal,dz00);
261 /* Update vectorial force */
262 fix0 = _mm_add_pd(fix0,tx);
263 fiy0 = _mm_add_pd(fiy0,ty);
264 fiz0 = _mm_add_pd(fiz0,tz);
266 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
268 /* Inner loop uses 32 flops */
271 /* End of innermost loop */
273 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
274 f+i_coord_offset,fshift+i_shift_offset);
276 ggid = gid[iidx];
277 /* Update potential energies */
278 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
280 /* Increment number of inner iterations */
281 inneriter += j_index_end - j_index_start;
283 /* Outer loop uses 7 flops */
286 /* Increment number of outer iterations */
287 outeriter += nri;
289 /* Update outer/inner flops */
291 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_VF,outeriter*7 + inneriter*32);
294 * Gromacs nonbonded kernel: nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_sse2_double
295 * Electrostatics interaction: None
296 * VdW interaction: LennardJones
297 * Geometry: Particle-Particle
298 * Calculate force/pot: Force
300 void
301 nb_kernel_ElecNone_VdwLJ_GeomP1P1_F_sse2_double
302 (t_nblist * gmx_restrict nlist,
303 rvec * gmx_restrict xx,
304 rvec * gmx_restrict ff,
305 t_forcerec * gmx_restrict fr,
306 t_mdatoms * gmx_restrict mdatoms,
307 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
308 t_nrnb * gmx_restrict nrnb)
310 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
311 * just 0 for non-waters.
312 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
313 * jnr indices corresponding to data put in the four positions in the SIMD register.
315 int i_shift_offset,i_coord_offset,outeriter,inneriter;
316 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
317 int jnrA,jnrB;
318 int j_coord_offsetA,j_coord_offsetB;
319 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
320 real rcutoff_scalar;
321 real *shiftvec,*fshift,*x,*f;
322 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
323 int vdwioffset0;
324 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
325 int vdwjidx0A,vdwjidx0B;
326 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
327 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
328 int nvdwtype;
329 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
330 int *vdwtype;
331 real *vdwparam;
332 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
333 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
334 __m128d dummy_mask,cutoff_mask;
335 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
336 __m128d one = _mm_set1_pd(1.0);
337 __m128d two = _mm_set1_pd(2.0);
338 x = xx[0];
339 f = ff[0];
341 nri = nlist->nri;
342 iinr = nlist->iinr;
343 jindex = nlist->jindex;
344 jjnr = nlist->jjnr;
345 shiftidx = nlist->shift;
346 gid = nlist->gid;
347 shiftvec = fr->shift_vec[0];
348 fshift = fr->fshift[0];
349 nvdwtype = fr->ntype;
350 vdwparam = fr->nbfp;
351 vdwtype = mdatoms->typeA;
353 /* Avoid stupid compiler warnings */
354 jnrA = jnrB = 0;
355 j_coord_offsetA = 0;
356 j_coord_offsetB = 0;
358 outeriter = 0;
359 inneriter = 0;
361 /* Start outer loop over neighborlists */
362 for(iidx=0; iidx<nri; iidx++)
364 /* Load shift vector for this list */
365 i_shift_offset = DIM*shiftidx[iidx];
367 /* Load limits for loop over neighbors */
368 j_index_start = jindex[iidx];
369 j_index_end = jindex[iidx+1];
371 /* Get outer coordinate index */
372 inr = iinr[iidx];
373 i_coord_offset = DIM*inr;
375 /* Load i particle coords and add shift vector */
376 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
378 fix0 = _mm_setzero_pd();
379 fiy0 = _mm_setzero_pd();
380 fiz0 = _mm_setzero_pd();
382 /* Load parameters for i particles */
383 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
385 /* Start inner kernel loop */
386 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
389 /* Get j neighbor index, and coordinate index */
390 jnrA = jjnr[jidx];
391 jnrB = jjnr[jidx+1];
392 j_coord_offsetA = DIM*jnrA;
393 j_coord_offsetB = DIM*jnrB;
395 /* load j atom coordinates */
396 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
397 &jx0,&jy0,&jz0);
399 /* Calculate displacement vector */
400 dx00 = _mm_sub_pd(ix0,jx0);
401 dy00 = _mm_sub_pd(iy0,jy0);
402 dz00 = _mm_sub_pd(iz0,jz0);
404 /* Calculate squared distance and things based on it */
405 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
407 rinvsq00 = gmx_mm_inv_pd(rsq00);
409 /* Load parameters for j particles */
410 vdwjidx0A = 2*vdwtype[jnrA+0];
411 vdwjidx0B = 2*vdwtype[jnrB+0];
413 /**************************
414 * CALCULATE INTERACTIONS *
415 **************************/
417 /* Compute parameters for interactions between i and j atoms */
418 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
419 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
421 /* LENNARD-JONES DISPERSION/REPULSION */
423 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
424 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
426 fscal = fvdw;
428 /* Calculate temporary vectorial force */
429 tx = _mm_mul_pd(fscal,dx00);
430 ty = _mm_mul_pd(fscal,dy00);
431 tz = _mm_mul_pd(fscal,dz00);
433 /* Update vectorial force */
434 fix0 = _mm_add_pd(fix0,tx);
435 fiy0 = _mm_add_pd(fiy0,ty);
436 fiz0 = _mm_add_pd(fiz0,tz);
438 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
440 /* Inner loop uses 27 flops */
443 if(jidx<j_index_end)
446 jnrA = jjnr[jidx];
447 j_coord_offsetA = DIM*jnrA;
449 /* load j atom coordinates */
450 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
451 &jx0,&jy0,&jz0);
453 /* Calculate displacement vector */
454 dx00 = _mm_sub_pd(ix0,jx0);
455 dy00 = _mm_sub_pd(iy0,jy0);
456 dz00 = _mm_sub_pd(iz0,jz0);
458 /* Calculate squared distance and things based on it */
459 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
461 rinvsq00 = gmx_mm_inv_pd(rsq00);
463 /* Load parameters for j particles */
464 vdwjidx0A = 2*vdwtype[jnrA+0];
466 /**************************
467 * CALCULATE INTERACTIONS *
468 **************************/
470 /* Compute parameters for interactions between i and j atoms */
471 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
473 /* LENNARD-JONES DISPERSION/REPULSION */
475 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
476 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
478 fscal = fvdw;
480 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
482 /* Calculate temporary vectorial force */
483 tx = _mm_mul_pd(fscal,dx00);
484 ty = _mm_mul_pd(fscal,dy00);
485 tz = _mm_mul_pd(fscal,dz00);
487 /* Update vectorial force */
488 fix0 = _mm_add_pd(fix0,tx);
489 fiy0 = _mm_add_pd(fiy0,ty);
490 fiz0 = _mm_add_pd(fiz0,tz);
492 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
494 /* Inner loop uses 27 flops */
497 /* End of innermost loop */
499 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
500 f+i_coord_offset,fshift+i_shift_offset);
502 /* Increment number of inner iterations */
503 inneriter += j_index_end - j_index_start;
505 /* Outer loop uses 6 flops */
508 /* Increment number of outer iterations */
509 outeriter += nri;
511 /* Update outer/inner flops */
513 inc_nrnb(nrnb,eNR_NBKERNEL_VDW_F,outeriter*6 + inneriter*27);