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_ElecEw_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_ElecEw_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 /* Avoid stupid compiler warnings */
117 jnrA = jnrB = jnrC = jnrD = 0;
126 for(iidx=0;iidx<4*DIM;iidx++)
131 /* Start outer loop over neighborlists */
132 for(iidx=0; iidx<nri; iidx++)
134 /* Load shift vector for this list */
135 i_shift_offset = DIM*shiftidx[iidx];
137 /* Load limits for loop over neighbors */
138 j_index_start = jindex[iidx];
139 j_index_end = jindex[iidx+1];
141 /* Get outer coordinate index */
143 i_coord_offset = DIM*inr;
145 /* Load i particle coords and add shift vector */
146 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
148 fix0 = _mm_setzero_ps();
149 fiy0 = _mm_setzero_ps();
150 fiz0 = _mm_setzero_ps();
152 /* Load parameters for i particles */
153 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
155 /* Reset potential sums */
156 velecsum = _mm_setzero_ps();
158 /* Start inner kernel loop */
159 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
162 /* Get j neighbor index, and coordinate index */
167 j_coord_offsetA = DIM*jnrA;
168 j_coord_offsetB = DIM*jnrB;
169 j_coord_offsetC = DIM*jnrC;
170 j_coord_offsetD = DIM*jnrD;
172 /* load j atom coordinates */
173 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
174 x+j_coord_offsetC,x+j_coord_offsetD,
177 /* Calculate displacement vector */
178 dx00 = _mm_sub_ps(ix0,jx0);
179 dy00 = _mm_sub_ps(iy0,jy0);
180 dz00 = _mm_sub_ps(iz0,jz0);
182 /* Calculate squared distance and things based on it */
183 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
185 rinv00 = gmx_mm_invsqrt_ps(rsq00);
187 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
189 /* Load parameters for j particles */
190 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
191 charge+jnrC+0,charge+jnrD+0);
193 /**************************
194 * CALCULATE INTERACTIONS *
195 **************************/
197 r00 = _mm_mul_ps(rsq00,rinv00);
199 /* Compute parameters for interactions between i and j atoms */
200 qq00 = _mm_mul_ps(iq0,jq0);
202 /* EWALD ELECTROSTATICS */
204 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
205 ewrt = _mm_mul_ps(r00,ewtabscale);
206 ewitab = _mm_cvttps_epi32(ewrt);
207 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
208 ewitab = _mm_slli_epi32(ewitab,2);
209 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
210 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
211 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
212 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
213 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
214 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
215 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
216 velec = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
217 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
219 /* Update potential sum for this i atom from the interaction with this j atom. */
220 velecsum = _mm_add_ps(velecsum,velec);
224 /* Calculate temporary vectorial force */
225 tx = _mm_mul_ps(fscal,dx00);
226 ty = _mm_mul_ps(fscal,dy00);
227 tz = _mm_mul_ps(fscal,dz00);
229 /* Update vectorial force */
230 fix0 = _mm_add_ps(fix0,tx);
231 fiy0 = _mm_add_ps(fiy0,ty);
232 fiz0 = _mm_add_ps(fiz0,tz);
234 fjptrA = f+j_coord_offsetA;
235 fjptrB = f+j_coord_offsetB;
236 fjptrC = f+j_coord_offsetC;
237 fjptrD = f+j_coord_offsetD;
238 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
240 /* Inner loop uses 41 flops */
246 /* Get j neighbor index, and coordinate index */
247 jnrlistA = jjnr[jidx];
248 jnrlistB = jjnr[jidx+1];
249 jnrlistC = jjnr[jidx+2];
250 jnrlistD = jjnr[jidx+3];
251 /* Sign of each element will be negative for non-real atoms.
252 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
253 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
255 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
256 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
257 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
258 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
259 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
260 j_coord_offsetA = DIM*jnrA;
261 j_coord_offsetB = DIM*jnrB;
262 j_coord_offsetC = DIM*jnrC;
263 j_coord_offsetD = DIM*jnrD;
265 /* load j atom coordinates */
266 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
267 x+j_coord_offsetC,x+j_coord_offsetD,
270 /* Calculate displacement vector */
271 dx00 = _mm_sub_ps(ix0,jx0);
272 dy00 = _mm_sub_ps(iy0,jy0);
273 dz00 = _mm_sub_ps(iz0,jz0);
275 /* Calculate squared distance and things based on it */
276 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
278 rinv00 = gmx_mm_invsqrt_ps(rsq00);
280 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
282 /* Load parameters for j particles */
283 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
284 charge+jnrC+0,charge+jnrD+0);
286 /**************************
287 * CALCULATE INTERACTIONS *
288 **************************/
290 r00 = _mm_mul_ps(rsq00,rinv00);
291 r00 = _mm_andnot_ps(dummy_mask,r00);
293 /* Compute parameters for interactions between i and j atoms */
294 qq00 = _mm_mul_ps(iq0,jq0);
296 /* EWALD ELECTROSTATICS */
298 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
299 ewrt = _mm_mul_ps(r00,ewtabscale);
300 ewitab = _mm_cvttps_epi32(ewrt);
301 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
302 ewitab = _mm_slli_epi32(ewitab,2);
303 ewtabF = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
304 ewtabD = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
305 ewtabV = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
306 ewtabFn = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
307 _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
308 felec = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
309 velec = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
310 velec = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
311 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
313 /* Update potential sum for this i atom from the interaction with this j atom. */
314 velec = _mm_andnot_ps(dummy_mask,velec);
315 velecsum = _mm_add_ps(velecsum,velec);
319 fscal = _mm_andnot_ps(dummy_mask,fscal);
321 /* Calculate temporary vectorial force */
322 tx = _mm_mul_ps(fscal,dx00);
323 ty = _mm_mul_ps(fscal,dy00);
324 tz = _mm_mul_ps(fscal,dz00);
326 /* Update vectorial force */
327 fix0 = _mm_add_ps(fix0,tx);
328 fiy0 = _mm_add_ps(fiy0,ty);
329 fiz0 = _mm_add_ps(fiz0,tz);
331 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
332 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
333 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
334 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
335 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
337 /* Inner loop uses 42 flops */
340 /* End of innermost loop */
342 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
343 f+i_coord_offset,fshift+i_shift_offset);
346 /* Update potential energies */
347 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
349 /* Increment number of inner iterations */
350 inneriter += j_index_end - j_index_start;
352 /* Outer loop uses 8 flops */
355 /* Increment number of outer iterations */
358 /* Update outer/inner flops */
360 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*42);
363 * Gromacs nonbonded kernel: nb_kernel_ElecEw_VdwNone_GeomP1P1_F_sse4_1_single
364 * Electrostatics interaction: Ewald
365 * VdW interaction: None
366 * Geometry: Particle-Particle
367 * Calculate force/pot: Force
370 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_sse4_1_single
371 (t_nblist * gmx_restrict nlist,
372 rvec * gmx_restrict xx,
373 rvec * gmx_restrict ff,
374 t_forcerec * gmx_restrict fr,
375 t_mdatoms * gmx_restrict mdatoms,
376 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
377 t_nrnb * gmx_restrict nrnb)
379 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
380 * just 0 for non-waters.
381 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
382 * jnr indices corresponding to data put in the four positions in the SIMD register.
384 int i_shift_offset,i_coord_offset,outeriter,inneriter;
385 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
386 int jnrA,jnrB,jnrC,jnrD;
387 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
388 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
389 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
391 real *shiftvec,*fshift,*x,*f;
392 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
394 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
396 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
397 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
398 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
399 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
400 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
403 __m128 ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
405 __m128 dummy_mask,cutoff_mask;
406 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
407 __m128 one = _mm_set1_ps(1.0);
408 __m128 two = _mm_set1_ps(2.0);
414 jindex = nlist->jindex;
416 shiftidx = nlist->shift;
418 shiftvec = fr->shift_vec[0];
419 fshift = fr->fshift[0];
420 facel = _mm_set1_ps(fr->epsfac);
421 charge = mdatoms->chargeA;
423 sh_ewald = _mm_set1_ps(fr->ic->sh_ewald);
424 ewtab = fr->ic->tabq_coul_F;
425 ewtabscale = _mm_set1_ps(fr->ic->tabq_scale);
426 ewtabhalfspace = _mm_set1_ps(0.5/fr->ic->tabq_scale);
428 /* Avoid stupid compiler warnings */
429 jnrA = jnrB = jnrC = jnrD = 0;
438 for(iidx=0;iidx<4*DIM;iidx++)
443 /* Start outer loop over neighborlists */
444 for(iidx=0; iidx<nri; iidx++)
446 /* Load shift vector for this list */
447 i_shift_offset = DIM*shiftidx[iidx];
449 /* Load limits for loop over neighbors */
450 j_index_start = jindex[iidx];
451 j_index_end = jindex[iidx+1];
453 /* Get outer coordinate index */
455 i_coord_offset = DIM*inr;
457 /* Load i particle coords and add shift vector */
458 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
460 fix0 = _mm_setzero_ps();
461 fiy0 = _mm_setzero_ps();
462 fiz0 = _mm_setzero_ps();
464 /* Load parameters for i particles */
465 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
467 /* Start inner kernel loop */
468 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
471 /* Get j neighbor index, and coordinate index */
476 j_coord_offsetA = DIM*jnrA;
477 j_coord_offsetB = DIM*jnrB;
478 j_coord_offsetC = DIM*jnrC;
479 j_coord_offsetD = DIM*jnrD;
481 /* load j atom coordinates */
482 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
483 x+j_coord_offsetC,x+j_coord_offsetD,
486 /* Calculate displacement vector */
487 dx00 = _mm_sub_ps(ix0,jx0);
488 dy00 = _mm_sub_ps(iy0,jy0);
489 dz00 = _mm_sub_ps(iz0,jz0);
491 /* Calculate squared distance and things based on it */
492 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
494 rinv00 = gmx_mm_invsqrt_ps(rsq00);
496 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
498 /* Load parameters for j particles */
499 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
500 charge+jnrC+0,charge+jnrD+0);
502 /**************************
503 * CALCULATE INTERACTIONS *
504 **************************/
506 r00 = _mm_mul_ps(rsq00,rinv00);
508 /* Compute parameters for interactions between i and j atoms */
509 qq00 = _mm_mul_ps(iq0,jq0);
511 /* EWALD ELECTROSTATICS */
513 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
514 ewrt = _mm_mul_ps(r00,ewtabscale);
515 ewitab = _mm_cvttps_epi32(ewrt);
516 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
517 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
518 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
520 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
521 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
525 /* Calculate temporary vectorial force */
526 tx = _mm_mul_ps(fscal,dx00);
527 ty = _mm_mul_ps(fscal,dy00);
528 tz = _mm_mul_ps(fscal,dz00);
530 /* Update vectorial force */
531 fix0 = _mm_add_ps(fix0,tx);
532 fiy0 = _mm_add_ps(fiy0,ty);
533 fiz0 = _mm_add_ps(fiz0,tz);
535 fjptrA = f+j_coord_offsetA;
536 fjptrB = f+j_coord_offsetB;
537 fjptrC = f+j_coord_offsetC;
538 fjptrD = f+j_coord_offsetD;
539 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
541 /* Inner loop uses 36 flops */
547 /* Get j neighbor index, and coordinate index */
548 jnrlistA = jjnr[jidx];
549 jnrlistB = jjnr[jidx+1];
550 jnrlistC = jjnr[jidx+2];
551 jnrlistD = jjnr[jidx+3];
552 /* Sign of each element will be negative for non-real atoms.
553 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
554 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
556 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
557 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
558 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
559 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
560 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
561 j_coord_offsetA = DIM*jnrA;
562 j_coord_offsetB = DIM*jnrB;
563 j_coord_offsetC = DIM*jnrC;
564 j_coord_offsetD = DIM*jnrD;
566 /* load j atom coordinates */
567 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
568 x+j_coord_offsetC,x+j_coord_offsetD,
571 /* Calculate displacement vector */
572 dx00 = _mm_sub_ps(ix0,jx0);
573 dy00 = _mm_sub_ps(iy0,jy0);
574 dz00 = _mm_sub_ps(iz0,jz0);
576 /* Calculate squared distance and things based on it */
577 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
579 rinv00 = gmx_mm_invsqrt_ps(rsq00);
581 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
583 /* Load parameters for j particles */
584 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
585 charge+jnrC+0,charge+jnrD+0);
587 /**************************
588 * CALCULATE INTERACTIONS *
589 **************************/
591 r00 = _mm_mul_ps(rsq00,rinv00);
592 r00 = _mm_andnot_ps(dummy_mask,r00);
594 /* Compute parameters for interactions between i and j atoms */
595 qq00 = _mm_mul_ps(iq0,jq0);
597 /* EWALD ELECTROSTATICS */
599 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
600 ewrt = _mm_mul_ps(r00,ewtabscale);
601 ewitab = _mm_cvttps_epi32(ewrt);
602 eweps = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
603 gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
604 ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
606 felec = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
607 felec = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
611 fscal = _mm_andnot_ps(dummy_mask,fscal);
613 /* Calculate temporary vectorial force */
614 tx = _mm_mul_ps(fscal,dx00);
615 ty = _mm_mul_ps(fscal,dy00);
616 tz = _mm_mul_ps(fscal,dz00);
618 /* Update vectorial force */
619 fix0 = _mm_add_ps(fix0,tx);
620 fiy0 = _mm_add_ps(fiy0,ty);
621 fiz0 = _mm_add_ps(fiz0,tz);
623 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
624 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
625 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
626 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
627 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
629 /* Inner loop uses 37 flops */
632 /* End of innermost loop */
634 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
635 f+i_coord_offset,fshift+i_shift_offset);
637 /* Increment number of inner iterations */
638 inneriter += j_index_end - j_index_start;
640 /* Outer loop uses 7 flops */
643 /* Increment number of outer iterations */
646 /* Update outer/inner flops */
648 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*37);