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_ElecRFCut_VdwNone_GeomP1P1_VF_sse4_1_double
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_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;
84 int vdwjidx0A,vdwjidx0B;
85 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
89 __m128d dummy_mask,cutoff_mask;
90 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
91 __m128d one = _mm_set1_pd(1.0);
92 __m128d two = _mm_set1_pd(2.0);
98 jindex = nlist->jindex;
100 shiftidx = nlist->shift;
102 shiftvec = fr->shift_vec[0];
103 fshift = fr->fshift[0];
104 facel = _mm_set1_pd(fr->epsfac);
105 charge = mdatoms->chargeA;
106 krf = _mm_set1_pd(fr->ic->k_rf);
107 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
108 crf = _mm_set1_pd(fr->ic->c_rf);
110 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
111 rcutoff_scalar = fr->rcoulomb;
112 rcutoff = _mm_set1_pd(rcutoff_scalar);
113 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
115 /* Avoid stupid compiler warnings */
123 /* Start outer loop over neighborlists */
124 for(iidx=0; iidx<nri; iidx++)
126 /* Load shift vector for this list */
127 i_shift_offset = DIM*shiftidx[iidx];
129 /* Load limits for loop over neighbors */
130 j_index_start = jindex[iidx];
131 j_index_end = jindex[iidx+1];
133 /* Get outer coordinate index */
135 i_coord_offset = DIM*inr;
137 /* Load i particle coords and add shift vector */
138 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
140 fix0 = _mm_setzero_pd();
141 fiy0 = _mm_setzero_pd();
142 fiz0 = _mm_setzero_pd();
144 /* Load parameters for i particles */
145 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
147 /* Reset potential sums */
148 velecsum = _mm_setzero_pd();
150 /* Start inner kernel loop */
151 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
154 /* Get j neighbor index, and coordinate index */
157 j_coord_offsetA = DIM*jnrA;
158 j_coord_offsetB = DIM*jnrB;
160 /* load j atom coordinates */
161 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
164 /* Calculate displacement vector */
165 dx00 = _mm_sub_pd(ix0,jx0);
166 dy00 = _mm_sub_pd(iy0,jy0);
167 dz00 = _mm_sub_pd(iz0,jz0);
169 /* Calculate squared distance and things based on it */
170 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
172 rinv00 = gmx_mm_invsqrt_pd(rsq00);
174 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
176 /* Load parameters for j particles */
177 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
179 /**************************
180 * CALCULATE INTERACTIONS *
181 **************************/
183 if (gmx_mm_any_lt(rsq00,rcutoff2))
186 /* Compute parameters for interactions between i and j atoms */
187 qq00 = _mm_mul_pd(iq0,jq0);
189 /* REACTION-FIELD ELECTROSTATICS */
190 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
191 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
193 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
195 /* Update potential sum for this i atom from the interaction with this j atom. */
196 velec = _mm_and_pd(velec,cutoff_mask);
197 velecsum = _mm_add_pd(velecsum,velec);
201 fscal = _mm_and_pd(fscal,cutoff_mask);
203 /* Calculate temporary vectorial force */
204 tx = _mm_mul_pd(fscal,dx00);
205 ty = _mm_mul_pd(fscal,dy00);
206 tz = _mm_mul_pd(fscal,dz00);
208 /* Update vectorial force */
209 fix0 = _mm_add_pd(fix0,tx);
210 fiy0 = _mm_add_pd(fiy0,ty);
211 fiz0 = _mm_add_pd(fiz0,tz);
213 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
217 /* Inner loop uses 36 flops */
224 j_coord_offsetA = DIM*jnrA;
226 /* load j atom coordinates */
227 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
230 /* Calculate displacement vector */
231 dx00 = _mm_sub_pd(ix0,jx0);
232 dy00 = _mm_sub_pd(iy0,jy0);
233 dz00 = _mm_sub_pd(iz0,jz0);
235 /* Calculate squared distance and things based on it */
236 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
238 rinv00 = gmx_mm_invsqrt_pd(rsq00);
240 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
242 /* Load parameters for j particles */
243 jq0 = _mm_load_sd(charge+jnrA+0);
245 /**************************
246 * CALCULATE INTERACTIONS *
247 **************************/
249 if (gmx_mm_any_lt(rsq00,rcutoff2))
252 /* Compute parameters for interactions between i and j atoms */
253 qq00 = _mm_mul_pd(iq0,jq0);
255 /* REACTION-FIELD ELECTROSTATICS */
256 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_add_pd(rinv00,_mm_mul_pd(krf,rsq00)),crf));
257 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
259 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
261 /* Update potential sum for this i atom from the interaction with this j atom. */
262 velec = _mm_and_pd(velec,cutoff_mask);
263 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
264 velecsum = _mm_add_pd(velecsum,velec);
268 fscal = _mm_and_pd(fscal,cutoff_mask);
270 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
272 /* Calculate temporary vectorial force */
273 tx = _mm_mul_pd(fscal,dx00);
274 ty = _mm_mul_pd(fscal,dy00);
275 tz = _mm_mul_pd(fscal,dz00);
277 /* Update vectorial force */
278 fix0 = _mm_add_pd(fix0,tx);
279 fiy0 = _mm_add_pd(fiy0,ty);
280 fiz0 = _mm_add_pd(fiz0,tz);
282 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
286 /* Inner loop uses 36 flops */
289 /* End of innermost loop */
291 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
292 f+i_coord_offset,fshift+i_shift_offset);
295 /* Update potential energies */
296 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
298 /* Increment number of inner iterations */
299 inneriter += j_index_end - j_index_start;
301 /* Outer loop uses 8 flops */
304 /* Increment number of outer iterations */
307 /* Update outer/inner flops */
309 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*36);
312 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_sse4_1_double
313 * Electrostatics interaction: ReactionField
314 * VdW interaction: None
315 * Geometry: Particle-Particle
316 * Calculate force/pot: Force
319 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_sse4_1_double
320 (t_nblist * gmx_restrict nlist,
321 rvec * gmx_restrict xx,
322 rvec * gmx_restrict ff,
323 t_forcerec * gmx_restrict fr,
324 t_mdatoms * gmx_restrict mdatoms,
325 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
326 t_nrnb * gmx_restrict nrnb)
328 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
329 * just 0 for non-waters.
330 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
331 * jnr indices corresponding to data put in the four positions in the SIMD register.
333 int i_shift_offset,i_coord_offset,outeriter,inneriter;
334 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
336 int j_coord_offsetA,j_coord_offsetB;
337 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
339 real *shiftvec,*fshift,*x,*f;
340 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
342 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
343 int vdwjidx0A,vdwjidx0B;
344 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
345 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
346 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
348 __m128d dummy_mask,cutoff_mask;
349 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
350 __m128d one = _mm_set1_pd(1.0);
351 __m128d two = _mm_set1_pd(2.0);
357 jindex = nlist->jindex;
359 shiftidx = nlist->shift;
361 shiftvec = fr->shift_vec[0];
362 fshift = fr->fshift[0];
363 facel = _mm_set1_pd(fr->epsfac);
364 charge = mdatoms->chargeA;
365 krf = _mm_set1_pd(fr->ic->k_rf);
366 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
367 crf = _mm_set1_pd(fr->ic->c_rf);
369 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
370 rcutoff_scalar = fr->rcoulomb;
371 rcutoff = _mm_set1_pd(rcutoff_scalar);
372 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
374 /* Avoid stupid compiler warnings */
382 /* Start outer loop over neighborlists */
383 for(iidx=0; iidx<nri; iidx++)
385 /* Load shift vector for this list */
386 i_shift_offset = DIM*shiftidx[iidx];
388 /* Load limits for loop over neighbors */
389 j_index_start = jindex[iidx];
390 j_index_end = jindex[iidx+1];
392 /* Get outer coordinate index */
394 i_coord_offset = DIM*inr;
396 /* Load i particle coords and add shift vector */
397 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
399 fix0 = _mm_setzero_pd();
400 fiy0 = _mm_setzero_pd();
401 fiz0 = _mm_setzero_pd();
403 /* Load parameters for i particles */
404 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
406 /* Start inner kernel loop */
407 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
410 /* Get j neighbor index, and coordinate index */
413 j_coord_offsetA = DIM*jnrA;
414 j_coord_offsetB = DIM*jnrB;
416 /* load j atom coordinates */
417 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
420 /* Calculate displacement vector */
421 dx00 = _mm_sub_pd(ix0,jx0);
422 dy00 = _mm_sub_pd(iy0,jy0);
423 dz00 = _mm_sub_pd(iz0,jz0);
425 /* Calculate squared distance and things based on it */
426 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
428 rinv00 = gmx_mm_invsqrt_pd(rsq00);
430 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
432 /* Load parameters for j particles */
433 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
435 /**************************
436 * CALCULATE INTERACTIONS *
437 **************************/
439 if (gmx_mm_any_lt(rsq00,rcutoff2))
442 /* Compute parameters for interactions between i and j atoms */
443 qq00 = _mm_mul_pd(iq0,jq0);
445 /* REACTION-FIELD ELECTROSTATICS */
446 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
448 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
452 fscal = _mm_and_pd(fscal,cutoff_mask);
454 /* Calculate temporary vectorial force */
455 tx = _mm_mul_pd(fscal,dx00);
456 ty = _mm_mul_pd(fscal,dy00);
457 tz = _mm_mul_pd(fscal,dz00);
459 /* Update vectorial force */
460 fix0 = _mm_add_pd(fix0,tx);
461 fiy0 = _mm_add_pd(fiy0,ty);
462 fiz0 = _mm_add_pd(fiz0,tz);
464 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
468 /* Inner loop uses 30 flops */
475 j_coord_offsetA = DIM*jnrA;
477 /* load j atom coordinates */
478 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
481 /* Calculate displacement vector */
482 dx00 = _mm_sub_pd(ix0,jx0);
483 dy00 = _mm_sub_pd(iy0,jy0);
484 dz00 = _mm_sub_pd(iz0,jz0);
486 /* Calculate squared distance and things based on it */
487 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
489 rinv00 = gmx_mm_invsqrt_pd(rsq00);
491 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
493 /* Load parameters for j particles */
494 jq0 = _mm_load_sd(charge+jnrA+0);
496 /**************************
497 * CALCULATE INTERACTIONS *
498 **************************/
500 if (gmx_mm_any_lt(rsq00,rcutoff2))
503 /* Compute parameters for interactions between i and j atoms */
504 qq00 = _mm_mul_pd(iq0,jq0);
506 /* REACTION-FIELD ELECTROSTATICS */
507 felec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_mul_pd(rinv00,rinvsq00),krf2));
509 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
513 fscal = _mm_and_pd(fscal,cutoff_mask);
515 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
517 /* Calculate temporary vectorial force */
518 tx = _mm_mul_pd(fscal,dx00);
519 ty = _mm_mul_pd(fscal,dy00);
520 tz = _mm_mul_pd(fscal,dz00);
522 /* Update vectorial force */
523 fix0 = _mm_add_pd(fix0,tx);
524 fiy0 = _mm_add_pd(fiy0,ty);
525 fiz0 = _mm_add_pd(fiz0,tz);
527 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
531 /* Inner loop uses 30 flops */
534 /* End of innermost loop */
536 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
537 f+i_coord_offset,fshift+i_shift_offset);
539 /* Increment number of inner iterations */
540 inneriter += j_index_end - j_index_start;
542 /* Outer loop uses 7 flops */
545 /* Increment number of outer iterations */
548 /* Update outer/inner flops */
550 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*30);