2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS sse2_double kernel generator.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_sse2_double.h"
48 #include "kernelutil_x86_sse2_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomP1P1_VF_sse2_double
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRF_VdwNone_GeomP1P1_VF_sse2_double
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82 int vdwjidx0A,vdwjidx0B;
83 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
85 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
87 __m128d dummy_mask,cutoff_mask;
88 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
89 __m128d one = _mm_set1_pd(1.0);
90 __m128d two = _mm_set1_pd(2.0);
96 jindex = nlist->jindex;
98 shiftidx = nlist->shift;
100 shiftvec = fr->shift_vec[0];
101 fshift = fr->fshift[0];
102 facel = _mm_set1_pd(fr->epsfac);
103 charge = mdatoms->chargeA;
104 krf = _mm_set1_pd(fr->ic->k_rf);
105 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
106 crf = _mm_set1_pd(fr->ic->c_rf);
108 /* Avoid stupid compiler warnings */
116 /* Start outer loop over neighborlists */
117 for(iidx=0; iidx<nri; iidx++)
119 /* Load shift vector for this list */
120 i_shift_offset = DIM*shiftidx[iidx];
122 /* Load limits for loop over neighbors */
123 j_index_start = jindex[iidx];
124 j_index_end = jindex[iidx+1];
126 /* Get outer coordinate index */
128 i_coord_offset = DIM*inr;
130 /* Load i particle coords and add shift vector */
131 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
133 fix0 = _mm_setzero_pd();
134 fiy0 = _mm_setzero_pd();
135 fiz0 = _mm_setzero_pd();
137 /* Load parameters for i particles */
138 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
140 /* Reset potential sums */
141 velecsum = _mm_setzero_pd();
143 /* Start inner kernel loop */
144 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
147 /* Get j neighbor index, and coordinate index */
150 j_coord_offsetA = DIM*jnrA;
151 j_coord_offsetB = DIM*jnrB;
153 /* load j atom coordinates */
154 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
157 /* Calculate displacement vector */
158 dx00 = _mm_sub_pd(ix0,jx0);
159 dy00 = _mm_sub_pd(iy0,jy0);
160 dz00 = _mm_sub_pd(iz0,jz0);
162 /* Calculate squared distance and things based on it */
163 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
165 rinv00 = gmx_mm_invsqrt_pd(rsq00);
167 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
169 /* Load parameters for j particles */
170 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
172 /**************************
173 * CALCULATE INTERACTIONS *
174 **************************/
176 /* Compute parameters for interactions between i and j atoms */
177 qq00 = _mm_mul_pd(iq0,jq0);
179 /* REACTION-FIELD ELECTROSTATICS */
180 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
181 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
183 /* Update potential sum for this i atom from the interaction with this j atom. */
184 velecsum = _mm_add_pd(velecsum,velec);
188 /* Calculate temporary vectorial force */
189 tx = _mm_mul_pd(fscal,dx00);
190 ty = _mm_mul_pd(fscal,dy00);
191 tz = _mm_mul_pd(fscal,dz00);
193 /* Update vectorial force */
194 fix0 = _mm_add_pd(fix0,tx);
195 fiy0 = _mm_add_pd(fiy0,ty);
196 fiz0 = _mm_add_pd(fiz0,tz);
198 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
200 /* Inner loop uses 32 flops */
207 j_coord_offsetA = DIM*jnrA;
209 /* load j atom coordinates */
210 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
213 /* Calculate displacement vector */
214 dx00 = _mm_sub_pd(ix0,jx0);
215 dy00 = _mm_sub_pd(iy0,jy0);
216 dz00 = _mm_sub_pd(iz0,jz0);
218 /* Calculate squared distance and things based on it */
219 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
221 rinv00 = gmx_mm_invsqrt_pd(rsq00);
223 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
225 /* Load parameters for j particles */
226 jq0 = _mm_load_sd(charge+jnrA+0);
228 /**************************
229 * CALCULATE INTERACTIONS *
230 **************************/
232 /* Compute parameters for interactions between i and j atoms */
233 qq00 = _mm_mul_pd(iq0,jq0);
235 /* REACTION-FIELD ELECTROSTATICS */
236 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
237 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
239 /* Update potential sum for this i atom from the interaction with this j atom. */
240 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
241 velecsum = _mm_add_pd(velecsum,velec);
245 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
247 /* Calculate temporary vectorial force */
248 tx = _mm_mul_pd(fscal,dx00);
249 ty = _mm_mul_pd(fscal,dy00);
250 tz = _mm_mul_pd(fscal,dz00);
252 /* Update vectorial force */
253 fix0 = _mm_add_pd(fix0,tx);
254 fiy0 = _mm_add_pd(fiy0,ty);
255 fiz0 = _mm_add_pd(fiz0,tz);
257 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
259 /* Inner loop uses 32 flops */
262 /* End of innermost loop */
264 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
265 f+i_coord_offset,fshift+i_shift_offset);
268 /* Update potential energies */
269 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
271 /* Increment number of inner iterations */
272 inneriter += j_index_end - j_index_start;
274 /* Outer loop uses 8 flops */
277 /* Increment number of outer iterations */
280 /* Update outer/inner flops */
282 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*32);
285 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomP1P1_F_sse2_double
286 * Electrostatics interaction: ReactionField
287 * VdW interaction: None
288 * Geometry: Particle-Particle
289 * Calculate force/pot: Force
292 nb_kernel_ElecRF_VdwNone_GeomP1P1_F_sse2_double
293 (t_nblist * gmx_restrict nlist,
294 rvec * gmx_restrict xx,
295 rvec * gmx_restrict ff,
296 t_forcerec * gmx_restrict fr,
297 t_mdatoms * gmx_restrict mdatoms,
298 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
299 t_nrnb * gmx_restrict nrnb)
301 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
302 * just 0 for non-waters.
303 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
304 * jnr indices corresponding to data put in the four positions in the SIMD register.
306 int i_shift_offset,i_coord_offset,outeriter,inneriter;
307 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
309 int j_coord_offsetA,j_coord_offsetB;
310 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
312 real *shiftvec,*fshift,*x,*f;
313 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
315 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
316 int vdwjidx0A,vdwjidx0B;
317 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
318 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
319 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
321 __m128d dummy_mask,cutoff_mask;
322 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
323 __m128d one = _mm_set1_pd(1.0);
324 __m128d two = _mm_set1_pd(2.0);
330 jindex = nlist->jindex;
332 shiftidx = nlist->shift;
334 shiftvec = fr->shift_vec[0];
335 fshift = fr->fshift[0];
336 facel = _mm_set1_pd(fr->epsfac);
337 charge = mdatoms->chargeA;
338 krf = _mm_set1_pd(fr->ic->k_rf);
339 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
340 crf = _mm_set1_pd(fr->ic->c_rf);
342 /* Avoid stupid compiler warnings */
350 /* Start outer loop over neighborlists */
351 for(iidx=0; iidx<nri; iidx++)
353 /* Load shift vector for this list */
354 i_shift_offset = DIM*shiftidx[iidx];
356 /* Load limits for loop over neighbors */
357 j_index_start = jindex[iidx];
358 j_index_end = jindex[iidx+1];
360 /* Get outer coordinate index */
362 i_coord_offset = DIM*inr;
364 /* Load i particle coords and add shift vector */
365 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
367 fix0 = _mm_setzero_pd();
368 fiy0 = _mm_setzero_pd();
369 fiz0 = _mm_setzero_pd();
371 /* Load parameters for i particles */
372 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
374 /* Start inner kernel loop */
375 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
378 /* Get j neighbor index, and coordinate index */
381 j_coord_offsetA = DIM*jnrA;
382 j_coord_offsetB = DIM*jnrB;
384 /* load j atom coordinates */
385 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
388 /* Calculate displacement vector */
389 dx00 = _mm_sub_pd(ix0,jx0);
390 dy00 = _mm_sub_pd(iy0,jy0);
391 dz00 = _mm_sub_pd(iz0,jz0);
393 /* Calculate squared distance and things based on it */
394 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
396 rinv00 = gmx_mm_invsqrt_pd(rsq00);
398 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
400 /* Load parameters for j particles */
401 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
403 /**************************
404 * CALCULATE INTERACTIONS *
405 **************************/
407 /* Compute parameters for interactions between i and j atoms */
408 qq00 = _mm_mul_pd(iq0,jq0);
410 /* REACTION-FIELD ELECTROSTATICS */
411 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
415 /* Calculate temporary vectorial force */
416 tx = _mm_mul_pd(fscal,dx00);
417 ty = _mm_mul_pd(fscal,dy00);
418 tz = _mm_mul_pd(fscal,dz00);
420 /* Update vectorial force */
421 fix0 = _mm_add_pd(fix0,tx);
422 fiy0 = _mm_add_pd(fiy0,ty);
423 fiz0 = _mm_add_pd(fiz0,tz);
425 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
427 /* Inner loop uses 27 flops */
434 j_coord_offsetA = DIM*jnrA;
436 /* load j atom coordinates */
437 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
440 /* Calculate displacement vector */
441 dx00 = _mm_sub_pd(ix0,jx0);
442 dy00 = _mm_sub_pd(iy0,jy0);
443 dz00 = _mm_sub_pd(iz0,jz0);
445 /* Calculate squared distance and things based on it */
446 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
448 rinv00 = gmx_mm_invsqrt_pd(rsq00);
450 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
452 /* Load parameters for j particles */
453 jq0 = _mm_load_sd(charge+jnrA+0);
455 /**************************
456 * CALCULATE INTERACTIONS *
457 **************************/
459 /* Compute parameters for interactions between i and j atoms */
460 qq00 = _mm_mul_pd(iq0,jq0);
462 /* REACTION-FIELD ELECTROSTATICS */
463 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
467 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
469 /* Calculate temporary vectorial force */
470 tx = _mm_mul_pd(fscal,dx00);
471 ty = _mm_mul_pd(fscal,dy00);
472 tz = _mm_mul_pd(fscal,dz00);
474 /* Update vectorial force */
475 fix0 = _mm_add_pd(fix0,tx);
476 fiy0 = _mm_add_pd(fiy0,ty);
477 fiz0 = _mm_add_pd(fiz0,tz);
479 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
481 /* Inner loop uses 27 flops */
484 /* End of innermost loop */
486 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
487 f+i_coord_offset,fshift+i_shift_offset);
489 /* Increment number of inner iterations */
490 inneriter += j_index_end - j_index_start;
492 /* Outer loop uses 7 flops */
495 /* Increment number of outer iterations */
498 /* Update outer/inner flops */
500 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*27);