2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * 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.
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
49 #include "gmx_math_x86_sse2_single.h"
50 #include "kernelutil_x86_sse2_single.h"
53 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwNone_GeomP1P1_VF_sse2_single
54 * Electrostatics interaction: GeneralizedBorn
55 * VdW interaction: None
56 * Geometry: Particle-Particle
57 * Calculate force/pot: PotentialAndForce
60 nb_kernel_ElecGB_VdwNone_GeomP1P1_VF_sse2_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_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 refer to j loop unrolling done with SSE, e.g. for the four 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 jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
81 real *shiftvec,*fshift,*x,*f;
82 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
93 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,dvdatmp;
94 __m128 minushalf = _mm_set1_ps(-0.5);
95 real *invsqrta,*dvda,*gbtab;
97 __m128i ifour = _mm_set1_epi32(4);
98 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
100 __m128 dummy_mask,cutoff_mask;
101 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
102 __m128 one = _mm_set1_ps(1.0);
103 __m128 two = _mm_set1_ps(2.0);
109 jindex = nlist->jindex;
111 shiftidx = nlist->shift;
113 shiftvec = fr->shift_vec[0];
114 fshift = fr->fshift[0];
115 facel = _mm_set1_ps(fr->epsfac);
116 charge = mdatoms->chargeA;
118 invsqrta = fr->invsqrta;
120 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
121 gbtab = fr->gbtab.data;
122 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
124 /* Avoid stupid compiler warnings */
125 jnrA = jnrB = jnrC = jnrD = 0;
134 for(iidx=0;iidx<4*DIM;iidx++)
139 /* Start outer loop over neighborlists */
140 for(iidx=0; iidx<nri; iidx++)
142 /* Load shift vector for this list */
143 i_shift_offset = DIM*shiftidx[iidx];
145 /* Load limits for loop over neighbors */
146 j_index_start = jindex[iidx];
147 j_index_end = jindex[iidx+1];
149 /* Get outer coordinate index */
151 i_coord_offset = DIM*inr;
153 /* Load i particle coords and add shift vector */
154 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
156 fix0 = _mm_setzero_ps();
157 fiy0 = _mm_setzero_ps();
158 fiz0 = _mm_setzero_ps();
160 /* Load parameters for i particles */
161 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
162 isai0 = _mm_load1_ps(invsqrta+inr+0);
164 /* Reset potential sums */
165 velecsum = _mm_setzero_ps();
166 vgbsum = _mm_setzero_ps();
167 dvdasum = _mm_setzero_ps();
169 /* Start inner kernel loop */
170 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
173 /* Get j neighbor index, and coordinate index */
178 j_coord_offsetA = DIM*jnrA;
179 j_coord_offsetB = DIM*jnrB;
180 j_coord_offsetC = DIM*jnrC;
181 j_coord_offsetD = DIM*jnrD;
183 /* load j atom coordinates */
184 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
185 x+j_coord_offsetC,x+j_coord_offsetD,
188 /* Calculate displacement vector */
189 dx00 = _mm_sub_ps(ix0,jx0);
190 dy00 = _mm_sub_ps(iy0,jy0);
191 dz00 = _mm_sub_ps(iz0,jz0);
193 /* Calculate squared distance and things based on it */
194 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
196 rinv00 = gmx_mm_invsqrt_ps(rsq00);
198 /* Load parameters for j particles */
199 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
200 charge+jnrC+0,charge+jnrD+0);
201 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
202 invsqrta+jnrC+0,invsqrta+jnrD+0);
204 /**************************
205 * CALCULATE INTERACTIONS *
206 **************************/
208 r00 = _mm_mul_ps(rsq00,rinv00);
210 /* Compute parameters for interactions between i and j atoms */
211 qq00 = _mm_mul_ps(iq0,jq0);
213 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
214 isaprod = _mm_mul_ps(isai0,isaj0);
215 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
216 gbscale = _mm_mul_ps(isaprod,gbtabscale);
218 /* Calculate generalized born table index - this is a separate table from the normal one,
219 * but we use the same procedure by multiplying r with scale and truncating to integer.
221 rt = _mm_mul_ps(r00,gbscale);
222 gbitab = _mm_cvttps_epi32(rt);
223 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
224 gbitab = _mm_slli_epi32(gbitab,2);
226 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
227 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
228 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
229 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
230 _MM_TRANSPOSE4_PS(Y,F,G,H);
231 Heps = _mm_mul_ps(gbeps,H);
232 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
233 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
234 vgb = _mm_mul_ps(gbqqfactor,VV);
236 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
237 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
238 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
239 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
244 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
245 velec = _mm_mul_ps(qq00,rinv00);
246 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
248 /* Update potential sum for this i atom from the interaction with this j atom. */
249 velecsum = _mm_add_ps(velecsum,velec);
250 vgbsum = _mm_add_ps(vgbsum,vgb);
254 /* Calculate temporary vectorial force */
255 tx = _mm_mul_ps(fscal,dx00);
256 ty = _mm_mul_ps(fscal,dy00);
257 tz = _mm_mul_ps(fscal,dz00);
259 /* Update vectorial force */
260 fix0 = _mm_add_ps(fix0,tx);
261 fiy0 = _mm_add_ps(fiy0,ty);
262 fiz0 = _mm_add_ps(fiz0,tz);
264 fjptrA = f+j_coord_offsetA;
265 fjptrB = f+j_coord_offsetB;
266 fjptrC = f+j_coord_offsetC;
267 fjptrD = f+j_coord_offsetD;
268 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
270 /* Inner loop uses 58 flops */
276 /* Get j neighbor index, and coordinate index */
277 jnrlistA = jjnr[jidx];
278 jnrlistB = jjnr[jidx+1];
279 jnrlistC = jjnr[jidx+2];
280 jnrlistD = jjnr[jidx+3];
281 /* Sign of each element will be negative for non-real atoms.
282 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
283 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
285 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
286 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
287 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
288 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
289 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
290 j_coord_offsetA = DIM*jnrA;
291 j_coord_offsetB = DIM*jnrB;
292 j_coord_offsetC = DIM*jnrC;
293 j_coord_offsetD = DIM*jnrD;
295 /* load j atom coordinates */
296 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
297 x+j_coord_offsetC,x+j_coord_offsetD,
300 /* Calculate displacement vector */
301 dx00 = _mm_sub_ps(ix0,jx0);
302 dy00 = _mm_sub_ps(iy0,jy0);
303 dz00 = _mm_sub_ps(iz0,jz0);
305 /* Calculate squared distance and things based on it */
306 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
308 rinv00 = gmx_mm_invsqrt_ps(rsq00);
310 /* Load parameters for j particles */
311 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
312 charge+jnrC+0,charge+jnrD+0);
313 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
314 invsqrta+jnrC+0,invsqrta+jnrD+0);
316 /**************************
317 * CALCULATE INTERACTIONS *
318 **************************/
320 r00 = _mm_mul_ps(rsq00,rinv00);
321 r00 = _mm_andnot_ps(dummy_mask,r00);
323 /* Compute parameters for interactions between i and j atoms */
324 qq00 = _mm_mul_ps(iq0,jq0);
326 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
327 isaprod = _mm_mul_ps(isai0,isaj0);
328 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
329 gbscale = _mm_mul_ps(isaprod,gbtabscale);
331 /* Calculate generalized born table index - this is a separate table from the normal one,
332 * but we use the same procedure by multiplying r with scale and truncating to integer.
334 rt = _mm_mul_ps(r00,gbscale);
335 gbitab = _mm_cvttps_epi32(rt);
336 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
337 gbitab = _mm_slli_epi32(gbitab,2);
339 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
340 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
341 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
342 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
343 _MM_TRANSPOSE4_PS(Y,F,G,H);
344 Heps = _mm_mul_ps(gbeps,H);
345 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
346 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
347 vgb = _mm_mul_ps(gbqqfactor,VV);
349 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
350 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
351 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
352 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
353 /* 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. */
354 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
355 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
356 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
357 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
358 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
359 velec = _mm_mul_ps(qq00,rinv00);
360 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
362 /* Update potential sum for this i atom from the interaction with this j atom. */
363 velec = _mm_andnot_ps(dummy_mask,velec);
364 velecsum = _mm_add_ps(velecsum,velec);
365 vgb = _mm_andnot_ps(dummy_mask,vgb);
366 vgbsum = _mm_add_ps(vgbsum,vgb);
370 fscal = _mm_andnot_ps(dummy_mask,fscal);
372 /* Calculate temporary vectorial force */
373 tx = _mm_mul_ps(fscal,dx00);
374 ty = _mm_mul_ps(fscal,dy00);
375 tz = _mm_mul_ps(fscal,dz00);
377 /* Update vectorial force */
378 fix0 = _mm_add_ps(fix0,tx);
379 fiy0 = _mm_add_ps(fiy0,ty);
380 fiz0 = _mm_add_ps(fiz0,tz);
382 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
383 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
384 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
385 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
386 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
388 /* Inner loop uses 59 flops */
391 /* End of innermost loop */
393 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
394 f+i_coord_offset,fshift+i_shift_offset);
397 /* Update potential energies */
398 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
399 gmx_mm_update_1pot_ps(vgbsum,kernel_data->energygrp_polarization+ggid);
400 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
401 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
403 /* Increment number of inner iterations */
404 inneriter += j_index_end - j_index_start;
406 /* Outer loop uses 9 flops */
409 /* Increment number of outer iterations */
412 /* Update outer/inner flops */
414 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*9 + inneriter*59);
417 * Gromacs nonbonded kernel: nb_kernel_ElecGB_VdwNone_GeomP1P1_F_sse2_single
418 * Electrostatics interaction: GeneralizedBorn
419 * VdW interaction: None
420 * Geometry: Particle-Particle
421 * Calculate force/pot: Force
424 nb_kernel_ElecGB_VdwNone_GeomP1P1_F_sse2_single
425 (t_nblist * gmx_restrict nlist,
426 rvec * gmx_restrict xx,
427 rvec * gmx_restrict ff,
428 t_forcerec * gmx_restrict fr,
429 t_mdatoms * gmx_restrict mdatoms,
430 nb_kernel_data_t * gmx_restrict kernel_data,
431 t_nrnb * gmx_restrict nrnb)
433 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
434 * just 0 for non-waters.
435 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
436 * jnr indices corresponding to data put in the four positions in the SIMD register.
438 int i_shift_offset,i_coord_offset,outeriter,inneriter;
439 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
440 int jnrA,jnrB,jnrC,jnrD;
441 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
442 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
443 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
445 real *shiftvec,*fshift,*x,*f;
446 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
448 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
450 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
451 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
452 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
453 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
454 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
457 __m128 vgb,fgb,vgbsum,dvdasum,gbscale,gbtabscale,isaprod,gbqqfactor,gbinvepsdiff,gbeps,dvdatmp;
458 __m128 minushalf = _mm_set1_ps(-0.5);
459 real *invsqrta,*dvda,*gbtab;
461 __m128i ifour = _mm_set1_epi32(4);
462 __m128 rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF;
464 __m128 dummy_mask,cutoff_mask;
465 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
466 __m128 one = _mm_set1_ps(1.0);
467 __m128 two = _mm_set1_ps(2.0);
473 jindex = nlist->jindex;
475 shiftidx = nlist->shift;
477 shiftvec = fr->shift_vec[0];
478 fshift = fr->fshift[0];
479 facel = _mm_set1_ps(fr->epsfac);
480 charge = mdatoms->chargeA;
482 invsqrta = fr->invsqrta;
484 gbtabscale = _mm_set1_ps(fr->gbtab.scale);
485 gbtab = fr->gbtab.data;
486 gbinvepsdiff = _mm_set1_ps((1.0/fr->epsilon_r) - (1.0/fr->gb_epsilon_solvent));
488 /* Avoid stupid compiler warnings */
489 jnrA = jnrB = jnrC = jnrD = 0;
498 for(iidx=0;iidx<4*DIM;iidx++)
503 /* Start outer loop over neighborlists */
504 for(iidx=0; iidx<nri; iidx++)
506 /* Load shift vector for this list */
507 i_shift_offset = DIM*shiftidx[iidx];
509 /* Load limits for loop over neighbors */
510 j_index_start = jindex[iidx];
511 j_index_end = jindex[iidx+1];
513 /* Get outer coordinate index */
515 i_coord_offset = DIM*inr;
517 /* Load i particle coords and add shift vector */
518 gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
520 fix0 = _mm_setzero_ps();
521 fiy0 = _mm_setzero_ps();
522 fiz0 = _mm_setzero_ps();
524 /* Load parameters for i particles */
525 iq0 = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
526 isai0 = _mm_load1_ps(invsqrta+inr+0);
528 dvdasum = _mm_setzero_ps();
530 /* Start inner kernel loop */
531 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
534 /* Get j neighbor index, and coordinate index */
539 j_coord_offsetA = DIM*jnrA;
540 j_coord_offsetB = DIM*jnrB;
541 j_coord_offsetC = DIM*jnrC;
542 j_coord_offsetD = DIM*jnrD;
544 /* load j atom coordinates */
545 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
546 x+j_coord_offsetC,x+j_coord_offsetD,
549 /* Calculate displacement vector */
550 dx00 = _mm_sub_ps(ix0,jx0);
551 dy00 = _mm_sub_ps(iy0,jy0);
552 dz00 = _mm_sub_ps(iz0,jz0);
554 /* Calculate squared distance and things based on it */
555 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
557 rinv00 = gmx_mm_invsqrt_ps(rsq00);
559 /* Load parameters for j particles */
560 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
561 charge+jnrC+0,charge+jnrD+0);
562 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
563 invsqrta+jnrC+0,invsqrta+jnrD+0);
565 /**************************
566 * CALCULATE INTERACTIONS *
567 **************************/
569 r00 = _mm_mul_ps(rsq00,rinv00);
571 /* Compute parameters for interactions between i and j atoms */
572 qq00 = _mm_mul_ps(iq0,jq0);
574 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
575 isaprod = _mm_mul_ps(isai0,isaj0);
576 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
577 gbscale = _mm_mul_ps(isaprod,gbtabscale);
579 /* Calculate generalized born table index - this is a separate table from the normal one,
580 * but we use the same procedure by multiplying r with scale and truncating to integer.
582 rt = _mm_mul_ps(r00,gbscale);
583 gbitab = _mm_cvttps_epi32(rt);
584 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
585 gbitab = _mm_slli_epi32(gbitab,2);
587 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
588 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
589 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
590 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
591 _MM_TRANSPOSE4_PS(Y,F,G,H);
592 Heps = _mm_mul_ps(gbeps,H);
593 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
594 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
595 vgb = _mm_mul_ps(gbqqfactor,VV);
597 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
598 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
599 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
600 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
605 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
606 velec = _mm_mul_ps(qq00,rinv00);
607 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
611 /* Calculate temporary vectorial force */
612 tx = _mm_mul_ps(fscal,dx00);
613 ty = _mm_mul_ps(fscal,dy00);
614 tz = _mm_mul_ps(fscal,dz00);
616 /* Update vectorial force */
617 fix0 = _mm_add_ps(fix0,tx);
618 fiy0 = _mm_add_ps(fiy0,ty);
619 fiz0 = _mm_add_ps(fiz0,tz);
621 fjptrA = f+j_coord_offsetA;
622 fjptrB = f+j_coord_offsetB;
623 fjptrC = f+j_coord_offsetC;
624 fjptrD = f+j_coord_offsetD;
625 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
627 /* Inner loop uses 56 flops */
633 /* Get j neighbor index, and coordinate index */
634 jnrlistA = jjnr[jidx];
635 jnrlistB = jjnr[jidx+1];
636 jnrlistC = jjnr[jidx+2];
637 jnrlistD = jjnr[jidx+3];
638 /* Sign of each element will be negative for non-real atoms.
639 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
640 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
642 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
643 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
644 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
645 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
646 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
647 j_coord_offsetA = DIM*jnrA;
648 j_coord_offsetB = DIM*jnrB;
649 j_coord_offsetC = DIM*jnrC;
650 j_coord_offsetD = DIM*jnrD;
652 /* load j atom coordinates */
653 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
654 x+j_coord_offsetC,x+j_coord_offsetD,
657 /* Calculate displacement vector */
658 dx00 = _mm_sub_ps(ix0,jx0);
659 dy00 = _mm_sub_ps(iy0,jy0);
660 dz00 = _mm_sub_ps(iz0,jz0);
662 /* Calculate squared distance and things based on it */
663 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
665 rinv00 = gmx_mm_invsqrt_ps(rsq00);
667 /* Load parameters for j particles */
668 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
669 charge+jnrC+0,charge+jnrD+0);
670 isaj0 = gmx_mm_load_4real_swizzle_ps(invsqrta+jnrA+0,invsqrta+jnrB+0,
671 invsqrta+jnrC+0,invsqrta+jnrD+0);
673 /**************************
674 * CALCULATE INTERACTIONS *
675 **************************/
677 r00 = _mm_mul_ps(rsq00,rinv00);
678 r00 = _mm_andnot_ps(dummy_mask,r00);
680 /* Compute parameters for interactions between i and j atoms */
681 qq00 = _mm_mul_ps(iq0,jq0);
683 /* GENERALIZED BORN AND COULOMB ELECTROSTATICS */
684 isaprod = _mm_mul_ps(isai0,isaj0);
685 gbqqfactor = _mm_xor_ps(signbit,_mm_mul_ps(qq00,_mm_mul_ps(isaprod,gbinvepsdiff)));
686 gbscale = _mm_mul_ps(isaprod,gbtabscale);
688 /* Calculate generalized born table index - this is a separate table from the normal one,
689 * but we use the same procedure by multiplying r with scale and truncating to integer.
691 rt = _mm_mul_ps(r00,gbscale);
692 gbitab = _mm_cvttps_epi32(rt);
693 gbeps = _mm_sub_ps(rt,_mm_cvtepi32_ps(gbitab));
694 gbitab = _mm_slli_epi32(gbitab,2);
696 Y = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,0) );
697 F = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,1) );
698 G = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,2) );
699 H = _mm_load_ps( gbtab + gmx_mm_extract_epi32(gbitab,3) );
700 _MM_TRANSPOSE4_PS(Y,F,G,H);
701 Heps = _mm_mul_ps(gbeps,H);
702 Fp = _mm_add_ps(F,_mm_mul_ps(gbeps,_mm_add_ps(G,Heps)));
703 VV = _mm_add_ps(Y,_mm_mul_ps(gbeps,Fp));
704 vgb = _mm_mul_ps(gbqqfactor,VV);
706 FF = _mm_add_ps(Fp,_mm_mul_ps(gbeps,_mm_add_ps(G,_mm_add_ps(Heps,Heps))));
707 fgb = _mm_mul_ps(gbqqfactor,_mm_mul_ps(FF,gbscale));
708 dvdatmp = _mm_mul_ps(minushalf,_mm_add_ps(vgb,_mm_mul_ps(fgb,r00)));
709 dvdasum = _mm_add_ps(dvdasum,dvdatmp);
710 /* 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. */
711 fjptrA = (jnrlistA>=0) ? dvda+jnrA : scratch;
712 fjptrB = (jnrlistB>=0) ? dvda+jnrB : scratch;
713 fjptrC = (jnrlistC>=0) ? dvda+jnrC : scratch;
714 fjptrD = (jnrlistD>=0) ? dvda+jnrD : scratch;
715 gmx_mm_increment_4real_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,_mm_mul_ps(dvdatmp,_mm_mul_ps(isaj0,isaj0)));
716 velec = _mm_mul_ps(qq00,rinv00);
717 felec = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(velec,rinv00),fgb),rinv00);
721 fscal = _mm_andnot_ps(dummy_mask,fscal);
723 /* Calculate temporary vectorial force */
724 tx = _mm_mul_ps(fscal,dx00);
725 ty = _mm_mul_ps(fscal,dy00);
726 tz = _mm_mul_ps(fscal,dz00);
728 /* Update vectorial force */
729 fix0 = _mm_add_ps(fix0,tx);
730 fiy0 = _mm_add_ps(fiy0,ty);
731 fiz0 = _mm_add_ps(fiz0,tz);
733 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
734 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
735 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
736 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
737 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
739 /* Inner loop uses 57 flops */
742 /* End of innermost loop */
744 gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
745 f+i_coord_offset,fshift+i_shift_offset);
747 dvdasum = _mm_mul_ps(dvdasum, _mm_mul_ps(isai0,isai0));
748 gmx_mm_update_1pot_ps(dvdasum,dvda+inr);
750 /* Increment number of inner iterations */
751 inneriter += j_index_end - j_index_start;
753 /* Outer loop uses 7 flops */
756 /* Increment number of outer iterations */
759 /* Update outer/inner flops */
761 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*57);