2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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.
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomP1P1_VF_sse2_single
51 * Electrostatics interaction: Ewald
52 * VdW interaction: None
53 * Geometry: Particle-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_VF_sse2_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;
90 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
92 __m128 dummy_mask,cutoff_mask;
93 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
94 __m128 one = _mm_set1_ps(1.0);
95 __m128 two = _mm_set1_ps(2.0);
101 jindex = nlist->jindex;
103 shiftidx = nlist->shift;
105 shiftvec = fr->shift_vec[0];
106 fshift = fr->fshift[0];
107 facel = _mm_set1_ps(fr->ic->epsfac);
108 charge = mdatoms->chargeA;
110 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
111 ewtab = fr->ic->tabq_coul_FDV0;
112 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
113 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
115 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
116 rcutoff_scalar = fr->ic->rcoulomb;
117 rcutoff = _mm_set1_ps(rcutoff_scalar);
118 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
120 /* Avoid stupid compiler warnings */
121 jnrA = jnrB = jnrC = jnrD = 0;
130 for(iidx=0;iidx<4*DIM;iidx++)
135 /* Start outer loop over neighborlists */
136 for(iidx=0; iidx<nri; iidx++)
138 /* Load shift vector for this list */
139 i_shift_offset = DIM*shiftidx[iidx];
141 /* Load limits for loop over neighbors */
142 j_index_start = jindex[iidx];
143 j_index_end = jindex[iidx+1];
145 /* Get outer coordinate index */
147 i_coord_offset = DIM*inr;
149 /* Load i particle coords and add shift vector */
150 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
152 fix0 = _mm_setzero_ps();
153 fiy0 = _mm_setzero_ps();
154 fiz0 = _mm_setzero_ps();
156 /* Load parameters for i particles */
157 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
159 /* Reset potential sums */
160 velecsum = _mm_setzero_ps();
162 /* Start inner kernel loop */
163 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
166 /* Get j neighbor index, and coordinate index */
171 j_coord_offsetA = DIM*jnrA;
172 j_coord_offsetB = DIM*jnrB;
173 j_coord_offsetC = DIM*jnrC;
174 j_coord_offsetD = DIM*jnrD;
176 /* load j atom coordinates */
177 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
178 x+j_coord_offsetC,x+j_coord_offsetD,
181 /* Calculate displacement vector */
182 dx00 = _mm_sub_ps(ix0,jx0);
183 dy00 = _mm_sub_ps(iy0,jy0);
184 dz00 = _mm_sub_ps(iz0,jz0);
186 /* Calculate squared distance and things based on it */
187 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
189 rinv00 = sse2_invsqrt_f(rsq00);
191 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
193 /* Load parameters for j particles */
194 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
195 charge+jnrC+0,charge+jnrD+0);
197 /**************************
198 * CALCULATE INTERACTIONS *
199 **************************/
201 if (gmx_mm_any_lt(rsq00,rcutoff2))
204 r00 = _mm_mul_ps(rsq00,rinv00);
206 /* Compute parameters for interactions between i and j atoms */
207 qq00 = _mm_mul_ps(iq0,jq0);
209 /* EWALD ELECTROSTATICS */
211 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
212 ewrt = _mm_mul_ps(r00,ewtabscale);
213 ewitab = _mm_cvttps_epi32(ewrt);
214 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
215 ewitab = _mm_slli_epi32(ewitab,2);
216 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
217 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
218 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
219 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
220 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
221 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
222 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
223 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_sub_ps(rinv00,sh_ewald),velec));
224 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
226 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
228 /* Update potential sum for this i atom from the interaction with this j atom. */
229 velec = _mm_and_ps(velec,cutoff_mask);
230 velecsum = _mm_add_ps(velecsum,velec);
234 fscal = _mm_and_ps(fscal,cutoff_mask);
236 /* Calculate temporary vectorial force */
237 tx = _mm_mul_ps(fscal,dx00);
238 ty = _mm_mul_ps(fscal,dy00);
239 tz = _mm_mul_ps(fscal,dz00);
241 /* Update vectorial force */
242 fix0 = _mm_add_ps(fix0,tx);
243 fiy0 = _mm_add_ps(fiy0,ty);
244 fiz0 = _mm_add_ps(fiz0,tz);
246 fjptrA = f+j_coord_offsetA;
247 fjptrB = f+j_coord_offsetB;
248 fjptrC = f+j_coord_offsetC;
249 fjptrD = f+j_coord_offsetD;
250 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
254 /* Inner loop uses 46 flops */
260 /* Get j neighbor index, and coordinate index */
261 jnrlistA = jjnr[jidx];
262 jnrlistB = jjnr[jidx+1];
263 jnrlistC = jjnr[jidx+2];
264 jnrlistD = jjnr[jidx+3];
265 /* Sign of each element will be negative for non-real atoms.
266 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
267 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
269 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
270 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
271 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
272 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
273 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
274 j_coord_offsetA = DIM*jnrA;
275 j_coord_offsetB = DIM*jnrB;
276 j_coord_offsetC = DIM*jnrC;
277 j_coord_offsetD = DIM*jnrD;
279 /* load j atom coordinates */
280 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
281 x+j_coord_offsetC,x+j_coord_offsetD,
284 /* Calculate displacement vector */
285 dx00 = _mm_sub_ps(ix0,jx0);
286 dy00 = _mm_sub_ps(iy0,jy0);
287 dz00 = _mm_sub_ps(iz0,jz0);
289 /* Calculate squared distance and things based on it */
290 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
292 rinv00 = sse2_invsqrt_f(rsq00);
294 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
296 /* Load parameters for j particles */
297 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
298 charge+jnrC+0,charge+jnrD+0);
300 /**************************
301 * CALCULATE INTERACTIONS *
302 **************************/
304 if (gmx_mm_any_lt(rsq00,rcutoff2))
307 r00 = _mm_mul_ps(rsq00,rinv00);
308 r00 = _mm_andnot_ps(dummy_mask,r00);
310 /* Compute parameters for interactions between i and j atoms */
311 qq00 = _mm_mul_ps(iq0,jq0);
313 /* EWALD ELECTROSTATICS */
315 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
316 ewrt = _mm_mul_ps(r00,ewtabscale);
317 ewitab = _mm_cvttps_epi32(ewrt);
318 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
319 ewitab = _mm_slli_epi32(ewitab,2);
320 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
321 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
322 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
323 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
324 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
325 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
326 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
327 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_sub_ps(rinv00,sh_ewald),velec));
328 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
330 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
332 /* Update potential sum for this i atom from the interaction with this j atom. */
333 velec = _mm_and_ps(velec,cutoff_mask);
334 velec = _mm_andnot_ps(dummy_mask,velec);
335 velecsum = _mm_add_ps(velecsum,velec);
339 fscal = _mm_and_ps(fscal,cutoff_mask);
341 fscal = _mm_andnot_ps(dummy_mask,fscal);
343 /* Calculate temporary vectorial force */
344 tx = _mm_mul_ps(fscal,dx00);
345 ty = _mm_mul_ps(fscal,dy00);
346 tz = _mm_mul_ps(fscal,dz00);
348 /* Update vectorial force */
349 fix0 = _mm_add_ps(fix0,tx);
350 fiy0 = _mm_add_ps(fiy0,ty);
351 fiz0 = _mm_add_ps(fiz0,tz);
353 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
354 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
355 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
356 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
357 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
361 /* Inner loop uses 47 flops */
364 /* End of innermost loop */
366 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
367 f+i_coord_offset,fshift+i_shift_offset);
370 /* Update potential energies */
371 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
373 /* Increment number of inner iterations */
374 inneriter += j_index_end - j_index_start;
376 /* Outer loop uses 8 flops */
379 /* Increment number of outer iterations */
382 /* Update outer/inner flops */
384 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*47);
387 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_sse2_single
388 * Electrostatics interaction: Ewald
389 * VdW interaction: None
390 * Geometry: Particle-Particle
391 * Calculate force/pot: Force
394 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_sse2_single
395 (t_nblist * gmx_restrict nlist,
396 rvec * gmx_restrict xx,
397 rvec * gmx_restrict ff,
398 struct t_forcerec * gmx_restrict fr,
399 t_mdatoms * gmx_restrict mdatoms,
400 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
401 t_nrnb * gmx_restrict nrnb)
403 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
404 * just 0 for non-waters.
405 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
406 * jnr indices corresponding to data put in the four positions in the SIMD register.
408 int i_shift_offset,i_coord_offset,outeriter,inneriter;
409 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
410 int jnrA,jnrB,jnrC,jnrD;
411 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
412 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
413 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
415 real *shiftvec,*fshift,*x,*f;
416 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
418 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
420 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
421 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
422 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
423 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
424 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
427 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
429 __m128 dummy_mask,cutoff_mask;
430 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
431 __m128 one = _mm_set1_ps(1.0);
432 __m128 two = _mm_set1_ps(2.0);
438 jindex = nlist->jindex;
440 shiftidx = nlist->shift;
442 shiftvec = fr->shift_vec[0];
443 fshift = fr->fshift[0];
444 facel = _mm_set1_ps(fr->ic->epsfac);
445 charge = mdatoms->chargeA;
447 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
448 ewtab = fr->ic->tabq_coul_F;
449 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
450 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
452 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
453 rcutoff_scalar = fr->ic->rcoulomb;
454 rcutoff = _mm_set1_ps(rcutoff_scalar);
455 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
457 /* Avoid stupid compiler warnings */
458 jnrA = jnrB = jnrC = jnrD = 0;
467 for(iidx=0;iidx<4*DIM;iidx++)
472 /* Start outer loop over neighborlists */
473 for(iidx=0; iidx<nri; iidx++)
475 /* Load shift vector for this list */
476 i_shift_offset = DIM*shiftidx[iidx];
478 /* Load limits for loop over neighbors */
479 j_index_start = jindex[iidx];
480 j_index_end = jindex[iidx+1];
482 /* Get outer coordinate index */
484 i_coord_offset = DIM*inr;
486 /* Load i particle coords and add shift vector */
487 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
489 fix0 = _mm_setzero_ps();
490 fiy0 = _mm_setzero_ps();
491 fiz0 = _mm_setzero_ps();
493 /* Load parameters for i particles */
494 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
496 /* Start inner kernel loop */
497 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
500 /* Get j neighbor index, and coordinate index */
505 j_coord_offsetA = DIM*jnrA;
506 j_coord_offsetB = DIM*jnrB;
507 j_coord_offsetC = DIM*jnrC;
508 j_coord_offsetD = DIM*jnrD;
510 /* load j atom coordinates */
511 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
512 x+j_coord_offsetC,x+j_coord_offsetD,
515 /* Calculate displacement vector */
516 dx00 = _mm_sub_ps(ix0,jx0);
517 dy00 = _mm_sub_ps(iy0,jy0);
518 dz00 = _mm_sub_ps(iz0,jz0);
520 /* Calculate squared distance and things based on it */
521 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
523 rinv00 = sse2_invsqrt_f(rsq00);
525 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
527 /* Load parameters for j particles */
528 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
529 charge+jnrC+0,charge+jnrD+0);
531 /**************************
532 * CALCULATE INTERACTIONS *
533 **************************/
535 if (gmx_mm_any_lt(rsq00,rcutoff2))
538 r00 = _mm_mul_ps(rsq00,rinv00);
540 /* Compute parameters for interactions between i and j atoms */
541 qq00 = _mm_mul_ps(iq0,jq0);
543 /* EWALD ELECTROSTATICS */
545 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
546 ewrt = _mm_mul_ps(r00,ewtabscale);
547 ewitab = _mm_cvttps_epi32(ewrt);
548 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
549 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
550 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
552 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
553 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
555 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
559 fscal = _mm_and_ps(fscal,cutoff_mask);
561 /* Calculate temporary vectorial force */
562 tx = _mm_mul_ps(fscal,dx00);
563 ty = _mm_mul_ps(fscal,dy00);
564 tz = _mm_mul_ps(fscal,dz00);
566 /* Update vectorial force */
567 fix0 = _mm_add_ps(fix0,tx);
568 fiy0 = _mm_add_ps(fiy0,ty);
569 fiz0 = _mm_add_ps(fiz0,tz);
571 fjptrA = f+j_coord_offsetA;
572 fjptrB = f+j_coord_offsetB;
573 fjptrC = f+j_coord_offsetC;
574 fjptrD = f+j_coord_offsetD;
575 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
579 /* Inner loop uses 39 flops */
585 /* Get j neighbor index, and coordinate index */
586 jnrlistA = jjnr[jidx];
587 jnrlistB = jjnr[jidx+1];
588 jnrlistC = jjnr[jidx+2];
589 jnrlistD = jjnr[jidx+3];
590 /* Sign of each element will be negative for non-real atoms.
591 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
592 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
594 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
595 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
596 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
597 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
598 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
599 j_coord_offsetA = DIM*jnrA;
600 j_coord_offsetB = DIM*jnrB;
601 j_coord_offsetC = DIM*jnrC;
602 j_coord_offsetD = DIM*jnrD;
604 /* load j atom coordinates */
605 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
606 x+j_coord_offsetC,x+j_coord_offsetD,
609 /* Calculate displacement vector */
610 dx00 = _mm_sub_ps(ix0,jx0);
611 dy00 = _mm_sub_ps(iy0,jy0);
612 dz00 = _mm_sub_ps(iz0,jz0);
614 /* Calculate squared distance and things based on it */
615 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
617 rinv00 = sse2_invsqrt_f(rsq00);
619 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
621 /* Load parameters for j particles */
622 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
623 charge+jnrC+0,charge+jnrD+0);
625 /**************************
626 * CALCULATE INTERACTIONS *
627 **************************/
629 if (gmx_mm_any_lt(rsq00,rcutoff2))
632 r00 = _mm_mul_ps(rsq00,rinv00);
633 r00 = _mm_andnot_ps(dummy_mask,r00);
635 /* Compute parameters for interactions between i and j atoms */
636 qq00 = _mm_mul_ps(iq0,jq0);
638 /* EWALD ELECTROSTATICS */
640 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
641 ewrt = _mm_mul_ps(r00,ewtabscale);
642 ewitab = _mm_cvttps_epi32(ewrt);
643 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
644 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
645 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
647 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
648 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
650 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
654 fscal = _mm_and_ps(fscal,cutoff_mask);
656 fscal = _mm_andnot_ps(dummy_mask,fscal);
658 /* Calculate temporary vectorial force */
659 tx = _mm_mul_ps(fscal,dx00);
660 ty = _mm_mul_ps(fscal,dy00);
661 tz = _mm_mul_ps(fscal,dz00);
663 /* Update vectorial force */
664 fix0 = _mm_add_ps(fix0,tx);
665 fiy0 = _mm_add_ps(fiy0,ty);
666 fiz0 = _mm_add_ps(fiz0,tz);
668 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
669 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
670 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
671 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
672 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
676 /* Inner loop uses 40 flops */
679 /* End of innermost loop */
681 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
682 f+i_coord_offset,fshift+i_shift_offset);
684 /* Increment number of inner iterations */
685 inneriter += j_index_end - j_index_start;
687 /* Outer loop uses 7 flops */
690 /* Increment number of outer iterations */
693 /* Update outer/inner flops */
695 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*40);