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 sse4_1_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_sse4_1_single.h"
48 #include "kernelutil_x86_sse4_1_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomP1P1_VF_sse4_1_single
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_VF_sse4_1_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
91 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
93 __m128 dummy_mask,cutoff_mask;
94 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
95 __m128 one = _mm_set1_ps(1.0);
96 __m128 two = _mm_set1_ps(2.0);
102 jindex = nlist->jindex;
104 shiftidx = nlist->shift;
106 shiftvec = fr->shift_vec[0];
107 fshift = fr->fshift[0];
108 facel = _mm_set1_ps(fr->epsfac);
109 charge = mdatoms->chargeA;
111 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
112 ewtab = fr->ic->tabq_coul_FDV0;
113 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
114 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
116 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
117 rcutoff_scalar = fr->rcoulomb;
118 rcutoff = _mm_set1_ps(rcutoff_scalar);
119 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
121 /* Avoid stupid compiler warnings */
122 jnrA = jnrB = jnrC = jnrD = 0;
131 for(iidx=0;iidx<4*DIM;iidx++)
136 /* Start outer loop over neighborlists */
137 for(iidx=0; iidx<nri; iidx++)
139 /* Load shift vector for this list */
140 i_shift_offset = DIM*shiftidx[iidx];
142 /* Load limits for loop over neighbors */
143 j_index_start = jindex[iidx];
144 j_index_end = jindex[iidx+1];
146 /* Get outer coordinate index */
148 i_coord_offset = DIM*inr;
150 /* Load i particle coords and add shift vector */
151 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
153 fix0 = _mm_setzero_ps();
154 fiy0 = _mm_setzero_ps();
155 fiz0 = _mm_setzero_ps();
157 /* Load parameters for i particles */
158 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
160 /* Reset potential sums */
161 velecsum = _mm_setzero_ps();
163 /* Start inner kernel loop */
164 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
167 /* Get j neighbor index, and coordinate index */
172 j_coord_offsetA = DIM*jnrA;
173 j_coord_offsetB = DIM*jnrB;
174 j_coord_offsetC = DIM*jnrC;
175 j_coord_offsetD = DIM*jnrD;
177 /* load j atom coordinates */
178 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
179 x+j_coord_offsetC,x+j_coord_offsetD,
182 /* Calculate displacement vector */
183 dx00 = _mm_sub_ps(ix0,jx0);
184 dy00 = _mm_sub_ps(iy0,jy0);
185 dz00 = _mm_sub_ps(iz0,jz0);
187 /* Calculate squared distance and things based on it */
188 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
190 rinv00 = gmx_mm_invsqrt_ps(rsq00);
192 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
194 /* Load parameters for j particles */
195 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
196 charge+jnrC+0,charge+jnrD+0);
198 /**************************
199 * CALCULATE INTERACTIONS *
200 **************************/
202 if (gmx_mm_any_lt(rsq00,rcutoff2))
205 r00 = _mm_mul_ps(rsq00,rinv00);
207 /* Compute parameters for interactions between i and j atoms */
208 qq00 = _mm_mul_ps(iq0,jq0);
210 /* EWALD ELECTROSTATICS */
212 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
213 ewrt = _mm_mul_ps(r00,ewtabscale);
214 ewitab = _mm_cvttps_epi32(ewrt);
215 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
216 ewitab = _mm_slli_epi32(ewitab,2);
217 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
218 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
219 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
220 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
221 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
222 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
223 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
224 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_sub_ps(rinv00,sh_ewald),velec));
225 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
227 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
229 /* Update potential sum for this i atom from the interaction with this j atom. */
230 velec = _mm_and_ps(velec,cutoff_mask);
231 velecsum = _mm_add_ps(velecsum,velec);
235 fscal = _mm_and_ps(fscal,cutoff_mask);
237 /* Calculate temporary vectorial force */
238 tx = _mm_mul_ps(fscal,dx00);
239 ty = _mm_mul_ps(fscal,dy00);
240 tz = _mm_mul_ps(fscal,dz00);
242 /* Update vectorial force */
243 fix0 = _mm_add_ps(fix0,tx);
244 fiy0 = _mm_add_ps(fiy0,ty);
245 fiz0 = _mm_add_ps(fiz0,tz);
247 fjptrA = f+j_coord_offsetA;
248 fjptrB = f+j_coord_offsetB;
249 fjptrC = f+j_coord_offsetC;
250 fjptrD = f+j_coord_offsetD;
251 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
255 /* Inner loop uses 46 flops */
261 /* Get j neighbor index, and coordinate index */
262 jnrlistA = jjnr[jidx];
263 jnrlistB = jjnr[jidx+1];
264 jnrlistC = jjnr[jidx+2];
265 jnrlistD = jjnr[jidx+3];
266 /* Sign of each element will be negative for non-real atoms.
267 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
268 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
270 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
271 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
272 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
273 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
274 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
275 j_coord_offsetA = DIM*jnrA;
276 j_coord_offsetB = DIM*jnrB;
277 j_coord_offsetC = DIM*jnrC;
278 j_coord_offsetD = DIM*jnrD;
280 /* load j atom coordinates */
281 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
282 x+j_coord_offsetC,x+j_coord_offsetD,
285 /* Calculate displacement vector */
286 dx00 = _mm_sub_ps(ix0,jx0);
287 dy00 = _mm_sub_ps(iy0,jy0);
288 dz00 = _mm_sub_ps(iz0,jz0);
290 /* Calculate squared distance and things based on it */
291 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
293 rinv00 = gmx_mm_invsqrt_ps(rsq00);
295 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
297 /* Load parameters for j particles */
298 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
299 charge+jnrC+0,charge+jnrD+0);
301 /**************************
302 * CALCULATE INTERACTIONS *
303 **************************/
305 if (gmx_mm_any_lt(rsq00,rcutoff2))
308 r00 = _mm_mul_ps(rsq00,rinv00);
309 r00 = _mm_andnot_ps(dummy_mask,r00);
311 /* Compute parameters for interactions between i and j atoms */
312 qq00 = _mm_mul_ps(iq0,jq0);
314 /* EWALD ELECTROSTATICS */
316 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
317 ewrt = _mm_mul_ps(r00,ewtabscale);
318 ewitab = _mm_cvttps_epi32(ewrt);
319 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
320 ewitab = _mm_slli_epi32(ewitab,2);
321 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
322 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
323 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
324 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
325 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
326 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
327 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
328 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_sub_ps(rinv00,sh_ewald),velec));
329 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
331 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
333 /* Update potential sum for this i atom from the interaction with this j atom. */
334 velec = _mm_and_ps(velec,cutoff_mask);
335 velec = _mm_andnot_ps(dummy_mask,velec);
336 velecsum = _mm_add_ps(velecsum,velec);
340 fscal = _mm_and_ps(fscal,cutoff_mask);
342 fscal = _mm_andnot_ps(dummy_mask,fscal);
344 /* Calculate temporary vectorial force */
345 tx = _mm_mul_ps(fscal,dx00);
346 ty = _mm_mul_ps(fscal,dy00);
347 tz = _mm_mul_ps(fscal,dz00);
349 /* Update vectorial force */
350 fix0 = _mm_add_ps(fix0,tx);
351 fiy0 = _mm_add_ps(fiy0,ty);
352 fiz0 = _mm_add_ps(fiz0,tz);
354 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
355 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
356 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
357 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
358 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
362 /* Inner loop uses 47 flops */
365 /* End of innermost loop */
367 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
368 f+i_coord_offset,fshift+i_shift_offset);
371 /* Update potential energies */
372 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
374 /* Increment number of inner iterations */
375 inneriter += j_index_end - j_index_start;
377 /* Outer loop uses 8 flops */
380 /* Increment number of outer iterations */
383 /* Update outer/inner flops */
385 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*47);
388 * Gromacs nonbonded kernel: nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_sse4_1_single
389 * Electrostatics interaction: Ewald
390 * VdW interaction: None
391 * Geometry: Particle-Particle
392 * Calculate force/pot: Force
395 nb_kernel_ElecEwSh_VdwNone_GeomP1P1_F_sse4_1_single
396 (t_nblist * gmx_restrict nlist,
397 rvec * gmx_restrict xx,
398 rvec * gmx_restrict ff,
399 t_forcerec * gmx_restrict fr,
400 t_mdatoms * gmx_restrict mdatoms,
401 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
402 t_nrnb * gmx_restrict nrnb)
404 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
405 * just 0 for non-waters.
406 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
407 * jnr indices corresponding to data put in the four positions in the SIMD register.
409 int i_shift_offset,i_coord_offset,outeriter,inneriter;
410 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
411 int jnrA,jnrB,jnrC,jnrD;
412 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
413 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
414 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
416 real *shiftvec,*fshift,*x,*f;
417 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
419 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
421 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
422 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
423 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
424 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
425 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
428 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
430 __m128 dummy_mask,cutoff_mask;
431 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
432 __m128 one = _mm_set1_ps(1.0);
433 __m128 two = _mm_set1_ps(2.0);
439 jindex = nlist->jindex;
441 shiftidx = nlist->shift;
443 shiftvec = fr->shift_vec[0];
444 fshift = fr->fshift[0];
445 facel = _mm_set1_ps(fr->epsfac);
446 charge = mdatoms->chargeA;
448 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
449 ewtab = fr->ic->tabq_coul_F;
450 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
451 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
453 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
454 rcutoff_scalar = fr->rcoulomb;
455 rcutoff = _mm_set1_ps(rcutoff_scalar);
456 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
458 /* Avoid stupid compiler warnings */
459 jnrA = jnrB = jnrC = jnrD = 0;
468 for(iidx=0;iidx<4*DIM;iidx++)
473 /* Start outer loop over neighborlists */
474 for(iidx=0; iidx<nri; iidx++)
476 /* Load shift vector for this list */
477 i_shift_offset = DIM*shiftidx[iidx];
479 /* Load limits for loop over neighbors */
480 j_index_start = jindex[iidx];
481 j_index_end = jindex[iidx+1];
483 /* Get outer coordinate index */
485 i_coord_offset = DIM*inr;
487 /* Load i particle coords and add shift vector */
488 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
490 fix0 = _mm_setzero_ps();
491 fiy0 = _mm_setzero_ps();
492 fiz0 = _mm_setzero_ps();
494 /* Load parameters for i particles */
495 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
497 /* Start inner kernel loop */
498 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
501 /* Get j neighbor index, and coordinate index */
506 j_coord_offsetA = DIM*jnrA;
507 j_coord_offsetB = DIM*jnrB;
508 j_coord_offsetC = DIM*jnrC;
509 j_coord_offsetD = DIM*jnrD;
511 /* load j atom coordinates */
512 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
513 x+j_coord_offsetC,x+j_coord_offsetD,
516 /* Calculate displacement vector */
517 dx00 = _mm_sub_ps(ix0,jx0);
518 dy00 = _mm_sub_ps(iy0,jy0);
519 dz00 = _mm_sub_ps(iz0,jz0);
521 /* Calculate squared distance and things based on it */
522 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
524 rinv00 = gmx_mm_invsqrt_ps(rsq00);
526 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
528 /* Load parameters for j particles */
529 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
530 charge+jnrC+0,charge+jnrD+0);
532 /**************************
533 * CALCULATE INTERACTIONS *
534 **************************/
536 if (gmx_mm_any_lt(rsq00,rcutoff2))
539 r00 = _mm_mul_ps(rsq00,rinv00);
541 /* Compute parameters for interactions between i and j atoms */
542 qq00 = _mm_mul_ps(iq0,jq0);
544 /* EWALD ELECTROSTATICS */
546 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
547 ewrt = _mm_mul_ps(r00,ewtabscale);
548 ewitab = _mm_cvttps_epi32(ewrt);
549 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
550 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
551 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
553 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
554 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
556 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
560 fscal = _mm_and_ps(fscal,cutoff_mask);
562 /* Calculate temporary vectorial force */
563 tx = _mm_mul_ps(fscal,dx00);
564 ty = _mm_mul_ps(fscal,dy00);
565 tz = _mm_mul_ps(fscal,dz00);
567 /* Update vectorial force */
568 fix0 = _mm_add_ps(fix0,tx);
569 fiy0 = _mm_add_ps(fiy0,ty);
570 fiz0 = _mm_add_ps(fiz0,tz);
572 fjptrA = f+j_coord_offsetA;
573 fjptrB = f+j_coord_offsetB;
574 fjptrC = f+j_coord_offsetC;
575 fjptrD = f+j_coord_offsetD;
576 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
580 /* Inner loop uses 39 flops */
586 /* Get j neighbor index, and coordinate index */
587 jnrlistA = jjnr[jidx];
588 jnrlistB = jjnr[jidx+1];
589 jnrlistC = jjnr[jidx+2];
590 jnrlistD = jjnr[jidx+3];
591 /* Sign of each element will be negative for non-real atoms.
592 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
593 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
595 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
596 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
597 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
598 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
599 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
600 j_coord_offsetA = DIM*jnrA;
601 j_coord_offsetB = DIM*jnrB;
602 j_coord_offsetC = DIM*jnrC;
603 j_coord_offsetD = DIM*jnrD;
605 /* load j atom coordinates */
606 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
607 x+j_coord_offsetC,x+j_coord_offsetD,
610 /* Calculate displacement vector */
611 dx00 = _mm_sub_ps(ix0,jx0);
612 dy00 = _mm_sub_ps(iy0,jy0);
613 dz00 = _mm_sub_ps(iz0,jz0);
615 /* Calculate squared distance and things based on it */
616 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
618 rinv00 = gmx_mm_invsqrt_ps(rsq00);
620 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
622 /* Load parameters for j particles */
623 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
624 charge+jnrC+0,charge+jnrD+0);
626 /**************************
627 * CALCULATE INTERACTIONS *
628 **************************/
630 if (gmx_mm_any_lt(rsq00,rcutoff2))
633 r00 = _mm_mul_ps(rsq00,rinv00);
634 r00 = _mm_andnot_ps(dummy_mask,r00);
636 /* Compute parameters for interactions between i and j atoms */
637 qq00 = _mm_mul_ps(iq0,jq0);
639 /* EWALD ELECTROSTATICS */
641 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
642 ewrt = _mm_mul_ps(r00,ewtabscale);
643 ewitab = _mm_cvttps_epi32(ewrt);
644 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
645 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
646 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
648 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
649 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
651 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
655 fscal = _mm_and_ps(fscal,cutoff_mask);
657 fscal = _mm_andnot_ps(dummy_mask,fscal);
659 /* Calculate temporary vectorial force */
660 tx = _mm_mul_ps(fscal,dx00);
661 ty = _mm_mul_ps(fscal,dy00);
662 tz = _mm_mul_ps(fscal,dz00);
664 /* Update vectorial force */
665 fix0 = _mm_add_ps(fix0,tx);
666 fiy0 = _mm_add_ps(fiy0,ty);
667 fiz0 = _mm_add_ps(fiz0,tz);
669 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
670 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
671 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
672 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
673 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
677 /* Inner loop uses 40 flops */
680 /* End of innermost loop */
682 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
683 f+i_coord_offset,fshift+i_shift_offset);
685 /* Increment number of inner iterations */
686 inneriter += j_index_end - j_index_start;
688 /* Outer loop uses 7 flops */
691 /* Increment number of outer iterations */
694 /* Update outer/inner flops */
696 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*40);