2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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_ElecRF_VdwNone_GeomP1P1_VF_sse4_1_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: None
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRF_VdwNone_GeomP1P1_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;
84 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
85 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
89 __m128 dummy_mask,cutoff_mask;
90 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
91 __m128 one = _mm_set1_ps(1.0);
92 __m128 two = _mm_set1_ps(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_ps(fr->ic->epsfac);
105 charge = mdatoms->chargeA;
106 krf = _mm_set1_ps(fr->ic->k_rf);
107 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
108 crf = _mm_set1_ps(fr->ic->c_rf);
110 /* Avoid stupid compiler warnings */
111 jnrA = jnrB = jnrC = jnrD = 0;
120 for(iidx=0;iidx<4*DIM;iidx++)
125 /* Start outer loop over neighborlists */
126 for(iidx=0; iidx<nri; iidx++)
128 /* Load shift vector for this list */
129 i_shift_offset = DIM*shiftidx[iidx];
131 /* Load limits for loop over neighbors */
132 j_index_start = jindex[iidx];
133 j_index_end = jindex[iidx+1];
135 /* Get outer coordinate index */
137 i_coord_offset = DIM*inr;
139 /* Load i particle coords and add shift vector */
140 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
142 fix0 = _mm_setzero_ps();
143 fiy0 = _mm_setzero_ps();
144 fiz0 = _mm_setzero_ps();
146 /* Load parameters for i particles */
147 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
149 /* Reset potential sums */
150 velecsum = _mm_setzero_ps();
152 /* Start inner kernel loop */
153 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
156 /* Get j neighbor index, and coordinate index */
161 j_coord_offsetA = DIM*jnrA;
162 j_coord_offsetB = DIM*jnrB;
163 j_coord_offsetC = DIM*jnrC;
164 j_coord_offsetD = DIM*jnrD;
166 /* load j atom coordinates */
167 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
168 x+j_coord_offsetC,x+j_coord_offsetD,
171 /* Calculate displacement vector */
172 dx00 = _mm_sub_ps(ix0,jx0);
173 dy00 = _mm_sub_ps(iy0,jy0);
174 dz00 = _mm_sub_ps(iz0,jz0);
176 /* Calculate squared distance and things based on it */
177 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
179 rinv00 = sse41_invsqrt_f(rsq00);
181 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
183 /* Load parameters for j particles */
184 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
185 charge+jnrC+0,charge+jnrD+0);
187 /**************************
188 * CALCULATE INTERACTIONS *
189 **************************/
191 /* Compute parameters for interactions between i and j atoms */
192 qq00 = _mm_mul_ps(iq0,jq0);
194 /* REACTION-FIELD ELECTROSTATICS */
195 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
196 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
198 /* Update potential sum for this i atom from the interaction with this j atom. */
199 velecsum = _mm_add_ps(velecsum,velec);
203 /* Calculate temporary vectorial force */
204 tx = _mm_mul_ps(fscal,dx00);
205 ty = _mm_mul_ps(fscal,dy00);
206 tz = _mm_mul_ps(fscal,dz00);
208 /* Update vectorial force */
209 fix0 = _mm_add_ps(fix0,tx);
210 fiy0 = _mm_add_ps(fiy0,ty);
211 fiz0 = _mm_add_ps(fiz0,tz);
213 fjptrA = f+j_coord_offsetA;
214 fjptrB = f+j_coord_offsetB;
215 fjptrC = f+j_coord_offsetC;
216 fjptrD = f+j_coord_offsetD;
217 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
219 /* Inner loop uses 32 flops */
225 /* Get j neighbor index, and coordinate index */
226 jnrlistA = jjnr[jidx];
227 jnrlistB = jjnr[jidx+1];
228 jnrlistC = jjnr[jidx+2];
229 jnrlistD = jjnr[jidx+3];
230 /* Sign of each element will be negative for non-real atoms.
231 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
232 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
234 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
235 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
236 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
237 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
238 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
239 j_coord_offsetA = DIM*jnrA;
240 j_coord_offsetB = DIM*jnrB;
241 j_coord_offsetC = DIM*jnrC;
242 j_coord_offsetD = DIM*jnrD;
244 /* load j atom coordinates */
245 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
246 x+j_coord_offsetC,x+j_coord_offsetD,
249 /* Calculate displacement vector */
250 dx00 = _mm_sub_ps(ix0,jx0);
251 dy00 = _mm_sub_ps(iy0,jy0);
252 dz00 = _mm_sub_ps(iz0,jz0);
254 /* Calculate squared distance and things based on it */
255 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
257 rinv00 = sse41_invsqrt_f(rsq00);
259 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
261 /* Load parameters for j particles */
262 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
263 charge+jnrC+0,charge+jnrD+0);
265 /**************************
266 * CALCULATE INTERACTIONS *
267 **************************/
269 /* Compute parameters for interactions between i and j atoms */
270 qq00 = _mm_mul_ps(iq0,jq0);
272 /* REACTION-FIELD ELECTROSTATICS */
273 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
274 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
276 /* Update potential sum for this i atom from the interaction with this j atom. */
277 velec = _mm_andnot_ps(dummy_mask,velec);
278 velecsum = _mm_add_ps(velecsum,velec);
282 fscal = _mm_andnot_ps(dummy_mask,fscal);
284 /* Calculate temporary vectorial force */
285 tx = _mm_mul_ps(fscal,dx00);
286 ty = _mm_mul_ps(fscal,dy00);
287 tz = _mm_mul_ps(fscal,dz00);
289 /* Update vectorial force */
290 fix0 = _mm_add_ps(fix0,tx);
291 fiy0 = _mm_add_ps(fiy0,ty);
292 fiz0 = _mm_add_ps(fiz0,tz);
294 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
295 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
296 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
297 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
298 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
300 /* Inner loop uses 32 flops */
303 /* End of innermost loop */
305 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
306 f+i_coord_offset,fshift+i_shift_offset);
309 /* Update potential energies */
310 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
312 /* Increment number of inner iterations */
313 inneriter += j_index_end - j_index_start;
315 /* Outer loop uses 8 flops */
318 /* Increment number of outer iterations */
321 /* Update outer/inner flops */
323 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*32);
326 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomP1P1_F_sse4_1_single
327 * Electrostatics interaction: ReactionField
328 * VdW interaction: None
329 * Geometry: Particle-Particle
330 * Calculate force/pot: Force
333 nb_kernel_ElecRF_VdwNone_GeomP1P1_F_sse4_1_single
334 (t_nblist * gmx_restrict nlist,
335 rvec * gmx_restrict xx,
336 rvec * gmx_restrict ff,
337 struct t_forcerec * gmx_restrict fr,
338 t_mdatoms * gmx_restrict mdatoms,
339 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
340 t_nrnb * gmx_restrict nrnb)
342 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
343 * just 0 for non-waters.
344 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
345 * jnr indices corresponding to data put in the four positions in the SIMD register.
347 int i_shift_offset,i_coord_offset,outeriter,inneriter;
348 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
349 int jnrA,jnrB,jnrC,jnrD;
350 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
351 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
352 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
354 real *shiftvec,*fshift,*x,*f;
355 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
357 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
359 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
360 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
361 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
362 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
363 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
365 __m128 dummy_mask,cutoff_mask;
366 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
367 __m128 one = _mm_set1_ps(1.0);
368 __m128 two = _mm_set1_ps(2.0);
374 jindex = nlist->jindex;
376 shiftidx = nlist->shift;
378 shiftvec = fr->shift_vec[0];
379 fshift = fr->fshift[0];
380 facel = _mm_set1_ps(fr->ic->epsfac);
381 charge = mdatoms->chargeA;
382 krf = _mm_set1_ps(fr->ic->k_rf);
383 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
384 crf = _mm_set1_ps(fr->ic->c_rf);
386 /* Avoid stupid compiler warnings */
387 jnrA = jnrB = jnrC = jnrD = 0;
396 for(iidx=0;iidx<4*DIM;iidx++)
401 /* Start outer loop over neighborlists */
402 for(iidx=0; iidx<nri; iidx++)
404 /* Load shift vector for this list */
405 i_shift_offset = DIM*shiftidx[iidx];
407 /* Load limits for loop over neighbors */
408 j_index_start = jindex[iidx];
409 j_index_end = jindex[iidx+1];
411 /* Get outer coordinate index */
413 i_coord_offset = DIM*inr;
415 /* Load i particle coords and add shift vector */
416 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
418 fix0 = _mm_setzero_ps();
419 fiy0 = _mm_setzero_ps();
420 fiz0 = _mm_setzero_ps();
422 /* Load parameters for i particles */
423 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+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 */
434 j_coord_offsetA = DIM*jnrA;
435 j_coord_offsetB = DIM*jnrB;
436 j_coord_offsetC = DIM*jnrC;
437 j_coord_offsetD = DIM*jnrD;
439 /* load j atom coordinates */
440 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
441 x+j_coord_offsetC,x+j_coord_offsetD,
444 /* Calculate displacement vector */
445 dx00 = _mm_sub_ps(ix0,jx0);
446 dy00 = _mm_sub_ps(iy0,jy0);
447 dz00 = _mm_sub_ps(iz0,jz0);
449 /* Calculate squared distance and things based on it */
450 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
452 rinv00 = sse41_invsqrt_f(rsq00);
454 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
456 /* Load parameters for j particles */
457 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
458 charge+jnrC+0,charge+jnrD+0);
460 /**************************
461 * CALCULATE INTERACTIONS *
462 **************************/
464 /* Compute parameters for interactions between i and j atoms */
465 qq00 = _mm_mul_ps(iq0,jq0);
467 /* REACTION-FIELD ELECTROSTATICS */
468 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
472 /* Calculate temporary vectorial force */
473 tx = _mm_mul_ps(fscal,dx00);
474 ty = _mm_mul_ps(fscal,dy00);
475 tz = _mm_mul_ps(fscal,dz00);
477 /* Update vectorial force */
478 fix0 = _mm_add_ps(fix0,tx);
479 fiy0 = _mm_add_ps(fiy0,ty);
480 fiz0 = _mm_add_ps(fiz0,tz);
482 fjptrA = f+j_coord_offsetA;
483 fjptrB = f+j_coord_offsetB;
484 fjptrC = f+j_coord_offsetC;
485 fjptrD = f+j_coord_offsetD;
486 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
488 /* Inner loop uses 27 flops */
494 /* Get j neighbor index, and coordinate index */
495 jnrlistA = jjnr[jidx];
496 jnrlistB = jjnr[jidx+1];
497 jnrlistC = jjnr[jidx+2];
498 jnrlistD = jjnr[jidx+3];
499 /* Sign of each element will be negative for non-real atoms.
500 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
501 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
503 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
504 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
505 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
506 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
507 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
508 j_coord_offsetA = DIM*jnrA;
509 j_coord_offsetB = DIM*jnrB;
510 j_coord_offsetC = DIM*jnrC;
511 j_coord_offsetD = DIM*jnrD;
513 /* load j atom coordinates */
514 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
515 x+j_coord_offsetC,x+j_coord_offsetD,
518 /* Calculate displacement vector */
519 dx00 = _mm_sub_ps(ix0,jx0);
520 dy00 = _mm_sub_ps(iy0,jy0);
521 dz00 = _mm_sub_ps(iz0,jz0);
523 /* Calculate squared distance and things based on it */
524 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
526 rinv00 = sse41_invsqrt_f(rsq00);
528 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
530 /* Load parameters for j particles */
531 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
532 charge+jnrC+0,charge+jnrD+0);
534 /**************************
535 * CALCULATE INTERACTIONS *
536 **************************/
538 /* Compute parameters for interactions between i and j atoms */
539 qq00 = _mm_mul_ps(iq0,jq0);
541 /* REACTION-FIELD ELECTROSTATICS */
542 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
546 fscal = _mm_andnot_ps(dummy_mask,fscal);
548 /* Calculate temporary vectorial force */
549 tx = _mm_mul_ps(fscal,dx00);
550 ty = _mm_mul_ps(fscal,dy00);
551 tz = _mm_mul_ps(fscal,dz00);
553 /* Update vectorial force */
554 fix0 = _mm_add_ps(fix0,tx);
555 fiy0 = _mm_add_ps(fiy0,ty);
556 fiz0 = _mm_add_ps(fiz0,tz);
558 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
559 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
560 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
561 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
562 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
564 /* Inner loop uses 27 flops */
567 /* End of innermost loop */
569 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
570 f+i_coord_offset,fshift+i_shift_offset);
572 /* Increment number of inner iterations */
573 inneriter += j_index_end - j_index_start;
575 /* Outer loop uses 7 flops */
578 /* Increment number of outer iterations */
581 /* Update outer/inner flops */
583 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*27);