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_ElecRFCut_VdwNone_GeomW3P1_VF_sse2_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: None
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_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;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128 dummy_mask,cutoff_mask;
97 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
98 __m128 one = _mm_set1_ps(1.0);
99 __m128 two = _mm_set1_ps(2.0);
105 jindex = nlist->jindex;
107 shiftidx = nlist->shift;
109 shiftvec = fr->shift_vec[0];
110 fshift = fr->fshift[0];
111 facel = _mm_set1_ps(fr->epsfac);
112 charge = mdatoms->chargeA;
113 krf = _mm_set1_ps(fr->ic->k_rf);
114 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
115 crf = _mm_set1_ps(fr->ic->c_rf);
117 /* Setup water-specific parameters */
118 inr = nlist->iinr[0];
119 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
120 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
121 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
123 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
124 rcutoff_scalar = fr->rcoulomb;
125 rcutoff = _mm_set1_ps(rcutoff_scalar);
126 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
128 /* Avoid stupid compiler warnings */
129 jnrA = jnrB = jnrC = jnrD = 0;
138 for(iidx=0;iidx<4*DIM;iidx++)
143 /* Start outer loop over neighborlists */
144 for(iidx=0; iidx<nri; iidx++)
146 /* Load shift vector for this list */
147 i_shift_offset = DIM*shiftidx[iidx];
149 /* Load limits for loop over neighbors */
150 j_index_start = jindex[iidx];
151 j_index_end = jindex[iidx+1];
153 /* Get outer coordinate index */
155 i_coord_offset = DIM*inr;
157 /* Load i particle coords and add shift vector */
158 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
159 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
161 fix0 = _mm_setzero_ps();
162 fiy0 = _mm_setzero_ps();
163 fiz0 = _mm_setzero_ps();
164 fix1 = _mm_setzero_ps();
165 fiy1 = _mm_setzero_ps();
166 fiz1 = _mm_setzero_ps();
167 fix2 = _mm_setzero_ps();
168 fiy2 = _mm_setzero_ps();
169 fiz2 = _mm_setzero_ps();
171 /* Reset potential sums */
172 velecsum = _mm_setzero_ps();
174 /* Start inner kernel loop */
175 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
178 /* Get j neighbor index, and coordinate index */
183 j_coord_offsetA = DIM*jnrA;
184 j_coord_offsetB = DIM*jnrB;
185 j_coord_offsetC = DIM*jnrC;
186 j_coord_offsetD = DIM*jnrD;
188 /* load j atom coordinates */
189 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
190 x+j_coord_offsetC,x+j_coord_offsetD,
193 /* Calculate displacement vector */
194 dx00 = _mm_sub_ps(ix0,jx0);
195 dy00 = _mm_sub_ps(iy0,jy0);
196 dz00 = _mm_sub_ps(iz0,jz0);
197 dx10 = _mm_sub_ps(ix1,jx0);
198 dy10 = _mm_sub_ps(iy1,jy0);
199 dz10 = _mm_sub_ps(iz1,jz0);
200 dx20 = _mm_sub_ps(ix2,jx0);
201 dy20 = _mm_sub_ps(iy2,jy0);
202 dz20 = _mm_sub_ps(iz2,jz0);
204 /* Calculate squared distance and things based on it */
205 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
206 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
207 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
209 rinv00 = gmx_mm_invsqrt_ps(rsq00);
210 rinv10 = gmx_mm_invsqrt_ps(rsq10);
211 rinv20 = gmx_mm_invsqrt_ps(rsq20);
213 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
214 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
215 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
217 /* Load parameters for j particles */
218 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
219 charge+jnrC+0,charge+jnrD+0);
221 fjx0 = _mm_setzero_ps();
222 fjy0 = _mm_setzero_ps();
223 fjz0 = _mm_setzero_ps();
225 /**************************
226 * CALCULATE INTERACTIONS *
227 **************************/
229 if (gmx_mm_any_lt(rsq00,rcutoff2))
232 /* Compute parameters for interactions between i and j atoms */
233 qq00 = _mm_mul_ps(iq0,jq0);
235 /* REACTION-FIELD ELECTROSTATICS */
236 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
237 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
239 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
241 /* Update potential sum for this i atom from the interaction with this j atom. */
242 velec = _mm_and_ps(velec,cutoff_mask);
243 velecsum = _mm_add_ps(velecsum,velec);
247 fscal = _mm_and_ps(fscal,cutoff_mask);
249 /* Calculate temporary vectorial force */
250 tx = _mm_mul_ps(fscal,dx00);
251 ty = _mm_mul_ps(fscal,dy00);
252 tz = _mm_mul_ps(fscal,dz00);
254 /* Update vectorial force */
255 fix0 = _mm_add_ps(fix0,tx);
256 fiy0 = _mm_add_ps(fiy0,ty);
257 fiz0 = _mm_add_ps(fiz0,tz);
259 fjx0 = _mm_add_ps(fjx0,tx);
260 fjy0 = _mm_add_ps(fjy0,ty);
261 fjz0 = _mm_add_ps(fjz0,tz);
265 /**************************
266 * CALCULATE INTERACTIONS *
267 **************************/
269 if (gmx_mm_any_lt(rsq10,rcutoff2))
272 /* Compute parameters for interactions between i and j atoms */
273 qq10 = _mm_mul_ps(iq1,jq0);
275 /* REACTION-FIELD ELECTROSTATICS */
276 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
277 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
279 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
281 /* Update potential sum for this i atom from the interaction with this j atom. */
282 velec = _mm_and_ps(velec,cutoff_mask);
283 velecsum = _mm_add_ps(velecsum,velec);
287 fscal = _mm_and_ps(fscal,cutoff_mask);
289 /* Calculate temporary vectorial force */
290 tx = _mm_mul_ps(fscal,dx10);
291 ty = _mm_mul_ps(fscal,dy10);
292 tz = _mm_mul_ps(fscal,dz10);
294 /* Update vectorial force */
295 fix1 = _mm_add_ps(fix1,tx);
296 fiy1 = _mm_add_ps(fiy1,ty);
297 fiz1 = _mm_add_ps(fiz1,tz);
299 fjx0 = _mm_add_ps(fjx0,tx);
300 fjy0 = _mm_add_ps(fjy0,ty);
301 fjz0 = _mm_add_ps(fjz0,tz);
305 /**************************
306 * CALCULATE INTERACTIONS *
307 **************************/
309 if (gmx_mm_any_lt(rsq20,rcutoff2))
312 /* Compute parameters for interactions between i and j atoms */
313 qq20 = _mm_mul_ps(iq2,jq0);
315 /* REACTION-FIELD ELECTROSTATICS */
316 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
317 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
319 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
321 /* Update potential sum for this i atom from the interaction with this j atom. */
322 velec = _mm_and_ps(velec,cutoff_mask);
323 velecsum = _mm_add_ps(velecsum,velec);
327 fscal = _mm_and_ps(fscal,cutoff_mask);
329 /* Calculate temporary vectorial force */
330 tx = _mm_mul_ps(fscal,dx20);
331 ty = _mm_mul_ps(fscal,dy20);
332 tz = _mm_mul_ps(fscal,dz20);
334 /* Update vectorial force */
335 fix2 = _mm_add_ps(fix2,tx);
336 fiy2 = _mm_add_ps(fiy2,ty);
337 fiz2 = _mm_add_ps(fiz2,tz);
339 fjx0 = _mm_add_ps(fjx0,tx);
340 fjy0 = _mm_add_ps(fjy0,ty);
341 fjz0 = _mm_add_ps(fjz0,tz);
345 fjptrA = f+j_coord_offsetA;
346 fjptrB = f+j_coord_offsetB;
347 fjptrC = f+j_coord_offsetC;
348 fjptrD = f+j_coord_offsetD;
350 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
352 /* Inner loop uses 108 flops */
358 /* Get j neighbor index, and coordinate index */
359 jnrlistA = jjnr[jidx];
360 jnrlistB = jjnr[jidx+1];
361 jnrlistC = jjnr[jidx+2];
362 jnrlistD = jjnr[jidx+3];
363 /* Sign of each element will be negative for non-real atoms.
364 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
365 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
367 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
368 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
369 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
370 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
371 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
372 j_coord_offsetA = DIM*jnrA;
373 j_coord_offsetB = DIM*jnrB;
374 j_coord_offsetC = DIM*jnrC;
375 j_coord_offsetD = DIM*jnrD;
377 /* load j atom coordinates */
378 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
379 x+j_coord_offsetC,x+j_coord_offsetD,
382 /* Calculate displacement vector */
383 dx00 = _mm_sub_ps(ix0,jx0);
384 dy00 = _mm_sub_ps(iy0,jy0);
385 dz00 = _mm_sub_ps(iz0,jz0);
386 dx10 = _mm_sub_ps(ix1,jx0);
387 dy10 = _mm_sub_ps(iy1,jy0);
388 dz10 = _mm_sub_ps(iz1,jz0);
389 dx20 = _mm_sub_ps(ix2,jx0);
390 dy20 = _mm_sub_ps(iy2,jy0);
391 dz20 = _mm_sub_ps(iz2,jz0);
393 /* Calculate squared distance and things based on it */
394 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
395 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
396 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
398 rinv00 = gmx_mm_invsqrt_ps(rsq00);
399 rinv10 = gmx_mm_invsqrt_ps(rsq10);
400 rinv20 = gmx_mm_invsqrt_ps(rsq20);
402 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
403 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
404 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
406 /* Load parameters for j particles */
407 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
408 charge+jnrC+0,charge+jnrD+0);
410 fjx0 = _mm_setzero_ps();
411 fjy0 = _mm_setzero_ps();
412 fjz0 = _mm_setzero_ps();
414 /**************************
415 * CALCULATE INTERACTIONS *
416 **************************/
418 if (gmx_mm_any_lt(rsq00,rcutoff2))
421 /* Compute parameters for interactions between i and j atoms */
422 qq00 = _mm_mul_ps(iq0,jq0);
424 /* REACTION-FIELD ELECTROSTATICS */
425 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
426 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
428 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
430 /* Update potential sum for this i atom from the interaction with this j atom. */
431 velec = _mm_and_ps(velec,cutoff_mask);
432 velec = _mm_andnot_ps(dummy_mask,velec);
433 velecsum = _mm_add_ps(velecsum,velec);
437 fscal = _mm_and_ps(fscal,cutoff_mask);
439 fscal = _mm_andnot_ps(dummy_mask,fscal);
441 /* Calculate temporary vectorial force */
442 tx = _mm_mul_ps(fscal,dx00);
443 ty = _mm_mul_ps(fscal,dy00);
444 tz = _mm_mul_ps(fscal,dz00);
446 /* Update vectorial force */
447 fix0 = _mm_add_ps(fix0,tx);
448 fiy0 = _mm_add_ps(fiy0,ty);
449 fiz0 = _mm_add_ps(fiz0,tz);
451 fjx0 = _mm_add_ps(fjx0,tx);
452 fjy0 = _mm_add_ps(fjy0,ty);
453 fjz0 = _mm_add_ps(fjz0,tz);
457 /**************************
458 * CALCULATE INTERACTIONS *
459 **************************/
461 if (gmx_mm_any_lt(rsq10,rcutoff2))
464 /* Compute parameters for interactions between i and j atoms */
465 qq10 = _mm_mul_ps(iq1,jq0);
467 /* REACTION-FIELD ELECTROSTATICS */
468 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
469 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
471 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
473 /* Update potential sum for this i atom from the interaction with this j atom. */
474 velec = _mm_and_ps(velec,cutoff_mask);
475 velec = _mm_andnot_ps(dummy_mask,velec);
476 velecsum = _mm_add_ps(velecsum,velec);
480 fscal = _mm_and_ps(fscal,cutoff_mask);
482 fscal = _mm_andnot_ps(dummy_mask,fscal);
484 /* Calculate temporary vectorial force */
485 tx = _mm_mul_ps(fscal,dx10);
486 ty = _mm_mul_ps(fscal,dy10);
487 tz = _mm_mul_ps(fscal,dz10);
489 /* Update vectorial force */
490 fix1 = _mm_add_ps(fix1,tx);
491 fiy1 = _mm_add_ps(fiy1,ty);
492 fiz1 = _mm_add_ps(fiz1,tz);
494 fjx0 = _mm_add_ps(fjx0,tx);
495 fjy0 = _mm_add_ps(fjy0,ty);
496 fjz0 = _mm_add_ps(fjz0,tz);
500 /**************************
501 * CALCULATE INTERACTIONS *
502 **************************/
504 if (gmx_mm_any_lt(rsq20,rcutoff2))
507 /* Compute parameters for interactions between i and j atoms */
508 qq20 = _mm_mul_ps(iq2,jq0);
510 /* REACTION-FIELD ELECTROSTATICS */
511 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
512 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
514 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
516 /* Update potential sum for this i atom from the interaction with this j atom. */
517 velec = _mm_and_ps(velec,cutoff_mask);
518 velec = _mm_andnot_ps(dummy_mask,velec);
519 velecsum = _mm_add_ps(velecsum,velec);
523 fscal = _mm_and_ps(fscal,cutoff_mask);
525 fscal = _mm_andnot_ps(dummy_mask,fscal);
527 /* Calculate temporary vectorial force */
528 tx = _mm_mul_ps(fscal,dx20);
529 ty = _mm_mul_ps(fscal,dy20);
530 tz = _mm_mul_ps(fscal,dz20);
532 /* Update vectorial force */
533 fix2 = _mm_add_ps(fix2,tx);
534 fiy2 = _mm_add_ps(fiy2,ty);
535 fiz2 = _mm_add_ps(fiz2,tz);
537 fjx0 = _mm_add_ps(fjx0,tx);
538 fjy0 = _mm_add_ps(fjy0,ty);
539 fjz0 = _mm_add_ps(fjz0,tz);
543 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
544 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
545 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
546 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
548 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
550 /* Inner loop uses 108 flops */
553 /* End of innermost loop */
555 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
556 f+i_coord_offset,fshift+i_shift_offset);
559 /* Update potential energies */
560 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
562 /* Increment number of inner iterations */
563 inneriter += j_index_end - j_index_start;
565 /* Outer loop uses 19 flops */
568 /* Increment number of outer iterations */
571 /* Update outer/inner flops */
573 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*108);
576 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_sse2_single
577 * Electrostatics interaction: ReactionField
578 * VdW interaction: None
579 * Geometry: Water3-Particle
580 * Calculate force/pot: Force
583 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_sse2_single
584 (t_nblist * gmx_restrict nlist,
585 rvec * gmx_restrict xx,
586 rvec * gmx_restrict ff,
587 t_forcerec * gmx_restrict fr,
588 t_mdatoms * gmx_restrict mdatoms,
589 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
590 t_nrnb * gmx_restrict nrnb)
592 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
593 * just 0 for non-waters.
594 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
595 * jnr indices corresponding to data put in the four positions in the SIMD register.
597 int i_shift_offset,i_coord_offset,outeriter,inneriter;
598 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
599 int jnrA,jnrB,jnrC,jnrD;
600 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
601 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
602 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
604 real *shiftvec,*fshift,*x,*f;
605 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
607 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
609 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
611 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
613 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
614 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
615 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
616 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
617 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
618 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
619 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
621 __m128 dummy_mask,cutoff_mask;
622 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
623 __m128 one = _mm_set1_ps(1.0);
624 __m128 two = _mm_set1_ps(2.0);
630 jindex = nlist->jindex;
632 shiftidx = nlist->shift;
634 shiftvec = fr->shift_vec[0];
635 fshift = fr->fshift[0];
636 facel = _mm_set1_ps(fr->epsfac);
637 charge = mdatoms->chargeA;
638 krf = _mm_set1_ps(fr->ic->k_rf);
639 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
640 crf = _mm_set1_ps(fr->ic->c_rf);
642 /* Setup water-specific parameters */
643 inr = nlist->iinr[0];
644 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
645 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
646 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
648 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
649 rcutoff_scalar = fr->rcoulomb;
650 rcutoff = _mm_set1_ps(rcutoff_scalar);
651 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
653 /* Avoid stupid compiler warnings */
654 jnrA = jnrB = jnrC = jnrD = 0;
663 for(iidx=0;iidx<4*DIM;iidx++)
668 /* Start outer loop over neighborlists */
669 for(iidx=0; iidx<nri; iidx++)
671 /* Load shift vector for this list */
672 i_shift_offset = DIM*shiftidx[iidx];
674 /* Load limits for loop over neighbors */
675 j_index_start = jindex[iidx];
676 j_index_end = jindex[iidx+1];
678 /* Get outer coordinate index */
680 i_coord_offset = DIM*inr;
682 /* Load i particle coords and add shift vector */
683 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
684 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
686 fix0 = _mm_setzero_ps();
687 fiy0 = _mm_setzero_ps();
688 fiz0 = _mm_setzero_ps();
689 fix1 = _mm_setzero_ps();
690 fiy1 = _mm_setzero_ps();
691 fiz1 = _mm_setzero_ps();
692 fix2 = _mm_setzero_ps();
693 fiy2 = _mm_setzero_ps();
694 fiz2 = _mm_setzero_ps();
696 /* Start inner kernel loop */
697 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
700 /* Get j neighbor index, and coordinate index */
705 j_coord_offsetA = DIM*jnrA;
706 j_coord_offsetB = DIM*jnrB;
707 j_coord_offsetC = DIM*jnrC;
708 j_coord_offsetD = DIM*jnrD;
710 /* load j atom coordinates */
711 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
712 x+j_coord_offsetC,x+j_coord_offsetD,
715 /* Calculate displacement vector */
716 dx00 = _mm_sub_ps(ix0,jx0);
717 dy00 = _mm_sub_ps(iy0,jy0);
718 dz00 = _mm_sub_ps(iz0,jz0);
719 dx10 = _mm_sub_ps(ix1,jx0);
720 dy10 = _mm_sub_ps(iy1,jy0);
721 dz10 = _mm_sub_ps(iz1,jz0);
722 dx20 = _mm_sub_ps(ix2,jx0);
723 dy20 = _mm_sub_ps(iy2,jy0);
724 dz20 = _mm_sub_ps(iz2,jz0);
726 /* Calculate squared distance and things based on it */
727 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
728 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
729 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
731 rinv00 = gmx_mm_invsqrt_ps(rsq00);
732 rinv10 = gmx_mm_invsqrt_ps(rsq10);
733 rinv20 = gmx_mm_invsqrt_ps(rsq20);
735 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
736 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
737 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
739 /* Load parameters for j particles */
740 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
741 charge+jnrC+0,charge+jnrD+0);
743 fjx0 = _mm_setzero_ps();
744 fjy0 = _mm_setzero_ps();
745 fjz0 = _mm_setzero_ps();
747 /**************************
748 * CALCULATE INTERACTIONS *
749 **************************/
751 if (gmx_mm_any_lt(rsq00,rcutoff2))
754 /* Compute parameters for interactions between i and j atoms */
755 qq00 = _mm_mul_ps(iq0,jq0);
757 /* REACTION-FIELD ELECTROSTATICS */
758 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
760 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
764 fscal = _mm_and_ps(fscal,cutoff_mask);
766 /* Calculate temporary vectorial force */
767 tx = _mm_mul_ps(fscal,dx00);
768 ty = _mm_mul_ps(fscal,dy00);
769 tz = _mm_mul_ps(fscal,dz00);
771 /* Update vectorial force */
772 fix0 = _mm_add_ps(fix0,tx);
773 fiy0 = _mm_add_ps(fiy0,ty);
774 fiz0 = _mm_add_ps(fiz0,tz);
776 fjx0 = _mm_add_ps(fjx0,tx);
777 fjy0 = _mm_add_ps(fjy0,ty);
778 fjz0 = _mm_add_ps(fjz0,tz);
782 /**************************
783 * CALCULATE INTERACTIONS *
784 **************************/
786 if (gmx_mm_any_lt(rsq10,rcutoff2))
789 /* Compute parameters for interactions between i and j atoms */
790 qq10 = _mm_mul_ps(iq1,jq0);
792 /* REACTION-FIELD ELECTROSTATICS */
793 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
795 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
799 fscal = _mm_and_ps(fscal,cutoff_mask);
801 /* Calculate temporary vectorial force */
802 tx = _mm_mul_ps(fscal,dx10);
803 ty = _mm_mul_ps(fscal,dy10);
804 tz = _mm_mul_ps(fscal,dz10);
806 /* Update vectorial force */
807 fix1 = _mm_add_ps(fix1,tx);
808 fiy1 = _mm_add_ps(fiy1,ty);
809 fiz1 = _mm_add_ps(fiz1,tz);
811 fjx0 = _mm_add_ps(fjx0,tx);
812 fjy0 = _mm_add_ps(fjy0,ty);
813 fjz0 = _mm_add_ps(fjz0,tz);
817 /**************************
818 * CALCULATE INTERACTIONS *
819 **************************/
821 if (gmx_mm_any_lt(rsq20,rcutoff2))
824 /* Compute parameters for interactions between i and j atoms */
825 qq20 = _mm_mul_ps(iq2,jq0);
827 /* REACTION-FIELD ELECTROSTATICS */
828 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
830 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
834 fscal = _mm_and_ps(fscal,cutoff_mask);
836 /* Calculate temporary vectorial force */
837 tx = _mm_mul_ps(fscal,dx20);
838 ty = _mm_mul_ps(fscal,dy20);
839 tz = _mm_mul_ps(fscal,dz20);
841 /* Update vectorial force */
842 fix2 = _mm_add_ps(fix2,tx);
843 fiy2 = _mm_add_ps(fiy2,ty);
844 fiz2 = _mm_add_ps(fiz2,tz);
846 fjx0 = _mm_add_ps(fjx0,tx);
847 fjy0 = _mm_add_ps(fjy0,ty);
848 fjz0 = _mm_add_ps(fjz0,tz);
852 fjptrA = f+j_coord_offsetA;
853 fjptrB = f+j_coord_offsetB;
854 fjptrC = f+j_coord_offsetC;
855 fjptrD = f+j_coord_offsetD;
857 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
859 /* Inner loop uses 90 flops */
865 /* Get j neighbor index, and coordinate index */
866 jnrlistA = jjnr[jidx];
867 jnrlistB = jjnr[jidx+1];
868 jnrlistC = jjnr[jidx+2];
869 jnrlistD = jjnr[jidx+3];
870 /* Sign of each element will be negative for non-real atoms.
871 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
872 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
874 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
875 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
876 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
877 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
878 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
879 j_coord_offsetA = DIM*jnrA;
880 j_coord_offsetB = DIM*jnrB;
881 j_coord_offsetC = DIM*jnrC;
882 j_coord_offsetD = DIM*jnrD;
884 /* load j atom coordinates */
885 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
886 x+j_coord_offsetC,x+j_coord_offsetD,
889 /* Calculate displacement vector */
890 dx00 = _mm_sub_ps(ix0,jx0);
891 dy00 = _mm_sub_ps(iy0,jy0);
892 dz00 = _mm_sub_ps(iz0,jz0);
893 dx10 = _mm_sub_ps(ix1,jx0);
894 dy10 = _mm_sub_ps(iy1,jy0);
895 dz10 = _mm_sub_ps(iz1,jz0);
896 dx20 = _mm_sub_ps(ix2,jx0);
897 dy20 = _mm_sub_ps(iy2,jy0);
898 dz20 = _mm_sub_ps(iz2,jz0);
900 /* Calculate squared distance and things based on it */
901 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
902 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
903 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
905 rinv00 = gmx_mm_invsqrt_ps(rsq00);
906 rinv10 = gmx_mm_invsqrt_ps(rsq10);
907 rinv20 = gmx_mm_invsqrt_ps(rsq20);
909 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
910 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
911 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
913 /* Load parameters for j particles */
914 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
915 charge+jnrC+0,charge+jnrD+0);
917 fjx0 = _mm_setzero_ps();
918 fjy0 = _mm_setzero_ps();
919 fjz0 = _mm_setzero_ps();
921 /**************************
922 * CALCULATE INTERACTIONS *
923 **************************/
925 if (gmx_mm_any_lt(rsq00,rcutoff2))
928 /* Compute parameters for interactions between i and j atoms */
929 qq00 = _mm_mul_ps(iq0,jq0);
931 /* REACTION-FIELD ELECTROSTATICS */
932 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
934 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
938 fscal = _mm_and_ps(fscal,cutoff_mask);
940 fscal = _mm_andnot_ps(dummy_mask,fscal);
942 /* Calculate temporary vectorial force */
943 tx = _mm_mul_ps(fscal,dx00);
944 ty = _mm_mul_ps(fscal,dy00);
945 tz = _mm_mul_ps(fscal,dz00);
947 /* Update vectorial force */
948 fix0 = _mm_add_ps(fix0,tx);
949 fiy0 = _mm_add_ps(fiy0,ty);
950 fiz0 = _mm_add_ps(fiz0,tz);
952 fjx0 = _mm_add_ps(fjx0,tx);
953 fjy0 = _mm_add_ps(fjy0,ty);
954 fjz0 = _mm_add_ps(fjz0,tz);
958 /**************************
959 * CALCULATE INTERACTIONS *
960 **************************/
962 if (gmx_mm_any_lt(rsq10,rcutoff2))
965 /* Compute parameters for interactions between i and j atoms */
966 qq10 = _mm_mul_ps(iq1,jq0);
968 /* REACTION-FIELD ELECTROSTATICS */
969 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
971 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
975 fscal = _mm_and_ps(fscal,cutoff_mask);
977 fscal = _mm_andnot_ps(dummy_mask,fscal);
979 /* Calculate temporary vectorial force */
980 tx = _mm_mul_ps(fscal,dx10);
981 ty = _mm_mul_ps(fscal,dy10);
982 tz = _mm_mul_ps(fscal,dz10);
984 /* Update vectorial force */
985 fix1 = _mm_add_ps(fix1,tx);
986 fiy1 = _mm_add_ps(fiy1,ty);
987 fiz1 = _mm_add_ps(fiz1,tz);
989 fjx0 = _mm_add_ps(fjx0,tx);
990 fjy0 = _mm_add_ps(fjy0,ty);
991 fjz0 = _mm_add_ps(fjz0,tz);
995 /**************************
996 * CALCULATE INTERACTIONS *
997 **************************/
999 if (gmx_mm_any_lt(rsq20,rcutoff2))
1002 /* Compute parameters for interactions between i and j atoms */
1003 qq20 = _mm_mul_ps(iq2,jq0);
1005 /* REACTION-FIELD ELECTROSTATICS */
1006 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1008 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
1012 fscal = _mm_and_ps(fscal,cutoff_mask);
1014 fscal = _mm_andnot_ps(dummy_mask,fscal);
1016 /* Calculate temporary vectorial force */
1017 tx = _mm_mul_ps(fscal,dx20);
1018 ty = _mm_mul_ps(fscal,dy20);
1019 tz = _mm_mul_ps(fscal,dz20);
1021 /* Update vectorial force */
1022 fix2 = _mm_add_ps(fix2,tx);
1023 fiy2 = _mm_add_ps(fiy2,ty);
1024 fiz2 = _mm_add_ps(fiz2,tz);
1026 fjx0 = _mm_add_ps(fjx0,tx);
1027 fjy0 = _mm_add_ps(fjy0,ty);
1028 fjz0 = _mm_add_ps(fjz0,tz);
1032 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1033 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1034 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1035 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1037 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1039 /* Inner loop uses 90 flops */
1042 /* End of innermost loop */
1044 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1045 f+i_coord_offset,fshift+i_shift_offset);
1047 /* Increment number of inner iterations */
1048 inneriter += j_index_end - j_index_start;
1050 /* Outer loop uses 18 flops */
1053 /* Increment number of outer iterations */
1056 /* Update outer/inner flops */
1058 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*90);