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 avx_128_fma_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_avx_128_fma_single
52 * Electrostatics interaction: GeneralizedBorn
53 * VdW interaction: LennardJones
54 * Geometry: Particle-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecGB_VdwLJ_GeomP1P1_VF_avx_128_fma_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 AVX_128, 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 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
86 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
87 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
88 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
91 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
92 __m128 minushalf = _mm_set1_ps(-0.5);
93 real *invsqrta,*dvda,*gbtab;
95 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
98 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
99 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
101 __m128i ifour = _mm_set1_epi32(4);
102 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
104 __m128 dummy_mask,cutoff_mask;
105 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
106 __m128 one = _mm_set1_ps(1.0);
107 __m128 two = _mm_set1_ps(2.0);
113 jindex = nlist->jindex;
115 shiftidx = nlist->shift;
117 shiftvec = fr->shift_vec[0];
118 fshift = fr->fshift[0];
119 facel = _mm_set1_ps(fr->epsfac);
120 charge = mdatoms->chargeA;
121 nvdwtype = fr->ntype;
123 vdwtype = mdatoms->typeA;
125 invsqrta = fr->invsqrta;
127 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
128 gbtab = fr->gbtab.data;
129 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
131 /* Avoid stupid compiler warnings */
132 jnrA = jnrB = jnrC = jnrD = 0;
141 for(iidx=0;iidx<4*DIM;iidx++)
146 /* Start outer loop over neighborlists */
147 for(iidx=0; iidx<nri; iidx++)
149 /* Load shift vector for this list */
150 i_shift_offset = DIM*shiftidx[iidx];
152 /* Load limits for loop over neighbors */
153 j_index_start = jindex[iidx];
154 j_index_end = jindex[iidx+1];
156 /* Get outer coordinate index */
158 i_coord_offset = DIM*inr;
160 /* Load i particle coords and add shift vector */
161 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
163 fix0 = _mm_setzero_ps();
164 fiy0 = _mm_setzero_ps();
165 fiz0 = _mm_setzero_ps();
167 /* Load parameters for i particles */
168 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
169 isai0 = _mm_load1_ps(invsqrta+inr+0);
170 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
172 /* Reset potential sums */
173 velecsum = _mm_setzero_ps();
174 vgbsum = _mm_setzero_ps();
175 vvdwsum = _mm_setzero_ps();
176 dvdasum = _mm_setzero_ps();
178 /* Start inner kernel loop */
179 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
182 /* Get j neighbor index, and coordinate index */
187 j_coord_offsetA = DIM*jnrA;
188 j_coord_offsetB = DIM*jnrB;
189 j_coord_offsetC = DIM*jnrC;
190 j_coord_offsetD = DIM*jnrD;
192 /* load j atom coordinates */
193 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
194 x+j_coord_offsetC,x+j_coord_offsetD,
197 /* Calculate displacement vector */
198 dx00 = _mm_sub_ps(ix0,jx0);
199 dy00 = _mm_sub_ps(iy0,jy0);
200 dz00 = _mm_sub_ps(iz0,jz0);
202 /* Calculate squared distance and things based on it */
203 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
205 rinv00 = gmx_mm_invsqrt_ps(rsq00);
207 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
209 /* Load parameters for j particles */
210 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
211 charge+jnrC+0,charge+jnrD+0);
212 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
213 invsqrta+jnrC+0,invsqrta+jnrD+0);
214 vdwjidx0A = 2*vdwtype[jnrA+0];
215 vdwjidx0B = 2*vdwtype[jnrB+0];
216 vdwjidx0C = 2*vdwtype[jnrC+0];
217 vdwjidx0D = 2*vdwtype[jnrD+0];
219 /**************************
220 * CALCULATE INTERACTIONS *
221 **************************/
223 r00 = _mm_mul_ps(rsq00,rinv00);
225 /* Compute parameters for interactions between i and j atoms */
226 qq00 = _mm_mul_ps(iq0,jq0);
227 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
228 vdwparam+vdwioffset0+vdwjidx0B,
229 vdwparam+vdwioffset0+vdwjidx0C,
230 vdwparam+vdwioffset0+vdwjidx0D,
233 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
234 isaprod = _mm_mul_ps(isai0,isaj0);
235 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
236 gbscale = _mm_mul_ps(isaprod,gbtabscale);
238 /* Calculate generalized born table index - this is a separate table from the normal one,
239 * but we use the same procedure by multiplying r with scale and truncating to integer.
241 rt = _mm_mul_ps(r00,gbscale);
242 gbitab = _mm_cvttps_epi32(rt);
244 gbeps = _mm_frcz_ps(rt);
246 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
248 gbitab = _mm_slli_epi32(gbitab,2);
250 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
251 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
252 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
253 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
254 _MM_TRANSPOSE4_PS(Y,F,G,H);
255 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
256 VV = _mm_macc_ps(gbeps,Fp,Y);
257 vgb = _mm_mul_ps(gbqqfactor,VV);
259 twogbeps = _mm_add_ps(gbeps,gbeps);
260 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
261 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
262 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
263 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
268 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
269 velec = _mm_mul_ps(qq00,rinv00);
270 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
272 /* LENNARD-JONES DISPERSION/REPULSION */
274 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
275 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
276 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
277 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
278 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
280 /* Update potential sum for this i atom from the interaction with this j atom. */
281 velecsum = _mm_add_ps(velecsum,velec);
282 vgbsum = _mm_add_ps(vgbsum,vgb);
283 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
285 fscal = _mm_add_ps(felec,fvdw);
287 /* Update vectorial force */
288 fix0 = _mm_macc_ps(dx00,fscal,fix0);
289 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
290 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
292 fjptrA = f+j_coord_offsetA;
293 fjptrB = f+j_coord_offsetB;
294 fjptrC = f+j_coord_offsetC;
295 fjptrD = f+j_coord_offsetD;
296 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
297 _mm_mul_ps(dx00,fscal),
298 _mm_mul_ps(dy00,fscal),
299 _mm_mul_ps(dz00,fscal));
301 /* Inner loop uses 74 flops */
307 /* Get j neighbor index, and coordinate index */
308 jnrlistA = jjnr[jidx];
309 jnrlistB = jjnr[jidx+1];
310 jnrlistC = jjnr[jidx+2];
311 jnrlistD = jjnr[jidx+3];
312 /* Sign of each element will be negative for non-real atoms.
313 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
314 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
316 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
317 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
318 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
319 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
320 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
321 j_coord_offsetA = DIM*jnrA;
322 j_coord_offsetB = DIM*jnrB;
323 j_coord_offsetC = DIM*jnrC;
324 j_coord_offsetD = DIM*jnrD;
326 /* load j atom coordinates */
327 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
328 x+j_coord_offsetC,x+j_coord_offsetD,
331 /* Calculate displacement vector */
332 dx00 = _mm_sub_ps(ix0,jx0);
333 dy00 = _mm_sub_ps(iy0,jy0);
334 dz00 = _mm_sub_ps(iz0,jz0);
336 /* Calculate squared distance and things based on it */
337 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
339 rinv00 = gmx_mm_invsqrt_ps(rsq00);
341 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
343 /* Load parameters for j particles */
344 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
345 charge+jnrC+0,charge+jnrD+0);
346 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
347 invsqrta+jnrC+0,invsqrta+jnrD+0);
348 vdwjidx0A = 2*vdwtype[jnrA+0];
349 vdwjidx0B = 2*vdwtype[jnrB+0];
350 vdwjidx0C = 2*vdwtype[jnrC+0];
351 vdwjidx0D = 2*vdwtype[jnrD+0];
353 /**************************
354 * CALCULATE INTERACTIONS *
355 **************************/
357 r00 = _mm_mul_ps(rsq00,rinv00);
358 r00 = _mm_andnot_ps(dummy_mask,r00);
360 /* Compute parameters for interactions between i and j atoms */
361 qq00 = _mm_mul_ps(iq0,jq0);
362 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
363 vdwparam+vdwioffset0+vdwjidx0B,
364 vdwparam+vdwioffset0+vdwjidx0C,
365 vdwparam+vdwioffset0+vdwjidx0D,
368 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
369 isaprod = _mm_mul_ps(isai0,isaj0);
370 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
371 gbscale = _mm_mul_ps(isaprod,gbtabscale);
373 /* Calculate generalized born table index - this is a separate table from the normal one,
374 * but we use the same procedure by multiplying r with scale and truncating to integer.
376 rt = _mm_mul_ps(r00,gbscale);
377 gbitab = _mm_cvttps_epi32(rt);
379 gbeps = _mm_frcz_ps(rt);
381 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
383 gbitab = _mm_slli_epi32(gbitab,2);
385 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
386 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
387 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
388 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
389 _MM_TRANSPOSE4_PS(Y,F,G,H);
390 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
391 VV = _mm_macc_ps(gbeps,Fp,Y);
392 vgb = _mm_mul_ps(gbqqfactor,VV);
394 twogbeps = _mm_add_ps(gbeps,gbeps);
395 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
396 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
397 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
398 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
399 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
400 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
401 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
402 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
403 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
404 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
405 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
406 velec = _mm_mul_ps(qq00,rinv00);
407 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
409 /* LENNARD-JONES DISPERSION/REPULSION */
411 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
412 vvdw6 = _mm_mul_ps(c6_00,rinvsix);
413 vvdw12 = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
414 vvdw = _mm_msub_ps(vvdw12,one_twelfth,_mm_mul_ps(vvdw6,one_sixth));
415 fvdw = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
417 /* Update potential sum for this i atom from the interaction with this j atom. */
418 velec = _mm_andnot_ps(dummy_mask,velec);
419 velecsum = _mm_add_ps(velecsum,velec);
420 vgb = _mm_andnot_ps(dummy_mask,vgb);
421 vgbsum = _mm_add_ps(vgbsum,vgb);
422 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
423 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
425 fscal = _mm_add_ps(felec,fvdw);
427 fscal = _mm_andnot_ps(dummy_mask,fscal);
429 /* Update vectorial force */
430 fix0 = _mm_macc_ps(dx00,fscal,fix0);
431 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
432 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
434 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
435 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
436 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
437 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
438 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
439 _mm_mul_ps(dx00,fscal),
440 _mm_mul_ps(dy00,fscal),
441 _mm_mul_ps(dz00,fscal));
443 /* Inner loop uses 75 flops */
446 /* End of innermost loop */
448 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
449 f+i_coord_offset,fshift+i_shift_offset);
452 /* Update potential energies */
453 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
454 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
455 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
456 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
457 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
459 /* Increment number of inner iterations */
460 inneriter += j_index_end - j_index_start;
462 /* Outer loop uses 10 flops */
465 /* Increment number of outer iterations */
468 /* Update outer/inner flops */
470 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*10 + inneriter*75);
473 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_single
474 * Electrostatics interaction: GeneralizedBorn
475 * VdW interaction: LennardJones
476 * Geometry: Particle-Particle
477 * Calculate force/pot: Force
480 nb_kernel_ElecGB_VdwLJ_GeomP1P1_F_avx_128_fma_single
481 (t_nblist * gmx_restrict nlist,
482 rvec * gmx_restrict xx,
483 rvec * gmx_restrict ff,
484 t_forcerec * gmx_restrict fr,
485 t_mdatoms * gmx_restrict mdatoms,
486 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
487 t_nrnb * gmx_restrict nrnb)
489 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
490 * just 0 for non-waters.
491 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
492 * jnr indices corresponding to data put in the four positions in the SIMD register.
494 int i_shift_offset,i_coord_offset,outeriter,inneriter;
495 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
496 int jnrA,jnrB,jnrC,jnrD;
497 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
498 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
499 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
501 real *shiftvec,*fshift,*x,*f;
502 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
504 __m128 fscal,rcutoff,rcutoff2,jidxall;
506 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
507 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
508 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
509 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
510 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
513 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,twogbeps,dvdatmp;
514 __m128 minushalf = _mm_set1_ps(-0.5);
515 real *invsqrta,*dvda,*gbtab;
517 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
520 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
521 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
523 __m128i ifour = _mm_set1_epi32(4);
524 __m128 rt,vfeps,twovfeps,vftabscale,Y,F,G,H,Fp,VV,FF;
526 __m128 dummy_mask,cutoff_mask;
527 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
528 __m128 one = _mm_set1_ps(1.0);
529 __m128 two = _mm_set1_ps(2.0);
535 jindex = nlist->jindex;
537 shiftidx = nlist->shift;
539 shiftvec = fr->shift_vec[0];
540 fshift = fr->fshift[0];
541 facel = _mm_set1_ps(fr->epsfac);
542 charge = mdatoms->chargeA;
543 nvdwtype = fr->ntype;
545 vdwtype = mdatoms->typeA;
547 invsqrta = fr->invsqrta;
549 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
550 gbtab = fr->gbtab.data;
551 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
553 /* Avoid stupid compiler warnings */
554 jnrA = jnrB = jnrC = jnrD = 0;
563 for(iidx=0;iidx<4*DIM;iidx++)
568 /* Start outer loop over neighborlists */
569 for(iidx=0; iidx<nri; iidx++)
571 /* Load shift vector for this list */
572 i_shift_offset = DIM*shiftidx[iidx];
574 /* Load limits for loop over neighbors */
575 j_index_start = jindex[iidx];
576 j_index_end = jindex[iidx+1];
578 /* Get outer coordinate index */
580 i_coord_offset = DIM*inr;
582 /* Load i particle coords and add shift vector */
583 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
585 fix0 = _mm_setzero_ps();
586 fiy0 = _mm_setzero_ps();
587 fiz0 = _mm_setzero_ps();
589 /* Load parameters for i particles */
590 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
591 isai0 = _mm_load1_ps(invsqrta+inr+0);
592 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
594 dvdasum = _mm_setzero_ps();
596 /* Start inner kernel loop */
597 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
600 /* Get j neighbor index, and coordinate index */
605 j_coord_offsetA = DIM*jnrA;
606 j_coord_offsetB = DIM*jnrB;
607 j_coord_offsetC = DIM*jnrC;
608 j_coord_offsetD = DIM*jnrD;
610 /* load j atom coordinates */
611 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
612 x+j_coord_offsetC,x+j_coord_offsetD,
615 /* Calculate displacement vector */
616 dx00 = _mm_sub_ps(ix0,jx0);
617 dy00 = _mm_sub_ps(iy0,jy0);
618 dz00 = _mm_sub_ps(iz0,jz0);
620 /* Calculate squared distance and things based on it */
621 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
623 rinv00 = gmx_mm_invsqrt_ps(rsq00);
625 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
627 /* Load parameters for j particles */
628 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
629 charge+jnrC+0,charge+jnrD+0);
630 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
631 invsqrta+jnrC+0,invsqrta+jnrD+0);
632 vdwjidx0A = 2*vdwtype[jnrA+0];
633 vdwjidx0B = 2*vdwtype[jnrB+0];
634 vdwjidx0C = 2*vdwtype[jnrC+0];
635 vdwjidx0D = 2*vdwtype[jnrD+0];
637 /**************************
638 * CALCULATE INTERACTIONS *
639 **************************/
641 r00 = _mm_mul_ps(rsq00,rinv00);
643 /* Compute parameters for interactions between i and j atoms */
644 qq00 = _mm_mul_ps(iq0,jq0);
645 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
646 vdwparam+vdwioffset0+vdwjidx0B,
647 vdwparam+vdwioffset0+vdwjidx0C,
648 vdwparam+vdwioffset0+vdwjidx0D,
651 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
652 isaprod = _mm_mul_ps(isai0,isaj0);
653 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
654 gbscale = _mm_mul_ps(isaprod,gbtabscale);
656 /* Calculate generalized born table index - this is a separate table from the normal one,
657 * but we use the same procedure by multiplying r with scale and truncating to integer.
659 rt = _mm_mul_ps(r00,gbscale);
660 gbitab = _mm_cvttps_epi32(rt);
662 gbeps = _mm_frcz_ps(rt);
664 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
666 gbitab = _mm_slli_epi32(gbitab,2);
668 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
669 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
670 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
671 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
672 _MM_TRANSPOSE4_PS(Y,F,G,H);
673 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
674 VV = _mm_macc_ps(gbeps,Fp,Y);
675 vgb = _mm_mul_ps(gbqqfactor,VV);
677 twogbeps = _mm_add_ps(gbeps,gbeps);
678 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
679 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
680 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
681 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
686 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
687 velec = _mm_mul_ps(qq00,rinv00);
688 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
690 /* LENNARD-JONES DISPERSION/REPULSION */
692 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
693 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
695 fscal = _mm_add_ps(felec,fvdw);
697 /* Update vectorial force */
698 fix0 = _mm_macc_ps(dx00,fscal,fix0);
699 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
700 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
702 fjptrA = f+j_coord_offsetA;
703 fjptrB = f+j_coord_offsetB;
704 fjptrC = f+j_coord_offsetC;
705 fjptrD = f+j_coord_offsetD;
706 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
707 _mm_mul_ps(dx00,fscal),
708 _mm_mul_ps(dy00,fscal),
709 _mm_mul_ps(dz00,fscal));
711 /* Inner loop uses 67 flops */
717 /* Get j neighbor index, and coordinate index */
718 jnrlistA = jjnr[jidx];
719 jnrlistB = jjnr[jidx+1];
720 jnrlistC = jjnr[jidx+2];
721 jnrlistD = jjnr[jidx+3];
722 /* Sign of each element will be negative for non-real atoms.
723 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
724 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
726 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
727 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
728 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
729 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
730 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
731 j_coord_offsetA = DIM*jnrA;
732 j_coord_offsetB = DIM*jnrB;
733 j_coord_offsetC = DIM*jnrC;
734 j_coord_offsetD = DIM*jnrD;
736 /* load j atom coordinates */
737 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
738 x+j_coord_offsetC,x+j_coord_offsetD,
741 /* Calculate displacement vector */
742 dx00 = _mm_sub_ps(ix0,jx0);
743 dy00 = _mm_sub_ps(iy0,jy0);
744 dz00 = _mm_sub_ps(iz0,jz0);
746 /* Calculate squared distance and things based on it */
747 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
749 rinv00 = gmx_mm_invsqrt_ps(rsq00);
751 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
753 /* Load parameters for j particles */
754 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
755 charge+jnrC+0,charge+jnrD+0);
756 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
757 invsqrta+jnrC+0,invsqrta+jnrD+0);
758 vdwjidx0A = 2*vdwtype[jnrA+0];
759 vdwjidx0B = 2*vdwtype[jnrB+0];
760 vdwjidx0C = 2*vdwtype[jnrC+0];
761 vdwjidx0D = 2*vdwtype[jnrD+0];
763 /**************************
764 * CALCULATE INTERACTIONS *
765 **************************/
767 r00 = _mm_mul_ps(rsq00,rinv00);
768 r00 = _mm_andnot_ps(dummy_mask,r00);
770 /* Compute parameters for interactions between i and j atoms */
771 qq00 = _mm_mul_ps(iq0,jq0);
772 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
773 vdwparam+vdwioffset0+vdwjidx0B,
774 vdwparam+vdwioffset0+vdwjidx0C,
775 vdwparam+vdwioffset0+vdwjidx0D,
778 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
779 isaprod = _mm_mul_ps(isai0,isaj0);
780 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
781 gbscale = _mm_mul_ps(isaprod,gbtabscale);
783 /* Calculate generalized born table index - this is a separate table from the normal one,
784 * but we use the same procedure by multiplying r with scale and truncating to integer.
786 rt = _mm_mul_ps(r00,gbscale);
787 gbitab = _mm_cvttps_epi32(rt);
789 gbeps = _mm_frcz_ps(rt);
791 gbeps = _mm_sub_ps(rt,_mm_round_ps(rt, _MM_FROUND_FLOOR));
793 gbitab = _mm_slli_epi32(gbitab,2);
795 Y = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,0) );
796 F = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,1) );
797 G = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,2) );
798 H = _mm_load_ps( gbtab + _mm_extract_epi32(gbitab,3) );
799 _MM_TRANSPOSE4_PS(Y,F,G,H);
800 Fp = _mm_macc_ps(gbeps,_mm_macc_ps(gbeps,H,G),F);
801 VV = _mm_macc_ps(gbeps,Fp,Y);
802 vgb = _mm_mul_ps(gbqqfactor,VV);
804 twogbeps = _mm_add_ps(gbeps,gbeps);
805 FF = _mm_macc_ps(_mm_macc_ps(twogbeps,H,G),gbeps,Fp);
806 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
807 dvdatmp = _mm_mul_ps(minushalf,_mm_macc_ps(fgb,r00,vgb));
808 dvdatmp = _mm_andnot_ps(dummy_mask,dvdatmp);
809 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
810 /* The pointers to scratch make sure that this code with compilers that take gmx_restrict seriously (e.g. icc 13) really can't screw things up. */
811 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
812 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
813 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
814 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
815 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
816 velec = _mm_mul_ps(qq00,rinv00);
817 felec = _mm_mul_ps(_mm_msub_ps(velec,rinv00,fgb),rinv00);
819 /* LENNARD-JONES DISPERSION/REPULSION */
821 rinvsix = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
822 fvdw = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
824 fscal = _mm_add_ps(felec,fvdw);
826 fscal = _mm_andnot_ps(dummy_mask,fscal);
828 /* Update vectorial force */
829 fix0 = _mm_macc_ps(dx00,fscal,fix0);
830 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
831 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
833 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
834 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
835 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
836 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
837 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
838 _mm_mul_ps(dx00,fscal),
839 _mm_mul_ps(dy00,fscal),
840 _mm_mul_ps(dz00,fscal));
842 /* Inner loop uses 68 flops */
845 /* End of innermost loop */
847 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
848 f+i_coord_offset,fshift+i_shift_offset);
850 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
851 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
853 /* Increment number of inner iterations */
854 inneriter += j_index_end - j_index_start;
856 /* Outer loop uses 7 flops */
859 /* Increment number of outer iterations */
862 /* Update outer/inner flops */
864 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*68);