2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 * Note: this file was generated by the GROMACS avx_128_fma_single kernel generator.
42 #include "../nb_kernel.h"
43 #include "gromacs/legacyheaders/types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "gromacs/legacyheaders/nrnb.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomW4P1_VF_avx_128_fma_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_avx_128_fma_single
59 (t_nblist * gmx_restrict nlist,
60 rvec * gmx_restrict xx,
61 rvec * gmx_restrict ff,
62 t_forcerec * gmx_restrict fr,
63 t_mdatoms * gmx_restrict mdatoms,
64 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65 t_nrnb * gmx_restrict nrnb)
67 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68 * just 0 for non-waters.
69 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
70 * jnr indices corresponding to data put in the four positions in the SIMD register.
72 int i_shift_offset,i_coord_offset,outeriter,inneriter;
73 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74 int jnrA,jnrB,jnrC,jnrD;
75 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
79 real *shiftvec,*fshift,*x,*f;
80 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
82 __m128 fscal,rcutoff,rcutoff2,jidxall;
84 __m128 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 /* Update vectorial force */
234 fix1 = _mm_macc_ps(dx10,fscal,fix1);
235 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
236 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
238 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
239 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
240 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
242 /**************************
243 * CALCULATE INTERACTIONS *
244 **************************/
246 /* Compute parameters for interactions between i and j atoms */
247 qq20 = _mm_mul_ps(iq2,jq0);
249 /* COULOMB ELECTROSTATICS */
250 velec = _mm_mul_ps(qq20,rinv20);
251 felec = _mm_mul_ps(velec,rinvsq20);
253 /* Update potential sum for this i atom from the interaction with this j atom. */
254 velecsum = _mm_add_ps(velecsum,velec);
258 /* Update vectorial force */
259 fix2 = _mm_macc_ps(dx20,fscal,fix2);
260 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
261 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
263 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
264 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
265 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
267 /**************************
268 * CALCULATE INTERACTIONS *
269 **************************/
271 /* Compute parameters for interactions between i and j atoms */
272 qq30 = _mm_mul_ps(iq3,jq0);
274 /* COULOMB ELECTROSTATICS */
275 velec = _mm_mul_ps(qq30,rinv30);
276 felec = _mm_mul_ps(velec,rinvsq30);
278 /* Update potential sum for this i atom from the interaction with this j atom. */
279 velecsum = _mm_add_ps(velecsum,velec);
283 /* Update vectorial force */
284 fix3 = _mm_macc_ps(dx30,fscal,fix3);
285 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
286 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
288 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
289 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
290 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
292 fjptrA = f+j_coord_offsetA;
293 fjptrB = f+j_coord_offsetB;
294 fjptrC = f+j_coord_offsetC;
295 fjptrD = f+j_coord_offsetD;
297 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
299 /* Inner loop uses 93 flops */
305 /* Get j neighbor index, and coordinate index */
306 jnrlistA = jjnr[jidx];
307 jnrlistB = jjnr[jidx+1];
308 jnrlistC = jjnr[jidx+2];
309 jnrlistD = jjnr[jidx+3];
310 /* Sign of each element will be negative for non-real atoms.
311 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
312 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
314 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
315 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
316 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
317 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
318 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
319 j_coord_offsetA = DIM*jnrA;
320 j_coord_offsetB = DIM*jnrB;
321 j_coord_offsetC = DIM*jnrC;
322 j_coord_offsetD = DIM*jnrD;
324 /* load j atom coordinates */
325 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
326 x+j_coord_offsetC,x+j_coord_offsetD,
329 /* Calculate displacement vector */
330 dx10 = _mm_sub_ps(ix1,jx0);
331 dy10 = _mm_sub_ps(iy1,jy0);
332 dz10 = _mm_sub_ps(iz1,jz0);
333 dx20 = _mm_sub_ps(ix2,jx0);
334 dy20 = _mm_sub_ps(iy2,jy0);
335 dz20 = _mm_sub_ps(iz2,jz0);
336 dx30 = _mm_sub_ps(ix3,jx0);
337 dy30 = _mm_sub_ps(iy3,jy0);
338 dz30 = _mm_sub_ps(iz3,jz0);
340 /* Calculate squared distance and things based on it */
341 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
342 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
343 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
345 rinv10 = gmx_mm_invsqrt_ps(rsq10);
346 rinv20 = gmx_mm_invsqrt_ps(rsq20);
347 rinv30 = gmx_mm_invsqrt_ps(rsq30);
349 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
350 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
351 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
353 /* Load parameters for j particles */
354 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
355 charge+jnrC+0,charge+jnrD+0);
357 fjx0 = _mm_setzero_ps();
358 fjy0 = _mm_setzero_ps();
359 fjz0 = _mm_setzero_ps();
361 /**************************
362 * CALCULATE INTERACTIONS *
363 **************************/
365 /* Compute parameters for interactions between i and j atoms */
366 qq10 = _mm_mul_ps(iq1,jq0);
368 /* COULOMB ELECTROSTATICS */
369 velec = _mm_mul_ps(qq10,rinv10);
370 felec = _mm_mul_ps(velec,rinvsq10);
372 /* Update potential sum for this i atom from the interaction with this j atom. */
373 velec = _mm_andnot_ps(dummy_mask,velec);
374 velecsum = _mm_add_ps(velecsum,velec);
378 fscal = _mm_andnot_ps(dummy_mask,fscal);
380 /* Update vectorial force */
381 fix1 = _mm_macc_ps(dx10,fscal,fix1);
382 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
383 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
385 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
386 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
387 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
389 /**************************
390 * CALCULATE INTERACTIONS *
391 **************************/
393 /* Compute parameters for interactions between i and j atoms */
394 qq20 = _mm_mul_ps(iq2,jq0);
396 /* COULOMB ELECTROSTATICS */
397 velec = _mm_mul_ps(qq20,rinv20);
398 felec = _mm_mul_ps(velec,rinvsq20);
400 /* Update potential sum for this i atom from the interaction with this j atom. */
401 velec = _mm_andnot_ps(dummy_mask,velec);
402 velecsum = _mm_add_ps(velecsum,velec);
406 fscal = _mm_andnot_ps(dummy_mask,fscal);
408 /* Update vectorial force */
409 fix2 = _mm_macc_ps(dx20,fscal,fix2);
410 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
411 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
413 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
414 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
415 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
417 /**************************
418 * CALCULATE INTERACTIONS *
419 **************************/
421 /* Compute parameters for interactions between i and j atoms */
422 qq30 = _mm_mul_ps(iq3,jq0);
424 /* COULOMB ELECTROSTATICS */
425 velec = _mm_mul_ps(qq30,rinv30);
426 felec = _mm_mul_ps(velec,rinvsq30);
428 /* Update potential sum for this i atom from the interaction with this j atom. */
429 velec = _mm_andnot_ps(dummy_mask,velec);
430 velecsum = _mm_add_ps(velecsum,velec);
434 fscal = _mm_andnot_ps(dummy_mask,fscal);
436 /* Update vectorial force */
437 fix3 = _mm_macc_ps(dx30,fscal,fix3);
438 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
439 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
441 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
442 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
443 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
445 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
446 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
447 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
448 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
450 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
452 /* Inner loop uses 93 flops */
455 /* End of innermost loop */
457 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
458 f+i_coord_offset+DIM,fshift+i_shift_offset);
461 /* Update potential energies */
462 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
464 /* Increment number of inner iterations */
465 inneriter += j_index_end - j_index_start;
467 /* Outer loop uses 19 flops */
470 /* Increment number of outer iterations */
473 /* Update outer/inner flops */
475 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*93);
478 * Gromacs nonbonded kernel: nb_kernel_ElecCoul_VdwNone_GeomW4P1_F_avx_128_fma_single
479 * Electrostatics interaction: Coulomb
480 * VdW interaction: None
481 * Geometry: Water4-Particle
482 * Calculate force/pot: Force
485 nb_kernel_ElecCoul_VdwNone_GeomW4P1_F_avx_128_fma_single
486 (t_nblist * gmx_restrict nlist,
487 rvec * gmx_restrict xx,
488 rvec * gmx_restrict ff,
489 t_forcerec * gmx_restrict fr,
490 t_mdatoms * gmx_restrict mdatoms,
491 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
492 t_nrnb * gmx_restrict nrnb)
494 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
495 * just 0 for non-waters.
496 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
497 * jnr indices corresponding to data put in the four positions in the SIMD register.
499 int i_shift_offset,i_coord_offset,outeriter,inneriter;
500 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
501 int jnrA,jnrB,jnrC,jnrD;
502 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
503 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
504 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
506 real *shiftvec,*fshift,*x,*f;
507 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
509 __m128 fscal,rcutoff,rcutoff2,jidxall;
511 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
513 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
515 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
516 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
517 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
518 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
519 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
520 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
521 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
523 __m128 dummy_mask,cutoff_mask;
524 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
525 __m128 one = _mm_set1_ps(1.0);
526 __m128 two = _mm_set1_ps(2.0);
532 jindex = nlist->jindex;
534 shiftidx = nlist->shift;
536 shiftvec = fr->shift_vec[0];
537 fshift = fr->fshift[0];
538 facel = _mm_set1_ps(fr->epsfac);
539 charge = mdatoms->chargeA;
541 /* Setup water-specific parameters */
542 inr = nlist->iinr[0];
543 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
544 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
545 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
547 /* Avoid stupid compiler warnings */
548 jnrA = jnrB = jnrC = jnrD = 0;
557 for(iidx=0;iidx<4*DIM;iidx++)
562 /* Start outer loop over neighborlists */
563 for(iidx=0; iidx<nri; iidx++)
565 /* Load shift vector for this list */
566 i_shift_offset = DIM*shiftidx[iidx];
568 /* Load limits for loop over neighbors */
569 j_index_start = jindex[iidx];
570 j_index_end = jindex[iidx+1];
572 /* Get outer coordinate index */
574 i_coord_offset = DIM*inr;
576 /* Load i particle coords and add shift vector */
577 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
578 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
580 fix1 = _mm_setzero_ps();
581 fiy1 = _mm_setzero_ps();
582 fiz1 = _mm_setzero_ps();
583 fix2 = _mm_setzero_ps();
584 fiy2 = _mm_setzero_ps();
585 fiz2 = _mm_setzero_ps();
586 fix3 = _mm_setzero_ps();
587 fiy3 = _mm_setzero_ps();
588 fiz3 = _mm_setzero_ps();
590 /* Start inner kernel loop */
591 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
594 /* Get j neighbor index, and coordinate index */
599 j_coord_offsetA = DIM*jnrA;
600 j_coord_offsetB = DIM*jnrB;
601 j_coord_offsetC = DIM*jnrC;
602 j_coord_offsetD = DIM*jnrD;
604 /* load j atom coordinates */
605 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
606 x+j_coord_offsetC,x+j_coord_offsetD,
609 /* Calculate displacement vector */
610 dx10 = _mm_sub_ps(ix1,jx0);
611 dy10 = _mm_sub_ps(iy1,jy0);
612 dz10 = _mm_sub_ps(iz1,jz0);
613 dx20 = _mm_sub_ps(ix2,jx0);
614 dy20 = _mm_sub_ps(iy2,jy0);
615 dz20 = _mm_sub_ps(iz2,jz0);
616 dx30 = _mm_sub_ps(ix3,jx0);
617 dy30 = _mm_sub_ps(iy3,jy0);
618 dz30 = _mm_sub_ps(iz3,jz0);
620 /* Calculate squared distance and things based on it */
621 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
622 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
623 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
625 rinv10 = gmx_mm_invsqrt_ps(rsq10);
626 rinv20 = gmx_mm_invsqrt_ps(rsq20);
627 rinv30 = gmx_mm_invsqrt_ps(rsq30);
629 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
630 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
631 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
633 /* Load parameters for j particles */
634 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
635 charge+jnrC+0,charge+jnrD+0);
637 fjx0 = _mm_setzero_ps();
638 fjy0 = _mm_setzero_ps();
639 fjz0 = _mm_setzero_ps();
641 /**************************
642 * CALCULATE INTERACTIONS *
643 **************************/
645 /* Compute parameters for interactions between i and j atoms */
646 qq10 = _mm_mul_ps(iq1,jq0);
648 /* COULOMB ELECTROSTATICS */
649 velec = _mm_mul_ps(qq10,rinv10);
650 felec = _mm_mul_ps(velec,rinvsq10);
654 /* Update vectorial force */
655 fix1 = _mm_macc_ps(dx10,fscal,fix1);
656 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
657 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
659 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
660 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
661 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
663 /**************************
664 * CALCULATE INTERACTIONS *
665 **************************/
667 /* Compute parameters for interactions between i and j atoms */
668 qq20 = _mm_mul_ps(iq2,jq0);
670 /* COULOMB ELECTROSTATICS */
671 velec = _mm_mul_ps(qq20,rinv20);
672 felec = _mm_mul_ps(velec,rinvsq20);
676 /* Update vectorial force */
677 fix2 = _mm_macc_ps(dx20,fscal,fix2);
678 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
679 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
681 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
682 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
683 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
685 /**************************
686 * CALCULATE INTERACTIONS *
687 **************************/
689 /* Compute parameters for interactions between i and j atoms */
690 qq30 = _mm_mul_ps(iq3,jq0);
692 /* COULOMB ELECTROSTATICS */
693 velec = _mm_mul_ps(qq30,rinv30);
694 felec = _mm_mul_ps(velec,rinvsq30);
698 /* Update vectorial force */
699 fix3 = _mm_macc_ps(dx30,fscal,fix3);
700 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
701 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
703 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
704 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
705 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
707 fjptrA = f+j_coord_offsetA;
708 fjptrB = f+j_coord_offsetB;
709 fjptrC = f+j_coord_offsetC;
710 fjptrD = f+j_coord_offsetD;
712 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
714 /* Inner loop uses 90 flops */
720 /* Get j neighbor index, and coordinate index */
721 jnrlistA = jjnr[jidx];
722 jnrlistB = jjnr[jidx+1];
723 jnrlistC = jjnr[jidx+2];
724 jnrlistD = jjnr[jidx+3];
725 /* Sign of each element will be negative for non-real atoms.
726 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
727 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
729 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
730 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
731 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
732 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
733 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
734 j_coord_offsetA = DIM*jnrA;
735 j_coord_offsetB = DIM*jnrB;
736 j_coord_offsetC = DIM*jnrC;
737 j_coord_offsetD = DIM*jnrD;
739 /* load j atom coordinates */
740 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
741 x+j_coord_offsetC,x+j_coord_offsetD,
744 /* Calculate displacement vector */
745 dx10 = _mm_sub_ps(ix1,jx0);
746 dy10 = _mm_sub_ps(iy1,jy0);
747 dz10 = _mm_sub_ps(iz1,jz0);
748 dx20 = _mm_sub_ps(ix2,jx0);
749 dy20 = _mm_sub_ps(iy2,jy0);
750 dz20 = _mm_sub_ps(iz2,jz0);
751 dx30 = _mm_sub_ps(ix3,jx0);
752 dy30 = _mm_sub_ps(iy3,jy0);
753 dz30 = _mm_sub_ps(iz3,jz0);
755 /* Calculate squared distance and things based on it */
756 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
757 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
758 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
760 rinv10 = gmx_mm_invsqrt_ps(rsq10);
761 rinv20 = gmx_mm_invsqrt_ps(rsq20);
762 rinv30 = gmx_mm_invsqrt_ps(rsq30);
764 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
765 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
766 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
768 /* Load parameters for j particles */
769 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
770 charge+jnrC+0,charge+jnrD+0);
772 fjx0 = _mm_setzero_ps();
773 fjy0 = _mm_setzero_ps();
774 fjz0 = _mm_setzero_ps();
776 /**************************
777 * CALCULATE INTERACTIONS *
778 **************************/
780 /* Compute parameters for interactions between i and j atoms */
781 qq10 = _mm_mul_ps(iq1,jq0);
783 /* COULOMB ELECTROSTATICS */
784 velec = _mm_mul_ps(qq10,rinv10);
785 felec = _mm_mul_ps(velec,rinvsq10);
789 fscal = _mm_andnot_ps(dummy_mask,fscal);
791 /* Update vectorial force */
792 fix1 = _mm_macc_ps(dx10,fscal,fix1);
793 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
794 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
796 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
797 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
798 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
800 /**************************
801 * CALCULATE INTERACTIONS *
802 **************************/
804 /* Compute parameters for interactions between i and j atoms */
805 qq20 = _mm_mul_ps(iq2,jq0);
807 /* COULOMB ELECTROSTATICS */
808 velec = _mm_mul_ps(qq20,rinv20);
809 felec = _mm_mul_ps(velec,rinvsq20);
813 fscal = _mm_andnot_ps(dummy_mask,fscal);
815 /* Update vectorial force */
816 fix2 = _mm_macc_ps(dx20,fscal,fix2);
817 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
818 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
820 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
821 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
822 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
824 /**************************
825 * CALCULATE INTERACTIONS *
826 **************************/
828 /* Compute parameters for interactions between i and j atoms */
829 qq30 = _mm_mul_ps(iq3,jq0);
831 /* COULOMB ELECTROSTATICS */
832 velec = _mm_mul_ps(qq30,rinv30);
833 felec = _mm_mul_ps(velec,rinvsq30);
837 fscal = _mm_andnot_ps(dummy_mask,fscal);
839 /* Update vectorial force */
840 fix3 = _mm_macc_ps(dx30,fscal,fix3);
841 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
842 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
844 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
845 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
846 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
848 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
849 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
850 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
851 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
853 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
855 /* Inner loop uses 90 flops */
858 /* End of innermost loop */
860 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
861 f+i_coord_offset+DIM,fshift+i_shift_offset);
863 /* Increment number of inner iterations */
864 inneriter += j_index_end - j_index_start;
866 /* Outer loop uses 18 flops */
869 /* Increment number of outer iterations */
872 /* Update outer/inner flops */
874 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*90);