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_double kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_sse2_double.h"
48 #include "kernelutil_x86_sse2_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwNone_GeomP1P1_VF_sse2_double
52 * Electrostatics interaction: Ewald
53 * VdW interaction: None
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecEwSw_VdwNone_GeomP1P1_VF_sse2_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82 int vdwjidx0A,vdwjidx0B;
83 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
85 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
88 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
90 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
91 real rswitch_scalar,d_scalar;
92 __m128d dummy_mask,cutoff_mask;
93 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
94 __m128d one = _mm_set1_pd(1.0);
95 __m128d two = _mm_set1_pd(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_pd(fr->epsfac);
108 charge = mdatoms->chargeA;
110 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
111 ewtab = fr->ic->tabq_coul_FDV0;
112 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
113 ewtabhalfspace = _mm_set1_pd(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->rcoulomb;
117 rcutoff = _mm_set1_pd(rcutoff_scalar);
118 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
120 rswitch_scalar = fr->rcoulomb_switch;
121 rswitch = _mm_set1_pd(rswitch_scalar);
122 /* Setup switch parameters */
123 d_scalar = rcutoff_scalar-rswitch_scalar;
124 d = _mm_set1_pd(d_scalar);
125 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
126 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
127 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
128 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
129 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
130 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
132 /* Avoid stupid compiler warnings */
140 /* Start outer loop over neighborlists */
141 for(iidx=0; iidx<nri; iidx++)
143 /* Load shift vector for this list */
144 i_shift_offset = DIM*shiftidx[iidx];
146 /* Load limits for loop over neighbors */
147 j_index_start = jindex[iidx];
148 j_index_end = jindex[iidx+1];
150 /* Get outer coordinate index */
152 i_coord_offset = DIM*inr;
154 /* Load i particle coords and add shift vector */
155 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
157 fix0 = _mm_setzero_pd();
158 fiy0 = _mm_setzero_pd();
159 fiz0 = _mm_setzero_pd();
161 /* Load parameters for i particles */
162 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
164 /* Reset potential sums */
165 velecsum = _mm_setzero_pd();
167 /* Start inner kernel loop */
168 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
171 /* Get j neighbor index, and coordinate index */
174 j_coord_offsetA = DIM*jnrA;
175 j_coord_offsetB = DIM*jnrB;
177 /* load j atom coordinates */
178 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
181 /* Calculate displacement vector */
182 dx00 = _mm_sub_pd(ix0,jx0);
183 dy00 = _mm_sub_pd(iy0,jy0);
184 dz00 = _mm_sub_pd(iz0,jz0);
186 /* Calculate squared distance and things based on it */
187 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
189 rinv00 = gmx_mm_invsqrt_pd(rsq00);
191 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
193 /* Load parameters for j particles */
194 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
196 /**************************
197 * CALCULATE INTERACTIONS *
198 **************************/
200 if (gmx_mm_any_lt(rsq00,rcutoff2))
203 r00 = _mm_mul_pd(rsq00,rinv00);
205 /* Compute parameters for interactions between i and j atoms */
206 qq00 = _mm_mul_pd(iq0,jq0);
208 /* EWALD ELECTROSTATICS */
210 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
211 ewrt = _mm_mul_pd(r00,ewtabscale);
212 ewitab = _mm_cvttpd_epi32(ewrt);
213 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
214 ewitab = _mm_slli_epi32(ewitab,2);
215 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
216 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
217 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
218 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
219 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
220 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
221 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
222 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
223 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
224 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
226 d = _mm_sub_pd(r00,rswitch);
227 d = _mm_max_pd(d,_mm_setzero_pd());
228 d2 = _mm_mul_pd(d,d);
229 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_add_pd(swV3,_mm_mul_pd(d,_mm_add_pd(swV4,_mm_mul_pd(d,swV5)))))));
231 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
233 /* Evaluate switch function */
234 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
235 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
236 velec = _mm_mul_pd(velec,sw);
237 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
239 /* Update potential sum for this i atom from the interaction with this j atom. */
240 velec = _mm_and_pd(velec,cutoff_mask);
241 velecsum = _mm_add_pd(velecsum,velec);
245 fscal = _mm_and_pd(fscal,cutoff_mask);
247 /* Calculate temporary vectorial force */
248 tx = _mm_mul_pd(fscal,dx00);
249 ty = _mm_mul_pd(fscal,dy00);
250 tz = _mm_mul_pd(fscal,dz00);
252 /* Update vectorial force */
253 fix0 = _mm_add_pd(fix0,tx);
254 fiy0 = _mm_add_pd(fiy0,ty);
255 fiz0 = _mm_add_pd(fiz0,tz);
257 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
261 /* Inner loop uses 65 flops */
268 j_coord_offsetA = DIM*jnrA;
270 /* load j atom coordinates */
271 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
274 /* Calculate displacement vector */
275 dx00 = _mm_sub_pd(ix0,jx0);
276 dy00 = _mm_sub_pd(iy0,jy0);
277 dz00 = _mm_sub_pd(iz0,jz0);
279 /* Calculate squared distance and things based on it */
280 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
282 rinv00 = gmx_mm_invsqrt_pd(rsq00);
284 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
286 /* Load parameters for j particles */
287 jq0 = _mm_load_sd(charge+jnrA+0);
289 /**************************
290 * CALCULATE INTERACTIONS *
291 **************************/
293 if (gmx_mm_any_lt(rsq00,rcutoff2))
296 r00 = _mm_mul_pd(rsq00,rinv00);
298 /* Compute parameters for interactions between i and j atoms */
299 qq00 = _mm_mul_pd(iq0,jq0);
301 /* EWALD ELECTROSTATICS */
303 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
304 ewrt = _mm_mul_pd(r00,ewtabscale);
305 ewitab = _mm_cvttpd_epi32(ewrt);
306 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
307 ewitab = _mm_slli_epi32(ewitab,2);
308 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
309 ewtabD = _mm_setzero_pd();
310 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
311 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
312 ewtabFn = _mm_setzero_pd();
313 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
314 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
315 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
316 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
317 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
319 d = _mm_sub_pd(r00,rswitch);
320 d = _mm_max_pd(d,_mm_setzero_pd());
321 d2 = _mm_mul_pd(d,d);
322 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_add_pd(swV3,_mm_mul_pd(d,_mm_add_pd(swV4,_mm_mul_pd(d,swV5)))))));
324 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
326 /* Evaluate switch function */
327 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
328 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
329 velec = _mm_mul_pd(velec,sw);
330 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
332 /* Update potential sum for this i atom from the interaction with this j atom. */
333 velec = _mm_and_pd(velec,cutoff_mask);
334 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
335 velecsum = _mm_add_pd(velecsum,velec);
339 fscal = _mm_and_pd(fscal,cutoff_mask);
341 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
343 /* Calculate temporary vectorial force */
344 tx = _mm_mul_pd(fscal,dx00);
345 ty = _mm_mul_pd(fscal,dy00);
346 tz = _mm_mul_pd(fscal,dz00);
348 /* Update vectorial force */
349 fix0 = _mm_add_pd(fix0,tx);
350 fiy0 = _mm_add_pd(fiy0,ty);
351 fiz0 = _mm_add_pd(fiz0,tz);
353 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
357 /* Inner loop uses 65 flops */
360 /* End of innermost loop */
362 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
363 f+i_coord_offset,fshift+i_shift_offset);
366 /* Update potential energies */
367 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
369 /* Increment number of inner iterations */
370 inneriter += j_index_end - j_index_start;
372 /* Outer loop uses 8 flops */
375 /* Increment number of outer iterations */
378 /* Update outer/inner flops */
380 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*65);
383 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_sse2_double
384 * Electrostatics interaction: Ewald
385 * VdW interaction: None
386 * Geometry: Particle-Particle
387 * Calculate force/pot: Force
390 nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_sse2_double
391 (t_nblist * gmx_restrict nlist,
392 rvec * gmx_restrict xx,
393 rvec * gmx_restrict ff,
394 t_forcerec * gmx_restrict fr,
395 t_mdatoms * gmx_restrict mdatoms,
396 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
397 t_nrnb * gmx_restrict nrnb)
399 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
400 * just 0 for non-waters.
401 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
402 * jnr indices corresponding to data put in the four positions in the SIMD register.
404 int i_shift_offset,i_coord_offset,outeriter,inneriter;
405 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
407 int j_coord_offsetA,j_coord_offsetB;
408 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
410 real *shiftvec,*fshift,*x,*f;
411 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
413 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
414 int vdwjidx0A,vdwjidx0B;
415 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
416 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
417 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
420 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
422 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
423 real rswitch_scalar,d_scalar;
424 __m128d dummy_mask,cutoff_mask;
425 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
426 __m128d one = _mm_set1_pd(1.0);
427 __m128d two = _mm_set1_pd(2.0);
433 jindex = nlist->jindex;
435 shiftidx = nlist->shift;
437 shiftvec = fr->shift_vec[0];
438 fshift = fr->fshift[0];
439 facel = _mm_set1_pd(fr->epsfac);
440 charge = mdatoms->chargeA;
442 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
443 ewtab = fr->ic->tabq_coul_FDV0;
444 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
445 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
447 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
448 rcutoff_scalar = fr->rcoulomb;
449 rcutoff = _mm_set1_pd(rcutoff_scalar);
450 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
452 rswitch_scalar = fr->rcoulomb_switch;
453 rswitch = _mm_set1_pd(rswitch_scalar);
454 /* Setup switch parameters */
455 d_scalar = rcutoff_scalar-rswitch_scalar;
456 d = _mm_set1_pd(d_scalar);
457 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
458 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
459 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
460 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
461 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
462 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
464 /* Avoid stupid compiler warnings */
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_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
489 fix0 = _mm_setzero_pd();
490 fiy0 = _mm_setzero_pd();
491 fiz0 = _mm_setzero_pd();
493 /* Load parameters for i particles */
494 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
496 /* Start inner kernel loop */
497 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
500 /* Get j neighbor index, and coordinate index */
503 j_coord_offsetA = DIM*jnrA;
504 j_coord_offsetB = DIM*jnrB;
506 /* load j atom coordinates */
507 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
510 /* Calculate displacement vector */
511 dx00 = _mm_sub_pd(ix0,jx0);
512 dy00 = _mm_sub_pd(iy0,jy0);
513 dz00 = _mm_sub_pd(iz0,jz0);
515 /* Calculate squared distance and things based on it */
516 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
518 rinv00 = gmx_mm_invsqrt_pd(rsq00);
520 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
522 /* Load parameters for j particles */
523 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
525 /**************************
526 * CALCULATE INTERACTIONS *
527 **************************/
529 if (gmx_mm_any_lt(rsq00,rcutoff2))
532 r00 = _mm_mul_pd(rsq00,rinv00);
534 /* Compute parameters for interactions between i and j atoms */
535 qq00 = _mm_mul_pd(iq0,jq0);
537 /* EWALD ELECTROSTATICS */
539 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
540 ewrt = _mm_mul_pd(r00,ewtabscale);
541 ewitab = _mm_cvttpd_epi32(ewrt);
542 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
543 ewitab = _mm_slli_epi32(ewitab,2);
544 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
545 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
546 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
547 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
548 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
549 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
550 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
551 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
552 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
553 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
555 d = _mm_sub_pd(r00,rswitch);
556 d = _mm_max_pd(d,_mm_setzero_pd());
557 d2 = _mm_mul_pd(d,d);
558 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_add_pd(swV3,_mm_mul_pd(d,_mm_add_pd(swV4,_mm_mul_pd(d,swV5)))))));
560 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
562 /* Evaluate switch function */
563 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
564 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
565 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
569 fscal = _mm_and_pd(fscal,cutoff_mask);
571 /* Calculate temporary vectorial force */
572 tx = _mm_mul_pd(fscal,dx00);
573 ty = _mm_mul_pd(fscal,dy00);
574 tz = _mm_mul_pd(fscal,dz00);
576 /* Update vectorial force */
577 fix0 = _mm_add_pd(fix0,tx);
578 fiy0 = _mm_add_pd(fiy0,ty);
579 fiz0 = _mm_add_pd(fiz0,tz);
581 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
585 /* Inner loop uses 62 flops */
592 j_coord_offsetA = DIM*jnrA;
594 /* load j atom coordinates */
595 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
598 /* Calculate displacement vector */
599 dx00 = _mm_sub_pd(ix0,jx0);
600 dy00 = _mm_sub_pd(iy0,jy0);
601 dz00 = _mm_sub_pd(iz0,jz0);
603 /* Calculate squared distance and things based on it */
604 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
606 rinv00 = gmx_mm_invsqrt_pd(rsq00);
608 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
610 /* Load parameters for j particles */
611 jq0 = _mm_load_sd(charge+jnrA+0);
613 /**************************
614 * CALCULATE INTERACTIONS *
615 **************************/
617 if (gmx_mm_any_lt(rsq00,rcutoff2))
620 r00 = _mm_mul_pd(rsq00,rinv00);
622 /* Compute parameters for interactions between i and j atoms */
623 qq00 = _mm_mul_pd(iq0,jq0);
625 /* EWALD ELECTROSTATICS */
627 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
628 ewrt = _mm_mul_pd(r00,ewtabscale);
629 ewitab = _mm_cvttpd_epi32(ewrt);
630 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
631 ewitab = _mm_slli_epi32(ewitab,2);
632 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
633 ewtabD = _mm_setzero_pd();
634 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
635 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
636 ewtabFn = _mm_setzero_pd();
637 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
638 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
639 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
640 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
641 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
643 d = _mm_sub_pd(r00,rswitch);
644 d = _mm_max_pd(d,_mm_setzero_pd());
645 d2 = _mm_mul_pd(d,d);
646 sw = _mm_add_pd(one,_mm_mul_pd(d2,_mm_mul_pd(d,_mm_add_pd(swV3,_mm_mul_pd(d,_mm_add_pd(swV4,_mm_mul_pd(d,swV5)))))));
648 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
650 /* Evaluate switch function */
651 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
652 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
653 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
657 fscal = _mm_and_pd(fscal,cutoff_mask);
659 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
661 /* Calculate temporary vectorial force */
662 tx = _mm_mul_pd(fscal,dx00);
663 ty = _mm_mul_pd(fscal,dy00);
664 tz = _mm_mul_pd(fscal,dz00);
666 /* Update vectorial force */
667 fix0 = _mm_add_pd(fix0,tx);
668 fiy0 = _mm_add_pd(fiy0,ty);
669 fiz0 = _mm_add_pd(fiz0,tz);
671 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
675 /* Inner loop uses 62 flops */
678 /* End of innermost loop */
680 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
681 f+i_coord_offset,fshift+i_shift_offset);
683 /* Increment number of inner iterations */
684 inneriter += j_index_end - j_index_start;
686 /* Outer loop uses 7 flops */
689 /* Increment number of outer iterations */
692 /* Update outer/inner flops */
694 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*62);