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 sse2_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gromacs/simd/math_x86_sse2_single.h"
50 #include "kernelutil_x86_sse2_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomP1P1_VF_sse2_single
54 * Electrostatics interaction: Ewald
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_VF_sse2_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 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
93 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
95 __m128 dummy_mask,cutoff_mask;
96 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
97 __m128 one = _mm_set1_ps(1.0);
98 __m128 two = _mm_set1_ps(2.0);
104 jindex = nlist->jindex;
106 shiftidx = nlist->shift;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm_set1_ps(fr->epsfac);
111 charge = mdatoms->chargeA;
113 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
114 ewtab = fr->ic->tabq_coul_FDV0;
115 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
116 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
118 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
119 rcutoff_scalar = fr->rcoulomb;
120 rcutoff = _mm_set1_ps(rcutoff_scalar);
121 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
123 /* Avoid stupid compiler warnings */
124 jnrA = jnrB = jnrC = jnrD = 0;
133 for(iidx=0;iidx<4*DIM;iidx++)
138 /* Start outer loop over neighborlists */
139 for(iidx=0; iidx<nri; iidx++)
141 /* Load shift vector for this list */
142 i_shift_offset = DIM*shiftidx[iidx];
144 /* Load limits for loop over neighbors */
145 j_index_start = jindex[iidx];
146 j_index_end = jindex[iidx+1];
148 /* Get outer coordinate index */
150 i_coord_offset = DIM*inr;
152 /* Load i particle coords and add shift vector */
153 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
155 fix0 = _mm_setzero_ps();
156 fiy0 = _mm_setzero_ps();
157 fiz0 = _mm_setzero_ps();
159 /* Load parameters for i particles */
160 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
162 /* Reset potential sums */
163 velecsum = _mm_setzero_ps();
165 /* Start inner kernel loop */
166 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
169 /* Get j neighbor index, and coordinate index */
174 j_coord_offsetA = DIM*jnrA;
175 j_coord_offsetB = DIM*jnrB;
176 j_coord_offsetC = DIM*jnrC;
177 j_coord_offsetD = DIM*jnrD;
179 /* load j atom coordinates */
180 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
181 x+j_coord_offsetC,x+j_coord_offsetD,
184 /* Calculate displacement vector */
185 dx00 = _mm_sub_ps(ix0,jx0);
186 dy00 = _mm_sub_ps(iy0,jy0);
187 dz00 = _mm_sub_ps(iz0,jz0);
189 /* Calculate squared distance and things based on it */
190 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
192 rinv00 = gmx_mm_invsqrt_ps(rsq00);
194 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
196 /* Load parameters for j particles */
197 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
198 charge+jnrC+0,charge+jnrD+0);
200 /**************************
201 * CALCULATE INTERACTIONS *
202 **************************/
204 if (gmx_mm_any_lt(rsq00,rcutoff2))
207 r00 = _mm_mul_ps(rsq00,rinv00);
209 /* Compute parameters for interactions between i and j atoms */
210 qq00 = _mm_mul_ps(iq0,jq0);
212 /* EWALD ELECTROSTATICS */
214 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
215 ewrt = _mm_mul_ps(r00,ewtabscale);
216 ewitab = _mm_cvttps_epi32(ewrt);
217 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
218 ewitab = _mm_slli_epi32(ewitab,2);
219 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
220 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
221 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
222 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
223 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
224 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
225 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
226 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_sub_ps(rinv00,sh_ewald),velec));
227 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
229 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
231 /* Update potential sum for this i atom from the interaction with this j atom. */
232 velec = _mm_and_ps(velec,cutoff_mask);
233 velecsum = _mm_add_ps(velecsum,velec);
237 fscal = _mm_and_ps(fscal,cutoff_mask);
239 /* Calculate temporary vectorial force */
240 tx = _mm_mul_ps(fscal,dx00);
241 ty = _mm_mul_ps(fscal,dy00);
242 tz = _mm_mul_ps(fscal,dz00);
244 /* Update vectorial force */
245 fix0 = _mm_add_ps(fix0,tx);
246 fiy0 = _mm_add_ps(fiy0,ty);
247 fiz0 = _mm_add_ps(fiz0,tz);
249 fjptrA = f+j_coord_offsetA;
250 fjptrB = f+j_coord_offsetB;
251 fjptrC = f+j_coord_offsetC;
252 fjptrD = f+j_coord_offsetD;
253 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
257 /* Inner loop uses 46 flops */
263 /* Get j neighbor index, and coordinate index */
264 jnrlistA = jjnr[jidx];
265 jnrlistB = jjnr[jidx+1];
266 jnrlistC = jjnr[jidx+2];
267 jnrlistD = jjnr[jidx+3];
268 /* Sign of each element will be negative for non-real atoms.
269 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
270 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
272 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
273 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
274 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
275 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
276 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
277 j_coord_offsetA = DIM*jnrA;
278 j_coord_offsetB = DIM*jnrB;
279 j_coord_offsetC = DIM*jnrC;
280 j_coord_offsetD = DIM*jnrD;
282 /* load j atom coordinates */
283 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
284 x+j_coord_offsetC,x+j_coord_offsetD,
287 /* Calculate displacement vector */
288 dx00 = _mm_sub_ps(ix0,jx0);
289 dy00 = _mm_sub_ps(iy0,jy0);
290 dz00 = _mm_sub_ps(iz0,jz0);
292 /* Calculate squared distance and things based on it */
293 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
295 rinv00 = gmx_mm_invsqrt_ps(rsq00);
297 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
299 /* Load parameters for j particles */
300 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
301 charge+jnrC+0,charge+jnrD+0);
303 /**************************
304 * CALCULATE INTERACTIONS *
305 **************************/
307 if (gmx_mm_any_lt(rsq00,rcutoff2))
310 r00 = _mm_mul_ps(rsq00,rinv00);
311 r00 = _mm_andnot_ps(dummy_mask,r00);
313 /* Compute parameters for interactions between i and j atoms */
314 qq00 = _mm_mul_ps(iq0,jq0);
316 /* EWALD ELECTROSTATICS */
318 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
319 ewrt = _mm_mul_ps(r00,ewtabscale);
320 ewitab = _mm_cvttps_epi32(ewrt);
321 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
322 ewitab = _mm_slli_epi32(ewitab,2);
323 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
324 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
325 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
326 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
327 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
328 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
329 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
330 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_sub_ps(rinv00,sh_ewald),velec));
331 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
333 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
335 /* Update potential sum for this i atom from the interaction with this j atom. */
336 velec = _mm_and_ps(velec,cutoff_mask);
337 velec = _mm_andnot_ps(dummy_mask,velec);
338 velecsum = _mm_add_ps(velecsum,velec);
342 fscal = _mm_and_ps(fscal,cutoff_mask);
344 fscal = _mm_andnot_ps(dummy_mask,fscal);
346 /* Calculate temporary vectorial force */
347 tx = _mm_mul_ps(fscal,dx00);
348 ty = _mm_mul_ps(fscal,dy00);
349 tz = _mm_mul_ps(fscal,dz00);
351 /* Update vectorial force */
352 fix0 = _mm_add_ps(fix0,tx);
353 fiy0 = _mm_add_ps(fiy0,ty);
354 fiz0 = _mm_add_ps(fiz0,tz);
356 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
357 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
358 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
359 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
360 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
364 /* Inner loop uses 47 flops */
367 /* End of innermost loop */
369 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
370 f+i_coord_offset,fshift+i_shift_offset);
373 /* Update potential energies */
374 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
376 /* Increment number of inner iterations */
377 inneriter += j_index_end - j_index_start;
379 /* Outer loop uses 8 flops */
382 /* Increment number of outer iterations */
385 /* Update outer/inner flops */
387 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*47);
390 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_sse2_single
391 * Electrostatics interaction: Ewald
392 * VdW interaction: None
393 * Geometry: Particle-Particle
394 * Calculate force/pot: Force
397 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_sse2_single
398 (t_nblist * gmx_restrict nlist,
399 rvec * gmx_restrict xx,
400 rvec * gmx_restrict ff,
401 t_forcerec * gmx_restrict fr,
402 t_mdatoms * gmx_restrict mdatoms,
403 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
404 t_nrnb * gmx_restrict nrnb)
406 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
407 * just 0 for non-waters.
408 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
409 * jnr indices corresponding to data put in the four positions in the SIMD register.
411 int i_shift_offset,i_coord_offset,outeriter,inneriter;
412 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
413 int jnrA,jnrB,jnrC,jnrD;
414 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
415 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
416 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
418 real *shiftvec,*fshift,*x,*f;
419 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
421 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
423 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
424 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
425 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
426 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
427 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
430 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
432 __m128 dummy_mask,cutoff_mask;
433 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
434 __m128 one = _mm_set1_ps(1.0);
435 __m128 two = _mm_set1_ps(2.0);
441 jindex = nlist->jindex;
443 shiftidx = nlist->shift;
445 shiftvec = fr->shift_vec[0];
446 fshift = fr->fshift[0];
447 facel = _mm_set1_ps(fr->epsfac);
448 charge = mdatoms->chargeA;
450 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
451 ewtab = fr->ic->tabq_coul_F;
452 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
453 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
455 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
456 rcutoff_scalar = fr->rcoulomb;
457 rcutoff = _mm_set1_ps(rcutoff_scalar);
458 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
460 /* Avoid stupid compiler warnings */
461 jnrA = jnrB = jnrC = jnrD = 0;
470 for(iidx=0;iidx<4*DIM;iidx++)
475 /* Start outer loop over neighborlists */
476 for(iidx=0; iidx<nri; iidx++)
478 /* Load shift vector for this list */
479 i_shift_offset = DIM*shiftidx[iidx];
481 /* Load limits for loop over neighbors */
482 j_index_start = jindex[iidx];
483 j_index_end = jindex[iidx+1];
485 /* Get outer coordinate index */
487 i_coord_offset = DIM*inr;
489 /* Load i particle coords and add shift vector */
490 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
492 fix0 = _mm_setzero_ps();
493 fiy0 = _mm_setzero_ps();
494 fiz0 = _mm_setzero_ps();
496 /* Load parameters for i particles */
497 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
499 /* Start inner kernel loop */
500 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
503 /* Get j neighbor index, and coordinate index */
508 j_coord_offsetA = DIM*jnrA;
509 j_coord_offsetB = DIM*jnrB;
510 j_coord_offsetC = DIM*jnrC;
511 j_coord_offsetD = DIM*jnrD;
513 /* load j atom coordinates */
514 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
515 x+j_coord_offsetC,x+j_coord_offsetD,
518 /* Calculate displacement vector */
519 dx00 = _mm_sub_ps(ix0,jx0);
520 dy00 = _mm_sub_ps(iy0,jy0);
521 dz00 = _mm_sub_ps(iz0,jz0);
523 /* Calculate squared distance and things based on it */
524 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
526 rinv00 = gmx_mm_invsqrt_ps(rsq00);
528 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
530 /* Load parameters for j particles */
531 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
532 charge+jnrC+0,charge+jnrD+0);
534 /**************************
535 * CALCULATE INTERACTIONS *
536 **************************/
538 if (gmx_mm_any_lt(rsq00,rcutoff2))
541 r00 = _mm_mul_ps(rsq00,rinv00);
543 /* Compute parameters for interactions between i and j atoms */
544 qq00 = _mm_mul_ps(iq0,jq0);
546 /* EWALD ELECTROSTATICS */
548 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
549 ewrt = _mm_mul_ps(r00,ewtabscale);
550 ewitab = _mm_cvttps_epi32(ewrt);
551 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
552 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
553 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
555 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
556 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
558 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
562 fscal = _mm_and_ps(fscal,cutoff_mask);
564 /* Calculate temporary vectorial force */
565 tx = _mm_mul_ps(fscal,dx00);
566 ty = _mm_mul_ps(fscal,dy00);
567 tz = _mm_mul_ps(fscal,dz00);
569 /* Update vectorial force */
570 fix0 = _mm_add_ps(fix0,tx);
571 fiy0 = _mm_add_ps(fiy0,ty);
572 fiz0 = _mm_add_ps(fiz0,tz);
574 fjptrA = f+j_coord_offsetA;
575 fjptrB = f+j_coord_offsetB;
576 fjptrC = f+j_coord_offsetC;
577 fjptrD = f+j_coord_offsetD;
578 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
582 /* Inner loop uses 39 flops */
588 /* Get j neighbor index, and coordinate index */
589 jnrlistA = jjnr[jidx];
590 jnrlistB = jjnr[jidx+1];
591 jnrlistC = jjnr[jidx+2];
592 jnrlistD = jjnr[jidx+3];
593 /* Sign of each element will be negative for non-real atoms.
594 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
595 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
597 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
598 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
599 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
600 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
601 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
602 j_coord_offsetA = DIM*jnrA;
603 j_coord_offsetB = DIM*jnrB;
604 j_coord_offsetC = DIM*jnrC;
605 j_coord_offsetD = DIM*jnrD;
607 /* load j atom coordinates */
608 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
609 x+j_coord_offsetC,x+j_coord_offsetD,
612 /* Calculate displacement vector */
613 dx00 = _mm_sub_ps(ix0,jx0);
614 dy00 = _mm_sub_ps(iy0,jy0);
615 dz00 = _mm_sub_ps(iz0,jz0);
617 /* Calculate squared distance and things based on it */
618 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
620 rinv00 = gmx_mm_invsqrt_ps(rsq00);
622 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
624 /* Load parameters for j particles */
625 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
626 charge+jnrC+0,charge+jnrD+0);
628 /**************************
629 * CALCULATE INTERACTIONS *
630 **************************/
632 if (gmx_mm_any_lt(rsq00,rcutoff2))
635 r00 = _mm_mul_ps(rsq00,rinv00);
636 r00 = _mm_andnot_ps(dummy_mask,r00);
638 /* Compute parameters for interactions between i and j atoms */
639 qq00 = _mm_mul_ps(iq0,jq0);
641 /* EWALD ELECTROSTATICS */
643 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
644 ewrt = _mm_mul_ps(r00,ewtabscale);
645 ewitab = _mm_cvttps_epi32(ewrt);
646 eweps = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
647 gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
648 ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
650 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
651 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
653 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
657 fscal = _mm_and_ps(fscal,cutoff_mask);
659 fscal = _mm_andnot_ps(dummy_mask,fscal);
661 /* Calculate temporary vectorial force */
662 tx = _mm_mul_ps(fscal,dx00);
663 ty = _mm_mul_ps(fscal,dy00);
664 tz = _mm_mul_ps(fscal,dz00);
666 /* Update vectorial force */
667 fix0 = _mm_add_ps(fix0,tx);
668 fiy0 = _mm_add_ps(fiy0,ty);
669 fiz0 = _mm_add_ps(fiz0,tz);
671 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
672 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
673 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
674 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
675 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
679 /* Inner loop uses 40 flops */
682 /* End of innermost loop */
684 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
685 f+i_coord_offset,fshift+i_shift_offset);
687 /* Increment number of inner iterations */
688 inneriter += j_index_end - j_index_start;
690 /* Outer loop uses 7 flops */
693 /* Increment number of outer iterations */
696 /* Update outer/inner flops */
698 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*40);