2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013, 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 "types/simple.h"
49 #include "gromacs/simd/math_x86_sse4_1_single.h"
50 #include "kernelutil_x86_sse4_1_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_sse4_1_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: None
56 * Geometry: Water4-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_sse4_1_single
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,C,D refer to j loop unrolling done with SSE, e.g. for the four 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;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
90 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
91 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
92 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
93 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
94 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
95 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
96 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
98 __m128 dummy_mask,cutoff_mask;
99 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
100 __m128 one = _mm_set1_ps(1.0);
101 __m128 two = _mm_set1_ps(2.0);
107 jindex = nlist->jindex;
109 shiftidx = nlist->shift;
111 shiftvec = fr->shift_vec[0];
112 fshift = fr->fshift[0];
113 facel = _mm_set1_ps(fr->epsfac);
114 charge = mdatoms->chargeA;
115 krf = _mm_set1_ps(fr->ic->k_rf);
116 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
117 crf = _mm_set1_ps(fr->ic->c_rf);
119 /* Setup water-specific parameters */
120 inr = nlist->iinr[0];
121 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
122 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
123 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
125 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
126 rcutoff_scalar = fr->rcoulomb;
127 rcutoff = _mm_set1_ps(rcutoff_scalar);
128 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
130 /* Avoid stupid compiler warnings */
131 jnrA = jnrB = jnrC = jnrD = 0;
140 for(iidx=0;iidx<4*DIM;iidx++)
145 /* Start outer loop over neighborlists */
146 for(iidx=0; iidx<nri; iidx++)
148 /* Load shift vector for this list */
149 i_shift_offset = DIM*shiftidx[iidx];
151 /* Load limits for loop over neighbors */
152 j_index_start = jindex[iidx];
153 j_index_end = jindex[iidx+1];
155 /* Get outer coordinate index */
157 i_coord_offset = DIM*inr;
159 /* Load i particle coords and add shift vector */
160 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
161 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
163 fix1 = _mm_setzero_ps();
164 fiy1 = _mm_setzero_ps();
165 fiz1 = _mm_setzero_ps();
166 fix2 = _mm_setzero_ps();
167 fiy2 = _mm_setzero_ps();
168 fiz2 = _mm_setzero_ps();
169 fix3 = _mm_setzero_ps();
170 fiy3 = _mm_setzero_ps();
171 fiz3 = _mm_setzero_ps();
173 /* Reset potential sums */
174 velecsum = _mm_setzero_ps();
176 /* Start inner kernel loop */
177 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
180 /* Get j neighbor index, and coordinate index */
185 j_coord_offsetA = DIM*jnrA;
186 j_coord_offsetB = DIM*jnrB;
187 j_coord_offsetC = DIM*jnrC;
188 j_coord_offsetD = DIM*jnrD;
190 /* load j atom coordinates */
191 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
192 x+j_coord_offsetC,x+j_coord_offsetD,
195 /* Calculate displacement vector */
196 dx10 = _mm_sub_ps(ix1,jx0);
197 dy10 = _mm_sub_ps(iy1,jy0);
198 dz10 = _mm_sub_ps(iz1,jz0);
199 dx20 = _mm_sub_ps(ix2,jx0);
200 dy20 = _mm_sub_ps(iy2,jy0);
201 dz20 = _mm_sub_ps(iz2,jz0);
202 dx30 = _mm_sub_ps(ix3,jx0);
203 dy30 = _mm_sub_ps(iy3,jy0);
204 dz30 = _mm_sub_ps(iz3,jz0);
206 /* Calculate squared distance and things based on it */
207 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
208 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
209 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
211 rinv10 = gmx_mm_invsqrt_ps(rsq10);
212 rinv20 = gmx_mm_invsqrt_ps(rsq20);
213 rinv30 = gmx_mm_invsqrt_ps(rsq30);
215 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
216 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
217 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
219 /* Load parameters for j particles */
220 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
221 charge+jnrC+0,charge+jnrD+0);
223 fjx0 = _mm_setzero_ps();
224 fjy0 = _mm_setzero_ps();
225 fjz0 = _mm_setzero_ps();
227 /**************************
228 * CALCULATE INTERACTIONS *
229 **************************/
231 if (gmx_mm_any_lt(rsq10,rcutoff2))
234 /* Compute parameters for interactions between i and j atoms */
235 qq10 = _mm_mul_ps(iq1,jq0);
237 /* REACTION-FIELD ELECTROSTATICS */
238 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
239 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
241 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
243 /* Update potential sum for this i atom from the interaction with this j atom. */
244 velec = _mm_and_ps(velec,cutoff_mask);
245 velecsum = _mm_add_ps(velecsum,velec);
249 fscal = _mm_and_ps(fscal,cutoff_mask);
251 /* Calculate temporary vectorial force */
252 tx = _mm_mul_ps(fscal,dx10);
253 ty = _mm_mul_ps(fscal,dy10);
254 tz = _mm_mul_ps(fscal,dz10);
256 /* Update vectorial force */
257 fix1 = _mm_add_ps(fix1,tx);
258 fiy1 = _mm_add_ps(fiy1,ty);
259 fiz1 = _mm_add_ps(fiz1,tz);
261 fjx0 = _mm_add_ps(fjx0,tx);
262 fjy0 = _mm_add_ps(fjy0,ty);
263 fjz0 = _mm_add_ps(fjz0,tz);
267 /**************************
268 * CALCULATE INTERACTIONS *
269 **************************/
271 if (gmx_mm_any_lt(rsq20,rcutoff2))
274 /* Compute parameters for interactions between i and j atoms */
275 qq20 = _mm_mul_ps(iq2,jq0);
277 /* REACTION-FIELD ELECTROSTATICS */
278 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
279 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
281 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
283 /* Update potential sum for this i atom from the interaction with this j atom. */
284 velec = _mm_and_ps(velec,cutoff_mask);
285 velecsum = _mm_add_ps(velecsum,velec);
289 fscal = _mm_and_ps(fscal,cutoff_mask);
291 /* Calculate temporary vectorial force */
292 tx = _mm_mul_ps(fscal,dx20);
293 ty = _mm_mul_ps(fscal,dy20);
294 tz = _mm_mul_ps(fscal,dz20);
296 /* Update vectorial force */
297 fix2 = _mm_add_ps(fix2,tx);
298 fiy2 = _mm_add_ps(fiy2,ty);
299 fiz2 = _mm_add_ps(fiz2,tz);
301 fjx0 = _mm_add_ps(fjx0,tx);
302 fjy0 = _mm_add_ps(fjy0,ty);
303 fjz0 = _mm_add_ps(fjz0,tz);
307 /**************************
308 * CALCULATE INTERACTIONS *
309 **************************/
311 if (gmx_mm_any_lt(rsq30,rcutoff2))
314 /* Compute parameters for interactions between i and j atoms */
315 qq30 = _mm_mul_ps(iq3,jq0);
317 /* REACTION-FIELD ELECTROSTATICS */
318 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
319 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
321 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
323 /* Update potential sum for this i atom from the interaction with this j atom. */
324 velec = _mm_and_ps(velec,cutoff_mask);
325 velecsum = _mm_add_ps(velecsum,velec);
329 fscal = _mm_and_ps(fscal,cutoff_mask);
331 /* Calculate temporary vectorial force */
332 tx = _mm_mul_ps(fscal,dx30);
333 ty = _mm_mul_ps(fscal,dy30);
334 tz = _mm_mul_ps(fscal,dz30);
336 /* Update vectorial force */
337 fix3 = _mm_add_ps(fix3,tx);
338 fiy3 = _mm_add_ps(fiy3,ty);
339 fiz3 = _mm_add_ps(fiz3,tz);
341 fjx0 = _mm_add_ps(fjx0,tx);
342 fjy0 = _mm_add_ps(fjy0,ty);
343 fjz0 = _mm_add_ps(fjz0,tz);
347 fjptrA = f+j_coord_offsetA;
348 fjptrB = f+j_coord_offsetB;
349 fjptrC = f+j_coord_offsetC;
350 fjptrD = f+j_coord_offsetD;
352 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
354 /* Inner loop uses 108 flops */
360 /* Get j neighbor index, and coordinate index */
361 jnrlistA = jjnr[jidx];
362 jnrlistB = jjnr[jidx+1];
363 jnrlistC = jjnr[jidx+2];
364 jnrlistD = jjnr[jidx+3];
365 /* Sign of each element will be negative for non-real atoms.
366 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
367 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
369 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
370 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
371 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
372 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
373 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
374 j_coord_offsetA = DIM*jnrA;
375 j_coord_offsetB = DIM*jnrB;
376 j_coord_offsetC = DIM*jnrC;
377 j_coord_offsetD = DIM*jnrD;
379 /* load j atom coordinates */
380 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
381 x+j_coord_offsetC,x+j_coord_offsetD,
384 /* Calculate displacement vector */
385 dx10 = _mm_sub_ps(ix1,jx0);
386 dy10 = _mm_sub_ps(iy1,jy0);
387 dz10 = _mm_sub_ps(iz1,jz0);
388 dx20 = _mm_sub_ps(ix2,jx0);
389 dy20 = _mm_sub_ps(iy2,jy0);
390 dz20 = _mm_sub_ps(iz2,jz0);
391 dx30 = _mm_sub_ps(ix3,jx0);
392 dy30 = _mm_sub_ps(iy3,jy0);
393 dz30 = _mm_sub_ps(iz3,jz0);
395 /* Calculate squared distance and things based on it */
396 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
397 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
398 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
400 rinv10 = gmx_mm_invsqrt_ps(rsq10);
401 rinv20 = gmx_mm_invsqrt_ps(rsq20);
402 rinv30 = gmx_mm_invsqrt_ps(rsq30);
404 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
405 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
406 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
408 /* Load parameters for j particles */
409 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
410 charge+jnrC+0,charge+jnrD+0);
412 fjx0 = _mm_setzero_ps();
413 fjy0 = _mm_setzero_ps();
414 fjz0 = _mm_setzero_ps();
416 /**************************
417 * CALCULATE INTERACTIONS *
418 **************************/
420 if (gmx_mm_any_lt(rsq10,rcutoff2))
423 /* Compute parameters for interactions between i and j atoms */
424 qq10 = _mm_mul_ps(iq1,jq0);
426 /* REACTION-FIELD ELECTROSTATICS */
427 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
428 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
430 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
432 /* Update potential sum for this i atom from the interaction with this j atom. */
433 velec = _mm_and_ps(velec,cutoff_mask);
434 velec = _mm_andnot_ps(dummy_mask,velec);
435 velecsum = _mm_add_ps(velecsum,velec);
439 fscal = _mm_and_ps(fscal,cutoff_mask);
441 fscal = _mm_andnot_ps(dummy_mask,fscal);
443 /* Calculate temporary vectorial force */
444 tx = _mm_mul_ps(fscal,dx10);
445 ty = _mm_mul_ps(fscal,dy10);
446 tz = _mm_mul_ps(fscal,dz10);
448 /* Update vectorial force */
449 fix1 = _mm_add_ps(fix1,tx);
450 fiy1 = _mm_add_ps(fiy1,ty);
451 fiz1 = _mm_add_ps(fiz1,tz);
453 fjx0 = _mm_add_ps(fjx0,tx);
454 fjy0 = _mm_add_ps(fjy0,ty);
455 fjz0 = _mm_add_ps(fjz0,tz);
459 /**************************
460 * CALCULATE INTERACTIONS *
461 **************************/
463 if (gmx_mm_any_lt(rsq20,rcutoff2))
466 /* Compute parameters for interactions between i and j atoms */
467 qq20 = _mm_mul_ps(iq2,jq0);
469 /* REACTION-FIELD ELECTROSTATICS */
470 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
471 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
473 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
475 /* Update potential sum for this i atom from the interaction with this j atom. */
476 velec = _mm_and_ps(velec,cutoff_mask);
477 velec = _mm_andnot_ps(dummy_mask,velec);
478 velecsum = _mm_add_ps(velecsum,velec);
482 fscal = _mm_and_ps(fscal,cutoff_mask);
484 fscal = _mm_andnot_ps(dummy_mask,fscal);
486 /* Calculate temporary vectorial force */
487 tx = _mm_mul_ps(fscal,dx20);
488 ty = _mm_mul_ps(fscal,dy20);
489 tz = _mm_mul_ps(fscal,dz20);
491 /* Update vectorial force */
492 fix2 = _mm_add_ps(fix2,tx);
493 fiy2 = _mm_add_ps(fiy2,ty);
494 fiz2 = _mm_add_ps(fiz2,tz);
496 fjx0 = _mm_add_ps(fjx0,tx);
497 fjy0 = _mm_add_ps(fjy0,ty);
498 fjz0 = _mm_add_ps(fjz0,tz);
502 /**************************
503 * CALCULATE INTERACTIONS *
504 **************************/
506 if (gmx_mm_any_lt(rsq30,rcutoff2))
509 /* Compute parameters for interactions between i and j atoms */
510 qq30 = _mm_mul_ps(iq3,jq0);
512 /* REACTION-FIELD ELECTROSTATICS */
513 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
514 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
516 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
518 /* Update potential sum for this i atom from the interaction with this j atom. */
519 velec = _mm_and_ps(velec,cutoff_mask);
520 velec = _mm_andnot_ps(dummy_mask,velec);
521 velecsum = _mm_add_ps(velecsum,velec);
525 fscal = _mm_and_ps(fscal,cutoff_mask);
527 fscal = _mm_andnot_ps(dummy_mask,fscal);
529 /* Calculate temporary vectorial force */
530 tx = _mm_mul_ps(fscal,dx30);
531 ty = _mm_mul_ps(fscal,dy30);
532 tz = _mm_mul_ps(fscal,dz30);
534 /* Update vectorial force */
535 fix3 = _mm_add_ps(fix3,tx);
536 fiy3 = _mm_add_ps(fiy3,ty);
537 fiz3 = _mm_add_ps(fiz3,tz);
539 fjx0 = _mm_add_ps(fjx0,tx);
540 fjy0 = _mm_add_ps(fjy0,ty);
541 fjz0 = _mm_add_ps(fjz0,tz);
545 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
546 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
547 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
548 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
550 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
552 /* Inner loop uses 108 flops */
555 /* End of innermost loop */
557 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
558 f+i_coord_offset+DIM,fshift+i_shift_offset);
561 /* Update potential energies */
562 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
564 /* Increment number of inner iterations */
565 inneriter += j_index_end - j_index_start;
567 /* Outer loop uses 19 flops */
570 /* Increment number of outer iterations */
573 /* Update outer/inner flops */
575 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*108);
578 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_sse4_1_single
579 * Electrostatics interaction: ReactionField
580 * VdW interaction: None
581 * Geometry: Water4-Particle
582 * Calculate force/pot: Force
585 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_sse4_1_single
586 (t_nblist * gmx_restrict nlist,
587 rvec * gmx_restrict xx,
588 rvec * gmx_restrict ff,
589 t_forcerec * gmx_restrict fr,
590 t_mdatoms * gmx_restrict mdatoms,
591 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
592 t_nrnb * gmx_restrict nrnb)
594 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
595 * just 0 for non-waters.
596 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
597 * jnr indices corresponding to data put in the four positions in the SIMD register.
599 int i_shift_offset,i_coord_offset,outeriter,inneriter;
600 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
601 int jnrA,jnrB,jnrC,jnrD;
602 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
603 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
604 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
606 real *shiftvec,*fshift,*x,*f;
607 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
609 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
611 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
613 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
615 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
616 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
617 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
618 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
619 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
620 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
621 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
623 __m128 dummy_mask,cutoff_mask;
624 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
625 __m128 one = _mm_set1_ps(1.0);
626 __m128 two = _mm_set1_ps(2.0);
632 jindex = nlist->jindex;
634 shiftidx = nlist->shift;
636 shiftvec = fr->shift_vec[0];
637 fshift = fr->fshift[0];
638 facel = _mm_set1_ps(fr->epsfac);
639 charge = mdatoms->chargeA;
640 krf = _mm_set1_ps(fr->ic->k_rf);
641 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
642 crf = _mm_set1_ps(fr->ic->c_rf);
644 /* Setup water-specific parameters */
645 inr = nlist->iinr[0];
646 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
647 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
648 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
650 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
651 rcutoff_scalar = fr->rcoulomb;
652 rcutoff = _mm_set1_ps(rcutoff_scalar);
653 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
655 /* Avoid stupid compiler warnings */
656 jnrA = jnrB = jnrC = jnrD = 0;
665 for(iidx=0;iidx<4*DIM;iidx++)
670 /* Start outer loop over neighborlists */
671 for(iidx=0; iidx<nri; iidx++)
673 /* Load shift vector for this list */
674 i_shift_offset = DIM*shiftidx[iidx];
676 /* Load limits for loop over neighbors */
677 j_index_start = jindex[iidx];
678 j_index_end = jindex[iidx+1];
680 /* Get outer coordinate index */
682 i_coord_offset = DIM*inr;
684 /* Load i particle coords and add shift vector */
685 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
686 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
688 fix1 = _mm_setzero_ps();
689 fiy1 = _mm_setzero_ps();
690 fiz1 = _mm_setzero_ps();
691 fix2 = _mm_setzero_ps();
692 fiy2 = _mm_setzero_ps();
693 fiz2 = _mm_setzero_ps();
694 fix3 = _mm_setzero_ps();
695 fiy3 = _mm_setzero_ps();
696 fiz3 = _mm_setzero_ps();
698 /* Start inner kernel loop */
699 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
702 /* Get j neighbor index, and coordinate index */
707 j_coord_offsetA = DIM*jnrA;
708 j_coord_offsetB = DIM*jnrB;
709 j_coord_offsetC = DIM*jnrC;
710 j_coord_offsetD = DIM*jnrD;
712 /* load j atom coordinates */
713 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
714 x+j_coord_offsetC,x+j_coord_offsetD,
717 /* Calculate displacement vector */
718 dx10 = _mm_sub_ps(ix1,jx0);
719 dy10 = _mm_sub_ps(iy1,jy0);
720 dz10 = _mm_sub_ps(iz1,jz0);
721 dx20 = _mm_sub_ps(ix2,jx0);
722 dy20 = _mm_sub_ps(iy2,jy0);
723 dz20 = _mm_sub_ps(iz2,jz0);
724 dx30 = _mm_sub_ps(ix3,jx0);
725 dy30 = _mm_sub_ps(iy3,jy0);
726 dz30 = _mm_sub_ps(iz3,jz0);
728 /* Calculate squared distance and things based on it */
729 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
730 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
731 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
733 rinv10 = gmx_mm_invsqrt_ps(rsq10);
734 rinv20 = gmx_mm_invsqrt_ps(rsq20);
735 rinv30 = gmx_mm_invsqrt_ps(rsq30);
737 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
738 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
739 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
741 /* Load parameters for j particles */
742 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
743 charge+jnrC+0,charge+jnrD+0);
745 fjx0 = _mm_setzero_ps();
746 fjy0 = _mm_setzero_ps();
747 fjz0 = _mm_setzero_ps();
749 /**************************
750 * CALCULATE INTERACTIONS *
751 **************************/
753 if (gmx_mm_any_lt(rsq10,rcutoff2))
756 /* Compute parameters for interactions between i and j atoms */
757 qq10 = _mm_mul_ps(iq1,jq0);
759 /* REACTION-FIELD ELECTROSTATICS */
760 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
762 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
766 fscal = _mm_and_ps(fscal,cutoff_mask);
768 /* Calculate temporary vectorial force */
769 tx = _mm_mul_ps(fscal,dx10);
770 ty = _mm_mul_ps(fscal,dy10);
771 tz = _mm_mul_ps(fscal,dz10);
773 /* Update vectorial force */
774 fix1 = _mm_add_ps(fix1,tx);
775 fiy1 = _mm_add_ps(fiy1,ty);
776 fiz1 = _mm_add_ps(fiz1,tz);
778 fjx0 = _mm_add_ps(fjx0,tx);
779 fjy0 = _mm_add_ps(fjy0,ty);
780 fjz0 = _mm_add_ps(fjz0,tz);
784 /**************************
785 * CALCULATE INTERACTIONS *
786 **************************/
788 if (gmx_mm_any_lt(rsq20,rcutoff2))
791 /* Compute parameters for interactions between i and j atoms */
792 qq20 = _mm_mul_ps(iq2,jq0);
794 /* REACTION-FIELD ELECTROSTATICS */
795 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
797 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
801 fscal = _mm_and_ps(fscal,cutoff_mask);
803 /* Calculate temporary vectorial force */
804 tx = _mm_mul_ps(fscal,dx20);
805 ty = _mm_mul_ps(fscal,dy20);
806 tz = _mm_mul_ps(fscal,dz20);
808 /* Update vectorial force */
809 fix2 = _mm_add_ps(fix2,tx);
810 fiy2 = _mm_add_ps(fiy2,ty);
811 fiz2 = _mm_add_ps(fiz2,tz);
813 fjx0 = _mm_add_ps(fjx0,tx);
814 fjy0 = _mm_add_ps(fjy0,ty);
815 fjz0 = _mm_add_ps(fjz0,tz);
819 /**************************
820 * CALCULATE INTERACTIONS *
821 **************************/
823 if (gmx_mm_any_lt(rsq30,rcutoff2))
826 /* Compute parameters for interactions between i and j atoms */
827 qq30 = _mm_mul_ps(iq3,jq0);
829 /* REACTION-FIELD ELECTROSTATICS */
830 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
832 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
836 fscal = _mm_and_ps(fscal,cutoff_mask);
838 /* Calculate temporary vectorial force */
839 tx = _mm_mul_ps(fscal,dx30);
840 ty = _mm_mul_ps(fscal,dy30);
841 tz = _mm_mul_ps(fscal,dz30);
843 /* Update vectorial force */
844 fix3 = _mm_add_ps(fix3,tx);
845 fiy3 = _mm_add_ps(fiy3,ty);
846 fiz3 = _mm_add_ps(fiz3,tz);
848 fjx0 = _mm_add_ps(fjx0,tx);
849 fjy0 = _mm_add_ps(fjy0,ty);
850 fjz0 = _mm_add_ps(fjz0,tz);
854 fjptrA = f+j_coord_offsetA;
855 fjptrB = f+j_coord_offsetB;
856 fjptrC = f+j_coord_offsetC;
857 fjptrD = f+j_coord_offsetD;
859 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
861 /* Inner loop uses 90 flops */
867 /* Get j neighbor index, and coordinate index */
868 jnrlistA = jjnr[jidx];
869 jnrlistB = jjnr[jidx+1];
870 jnrlistC = jjnr[jidx+2];
871 jnrlistD = jjnr[jidx+3];
872 /* Sign of each element will be negative for non-real atoms.
873 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
874 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
876 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
877 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
878 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
879 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
880 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
881 j_coord_offsetA = DIM*jnrA;
882 j_coord_offsetB = DIM*jnrB;
883 j_coord_offsetC = DIM*jnrC;
884 j_coord_offsetD = DIM*jnrD;
886 /* load j atom coordinates */
887 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
888 x+j_coord_offsetC,x+j_coord_offsetD,
891 /* Calculate displacement vector */
892 dx10 = _mm_sub_ps(ix1,jx0);
893 dy10 = _mm_sub_ps(iy1,jy0);
894 dz10 = _mm_sub_ps(iz1,jz0);
895 dx20 = _mm_sub_ps(ix2,jx0);
896 dy20 = _mm_sub_ps(iy2,jy0);
897 dz20 = _mm_sub_ps(iz2,jz0);
898 dx30 = _mm_sub_ps(ix3,jx0);
899 dy30 = _mm_sub_ps(iy3,jy0);
900 dz30 = _mm_sub_ps(iz3,jz0);
902 /* Calculate squared distance and things based on it */
903 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
904 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
905 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
907 rinv10 = gmx_mm_invsqrt_ps(rsq10);
908 rinv20 = gmx_mm_invsqrt_ps(rsq20);
909 rinv30 = gmx_mm_invsqrt_ps(rsq30);
911 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
912 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
913 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
915 /* Load parameters for j particles */
916 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
917 charge+jnrC+0,charge+jnrD+0);
919 fjx0 = _mm_setzero_ps();
920 fjy0 = _mm_setzero_ps();
921 fjz0 = _mm_setzero_ps();
923 /**************************
924 * CALCULATE INTERACTIONS *
925 **************************/
927 if (gmx_mm_any_lt(rsq10,rcutoff2))
930 /* Compute parameters for interactions between i and j atoms */
931 qq10 = _mm_mul_ps(iq1,jq0);
933 /* REACTION-FIELD ELECTROSTATICS */
934 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
936 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
940 fscal = _mm_and_ps(fscal,cutoff_mask);
942 fscal = _mm_andnot_ps(dummy_mask,fscal);
944 /* Calculate temporary vectorial force */
945 tx = _mm_mul_ps(fscal,dx10);
946 ty = _mm_mul_ps(fscal,dy10);
947 tz = _mm_mul_ps(fscal,dz10);
949 /* Update vectorial force */
950 fix1 = _mm_add_ps(fix1,tx);
951 fiy1 = _mm_add_ps(fiy1,ty);
952 fiz1 = _mm_add_ps(fiz1,tz);
954 fjx0 = _mm_add_ps(fjx0,tx);
955 fjy0 = _mm_add_ps(fjy0,ty);
956 fjz0 = _mm_add_ps(fjz0,tz);
960 /**************************
961 * CALCULATE INTERACTIONS *
962 **************************/
964 if (gmx_mm_any_lt(rsq20,rcutoff2))
967 /* Compute parameters for interactions between i and j atoms */
968 qq20 = _mm_mul_ps(iq2,jq0);
970 /* REACTION-FIELD ELECTROSTATICS */
971 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
973 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
977 fscal = _mm_and_ps(fscal,cutoff_mask);
979 fscal = _mm_andnot_ps(dummy_mask,fscal);
981 /* Calculate temporary vectorial force */
982 tx = _mm_mul_ps(fscal,dx20);
983 ty = _mm_mul_ps(fscal,dy20);
984 tz = _mm_mul_ps(fscal,dz20);
986 /* Update vectorial force */
987 fix2 = _mm_add_ps(fix2,tx);
988 fiy2 = _mm_add_ps(fiy2,ty);
989 fiz2 = _mm_add_ps(fiz2,tz);
991 fjx0 = _mm_add_ps(fjx0,tx);
992 fjy0 = _mm_add_ps(fjy0,ty);
993 fjz0 = _mm_add_ps(fjz0,tz);
997 /**************************
998 * CALCULATE INTERACTIONS *
999 **************************/
1001 if (gmx_mm_any_lt(rsq30,rcutoff2))
1004 /* Compute parameters for interactions between i and j atoms */
1005 qq30 = _mm_mul_ps(iq3,jq0);
1007 /* REACTION-FIELD ELECTROSTATICS */
1008 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
1010 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1014 fscal = _mm_and_ps(fscal,cutoff_mask);
1016 fscal = _mm_andnot_ps(dummy_mask,fscal);
1018 /* Calculate temporary vectorial force */
1019 tx = _mm_mul_ps(fscal,dx30);
1020 ty = _mm_mul_ps(fscal,dy30);
1021 tz = _mm_mul_ps(fscal,dz30);
1023 /* Update vectorial force */
1024 fix3 = _mm_add_ps(fix3,tx);
1025 fiy3 = _mm_add_ps(fiy3,ty);
1026 fiz3 = _mm_add_ps(fiz3,tz);
1028 fjx0 = _mm_add_ps(fjx0,tx);
1029 fjy0 = _mm_add_ps(fjy0,ty);
1030 fjz0 = _mm_add_ps(fjz0,tz);
1034 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1035 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1036 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1037 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1039 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1041 /* Inner loop uses 90 flops */
1044 /* End of innermost loop */
1046 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1047 f+i_coord_offset+DIM,fshift+i_shift_offset);
1049 /* Increment number of inner iterations */
1050 inneriter += j_index_end - j_index_start;
1052 /* Outer loop uses 18 flops */
1055 /* Increment number of outer iterations */
1058 /* Update outer/inner flops */
1060 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*90);