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_ElecRFCut_VdwLJSh_GeomW4P1_VF_sse4_1_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_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
;
86 __m128 ix1
,iy1
,iz1
,fix1
,fiy1
,fiz1
,iq1
,isai1
;
88 __m128 ix2
,iy2
,iz2
,fix2
,fiy2
,fiz2
,iq2
,isai2
;
90 __m128 ix3
,iy3
,iz3
,fix3
,fiy3
,fiz3
,iq3
,isai3
;
91 int vdwjidx0A
,vdwjidx0B
,vdwjidx0C
,vdwjidx0D
;
92 __m128 jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
93 __m128 dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
94 __m128 dx10
,dy10
,dz10
,rsq10
,rinv10
,rinvsq10
,r10
,qq10
,c6_10
,c12_10
;
95 __m128 dx20
,dy20
,dz20
,rsq20
,rinv20
,rinvsq20
,r20
,qq20
,c6_20
,c12_20
;
96 __m128 dx30
,dy30
,dz30
,rsq30
,rinv30
,rinvsq30
,r30
,qq30
,c6_30
,c12_30
;
97 __m128 velec
,felec
,velecsum
,facel
,crf
,krf
,krf2
;
100 __m128 rinvsix
,rvdw
,vvdw
,vvdw6
,vvdw12
,fvdw
,fvdw6
,fvdw12
,vvdwsum
,sh_vdw_invrcut6
;
103 __m128 one_sixth
= _mm_set1_ps(1.0/6.0);
104 __m128 one_twelfth
= _mm_set1_ps(1.0/12.0);
105 __m128 dummy_mask
,cutoff_mask
;
106 __m128 signbit
= _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107 __m128 one
= _mm_set1_ps(1.0);
108 __m128 two
= _mm_set1_ps(2.0);
114 jindex
= nlist
->jindex
;
116 shiftidx
= nlist
->shift
;
118 shiftvec
= fr
->shift_vec
[0];
119 fshift
= fr
->fshift
[0];
120 facel
= _mm_set1_ps(fr
->epsfac
);
121 charge
= mdatoms
->chargeA
;
122 krf
= _mm_set1_ps(fr
->ic
->k_rf
);
123 krf2
= _mm_set1_ps(fr
->ic
->k_rf
*2.0);
124 crf
= _mm_set1_ps(fr
->ic
->c_rf
);
125 nvdwtype
= fr
->ntype
;
127 vdwtype
= mdatoms
->typeA
;
129 /* Setup water-specific parameters */
130 inr
= nlist
->iinr
[0];
131 iq1
= _mm_mul_ps(facel
,_mm_set1_ps(charge
[inr
+1]));
132 iq2
= _mm_mul_ps(facel
,_mm_set1_ps(charge
[inr
+2]));
133 iq3
= _mm_mul_ps(facel
,_mm_set1_ps(charge
[inr
+3]));
134 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
136 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
137 rcutoff_scalar
= fr
->rcoulomb
;
138 rcutoff
= _mm_set1_ps(rcutoff_scalar
);
139 rcutoff2
= _mm_mul_ps(rcutoff
,rcutoff
);
141 sh_vdw_invrcut6
= _mm_set1_ps(fr
->ic
->sh_invrc6
);
142 rvdw
= _mm_set1_ps(fr
->rvdw
);
144 /* Avoid stupid compiler warnings */
145 jnrA
= jnrB
= jnrC
= jnrD
= 0;
154 for(iidx
=0;iidx
<4*DIM
;iidx
++)
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_ps(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_ps();
178 fiy0
= _mm_setzero_ps();
179 fiz0
= _mm_setzero_ps();
180 fix1
= _mm_setzero_ps();
181 fiy1
= _mm_setzero_ps();
182 fiz1
= _mm_setzero_ps();
183 fix2
= _mm_setzero_ps();
184 fiy2
= _mm_setzero_ps();
185 fiz2
= _mm_setzero_ps();
186 fix3
= _mm_setzero_ps();
187 fiy3
= _mm_setzero_ps();
188 fiz3
= _mm_setzero_ps();
190 /* Reset potential sums */
191 velecsum
= _mm_setzero_ps();
192 vvdwsum
= _mm_setzero_ps();
194 /* Start inner kernel loop */
195 for(jidx
=j_index_start
; jidx
<j_index_end
&& jjnr
[jidx
+3]>=0; jidx
+=4)
198 /* Get j neighbor index, and coordinate index */
203 j_coord_offsetA
= DIM
*jnrA
;
204 j_coord_offsetB
= DIM
*jnrB
;
205 j_coord_offsetC
= DIM
*jnrC
;
206 j_coord_offsetD
= DIM
*jnrD
;
208 /* load j atom coordinates */
209 gmx_mm_load_1rvec_4ptr_swizzle_ps(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
210 x
+j_coord_offsetC
,x
+j_coord_offsetD
,
213 /* Calculate displacement vector */
214 dx00
= _mm_sub_ps(ix0
,jx0
);
215 dy00
= _mm_sub_ps(iy0
,jy0
);
216 dz00
= _mm_sub_ps(iz0
,jz0
);
217 dx10
= _mm_sub_ps(ix1
,jx0
);
218 dy10
= _mm_sub_ps(iy1
,jy0
);
219 dz10
= _mm_sub_ps(iz1
,jz0
);
220 dx20
= _mm_sub_ps(ix2
,jx0
);
221 dy20
= _mm_sub_ps(iy2
,jy0
);
222 dz20
= _mm_sub_ps(iz2
,jz0
);
223 dx30
= _mm_sub_ps(ix3
,jx0
);
224 dy30
= _mm_sub_ps(iy3
,jy0
);
225 dz30
= _mm_sub_ps(iz3
,jz0
);
227 /* Calculate squared distance and things based on it */
228 rsq00
= gmx_mm_calc_rsq_ps(dx00
,dy00
,dz00
);
229 rsq10
= gmx_mm_calc_rsq_ps(dx10
,dy10
,dz10
);
230 rsq20
= gmx_mm_calc_rsq_ps(dx20
,dy20
,dz20
);
231 rsq30
= gmx_mm_calc_rsq_ps(dx30
,dy30
,dz30
);
233 rinv10
= gmx_mm_invsqrt_ps(rsq10
);
234 rinv20
= gmx_mm_invsqrt_ps(rsq20
);
235 rinv30
= gmx_mm_invsqrt_ps(rsq30
);
237 rinvsq00
= gmx_mm_inv_ps(rsq00
);
238 rinvsq10
= _mm_mul_ps(rinv10
,rinv10
);
239 rinvsq20
= _mm_mul_ps(rinv20
,rinv20
);
240 rinvsq30
= _mm_mul_ps(rinv30
,rinv30
);
242 /* Load parameters for j particles */
243 jq0
= gmx_mm_load_4real_swizzle_ps(charge
+jnrA
+0,charge
+jnrB
+0,
244 charge
+jnrC
+0,charge
+jnrD
+0);
245 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
246 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
247 vdwjidx0C
= 2*vdwtype
[jnrC
+0];
248 vdwjidx0D
= 2*vdwtype
[jnrD
+0];
250 fjx0
= _mm_setzero_ps();
251 fjy0
= _mm_setzero_ps();
252 fjz0
= _mm_setzero_ps();
254 /**************************
255 * CALCULATE INTERACTIONS *
256 **************************/
258 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
261 /* Compute parameters for interactions between i and j atoms */
262 gmx_mm_load_4pair_swizzle_ps(vdwparam
+vdwioffset0
+vdwjidx0A
,
263 vdwparam
+vdwioffset0
+vdwjidx0B
,
264 vdwparam
+vdwioffset0
+vdwjidx0C
,
265 vdwparam
+vdwioffset0
+vdwjidx0D
,
268 /* LENNARD-JONES DISPERSION/REPULSION */
270 rinvsix
= _mm_mul_ps(_mm_mul_ps(rinvsq00
,rinvsq00
),rinvsq00
);
271 vvdw6
= _mm_mul_ps(c6_00
,rinvsix
);
272 vvdw12
= _mm_mul_ps(c12_00
,_mm_mul_ps(rinvsix
,rinvsix
));
273 vvdw
= _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12
, _mm_mul_ps(c12_00
,_mm_mul_ps(sh_vdw_invrcut6
,sh_vdw_invrcut6
))), one_twelfth
) ,
274 _mm_mul_ps( _mm_sub_ps(vvdw6
,_mm_mul_ps(c6_00
,sh_vdw_invrcut6
)),one_sixth
));
275 fvdw
= _mm_mul_ps(_mm_sub_ps(vvdw12
,vvdw6
),rinvsq00
);
277 cutoff_mask
= _mm_cmplt_ps(rsq00
,rcutoff2
);
279 /* Update potential sum for this i atom from the interaction with this j atom. */
280 vvdw
= _mm_and_ps(vvdw
,cutoff_mask
);
281 vvdwsum
= _mm_add_ps(vvdwsum
,vvdw
);
285 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
287 /* Calculate temporary vectorial force */
288 tx
= _mm_mul_ps(fscal
,dx00
);
289 ty
= _mm_mul_ps(fscal
,dy00
);
290 tz
= _mm_mul_ps(fscal
,dz00
);
292 /* Update vectorial force */
293 fix0
= _mm_add_ps(fix0
,tx
);
294 fiy0
= _mm_add_ps(fiy0
,ty
);
295 fiz0
= _mm_add_ps(fiz0
,tz
);
297 fjx0
= _mm_add_ps(fjx0
,tx
);
298 fjy0
= _mm_add_ps(fjy0
,ty
);
299 fjz0
= _mm_add_ps(fjz0
,tz
);
303 /**************************
304 * CALCULATE INTERACTIONS *
305 **************************/
307 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
310 /* Compute parameters for interactions between i and j atoms */
311 qq10
= _mm_mul_ps(iq1
,jq0
);
313 /* REACTION-FIELD ELECTROSTATICS */
314 velec
= _mm_mul_ps(qq10
,_mm_sub_ps(_mm_add_ps(rinv10
,_mm_mul_ps(krf
,rsq10
)),crf
));
315 felec
= _mm_mul_ps(qq10
,_mm_sub_ps(_mm_mul_ps(rinv10
,rinvsq10
),krf2
));
317 cutoff_mask
= _mm_cmplt_ps(rsq10
,rcutoff2
);
319 /* Update potential sum for this i atom from the interaction with this j atom. */
320 velec
= _mm_and_ps(velec
,cutoff_mask
);
321 velecsum
= _mm_add_ps(velecsum
,velec
);
325 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
327 /* Calculate temporary vectorial force */
328 tx
= _mm_mul_ps(fscal
,dx10
);
329 ty
= _mm_mul_ps(fscal
,dy10
);
330 tz
= _mm_mul_ps(fscal
,dz10
);
332 /* Update vectorial force */
333 fix1
= _mm_add_ps(fix1
,tx
);
334 fiy1
= _mm_add_ps(fiy1
,ty
);
335 fiz1
= _mm_add_ps(fiz1
,tz
);
337 fjx0
= _mm_add_ps(fjx0
,tx
);
338 fjy0
= _mm_add_ps(fjy0
,ty
);
339 fjz0
= _mm_add_ps(fjz0
,tz
);
343 /**************************
344 * CALCULATE INTERACTIONS *
345 **************************/
347 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
350 /* Compute parameters for interactions between i and j atoms */
351 qq20
= _mm_mul_ps(iq2
,jq0
);
353 /* REACTION-FIELD ELECTROSTATICS */
354 velec
= _mm_mul_ps(qq20
,_mm_sub_ps(_mm_add_ps(rinv20
,_mm_mul_ps(krf
,rsq20
)),crf
));
355 felec
= _mm_mul_ps(qq20
,_mm_sub_ps(_mm_mul_ps(rinv20
,rinvsq20
),krf2
));
357 cutoff_mask
= _mm_cmplt_ps(rsq20
,rcutoff2
);
359 /* Update potential sum for this i atom from the interaction with this j atom. */
360 velec
= _mm_and_ps(velec
,cutoff_mask
);
361 velecsum
= _mm_add_ps(velecsum
,velec
);
365 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
367 /* Calculate temporary vectorial force */
368 tx
= _mm_mul_ps(fscal
,dx20
);
369 ty
= _mm_mul_ps(fscal
,dy20
);
370 tz
= _mm_mul_ps(fscal
,dz20
);
372 /* Update vectorial force */
373 fix2
= _mm_add_ps(fix2
,tx
);
374 fiy2
= _mm_add_ps(fiy2
,ty
);
375 fiz2
= _mm_add_ps(fiz2
,tz
);
377 fjx0
= _mm_add_ps(fjx0
,tx
);
378 fjy0
= _mm_add_ps(fjy0
,ty
);
379 fjz0
= _mm_add_ps(fjz0
,tz
);
383 /**************************
384 * CALCULATE INTERACTIONS *
385 **************************/
387 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
390 /* Compute parameters for interactions between i and j atoms */
391 qq30
= _mm_mul_ps(iq3
,jq0
);
393 /* REACTION-FIELD ELECTROSTATICS */
394 velec
= _mm_mul_ps(qq30
,_mm_sub_ps(_mm_add_ps(rinv30
,_mm_mul_ps(krf
,rsq30
)),crf
));
395 felec
= _mm_mul_ps(qq30
,_mm_sub_ps(_mm_mul_ps(rinv30
,rinvsq30
),krf2
));
397 cutoff_mask
= _mm_cmplt_ps(rsq30
,rcutoff2
);
399 /* Update potential sum for this i atom from the interaction with this j atom. */
400 velec
= _mm_and_ps(velec
,cutoff_mask
);
401 velecsum
= _mm_add_ps(velecsum
,velec
);
405 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
407 /* Calculate temporary vectorial force */
408 tx
= _mm_mul_ps(fscal
,dx30
);
409 ty
= _mm_mul_ps(fscal
,dy30
);
410 tz
= _mm_mul_ps(fscal
,dz30
);
412 /* Update vectorial force */
413 fix3
= _mm_add_ps(fix3
,tx
);
414 fiy3
= _mm_add_ps(fiy3
,ty
);
415 fiz3
= _mm_add_ps(fiz3
,tz
);
417 fjx0
= _mm_add_ps(fjx0
,tx
);
418 fjy0
= _mm_add_ps(fjy0
,ty
);
419 fjz0
= _mm_add_ps(fjz0
,tz
);
423 fjptrA
= f
+j_coord_offsetA
;
424 fjptrB
= f
+j_coord_offsetB
;
425 fjptrC
= f
+j_coord_offsetC
;
426 fjptrD
= f
+j_coord_offsetD
;
428 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA
,fjptrB
,fjptrC
,fjptrD
,fjx0
,fjy0
,fjz0
);
430 /* Inner loop uses 149 flops */
436 /* Get j neighbor index, and coordinate index */
437 jnrlistA
= jjnr
[jidx
];
438 jnrlistB
= jjnr
[jidx
+1];
439 jnrlistC
= jjnr
[jidx
+2];
440 jnrlistD
= jjnr
[jidx
+3];
441 /* Sign of each element will be negative for non-real atoms.
442 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
443 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
445 dummy_mask
= gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i
*)(jjnr
+jidx
)),_mm_setzero_si128()));
446 jnrA
= (jnrlistA
>=0) ? jnrlistA
: 0;
447 jnrB
= (jnrlistB
>=0) ? jnrlistB
: 0;
448 jnrC
= (jnrlistC
>=0) ? jnrlistC
: 0;
449 jnrD
= (jnrlistD
>=0) ? jnrlistD
: 0;
450 j_coord_offsetA
= DIM
*jnrA
;
451 j_coord_offsetB
= DIM
*jnrB
;
452 j_coord_offsetC
= DIM
*jnrC
;
453 j_coord_offsetD
= DIM
*jnrD
;
455 /* load j atom coordinates */
456 gmx_mm_load_1rvec_4ptr_swizzle_ps(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
457 x
+j_coord_offsetC
,x
+j_coord_offsetD
,
460 /* Calculate displacement vector */
461 dx00
= _mm_sub_ps(ix0
,jx0
);
462 dy00
= _mm_sub_ps(iy0
,jy0
);
463 dz00
= _mm_sub_ps(iz0
,jz0
);
464 dx10
= _mm_sub_ps(ix1
,jx0
);
465 dy10
= _mm_sub_ps(iy1
,jy0
);
466 dz10
= _mm_sub_ps(iz1
,jz0
);
467 dx20
= _mm_sub_ps(ix2
,jx0
);
468 dy20
= _mm_sub_ps(iy2
,jy0
);
469 dz20
= _mm_sub_ps(iz2
,jz0
);
470 dx30
= _mm_sub_ps(ix3
,jx0
);
471 dy30
= _mm_sub_ps(iy3
,jy0
);
472 dz30
= _mm_sub_ps(iz3
,jz0
);
474 /* Calculate squared distance and things based on it */
475 rsq00
= gmx_mm_calc_rsq_ps(dx00
,dy00
,dz00
);
476 rsq10
= gmx_mm_calc_rsq_ps(dx10
,dy10
,dz10
);
477 rsq20
= gmx_mm_calc_rsq_ps(dx20
,dy20
,dz20
);
478 rsq30
= gmx_mm_calc_rsq_ps(dx30
,dy30
,dz30
);
480 rinv10
= gmx_mm_invsqrt_ps(rsq10
);
481 rinv20
= gmx_mm_invsqrt_ps(rsq20
);
482 rinv30
= gmx_mm_invsqrt_ps(rsq30
);
484 rinvsq00
= gmx_mm_inv_ps(rsq00
);
485 rinvsq10
= _mm_mul_ps(rinv10
,rinv10
);
486 rinvsq20
= _mm_mul_ps(rinv20
,rinv20
);
487 rinvsq30
= _mm_mul_ps(rinv30
,rinv30
);
489 /* Load parameters for j particles */
490 jq0
= gmx_mm_load_4real_swizzle_ps(charge
+jnrA
+0,charge
+jnrB
+0,
491 charge
+jnrC
+0,charge
+jnrD
+0);
492 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
493 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
494 vdwjidx0C
= 2*vdwtype
[jnrC
+0];
495 vdwjidx0D
= 2*vdwtype
[jnrD
+0];
497 fjx0
= _mm_setzero_ps();
498 fjy0
= _mm_setzero_ps();
499 fjz0
= _mm_setzero_ps();
501 /**************************
502 * CALCULATE INTERACTIONS *
503 **************************/
505 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
508 /* Compute parameters for interactions between i and j atoms */
509 gmx_mm_load_4pair_swizzle_ps(vdwparam
+vdwioffset0
+vdwjidx0A
,
510 vdwparam
+vdwioffset0
+vdwjidx0B
,
511 vdwparam
+vdwioffset0
+vdwjidx0C
,
512 vdwparam
+vdwioffset0
+vdwjidx0D
,
515 /* LENNARD-JONES DISPERSION/REPULSION */
517 rinvsix
= _mm_mul_ps(_mm_mul_ps(rinvsq00
,rinvsq00
),rinvsq00
);
518 vvdw6
= _mm_mul_ps(c6_00
,rinvsix
);
519 vvdw12
= _mm_mul_ps(c12_00
,_mm_mul_ps(rinvsix
,rinvsix
));
520 vvdw
= _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12
, _mm_mul_ps(c12_00
,_mm_mul_ps(sh_vdw_invrcut6
,sh_vdw_invrcut6
))), one_twelfth
) ,
521 _mm_mul_ps( _mm_sub_ps(vvdw6
,_mm_mul_ps(c6_00
,sh_vdw_invrcut6
)),one_sixth
));
522 fvdw
= _mm_mul_ps(_mm_sub_ps(vvdw12
,vvdw6
),rinvsq00
);
524 cutoff_mask
= _mm_cmplt_ps(rsq00
,rcutoff2
);
526 /* Update potential sum for this i atom from the interaction with this j atom. */
527 vvdw
= _mm_and_ps(vvdw
,cutoff_mask
);
528 vvdw
= _mm_andnot_ps(dummy_mask
,vvdw
);
529 vvdwsum
= _mm_add_ps(vvdwsum
,vvdw
);
533 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
535 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
537 /* Calculate temporary vectorial force */
538 tx
= _mm_mul_ps(fscal
,dx00
);
539 ty
= _mm_mul_ps(fscal
,dy00
);
540 tz
= _mm_mul_ps(fscal
,dz00
);
542 /* Update vectorial force */
543 fix0
= _mm_add_ps(fix0
,tx
);
544 fiy0
= _mm_add_ps(fiy0
,ty
);
545 fiz0
= _mm_add_ps(fiz0
,tz
);
547 fjx0
= _mm_add_ps(fjx0
,tx
);
548 fjy0
= _mm_add_ps(fjy0
,ty
);
549 fjz0
= _mm_add_ps(fjz0
,tz
);
553 /**************************
554 * CALCULATE INTERACTIONS *
555 **************************/
557 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
560 /* Compute parameters for interactions between i and j atoms */
561 qq10
= _mm_mul_ps(iq1
,jq0
);
563 /* REACTION-FIELD ELECTROSTATICS */
564 velec
= _mm_mul_ps(qq10
,_mm_sub_ps(_mm_add_ps(rinv10
,_mm_mul_ps(krf
,rsq10
)),crf
));
565 felec
= _mm_mul_ps(qq10
,_mm_sub_ps(_mm_mul_ps(rinv10
,rinvsq10
),krf2
));
567 cutoff_mask
= _mm_cmplt_ps(rsq10
,rcutoff2
);
569 /* Update potential sum for this i atom from the interaction with this j atom. */
570 velec
= _mm_and_ps(velec
,cutoff_mask
);
571 velec
= _mm_andnot_ps(dummy_mask
,velec
);
572 velecsum
= _mm_add_ps(velecsum
,velec
);
576 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
578 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
580 /* Calculate temporary vectorial force */
581 tx
= _mm_mul_ps(fscal
,dx10
);
582 ty
= _mm_mul_ps(fscal
,dy10
);
583 tz
= _mm_mul_ps(fscal
,dz10
);
585 /* Update vectorial force */
586 fix1
= _mm_add_ps(fix1
,tx
);
587 fiy1
= _mm_add_ps(fiy1
,ty
);
588 fiz1
= _mm_add_ps(fiz1
,tz
);
590 fjx0
= _mm_add_ps(fjx0
,tx
);
591 fjy0
= _mm_add_ps(fjy0
,ty
);
592 fjz0
= _mm_add_ps(fjz0
,tz
);
596 /**************************
597 * CALCULATE INTERACTIONS *
598 **************************/
600 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
603 /* Compute parameters for interactions between i and j atoms */
604 qq20
= _mm_mul_ps(iq2
,jq0
);
606 /* REACTION-FIELD ELECTROSTATICS */
607 velec
= _mm_mul_ps(qq20
,_mm_sub_ps(_mm_add_ps(rinv20
,_mm_mul_ps(krf
,rsq20
)),crf
));
608 felec
= _mm_mul_ps(qq20
,_mm_sub_ps(_mm_mul_ps(rinv20
,rinvsq20
),krf2
));
610 cutoff_mask
= _mm_cmplt_ps(rsq20
,rcutoff2
);
612 /* Update potential sum for this i atom from the interaction with this j atom. */
613 velec
= _mm_and_ps(velec
,cutoff_mask
);
614 velec
= _mm_andnot_ps(dummy_mask
,velec
);
615 velecsum
= _mm_add_ps(velecsum
,velec
);
619 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
621 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
623 /* Calculate temporary vectorial force */
624 tx
= _mm_mul_ps(fscal
,dx20
);
625 ty
= _mm_mul_ps(fscal
,dy20
);
626 tz
= _mm_mul_ps(fscal
,dz20
);
628 /* Update vectorial force */
629 fix2
= _mm_add_ps(fix2
,tx
);
630 fiy2
= _mm_add_ps(fiy2
,ty
);
631 fiz2
= _mm_add_ps(fiz2
,tz
);
633 fjx0
= _mm_add_ps(fjx0
,tx
);
634 fjy0
= _mm_add_ps(fjy0
,ty
);
635 fjz0
= _mm_add_ps(fjz0
,tz
);
639 /**************************
640 * CALCULATE INTERACTIONS *
641 **************************/
643 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
646 /* Compute parameters for interactions between i and j atoms */
647 qq30
= _mm_mul_ps(iq3
,jq0
);
649 /* REACTION-FIELD ELECTROSTATICS */
650 velec
= _mm_mul_ps(qq30
,_mm_sub_ps(_mm_add_ps(rinv30
,_mm_mul_ps(krf
,rsq30
)),crf
));
651 felec
= _mm_mul_ps(qq30
,_mm_sub_ps(_mm_mul_ps(rinv30
,rinvsq30
),krf2
));
653 cutoff_mask
= _mm_cmplt_ps(rsq30
,rcutoff2
);
655 /* Update potential sum for this i atom from the interaction with this j atom. */
656 velec
= _mm_and_ps(velec
,cutoff_mask
);
657 velec
= _mm_andnot_ps(dummy_mask
,velec
);
658 velecsum
= _mm_add_ps(velecsum
,velec
);
662 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
664 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
666 /* Calculate temporary vectorial force */
667 tx
= _mm_mul_ps(fscal
,dx30
);
668 ty
= _mm_mul_ps(fscal
,dy30
);
669 tz
= _mm_mul_ps(fscal
,dz30
);
671 /* Update vectorial force */
672 fix3
= _mm_add_ps(fix3
,tx
);
673 fiy3
= _mm_add_ps(fiy3
,ty
);
674 fiz3
= _mm_add_ps(fiz3
,tz
);
676 fjx0
= _mm_add_ps(fjx0
,tx
);
677 fjy0
= _mm_add_ps(fjy0
,ty
);
678 fjz0
= _mm_add_ps(fjz0
,tz
);
682 fjptrA
= (jnrlistA
>=0) ? f
+j_coord_offsetA
: scratch
;
683 fjptrB
= (jnrlistB
>=0) ? f
+j_coord_offsetB
: scratch
;
684 fjptrC
= (jnrlistC
>=0) ? f
+j_coord_offsetC
: scratch
;
685 fjptrD
= (jnrlistD
>=0) ? f
+j_coord_offsetD
: scratch
;
687 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA
,fjptrB
,fjptrC
,fjptrD
,fjx0
,fjy0
,fjz0
);
689 /* Inner loop uses 149 flops */
692 /* End of innermost loop */
694 gmx_mm_update_iforce_4atom_swizzle_ps(fix0
,fiy0
,fiz0
,fix1
,fiy1
,fiz1
,fix2
,fiy2
,fiz2
,fix3
,fiy3
,fiz3
,
695 f
+i_coord_offset
,fshift
+i_shift_offset
);
698 /* Update potential energies */
699 gmx_mm_update_1pot_ps(velecsum
,kernel_data
->energygrp_elec
+ggid
);
700 gmx_mm_update_1pot_ps(vvdwsum
,kernel_data
->energygrp_vdw
+ggid
);
702 /* Increment number of inner iterations */
703 inneriter
+= j_index_end
- j_index_start
;
705 /* Outer loop uses 26 flops */
708 /* Increment number of outer iterations */
711 /* Update outer/inner flops */
713 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_VDW_W4_VF
,outeriter
*26 + inneriter
*149);
716 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_sse4_1_single
717 * Electrostatics interaction: ReactionField
718 * VdW interaction: LennardJones
719 * Geometry: Water4-Particle
720 * Calculate force/pot: Force
723 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_sse4_1_single
724 (t_nblist
* gmx_restrict nlist
,
725 rvec
* gmx_restrict xx
,
726 rvec
* gmx_restrict ff
,
727 t_forcerec
* gmx_restrict fr
,
728 t_mdatoms
* gmx_restrict mdatoms
,
729 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
730 t_nrnb
* gmx_restrict nrnb
)
732 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
733 * just 0 for non-waters.
734 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
735 * jnr indices corresponding to data put in the four positions in the SIMD register.
737 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
738 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
739 int jnrA
,jnrB
,jnrC
,jnrD
;
740 int jnrlistA
,jnrlistB
,jnrlistC
,jnrlistD
;
741 int j_coord_offsetA
,j_coord_offsetB
,j_coord_offsetC
,j_coord_offsetD
;
742 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
744 real
*shiftvec
,*fshift
,*x
,*f
;
745 real
*fjptrA
,*fjptrB
,*fjptrC
,*fjptrD
;
747 __m128 tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
749 __m128 ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
751 __m128 ix1
,iy1
,iz1
,fix1
,fiy1
,fiz1
,iq1
,isai1
;
753 __m128 ix2
,iy2
,iz2
,fix2
,fiy2
,fiz2
,iq2
,isai2
;
755 __m128 ix3
,iy3
,iz3
,fix3
,fiy3
,fiz3
,iq3
,isai3
;
756 int vdwjidx0A
,vdwjidx0B
,vdwjidx0C
,vdwjidx0D
;
757 __m128 jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
758 __m128 dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
759 __m128 dx10
,dy10
,dz10
,rsq10
,rinv10
,rinvsq10
,r10
,qq10
,c6_10
,c12_10
;
760 __m128 dx20
,dy20
,dz20
,rsq20
,rinv20
,rinvsq20
,r20
,qq20
,c6_20
,c12_20
;
761 __m128 dx30
,dy30
,dz30
,rsq30
,rinv30
,rinvsq30
,r30
,qq30
,c6_30
,c12_30
;
762 __m128 velec
,felec
,velecsum
,facel
,crf
,krf
,krf2
;
765 __m128 rinvsix
,rvdw
,vvdw
,vvdw6
,vvdw12
,fvdw
,fvdw6
,fvdw12
,vvdwsum
,sh_vdw_invrcut6
;
768 __m128 one_sixth
= _mm_set1_ps(1.0/6.0);
769 __m128 one_twelfth
= _mm_set1_ps(1.0/12.0);
770 __m128 dummy_mask
,cutoff_mask
;
771 __m128 signbit
= _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
772 __m128 one
= _mm_set1_ps(1.0);
773 __m128 two
= _mm_set1_ps(2.0);
779 jindex
= nlist
->jindex
;
781 shiftidx
= nlist
->shift
;
783 shiftvec
= fr
->shift_vec
[0];
784 fshift
= fr
->fshift
[0];
785 facel
= _mm_set1_ps(fr
->epsfac
);
786 charge
= mdatoms
->chargeA
;
787 krf
= _mm_set1_ps(fr
->ic
->k_rf
);
788 krf2
= _mm_set1_ps(fr
->ic
->k_rf
*2.0);
789 crf
= _mm_set1_ps(fr
->ic
->c_rf
);
790 nvdwtype
= fr
->ntype
;
792 vdwtype
= mdatoms
->typeA
;
794 /* Setup water-specific parameters */
795 inr
= nlist
->iinr
[0];
796 iq1
= _mm_mul_ps(facel
,_mm_set1_ps(charge
[inr
+1]));
797 iq2
= _mm_mul_ps(facel
,_mm_set1_ps(charge
[inr
+2]));
798 iq3
= _mm_mul_ps(facel
,_mm_set1_ps(charge
[inr
+3]));
799 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
801 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
802 rcutoff_scalar
= fr
->rcoulomb
;
803 rcutoff
= _mm_set1_ps(rcutoff_scalar
);
804 rcutoff2
= _mm_mul_ps(rcutoff
,rcutoff
);
806 sh_vdw_invrcut6
= _mm_set1_ps(fr
->ic
->sh_invrc6
);
807 rvdw
= _mm_set1_ps(fr
->rvdw
);
809 /* Avoid stupid compiler warnings */
810 jnrA
= jnrB
= jnrC
= jnrD
= 0;
819 for(iidx
=0;iidx
<4*DIM
;iidx
++)
824 /* Start outer loop over neighborlists */
825 for(iidx
=0; iidx
<nri
; iidx
++)
827 /* Load shift vector for this list */
828 i_shift_offset
= DIM
*shiftidx
[iidx
];
830 /* Load limits for loop over neighbors */
831 j_index_start
= jindex
[iidx
];
832 j_index_end
= jindex
[iidx
+1];
834 /* Get outer coordinate index */
836 i_coord_offset
= DIM
*inr
;
838 /* Load i particle coords and add shift vector */
839 gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec
+i_shift_offset
,x
+i_coord_offset
,
840 &ix0
,&iy0
,&iz0
,&ix1
,&iy1
,&iz1
,&ix2
,&iy2
,&iz2
,&ix3
,&iy3
,&iz3
);
842 fix0
= _mm_setzero_ps();
843 fiy0
= _mm_setzero_ps();
844 fiz0
= _mm_setzero_ps();
845 fix1
= _mm_setzero_ps();
846 fiy1
= _mm_setzero_ps();
847 fiz1
= _mm_setzero_ps();
848 fix2
= _mm_setzero_ps();
849 fiy2
= _mm_setzero_ps();
850 fiz2
= _mm_setzero_ps();
851 fix3
= _mm_setzero_ps();
852 fiy3
= _mm_setzero_ps();
853 fiz3
= _mm_setzero_ps();
855 /* Start inner kernel loop */
856 for(jidx
=j_index_start
; jidx
<j_index_end
&& jjnr
[jidx
+3]>=0; jidx
+=4)
859 /* Get j neighbor index, and coordinate index */
864 j_coord_offsetA
= DIM
*jnrA
;
865 j_coord_offsetB
= DIM
*jnrB
;
866 j_coord_offsetC
= DIM
*jnrC
;
867 j_coord_offsetD
= DIM
*jnrD
;
869 /* load j atom coordinates */
870 gmx_mm_load_1rvec_4ptr_swizzle_ps(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
871 x
+j_coord_offsetC
,x
+j_coord_offsetD
,
874 /* Calculate displacement vector */
875 dx00
= _mm_sub_ps(ix0
,jx0
);
876 dy00
= _mm_sub_ps(iy0
,jy0
);
877 dz00
= _mm_sub_ps(iz0
,jz0
);
878 dx10
= _mm_sub_ps(ix1
,jx0
);
879 dy10
= _mm_sub_ps(iy1
,jy0
);
880 dz10
= _mm_sub_ps(iz1
,jz0
);
881 dx20
= _mm_sub_ps(ix2
,jx0
);
882 dy20
= _mm_sub_ps(iy2
,jy0
);
883 dz20
= _mm_sub_ps(iz2
,jz0
);
884 dx30
= _mm_sub_ps(ix3
,jx0
);
885 dy30
= _mm_sub_ps(iy3
,jy0
);
886 dz30
= _mm_sub_ps(iz3
,jz0
);
888 /* Calculate squared distance and things based on it */
889 rsq00
= gmx_mm_calc_rsq_ps(dx00
,dy00
,dz00
);
890 rsq10
= gmx_mm_calc_rsq_ps(dx10
,dy10
,dz10
);
891 rsq20
= gmx_mm_calc_rsq_ps(dx20
,dy20
,dz20
);
892 rsq30
= gmx_mm_calc_rsq_ps(dx30
,dy30
,dz30
);
894 rinv10
= gmx_mm_invsqrt_ps(rsq10
);
895 rinv20
= gmx_mm_invsqrt_ps(rsq20
);
896 rinv30
= gmx_mm_invsqrt_ps(rsq30
);
898 rinvsq00
= gmx_mm_inv_ps(rsq00
);
899 rinvsq10
= _mm_mul_ps(rinv10
,rinv10
);
900 rinvsq20
= _mm_mul_ps(rinv20
,rinv20
);
901 rinvsq30
= _mm_mul_ps(rinv30
,rinv30
);
903 /* Load parameters for j particles */
904 jq0
= gmx_mm_load_4real_swizzle_ps(charge
+jnrA
+0,charge
+jnrB
+0,
905 charge
+jnrC
+0,charge
+jnrD
+0);
906 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
907 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
908 vdwjidx0C
= 2*vdwtype
[jnrC
+0];
909 vdwjidx0D
= 2*vdwtype
[jnrD
+0];
911 fjx0
= _mm_setzero_ps();
912 fjy0
= _mm_setzero_ps();
913 fjz0
= _mm_setzero_ps();
915 /**************************
916 * CALCULATE INTERACTIONS *
917 **************************/
919 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
922 /* Compute parameters for interactions between i and j atoms */
923 gmx_mm_load_4pair_swizzle_ps(vdwparam
+vdwioffset0
+vdwjidx0A
,
924 vdwparam
+vdwioffset0
+vdwjidx0B
,
925 vdwparam
+vdwioffset0
+vdwjidx0C
,
926 vdwparam
+vdwioffset0
+vdwjidx0D
,
929 /* LENNARD-JONES DISPERSION/REPULSION */
931 rinvsix
= _mm_mul_ps(_mm_mul_ps(rinvsq00
,rinvsq00
),rinvsq00
);
932 fvdw
= _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00
,rinvsix
),c6_00
),_mm_mul_ps(rinvsix
,rinvsq00
));
934 cutoff_mask
= _mm_cmplt_ps(rsq00
,rcutoff2
);
938 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
940 /* Calculate temporary vectorial force */
941 tx
= _mm_mul_ps(fscal
,dx00
);
942 ty
= _mm_mul_ps(fscal
,dy00
);
943 tz
= _mm_mul_ps(fscal
,dz00
);
945 /* Update vectorial force */
946 fix0
= _mm_add_ps(fix0
,tx
);
947 fiy0
= _mm_add_ps(fiy0
,ty
);
948 fiz0
= _mm_add_ps(fiz0
,tz
);
950 fjx0
= _mm_add_ps(fjx0
,tx
);
951 fjy0
= _mm_add_ps(fjy0
,ty
);
952 fjz0
= _mm_add_ps(fjz0
,tz
);
956 /**************************
957 * CALCULATE INTERACTIONS *
958 **************************/
960 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
963 /* Compute parameters for interactions between i and j atoms */
964 qq10
= _mm_mul_ps(iq1
,jq0
);
966 /* REACTION-FIELD ELECTROSTATICS */
967 felec
= _mm_mul_ps(qq10
,_mm_sub_ps(_mm_mul_ps(rinv10
,rinvsq10
),krf2
));
969 cutoff_mask
= _mm_cmplt_ps(rsq10
,rcutoff2
);
973 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
975 /* Calculate temporary vectorial force */
976 tx
= _mm_mul_ps(fscal
,dx10
);
977 ty
= _mm_mul_ps(fscal
,dy10
);
978 tz
= _mm_mul_ps(fscal
,dz10
);
980 /* Update vectorial force */
981 fix1
= _mm_add_ps(fix1
,tx
);
982 fiy1
= _mm_add_ps(fiy1
,ty
);
983 fiz1
= _mm_add_ps(fiz1
,tz
);
985 fjx0
= _mm_add_ps(fjx0
,tx
);
986 fjy0
= _mm_add_ps(fjy0
,ty
);
987 fjz0
= _mm_add_ps(fjz0
,tz
);
991 /**************************
992 * CALCULATE INTERACTIONS *
993 **************************/
995 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
998 /* Compute parameters for interactions between i and j atoms */
999 qq20
= _mm_mul_ps(iq2
,jq0
);
1001 /* REACTION-FIELD ELECTROSTATICS */
1002 felec
= _mm_mul_ps(qq20
,_mm_sub_ps(_mm_mul_ps(rinv20
,rinvsq20
),krf2
));
1004 cutoff_mask
= _mm_cmplt_ps(rsq20
,rcutoff2
);
1008 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
1010 /* Calculate temporary vectorial force */
1011 tx
= _mm_mul_ps(fscal
,dx20
);
1012 ty
= _mm_mul_ps(fscal
,dy20
);
1013 tz
= _mm_mul_ps(fscal
,dz20
);
1015 /* Update vectorial force */
1016 fix2
= _mm_add_ps(fix2
,tx
);
1017 fiy2
= _mm_add_ps(fiy2
,ty
);
1018 fiz2
= _mm_add_ps(fiz2
,tz
);
1020 fjx0
= _mm_add_ps(fjx0
,tx
);
1021 fjy0
= _mm_add_ps(fjy0
,ty
);
1022 fjz0
= _mm_add_ps(fjz0
,tz
);
1026 /**************************
1027 * CALCULATE INTERACTIONS *
1028 **************************/
1030 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
1033 /* Compute parameters for interactions between i and j atoms */
1034 qq30
= _mm_mul_ps(iq3
,jq0
);
1036 /* REACTION-FIELD ELECTROSTATICS */
1037 felec
= _mm_mul_ps(qq30
,_mm_sub_ps(_mm_mul_ps(rinv30
,rinvsq30
),krf2
));
1039 cutoff_mask
= _mm_cmplt_ps(rsq30
,rcutoff2
);
1043 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
1045 /* Calculate temporary vectorial force */
1046 tx
= _mm_mul_ps(fscal
,dx30
);
1047 ty
= _mm_mul_ps(fscal
,dy30
);
1048 tz
= _mm_mul_ps(fscal
,dz30
);
1050 /* Update vectorial force */
1051 fix3
= _mm_add_ps(fix3
,tx
);
1052 fiy3
= _mm_add_ps(fiy3
,ty
);
1053 fiz3
= _mm_add_ps(fiz3
,tz
);
1055 fjx0
= _mm_add_ps(fjx0
,tx
);
1056 fjy0
= _mm_add_ps(fjy0
,ty
);
1057 fjz0
= _mm_add_ps(fjz0
,tz
);
1061 fjptrA
= f
+j_coord_offsetA
;
1062 fjptrB
= f
+j_coord_offsetB
;
1063 fjptrC
= f
+j_coord_offsetC
;
1064 fjptrD
= f
+j_coord_offsetD
;
1066 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA
,fjptrB
,fjptrC
,fjptrD
,fjx0
,fjy0
,fjz0
);
1068 /* Inner loop uses 120 flops */
1071 if(jidx
<j_index_end
)
1074 /* Get j neighbor index, and coordinate index */
1075 jnrlistA
= jjnr
[jidx
];
1076 jnrlistB
= jjnr
[jidx
+1];
1077 jnrlistC
= jjnr
[jidx
+2];
1078 jnrlistD
= jjnr
[jidx
+3];
1079 /* Sign of each element will be negative for non-real atoms.
1080 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1081 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1083 dummy_mask
= gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i
*)(jjnr
+jidx
)),_mm_setzero_si128()));
1084 jnrA
= (jnrlistA
>=0) ? jnrlistA
: 0;
1085 jnrB
= (jnrlistB
>=0) ? jnrlistB
: 0;
1086 jnrC
= (jnrlistC
>=0) ? jnrlistC
: 0;
1087 jnrD
= (jnrlistD
>=0) ? jnrlistD
: 0;
1088 j_coord_offsetA
= DIM
*jnrA
;
1089 j_coord_offsetB
= DIM
*jnrB
;
1090 j_coord_offsetC
= DIM
*jnrC
;
1091 j_coord_offsetD
= DIM
*jnrD
;
1093 /* load j atom coordinates */
1094 gmx_mm_load_1rvec_4ptr_swizzle_ps(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
1095 x
+j_coord_offsetC
,x
+j_coord_offsetD
,
1098 /* Calculate displacement vector */
1099 dx00
= _mm_sub_ps(ix0
,jx0
);
1100 dy00
= _mm_sub_ps(iy0
,jy0
);
1101 dz00
= _mm_sub_ps(iz0
,jz0
);
1102 dx10
= _mm_sub_ps(ix1
,jx0
);
1103 dy10
= _mm_sub_ps(iy1
,jy0
);
1104 dz10
= _mm_sub_ps(iz1
,jz0
);
1105 dx20
= _mm_sub_ps(ix2
,jx0
);
1106 dy20
= _mm_sub_ps(iy2
,jy0
);
1107 dz20
= _mm_sub_ps(iz2
,jz0
);
1108 dx30
= _mm_sub_ps(ix3
,jx0
);
1109 dy30
= _mm_sub_ps(iy3
,jy0
);
1110 dz30
= _mm_sub_ps(iz3
,jz0
);
1112 /* Calculate squared distance and things based on it */
1113 rsq00
= gmx_mm_calc_rsq_ps(dx00
,dy00
,dz00
);
1114 rsq10
= gmx_mm_calc_rsq_ps(dx10
,dy10
,dz10
);
1115 rsq20
= gmx_mm_calc_rsq_ps(dx20
,dy20
,dz20
);
1116 rsq30
= gmx_mm_calc_rsq_ps(dx30
,dy30
,dz30
);
1118 rinv10
= gmx_mm_invsqrt_ps(rsq10
);
1119 rinv20
= gmx_mm_invsqrt_ps(rsq20
);
1120 rinv30
= gmx_mm_invsqrt_ps(rsq30
);
1122 rinvsq00
= gmx_mm_inv_ps(rsq00
);
1123 rinvsq10
= _mm_mul_ps(rinv10
,rinv10
);
1124 rinvsq20
= _mm_mul_ps(rinv20
,rinv20
);
1125 rinvsq30
= _mm_mul_ps(rinv30
,rinv30
);
1127 /* Load parameters for j particles */
1128 jq0
= gmx_mm_load_4real_swizzle_ps(charge
+jnrA
+0,charge
+jnrB
+0,
1129 charge
+jnrC
+0,charge
+jnrD
+0);
1130 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
1131 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
1132 vdwjidx0C
= 2*vdwtype
[jnrC
+0];
1133 vdwjidx0D
= 2*vdwtype
[jnrD
+0];
1135 fjx0
= _mm_setzero_ps();
1136 fjy0
= _mm_setzero_ps();
1137 fjz0
= _mm_setzero_ps();
1139 /**************************
1140 * CALCULATE INTERACTIONS *
1141 **************************/
1143 if (gmx_mm_any_lt(rsq00
,rcutoff2
))
1146 /* Compute parameters for interactions between i and j atoms */
1147 gmx_mm_load_4pair_swizzle_ps(vdwparam
+vdwioffset0
+vdwjidx0A
,
1148 vdwparam
+vdwioffset0
+vdwjidx0B
,
1149 vdwparam
+vdwioffset0
+vdwjidx0C
,
1150 vdwparam
+vdwioffset0
+vdwjidx0D
,
1153 /* LENNARD-JONES DISPERSION/REPULSION */
1155 rinvsix
= _mm_mul_ps(_mm_mul_ps(rinvsq00
,rinvsq00
),rinvsq00
);
1156 fvdw
= _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00
,rinvsix
),c6_00
),_mm_mul_ps(rinvsix
,rinvsq00
));
1158 cutoff_mask
= _mm_cmplt_ps(rsq00
,rcutoff2
);
1162 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
1164 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
1166 /* Calculate temporary vectorial force */
1167 tx
= _mm_mul_ps(fscal
,dx00
);
1168 ty
= _mm_mul_ps(fscal
,dy00
);
1169 tz
= _mm_mul_ps(fscal
,dz00
);
1171 /* Update vectorial force */
1172 fix0
= _mm_add_ps(fix0
,tx
);
1173 fiy0
= _mm_add_ps(fiy0
,ty
);
1174 fiz0
= _mm_add_ps(fiz0
,tz
);
1176 fjx0
= _mm_add_ps(fjx0
,tx
);
1177 fjy0
= _mm_add_ps(fjy0
,ty
);
1178 fjz0
= _mm_add_ps(fjz0
,tz
);
1182 /**************************
1183 * CALCULATE INTERACTIONS *
1184 **************************/
1186 if (gmx_mm_any_lt(rsq10
,rcutoff2
))
1189 /* Compute parameters for interactions between i and j atoms */
1190 qq10
= _mm_mul_ps(iq1
,jq0
);
1192 /* REACTION-FIELD ELECTROSTATICS */
1193 felec
= _mm_mul_ps(qq10
,_mm_sub_ps(_mm_mul_ps(rinv10
,rinvsq10
),krf2
));
1195 cutoff_mask
= _mm_cmplt_ps(rsq10
,rcutoff2
);
1199 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
1201 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
1203 /* Calculate temporary vectorial force */
1204 tx
= _mm_mul_ps(fscal
,dx10
);
1205 ty
= _mm_mul_ps(fscal
,dy10
);
1206 tz
= _mm_mul_ps(fscal
,dz10
);
1208 /* Update vectorial force */
1209 fix1
= _mm_add_ps(fix1
,tx
);
1210 fiy1
= _mm_add_ps(fiy1
,ty
);
1211 fiz1
= _mm_add_ps(fiz1
,tz
);
1213 fjx0
= _mm_add_ps(fjx0
,tx
);
1214 fjy0
= _mm_add_ps(fjy0
,ty
);
1215 fjz0
= _mm_add_ps(fjz0
,tz
);
1219 /**************************
1220 * CALCULATE INTERACTIONS *
1221 **************************/
1223 if (gmx_mm_any_lt(rsq20
,rcutoff2
))
1226 /* Compute parameters for interactions between i and j atoms */
1227 qq20
= _mm_mul_ps(iq2
,jq0
);
1229 /* REACTION-FIELD ELECTROSTATICS */
1230 felec
= _mm_mul_ps(qq20
,_mm_sub_ps(_mm_mul_ps(rinv20
,rinvsq20
),krf2
));
1232 cutoff_mask
= _mm_cmplt_ps(rsq20
,rcutoff2
);
1236 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
1238 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
1240 /* Calculate temporary vectorial force */
1241 tx
= _mm_mul_ps(fscal
,dx20
);
1242 ty
= _mm_mul_ps(fscal
,dy20
);
1243 tz
= _mm_mul_ps(fscal
,dz20
);
1245 /* Update vectorial force */
1246 fix2
= _mm_add_ps(fix2
,tx
);
1247 fiy2
= _mm_add_ps(fiy2
,ty
);
1248 fiz2
= _mm_add_ps(fiz2
,tz
);
1250 fjx0
= _mm_add_ps(fjx0
,tx
);
1251 fjy0
= _mm_add_ps(fjy0
,ty
);
1252 fjz0
= _mm_add_ps(fjz0
,tz
);
1256 /**************************
1257 * CALCULATE INTERACTIONS *
1258 **************************/
1260 if (gmx_mm_any_lt(rsq30
,rcutoff2
))
1263 /* Compute parameters for interactions between i and j atoms */
1264 qq30
= _mm_mul_ps(iq3
,jq0
);
1266 /* REACTION-FIELD ELECTROSTATICS */
1267 felec
= _mm_mul_ps(qq30
,_mm_sub_ps(_mm_mul_ps(rinv30
,rinvsq30
),krf2
));
1269 cutoff_mask
= _mm_cmplt_ps(rsq30
,rcutoff2
);
1273 fscal
= _mm_and_ps(fscal
,cutoff_mask
);
1275 fscal
= _mm_andnot_ps(dummy_mask
,fscal
);
1277 /* Calculate temporary vectorial force */
1278 tx
= _mm_mul_ps(fscal
,dx30
);
1279 ty
= _mm_mul_ps(fscal
,dy30
);
1280 tz
= _mm_mul_ps(fscal
,dz30
);
1282 /* Update vectorial force */
1283 fix3
= _mm_add_ps(fix3
,tx
);
1284 fiy3
= _mm_add_ps(fiy3
,ty
);
1285 fiz3
= _mm_add_ps(fiz3
,tz
);
1287 fjx0
= _mm_add_ps(fjx0
,tx
);
1288 fjy0
= _mm_add_ps(fjy0
,ty
);
1289 fjz0
= _mm_add_ps(fjz0
,tz
);
1293 fjptrA
= (jnrlistA
>=0) ? f
+j_coord_offsetA
: scratch
;
1294 fjptrB
= (jnrlistB
>=0) ? f
+j_coord_offsetB
: scratch
;
1295 fjptrC
= (jnrlistC
>=0) ? f
+j_coord_offsetC
: scratch
;
1296 fjptrD
= (jnrlistD
>=0) ? f
+j_coord_offsetD
: scratch
;
1298 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA
,fjptrB
,fjptrC
,fjptrD
,fjx0
,fjy0
,fjz0
);
1300 /* Inner loop uses 120 flops */
1303 /* End of innermost loop */
1305 gmx_mm_update_iforce_4atom_swizzle_ps(fix0
,fiy0
,fiz0
,fix1
,fiy1
,fiz1
,fix2
,fiy2
,fiz2
,fix3
,fiy3
,fiz3
,
1306 f
+i_coord_offset
,fshift
+i_shift_offset
);
1308 /* Increment number of inner iterations */
1309 inneriter
+= j_index_end
- j_index_start
;
1311 /* Outer loop uses 24 flops */
1314 /* Increment number of outer iterations */
1317 /* Update outer/inner flops */
1319 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_VDW_W4_F
,outeriter
*24 + inneriter
*120);