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.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_sse2_double.h"
50 #include "kernelutil_x86_sse2_double.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwNone_GeomP1P1_VF_sse2_double
54 * Electrostatics interaction: Ewald
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecEwSw_VdwNone_GeomP1P1_VF_sse2_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
77 int j_coord_offsetA,j_coord_offsetB;
78 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
80 real *shiftvec,*fshift,*x,*f;
81 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
83 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84 int vdwjidx0A,vdwjidx0B;
85 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
86 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
87 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
90 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
92 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
93 real rswitch_scalar,d_scalar;
94 __m128d dummy_mask,cutoff_mask;
95 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
96 __m128d one = _mm_set1_pd(1.0);
97 __m128d two = _mm_set1_pd(2.0);
103 jindex = nlist->jindex;
105 shiftidx = nlist->shift;
107 shiftvec = fr->shift_vec[0];
108 fshift = fr->fshift[0];
109 facel = _mm_set1_pd(fr->epsfac);
110 charge = mdatoms->chargeA;
112 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
113 ewtab = fr->ic->tabq_coul_FDV0;
114 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
115 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
117 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
118 rcutoff_scalar = fr->rcoulomb;
119 rcutoff = _mm_set1_pd(rcutoff_scalar);
120 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
122 rswitch_scalar = fr->rcoulomb_switch;
123 rswitch = _mm_set1_pd(rswitch_scalar);
124 /* Setup switch parameters */
125 d_scalar = rcutoff_scalar-rswitch_scalar;
126 d = _mm_set1_pd(d_scalar);
127 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
128 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
129 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
130 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
131 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
132 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
134 /* Avoid stupid compiler warnings */
142 /* Start outer loop over neighborlists */
143 for(iidx=0; iidx<nri; iidx++)
145 /* Load shift vector for this list */
146 i_shift_offset = DIM*shiftidx[iidx];
148 /* Load limits for loop over neighbors */
149 j_index_start = jindex[iidx];
150 j_index_end = jindex[iidx+1];
152 /* Get outer coordinate index */
154 i_coord_offset = DIM*inr;
156 /* Load i particle coords and add shift vector */
157 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
159 fix0 = _mm_setzero_pd();
160 fiy0 = _mm_setzero_pd();
161 fiz0 = _mm_setzero_pd();
163 /* Load parameters for i particles */
164 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
166 /* Reset potential sums */
167 velecsum = _mm_setzero_pd();
169 /* Start inner kernel loop */
170 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
173 /* Get j neighbor index, and coordinate index */
176 j_coord_offsetA = DIM*jnrA;
177 j_coord_offsetB = DIM*jnrB;
179 /* load j atom coordinates */
180 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
183 /* Calculate displacement vector */
184 dx00 = _mm_sub_pd(ix0,jx0);
185 dy00 = _mm_sub_pd(iy0,jy0);
186 dz00 = _mm_sub_pd(iz0,jz0);
188 /* Calculate squared distance and things based on it */
189 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
191 rinv00 = gmx_mm_invsqrt_pd(rsq00);
193 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
195 /* Load parameters for j particles */
196 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
198 /**************************
199 * CALCULATE INTERACTIONS *
200 **************************/
202 if (gmx_mm_any_lt(rsq00,rcutoff2))
205 r00 = _mm_mul_pd(rsq00,rinv00);
207 /* Compute parameters for interactions between i and j atoms */
208 qq00 = _mm_mul_pd(iq0,jq0);
210 /* EWALD ELECTROSTATICS */
212 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
213 ewrt = _mm_mul_pd(r00,ewtabscale);
214 ewitab = _mm_cvttpd_epi32(ewrt);
215 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
216 ewitab = _mm_slli_epi32(ewitab,2);
217 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
218 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
219 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
220 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
221 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
222 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
223 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
224 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
225 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
226 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
228 d = _mm_sub_pd(r00,rswitch);
229 d = _mm_max_pd(d,_mm_setzero_pd());
230 d2 = _mm_mul_pd(d,d);
231 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)))))));
233 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
235 /* Evaluate switch function */
236 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
237 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
238 velec = _mm_mul_pd(velec,sw);
239 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
241 /* Update potential sum for this i atom from the interaction with this j atom. */
242 velec = _mm_and_pd(velec,cutoff_mask);
243 velecsum = _mm_add_pd(velecsum,velec);
247 fscal = _mm_and_pd(fscal,cutoff_mask);
249 /* Calculate temporary vectorial force */
250 tx = _mm_mul_pd(fscal,dx00);
251 ty = _mm_mul_pd(fscal,dy00);
252 tz = _mm_mul_pd(fscal,dz00);
254 /* Update vectorial force */
255 fix0 = _mm_add_pd(fix0,tx);
256 fiy0 = _mm_add_pd(fiy0,ty);
257 fiz0 = _mm_add_pd(fiz0,tz);
259 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
263 /* Inner loop uses 65 flops */
270 j_coord_offsetA = DIM*jnrA;
272 /* load j atom coordinates */
273 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
276 /* Calculate displacement vector */
277 dx00 = _mm_sub_pd(ix0,jx0);
278 dy00 = _mm_sub_pd(iy0,jy0);
279 dz00 = _mm_sub_pd(iz0,jz0);
281 /* Calculate squared distance and things based on it */
282 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
284 rinv00 = gmx_mm_invsqrt_pd(rsq00);
286 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
288 /* Load parameters for j particles */
289 jq0 = _mm_load_sd(charge+jnrA+0);
291 /**************************
292 * CALCULATE INTERACTIONS *
293 **************************/
295 if (gmx_mm_any_lt(rsq00,rcutoff2))
298 r00 = _mm_mul_pd(rsq00,rinv00);
300 /* Compute parameters for interactions between i and j atoms */
301 qq00 = _mm_mul_pd(iq0,jq0);
303 /* EWALD ELECTROSTATICS */
305 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
306 ewrt = _mm_mul_pd(r00,ewtabscale);
307 ewitab = _mm_cvttpd_epi32(ewrt);
308 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
309 ewitab = _mm_slli_epi32(ewitab,2);
310 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
311 ewtabD = _mm_setzero_pd();
312 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
313 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
314 ewtabFn = _mm_setzero_pd();
315 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
316 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
317 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
318 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
319 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
321 d = _mm_sub_pd(r00,rswitch);
322 d = _mm_max_pd(d,_mm_setzero_pd());
323 d2 = _mm_mul_pd(d,d);
324 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)))))));
326 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
328 /* Evaluate switch function */
329 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
330 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
331 velec = _mm_mul_pd(velec,sw);
332 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
334 /* Update potential sum for this i atom from the interaction with this j atom. */
335 velec = _mm_and_pd(velec,cutoff_mask);
336 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
337 velecsum = _mm_add_pd(velecsum,velec);
341 fscal = _mm_and_pd(fscal,cutoff_mask);
343 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
345 /* Calculate temporary vectorial force */
346 tx = _mm_mul_pd(fscal,dx00);
347 ty = _mm_mul_pd(fscal,dy00);
348 tz = _mm_mul_pd(fscal,dz00);
350 /* Update vectorial force */
351 fix0 = _mm_add_pd(fix0,tx);
352 fiy0 = _mm_add_pd(fiy0,ty);
353 fiz0 = _mm_add_pd(fiz0,tz);
355 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
359 /* Inner loop uses 65 flops */
362 /* End of innermost loop */
364 gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
365 f+i_coord_offset,fshift+i_shift_offset);
368 /* Update potential energies */
369 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
371 /* Increment number of inner iterations */
372 inneriter += j_index_end - j_index_start;
374 /* Outer loop uses 8 flops */
377 /* Increment number of outer iterations */
380 /* Update outer/inner flops */
382 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*65);
385 * Gromacs nonbonded kernel: nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_sse2_double
386 * Electrostatics interaction: Ewald
387 * VdW interaction: None
388 * Geometry: Particle-Particle
389 * Calculate force/pot: Force
392 nb_kernel_ElecEwSw_VdwNone_GeomP1P1_F_sse2_double
393 (t_nblist * gmx_restrict nlist,
394 rvec * gmx_restrict xx,
395 rvec * gmx_restrict ff,
396 t_forcerec * gmx_restrict fr,
397 t_mdatoms * gmx_restrict mdatoms,
398 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
399 t_nrnb * gmx_restrict nrnb)
401 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
402 * just 0 for non-waters.
403 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
404 * jnr indices corresponding to data put in the four positions in the SIMD register.
406 int i_shift_offset,i_coord_offset,outeriter,inneriter;
407 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
409 int j_coord_offsetA,j_coord_offsetB;
410 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
412 real *shiftvec,*fshift,*x,*f;
413 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
415 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
416 int vdwjidx0A,vdwjidx0B;
417 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
418 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
419 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
422 __m128d ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
424 __m128d rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
425 real rswitch_scalar,d_scalar;
426 __m128d dummy_mask,cutoff_mask;
427 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
428 __m128d one = _mm_set1_pd(1.0);
429 __m128d two = _mm_set1_pd(2.0);
435 jindex = nlist->jindex;
437 shiftidx = nlist->shift;
439 shiftvec = fr->shift_vec[0];
440 fshift = fr->fshift[0];
441 facel = _mm_set1_pd(fr->epsfac);
442 charge = mdatoms->chargeA;
444 sh_ewald = _mm_set1_pd(fr->ic->sh_ewald);
445 ewtab = fr->ic->tabq_coul_FDV0;
446 ewtabscale = _mm_set1_pd(fr->ic->tabq_scale);
447 ewtabhalfspace = _mm_set1_pd(0.5/fr->ic->tabq_scale);
449 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
450 rcutoff_scalar = fr->rcoulomb;
451 rcutoff = _mm_set1_pd(rcutoff_scalar);
452 rcutoff2 = _mm_mul_pd(rcutoff,rcutoff);
454 rswitch_scalar = fr->rcoulomb_switch;
455 rswitch = _mm_set1_pd(rswitch_scalar);
456 /* Setup switch parameters */
457 d_scalar = rcutoff_scalar-rswitch_scalar;
458 d = _mm_set1_pd(d_scalar);
459 swV3 = _mm_set1_pd(-10.0/(d_scalar*d_scalar*d_scalar));
460 swV4 = _mm_set1_pd( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
461 swV5 = _mm_set1_pd( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
462 swF2 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar));
463 swF3 = _mm_set1_pd( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
464 swF4 = _mm_set1_pd(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
466 /* Avoid stupid compiler warnings */
474 /* Start outer loop over neighborlists */
475 for(iidx=0; iidx<nri; iidx++)
477 /* Load shift vector for this list */
478 i_shift_offset = DIM*shiftidx[iidx];
480 /* Load limits for loop over neighbors */
481 j_index_start = jindex[iidx];
482 j_index_end = jindex[iidx+1];
484 /* Get outer coordinate index */
486 i_coord_offset = DIM*inr;
488 /* Load i particle coords and add shift vector */
489 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
491 fix0 = _mm_setzero_pd();
492 fiy0 = _mm_setzero_pd();
493 fiz0 = _mm_setzero_pd();
495 /* Load parameters for i particles */
496 iq0 = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
498 /* Start inner kernel loop */
499 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
502 /* Get j neighbor index, and coordinate index */
505 j_coord_offsetA = DIM*jnrA;
506 j_coord_offsetB = DIM*jnrB;
508 /* load j atom coordinates */
509 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
512 /* Calculate displacement vector */
513 dx00 = _mm_sub_pd(ix0,jx0);
514 dy00 = _mm_sub_pd(iy0,jy0);
515 dz00 = _mm_sub_pd(iz0,jz0);
517 /* Calculate squared distance and things based on it */
518 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
520 rinv00 = gmx_mm_invsqrt_pd(rsq00);
522 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
524 /* Load parameters for j particles */
525 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
527 /**************************
528 * CALCULATE INTERACTIONS *
529 **************************/
531 if (gmx_mm_any_lt(rsq00,rcutoff2))
534 r00 = _mm_mul_pd(rsq00,rinv00);
536 /* Compute parameters for interactions between i and j atoms */
537 qq00 = _mm_mul_pd(iq0,jq0);
539 /* EWALD ELECTROSTATICS */
541 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
542 ewrt = _mm_mul_pd(r00,ewtabscale);
543 ewitab = _mm_cvttpd_epi32(ewrt);
544 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
545 ewitab = _mm_slli_epi32(ewitab,2);
546 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
547 ewtabD = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
548 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
549 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
550 ewtabFn = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
551 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
552 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
553 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
554 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
555 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
557 d = _mm_sub_pd(r00,rswitch);
558 d = _mm_max_pd(d,_mm_setzero_pd());
559 d2 = _mm_mul_pd(d,d);
560 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)))))));
562 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
564 /* Evaluate switch function */
565 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
566 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
567 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
571 fscal = _mm_and_pd(fscal,cutoff_mask);
573 /* Calculate temporary vectorial force */
574 tx = _mm_mul_pd(fscal,dx00);
575 ty = _mm_mul_pd(fscal,dy00);
576 tz = _mm_mul_pd(fscal,dz00);
578 /* Update vectorial force */
579 fix0 = _mm_add_pd(fix0,tx);
580 fiy0 = _mm_add_pd(fiy0,ty);
581 fiz0 = _mm_add_pd(fiz0,tz);
583 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
587 /* Inner loop uses 62 flops */
594 j_coord_offsetA = DIM*jnrA;
596 /* load j atom coordinates */
597 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
600 /* Calculate displacement vector */
601 dx00 = _mm_sub_pd(ix0,jx0);
602 dy00 = _mm_sub_pd(iy0,jy0);
603 dz00 = _mm_sub_pd(iz0,jz0);
605 /* Calculate squared distance and things based on it */
606 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
608 rinv00 = gmx_mm_invsqrt_pd(rsq00);
610 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
612 /* Load parameters for j particles */
613 jq0 = _mm_load_sd(charge+jnrA+0);
615 /**************************
616 * CALCULATE INTERACTIONS *
617 **************************/
619 if (gmx_mm_any_lt(rsq00,rcutoff2))
622 r00 = _mm_mul_pd(rsq00,rinv00);
624 /* Compute parameters for interactions between i and j atoms */
625 qq00 = _mm_mul_pd(iq0,jq0);
627 /* EWALD ELECTROSTATICS */
629 /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
630 ewrt = _mm_mul_pd(r00,ewtabscale);
631 ewitab = _mm_cvttpd_epi32(ewrt);
632 eweps = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
633 ewitab = _mm_slli_epi32(ewitab,2);
634 ewtabF = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
635 ewtabD = _mm_setzero_pd();
636 GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
637 ewtabV = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
638 ewtabFn = _mm_setzero_pd();
639 GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
640 felec = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
641 velec = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
642 velec = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
643 felec = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
645 d = _mm_sub_pd(r00,rswitch);
646 d = _mm_max_pd(d,_mm_setzero_pd());
647 d2 = _mm_mul_pd(d,d);
648 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)))))));
650 dsw = _mm_mul_pd(d2,_mm_add_pd(swF2,_mm_mul_pd(d,_mm_add_pd(swF3,_mm_mul_pd(d,swF4)))));
652 /* Evaluate switch function */
653 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
654 felec = _mm_sub_pd( _mm_mul_pd(felec,sw) , _mm_mul_pd(rinv00,_mm_mul_pd(velec,dsw)) );
655 cutoff_mask = _mm_cmplt_pd(rsq00,rcutoff2);
659 fscal = _mm_and_pd(fscal,cutoff_mask);
661 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
663 /* Calculate temporary vectorial force */
664 tx = _mm_mul_pd(fscal,dx00);
665 ty = _mm_mul_pd(fscal,dy00);
666 tz = _mm_mul_pd(fscal,dz00);
668 /* Update vectorial force */
669 fix0 = _mm_add_pd(fix0,tx);
670 fiy0 = _mm_add_pd(fiy0,ty);
671 fiz0 = _mm_add_pd(fiz0,tz);
673 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
677 /* Inner loop uses 62 flops */
680 /* End of innermost loop */
682 gmx_mm_update_iforce_1atom_swizzle_pd(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*62);