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_256_single kernel generator.
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
49 #include "gromacs/simd/math_x86_avx_256_single.h"
50 #include "kernelutil_x86_avx_256_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomP1P1_VF_avx_256_single
54 * Electrostatics interaction: ReactionField
55 * VdW interaction: LennardJones
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecRF_VdwLJ_GeomP1P1_VF_avx_256_single
61 (t_nblist * gmx_restrict nlist,
62 rvec * gmx_restrict xx,
63 rvec * gmx_restrict ff,
64 t_forcerec * gmx_restrict fr,
65 t_mdatoms * gmx_restrict mdatoms,
66 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67 t_nrnb * gmx_restrict nrnb)
69 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
70 * just 0 for non-waters.
71 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
72 * jnr indices corresponding to data put in the four positions in the SIMD register.
74 int i_shift_offset,i_coord_offset,outeriter,inneriter;
75 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76 int jnrA,jnrB,jnrC,jnrD;
77 int jnrE,jnrF,jnrG,jnrH;
78 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
79 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
80 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
81 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
82 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
84 real *shiftvec,*fshift,*x,*f;
85 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
87 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
88 real * vdwioffsetptr0;
89 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
90 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
91 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
92 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
93 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
96 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
99 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
100 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
101 __m256 dummy_mask,cutoff_mask;
102 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
103 __m256 one = _mm256_set1_ps(1.0);
104 __m256 two = _mm256_set1_ps(2.0);
110 jindex = nlist->jindex;
112 shiftidx = nlist->shift;
114 shiftvec = fr->shift_vec[0];
115 fshift = fr->fshift[0];
116 facel = _mm256_set1_ps(fr->epsfac);
117 charge = mdatoms->chargeA;
118 krf = _mm256_set1_ps(fr->ic->k_rf);
119 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
120 crf = _mm256_set1_ps(fr->ic->c_rf);
121 nvdwtype = fr->ntype;
123 vdwtype = mdatoms->typeA;
125 /* Avoid stupid compiler warnings */
126 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
139 for(iidx=0;iidx<4*DIM;iidx++)
144 /* Start outer loop over neighborlists */
145 for(iidx=0; iidx<nri; iidx++)
147 /* Load shift vector for this list */
148 i_shift_offset = DIM*shiftidx[iidx];
150 /* Load limits for loop over neighbors */
151 j_index_start = jindex[iidx];
152 j_index_end = jindex[iidx+1];
154 /* Get outer coordinate index */
156 i_coord_offset = DIM*inr;
158 /* Load i particle coords and add shift vector */
159 gmx_mm256_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
161 fix0 = _mm256_setzero_ps();
162 fiy0 = _mm256_setzero_ps();
163 fiz0 = _mm256_setzero_ps();
165 /* Load parameters for i particles */
166 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
167 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
169 /* Reset potential sums */
170 velecsum = _mm256_setzero_ps();
171 vvdwsum = _mm256_setzero_ps();
173 /* Start inner kernel loop */
174 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
177 /* Get j neighbor index, and coordinate index */
186 j_coord_offsetA = DIM*jnrA;
187 j_coord_offsetB = DIM*jnrB;
188 j_coord_offsetC = DIM*jnrC;
189 j_coord_offsetD = DIM*jnrD;
190 j_coord_offsetE = DIM*jnrE;
191 j_coord_offsetF = DIM*jnrF;
192 j_coord_offsetG = DIM*jnrG;
193 j_coord_offsetH = DIM*jnrH;
195 /* load j atom coordinates */
196 gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
197 x+j_coord_offsetC,x+j_coord_offsetD,
198 x+j_coord_offsetE,x+j_coord_offsetF,
199 x+j_coord_offsetG,x+j_coord_offsetH,
202 /* Calculate displacement vector */
203 dx00 = _mm256_sub_ps(ix0,jx0);
204 dy00 = _mm256_sub_ps(iy0,jy0);
205 dz00 = _mm256_sub_ps(iz0,jz0);
207 /* Calculate squared distance and things based on it */
208 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
210 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
212 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
214 /* Load parameters for j particles */
215 jq0 = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
216 charge+jnrC+0,charge+jnrD+0,
217 charge+jnrE+0,charge+jnrF+0,
218 charge+jnrG+0,charge+jnrH+0);
219 vdwjidx0A = 2*vdwtype[jnrA+0];
220 vdwjidx0B = 2*vdwtype[jnrB+0];
221 vdwjidx0C = 2*vdwtype[jnrC+0];
222 vdwjidx0D = 2*vdwtype[jnrD+0];
223 vdwjidx0E = 2*vdwtype[jnrE+0];
224 vdwjidx0F = 2*vdwtype[jnrF+0];
225 vdwjidx0G = 2*vdwtype[jnrG+0];
226 vdwjidx0H = 2*vdwtype[jnrH+0];
228 /**************************
229 * CALCULATE INTERACTIONS *
230 **************************/
232 /* Compute parameters for interactions between i and j atoms */
233 qq00 = _mm256_mul_ps(iq0,jq0);
234 gmx_mm256_load_8pair_swizzle_ps(vdwioffsetptr0+vdwjidx0A,
235 vdwioffsetptr0+vdwjidx0B,
236 vdwioffsetptr0+vdwjidx0C,
237 vdwioffsetptr0+vdwjidx0D,
238 vdwioffsetptr0+vdwjidx0E,
239 vdwioffsetptr0+vdwjidx0F,
240 vdwioffsetptr0+vdwjidx0G,
241 vdwioffsetptr0+vdwjidx0H,
244 /* REACTION-FIELD ELECTROSTATICS */
245 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
246 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
248 /* LENNARD-JONES DISPERSION/REPULSION */
250 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
251 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
252 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
253 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
254 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
256 /* Update potential sum for this i atom from the interaction with this j atom. */
257 velecsum = _mm256_add_ps(velecsum,velec);
258 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
260 fscal = _mm256_add_ps(felec,fvdw);
262 /* Calculate temporary vectorial force */
263 tx = _mm256_mul_ps(fscal,dx00);
264 ty = _mm256_mul_ps(fscal,dy00);
265 tz = _mm256_mul_ps(fscal,dz00);
267 /* Update vectorial force */
268 fix0 = _mm256_add_ps(fix0,tx);
269 fiy0 = _mm256_add_ps(fiy0,ty);
270 fiz0 = _mm256_add_ps(fiz0,tz);
272 fjptrA = f+j_coord_offsetA;
273 fjptrB = f+j_coord_offsetB;
274 fjptrC = f+j_coord_offsetC;
275 fjptrD = f+j_coord_offsetD;
276 fjptrE = f+j_coord_offsetE;
277 fjptrF = f+j_coord_offsetF;
278 fjptrG = f+j_coord_offsetG;
279 fjptrH = f+j_coord_offsetH;
280 gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
282 /* Inner loop uses 44 flops */
288 /* Get j neighbor index, and coordinate index */
289 jnrlistA = jjnr[jidx];
290 jnrlistB = jjnr[jidx+1];
291 jnrlistC = jjnr[jidx+2];
292 jnrlistD = jjnr[jidx+3];
293 jnrlistE = jjnr[jidx+4];
294 jnrlistF = jjnr[jidx+5];
295 jnrlistG = jjnr[jidx+6];
296 jnrlistH = jjnr[jidx+7];
297 /* Sign of each element will be negative for non-real atoms.
298 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
299 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
301 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
302 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
304 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
305 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
306 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
307 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
308 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
309 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
310 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
311 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
312 j_coord_offsetA = DIM*jnrA;
313 j_coord_offsetB = DIM*jnrB;
314 j_coord_offsetC = DIM*jnrC;
315 j_coord_offsetD = DIM*jnrD;
316 j_coord_offsetE = DIM*jnrE;
317 j_coord_offsetF = DIM*jnrF;
318 j_coord_offsetG = DIM*jnrG;
319 j_coord_offsetH = DIM*jnrH;
321 /* load j atom coordinates */
322 gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
323 x+j_coord_offsetC,x+j_coord_offsetD,
324 x+j_coord_offsetE,x+j_coord_offsetF,
325 x+j_coord_offsetG,x+j_coord_offsetH,
328 /* Calculate displacement vector */
329 dx00 = _mm256_sub_ps(ix0,jx0);
330 dy00 = _mm256_sub_ps(iy0,jy0);
331 dz00 = _mm256_sub_ps(iz0,jz0);
333 /* Calculate squared distance and things based on it */
334 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
336 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
338 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
340 /* Load parameters for j particles */
341 jq0 = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
342 charge+jnrC+0,charge+jnrD+0,
343 charge+jnrE+0,charge+jnrF+0,
344 charge+jnrG+0,charge+jnrH+0);
345 vdwjidx0A = 2*vdwtype[jnrA+0];
346 vdwjidx0B = 2*vdwtype[jnrB+0];
347 vdwjidx0C = 2*vdwtype[jnrC+0];
348 vdwjidx0D = 2*vdwtype[jnrD+0];
349 vdwjidx0E = 2*vdwtype[jnrE+0];
350 vdwjidx0F = 2*vdwtype[jnrF+0];
351 vdwjidx0G = 2*vdwtype[jnrG+0];
352 vdwjidx0H = 2*vdwtype[jnrH+0];
354 /**************************
355 * CALCULATE INTERACTIONS *
356 **************************/
358 /* Compute parameters for interactions between i and j atoms */
359 qq00 = _mm256_mul_ps(iq0,jq0);
360 gmx_mm256_load_8pair_swizzle_ps(vdwioffsetptr0+vdwjidx0A,
361 vdwioffsetptr0+vdwjidx0B,
362 vdwioffsetptr0+vdwjidx0C,
363 vdwioffsetptr0+vdwjidx0D,
364 vdwioffsetptr0+vdwjidx0E,
365 vdwioffsetptr0+vdwjidx0F,
366 vdwioffsetptr0+vdwjidx0G,
367 vdwioffsetptr0+vdwjidx0H,
370 /* REACTION-FIELD ELECTROSTATICS */
371 velec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
372 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
374 /* LENNARD-JONES DISPERSION/REPULSION */
376 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
377 vvdw6 = _mm256_mul_ps(c6_00,rinvsix);
378 vvdw12 = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
379 vvdw = _mm256_sub_ps( _mm256_mul_ps(vvdw12,one_twelfth) , _mm256_mul_ps(vvdw6,one_sixth) );
380 fvdw = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
382 /* Update potential sum for this i atom from the interaction with this j atom. */
383 velec = _mm256_andnot_ps(dummy_mask,velec);
384 velecsum = _mm256_add_ps(velecsum,velec);
385 vvdw = _mm256_andnot_ps(dummy_mask,vvdw);
386 vvdwsum = _mm256_add_ps(vvdwsum,vvdw);
388 fscal = _mm256_add_ps(felec,fvdw);
390 fscal = _mm256_andnot_ps(dummy_mask,fscal);
392 /* Calculate temporary vectorial force */
393 tx = _mm256_mul_ps(fscal,dx00);
394 ty = _mm256_mul_ps(fscal,dy00);
395 tz = _mm256_mul_ps(fscal,dz00);
397 /* Update vectorial force */
398 fix0 = _mm256_add_ps(fix0,tx);
399 fiy0 = _mm256_add_ps(fiy0,ty);
400 fiz0 = _mm256_add_ps(fiz0,tz);
402 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
403 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
404 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
405 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
406 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
407 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
408 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
409 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
410 gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
412 /* Inner loop uses 44 flops */
415 /* End of innermost loop */
417 gmx_mm256_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
418 f+i_coord_offset,fshift+i_shift_offset);
421 /* Update potential energies */
422 gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
423 gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
425 /* Increment number of inner iterations */
426 inneriter += j_index_end - j_index_start;
428 /* Outer loop uses 9 flops */
431 /* Increment number of outer iterations */
434 /* Update outer/inner flops */
436 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*44);
439 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomP1P1_F_avx_256_single
440 * Electrostatics interaction: ReactionField
441 * VdW interaction: LennardJones
442 * Geometry: Particle-Particle
443 * Calculate force/pot: Force
446 nb_kernel_ElecRF_VdwLJ_GeomP1P1_F_avx_256_single
447 (t_nblist * gmx_restrict nlist,
448 rvec * gmx_restrict xx,
449 rvec * gmx_restrict ff,
450 t_forcerec * gmx_restrict fr,
451 t_mdatoms * gmx_restrict mdatoms,
452 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
453 t_nrnb * gmx_restrict nrnb)
455 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
456 * just 0 for non-waters.
457 * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
458 * jnr indices corresponding to data put in the four positions in the SIMD register.
460 int i_shift_offset,i_coord_offset,outeriter,inneriter;
461 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
462 int jnrA,jnrB,jnrC,jnrD;
463 int jnrE,jnrF,jnrG,jnrH;
464 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
465 int jnrlistE,jnrlistF,jnrlistG,jnrlistH;
466 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
467 int j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
468 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
470 real *shiftvec,*fshift,*x,*f;
471 real *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
473 __m256 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
474 real * vdwioffsetptr0;
475 __m256 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
476 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
477 __m256 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
478 __m256 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
479 __m256 velec,felec,velecsum,facel,crf,krf,krf2;
482 __m256 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
485 __m256 one_sixth = _mm256_set1_ps(1.0/6.0);
486 __m256 one_twelfth = _mm256_set1_ps(1.0/12.0);
487 __m256 dummy_mask,cutoff_mask;
488 __m256 signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
489 __m256 one = _mm256_set1_ps(1.0);
490 __m256 two = _mm256_set1_ps(2.0);
496 jindex = nlist->jindex;
498 shiftidx = nlist->shift;
500 shiftvec = fr->shift_vec[0];
501 fshift = fr->fshift[0];
502 facel = _mm256_set1_ps(fr->epsfac);
503 charge = mdatoms->chargeA;
504 krf = _mm256_set1_ps(fr->ic->k_rf);
505 krf2 = _mm256_set1_ps(fr->ic->k_rf*2.0);
506 crf = _mm256_set1_ps(fr->ic->c_rf);
507 nvdwtype = fr->ntype;
509 vdwtype = mdatoms->typeA;
511 /* Avoid stupid compiler warnings */
512 jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
525 for(iidx=0;iidx<4*DIM;iidx++)
530 /* Start outer loop over neighborlists */
531 for(iidx=0; iidx<nri; iidx++)
533 /* Load shift vector for this list */
534 i_shift_offset = DIM*shiftidx[iidx];
536 /* Load limits for loop over neighbors */
537 j_index_start = jindex[iidx];
538 j_index_end = jindex[iidx+1];
540 /* Get outer coordinate index */
542 i_coord_offset = DIM*inr;
544 /* Load i particle coords and add shift vector */
545 gmx_mm256_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
547 fix0 = _mm256_setzero_ps();
548 fiy0 = _mm256_setzero_ps();
549 fiz0 = _mm256_setzero_ps();
551 /* Load parameters for i particles */
552 iq0 = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
553 vdwioffsetptr0 = vdwparam+2*nvdwtype*vdwtype[inr+0];
555 /* Start inner kernel loop */
556 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
559 /* Get j neighbor index, and coordinate index */
568 j_coord_offsetA = DIM*jnrA;
569 j_coord_offsetB = DIM*jnrB;
570 j_coord_offsetC = DIM*jnrC;
571 j_coord_offsetD = DIM*jnrD;
572 j_coord_offsetE = DIM*jnrE;
573 j_coord_offsetF = DIM*jnrF;
574 j_coord_offsetG = DIM*jnrG;
575 j_coord_offsetH = DIM*jnrH;
577 /* load j atom coordinates */
578 gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
579 x+j_coord_offsetC,x+j_coord_offsetD,
580 x+j_coord_offsetE,x+j_coord_offsetF,
581 x+j_coord_offsetG,x+j_coord_offsetH,
584 /* Calculate displacement vector */
585 dx00 = _mm256_sub_ps(ix0,jx0);
586 dy00 = _mm256_sub_ps(iy0,jy0);
587 dz00 = _mm256_sub_ps(iz0,jz0);
589 /* Calculate squared distance and things based on it */
590 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
592 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
594 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
596 /* Load parameters for j particles */
597 jq0 = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
598 charge+jnrC+0,charge+jnrD+0,
599 charge+jnrE+0,charge+jnrF+0,
600 charge+jnrG+0,charge+jnrH+0);
601 vdwjidx0A = 2*vdwtype[jnrA+0];
602 vdwjidx0B = 2*vdwtype[jnrB+0];
603 vdwjidx0C = 2*vdwtype[jnrC+0];
604 vdwjidx0D = 2*vdwtype[jnrD+0];
605 vdwjidx0E = 2*vdwtype[jnrE+0];
606 vdwjidx0F = 2*vdwtype[jnrF+0];
607 vdwjidx0G = 2*vdwtype[jnrG+0];
608 vdwjidx0H = 2*vdwtype[jnrH+0];
610 /**************************
611 * CALCULATE INTERACTIONS *
612 **************************/
614 /* Compute parameters for interactions between i and j atoms */
615 qq00 = _mm256_mul_ps(iq0,jq0);
616 gmx_mm256_load_8pair_swizzle_ps(vdwioffsetptr0+vdwjidx0A,
617 vdwioffsetptr0+vdwjidx0B,
618 vdwioffsetptr0+vdwjidx0C,
619 vdwioffsetptr0+vdwjidx0D,
620 vdwioffsetptr0+vdwjidx0E,
621 vdwioffsetptr0+vdwjidx0F,
622 vdwioffsetptr0+vdwjidx0G,
623 vdwioffsetptr0+vdwjidx0H,
626 /* REACTION-FIELD ELECTROSTATICS */
627 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
629 /* LENNARD-JONES DISPERSION/REPULSION */
631 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
632 fvdw = _mm256_mul_ps(_mm256_sub_ps(_mm256_mul_ps(c12_00,rinvsix),c6_00),_mm256_mul_ps(rinvsix,rinvsq00));
634 fscal = _mm256_add_ps(felec,fvdw);
636 /* Calculate temporary vectorial force */
637 tx = _mm256_mul_ps(fscal,dx00);
638 ty = _mm256_mul_ps(fscal,dy00);
639 tz = _mm256_mul_ps(fscal,dz00);
641 /* Update vectorial force */
642 fix0 = _mm256_add_ps(fix0,tx);
643 fiy0 = _mm256_add_ps(fiy0,ty);
644 fiz0 = _mm256_add_ps(fiz0,tz);
646 fjptrA = f+j_coord_offsetA;
647 fjptrB = f+j_coord_offsetB;
648 fjptrC = f+j_coord_offsetC;
649 fjptrD = f+j_coord_offsetD;
650 fjptrE = f+j_coord_offsetE;
651 fjptrF = f+j_coord_offsetF;
652 fjptrG = f+j_coord_offsetG;
653 fjptrH = f+j_coord_offsetH;
654 gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
656 /* Inner loop uses 34 flops */
662 /* Get j neighbor index, and coordinate index */
663 jnrlistA = jjnr[jidx];
664 jnrlistB = jjnr[jidx+1];
665 jnrlistC = jjnr[jidx+2];
666 jnrlistD = jjnr[jidx+3];
667 jnrlistE = jjnr[jidx+4];
668 jnrlistF = jjnr[jidx+5];
669 jnrlistG = jjnr[jidx+6];
670 jnrlistH = jjnr[jidx+7];
671 /* Sign of each element will be negative for non-real atoms.
672 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
673 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
675 dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
676 gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
678 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
679 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
680 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
681 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
682 jnrE = (jnrlistE>=0) ? jnrlistE : 0;
683 jnrF = (jnrlistF>=0) ? jnrlistF : 0;
684 jnrG = (jnrlistG>=0) ? jnrlistG : 0;
685 jnrH = (jnrlistH>=0) ? jnrlistH : 0;
686 j_coord_offsetA = DIM*jnrA;
687 j_coord_offsetB = DIM*jnrB;
688 j_coord_offsetC = DIM*jnrC;
689 j_coord_offsetD = DIM*jnrD;
690 j_coord_offsetE = DIM*jnrE;
691 j_coord_offsetF = DIM*jnrF;
692 j_coord_offsetG = DIM*jnrG;
693 j_coord_offsetH = DIM*jnrH;
695 /* load j atom coordinates */
696 gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
697 x+j_coord_offsetC,x+j_coord_offsetD,
698 x+j_coord_offsetE,x+j_coord_offsetF,
699 x+j_coord_offsetG,x+j_coord_offsetH,
702 /* Calculate displacement vector */
703 dx00 = _mm256_sub_ps(ix0,jx0);
704 dy00 = _mm256_sub_ps(iy0,jy0);
705 dz00 = _mm256_sub_ps(iz0,jz0);
707 /* Calculate squared distance and things based on it */
708 rsq00 = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
710 rinv00 = gmx_mm256_invsqrt_ps(rsq00);
712 rinvsq00 = _mm256_mul_ps(rinv00,rinv00);
714 /* Load parameters for j particles */
715 jq0 = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
716 charge+jnrC+0,charge+jnrD+0,
717 charge+jnrE+0,charge+jnrF+0,
718 charge+jnrG+0,charge+jnrH+0);
719 vdwjidx0A = 2*vdwtype[jnrA+0];
720 vdwjidx0B = 2*vdwtype[jnrB+0];
721 vdwjidx0C = 2*vdwtype[jnrC+0];
722 vdwjidx0D = 2*vdwtype[jnrD+0];
723 vdwjidx0E = 2*vdwtype[jnrE+0];
724 vdwjidx0F = 2*vdwtype[jnrF+0];
725 vdwjidx0G = 2*vdwtype[jnrG+0];
726 vdwjidx0H = 2*vdwtype[jnrH+0];
728 /**************************
729 * CALCULATE INTERACTIONS *
730 **************************/
732 /* Compute parameters for interactions between i and j atoms */
733 qq00 = _mm256_mul_ps(iq0,jq0);
734 gmx_mm256_load_8pair_swizzle_ps(vdwioffsetptr0+vdwjidx0A,
735 vdwioffsetptr0+vdwjidx0B,
736 vdwioffsetptr0+vdwjidx0C,
737 vdwioffsetptr0+vdwjidx0D,
738 vdwioffsetptr0+vdwjidx0E,
739 vdwioffsetptr0+vdwjidx0F,
740 vdwioffsetptr0+vdwjidx0G,
741 vdwioffsetptr0+vdwjidx0H,
744 /* REACTION-FIELD ELECTROSTATICS */
745 felec = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
747 /* LENNARD-JONES DISPERSION/REPULSION */
749 rinvsix = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
750 fvdw = _mm256_mul_ps(_mm256_sub_ps(_mm256_mul_ps(c12_00,rinvsix),c6_00),_mm256_mul_ps(rinvsix,rinvsq00));
752 fscal = _mm256_add_ps(felec,fvdw);
754 fscal = _mm256_andnot_ps(dummy_mask,fscal);
756 /* Calculate temporary vectorial force */
757 tx = _mm256_mul_ps(fscal,dx00);
758 ty = _mm256_mul_ps(fscal,dy00);
759 tz = _mm256_mul_ps(fscal,dz00);
761 /* Update vectorial force */
762 fix0 = _mm256_add_ps(fix0,tx);
763 fiy0 = _mm256_add_ps(fiy0,ty);
764 fiz0 = _mm256_add_ps(fiz0,tz);
766 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
767 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
768 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
769 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
770 fjptrE = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
771 fjptrF = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
772 fjptrG = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
773 fjptrH = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
774 gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
776 /* Inner loop uses 34 flops */
779 /* End of innermost loop */
781 gmx_mm256_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
782 f+i_coord_offset,fshift+i_shift_offset);
784 /* Increment number of inner iterations */
785 inneriter += j_index_end - j_index_start;
787 /* Outer loop uses 7 flops */
790 /* Increment number of outer iterations */
793 /* Update outer/inner flops */
795 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*34);