2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015, 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/math/vec.h"
46 #include "gromacs/legacyheaders/nrnb.h"
48 #include "gromacs/simd/math_x86_sse2_double.h"
49 #include "kernelutil_x86_sse2_double.h"
52 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_sse2_double
53 * Electrostatics interaction: GeneralizedBorn
54 * VdW interaction: LennardJones
55 * Geometry: Particle-Particle
56 * Calculate force/pot: PotentialAndForce
59 nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_sse2_double
60 (t_nblist
* gmx_restrict nlist
,
61 rvec
* gmx_restrict xx
,
62 rvec
* gmx_restrict ff
,
63 t_forcerec
* gmx_restrict fr
,
64 t_mdatoms
* gmx_restrict mdatoms
,
65 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
66 t_nrnb
* gmx_restrict nrnb
)
68 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
69 * just 0 for non-waters.
70 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
71 * jnr indices corresponding to data put in the four positions in the SIMD register.
73 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
74 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
76 int j_coord_offsetA
,j_coord_offsetB
;
77 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
79 real
*shiftvec
,*fshift
,*x
,*f
;
80 __m128d tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
82 __m128d ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
83 int vdwjidx0A
,vdwjidx0B
;
84 __m128d jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
85 __m128d dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
86 __m128d velec
,felec
,velecsum
,facel
,crf
,krf
,krf2
;
89 __m128d vgb
,fgb
,vgbsum
,dvdasum
,gbscale
,gbtabscale
,isaprod
,gbqqfactor
,gbinvepsdiff
,dvdaj
,gbeps
,dvdatmp
;
90 __m128d minushalf
= _mm_set1_pd(-0.5);
91 real
*invsqrta
,*dvda
,*gbtab
;
93 __m128d rinvsix
,rvdw
,vvdw
,vvdw6
,vvdw12
,fvdw
,fvdw6
,fvdw12
,vvdwsum
,sh_vdw_invrcut6
;
96 __m128d one_sixth
= _mm_set1_pd(1.0/6.0);
97 __m128d one_twelfth
= _mm_set1_pd(1.0/12.0);
99 __m128i ifour
= _mm_set1_epi32(4);
100 __m128d rt
,vfeps
,vftabscale
,Y
,F
,G
,H
,Heps
,Fp
,VV
,FF
;
102 __m128d dummy_mask
,cutoff_mask
;
103 __m128d signbit
= gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
104 __m128d one
= _mm_set1_pd(1.0);
105 __m128d two
= _mm_set1_pd(2.0);
111 jindex
= nlist
->jindex
;
113 shiftidx
= nlist
->shift
;
115 shiftvec
= fr
->shift_vec
[0];
116 fshift
= fr
->fshift
[0];
117 facel
= _mm_set1_pd(fr
->epsfac
);
118 charge
= mdatoms
->chargeA
;
119 nvdwtype
= fr
->ntype
;
121 vdwtype
= mdatoms
->typeA
;
123 invsqrta
= fr
->invsqrta
;
125 gbtabscale
= _mm_set1_pd(fr
->gbtab
.scale
);
126 gbtab
= fr
->gbtab
.data
;
127 gbinvepsdiff
= _mm_set1_pd((1.0/fr
->epsilon_r
) - (1.0/fr
->gb_epsilon_solvent
));
129 /* Avoid stupid compiler warnings */
137 /* Start outer loop over neighborlists */
138 for(iidx
=0; iidx
<nri
; iidx
++)
140 /* Load shift vector for this list */
141 i_shift_offset
= DIM
*shiftidx
[iidx
];
143 /* Load limits for loop over neighbors */
144 j_index_start
= jindex
[iidx
];
145 j_index_end
= jindex
[iidx
+1];
147 /* Get outer coordinate index */
149 i_coord_offset
= DIM
*inr
;
151 /* Load i particle coords and add shift vector */
152 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,&ix0
,&iy0
,&iz0
);
154 fix0
= _mm_setzero_pd();
155 fiy0
= _mm_setzero_pd();
156 fiz0
= _mm_setzero_pd();
158 /* Load parameters for i particles */
159 iq0
= _mm_mul_pd(facel
,_mm_load1_pd(charge
+inr
+0));
160 isai0
= _mm_load1_pd(invsqrta
+inr
+0);
161 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
163 /* Reset potential sums */
164 velecsum
= _mm_setzero_pd();
165 vgbsum
= _mm_setzero_pd();
166 vvdwsum
= _mm_setzero_pd();
167 dvdasum
= _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);
197 isaj0
= gmx_mm_load_2real_swizzle_pd(invsqrta
+jnrA
+0,invsqrta
+jnrB
+0);
198 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
199 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
201 /**************************
202 * CALCULATE INTERACTIONS *
203 **************************/
205 r00
= _mm_mul_pd(rsq00
,rinv00
);
207 /* Compute parameters for interactions between i and j atoms */
208 qq00
= _mm_mul_pd(iq0
,jq0
);
209 gmx_mm_load_2pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,
210 vdwparam
+vdwioffset0
+vdwjidx0B
,&c6_00
,&c12_00
);
212 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
213 isaprod
= _mm_mul_pd(isai0
,isaj0
);
214 gbqqfactor
= _mm_xor_pd(signbit
,_mm_mul_pd(qq00
,_mm_mul_pd(isaprod
,gbinvepsdiff
)));
215 gbscale
= _mm_mul_pd(isaprod
,gbtabscale
);
217 /* Calculate generalized born table index - this is a separate table from the normal one,
218 * but we use the same procedure by multiplying r with scale and truncating to integer.
220 rt
= _mm_mul_pd(r00
,gbscale
);
221 gbitab
= _mm_cvttpd_epi32(rt
);
222 gbeps
= _mm_sub_pd(rt
,_mm_cvtepi32_pd(gbitab
));
223 gbitab
= _mm_slli_epi32(gbitab
,2);
225 Y
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) );
226 F
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,1) );
227 GMX_MM_TRANSPOSE2_PD(Y
,F
);
228 G
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) +2);
229 H
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,1) +2);
230 GMX_MM_TRANSPOSE2_PD(G
,H
);
231 Heps
= _mm_mul_pd(gbeps
,H
);
232 Fp
= _mm_add_pd(F
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,Heps
)));
233 VV
= _mm_add_pd(Y
,_mm_mul_pd(gbeps
,Fp
));
234 vgb
= _mm_mul_pd(gbqqfactor
,VV
);
236 FF
= _mm_add_pd(Fp
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,_mm_add_pd(Heps
,Heps
))));
237 fgb
= _mm_mul_pd(gbqqfactor
,_mm_mul_pd(FF
,gbscale
));
238 dvdatmp
= _mm_mul_pd(minushalf
,_mm_add_pd(vgb
,_mm_mul_pd(fgb
,r00
)));
239 dvdasum
= _mm_add_pd(dvdasum
,dvdatmp
);
240 gmx_mm_increment_2real_swizzle_pd(dvda
+jnrA
,dvda
+jnrB
,_mm_mul_pd(dvdatmp
,_mm_mul_pd(isaj0
,isaj0
)));
241 velec
= _mm_mul_pd(qq00
,rinv00
);
242 felec
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec
,rinv00
),fgb
),rinv00
);
244 /* LENNARD-JONES DISPERSION/REPULSION */
246 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
247 vvdw6
= _mm_mul_pd(c6_00
,rinvsix
);
248 vvdw12
= _mm_mul_pd(c12_00
,_mm_mul_pd(rinvsix
,rinvsix
));
249 vvdw
= _mm_sub_pd( _mm_mul_pd(vvdw12
,one_twelfth
) , _mm_mul_pd(vvdw6
,one_sixth
) );
250 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
252 /* Update potential sum for this i atom from the interaction with this j atom. */
253 velecsum
= _mm_add_pd(velecsum
,velec
);
254 vgbsum
= _mm_add_pd(vgbsum
,vgb
);
255 vvdwsum
= _mm_add_pd(vvdwsum
,vvdw
);
257 fscal
= _mm_add_pd(felec
,fvdw
);
259 /* Calculate temporary vectorial force */
260 tx
= _mm_mul_pd(fscal
,dx00
);
261 ty
= _mm_mul_pd(fscal
,dy00
);
262 tz
= _mm_mul_pd(fscal
,dz00
);
264 /* Update vectorial force */
265 fix0
= _mm_add_pd(fix0
,tx
);
266 fiy0
= _mm_add_pd(fiy0
,ty
);
267 fiz0
= _mm_add_pd(fiz0
,tz
);
269 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,tx
,ty
,tz
);
271 /* Inner loop uses 71 flops */
278 j_coord_offsetA
= DIM
*jnrA
;
280 /* load j atom coordinates */
281 gmx_mm_load_1rvec_1ptr_swizzle_pd(x
+j_coord_offsetA
,
284 /* Calculate displacement vector */
285 dx00
= _mm_sub_pd(ix0
,jx0
);
286 dy00
= _mm_sub_pd(iy0
,jy0
);
287 dz00
= _mm_sub_pd(iz0
,jz0
);
289 /* Calculate squared distance and things based on it */
290 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
292 rinv00
= gmx_mm_invsqrt_pd(rsq00
);
294 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
296 /* Load parameters for j particles */
297 jq0
= _mm_load_sd(charge
+jnrA
+0);
298 isaj0
= _mm_load_sd(invsqrta
+jnrA
+0);
299 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
301 /**************************
302 * CALCULATE INTERACTIONS *
303 **************************/
305 r00
= _mm_mul_pd(rsq00
,rinv00
);
307 /* Compute parameters for interactions between i and j atoms */
308 qq00
= _mm_mul_pd(iq0
,jq0
);
309 gmx_mm_load_1pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,&c6_00
,&c12_00
);
311 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
312 isaprod
= _mm_mul_pd(isai0
,isaj0
);
313 gbqqfactor
= _mm_xor_pd(signbit
,_mm_mul_pd(qq00
,_mm_mul_pd(isaprod
,gbinvepsdiff
)));
314 gbscale
= _mm_mul_pd(isaprod
,gbtabscale
);
316 /* Calculate generalized born table index - this is a separate table from the normal one,
317 * but we use the same procedure by multiplying r with scale and truncating to integer.
319 rt
= _mm_mul_pd(r00
,gbscale
);
320 gbitab
= _mm_cvttpd_epi32(rt
);
321 gbeps
= _mm_sub_pd(rt
,_mm_cvtepi32_pd(gbitab
));
322 gbitab
= _mm_slli_epi32(gbitab
,2);
324 Y
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) );
325 F
= _mm_setzero_pd();
326 GMX_MM_TRANSPOSE2_PD(Y
,F
);
327 G
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) +2);
328 H
= _mm_setzero_pd();
329 GMX_MM_TRANSPOSE2_PD(G
,H
);
330 Heps
= _mm_mul_pd(gbeps
,H
);
331 Fp
= _mm_add_pd(F
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,Heps
)));
332 VV
= _mm_add_pd(Y
,_mm_mul_pd(gbeps
,Fp
));
333 vgb
= _mm_mul_pd(gbqqfactor
,VV
);
335 FF
= _mm_add_pd(Fp
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,_mm_add_pd(Heps
,Heps
))));
336 fgb
= _mm_mul_pd(gbqqfactor
,_mm_mul_pd(FF
,gbscale
));
337 dvdatmp
= _mm_mul_pd(minushalf
,_mm_add_pd(vgb
,_mm_mul_pd(fgb
,r00
)));
338 dvdatmp
= _mm_unpacklo_pd(dvdatmp
,_mm_setzero_pd());
339 dvdasum
= _mm_add_pd(dvdasum
,dvdatmp
);
340 gmx_mm_increment_1real_pd(dvda
+jnrA
,_mm_mul_pd(dvdatmp
,_mm_mul_pd(isaj0
,isaj0
)));
341 velec
= _mm_mul_pd(qq00
,rinv00
);
342 felec
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec
,rinv00
),fgb
),rinv00
);
344 /* LENNARD-JONES DISPERSION/REPULSION */
346 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
347 vvdw6
= _mm_mul_pd(c6_00
,rinvsix
);
348 vvdw12
= _mm_mul_pd(c12_00
,_mm_mul_pd(rinvsix
,rinvsix
));
349 vvdw
= _mm_sub_pd( _mm_mul_pd(vvdw12
,one_twelfth
) , _mm_mul_pd(vvdw6
,one_sixth
) );
350 fvdw
= _mm_mul_pd(_mm_sub_pd(vvdw12
,vvdw6
),rinvsq00
);
352 /* Update potential sum for this i atom from the interaction with this j atom. */
353 velec
= _mm_unpacklo_pd(velec
,_mm_setzero_pd());
354 velecsum
= _mm_add_pd(velecsum
,velec
);
355 vgb
= _mm_unpacklo_pd(vgb
,_mm_setzero_pd());
356 vgbsum
= _mm_add_pd(vgbsum
,vgb
);
357 vvdw
= _mm_unpacklo_pd(vvdw
,_mm_setzero_pd());
358 vvdwsum
= _mm_add_pd(vvdwsum
,vvdw
);
360 fscal
= _mm_add_pd(felec
,fvdw
);
362 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
364 /* Calculate temporary vectorial force */
365 tx
= _mm_mul_pd(fscal
,dx00
);
366 ty
= _mm_mul_pd(fscal
,dy00
);
367 tz
= _mm_mul_pd(fscal
,dz00
);
369 /* Update vectorial force */
370 fix0
= _mm_add_pd(fix0
,tx
);
371 fiy0
= _mm_add_pd(fiy0
,ty
);
372 fiz0
= _mm_add_pd(fiz0
,tz
);
374 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f
+j_coord_offsetA
,tx
,ty
,tz
);
376 /* Inner loop uses 71 flops */
379 /* End of innermost loop */
381 gmx_mm_update_iforce_1atom_swizzle_pd(fix0
,fiy0
,fiz0
,
382 f
+i_coord_offset
,fshift
+i_shift_offset
);
385 /* Update potential energies */
386 gmx_mm_update_1pot_pd(velecsum
,kernel_data
->energygrp_elec
+ggid
);
387 gmx_mm_update_1pot_pd(vgbsum
,kernel_data
->energygrp_polarization
+ggid
);
388 gmx_mm_update_1pot_pd(vvdwsum
,kernel_data
->energygrp_vdw
+ggid
);
389 dvdasum
= _mm_mul_pd(dvdasum
, _mm_mul_pd(isai0
,isai0
));
390 gmx_mm_update_1pot_pd(dvdasum
,dvda
+inr
);
392 /* Increment number of inner iterations */
393 inneriter
+= j_index_end
- j_index_start
;
395 /* Outer loop uses 10 flops */
398 /* Increment number of outer iterations */
401 /* Update outer/inner flops */
403 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_VDW_VF
,outeriter
*10 + inneriter
*71);
406 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_sse2_double
407 * Electrostatics interaction: GeneralizedBorn
408 * VdW interaction: LennardJones
409 * Geometry: Particle-Particle
410 * Calculate force/pot: Force
413 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_sse2_double
414 (t_nblist
* gmx_restrict nlist
,
415 rvec
* gmx_restrict xx
,
416 rvec
* gmx_restrict ff
,
417 t_forcerec
* gmx_restrict fr
,
418 t_mdatoms
* gmx_restrict mdatoms
,
419 nb_kernel_data_t gmx_unused
* gmx_restrict kernel_data
,
420 t_nrnb
* gmx_restrict nrnb
)
422 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
423 * just 0 for non-waters.
424 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
425 * jnr indices corresponding to data put in the four positions in the SIMD register.
427 int i_shift_offset
,i_coord_offset
,outeriter
,inneriter
;
428 int j_index_start
,j_index_end
,jidx
,nri
,inr
,ggid
,iidx
;
430 int j_coord_offsetA
,j_coord_offsetB
;
431 int *iinr
,*jindex
,*jjnr
,*shiftidx
,*gid
;
433 real
*shiftvec
,*fshift
,*x
,*f
;
434 __m128d tx
,ty
,tz
,fscal
,rcutoff
,rcutoff2
,jidxall
;
436 __m128d ix0
,iy0
,iz0
,fix0
,fiy0
,fiz0
,iq0
,isai0
;
437 int vdwjidx0A
,vdwjidx0B
;
438 __m128d jx0
,jy0
,jz0
,fjx0
,fjy0
,fjz0
,jq0
,isaj0
;
439 __m128d dx00
,dy00
,dz00
,rsq00
,rinv00
,rinvsq00
,r00
,qq00
,c6_00
,c12_00
;
440 __m128d velec
,felec
,velecsum
,facel
,crf
,krf
,krf2
;
443 __m128d vgb
,fgb
,vgbsum
,dvdasum
,gbscale
,gbtabscale
,isaprod
,gbqqfactor
,gbinvepsdiff
,dvdaj
,gbeps
,dvdatmp
;
444 __m128d minushalf
= _mm_set1_pd(-0.5);
445 real
*invsqrta
,*dvda
,*gbtab
;
447 __m128d rinvsix
,rvdw
,vvdw
,vvdw6
,vvdw12
,fvdw
,fvdw6
,fvdw12
,vvdwsum
,sh_vdw_invrcut6
;
450 __m128d one_sixth
= _mm_set1_pd(1.0/6.0);
451 __m128d one_twelfth
= _mm_set1_pd(1.0/12.0);
453 __m128i ifour
= _mm_set1_epi32(4);
454 __m128d rt
,vfeps
,vftabscale
,Y
,F
,G
,H
,Heps
,Fp
,VV
,FF
;
456 __m128d dummy_mask
,cutoff_mask
;
457 __m128d signbit
= gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
458 __m128d one
= _mm_set1_pd(1.0);
459 __m128d two
= _mm_set1_pd(2.0);
465 jindex
= nlist
->jindex
;
467 shiftidx
= nlist
->shift
;
469 shiftvec
= fr
->shift_vec
[0];
470 fshift
= fr
->fshift
[0];
471 facel
= _mm_set1_pd(fr
->epsfac
);
472 charge
= mdatoms
->chargeA
;
473 nvdwtype
= fr
->ntype
;
475 vdwtype
= mdatoms
->typeA
;
477 invsqrta
= fr
->invsqrta
;
479 gbtabscale
= _mm_set1_pd(fr
->gbtab
.scale
);
480 gbtab
= fr
->gbtab
.data
;
481 gbinvepsdiff
= _mm_set1_pd((1.0/fr
->epsilon_r
) - (1.0/fr
->gb_epsilon_solvent
));
483 /* Avoid stupid compiler warnings */
491 /* Start outer loop over neighborlists */
492 for(iidx
=0; iidx
<nri
; iidx
++)
494 /* Load shift vector for this list */
495 i_shift_offset
= DIM
*shiftidx
[iidx
];
497 /* Load limits for loop over neighbors */
498 j_index_start
= jindex
[iidx
];
499 j_index_end
= jindex
[iidx
+1];
501 /* Get outer coordinate index */
503 i_coord_offset
= DIM
*inr
;
505 /* Load i particle coords and add shift vector */
506 gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec
+i_shift_offset
,x
+i_coord_offset
,&ix0
,&iy0
,&iz0
);
508 fix0
= _mm_setzero_pd();
509 fiy0
= _mm_setzero_pd();
510 fiz0
= _mm_setzero_pd();
512 /* Load parameters for i particles */
513 iq0
= _mm_mul_pd(facel
,_mm_load1_pd(charge
+inr
+0));
514 isai0
= _mm_load1_pd(invsqrta
+inr
+0);
515 vdwioffset0
= 2*nvdwtype
*vdwtype
[inr
+0];
517 dvdasum
= _mm_setzero_pd();
519 /* Start inner kernel loop */
520 for(jidx
=j_index_start
; jidx
<j_index_end
-1; jidx
+=2)
523 /* Get j neighbor index, and coordinate index */
526 j_coord_offsetA
= DIM
*jnrA
;
527 j_coord_offsetB
= DIM
*jnrB
;
529 /* load j atom coordinates */
530 gmx_mm_load_1rvec_2ptr_swizzle_pd(x
+j_coord_offsetA
,x
+j_coord_offsetB
,
533 /* Calculate displacement vector */
534 dx00
= _mm_sub_pd(ix0
,jx0
);
535 dy00
= _mm_sub_pd(iy0
,jy0
);
536 dz00
= _mm_sub_pd(iz0
,jz0
);
538 /* Calculate squared distance and things based on it */
539 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
541 rinv00
= gmx_mm_invsqrt_pd(rsq00
);
543 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
545 /* Load parameters for j particles */
546 jq0
= gmx_mm_load_2real_swizzle_pd(charge
+jnrA
+0,charge
+jnrB
+0);
547 isaj0
= gmx_mm_load_2real_swizzle_pd(invsqrta
+jnrA
+0,invsqrta
+jnrB
+0);
548 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
549 vdwjidx0B
= 2*vdwtype
[jnrB
+0];
551 /**************************
552 * CALCULATE INTERACTIONS *
553 **************************/
555 r00
= _mm_mul_pd(rsq00
,rinv00
);
557 /* Compute parameters for interactions between i and j atoms */
558 qq00
= _mm_mul_pd(iq0
,jq0
);
559 gmx_mm_load_2pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,
560 vdwparam
+vdwioffset0
+vdwjidx0B
,&c6_00
,&c12_00
);
562 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
563 isaprod
= _mm_mul_pd(isai0
,isaj0
);
564 gbqqfactor
= _mm_xor_pd(signbit
,_mm_mul_pd(qq00
,_mm_mul_pd(isaprod
,gbinvepsdiff
)));
565 gbscale
= _mm_mul_pd(isaprod
,gbtabscale
);
567 /* Calculate generalized born table index - this is a separate table from the normal one,
568 * but we use the same procedure by multiplying r with scale and truncating to integer.
570 rt
= _mm_mul_pd(r00
,gbscale
);
571 gbitab
= _mm_cvttpd_epi32(rt
);
572 gbeps
= _mm_sub_pd(rt
,_mm_cvtepi32_pd(gbitab
));
573 gbitab
= _mm_slli_epi32(gbitab
,2);
575 Y
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) );
576 F
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,1) );
577 GMX_MM_TRANSPOSE2_PD(Y
,F
);
578 G
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) +2);
579 H
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,1) +2);
580 GMX_MM_TRANSPOSE2_PD(G
,H
);
581 Heps
= _mm_mul_pd(gbeps
,H
);
582 Fp
= _mm_add_pd(F
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,Heps
)));
583 VV
= _mm_add_pd(Y
,_mm_mul_pd(gbeps
,Fp
));
584 vgb
= _mm_mul_pd(gbqqfactor
,VV
);
586 FF
= _mm_add_pd(Fp
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,_mm_add_pd(Heps
,Heps
))));
587 fgb
= _mm_mul_pd(gbqqfactor
,_mm_mul_pd(FF
,gbscale
));
588 dvdatmp
= _mm_mul_pd(minushalf
,_mm_add_pd(vgb
,_mm_mul_pd(fgb
,r00
)));
589 dvdasum
= _mm_add_pd(dvdasum
,dvdatmp
);
590 gmx_mm_increment_2real_swizzle_pd(dvda
+jnrA
,dvda
+jnrB
,_mm_mul_pd(dvdatmp
,_mm_mul_pd(isaj0
,isaj0
)));
591 velec
= _mm_mul_pd(qq00
,rinv00
);
592 felec
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec
,rinv00
),fgb
),rinv00
);
594 /* LENNARD-JONES DISPERSION/REPULSION */
596 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
597 fvdw
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00
,rinvsix
),c6_00
),_mm_mul_pd(rinvsix
,rinvsq00
));
599 fscal
= _mm_add_pd(felec
,fvdw
);
601 /* Calculate temporary vectorial force */
602 tx
= _mm_mul_pd(fscal
,dx00
);
603 ty
= _mm_mul_pd(fscal
,dy00
);
604 tz
= _mm_mul_pd(fscal
,dz00
);
606 /* Update vectorial force */
607 fix0
= _mm_add_pd(fix0
,tx
);
608 fiy0
= _mm_add_pd(fiy0
,ty
);
609 fiz0
= _mm_add_pd(fiz0
,tz
);
611 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f
+j_coord_offsetA
,f
+j_coord_offsetB
,tx
,ty
,tz
);
613 /* Inner loop uses 64 flops */
620 j_coord_offsetA
= DIM
*jnrA
;
622 /* load j atom coordinates */
623 gmx_mm_load_1rvec_1ptr_swizzle_pd(x
+j_coord_offsetA
,
626 /* Calculate displacement vector */
627 dx00
= _mm_sub_pd(ix0
,jx0
);
628 dy00
= _mm_sub_pd(iy0
,jy0
);
629 dz00
= _mm_sub_pd(iz0
,jz0
);
631 /* Calculate squared distance and things based on it */
632 rsq00
= gmx_mm_calc_rsq_pd(dx00
,dy00
,dz00
);
634 rinv00
= gmx_mm_invsqrt_pd(rsq00
);
636 rinvsq00
= _mm_mul_pd(rinv00
,rinv00
);
638 /* Load parameters for j particles */
639 jq0
= _mm_load_sd(charge
+jnrA
+0);
640 isaj0
= _mm_load_sd(invsqrta
+jnrA
+0);
641 vdwjidx0A
= 2*vdwtype
[jnrA
+0];
643 /**************************
644 * CALCULATE INTERACTIONS *
645 **************************/
647 r00
= _mm_mul_pd(rsq00
,rinv00
);
649 /* Compute parameters for interactions between i and j atoms */
650 qq00
= _mm_mul_pd(iq0
,jq0
);
651 gmx_mm_load_1pair_swizzle_pd(vdwparam
+vdwioffset0
+vdwjidx0A
,&c6_00
,&c12_00
);
653 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
654 isaprod
= _mm_mul_pd(isai0
,isaj0
);
655 gbqqfactor
= _mm_xor_pd(signbit
,_mm_mul_pd(qq00
,_mm_mul_pd(isaprod
,gbinvepsdiff
)));
656 gbscale
= _mm_mul_pd(isaprod
,gbtabscale
);
658 /* Calculate generalized born table index - this is a separate table from the normal one,
659 * but we use the same procedure by multiplying r with scale and truncating to integer.
661 rt
= _mm_mul_pd(r00
,gbscale
);
662 gbitab
= _mm_cvttpd_epi32(rt
);
663 gbeps
= _mm_sub_pd(rt
,_mm_cvtepi32_pd(gbitab
));
664 gbitab
= _mm_slli_epi32(gbitab
,2);
666 Y
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) );
667 F
= _mm_setzero_pd();
668 GMX_MM_TRANSPOSE2_PD(Y
,F
);
669 G
= _mm_load_pd( gbtab
+ gmx_mm_extract_epi32(gbitab
,0) +2);
670 H
= _mm_setzero_pd();
671 GMX_MM_TRANSPOSE2_PD(G
,H
);
672 Heps
= _mm_mul_pd(gbeps
,H
);
673 Fp
= _mm_add_pd(F
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,Heps
)));
674 VV
= _mm_add_pd(Y
,_mm_mul_pd(gbeps
,Fp
));
675 vgb
= _mm_mul_pd(gbqqfactor
,VV
);
677 FF
= _mm_add_pd(Fp
,_mm_mul_pd(gbeps
,_mm_add_pd(G
,_mm_add_pd(Heps
,Heps
))));
678 fgb
= _mm_mul_pd(gbqqfactor
,_mm_mul_pd(FF
,gbscale
));
679 dvdatmp
= _mm_mul_pd(minushalf
,_mm_add_pd(vgb
,_mm_mul_pd(fgb
,r00
)));
680 dvdatmp
= _mm_unpacklo_pd(dvdatmp
,_mm_setzero_pd());
681 dvdasum
= _mm_add_pd(dvdasum
,dvdatmp
);
682 gmx_mm_increment_1real_pd(dvda
+jnrA
,_mm_mul_pd(dvdatmp
,_mm_mul_pd(isaj0
,isaj0
)));
683 velec
= _mm_mul_pd(qq00
,rinv00
);
684 felec
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(velec
,rinv00
),fgb
),rinv00
);
686 /* LENNARD-JONES DISPERSION/REPULSION */
688 rinvsix
= _mm_mul_pd(_mm_mul_pd(rinvsq00
,rinvsq00
),rinvsq00
);
689 fvdw
= _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00
,rinvsix
),c6_00
),_mm_mul_pd(rinvsix
,rinvsq00
));
691 fscal
= _mm_add_pd(felec
,fvdw
);
693 fscal
= _mm_unpacklo_pd(fscal
,_mm_setzero_pd());
695 /* Calculate temporary vectorial force */
696 tx
= _mm_mul_pd(fscal
,dx00
);
697 ty
= _mm_mul_pd(fscal
,dy00
);
698 tz
= _mm_mul_pd(fscal
,dz00
);
700 /* Update vectorial force */
701 fix0
= _mm_add_pd(fix0
,tx
);
702 fiy0
= _mm_add_pd(fiy0
,ty
);
703 fiz0
= _mm_add_pd(fiz0
,tz
);
705 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f
+j_coord_offsetA
,tx
,ty
,tz
);
707 /* Inner loop uses 64 flops */
710 /* End of innermost loop */
712 gmx_mm_update_iforce_1atom_swizzle_pd(fix0
,fiy0
,fiz0
,
713 f
+i_coord_offset
,fshift
+i_shift_offset
);
715 dvdasum
= _mm_mul_pd(dvdasum
, _mm_mul_pd(isai0
,isai0
));
716 gmx_mm_update_1pot_pd(dvdasum
,dvda
+inr
);
718 /* Increment number of inner iterations */
719 inneriter
+= j_index_end
- j_index_start
;
721 /* Outer loop uses 7 flops */
724 /* Increment number of outer iterations */
727 /* Update outer/inner flops */
729 inc_nrnb(nrnb
,eNR_NBKERNEL_ELEC_VDW_F
,outeriter
*7 + inneriter
*64);