Fix segmentation fault in minimize
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_single / nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_sse2_single.cpp
blobb8339e44a89157001ef0d398ea41b7e79b08c870
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017,2018, 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_single kernel generator.
38 #include "gmxpre.h"
40 #include "config.h"
42 #include <math.h>
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_VF_sse2_single
51 * Electrostatics interaction: Coulomb
52 * VdW interaction: CubicSplineTable
53 * Geometry: Water3-Particle
54 * Calculate force/pot: PotentialAndForce
56 void
57 nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_VF_sse2_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real rcutoff_scalar;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
80 real scratch[4*DIM];
81 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82 int vdwioffset0;
83 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84 int vdwioffset1;
85 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
86 int vdwioffset2;
87 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
94 real *charge;
95 int nvdwtype;
96 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 int *vdwtype;
98 real *vdwparam;
99 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
100 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
101 __m128i vfitab;
102 __m128i ifour = _mm_set1_epi32(4);
103 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
104 real *vftab;
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);
109 x = xx[0];
110 f = ff[0];
112 nri = nlist->nri;
113 iinr = nlist->iinr;
114 jindex = nlist->jindex;
115 jjnr = nlist->jjnr;
116 shiftidx = nlist->shift;
117 gid = nlist->gid;
118 shiftvec = fr->shift_vec[0];
119 fshift = fr->fshift[0];
120 facel = _mm_set1_ps(fr->ic->epsfac);
121 charge = mdatoms->chargeA;
122 nvdwtype = fr->ntype;
123 vdwparam = fr->nbfp;
124 vdwtype = mdatoms->typeA;
126 vftab = kernel_data->table_vdw->data;
127 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
129 /* Setup water-specific parameters */
130 inr = nlist->iinr[0];
131 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
132 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
133 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
134 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
136 /* Avoid stupid compiler warnings */
137 jnrA = jnrB = jnrC = jnrD = 0;
138 j_coord_offsetA = 0;
139 j_coord_offsetB = 0;
140 j_coord_offsetC = 0;
141 j_coord_offsetD = 0;
143 outeriter = 0;
144 inneriter = 0;
146 for(iidx=0;iidx<4*DIM;iidx++)
148 scratch[iidx] = 0.0;
151 /* Start outer loop over neighborlists */
152 for(iidx=0; iidx<nri; iidx++)
154 /* Load shift vector for this list */
155 i_shift_offset = DIM*shiftidx[iidx];
157 /* Load limits for loop over neighbors */
158 j_index_start = jindex[iidx];
159 j_index_end = jindex[iidx+1];
161 /* Get outer coordinate index */
162 inr = iinr[iidx];
163 i_coord_offset = DIM*inr;
165 /* Load i particle coords and add shift vector */
166 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
167 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
169 fix0 = _mm_setzero_ps();
170 fiy0 = _mm_setzero_ps();
171 fiz0 = _mm_setzero_ps();
172 fix1 = _mm_setzero_ps();
173 fiy1 = _mm_setzero_ps();
174 fiz1 = _mm_setzero_ps();
175 fix2 = _mm_setzero_ps();
176 fiy2 = _mm_setzero_ps();
177 fiz2 = _mm_setzero_ps();
179 /* Reset potential sums */
180 velecsum = _mm_setzero_ps();
181 vvdwsum = _mm_setzero_ps();
183 /* Start inner kernel loop */
184 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
187 /* Get j neighbor index, and coordinate index */
188 jnrA = jjnr[jidx];
189 jnrB = jjnr[jidx+1];
190 jnrC = jjnr[jidx+2];
191 jnrD = jjnr[jidx+3];
192 j_coord_offsetA = DIM*jnrA;
193 j_coord_offsetB = DIM*jnrB;
194 j_coord_offsetC = DIM*jnrC;
195 j_coord_offsetD = DIM*jnrD;
197 /* load j atom coordinates */
198 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
199 x+j_coord_offsetC,x+j_coord_offsetD,
200 &jx0,&jy0,&jz0);
202 /* Calculate displacement vector */
203 dx00 = _mm_sub_ps(ix0,jx0);
204 dy00 = _mm_sub_ps(iy0,jy0);
205 dz00 = _mm_sub_ps(iz0,jz0);
206 dx10 = _mm_sub_ps(ix1,jx0);
207 dy10 = _mm_sub_ps(iy1,jy0);
208 dz10 = _mm_sub_ps(iz1,jz0);
209 dx20 = _mm_sub_ps(ix2,jx0);
210 dy20 = _mm_sub_ps(iy2,jy0);
211 dz20 = _mm_sub_ps(iz2,jz0);
213 /* Calculate squared distance and things based on it */
214 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
215 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
216 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
218 rinv00 = sse2_invsqrt_f(rsq00);
219 rinv10 = sse2_invsqrt_f(rsq10);
220 rinv20 = sse2_invsqrt_f(rsq20);
222 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
223 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
224 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
226 /* Load parameters for j particles */
227 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
228 charge+jnrC+0,charge+jnrD+0);
229 vdwjidx0A = 2*vdwtype[jnrA+0];
230 vdwjidx0B = 2*vdwtype[jnrB+0];
231 vdwjidx0C = 2*vdwtype[jnrC+0];
232 vdwjidx0D = 2*vdwtype[jnrD+0];
234 fjx0 = _mm_setzero_ps();
235 fjy0 = _mm_setzero_ps();
236 fjz0 = _mm_setzero_ps();
238 /**************************
239 * CALCULATE INTERACTIONS *
240 **************************/
242 r00 = _mm_mul_ps(rsq00,rinv00);
244 /* Compute parameters for interactions between i and j atoms */
245 qq00 = _mm_mul_ps(iq0,jq0);
246 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
247 vdwparam+vdwioffset0+vdwjidx0B,
248 vdwparam+vdwioffset0+vdwjidx0C,
249 vdwparam+vdwioffset0+vdwjidx0D,
250 &c6_00,&c12_00);
252 /* Calculate table index by multiplying r with table scale and truncate to integer */
253 rt = _mm_mul_ps(r00,vftabscale);
254 vfitab = _mm_cvttps_epi32(rt);
255 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
256 vfitab = _mm_slli_epi32(vfitab,3);
258 /* COULOMB ELECTROSTATICS */
259 velec = _mm_mul_ps(qq00,rinv00);
260 felec = _mm_mul_ps(velec,rinvsq00);
262 /* CUBIC SPLINE TABLE DISPERSION */
263 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
264 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
265 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
266 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
267 _MM_TRANSPOSE4_PS(Y,F,G,H);
268 Heps = _mm_mul_ps(vfeps,H);
269 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
270 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
271 vvdw6 = _mm_mul_ps(c6_00,VV);
272 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
273 fvdw6 = _mm_mul_ps(c6_00,FF);
275 /* CUBIC SPLINE TABLE REPULSION */
276 vfitab = _mm_add_epi32(vfitab,ifour);
277 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
278 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
279 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
280 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
281 _MM_TRANSPOSE4_PS(Y,F,G,H);
282 Heps = _mm_mul_ps(vfeps,H);
283 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
284 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
285 vvdw12 = _mm_mul_ps(c12_00,VV);
286 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
287 fvdw12 = _mm_mul_ps(c12_00,FF);
288 vvdw = _mm_add_ps(vvdw12,vvdw6);
289 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
291 /* Update potential sum for this i atom from the interaction with this j atom. */
292 velecsum = _mm_add_ps(velecsum,velec);
293 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
295 fscal = _mm_add_ps(felec,fvdw);
297 /* Calculate temporary vectorial force */
298 tx = _mm_mul_ps(fscal,dx00);
299 ty = _mm_mul_ps(fscal,dy00);
300 tz = _mm_mul_ps(fscal,dz00);
302 /* Update vectorial force */
303 fix0 = _mm_add_ps(fix0,tx);
304 fiy0 = _mm_add_ps(fiy0,ty);
305 fiz0 = _mm_add_ps(fiz0,tz);
307 fjx0 = _mm_add_ps(fjx0,tx);
308 fjy0 = _mm_add_ps(fjy0,ty);
309 fjz0 = _mm_add_ps(fjz0,tz);
311 /**************************
312 * CALCULATE INTERACTIONS *
313 **************************/
315 /* Compute parameters for interactions between i and j atoms */
316 qq10 = _mm_mul_ps(iq1,jq0);
318 /* COULOMB ELECTROSTATICS */
319 velec = _mm_mul_ps(qq10,rinv10);
320 felec = _mm_mul_ps(velec,rinvsq10);
322 /* Update potential sum for this i atom from the interaction with this j atom. */
323 velecsum = _mm_add_ps(velecsum,velec);
325 fscal = felec;
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);
341 /**************************
342 * CALCULATE INTERACTIONS *
343 **************************/
345 /* Compute parameters for interactions between i and j atoms */
346 qq20 = _mm_mul_ps(iq2,jq0);
348 /* COULOMB ELECTROSTATICS */
349 velec = _mm_mul_ps(qq20,rinv20);
350 felec = _mm_mul_ps(velec,rinvsq20);
352 /* Update potential sum for this i atom from the interaction with this j atom. */
353 velecsum = _mm_add_ps(velecsum,velec);
355 fscal = felec;
357 /* Calculate temporary vectorial force */
358 tx = _mm_mul_ps(fscal,dx20);
359 ty = _mm_mul_ps(fscal,dy20);
360 tz = _mm_mul_ps(fscal,dz20);
362 /* Update vectorial force */
363 fix2 = _mm_add_ps(fix2,tx);
364 fiy2 = _mm_add_ps(fiy2,ty);
365 fiz2 = _mm_add_ps(fiz2,tz);
367 fjx0 = _mm_add_ps(fjx0,tx);
368 fjy0 = _mm_add_ps(fjy0,ty);
369 fjz0 = _mm_add_ps(fjz0,tz);
371 fjptrA = f+j_coord_offsetA;
372 fjptrB = f+j_coord_offsetB;
373 fjptrC = f+j_coord_offsetC;
374 fjptrD = f+j_coord_offsetD;
376 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
378 /* Inner loop uses 119 flops */
381 if(jidx<j_index_end)
384 /* Get j neighbor index, and coordinate index */
385 jnrlistA = jjnr[jidx];
386 jnrlistB = jjnr[jidx+1];
387 jnrlistC = jjnr[jidx+2];
388 jnrlistD = jjnr[jidx+3];
389 /* Sign of each element will be negative for non-real atoms.
390 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
391 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
393 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
394 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
395 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
396 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
397 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
398 j_coord_offsetA = DIM*jnrA;
399 j_coord_offsetB = DIM*jnrB;
400 j_coord_offsetC = DIM*jnrC;
401 j_coord_offsetD = DIM*jnrD;
403 /* load j atom coordinates */
404 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
405 x+j_coord_offsetC,x+j_coord_offsetD,
406 &jx0,&jy0,&jz0);
408 /* Calculate displacement vector */
409 dx00 = _mm_sub_ps(ix0,jx0);
410 dy00 = _mm_sub_ps(iy0,jy0);
411 dz00 = _mm_sub_ps(iz0,jz0);
412 dx10 = _mm_sub_ps(ix1,jx0);
413 dy10 = _mm_sub_ps(iy1,jy0);
414 dz10 = _mm_sub_ps(iz1,jz0);
415 dx20 = _mm_sub_ps(ix2,jx0);
416 dy20 = _mm_sub_ps(iy2,jy0);
417 dz20 = _mm_sub_ps(iz2,jz0);
419 /* Calculate squared distance and things based on it */
420 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
421 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
422 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
424 rinv00 = sse2_invsqrt_f(rsq00);
425 rinv10 = sse2_invsqrt_f(rsq10);
426 rinv20 = sse2_invsqrt_f(rsq20);
428 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
429 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
430 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
432 /* Load parameters for j particles */
433 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
434 charge+jnrC+0,charge+jnrD+0);
435 vdwjidx0A = 2*vdwtype[jnrA+0];
436 vdwjidx0B = 2*vdwtype[jnrB+0];
437 vdwjidx0C = 2*vdwtype[jnrC+0];
438 vdwjidx0D = 2*vdwtype[jnrD+0];
440 fjx0 = _mm_setzero_ps();
441 fjy0 = _mm_setzero_ps();
442 fjz0 = _mm_setzero_ps();
444 /**************************
445 * CALCULATE INTERACTIONS *
446 **************************/
448 r00 = _mm_mul_ps(rsq00,rinv00);
449 r00 = _mm_andnot_ps(dummy_mask,r00);
451 /* Compute parameters for interactions between i and j atoms */
452 qq00 = _mm_mul_ps(iq0,jq0);
453 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
454 vdwparam+vdwioffset0+vdwjidx0B,
455 vdwparam+vdwioffset0+vdwjidx0C,
456 vdwparam+vdwioffset0+vdwjidx0D,
457 &c6_00,&c12_00);
459 /* Calculate table index by multiplying r with table scale and truncate to integer */
460 rt = _mm_mul_ps(r00,vftabscale);
461 vfitab = _mm_cvttps_epi32(rt);
462 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
463 vfitab = _mm_slli_epi32(vfitab,3);
465 /* COULOMB ELECTROSTATICS */
466 velec = _mm_mul_ps(qq00,rinv00);
467 felec = _mm_mul_ps(velec,rinvsq00);
469 /* CUBIC SPLINE TABLE DISPERSION */
470 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
471 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
472 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
473 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
474 _MM_TRANSPOSE4_PS(Y,F,G,H);
475 Heps = _mm_mul_ps(vfeps,H);
476 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
477 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
478 vvdw6 = _mm_mul_ps(c6_00,VV);
479 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
480 fvdw6 = _mm_mul_ps(c6_00,FF);
482 /* CUBIC SPLINE TABLE REPULSION */
483 vfitab = _mm_add_epi32(vfitab,ifour);
484 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
485 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
486 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
487 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
488 _MM_TRANSPOSE4_PS(Y,F,G,H);
489 Heps = _mm_mul_ps(vfeps,H);
490 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
491 VV = _mm_add_ps(Y,_mm_mul_ps(vfeps,Fp));
492 vvdw12 = _mm_mul_ps(c12_00,VV);
493 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
494 fvdw12 = _mm_mul_ps(c12_00,FF);
495 vvdw = _mm_add_ps(vvdw12,vvdw6);
496 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
498 /* Update potential sum for this i atom from the interaction with this j atom. */
499 velec = _mm_andnot_ps(dummy_mask,velec);
500 velecsum = _mm_add_ps(velecsum,velec);
501 vvdw = _mm_andnot_ps(dummy_mask,vvdw);
502 vvdwsum = _mm_add_ps(vvdwsum,vvdw);
504 fscal = _mm_add_ps(felec,fvdw);
506 fscal = _mm_andnot_ps(dummy_mask,fscal);
508 /* Calculate temporary vectorial force */
509 tx = _mm_mul_ps(fscal,dx00);
510 ty = _mm_mul_ps(fscal,dy00);
511 tz = _mm_mul_ps(fscal,dz00);
513 /* Update vectorial force */
514 fix0 = _mm_add_ps(fix0,tx);
515 fiy0 = _mm_add_ps(fiy0,ty);
516 fiz0 = _mm_add_ps(fiz0,tz);
518 fjx0 = _mm_add_ps(fjx0,tx);
519 fjy0 = _mm_add_ps(fjy0,ty);
520 fjz0 = _mm_add_ps(fjz0,tz);
522 /**************************
523 * CALCULATE INTERACTIONS *
524 **************************/
526 /* Compute parameters for interactions between i and j atoms */
527 qq10 = _mm_mul_ps(iq1,jq0);
529 /* COULOMB ELECTROSTATICS */
530 velec = _mm_mul_ps(qq10,rinv10);
531 felec = _mm_mul_ps(velec,rinvsq10);
533 /* Update potential sum for this i atom from the interaction with this j atom. */
534 velec = _mm_andnot_ps(dummy_mask,velec);
535 velecsum = _mm_add_ps(velecsum,velec);
537 fscal = felec;
539 fscal = _mm_andnot_ps(dummy_mask,fscal);
541 /* Calculate temporary vectorial force */
542 tx = _mm_mul_ps(fscal,dx10);
543 ty = _mm_mul_ps(fscal,dy10);
544 tz = _mm_mul_ps(fscal,dz10);
546 /* Update vectorial force */
547 fix1 = _mm_add_ps(fix1,tx);
548 fiy1 = _mm_add_ps(fiy1,ty);
549 fiz1 = _mm_add_ps(fiz1,tz);
551 fjx0 = _mm_add_ps(fjx0,tx);
552 fjy0 = _mm_add_ps(fjy0,ty);
553 fjz0 = _mm_add_ps(fjz0,tz);
555 /**************************
556 * CALCULATE INTERACTIONS *
557 **************************/
559 /* Compute parameters for interactions between i and j atoms */
560 qq20 = _mm_mul_ps(iq2,jq0);
562 /* COULOMB ELECTROSTATICS */
563 velec = _mm_mul_ps(qq20,rinv20);
564 felec = _mm_mul_ps(velec,rinvsq20);
566 /* Update potential sum for this i atom from the interaction with this j atom. */
567 velec = _mm_andnot_ps(dummy_mask,velec);
568 velecsum = _mm_add_ps(velecsum,velec);
570 fscal = felec;
572 fscal = _mm_andnot_ps(dummy_mask,fscal);
574 /* Calculate temporary vectorial force */
575 tx = _mm_mul_ps(fscal,dx20);
576 ty = _mm_mul_ps(fscal,dy20);
577 tz = _mm_mul_ps(fscal,dz20);
579 /* Update vectorial force */
580 fix2 = _mm_add_ps(fix2,tx);
581 fiy2 = _mm_add_ps(fiy2,ty);
582 fiz2 = _mm_add_ps(fiz2,tz);
584 fjx0 = _mm_add_ps(fjx0,tx);
585 fjy0 = _mm_add_ps(fjy0,ty);
586 fjz0 = _mm_add_ps(fjz0,tz);
588 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
589 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
590 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
591 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
593 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
595 /* Inner loop uses 120 flops */
598 /* End of innermost loop */
600 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
601 f+i_coord_offset,fshift+i_shift_offset);
603 ggid = gid[iidx];
604 /* Update potential energies */
605 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
606 gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
608 /* Increment number of inner iterations */
609 inneriter += j_index_end - j_index_start;
611 /* Outer loop uses 20 flops */
614 /* Increment number of outer iterations */
615 outeriter += nri;
617 /* Update outer/inner flops */
619 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*120);
622 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_F_sse2_single
623 * Electrostatics interaction: Coulomb
624 * VdW interaction: CubicSplineTable
625 * Geometry: Water3-Particle
626 * Calculate force/pot: Force
628 void
629 nb_kernel_ElecCoul_VdwCSTab_GeomW3P1_F_sse2_single
630 (t_nblist * gmx_restrict nlist,
631 rvec * gmx_restrict xx,
632 rvec * gmx_restrict ff,
633 struct t_forcerec * gmx_restrict fr,
634 t_mdatoms * gmx_restrict mdatoms,
635 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
636 t_nrnb * gmx_restrict nrnb)
638 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
639 * just 0 for non-waters.
640 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
641 * jnr indices corresponding to data put in the four positions in the SIMD register.
643 int i_shift_offset,i_coord_offset,outeriter,inneriter;
644 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
645 int jnrA,jnrB,jnrC,jnrD;
646 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
647 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
648 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
649 real rcutoff_scalar;
650 real *shiftvec,*fshift,*x,*f;
651 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
652 real scratch[4*DIM];
653 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
654 int vdwioffset0;
655 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
656 int vdwioffset1;
657 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
658 int vdwioffset2;
659 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
660 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
661 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
662 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
663 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
664 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
665 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
666 real *charge;
667 int nvdwtype;
668 __m128 rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
669 int *vdwtype;
670 real *vdwparam;
671 __m128 one_sixth = _mm_set1_ps(1.0/6.0);
672 __m128 one_twelfth = _mm_set1_ps(1.0/12.0);
673 __m128i vfitab;
674 __m128i ifour = _mm_set1_epi32(4);
675 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
676 real *vftab;
677 __m128 dummy_mask,cutoff_mask;
678 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
679 __m128 one = _mm_set1_ps(1.0);
680 __m128 two = _mm_set1_ps(2.0);
681 x = xx[0];
682 f = ff[0];
684 nri = nlist->nri;
685 iinr = nlist->iinr;
686 jindex = nlist->jindex;
687 jjnr = nlist->jjnr;
688 shiftidx = nlist->shift;
689 gid = nlist->gid;
690 shiftvec = fr->shift_vec[0];
691 fshift = fr->fshift[0];
692 facel = _mm_set1_ps(fr->ic->epsfac);
693 charge = mdatoms->chargeA;
694 nvdwtype = fr->ntype;
695 vdwparam = fr->nbfp;
696 vdwtype = mdatoms->typeA;
698 vftab = kernel_data->table_vdw->data;
699 vftabscale = _mm_set1_ps(kernel_data->table_vdw->scale);
701 /* Setup water-specific parameters */
702 inr = nlist->iinr[0];
703 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
704 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
705 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
706 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
708 /* Avoid stupid compiler warnings */
709 jnrA = jnrB = jnrC = jnrD = 0;
710 j_coord_offsetA = 0;
711 j_coord_offsetB = 0;
712 j_coord_offsetC = 0;
713 j_coord_offsetD = 0;
715 outeriter = 0;
716 inneriter = 0;
718 for(iidx=0;iidx<4*DIM;iidx++)
720 scratch[iidx] = 0.0;
723 /* Start outer loop over neighborlists */
724 for(iidx=0; iidx<nri; iidx++)
726 /* Load shift vector for this list */
727 i_shift_offset = DIM*shiftidx[iidx];
729 /* Load limits for loop over neighbors */
730 j_index_start = jindex[iidx];
731 j_index_end = jindex[iidx+1];
733 /* Get outer coordinate index */
734 inr = iinr[iidx];
735 i_coord_offset = DIM*inr;
737 /* Load i particle coords and add shift vector */
738 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
739 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
741 fix0 = _mm_setzero_ps();
742 fiy0 = _mm_setzero_ps();
743 fiz0 = _mm_setzero_ps();
744 fix1 = _mm_setzero_ps();
745 fiy1 = _mm_setzero_ps();
746 fiz1 = _mm_setzero_ps();
747 fix2 = _mm_setzero_ps();
748 fiy2 = _mm_setzero_ps();
749 fiz2 = _mm_setzero_ps();
751 /* Start inner kernel loop */
752 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
755 /* Get j neighbor index, and coordinate index */
756 jnrA = jjnr[jidx];
757 jnrB = jjnr[jidx+1];
758 jnrC = jjnr[jidx+2];
759 jnrD = jjnr[jidx+3];
760 j_coord_offsetA = DIM*jnrA;
761 j_coord_offsetB = DIM*jnrB;
762 j_coord_offsetC = DIM*jnrC;
763 j_coord_offsetD = DIM*jnrD;
765 /* load j atom coordinates */
766 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
767 x+j_coord_offsetC,x+j_coord_offsetD,
768 &jx0,&jy0,&jz0);
770 /* Calculate displacement vector */
771 dx00 = _mm_sub_ps(ix0,jx0);
772 dy00 = _mm_sub_ps(iy0,jy0);
773 dz00 = _mm_sub_ps(iz0,jz0);
774 dx10 = _mm_sub_ps(ix1,jx0);
775 dy10 = _mm_sub_ps(iy1,jy0);
776 dz10 = _mm_sub_ps(iz1,jz0);
777 dx20 = _mm_sub_ps(ix2,jx0);
778 dy20 = _mm_sub_ps(iy2,jy0);
779 dz20 = _mm_sub_ps(iz2,jz0);
781 /* Calculate squared distance and things based on it */
782 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
783 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
784 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
786 rinv00 = sse2_invsqrt_f(rsq00);
787 rinv10 = sse2_invsqrt_f(rsq10);
788 rinv20 = sse2_invsqrt_f(rsq20);
790 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
791 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
792 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
794 /* Load parameters for j particles */
795 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
796 charge+jnrC+0,charge+jnrD+0);
797 vdwjidx0A = 2*vdwtype[jnrA+0];
798 vdwjidx0B = 2*vdwtype[jnrB+0];
799 vdwjidx0C = 2*vdwtype[jnrC+0];
800 vdwjidx0D = 2*vdwtype[jnrD+0];
802 fjx0 = _mm_setzero_ps();
803 fjy0 = _mm_setzero_ps();
804 fjz0 = _mm_setzero_ps();
806 /**************************
807 * CALCULATE INTERACTIONS *
808 **************************/
810 r00 = _mm_mul_ps(rsq00,rinv00);
812 /* Compute parameters for interactions between i and j atoms */
813 qq00 = _mm_mul_ps(iq0,jq0);
814 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
815 vdwparam+vdwioffset0+vdwjidx0B,
816 vdwparam+vdwioffset0+vdwjidx0C,
817 vdwparam+vdwioffset0+vdwjidx0D,
818 &c6_00,&c12_00);
820 /* Calculate table index by multiplying r with table scale and truncate to integer */
821 rt = _mm_mul_ps(r00,vftabscale);
822 vfitab = _mm_cvttps_epi32(rt);
823 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
824 vfitab = _mm_slli_epi32(vfitab,3);
826 /* COULOMB ELECTROSTATICS */
827 velec = _mm_mul_ps(qq00,rinv00);
828 felec = _mm_mul_ps(velec,rinvsq00);
830 /* CUBIC SPLINE TABLE DISPERSION */
831 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
832 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
833 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
834 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
835 _MM_TRANSPOSE4_PS(Y,F,G,H);
836 Heps = _mm_mul_ps(vfeps,H);
837 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
838 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
839 fvdw6 = _mm_mul_ps(c6_00,FF);
841 /* CUBIC SPLINE TABLE REPULSION */
842 vfitab = _mm_add_epi32(vfitab,ifour);
843 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
844 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
845 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
846 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
847 _MM_TRANSPOSE4_PS(Y,F,G,H);
848 Heps = _mm_mul_ps(vfeps,H);
849 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
850 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
851 fvdw12 = _mm_mul_ps(c12_00,FF);
852 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
854 fscal = _mm_add_ps(felec,fvdw);
856 /* Calculate temporary vectorial force */
857 tx = _mm_mul_ps(fscal,dx00);
858 ty = _mm_mul_ps(fscal,dy00);
859 tz = _mm_mul_ps(fscal,dz00);
861 /* Update vectorial force */
862 fix0 = _mm_add_ps(fix0,tx);
863 fiy0 = _mm_add_ps(fiy0,ty);
864 fiz0 = _mm_add_ps(fiz0,tz);
866 fjx0 = _mm_add_ps(fjx0,tx);
867 fjy0 = _mm_add_ps(fjy0,ty);
868 fjz0 = _mm_add_ps(fjz0,tz);
870 /**************************
871 * CALCULATE INTERACTIONS *
872 **************************/
874 /* Compute parameters for interactions between i and j atoms */
875 qq10 = _mm_mul_ps(iq1,jq0);
877 /* COULOMB ELECTROSTATICS */
878 velec = _mm_mul_ps(qq10,rinv10);
879 felec = _mm_mul_ps(velec,rinvsq10);
881 fscal = felec;
883 /* Calculate temporary vectorial force */
884 tx = _mm_mul_ps(fscal,dx10);
885 ty = _mm_mul_ps(fscal,dy10);
886 tz = _mm_mul_ps(fscal,dz10);
888 /* Update vectorial force */
889 fix1 = _mm_add_ps(fix1,tx);
890 fiy1 = _mm_add_ps(fiy1,ty);
891 fiz1 = _mm_add_ps(fiz1,tz);
893 fjx0 = _mm_add_ps(fjx0,tx);
894 fjy0 = _mm_add_ps(fjy0,ty);
895 fjz0 = _mm_add_ps(fjz0,tz);
897 /**************************
898 * CALCULATE INTERACTIONS *
899 **************************/
901 /* Compute parameters for interactions between i and j atoms */
902 qq20 = _mm_mul_ps(iq2,jq0);
904 /* COULOMB ELECTROSTATICS */
905 velec = _mm_mul_ps(qq20,rinv20);
906 felec = _mm_mul_ps(velec,rinvsq20);
908 fscal = felec;
910 /* Calculate temporary vectorial force */
911 tx = _mm_mul_ps(fscal,dx20);
912 ty = _mm_mul_ps(fscal,dy20);
913 tz = _mm_mul_ps(fscal,dz20);
915 /* Update vectorial force */
916 fix2 = _mm_add_ps(fix2,tx);
917 fiy2 = _mm_add_ps(fiy2,ty);
918 fiz2 = _mm_add_ps(fiz2,tz);
920 fjx0 = _mm_add_ps(fjx0,tx);
921 fjy0 = _mm_add_ps(fjy0,ty);
922 fjz0 = _mm_add_ps(fjz0,tz);
924 fjptrA = f+j_coord_offsetA;
925 fjptrB = f+j_coord_offsetB;
926 fjptrC = f+j_coord_offsetC;
927 fjptrD = f+j_coord_offsetD;
929 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
931 /* Inner loop uses 108 flops */
934 if(jidx<j_index_end)
937 /* Get j neighbor index, and coordinate index */
938 jnrlistA = jjnr[jidx];
939 jnrlistB = jjnr[jidx+1];
940 jnrlistC = jjnr[jidx+2];
941 jnrlistD = jjnr[jidx+3];
942 /* Sign of each element will be negative for non-real atoms.
943 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
944 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
946 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
947 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
948 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
949 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
950 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
951 j_coord_offsetA = DIM*jnrA;
952 j_coord_offsetB = DIM*jnrB;
953 j_coord_offsetC = DIM*jnrC;
954 j_coord_offsetD = DIM*jnrD;
956 /* load j atom coordinates */
957 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
958 x+j_coord_offsetC,x+j_coord_offsetD,
959 &jx0,&jy0,&jz0);
961 /* Calculate displacement vector */
962 dx00 = _mm_sub_ps(ix0,jx0);
963 dy00 = _mm_sub_ps(iy0,jy0);
964 dz00 = _mm_sub_ps(iz0,jz0);
965 dx10 = _mm_sub_ps(ix1,jx0);
966 dy10 = _mm_sub_ps(iy1,jy0);
967 dz10 = _mm_sub_ps(iz1,jz0);
968 dx20 = _mm_sub_ps(ix2,jx0);
969 dy20 = _mm_sub_ps(iy2,jy0);
970 dz20 = _mm_sub_ps(iz2,jz0);
972 /* Calculate squared distance and things based on it */
973 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
974 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
975 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
977 rinv00 = sse2_invsqrt_f(rsq00);
978 rinv10 = sse2_invsqrt_f(rsq10);
979 rinv20 = sse2_invsqrt_f(rsq20);
981 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
982 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
983 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
985 /* Load parameters for j particles */
986 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
987 charge+jnrC+0,charge+jnrD+0);
988 vdwjidx0A = 2*vdwtype[jnrA+0];
989 vdwjidx0B = 2*vdwtype[jnrB+0];
990 vdwjidx0C = 2*vdwtype[jnrC+0];
991 vdwjidx0D = 2*vdwtype[jnrD+0];
993 fjx0 = _mm_setzero_ps();
994 fjy0 = _mm_setzero_ps();
995 fjz0 = _mm_setzero_ps();
997 /**************************
998 * CALCULATE INTERACTIONS *
999 **************************/
1001 r00 = _mm_mul_ps(rsq00,rinv00);
1002 r00 = _mm_andnot_ps(dummy_mask,r00);
1004 /* Compute parameters for interactions between i and j atoms */
1005 qq00 = _mm_mul_ps(iq0,jq0);
1006 gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1007 vdwparam+vdwioffset0+vdwjidx0B,
1008 vdwparam+vdwioffset0+vdwjidx0C,
1009 vdwparam+vdwioffset0+vdwjidx0D,
1010 &c6_00,&c12_00);
1012 /* Calculate table index by multiplying r with table scale and truncate to integer */
1013 rt = _mm_mul_ps(r00,vftabscale);
1014 vfitab = _mm_cvttps_epi32(rt);
1015 vfeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(vfitab));
1016 vfitab = _mm_slli_epi32(vfitab,3);
1018 /* COULOMB ELECTROSTATICS */
1019 velec = _mm_mul_ps(qq00,rinv00);
1020 felec = _mm_mul_ps(velec,rinvsq00);
1022 /* CUBIC SPLINE TABLE DISPERSION */
1023 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1024 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1025 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1026 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1027 _MM_TRANSPOSE4_PS(Y,F,G,H);
1028 Heps = _mm_mul_ps(vfeps,H);
1029 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1030 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1031 fvdw6 = _mm_mul_ps(c6_00,FF);
1033 /* CUBIC SPLINE TABLE REPULSION */
1034 vfitab = _mm_add_epi32(vfitab,ifour);
1035 Y = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,0) );
1036 F = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,1) );
1037 G = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,2) );
1038 H = _mm_load_ps( vftab + gmx_mm_extract_epi32(vfitab,3) );
1039 _MM_TRANSPOSE4_PS(Y,F,G,H);
1040 Heps = _mm_mul_ps(vfeps,H);
1041 Fp = _mm_add_ps(F,_mm_mul_ps(vfeps,_mm_add_ps(G,Heps)));
1042 FF = _mm_add_ps(Fp,_mm_mul_ps(vfeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
1043 fvdw12 = _mm_mul_ps(c12_00,FF);
1044 fvdw = _mm_xor_ps(signbit,_mm_mul_ps(_mm_add_ps(fvdw6,fvdw12),_mm_mul_ps(vftabscale,rinv00)));
1046 fscal = _mm_add_ps(felec,fvdw);
1048 fscal = _mm_andnot_ps(dummy_mask,fscal);
1050 /* Calculate temporary vectorial force */
1051 tx = _mm_mul_ps(fscal,dx00);
1052 ty = _mm_mul_ps(fscal,dy00);
1053 tz = _mm_mul_ps(fscal,dz00);
1055 /* Update vectorial force */
1056 fix0 = _mm_add_ps(fix0,tx);
1057 fiy0 = _mm_add_ps(fiy0,ty);
1058 fiz0 = _mm_add_ps(fiz0,tz);
1060 fjx0 = _mm_add_ps(fjx0,tx);
1061 fjy0 = _mm_add_ps(fjy0,ty);
1062 fjz0 = _mm_add_ps(fjz0,tz);
1064 /**************************
1065 * CALCULATE INTERACTIONS *
1066 **************************/
1068 /* Compute parameters for interactions between i and j atoms */
1069 qq10 = _mm_mul_ps(iq1,jq0);
1071 /* COULOMB ELECTROSTATICS */
1072 velec = _mm_mul_ps(qq10,rinv10);
1073 felec = _mm_mul_ps(velec,rinvsq10);
1075 fscal = felec;
1077 fscal = _mm_andnot_ps(dummy_mask,fscal);
1079 /* Calculate temporary vectorial force */
1080 tx = _mm_mul_ps(fscal,dx10);
1081 ty = _mm_mul_ps(fscal,dy10);
1082 tz = _mm_mul_ps(fscal,dz10);
1084 /* Update vectorial force */
1085 fix1 = _mm_add_ps(fix1,tx);
1086 fiy1 = _mm_add_ps(fiy1,ty);
1087 fiz1 = _mm_add_ps(fiz1,tz);
1089 fjx0 = _mm_add_ps(fjx0,tx);
1090 fjy0 = _mm_add_ps(fjy0,ty);
1091 fjz0 = _mm_add_ps(fjz0,tz);
1093 /**************************
1094 * CALCULATE INTERACTIONS *
1095 **************************/
1097 /* Compute parameters for interactions between i and j atoms */
1098 qq20 = _mm_mul_ps(iq2,jq0);
1100 /* COULOMB ELECTROSTATICS */
1101 velec = _mm_mul_ps(qq20,rinv20);
1102 felec = _mm_mul_ps(velec,rinvsq20);
1104 fscal = felec;
1106 fscal = _mm_andnot_ps(dummy_mask,fscal);
1108 /* Calculate temporary vectorial force */
1109 tx = _mm_mul_ps(fscal,dx20);
1110 ty = _mm_mul_ps(fscal,dy20);
1111 tz = _mm_mul_ps(fscal,dz20);
1113 /* Update vectorial force */
1114 fix2 = _mm_add_ps(fix2,tx);
1115 fiy2 = _mm_add_ps(fiy2,ty);
1116 fiz2 = _mm_add_ps(fiz2,tz);
1118 fjx0 = _mm_add_ps(fjx0,tx);
1119 fjy0 = _mm_add_ps(fjy0,ty);
1120 fjz0 = _mm_add_ps(fjz0,tz);
1122 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1123 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1124 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1125 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1127 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1129 /* Inner loop uses 109 flops */
1132 /* End of innermost loop */
1134 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1135 f+i_coord_offset,fshift+i_shift_offset);
1137 /* Increment number of inner iterations */
1138 inneriter += j_index_end - j_index_start;
1140 /* Outer loop uses 18 flops */
1143 /* Increment number of outer iterations */
1144 outeriter += nri;
1146 /* Update outer/inner flops */
1148 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*109);