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_single 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_single.h"
48 #include "kernelutil_x86_sse2_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomP1P1_VF_sse2_single
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_single
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,C,D refer to j loop unrolling done with SSE, e.g. for the four 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;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128 dummy_mask,cutoff_mask;
91 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
92 __m128 one = _mm_set1_ps(1.0);
93 __m128 two = _mm_set1_ps(2.0);
99 jindex = nlist->jindex;
101 shiftidx = nlist->shift;
103 shiftvec = fr->shift_vec[0];
104 fshift = fr->fshift[0];
105 facel = _mm_set1_ps(fr->epsfac);
106 charge = mdatoms->chargeA;
107 krf = _mm_set1_ps(fr->ic->k_rf);
108 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
109 crf = _mm_set1_ps(fr->ic->c_rf);
111 /* Avoid stupid compiler warnings */
112 jnrA = jnrB = jnrC = jnrD = 0;
121 for(iidx=0;iidx<4*DIM;iidx++)
126 /* Start outer loop over neighborlists */
127 for(iidx=0; iidx<nri; iidx++)
129 /* Load shift vector for this list */
130 i_shift_offset = DIM*shiftidx[iidx];
132 /* Load limits for loop over neighbors */
133 j_index_start = jindex[iidx];
134 j_index_end = jindex[iidx+1];
136 /* Get outer coordinate index */
138 i_coord_offset = DIM*inr;
140 /* Load i particle coords and add shift vector */
141 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
143 fix0 = _mm_setzero_ps();
144 fiy0 = _mm_setzero_ps();
145 fiz0 = _mm_setzero_ps();
147 /* Load parameters for i particles */
148 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
150 /* Reset potential sums */
151 velecsum = _mm_setzero_ps();
153 /* Start inner kernel loop */
154 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
157 /* Get j neighbor index, and coordinate index */
162 j_coord_offsetA = DIM*jnrA;
163 j_coord_offsetB = DIM*jnrB;
164 j_coord_offsetC = DIM*jnrC;
165 j_coord_offsetD = DIM*jnrD;
167 /* load j atom coordinates */
168 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
169 x+j_coord_offsetC,x+j_coord_offsetD,
172 /* Calculate displacement vector */
173 dx00 = _mm_sub_ps(ix0,jx0);
174 dy00 = _mm_sub_ps(iy0,jy0);
175 dz00 = _mm_sub_ps(iz0,jz0);
177 /* Calculate squared distance and things based on it */
178 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
180 rinv00 = gmx_mm_invsqrt_ps(rsq00);
182 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
184 /* Load parameters for j particles */
185 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
186 charge+jnrC+0,charge+jnrD+0);
188 /**************************
189 * CALCULATE INTERACTIONS *
190 **************************/
192 /* Compute parameters for interactions between i and j atoms */
193 qq00 = _mm_mul_ps(iq0,jq0);
195 /* REACTION-FIELD ELECTROSTATICS */
196 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
197 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
199 /* Update potential sum for this i atom from the interaction with this j atom. */
200 velecsum = _mm_add_ps(velecsum,velec);
204 /* Calculate temporary vectorial force */
205 tx = _mm_mul_ps(fscal,dx00);
206 ty = _mm_mul_ps(fscal,dy00);
207 tz = _mm_mul_ps(fscal,dz00);
209 /* Update vectorial force */
210 fix0 = _mm_add_ps(fix0,tx);
211 fiy0 = _mm_add_ps(fiy0,ty);
212 fiz0 = _mm_add_ps(fiz0,tz);
214 fjptrA = f+j_coord_offsetA;
215 fjptrB = f+j_coord_offsetB;
216 fjptrC = f+j_coord_offsetC;
217 fjptrD = f+j_coord_offsetD;
218 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
220 /* Inner loop uses 32 flops */
226 /* Get j neighbor index, and coordinate index */
227 jnrlistA = jjnr[jidx];
228 jnrlistB = jjnr[jidx+1];
229 jnrlistC = jjnr[jidx+2];
230 jnrlistD = jjnr[jidx+3];
231 /* Sign of each element will be negative for non-real atoms.
232 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
233 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
235 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
236 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
237 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
238 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
239 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
240 j_coord_offsetA = DIM*jnrA;
241 j_coord_offsetB = DIM*jnrB;
242 j_coord_offsetC = DIM*jnrC;
243 j_coord_offsetD = DIM*jnrD;
245 /* load j atom coordinates */
246 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
247 x+j_coord_offsetC,x+j_coord_offsetD,
250 /* Calculate displacement vector */
251 dx00 = _mm_sub_ps(ix0,jx0);
252 dy00 = _mm_sub_ps(iy0,jy0);
253 dz00 = _mm_sub_ps(iz0,jz0);
255 /* Calculate squared distance and things based on it */
256 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
258 rinv00 = gmx_mm_invsqrt_ps(rsq00);
260 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
262 /* Load parameters for j particles */
263 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
264 charge+jnrC+0,charge+jnrD+0);
266 /**************************
267 * CALCULATE INTERACTIONS *
268 **************************/
270 /* Compute parameters for interactions between i and j atoms */
271 qq00 = _mm_mul_ps(iq0,jq0);
273 /* REACTION-FIELD ELECTROSTATICS */
274 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
275 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
277 /* Update potential sum for this i atom from the interaction with this j atom. */
278 velec = _mm_andnot_ps(dummy_mask,velec);
279 velecsum = _mm_add_ps(velecsum,velec);
283 fscal = _mm_andnot_ps(dummy_mask,fscal);
285 /* Calculate temporary vectorial force */
286 tx = _mm_mul_ps(fscal,dx00);
287 ty = _mm_mul_ps(fscal,dy00);
288 tz = _mm_mul_ps(fscal,dz00);
290 /* Update vectorial force */
291 fix0 = _mm_add_ps(fix0,tx);
292 fiy0 = _mm_add_ps(fiy0,ty);
293 fiz0 = _mm_add_ps(fiz0,tz);
295 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
296 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
297 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
298 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
299 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
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(velecsum,kernel_data->energygrp_elec+ggid);
313 /* Increment number of inner iterations */
314 inneriter += j_index_end - j_index_start;
316 /* Outer loop uses 8 flops */
319 /* Increment number of outer iterations */
322 /* Update outer/inner flops */
324 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*32);
327 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomP1P1_F_sse2_single
328 * Electrostatics interaction: ReactionField
329 * VdW interaction: None
330 * Geometry: Particle-Particle
331 * Calculate force/pot: Force
334 nb_kernel_ElecRF_VdwNone_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_unused * 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 jnrlistA,jnrlistB,jnrlistC,jnrlistD;
352 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
353 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
355 real *shiftvec,*fshift,*x,*f;
356 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
358 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
360 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
361 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
362 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
363 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
364 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
366 __m128 dummy_mask,cutoff_mask;
367 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
368 __m128 one = _mm_set1_ps(1.0);
369 __m128 two = _mm_set1_ps(2.0);
375 jindex = nlist->jindex;
377 shiftidx = nlist->shift;
379 shiftvec = fr->shift_vec[0];
380 fshift = fr->fshift[0];
381 facel = _mm_set1_ps(fr->epsfac);
382 charge = mdatoms->chargeA;
383 krf = _mm_set1_ps(fr->ic->k_rf);
384 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
385 crf = _mm_set1_ps(fr->ic->c_rf);
387 /* Avoid stupid compiler warnings */
388 jnrA = jnrB = jnrC = jnrD = 0;
397 for(iidx=0;iidx<4*DIM;iidx++)
402 /* Start outer loop over neighborlists */
403 for(iidx=0; iidx<nri; iidx++)
405 /* Load shift vector for this list */
406 i_shift_offset = DIM*shiftidx[iidx];
408 /* Load limits for loop over neighbors */
409 j_index_start = jindex[iidx];
410 j_index_end = jindex[iidx+1];
412 /* Get outer coordinate index */
414 i_coord_offset = DIM*inr;
416 /* Load i particle coords and add shift vector */
417 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
419 fix0 = _mm_setzero_ps();
420 fiy0 = _mm_setzero_ps();
421 fiz0 = _mm_setzero_ps();
423 /* Load parameters for i particles */
424 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
426 /* Start inner kernel loop */
427 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
430 /* 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 rinv00 = gmx_mm_invsqrt_ps(rsq00);
455 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
457 /* Load parameters for j particles */
458 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
459 charge+jnrC+0,charge+jnrD+0);
461 /**************************
462 * CALCULATE INTERACTIONS *
463 **************************/
465 /* Compute parameters for interactions between i and j atoms */
466 qq00 = _mm_mul_ps(iq0,jq0);
468 /* REACTION-FIELD ELECTROSTATICS */
469 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
473 /* Calculate temporary vectorial force */
474 tx = _mm_mul_ps(fscal,dx00);
475 ty = _mm_mul_ps(fscal,dy00);
476 tz = _mm_mul_ps(fscal,dz00);
478 /* Update vectorial force */
479 fix0 = _mm_add_ps(fix0,tx);
480 fiy0 = _mm_add_ps(fiy0,ty);
481 fiz0 = _mm_add_ps(fiz0,tz);
483 fjptrA = f+j_coord_offsetA;
484 fjptrB = f+j_coord_offsetB;
485 fjptrC = f+j_coord_offsetC;
486 fjptrD = f+j_coord_offsetD;
487 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
489 /* Inner loop uses 27 flops */
495 /* Get j neighbor index, and coordinate index */
496 jnrlistA = jjnr[jidx];
497 jnrlistB = jjnr[jidx+1];
498 jnrlistC = jjnr[jidx+2];
499 jnrlistD = jjnr[jidx+3];
500 /* Sign of each element will be negative for non-real atoms.
501 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
502 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
504 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
505 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
506 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
507 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
508 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
509 j_coord_offsetA = DIM*jnrA;
510 j_coord_offsetB = DIM*jnrB;
511 j_coord_offsetC = DIM*jnrC;
512 j_coord_offsetD = DIM*jnrD;
514 /* load j atom coordinates */
515 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
516 x+j_coord_offsetC,x+j_coord_offsetD,
519 /* Calculate displacement vector */
520 dx00 = _mm_sub_ps(ix0,jx0);
521 dy00 = _mm_sub_ps(iy0,jy0);
522 dz00 = _mm_sub_ps(iz0,jz0);
524 /* Calculate squared distance and things based on it */
525 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
527 rinv00 = gmx_mm_invsqrt_ps(rsq00);
529 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
531 /* Load parameters for j particles */
532 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
533 charge+jnrC+0,charge+jnrD+0);
535 /**************************
536 * CALCULATE INTERACTIONS *
537 **************************/
539 /* Compute parameters for interactions between i and j atoms */
540 qq00 = _mm_mul_ps(iq0,jq0);
542 /* REACTION-FIELD ELECTROSTATICS */
543 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
547 fscal = _mm_andnot_ps(dummy_mask,fscal);
549 /* Calculate temporary vectorial force */
550 tx = _mm_mul_ps(fscal,dx00);
551 ty = _mm_mul_ps(fscal,dy00);
552 tz = _mm_mul_ps(fscal,dz00);
554 /* Update vectorial force */
555 fix0 = _mm_add_ps(fix0,tx);
556 fiy0 = _mm_add_ps(fiy0,ty);
557 fiz0 = _mm_add_ps(fiz0,tz);
559 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
560 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
561 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
562 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
563 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
565 /* Inner loop uses 27 flops */
568 /* End of innermost loop */
570 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
571 f+i_coord_offset,fshift+i_shift_offset);
573 /* Increment number of inner iterations */
574 inneriter += j_index_end - j_index_start;
576 /* Outer loop uses 7 flops */
579 /* Increment number of outer iterations */
582 /* Update outer/inner flops */
584 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*27);