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 sse4_1_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
47 #include "gromacs/simd/math_x86_sse4_1_single.h"
48 #include "kernelutil_x86_sse4_1_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomW4P1_VF_sse4_1_single
52 * Electrostatics interaction: Coulomb
53 * VdW interaction: None
54 * Geometry: Water4-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecCoul_VdwNone_GeomW4P1_VF_sse4_1_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 SSE, 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 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
84 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
86 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
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 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
96 __m128 dummy_mask,cutoff_mask;
97 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
98 __m128 one = _mm_set1_ps(1.0);
99 __m128 two = _mm_set1_ps(2.0);
105 jindex = nlist->jindex;
107 shiftidx = nlist->shift;
109 shiftvec = fr->shift_vec[0];
110 fshift = fr->fshift[0];
111 facel = _mm_set1_ps(fr->epsfac);
112 charge = mdatoms->chargeA;
114 /* Setup water-specific parameters */
115 inr = nlist->iinr[0];
116 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
117 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
118 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
120 /* Avoid stupid compiler warnings */
121 jnrA = jnrB = jnrC = jnrD = 0;
130 for(iidx=0;iidx<4*DIM;iidx++)
135 /* Start outer loop over neighborlists */
136 for(iidx=0; iidx<nri; iidx++)
138 /* Load shift vector for this list */
139 i_shift_offset = DIM*shiftidx[iidx];
141 /* Load limits for loop over neighbors */
142 j_index_start = jindex[iidx];
143 j_index_end = jindex[iidx+1];
145 /* Get outer coordinate index */
147 i_coord_offset = DIM*inr;
149 /* Load i particle coords and add shift vector */
150 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
151 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
153 fix1 = _mm_setzero_ps();
154 fiy1 = _mm_setzero_ps();
155 fiz1 = _mm_setzero_ps();
156 fix2 = _mm_setzero_ps();
157 fiy2 = _mm_setzero_ps();
158 fiz2 = _mm_setzero_ps();
159 fix3 = _mm_setzero_ps();
160 fiy3 = _mm_setzero_ps();
161 fiz3 = _mm_setzero_ps();
163 /* Reset potential sums */
164 velecsum = _mm_setzero_ps();
166 /* Start inner kernel loop */
167 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
170 /* Get j neighbor index, and coordinate index */
175 j_coord_offsetA = DIM*jnrA;
176 j_coord_offsetB = DIM*jnrB;
177 j_coord_offsetC = DIM*jnrC;
178 j_coord_offsetD = DIM*jnrD;
180 /* load j atom coordinates */
181 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
182 x+j_coord_offsetC,x+j_coord_offsetD,
185 /* Calculate displacement vector */
186 dx10 = _mm_sub_ps(ix1,jx0);
187 dy10 = _mm_sub_ps(iy1,jy0);
188 dz10 = _mm_sub_ps(iz1,jz0);
189 dx20 = _mm_sub_ps(ix2,jx0);
190 dy20 = _mm_sub_ps(iy2,jy0);
191 dz20 = _mm_sub_ps(iz2,jz0);
192 dx30 = _mm_sub_ps(ix3,jx0);
193 dy30 = _mm_sub_ps(iy3,jy0);
194 dz30 = _mm_sub_ps(iz3,jz0);
196 /* Calculate squared distance and things based on it */
197 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
198 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
199 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
201 rinv10 = gmx_mm_invsqrt_ps(rsq10);
202 rinv20 = gmx_mm_invsqrt_ps(rsq20);
203 rinv30 = gmx_mm_invsqrt_ps(rsq30);
205 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
206 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
207 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
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);
213 fjx0 = _mm_setzero_ps();
214 fjy0 = _mm_setzero_ps();
215 fjz0 = _mm_setzero_ps();
217 /**************************
218 * CALCULATE INTERACTIONS *
219 **************************/
221 /* Compute parameters for interactions between i and j atoms */
222 qq10 = _mm_mul_ps(iq1,jq0);
224 /* COULOMB ELECTROSTATICS */
225 velec = _mm_mul_ps(qq10,rinv10);
226 felec = _mm_mul_ps(velec,rinvsq10);
228 /* Update potential sum for this i atom from the interaction with this j atom. */
229 velecsum = _mm_add_ps(velecsum,velec);
233 /* Calculate temporary vectorial force */
234 tx = _mm_mul_ps(fscal,dx10);
235 ty = _mm_mul_ps(fscal,dy10);
236 tz = _mm_mul_ps(fscal,dz10);
238 /* Update vectorial force */
239 fix1 = _mm_add_ps(fix1,tx);
240 fiy1 = _mm_add_ps(fiy1,ty);
241 fiz1 = _mm_add_ps(fiz1,tz);
243 fjx0 = _mm_add_ps(fjx0,tx);
244 fjy0 = _mm_add_ps(fjy0,ty);
245 fjz0 = _mm_add_ps(fjz0,tz);
247 /**************************
248 * CALCULATE INTERACTIONS *
249 **************************/
251 /* Compute parameters for interactions between i and j atoms */
252 qq20 = _mm_mul_ps(iq2,jq0);
254 /* COULOMB ELECTROSTATICS */
255 velec = _mm_mul_ps(qq20,rinv20);
256 felec = _mm_mul_ps(velec,rinvsq20);
258 /* Update potential sum for this i atom from the interaction with this j atom. */
259 velecsum = _mm_add_ps(velecsum,velec);
263 /* Calculate temporary vectorial force */
264 tx = _mm_mul_ps(fscal,dx20);
265 ty = _mm_mul_ps(fscal,dy20);
266 tz = _mm_mul_ps(fscal,dz20);
268 /* Update vectorial force */
269 fix2 = _mm_add_ps(fix2,tx);
270 fiy2 = _mm_add_ps(fiy2,ty);
271 fiz2 = _mm_add_ps(fiz2,tz);
273 fjx0 = _mm_add_ps(fjx0,tx);
274 fjy0 = _mm_add_ps(fjy0,ty);
275 fjz0 = _mm_add_ps(fjz0,tz);
277 /**************************
278 * CALCULATE INTERACTIONS *
279 **************************/
281 /* Compute parameters for interactions between i and j atoms */
282 qq30 = _mm_mul_ps(iq3,jq0);
284 /* COULOMB ELECTROSTATICS */
285 velec = _mm_mul_ps(qq30,rinv30);
286 felec = _mm_mul_ps(velec,rinvsq30);
288 /* Update potential sum for this i atom from the interaction with this j atom. */
289 velecsum = _mm_add_ps(velecsum,velec);
293 /* Calculate temporary vectorial force */
294 tx = _mm_mul_ps(fscal,dx30);
295 ty = _mm_mul_ps(fscal,dy30);
296 tz = _mm_mul_ps(fscal,dz30);
298 /* Update vectorial force */
299 fix3 = _mm_add_ps(fix3,tx);
300 fiy3 = _mm_add_ps(fiy3,ty);
301 fiz3 = _mm_add_ps(fiz3,tz);
303 fjx0 = _mm_add_ps(fjx0,tx);
304 fjy0 = _mm_add_ps(fjy0,ty);
305 fjz0 = _mm_add_ps(fjz0,tz);
307 fjptrA = f+j_coord_offsetA;
308 fjptrB = f+j_coord_offsetB;
309 fjptrC = f+j_coord_offsetC;
310 fjptrD = f+j_coord_offsetD;
312 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
314 /* Inner loop uses 84 flops */
320 /* Get j neighbor index, and coordinate index */
321 jnrlistA = jjnr[jidx];
322 jnrlistB = jjnr[jidx+1];
323 jnrlistC = jjnr[jidx+2];
324 jnrlistD = jjnr[jidx+3];
325 /* Sign of each element will be negative for non-real atoms.
326 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
327 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
329 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
330 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
331 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
332 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
333 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
334 j_coord_offsetA = DIM*jnrA;
335 j_coord_offsetB = DIM*jnrB;
336 j_coord_offsetC = DIM*jnrC;
337 j_coord_offsetD = DIM*jnrD;
339 /* load j atom coordinates */
340 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
341 x+j_coord_offsetC,x+j_coord_offsetD,
344 /* Calculate displacement vector */
345 dx10 = _mm_sub_ps(ix1,jx0);
346 dy10 = _mm_sub_ps(iy1,jy0);
347 dz10 = _mm_sub_ps(iz1,jz0);
348 dx20 = _mm_sub_ps(ix2,jx0);
349 dy20 = _mm_sub_ps(iy2,jy0);
350 dz20 = _mm_sub_ps(iz2,jz0);
351 dx30 = _mm_sub_ps(ix3,jx0);
352 dy30 = _mm_sub_ps(iy3,jy0);
353 dz30 = _mm_sub_ps(iz3,jz0);
355 /* Calculate squared distance and things based on it */
356 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
357 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
358 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
360 rinv10 = gmx_mm_invsqrt_ps(rsq10);
361 rinv20 = gmx_mm_invsqrt_ps(rsq20);
362 rinv30 = gmx_mm_invsqrt_ps(rsq30);
364 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
365 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
366 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
368 /* Load parameters for j particles */
369 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
370 charge+jnrC+0,charge+jnrD+0);
372 fjx0 = _mm_setzero_ps();
373 fjy0 = _mm_setzero_ps();
374 fjz0 = _mm_setzero_ps();
376 /**************************
377 * CALCULATE INTERACTIONS *
378 **************************/
380 /* Compute parameters for interactions between i and j atoms */
381 qq10 = _mm_mul_ps(iq1,jq0);
383 /* COULOMB ELECTROSTATICS */
384 velec = _mm_mul_ps(qq10,rinv10);
385 felec = _mm_mul_ps(velec,rinvsq10);
387 /* Update potential sum for this i atom from the interaction with this j atom. */
388 velec = _mm_andnot_ps(dummy_mask,velec);
389 velecsum = _mm_add_ps(velecsum,velec);
393 fscal = _mm_andnot_ps(dummy_mask,fscal);
395 /* Calculate temporary vectorial force */
396 tx = _mm_mul_ps(fscal,dx10);
397 ty = _mm_mul_ps(fscal,dy10);
398 tz = _mm_mul_ps(fscal,dz10);
400 /* Update vectorial force */
401 fix1 = _mm_add_ps(fix1,tx);
402 fiy1 = _mm_add_ps(fiy1,ty);
403 fiz1 = _mm_add_ps(fiz1,tz);
405 fjx0 = _mm_add_ps(fjx0,tx);
406 fjy0 = _mm_add_ps(fjy0,ty);
407 fjz0 = _mm_add_ps(fjz0,tz);
409 /**************************
410 * CALCULATE INTERACTIONS *
411 **************************/
413 /* Compute parameters for interactions between i and j atoms */
414 qq20 = _mm_mul_ps(iq2,jq0);
416 /* COULOMB ELECTROSTATICS */
417 velec = _mm_mul_ps(qq20,rinv20);
418 felec = _mm_mul_ps(velec,rinvsq20);
420 /* Update potential sum for this i atom from the interaction with this j atom. */
421 velec = _mm_andnot_ps(dummy_mask,velec);
422 velecsum = _mm_add_ps(velecsum,velec);
426 fscal = _mm_andnot_ps(dummy_mask,fscal);
428 /* Calculate temporary vectorial force */
429 tx = _mm_mul_ps(fscal,dx20);
430 ty = _mm_mul_ps(fscal,dy20);
431 tz = _mm_mul_ps(fscal,dz20);
433 /* Update vectorial force */
434 fix2 = _mm_add_ps(fix2,tx);
435 fiy2 = _mm_add_ps(fiy2,ty);
436 fiz2 = _mm_add_ps(fiz2,tz);
438 fjx0 = _mm_add_ps(fjx0,tx);
439 fjy0 = _mm_add_ps(fjy0,ty);
440 fjz0 = _mm_add_ps(fjz0,tz);
442 /**************************
443 * CALCULATE INTERACTIONS *
444 **************************/
446 /* Compute parameters for interactions between i and j atoms */
447 qq30 = _mm_mul_ps(iq3,jq0);
449 /* COULOMB ELECTROSTATICS */
450 velec = _mm_mul_ps(qq30,rinv30);
451 felec = _mm_mul_ps(velec,rinvsq30);
453 /* Update potential sum for this i atom from the interaction with this j atom. */
454 velec = _mm_andnot_ps(dummy_mask,velec);
455 velecsum = _mm_add_ps(velecsum,velec);
459 fscal = _mm_andnot_ps(dummy_mask,fscal);
461 /* Calculate temporary vectorial force */
462 tx = _mm_mul_ps(fscal,dx30);
463 ty = _mm_mul_ps(fscal,dy30);
464 tz = _mm_mul_ps(fscal,dz30);
466 /* Update vectorial force */
467 fix3 = _mm_add_ps(fix3,tx);
468 fiy3 = _mm_add_ps(fiy3,ty);
469 fiz3 = _mm_add_ps(fiz3,tz);
471 fjx0 = _mm_add_ps(fjx0,tx);
472 fjy0 = _mm_add_ps(fjy0,ty);
473 fjz0 = _mm_add_ps(fjz0,tz);
475 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
476 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
477 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
478 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
480 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
482 /* Inner loop uses 84 flops */
485 /* End of innermost loop */
487 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
488 f+i_coord_offset+DIM,fshift+i_shift_offset);
491 /* Update potential energies */
492 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
494 /* Increment number of inner iterations */
495 inneriter += j_index_end - j_index_start;
497 /* Outer loop uses 19 flops */
500 /* Increment number of outer iterations */
503 /* Update outer/inner flops */
505 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*84);
508 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomW4P1_F_sse4_1_single
509 * Electrostatics interaction: Coulomb
510 * VdW interaction: None
511 * Geometry: Water4-Particle
512 * Calculate force/pot: Force
515 nb_kernel_ElecCoul_VdwNone_GeomW4P1_F_sse4_1_single
516 (t_nblist * gmx_restrict nlist,
517 rvec * gmx_restrict xx,
518 rvec * gmx_restrict ff,
519 t_forcerec * gmx_restrict fr,
520 t_mdatoms * gmx_restrict mdatoms,
521 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
522 t_nrnb * gmx_restrict nrnb)
524 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
525 * just 0 for non-waters.
526 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
527 * jnr indices corresponding to data put in the four positions in the SIMD register.
529 int i_shift_offset,i_coord_offset,outeriter,inneriter;
530 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
531 int jnrA,jnrB,jnrC,jnrD;
532 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
533 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
534 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
536 real *shiftvec,*fshift,*x,*f;
537 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
539 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
541 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
543 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
545 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
546 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
547 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
548 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
549 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
550 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
551 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
553 __m128 dummy_mask,cutoff_mask;
554 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
555 __m128 one = _mm_set1_ps(1.0);
556 __m128 two = _mm_set1_ps(2.0);
562 jindex = nlist->jindex;
564 shiftidx = nlist->shift;
566 shiftvec = fr->shift_vec[0];
567 fshift = fr->fshift[0];
568 facel = _mm_set1_ps(fr->epsfac);
569 charge = mdatoms->chargeA;
571 /* Setup water-specific parameters */
572 inr = nlist->iinr[0];
573 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
574 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
575 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
577 /* Avoid stupid compiler warnings */
578 jnrA = jnrB = jnrC = jnrD = 0;
587 for(iidx=0;iidx<4*DIM;iidx++)
592 /* Start outer loop over neighborlists */
593 for(iidx=0; iidx<nri; iidx++)
595 /* Load shift vector for this list */
596 i_shift_offset = DIM*shiftidx[iidx];
598 /* Load limits for loop over neighbors */
599 j_index_start = jindex[iidx];
600 j_index_end = jindex[iidx+1];
602 /* Get outer coordinate index */
604 i_coord_offset = DIM*inr;
606 /* Load i particle coords and add shift vector */
607 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
608 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
610 fix1 = _mm_setzero_ps();
611 fiy1 = _mm_setzero_ps();
612 fiz1 = _mm_setzero_ps();
613 fix2 = _mm_setzero_ps();
614 fiy2 = _mm_setzero_ps();
615 fiz2 = _mm_setzero_ps();
616 fix3 = _mm_setzero_ps();
617 fiy3 = _mm_setzero_ps();
618 fiz3 = _mm_setzero_ps();
620 /* Start inner kernel loop */
621 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
624 /* Get j neighbor index, and coordinate index */
629 j_coord_offsetA = DIM*jnrA;
630 j_coord_offsetB = DIM*jnrB;
631 j_coord_offsetC = DIM*jnrC;
632 j_coord_offsetD = DIM*jnrD;
634 /* load j atom coordinates */
635 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
636 x+j_coord_offsetC,x+j_coord_offsetD,
639 /* Calculate displacement vector */
640 dx10 = _mm_sub_ps(ix1,jx0);
641 dy10 = _mm_sub_ps(iy1,jy0);
642 dz10 = _mm_sub_ps(iz1,jz0);
643 dx20 = _mm_sub_ps(ix2,jx0);
644 dy20 = _mm_sub_ps(iy2,jy0);
645 dz20 = _mm_sub_ps(iz2,jz0);
646 dx30 = _mm_sub_ps(ix3,jx0);
647 dy30 = _mm_sub_ps(iy3,jy0);
648 dz30 = _mm_sub_ps(iz3,jz0);
650 /* Calculate squared distance and things based on it */
651 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
652 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
653 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
655 rinv10 = gmx_mm_invsqrt_ps(rsq10);
656 rinv20 = gmx_mm_invsqrt_ps(rsq20);
657 rinv30 = gmx_mm_invsqrt_ps(rsq30);
659 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
660 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
661 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
663 /* Load parameters for j particles */
664 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
665 charge+jnrC+0,charge+jnrD+0);
667 fjx0 = _mm_setzero_ps();
668 fjy0 = _mm_setzero_ps();
669 fjz0 = _mm_setzero_ps();
671 /**************************
672 * CALCULATE INTERACTIONS *
673 **************************/
675 /* Compute parameters for interactions between i and j atoms */
676 qq10 = _mm_mul_ps(iq1,jq0);
678 /* COULOMB ELECTROSTATICS */
679 velec = _mm_mul_ps(qq10,rinv10);
680 felec = _mm_mul_ps(velec,rinvsq10);
684 /* Calculate temporary vectorial force */
685 tx = _mm_mul_ps(fscal,dx10);
686 ty = _mm_mul_ps(fscal,dy10);
687 tz = _mm_mul_ps(fscal,dz10);
689 /* Update vectorial force */
690 fix1 = _mm_add_ps(fix1,tx);
691 fiy1 = _mm_add_ps(fiy1,ty);
692 fiz1 = _mm_add_ps(fiz1,tz);
694 fjx0 = _mm_add_ps(fjx0,tx);
695 fjy0 = _mm_add_ps(fjy0,ty);
696 fjz0 = _mm_add_ps(fjz0,tz);
698 /**************************
699 * CALCULATE INTERACTIONS *
700 **************************/
702 /* Compute parameters for interactions between i and j atoms */
703 qq20 = _mm_mul_ps(iq2,jq0);
705 /* COULOMB ELECTROSTATICS */
706 velec = _mm_mul_ps(qq20,rinv20);
707 felec = _mm_mul_ps(velec,rinvsq20);
711 /* Calculate temporary vectorial force */
712 tx = _mm_mul_ps(fscal,dx20);
713 ty = _mm_mul_ps(fscal,dy20);
714 tz = _mm_mul_ps(fscal,dz20);
716 /* Update vectorial force */
717 fix2 = _mm_add_ps(fix2,tx);
718 fiy2 = _mm_add_ps(fiy2,ty);
719 fiz2 = _mm_add_ps(fiz2,tz);
721 fjx0 = _mm_add_ps(fjx0,tx);
722 fjy0 = _mm_add_ps(fjy0,ty);
723 fjz0 = _mm_add_ps(fjz0,tz);
725 /**************************
726 * CALCULATE INTERACTIONS *
727 **************************/
729 /* Compute parameters for interactions between i and j atoms */
730 qq30 = _mm_mul_ps(iq3,jq0);
732 /* COULOMB ELECTROSTATICS */
733 velec = _mm_mul_ps(qq30,rinv30);
734 felec = _mm_mul_ps(velec,rinvsq30);
738 /* Calculate temporary vectorial force */
739 tx = _mm_mul_ps(fscal,dx30);
740 ty = _mm_mul_ps(fscal,dy30);
741 tz = _mm_mul_ps(fscal,dz30);
743 /* Update vectorial force */
744 fix3 = _mm_add_ps(fix3,tx);
745 fiy3 = _mm_add_ps(fiy3,ty);
746 fiz3 = _mm_add_ps(fiz3,tz);
748 fjx0 = _mm_add_ps(fjx0,tx);
749 fjy0 = _mm_add_ps(fjy0,ty);
750 fjz0 = _mm_add_ps(fjz0,tz);
752 fjptrA = f+j_coord_offsetA;
753 fjptrB = f+j_coord_offsetB;
754 fjptrC = f+j_coord_offsetC;
755 fjptrD = f+j_coord_offsetD;
757 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
759 /* Inner loop uses 81 flops */
765 /* Get j neighbor index, and coordinate index */
766 jnrlistA = jjnr[jidx];
767 jnrlistB = jjnr[jidx+1];
768 jnrlistC = jjnr[jidx+2];
769 jnrlistD = jjnr[jidx+3];
770 /* Sign of each element will be negative for non-real atoms.
771 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
772 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
774 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
775 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
776 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
777 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
778 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
779 j_coord_offsetA = DIM*jnrA;
780 j_coord_offsetB = DIM*jnrB;
781 j_coord_offsetC = DIM*jnrC;
782 j_coord_offsetD = DIM*jnrD;
784 /* load j atom coordinates */
785 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
786 x+j_coord_offsetC,x+j_coord_offsetD,
789 /* Calculate displacement vector */
790 dx10 = _mm_sub_ps(ix1,jx0);
791 dy10 = _mm_sub_ps(iy1,jy0);
792 dz10 = _mm_sub_ps(iz1,jz0);
793 dx20 = _mm_sub_ps(ix2,jx0);
794 dy20 = _mm_sub_ps(iy2,jy0);
795 dz20 = _mm_sub_ps(iz2,jz0);
796 dx30 = _mm_sub_ps(ix3,jx0);
797 dy30 = _mm_sub_ps(iy3,jy0);
798 dz30 = _mm_sub_ps(iz3,jz0);
800 /* Calculate squared distance and things based on it */
801 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
802 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
803 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
805 rinv10 = gmx_mm_invsqrt_ps(rsq10);
806 rinv20 = gmx_mm_invsqrt_ps(rsq20);
807 rinv30 = gmx_mm_invsqrt_ps(rsq30);
809 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
810 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
811 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
813 /* Load parameters for j particles */
814 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
815 charge+jnrC+0,charge+jnrD+0);
817 fjx0 = _mm_setzero_ps();
818 fjy0 = _mm_setzero_ps();
819 fjz0 = _mm_setzero_ps();
821 /**************************
822 * CALCULATE INTERACTIONS *
823 **************************/
825 /* Compute parameters for interactions between i and j atoms */
826 qq10 = _mm_mul_ps(iq1,jq0);
828 /* COULOMB ELECTROSTATICS */
829 velec = _mm_mul_ps(qq10,rinv10);
830 felec = _mm_mul_ps(velec,rinvsq10);
834 fscal = _mm_andnot_ps(dummy_mask,fscal);
836 /* Calculate temporary vectorial force */
837 tx = _mm_mul_ps(fscal,dx10);
838 ty = _mm_mul_ps(fscal,dy10);
839 tz = _mm_mul_ps(fscal,dz10);
841 /* Update vectorial force */
842 fix1 = _mm_add_ps(fix1,tx);
843 fiy1 = _mm_add_ps(fiy1,ty);
844 fiz1 = _mm_add_ps(fiz1,tz);
846 fjx0 = _mm_add_ps(fjx0,tx);
847 fjy0 = _mm_add_ps(fjy0,ty);
848 fjz0 = _mm_add_ps(fjz0,tz);
850 /**************************
851 * CALCULATE INTERACTIONS *
852 **************************/
854 /* Compute parameters for interactions between i and j atoms */
855 qq20 = _mm_mul_ps(iq2,jq0);
857 /* COULOMB ELECTROSTATICS */
858 velec = _mm_mul_ps(qq20,rinv20);
859 felec = _mm_mul_ps(velec,rinvsq20);
863 fscal = _mm_andnot_ps(dummy_mask,fscal);
865 /* Calculate temporary vectorial force */
866 tx = _mm_mul_ps(fscal,dx20);
867 ty = _mm_mul_ps(fscal,dy20);
868 tz = _mm_mul_ps(fscal,dz20);
870 /* Update vectorial force */
871 fix2 = _mm_add_ps(fix2,tx);
872 fiy2 = _mm_add_ps(fiy2,ty);
873 fiz2 = _mm_add_ps(fiz2,tz);
875 fjx0 = _mm_add_ps(fjx0,tx);
876 fjy0 = _mm_add_ps(fjy0,ty);
877 fjz0 = _mm_add_ps(fjz0,tz);
879 /**************************
880 * CALCULATE INTERACTIONS *
881 **************************/
883 /* Compute parameters for interactions between i and j atoms */
884 qq30 = _mm_mul_ps(iq3,jq0);
886 /* COULOMB ELECTROSTATICS */
887 velec = _mm_mul_ps(qq30,rinv30);
888 felec = _mm_mul_ps(velec,rinvsq30);
892 fscal = _mm_andnot_ps(dummy_mask,fscal);
894 /* Calculate temporary vectorial force */
895 tx = _mm_mul_ps(fscal,dx30);
896 ty = _mm_mul_ps(fscal,dy30);
897 tz = _mm_mul_ps(fscal,dz30);
899 /* Update vectorial force */
900 fix3 = _mm_add_ps(fix3,tx);
901 fiy3 = _mm_add_ps(fiy3,ty);
902 fiz3 = _mm_add_ps(fiz3,tz);
904 fjx0 = _mm_add_ps(fjx0,tx);
905 fjy0 = _mm_add_ps(fjy0,ty);
906 fjz0 = _mm_add_ps(fjz0,tz);
908 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
909 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
910 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
911 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
913 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
915 /* Inner loop uses 81 flops */
918 /* End of innermost loop */
920 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
921 f+i_coord_offset+DIM,fshift+i_shift_offset);
923 /* Increment number of inner iterations */
924 inneriter += j_index_end - j_index_start;
926 /* Outer loop uses 18 flops */
929 /* Increment number of outer iterations */
932 /* Update outer/inner flops */
934 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*81);