2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_VF_sse2_double
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
57 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_VF_sse2_double
58 (t_nblist
* gmx_restrict nlist
,
59 rvec
* gmx_restrict xx
,
60 rvec
* gmx_restrict ff
,
61 struct t_forcerec
* gmx_restrict fr
,
62 t_mdatoms
* gmx_restrict mdatoms
,
63 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
64 t_nrnb
* gmx_restrict nrnb
)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
72 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
74 int j_coord_offsetA
,j_coord_offsetB
;
75 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
77 real
*shiftvec
,*fshift
,*x
,*f
;
78 __m128d tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
80 __m128d ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
82 __m128d ix1
,iy1
,iz1
,fix1
,fiy1
,fiz1
,iq1
,isai1
;
84 __m128d ix2
,iy2
,iz2
,fix2
,fiy2
,fiz2
,iq2
,isai2
;
86 __m128d ix3
,iy3
,iz3
,fix3
,fiy3
,fiz3
,iq3
,isai3
;
87 int vdwjidx0A
,vdwjidx0B
;
88 __m128d jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
89 __m128d dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
90 __m128d dx10
,dy10
,dz10
,rsq10
,rinv10
,rinvsq10
,r10
,qq10
,c6_10
,c12_10
;
91 __m128d dx20
,dy20
,dz20
,rsq20
,rinv20
,rinvsq20
,r20
,qq20
,c6_20
,c12_20
;
92 __m128d dx30
,dy30
,dz30
,rsq30
,rinv30
,rinvsq30
,r30
,qq30
,c6_30
,c12_30
;
93 __m128d velec
,felec
,velecsum
,facel
,crf
,krf
,krf2
;
96 __m128d rinvsix
,rvdw
,vvdw
,vvdw6
,vvdw12
,fvdw
,fvdw6
,fvdw12
,vvdwsum
,sh_vdw_invrcut6
;
99 __m128d one_sixth
= _mm_set1_pd(1.0/6.0);
100 __m128d one_twelfth
= _mm_set1_pd(1.0/12.0);
101 __m128d rswitch
,swV3
,swV4
,swV5
,swF2
,swF3
,swF4
,d
,d2
,sw
,dsw
;
102 real rswitch_scalar
,d_scalar
;
103 __m128d dummy_mask
,cutoff_mask
;
104 __m128d signbit
= gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
105 __m128d one
= _mm_set1_pd(1.0);
106 __m128d two
= _mm_set1_pd(2.0);
112 jindex
= nlist
->jindex
;
114 shiftidx
= nlist
->shift
;
116 shiftvec
= fr
->shift_vec
[0];
117 fshift
= fr
->fshift
[0];
118 facel
= _mm_set1_pd(fr
->ic
->epsfac
);
119 charge
= mdatoms
->chargeA
;
120 krf
= _mm_set1_pd(fr
->ic
->k_rf
);
121 krf2
= _mm_set1_pd(fr
->ic
->k_rf
*2.0);
122 crf
= _mm_set1_pd(fr
->ic
->c_rf
);
123 nvdwtype
= fr
->ntype
;
125 vdwtype
= mdatoms
->typeA
;
127 /* Setup water-specific parameters */
128 inr
= nlist
->iinr
[0];
129 iq1
= _mm_mul_pd(facel
,_mm_set1_pd(charge
[inr
+1]));
130 iq2
= _mm_mul_pd(facel
,_mm_set1_pd(charge
[inr
+2]));
131 iq3
= _mm_mul_pd(facel
,_mm_set1_pd(charge
[inr
+3]));
132 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
134 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
135 rcutoff_scalar
= fr
->ic
->rcoulomb
;
136 rcutoff
= _mm_set1_pd(rcutoff_scalar
);
137 rcutoff2
= _mm_mul_pd(rcutoff
,rcutoff
);
139 rswitch_scalar
= fr
->ic
->rvdw_switch
;
140 rswitch
= _mm_set1_pd(rswitch_scalar
);
141 /* Setup switch parameters */
142 d_scalar
= rcutoff_scalar
-rswitch_scalar
;
143 d
= _mm_set1_pd(d_scalar
);
144 swV3
= _mm_set1_pd(-10.0/(d_scalar
*d_scalar
*d_scalar
));
145 swV4
= _mm_set1_pd( 15.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
));
146 swV5
= _mm_set1_pd( -6.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
*d_scalar
));
147 swF2
= _mm_set1_pd(-30.0/(d_scalar
*d_scalar
*d_scalar
));
148 swF3
= _mm_set1_pd( 60.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
));
149 swF4
= _mm_set1_pd(-30.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
*d_scalar
));
151 /* Avoid stupid compiler warnings */
159 /* Start outer loop over neighborlists */
160 for(iidx
=0; iidx
<nri
; iidx
++)
162 /* Load shift vector for this list */
163 i_shift_offset
= DIM
*shiftidx
[iidx
];
165 /* Load limits for loop over neighbors */
166 j_index_start
= jindex
[iidx
];
167 j_index_end
= jindex
[iidx
+1];
169 /* Get outer coordinate index */
171 i_coord_offset
= DIM
*inr
;
173 /* Load i particle coords and add shift vector */
174 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,
175 &ix0
,&iy0
,&iz0
,&ix1
,&iy1
,&iz1
,&ix2
,&iy2
,&iz2
,&ix3
,&iy3
,&iz3
);
177 fix0
= _mm_setzero_pd();
178 fiy0
= _mm_setzero_pd();
179 fiz0
= _mm_setzero_pd();
180 fix1
= _mm_setzero_pd();
181 fiy1
= _mm_setzero_pd();
182 fiz1
= _mm_setzero_pd();
183 fix2
= _mm_setzero_pd();
184 fiy2
= _mm_setzero_pd();
185 fiz2
= _mm_setzero_pd();
186 fix3
= _mm_setzero_pd();
187 fiy3
= _mm_setzero_pd();
188 fiz3
= _mm_setzero_pd();
190 /* Reset potential sums */
191 velecsum
= _mm_setzero_pd();
192 vvdwsum
= _mm_setzero_pd();
194 /* Start inner kernel loop */
195 for(jidx
=j_index_start
; jidx
<j_index_end
-1; jidx
+=2)
198 /* Get j neighbor index, and coordinate index */
201 j_coord_offsetA
= DIM
*jnrA
;
202 j_coord_offsetB
= DIM
*jnrB
;
204 /* load j atom coordinates */
205 gmx_mm_load_1rvec_2ptr_swizzle_pd(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
208 /* Calculate displacement vector */
209 dx00
= _mm_sub_pd(ix0
,jx0
);
210 dy00
= _mm_sub_pd(iy0
,jy0
);
211 dz00
= _mm_sub_pd(iz0
,jz0
);
212 dx10
= _mm_sub_pd(ix1
,jx0
);
213 dy10
= _mm_sub_pd(iy1
,jy0
);
214 dz10
= _mm_sub_pd(iz1
,jz0
);
215 dx20
= _mm_sub_pd(ix2
,jx0
);
216 dy20
= _mm_sub_pd(iy2
,jy0
);
217 dz20
= _mm_sub_pd(iz2
,jz0
);
218 dx30
= _mm_sub_pd(ix3
,jx0
);
219 dy30
= _mm_sub_pd(iy3
,jy0
);
220 dz30
= _mm_sub_pd(iz3
,jz0
);
222 /* Calculate squared distance and things based on it */
223 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
224 rsq10
= gmx_mm_calc_rsq_pd(dx10
,dy10
,dz10
);
225 rsq20
= gmx_mm_calc_rsq_pd(dx20
,dy20
,dz20
);
226 rsq30
= gmx_mm_calc_rsq_pd(dx30
,dy30
,dz30
);
228 rinv00
= sse2_invsqrt_d(rsq00
);
229 rinv10
= sse2_invsqrt_d(rsq10
);
230 rinv20
= sse2_invsqrt_d(rsq20
);
231 rinv30
= sse2_invsqrt_d(rsq30
);
233 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
234 rinvsq10
= _mm_mul_pd(rinv10
,rinv10
);
235 rinvsq20
= _mm_mul_pd(rinv20
,rinv20
);
236 rinvsq30
= _mm_mul_pd(rinv30
,rinv30
);
238 /* Load parameters for j particles */
239 jq0
= gmx_mm_load_2real_swizzle_pd(charge
+jnrA
+0,charge
+jnrB
+0);
240 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
241 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
243 fjx0
= _mm_setzero_pd();
244 fjy0
= _mm_setzero_pd();
245 fjz0
= _mm_setzero_pd();
247 /**************************
248 * CALCULATE INTERACTIONS *
249 **************************/
251 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
254 r00
= _mm_mul_pd(rsq00
,rinv00
);
256 /* Compute parameters for interactions between i and j atoms */
257 gmx_mm_load_2pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,
258 vdwparam
+vdwioffset0
+vdwjidx0B
,&c6_00
,&c12_00
);
260 /* LENNARD-JONES DISPERSION/REPULSION */
262 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
263 vvdw6
= _mm_mul_pd(c6_00
,rinvsix
);
264 vvdw12
= _mm_mul_pd(c12_00
,_mm_mul_pd(rinvsix
,rinvsix
));
265 vvdw
= _mm_sub_pd( _mm_mul_pd(vvdw12
,one_twelfth
) , _mm_mul_pd(vvdw6
,one_sixth
) );
266 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
268 d
= _mm_sub_pd(r00
,rswitch
);
269 d
= _mm_max_pd(d
,_mm_setzero_pd());
270 d2
= _mm_mul_pd(d
,d
);
271 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
)))))));
273 dsw
= _mm_mul_pd(d2
,_mm_add_pd(swF2
,_mm_mul_pd(d
,_mm_add_pd(swF3
,_mm_mul_pd(d
,swF4
)))));
275 /* Evaluate switch function */
276 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
277 fvdw
= _mm_sub_pd( _mm_mul_pd(fvdw
,sw
) , _mm_mul_pd(rinv00
,_mm_mul_pd(vvdw
,dsw
)) );
278 vvdw
= _mm_mul_pd(vvdw
,sw
);
279 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
281 /* Update potential sum for this i atom from the interaction with this j atom. */
282 vvdw
= _mm_and_pd(vvdw
,cutoff_mask
);
283 vvdwsum
= _mm_add_pd(vvdwsum
,vvdw
);
287 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
289 /* Calculate temporary vectorial force */
290 tx
= _mm_mul_pd(fscal
,dx00
);
291 ty
= _mm_mul_pd(fscal
,dy00
);
292 tz
= _mm_mul_pd(fscal
,dz00
);
294 /* Update vectorial force */
295 fix0
= _mm_add_pd(fix0
,tx
);
296 fiy0
= _mm_add_pd(fiy0
,ty
);
297 fiz0
= _mm_add_pd(fiz0
,tz
);
299 fjx0
= _mm_add_pd(fjx0
,tx
);
300 fjy0
= _mm_add_pd(fjy0
,ty
);
301 fjz0
= _mm_add_pd(fjz0
,tz
);
305 /**************************
306 * CALCULATE INTERACTIONS *
307 **************************/
309 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
312 /* Compute parameters for interactions between i and j atoms */
313 qq10
= _mm_mul_pd(iq1
,jq0
);
315 /* REACTION-FIELD ELECTROSTATICS */
316 velec
= _mm_mul_pd(qq10
,_mm_sub_pd(_mm_add_pd(rinv10
,_mm_mul_pd(krf
,rsq10
)),crf
));
317 felec
= _mm_mul_pd(qq10
,_mm_sub_pd(_mm_mul_pd(rinv10
,rinvsq10
),krf2
));
319 cutoff_mask
= _mm_cmplt_pd(rsq10
,rcutoff2
);
321 /* Update potential sum for this i atom from the interaction with this j atom. */
322 velec
= _mm_and_pd(velec
,cutoff_mask
);
323 velecsum
= _mm_add_pd(velecsum
,velec
);
327 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
329 /* Calculate temporary vectorial force */
330 tx
= _mm_mul_pd(fscal
,dx10
);
331 ty
= _mm_mul_pd(fscal
,dy10
);
332 tz
= _mm_mul_pd(fscal
,dz10
);
334 /* Update vectorial force */
335 fix1
= _mm_add_pd(fix1
,tx
);
336 fiy1
= _mm_add_pd(fiy1
,ty
);
337 fiz1
= _mm_add_pd(fiz1
,tz
);
339 fjx0
= _mm_add_pd(fjx0
,tx
);
340 fjy0
= _mm_add_pd(fjy0
,ty
);
341 fjz0
= _mm_add_pd(fjz0
,tz
);
345 /**************************
346 * CALCULATE INTERACTIONS *
347 **************************/
349 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
352 /* Compute parameters for interactions between i and j atoms */
353 qq20
= _mm_mul_pd(iq2
,jq0
);
355 /* REACTION-FIELD ELECTROSTATICS */
356 velec
= _mm_mul_pd(qq20
,_mm_sub_pd(_mm_add_pd(rinv20
,_mm_mul_pd(krf
,rsq20
)),crf
));
357 felec
= _mm_mul_pd(qq20
,_mm_sub_pd(_mm_mul_pd(rinv20
,rinvsq20
),krf2
));
359 cutoff_mask
= _mm_cmplt_pd(rsq20
,rcutoff2
);
361 /* Update potential sum for this i atom from the interaction with this j atom. */
362 velec
= _mm_and_pd(velec
,cutoff_mask
);
363 velecsum
= _mm_add_pd(velecsum
,velec
);
367 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
369 /* Calculate temporary vectorial force */
370 tx
= _mm_mul_pd(fscal
,dx20
);
371 ty
= _mm_mul_pd(fscal
,dy20
);
372 tz
= _mm_mul_pd(fscal
,dz20
);
374 /* Update vectorial force */
375 fix2
= _mm_add_pd(fix2
,tx
);
376 fiy2
= _mm_add_pd(fiy2
,ty
);
377 fiz2
= _mm_add_pd(fiz2
,tz
);
379 fjx0
= _mm_add_pd(fjx0
,tx
);
380 fjy0
= _mm_add_pd(fjy0
,ty
);
381 fjz0
= _mm_add_pd(fjz0
,tz
);
385 /**************************
386 * CALCULATE INTERACTIONS *
387 **************************/
389 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
392 /* Compute parameters for interactions between i and j atoms */
393 qq30
= _mm_mul_pd(iq3
,jq0
);
395 /* REACTION-FIELD ELECTROSTATICS */
396 velec
= _mm_mul_pd(qq30
,_mm_sub_pd(_mm_add_pd(rinv30
,_mm_mul_pd(krf
,rsq30
)),crf
));
397 felec
= _mm_mul_pd(qq30
,_mm_sub_pd(_mm_mul_pd(rinv30
,rinvsq30
),krf2
));
399 cutoff_mask
= _mm_cmplt_pd(rsq30
,rcutoff2
);
401 /* Update potential sum for this i atom from the interaction with this j atom. */
402 velec
= _mm_and_pd(velec
,cutoff_mask
);
403 velecsum
= _mm_add_pd(velecsum
,velec
);
407 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
409 /* Calculate temporary vectorial force */
410 tx
= _mm_mul_pd(fscal
,dx30
);
411 ty
= _mm_mul_pd(fscal
,dy30
);
412 tz
= _mm_mul_pd(fscal
,dz30
);
414 /* Update vectorial force */
415 fix3
= _mm_add_pd(fix3
,tx
);
416 fiy3
= _mm_add_pd(fiy3
,ty
);
417 fiz3
= _mm_add_pd(fiz3
,tz
);
419 fjx0
= _mm_add_pd(fjx0
,tx
);
420 fjy0
= _mm_add_pd(fjy0
,ty
);
421 fjz0
= _mm_add_pd(fjz0
,tz
);
425 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,fjx0
,fjy0
,fjz0
);
427 /* Inner loop uses 170 flops */
434 j_coord_offsetA
= DIM
*jnrA
;
436 /* load j atom coordinates */
437 gmx_mm_load_1rvec_1ptr_swizzle_pd(x
+j_coord_offsetA
,
440 /* Calculate displacement vector */
441 dx00
= _mm_sub_pd(ix0
,jx0
);
442 dy00
= _mm_sub_pd(iy0
,jy0
);
443 dz00
= _mm_sub_pd(iz0
,jz0
);
444 dx10
= _mm_sub_pd(ix1
,jx0
);
445 dy10
= _mm_sub_pd(iy1
,jy0
);
446 dz10
= _mm_sub_pd(iz1
,jz0
);
447 dx20
= _mm_sub_pd(ix2
,jx0
);
448 dy20
= _mm_sub_pd(iy2
,jy0
);
449 dz20
= _mm_sub_pd(iz2
,jz0
);
450 dx30
= _mm_sub_pd(ix3
,jx0
);
451 dy30
= _mm_sub_pd(iy3
,jy0
);
452 dz30
= _mm_sub_pd(iz3
,jz0
);
454 /* Calculate squared distance and things based on it */
455 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
456 rsq10
= gmx_mm_calc_rsq_pd(dx10
,dy10
,dz10
);
457 rsq20
= gmx_mm_calc_rsq_pd(dx20
,dy20
,dz20
);
458 rsq30
= gmx_mm_calc_rsq_pd(dx30
,dy30
,dz30
);
460 rinv00
= sse2_invsqrt_d(rsq00
);
461 rinv10
= sse2_invsqrt_d(rsq10
);
462 rinv20
= sse2_invsqrt_d(rsq20
);
463 rinv30
= sse2_invsqrt_d(rsq30
);
465 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
466 rinvsq10
= _mm_mul_pd(rinv10
,rinv10
);
467 rinvsq20
= _mm_mul_pd(rinv20
,rinv20
);
468 rinvsq30
= _mm_mul_pd(rinv30
,rinv30
);
470 /* Load parameters for j particles */
471 jq0
= _mm_load_sd(charge
+jnrA
+0);
472 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
474 fjx0
= _mm_setzero_pd();
475 fjy0
= _mm_setzero_pd();
476 fjz0
= _mm_setzero_pd();
478 /**************************
479 * CALCULATE INTERACTIONS *
480 **************************/
482 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
485 r00
= _mm_mul_pd(rsq00
,rinv00
);
487 /* Compute parameters for interactions between i and j atoms */
488 gmx_mm_load_1pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,&c6_00
,&c12_00
);
490 /* LENNARD-JONES DISPERSION/REPULSION */
492 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
493 vvdw6
= _mm_mul_pd(c6_00
,rinvsix
);
494 vvdw12
= _mm_mul_pd(c12_00
,_mm_mul_pd(rinvsix
,rinvsix
));
495 vvdw
= _mm_sub_pd( _mm_mul_pd(vvdw12
,one_twelfth
) , _mm_mul_pd(vvdw6
,one_sixth
) );
496 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
498 d
= _mm_sub_pd(r00
,rswitch
);
499 d
= _mm_max_pd(d
,_mm_setzero_pd());
500 d2
= _mm_mul_pd(d
,d
);
501 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
)))))));
503 dsw
= _mm_mul_pd(d2
,_mm_add_pd(swF2
,_mm_mul_pd(d
,_mm_add_pd(swF3
,_mm_mul_pd(d
,swF4
)))));
505 /* Evaluate switch function */
506 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
507 fvdw
= _mm_sub_pd( _mm_mul_pd(fvdw
,sw
) , _mm_mul_pd(rinv00
,_mm_mul_pd(vvdw
,dsw
)) );
508 vvdw
= _mm_mul_pd(vvdw
,sw
);
509 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
511 /* Update potential sum for this i atom from the interaction with this j atom. */
512 vvdw
= _mm_and_pd(vvdw
,cutoff_mask
);
513 vvdw
= _mm_unpacklo_pd(vvdw
,_mm_setzero_pd());
514 vvdwsum
= _mm_add_pd(vvdwsum
,vvdw
);
518 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
520 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
522 /* Calculate temporary vectorial force */
523 tx
= _mm_mul_pd(fscal
,dx00
);
524 ty
= _mm_mul_pd(fscal
,dy00
);
525 tz
= _mm_mul_pd(fscal
,dz00
);
527 /* Update vectorial force */
528 fix0
= _mm_add_pd(fix0
,tx
);
529 fiy0
= _mm_add_pd(fiy0
,ty
);
530 fiz0
= _mm_add_pd(fiz0
,tz
);
532 fjx0
= _mm_add_pd(fjx0
,tx
);
533 fjy0
= _mm_add_pd(fjy0
,ty
);
534 fjz0
= _mm_add_pd(fjz0
,tz
);
538 /**************************
539 * CALCULATE INTERACTIONS *
540 **************************/
542 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
545 /* Compute parameters for interactions between i and j atoms */
546 qq10
= _mm_mul_pd(iq1
,jq0
);
548 /* REACTION-FIELD ELECTROSTATICS */
549 velec
= _mm_mul_pd(qq10
,_mm_sub_pd(_mm_add_pd(rinv10
,_mm_mul_pd(krf
,rsq10
)),crf
));
550 felec
= _mm_mul_pd(qq10
,_mm_sub_pd(_mm_mul_pd(rinv10
,rinvsq10
),krf2
));
552 cutoff_mask
= _mm_cmplt_pd(rsq10
,rcutoff2
);
554 /* Update potential sum for this i atom from the interaction with this j atom. */
555 velec
= _mm_and_pd(velec
,cutoff_mask
);
556 velec
= _mm_unpacklo_pd(velec
,_mm_setzero_pd());
557 velecsum
= _mm_add_pd(velecsum
,velec
);
561 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
563 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
565 /* Calculate temporary vectorial force */
566 tx
= _mm_mul_pd(fscal
,dx10
);
567 ty
= _mm_mul_pd(fscal
,dy10
);
568 tz
= _mm_mul_pd(fscal
,dz10
);
570 /* Update vectorial force */
571 fix1
= _mm_add_pd(fix1
,tx
);
572 fiy1
= _mm_add_pd(fiy1
,ty
);
573 fiz1
= _mm_add_pd(fiz1
,tz
);
575 fjx0
= _mm_add_pd(fjx0
,tx
);
576 fjy0
= _mm_add_pd(fjy0
,ty
);
577 fjz0
= _mm_add_pd(fjz0
,tz
);
581 /**************************
582 * CALCULATE INTERACTIONS *
583 **************************/
585 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
588 /* Compute parameters for interactions between i and j atoms */
589 qq20
= _mm_mul_pd(iq2
,jq0
);
591 /* REACTION-FIELD ELECTROSTATICS */
592 velec
= _mm_mul_pd(qq20
,_mm_sub_pd(_mm_add_pd(rinv20
,_mm_mul_pd(krf
,rsq20
)),crf
));
593 felec
= _mm_mul_pd(qq20
,_mm_sub_pd(_mm_mul_pd(rinv20
,rinvsq20
),krf2
));
595 cutoff_mask
= _mm_cmplt_pd(rsq20
,rcutoff2
);
597 /* Update potential sum for this i atom from the interaction with this j atom. */
598 velec
= _mm_and_pd(velec
,cutoff_mask
);
599 velec
= _mm_unpacklo_pd(velec
,_mm_setzero_pd());
600 velecsum
= _mm_add_pd(velecsum
,velec
);
604 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
606 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
608 /* Calculate temporary vectorial force */
609 tx
= _mm_mul_pd(fscal
,dx20
);
610 ty
= _mm_mul_pd(fscal
,dy20
);
611 tz
= _mm_mul_pd(fscal
,dz20
);
613 /* Update vectorial force */
614 fix2
= _mm_add_pd(fix2
,tx
);
615 fiy2
= _mm_add_pd(fiy2
,ty
);
616 fiz2
= _mm_add_pd(fiz2
,tz
);
618 fjx0
= _mm_add_pd(fjx0
,tx
);
619 fjy0
= _mm_add_pd(fjy0
,ty
);
620 fjz0
= _mm_add_pd(fjz0
,tz
);
624 /**************************
625 * CALCULATE INTERACTIONS *
626 **************************/
628 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
631 /* Compute parameters for interactions between i and j atoms */
632 qq30
= _mm_mul_pd(iq3
,jq0
);
634 /* REACTION-FIELD ELECTROSTATICS */
635 velec
= _mm_mul_pd(qq30
,_mm_sub_pd(_mm_add_pd(rinv30
,_mm_mul_pd(krf
,rsq30
)),crf
));
636 felec
= _mm_mul_pd(qq30
,_mm_sub_pd(_mm_mul_pd(rinv30
,rinvsq30
),krf2
));
638 cutoff_mask
= _mm_cmplt_pd(rsq30
,rcutoff2
);
640 /* Update potential sum for this i atom from the interaction with this j atom. */
641 velec
= _mm_and_pd(velec
,cutoff_mask
);
642 velec
= _mm_unpacklo_pd(velec
,_mm_setzero_pd());
643 velecsum
= _mm_add_pd(velecsum
,velec
);
647 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
649 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
651 /* Calculate temporary vectorial force */
652 tx
= _mm_mul_pd(fscal
,dx30
);
653 ty
= _mm_mul_pd(fscal
,dy30
);
654 tz
= _mm_mul_pd(fscal
,dz30
);
656 /* Update vectorial force */
657 fix3
= _mm_add_pd(fix3
,tx
);
658 fiy3
= _mm_add_pd(fiy3
,ty
);
659 fiz3
= _mm_add_pd(fiz3
,tz
);
661 fjx0
= _mm_add_pd(fjx0
,tx
);
662 fjy0
= _mm_add_pd(fjy0
,ty
);
663 fjz0
= _mm_add_pd(fjz0
,tz
);
667 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f
+j_coord_offsetA
,fjx0
,fjy0
,fjz0
);
669 /* Inner loop uses 170 flops */
672 /* End of innermost loop */
674 gmx_mm_update_iforce_4atom_swizzle_pd(fix0
,fiy0
,fiz0
,fix1
,fiy1
,fiz1
,fix2
,fiy2
,fiz2
,fix3
,fiy3
,fiz3
,
675 f
+i_coord_offset
,fshift
+i_shift_offset
);
678 /* Update potential energies */
679 gmx_mm_update_1pot_pd(velecsum
,kernel_data
->energygrp_elec
+ggid
);
680 gmx_mm_update_1pot_pd(vvdwsum
,kernel_data
->energygrp_vdw
+ggid
);
682 /* Increment number of inner iterations */
683 inneriter
+= j_index_end
- j_index_start
;
685 /* Outer loop uses 26 flops */
688 /* Increment number of outer iterations */
691 /* Update outer/inner flops */
693 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_VDW_W4_VF
,outeriter
*26 + inneriter
*170);
696 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_sse2_double
697 * Electrostatics interaction: ReactionField
698 * VdW interaction: LennardJones
699 * Geometry: Water4-Particle
700 * Calculate force/pot: Force
703 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_sse2_double
704 (t_nblist
* gmx_restrict nlist
,
705 rvec
* gmx_restrict xx
,
706 rvec
* gmx_restrict ff
,
707 struct t_forcerec
* gmx_restrict fr
,
708 t_mdatoms
* gmx_restrict mdatoms
,
709 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
710 t_nrnb
* gmx_restrict nrnb
)
712 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
713 * just 0 for non-waters.
714 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
715 * jnr indices corresponding to data put in the four positions in the SIMD register.
717 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
718 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
720 int j_coord_offsetA
,j_coord_offsetB
;
721 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
723 real
*shiftvec
,*fshift
,*x
,*f
;
724 __m128d tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
726 __m128d ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
728 __m128d ix1
,iy1
,iz1
,fix1
,fiy1
,fiz1
,iq1
,isai1
;
730 __m128d ix2
,iy2
,iz2
,fix2
,fiy2
,fiz2
,iq2
,isai2
;
732 __m128d ix3
,iy3
,iz3
,fix3
,fiy3
,fiz3
,iq3
,isai3
;
733 int vdwjidx0A
,vdwjidx0B
;
734 __m128d jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
735 __m128d dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
736 __m128d dx10
,dy10
,dz10
,rsq10
,rinv10
,rinvsq10
,r10
,qq10
,c6_10
,c12_10
;
737 __m128d dx20
,dy20
,dz20
,rsq20
,rinv20
,rinvsq20
,r20
,qq20
,c6_20
,c12_20
;
738 __m128d dx30
,dy30
,dz30
,rsq30
,rinv30
,rinvsq30
,r30
,qq30
,c6_30
,c12_30
;
739 __m128d velec
,felec
,velecsum
,facel
,crf
,krf
,krf2
;
742 __m128d rinvsix
,rvdw
,vvdw
,vvdw6
,vvdw12
,fvdw
,fvdw6
,fvdw12
,vvdwsum
,sh_vdw_invrcut6
;
745 __m128d one_sixth
= _mm_set1_pd(1.0/6.0);
746 __m128d one_twelfth
= _mm_set1_pd(1.0/12.0);
747 __m128d rswitch
,swV3
,swV4
,swV5
,swF2
,swF3
,swF4
,d
,d2
,sw
,dsw
;
748 real rswitch_scalar
,d_scalar
;
749 __m128d dummy_mask
,cutoff_mask
;
750 __m128d signbit
= gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
751 __m128d one
= _mm_set1_pd(1.0);
752 __m128d two
= _mm_set1_pd(2.0);
758 jindex
= nlist
->jindex
;
760 shiftidx
= nlist
->shift
;
762 shiftvec
= fr
->shift_vec
[0];
763 fshift
= fr
->fshift
[0];
764 facel
= _mm_set1_pd(fr
->ic
->epsfac
);
765 charge
= mdatoms
->chargeA
;
766 krf
= _mm_set1_pd(fr
->ic
->k_rf
);
767 krf2
= _mm_set1_pd(fr
->ic
->k_rf
*2.0);
768 crf
= _mm_set1_pd(fr
->ic
->c_rf
);
769 nvdwtype
= fr
->ntype
;
771 vdwtype
= mdatoms
->typeA
;
773 /* Setup water-specific parameters */
774 inr
= nlist
->iinr
[0];
775 iq1
= _mm_mul_pd(facel
,_mm_set1_pd(charge
[inr
+1]));
776 iq2
= _mm_mul_pd(facel
,_mm_set1_pd(charge
[inr
+2]));
777 iq3
= _mm_mul_pd(facel
,_mm_set1_pd(charge
[inr
+3]));
778 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
780 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
781 rcutoff_scalar
= fr
->ic
->rcoulomb
;
782 rcutoff
= _mm_set1_pd(rcutoff_scalar
);
783 rcutoff2
= _mm_mul_pd(rcutoff
,rcutoff
);
785 rswitch_scalar
= fr
->ic
->rvdw_switch
;
786 rswitch
= _mm_set1_pd(rswitch_scalar
);
787 /* Setup switch parameters */
788 d_scalar
= rcutoff_scalar
-rswitch_scalar
;
789 d
= _mm_set1_pd(d_scalar
);
790 swV3
= _mm_set1_pd(-10.0/(d_scalar
*d_scalar
*d_scalar
));
791 swV4
= _mm_set1_pd( 15.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
));
792 swV5
= _mm_set1_pd( -6.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
*d_scalar
));
793 swF2
= _mm_set1_pd(-30.0/(d_scalar
*d_scalar
*d_scalar
));
794 swF3
= _mm_set1_pd( 60.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
));
795 swF4
= _mm_set1_pd(-30.0/(d_scalar
*d_scalar
*d_scalar
*d_scalar
*d_scalar
));
797 /* Avoid stupid compiler warnings */
805 /* Start outer loop over neighborlists */
806 for(iidx
=0; iidx
<nri
; iidx
++)
808 /* Load shift vector for this list */
809 i_shift_offset
= DIM
*shiftidx
[iidx
];
811 /* Load limits for loop over neighbors */
812 j_index_start
= jindex
[iidx
];
813 j_index_end
= jindex
[iidx
+1];
815 /* Get outer coordinate index */
817 i_coord_offset
= DIM
*inr
;
819 /* Load i particle coords and add shift vector */
820 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,
821 &ix0
,&iy0
,&iz0
,&ix1
,&iy1
,&iz1
,&ix2
,&iy2
,&iz2
,&ix3
,&iy3
,&iz3
);
823 fix0
= _mm_setzero_pd();
824 fiy0
= _mm_setzero_pd();
825 fiz0
= _mm_setzero_pd();
826 fix1
= _mm_setzero_pd();
827 fiy1
= _mm_setzero_pd();
828 fiz1
= _mm_setzero_pd();
829 fix2
= _mm_setzero_pd();
830 fiy2
= _mm_setzero_pd();
831 fiz2
= _mm_setzero_pd();
832 fix3
= _mm_setzero_pd();
833 fiy3
= _mm_setzero_pd();
834 fiz3
= _mm_setzero_pd();
836 /* Start inner kernel loop */
837 for(jidx
=j_index_start
; jidx
<j_index_end
-1; jidx
+=2)
840 /* Get j neighbor index, and coordinate index */
843 j_coord_offsetA
= DIM
*jnrA
;
844 j_coord_offsetB
= DIM
*jnrB
;
846 /* load j atom coordinates */
847 gmx_mm_load_1rvec_2ptr_swizzle_pd(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
850 /* Calculate displacement vector */
851 dx00
= _mm_sub_pd(ix0
,jx0
);
852 dy00
= _mm_sub_pd(iy0
,jy0
);
853 dz00
= _mm_sub_pd(iz0
,jz0
);
854 dx10
= _mm_sub_pd(ix1
,jx0
);
855 dy10
= _mm_sub_pd(iy1
,jy0
);
856 dz10
= _mm_sub_pd(iz1
,jz0
);
857 dx20
= _mm_sub_pd(ix2
,jx0
);
858 dy20
= _mm_sub_pd(iy2
,jy0
);
859 dz20
= _mm_sub_pd(iz2
,jz0
);
860 dx30
= _mm_sub_pd(ix3
,jx0
);
861 dy30
= _mm_sub_pd(iy3
,jy0
);
862 dz30
= _mm_sub_pd(iz3
,jz0
);
864 /* Calculate squared distance and things based on it */
865 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
866 rsq10
= gmx_mm_calc_rsq_pd(dx10
,dy10
,dz10
);
867 rsq20
= gmx_mm_calc_rsq_pd(dx20
,dy20
,dz20
);
868 rsq30
= gmx_mm_calc_rsq_pd(dx30
,dy30
,dz30
);
870 rinv00
= sse2_invsqrt_d(rsq00
);
871 rinv10
= sse2_invsqrt_d(rsq10
);
872 rinv20
= sse2_invsqrt_d(rsq20
);
873 rinv30
= sse2_invsqrt_d(rsq30
);
875 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
876 rinvsq10
= _mm_mul_pd(rinv10
,rinv10
);
877 rinvsq20
= _mm_mul_pd(rinv20
,rinv20
);
878 rinvsq30
= _mm_mul_pd(rinv30
,rinv30
);
880 /* Load parameters for j particles */
881 jq0
= gmx_mm_load_2real_swizzle_pd(charge
+jnrA
+0,charge
+jnrB
+0);
882 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
883 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
885 fjx0
= _mm_setzero_pd();
886 fjy0
= _mm_setzero_pd();
887 fjz0
= _mm_setzero_pd();
889 /**************************
890 * CALCULATE INTERACTIONS *
891 **************************/
893 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
896 r00
= _mm_mul_pd(rsq00
,rinv00
);
898 /* Compute parameters for interactions between i and j atoms */
899 gmx_mm_load_2pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,
900 vdwparam
+vdwioffset0
+vdwjidx0B
,&c6_00
,&c12_00
);
902 /* LENNARD-JONES DISPERSION/REPULSION */
904 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
905 vvdw6
= _mm_mul_pd(c6_00
,rinvsix
);
906 vvdw12
= _mm_mul_pd(c12_00
,_mm_mul_pd(rinvsix
,rinvsix
));
907 vvdw
= _mm_sub_pd( _mm_mul_pd(vvdw12
,one_twelfth
) , _mm_mul_pd(vvdw6
,one_sixth
) );
908 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
910 d
= _mm_sub_pd(r00
,rswitch
);
911 d
= _mm_max_pd(d
,_mm_setzero_pd());
912 d2
= _mm_mul_pd(d
,d
);
913 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
)))))));
915 dsw
= _mm_mul_pd(d2
,_mm_add_pd(swF2
,_mm_mul_pd(d
,_mm_add_pd(swF3
,_mm_mul_pd(d
,swF4
)))));
917 /* Evaluate switch function */
918 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
919 fvdw
= _mm_sub_pd( _mm_mul_pd(fvdw
,sw
) , _mm_mul_pd(rinv00
,_mm_mul_pd(vvdw
,dsw
)) );
920 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
924 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
926 /* Calculate temporary vectorial force */
927 tx
= _mm_mul_pd(fscal
,dx00
);
928 ty
= _mm_mul_pd(fscal
,dy00
);
929 tz
= _mm_mul_pd(fscal
,dz00
);
931 /* Update vectorial force */
932 fix0
= _mm_add_pd(fix0
,tx
);
933 fiy0
= _mm_add_pd(fiy0
,ty
);
934 fiz0
= _mm_add_pd(fiz0
,tz
);
936 fjx0
= _mm_add_pd(fjx0
,tx
);
937 fjy0
= _mm_add_pd(fjy0
,ty
);
938 fjz0
= _mm_add_pd(fjz0
,tz
);
942 /**************************
943 * CALCULATE INTERACTIONS *
944 **************************/
946 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
949 /* Compute parameters for interactions between i and j atoms */
950 qq10
= _mm_mul_pd(iq1
,jq0
);
952 /* REACTION-FIELD ELECTROSTATICS */
953 felec
= _mm_mul_pd(qq10
,_mm_sub_pd(_mm_mul_pd(rinv10
,rinvsq10
),krf2
));
955 cutoff_mask
= _mm_cmplt_pd(rsq10
,rcutoff2
);
959 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
961 /* Calculate temporary vectorial force */
962 tx
= _mm_mul_pd(fscal
,dx10
);
963 ty
= _mm_mul_pd(fscal
,dy10
);
964 tz
= _mm_mul_pd(fscal
,dz10
);
966 /* Update vectorial force */
967 fix1
= _mm_add_pd(fix1
,tx
);
968 fiy1
= _mm_add_pd(fiy1
,ty
);
969 fiz1
= _mm_add_pd(fiz1
,tz
);
971 fjx0
= _mm_add_pd(fjx0
,tx
);
972 fjy0
= _mm_add_pd(fjy0
,ty
);
973 fjz0
= _mm_add_pd(fjz0
,tz
);
977 /**************************
978 * CALCULATE INTERACTIONS *
979 **************************/
981 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
984 /* Compute parameters for interactions between i and j atoms */
985 qq20
= _mm_mul_pd(iq2
,jq0
);
987 /* REACTION-FIELD ELECTROSTATICS */
988 felec
= _mm_mul_pd(qq20
,_mm_sub_pd(_mm_mul_pd(rinv20
,rinvsq20
),krf2
));
990 cutoff_mask
= _mm_cmplt_pd(rsq20
,rcutoff2
);
994 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
996 /* Calculate temporary vectorial force */
997 tx
= _mm_mul_pd(fscal
,dx20
);
998 ty
= _mm_mul_pd(fscal
,dy20
);
999 tz
= _mm_mul_pd(fscal
,dz20
);
1001 /* Update vectorial force */
1002 fix2
= _mm_add_pd(fix2
,tx
);
1003 fiy2
= _mm_add_pd(fiy2
,ty
);
1004 fiz2
= _mm_add_pd(fiz2
,tz
);
1006 fjx0
= _mm_add_pd(fjx0
,tx
);
1007 fjy0
= _mm_add_pd(fjy0
,ty
);
1008 fjz0
= _mm_add_pd(fjz0
,tz
);
1012 /**************************
1013 * CALCULATE INTERACTIONS *
1014 **************************/
1016 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
1019 /* Compute parameters for interactions between i and j atoms */
1020 qq30
= _mm_mul_pd(iq3
,jq0
);
1022 /* REACTION-FIELD ELECTROSTATICS */
1023 felec
= _mm_mul_pd(qq30
,_mm_sub_pd(_mm_mul_pd(rinv30
,rinvsq30
),krf2
));
1025 cutoff_mask
= _mm_cmplt_pd(rsq30
,rcutoff2
);
1029 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
1031 /* Calculate temporary vectorial force */
1032 tx
= _mm_mul_pd(fscal
,dx30
);
1033 ty
= _mm_mul_pd(fscal
,dy30
);
1034 tz
= _mm_mul_pd(fscal
,dz30
);
1036 /* Update vectorial force */
1037 fix3
= _mm_add_pd(fix3
,tx
);
1038 fiy3
= _mm_add_pd(fiy3
,ty
);
1039 fiz3
= _mm_add_pd(fiz3
,tz
);
1041 fjx0
= _mm_add_pd(fjx0
,tx
);
1042 fjy0
= _mm_add_pd(fjy0
,ty
);
1043 fjz0
= _mm_add_pd(fjz0
,tz
);
1047 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,fjx0
,fjy0
,fjz0
);
1049 /* Inner loop uses 149 flops */
1052 if(jidx
<j_index_end
)
1056 j_coord_offsetA
= DIM
*jnrA
;
1058 /* load j atom coordinates */
1059 gmx_mm_load_1rvec_1ptr_swizzle_pd(x
+j_coord_offsetA
,
1062 /* Calculate displacement vector */
1063 dx00
= _mm_sub_pd(ix0
,jx0
);
1064 dy00
= _mm_sub_pd(iy0
,jy0
);
1065 dz00
= _mm_sub_pd(iz0
,jz0
);
1066 dx10
= _mm_sub_pd(ix1
,jx0
);
1067 dy10
= _mm_sub_pd(iy1
,jy0
);
1068 dz10
= _mm_sub_pd(iz1
,jz0
);
1069 dx20
= _mm_sub_pd(ix2
,jx0
);
1070 dy20
= _mm_sub_pd(iy2
,jy0
);
1071 dz20
= _mm_sub_pd(iz2
,jz0
);
1072 dx30
= _mm_sub_pd(ix3
,jx0
);
1073 dy30
= _mm_sub_pd(iy3
,jy0
);
1074 dz30
= _mm_sub_pd(iz3
,jz0
);
1076 /* Calculate squared distance and things based on it */
1077 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
1078 rsq10
= gmx_mm_calc_rsq_pd(dx10
,dy10
,dz10
);
1079 rsq20
= gmx_mm_calc_rsq_pd(dx20
,dy20
,dz20
);
1080 rsq30
= gmx_mm_calc_rsq_pd(dx30
,dy30
,dz30
);
1082 rinv00
= sse2_invsqrt_d(rsq00
);
1083 rinv10
= sse2_invsqrt_d(rsq10
);
1084 rinv20
= sse2_invsqrt_d(rsq20
);
1085 rinv30
= sse2_invsqrt_d(rsq30
);
1087 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
1088 rinvsq10
= _mm_mul_pd(rinv10
,rinv10
);
1089 rinvsq20
= _mm_mul_pd(rinv20
,rinv20
);
1090 rinvsq30
= _mm_mul_pd(rinv30
,rinv30
);
1092 /* Load parameters for j particles */
1093 jq0
= _mm_load_sd(charge
+jnrA
+0);
1094 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
1096 fjx0
= _mm_setzero_pd();
1097 fjy0
= _mm_setzero_pd();
1098 fjz0
= _mm_setzero_pd();
1100 /**************************
1101 * CALCULATE INTERACTIONS *
1102 **************************/
1104 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
1107 r00
= _mm_mul_pd(rsq00
,rinv00
);
1109 /* Compute parameters for interactions between i and j atoms */
1110 gmx_mm_load_1pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,&c6_00
,&c12_00
);
1112 /* LENNARD-JONES DISPERSION/REPULSION */
1114 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
1115 vvdw6
= _mm_mul_pd(c6_00
,rinvsix
);
1116 vvdw12
= _mm_mul_pd(c12_00
,_mm_mul_pd(rinvsix
,rinvsix
));
1117 vvdw
= _mm_sub_pd( _mm_mul_pd(vvdw12
,one_twelfth
) , _mm_mul_pd(vvdw6
,one_sixth
) );
1118 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
1120 d
= _mm_sub_pd(r00
,rswitch
);
1121 d
= _mm_max_pd(d
,_mm_setzero_pd());
1122 d2
= _mm_mul_pd(d
,d
);
1123 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
)))))));
1125 dsw
= _mm_mul_pd(d2
,_mm_add_pd(swF2
,_mm_mul_pd(d
,_mm_add_pd(swF3
,_mm_mul_pd(d
,swF4
)))));
1127 /* Evaluate switch function */
1128 /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1129 fvdw
= _mm_sub_pd( _mm_mul_pd(fvdw
,sw
) , _mm_mul_pd(rinv00
,_mm_mul_pd(vvdw
,dsw
)) );
1130 cutoff_mask
= _mm_cmplt_pd(rsq00
,rcutoff2
);
1134 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
1136 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
1138 /* Calculate temporary vectorial force */
1139 tx
= _mm_mul_pd(fscal
,dx00
);
1140 ty
= _mm_mul_pd(fscal
,dy00
);
1141 tz
= _mm_mul_pd(fscal
,dz00
);
1143 /* Update vectorial force */
1144 fix0
= _mm_add_pd(fix0
,tx
);
1145 fiy0
= _mm_add_pd(fiy0
,ty
);
1146 fiz0
= _mm_add_pd(fiz0
,tz
);
1148 fjx0
= _mm_add_pd(fjx0
,tx
);
1149 fjy0
= _mm_add_pd(fjy0
,ty
);
1150 fjz0
= _mm_add_pd(fjz0
,tz
);
1154 /**************************
1155 * CALCULATE INTERACTIONS *
1156 **************************/
1158 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
1161 /* Compute parameters for interactions between i and j atoms */
1162 qq10
= _mm_mul_pd(iq1
,jq0
);
1164 /* REACTION-FIELD ELECTROSTATICS */
1165 felec
= _mm_mul_pd(qq10
,_mm_sub_pd(_mm_mul_pd(rinv10
,rinvsq10
),krf2
));
1167 cutoff_mask
= _mm_cmplt_pd(rsq10
,rcutoff2
);
1171 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
1173 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
1175 /* Calculate temporary vectorial force */
1176 tx
= _mm_mul_pd(fscal
,dx10
);
1177 ty
= _mm_mul_pd(fscal
,dy10
);
1178 tz
= _mm_mul_pd(fscal
,dz10
);
1180 /* Update vectorial force */
1181 fix1
= _mm_add_pd(fix1
,tx
);
1182 fiy1
= _mm_add_pd(fiy1
,ty
);
1183 fiz1
= _mm_add_pd(fiz1
,tz
);
1185 fjx0
= _mm_add_pd(fjx0
,tx
);
1186 fjy0
= _mm_add_pd(fjy0
,ty
);
1187 fjz0
= _mm_add_pd(fjz0
,tz
);
1191 /**************************
1192 * CALCULATE INTERACTIONS *
1193 **************************/
1195 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
1198 /* Compute parameters for interactions between i and j atoms */
1199 qq20
= _mm_mul_pd(iq2
,jq0
);
1201 /* REACTION-FIELD ELECTROSTATICS */
1202 felec
= _mm_mul_pd(qq20
,_mm_sub_pd(_mm_mul_pd(rinv20
,rinvsq20
),krf2
));
1204 cutoff_mask
= _mm_cmplt_pd(rsq20
,rcutoff2
);
1208 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
1210 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
1212 /* Calculate temporary vectorial force */
1213 tx
= _mm_mul_pd(fscal
,dx20
);
1214 ty
= _mm_mul_pd(fscal
,dy20
);
1215 tz
= _mm_mul_pd(fscal
,dz20
);
1217 /* Update vectorial force */
1218 fix2
= _mm_add_pd(fix2
,tx
);
1219 fiy2
= _mm_add_pd(fiy2
,ty
);
1220 fiz2
= _mm_add_pd(fiz2
,tz
);
1222 fjx0
= _mm_add_pd(fjx0
,tx
);
1223 fjy0
= _mm_add_pd(fjy0
,ty
);
1224 fjz0
= _mm_add_pd(fjz0
,tz
);
1228 /**************************
1229 * CALCULATE INTERACTIONS *
1230 **************************/
1232 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
1235 /* Compute parameters for interactions between i and j atoms */
1236 qq30
= _mm_mul_pd(iq3
,jq0
);
1238 /* REACTION-FIELD ELECTROSTATICS */
1239 felec
= _mm_mul_pd(qq30
,_mm_sub_pd(_mm_mul_pd(rinv30
,rinvsq30
),krf2
));
1241 cutoff_mask
= _mm_cmplt_pd(rsq30
,rcutoff2
);
1245 fscal
= _mm_and_pd(fscal
,cutoff_mask
);
1247 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
1249 /* Calculate temporary vectorial force */
1250 tx
= _mm_mul_pd(fscal
,dx30
);
1251 ty
= _mm_mul_pd(fscal
,dy30
);
1252 tz
= _mm_mul_pd(fscal
,dz30
);
1254 /* Update vectorial force */
1255 fix3
= _mm_add_pd(fix3
,tx
);
1256 fiy3
= _mm_add_pd(fiy3
,ty
);
1257 fiz3
= _mm_add_pd(fiz3
,tz
);
1259 fjx0
= _mm_add_pd(fjx0
,tx
);
1260 fjy0
= _mm_add_pd(fjy0
,ty
);
1261 fjz0
= _mm_add_pd(fjz0
,tz
);
1265 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f
+j_coord_offsetA
,fjx0
,fjy0
,fjz0
);
1267 /* Inner loop uses 149 flops */
1270 /* End of innermost loop */
1272 gmx_mm_update_iforce_4atom_swizzle_pd(fix0
,fiy0
,fiz0
,fix1
,fiy1
,fiz1
,fix2
,fiy2
,fiz2
,fix3
,fiy3
,fiz3
,
1273 f
+i_coord_offset
,fshift
+i_shift_offset
);
1275 /* Increment number of inner iterations */
1276 inneriter
+= j_index_end
- j_index_start
;
1278 /* Outer loop uses 24 flops */
1281 /* Increment number of outer iterations */
1284 /* Update outer/inner flops */
1286 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_VDW_W4_F
,outeriter
*24 + inneriter
*149);