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_ElecRF_VdwNone_GeomW3P1_VF_avx_128_fma_single
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: None
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
58 nb_kernel_ElecRF_VdwNone_GeomW3P1_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 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
86 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
88 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
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;
113 krf = _mm_set1_ps(fr->ic->k_rf);
114 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
115 crf = _mm_set1_ps(fr->ic->c_rf);
117 /* Setup water-specific parameters */
118 inr = nlist->iinr[0];
119 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
120 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
121 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
123 /* Avoid stupid compiler warnings */
124 jnrA = jnrB = jnrC = jnrD = 0;
133 for(iidx=0;iidx<4*DIM;iidx++)
138 /* Start outer loop over neighborlists */
139 for(iidx=0; iidx<nri; iidx++)
141 /* Load shift vector for this list */
142 i_shift_offset = DIM*shiftidx[iidx];
144 /* Load limits for loop over neighbors */
145 j_index_start = jindex[iidx];
146 j_index_end = jindex[iidx+1];
148 /* Get outer coordinate index */
150 i_coord_offset = DIM*inr;
152 /* Load i particle coords and add shift vector */
153 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
154 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
156 fix0 = _mm_setzero_ps();
157 fiy0 = _mm_setzero_ps();
158 fiz0 = _mm_setzero_ps();
159 fix1 = _mm_setzero_ps();
160 fiy1 = _mm_setzero_ps();
161 fiz1 = _mm_setzero_ps();
162 fix2 = _mm_setzero_ps();
163 fiy2 = _mm_setzero_ps();
164 fiz2 = _mm_setzero_ps();
166 /* Reset potential sums */
167 velecsum = _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);
192 dx10 = _mm_sub_ps(ix1,jx0);
193 dy10 = _mm_sub_ps(iy1,jy0);
194 dz10 = _mm_sub_ps(iz1,jz0);
195 dx20 = _mm_sub_ps(ix2,jx0);
196 dy20 = _mm_sub_ps(iy2,jy0);
197 dz20 = _mm_sub_ps(iz2,jz0);
199 /* Calculate squared distance and things based on it */
200 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
201 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
202 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
204 rinv00 = gmx_mm_invsqrt_ps(rsq00);
205 rinv10 = gmx_mm_invsqrt_ps(rsq10);
206 rinv20 = gmx_mm_invsqrt_ps(rsq20);
208 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
209 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
210 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
212 /* Load parameters for j particles */
213 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
214 charge+jnrC+0,charge+jnrD+0);
216 fjx0 = _mm_setzero_ps();
217 fjy0 = _mm_setzero_ps();
218 fjz0 = _mm_setzero_ps();
220 /**************************
221 * CALCULATE INTERACTIONS *
222 **************************/
224 /* Compute parameters for interactions between i and j atoms */
225 qq00 = _mm_mul_ps(iq0,jq0);
227 /* REACTION-FIELD ELECTROSTATICS */
228 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
229 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
231 /* Update potential sum for this i atom from the interaction with this j atom. */
232 velecsum = _mm_add_ps(velecsum,velec);
236 /* Update vectorial force */
237 fix0 = _mm_macc_ps(dx00,fscal,fix0);
238 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
239 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
241 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
242 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
243 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
245 /**************************
246 * CALCULATE INTERACTIONS *
247 **************************/
249 /* Compute parameters for interactions between i and j atoms */
250 qq10 = _mm_mul_ps(iq1,jq0);
252 /* REACTION-FIELD ELECTROSTATICS */
253 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
254 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
256 /* Update potential sum for this i atom from the interaction with this j atom. */
257 velecsum = _mm_add_ps(velecsum,velec);
261 /* Update vectorial force */
262 fix1 = _mm_macc_ps(dx10,fscal,fix1);
263 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
264 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
266 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
267 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
268 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
270 /**************************
271 * CALCULATE INTERACTIONS *
272 **************************/
274 /* Compute parameters for interactions between i and j atoms */
275 qq20 = _mm_mul_ps(iq2,jq0);
277 /* REACTION-FIELD ELECTROSTATICS */
278 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
279 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
281 /* Update potential sum for this i atom from the interaction with this j atom. */
282 velecsum = _mm_add_ps(velecsum,velec);
286 /* Update vectorial force */
287 fix2 = _mm_macc_ps(dx20,fscal,fix2);
288 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
289 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
291 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
292 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
293 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
295 fjptrA = f+j_coord_offsetA;
296 fjptrB = f+j_coord_offsetB;
297 fjptrC = f+j_coord_offsetC;
298 fjptrD = f+j_coord_offsetD;
300 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
302 /* Inner loop uses 105 flops */
308 /* Get j neighbor index, and coordinate index */
309 jnrlistA = jjnr[jidx];
310 jnrlistB = jjnr[jidx+1];
311 jnrlistC = jjnr[jidx+2];
312 jnrlistD = jjnr[jidx+3];
313 /* Sign of each element will be negative for non-real atoms.
314 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
315 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
317 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
318 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
319 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
320 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
321 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
322 j_coord_offsetA = DIM*jnrA;
323 j_coord_offsetB = DIM*jnrB;
324 j_coord_offsetC = DIM*jnrC;
325 j_coord_offsetD = DIM*jnrD;
327 /* load j atom coordinates */
328 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
329 x+j_coord_offsetC,x+j_coord_offsetD,
332 /* Calculate displacement vector */
333 dx00 = _mm_sub_ps(ix0,jx0);
334 dy00 = _mm_sub_ps(iy0,jy0);
335 dz00 = _mm_sub_ps(iz0,jz0);
336 dx10 = _mm_sub_ps(ix1,jx0);
337 dy10 = _mm_sub_ps(iy1,jy0);
338 dz10 = _mm_sub_ps(iz1,jz0);
339 dx20 = _mm_sub_ps(ix2,jx0);
340 dy20 = _mm_sub_ps(iy2,jy0);
341 dz20 = _mm_sub_ps(iz2,jz0);
343 /* Calculate squared distance and things based on it */
344 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
345 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
346 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
348 rinv00 = gmx_mm_invsqrt_ps(rsq00);
349 rinv10 = gmx_mm_invsqrt_ps(rsq10);
350 rinv20 = gmx_mm_invsqrt_ps(rsq20);
352 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
353 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
354 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
356 /* Load parameters for j particles */
357 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
358 charge+jnrC+0,charge+jnrD+0);
360 fjx0 = _mm_setzero_ps();
361 fjy0 = _mm_setzero_ps();
362 fjz0 = _mm_setzero_ps();
364 /**************************
365 * CALCULATE INTERACTIONS *
366 **************************/
368 /* Compute parameters for interactions between i and j atoms */
369 qq00 = _mm_mul_ps(iq0,jq0);
371 /* REACTION-FIELD ELECTROSTATICS */
372 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
373 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
375 /* Update potential sum for this i atom from the interaction with this j atom. */
376 velec = _mm_andnot_ps(dummy_mask,velec);
377 velecsum = _mm_add_ps(velecsum,velec);
381 fscal = _mm_andnot_ps(dummy_mask,fscal);
383 /* Update vectorial force */
384 fix0 = _mm_macc_ps(dx00,fscal,fix0);
385 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
386 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
388 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
389 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
390 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
392 /**************************
393 * CALCULATE INTERACTIONS *
394 **************************/
396 /* Compute parameters for interactions between i and j atoms */
397 qq10 = _mm_mul_ps(iq1,jq0);
399 /* REACTION-FIELD ELECTROSTATICS */
400 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
401 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
403 /* Update potential sum for this i atom from the interaction with this j atom. */
404 velec = _mm_andnot_ps(dummy_mask,velec);
405 velecsum = _mm_add_ps(velecsum,velec);
409 fscal = _mm_andnot_ps(dummy_mask,fscal);
411 /* Update vectorial force */
412 fix1 = _mm_macc_ps(dx10,fscal,fix1);
413 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
414 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
416 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
417 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
418 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
420 /**************************
421 * CALCULATE INTERACTIONS *
422 **************************/
424 /* Compute parameters for interactions between i and j atoms */
425 qq20 = _mm_mul_ps(iq2,jq0);
427 /* REACTION-FIELD ELECTROSTATICS */
428 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
429 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
431 /* Update potential sum for this i atom from the interaction with this j atom. */
432 velec = _mm_andnot_ps(dummy_mask,velec);
433 velecsum = _mm_add_ps(velecsum,velec);
437 fscal = _mm_andnot_ps(dummy_mask,fscal);
439 /* Update vectorial force */
440 fix2 = _mm_macc_ps(dx20,fscal,fix2);
441 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
442 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
444 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
445 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
446 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
448 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
449 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
450 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
451 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
453 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
455 /* Inner loop uses 105 flops */
458 /* End of innermost loop */
460 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
461 f+i_coord_offset,fshift+i_shift_offset);
464 /* Update potential energies */
465 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
467 /* Increment number of inner iterations */
468 inneriter += j_index_end - j_index_start;
470 /* Outer loop uses 19 flops */
473 /* Increment number of outer iterations */
476 /* Update outer/inner flops */
478 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*105);
481 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomW3P1_F_avx_128_fma_single
482 * Electrostatics interaction: ReactionField
483 * VdW interaction: None
484 * Geometry: Water3-Particle
485 * Calculate force/pot: Force
488 nb_kernel_ElecRF_VdwNone_GeomW3P1_F_avx_128_fma_single
489 (t_nblist * gmx_restrict nlist,
490 rvec * gmx_restrict xx,
491 rvec * gmx_restrict ff,
492 t_forcerec * gmx_restrict fr,
493 t_mdatoms * gmx_restrict mdatoms,
494 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
495 t_nrnb * gmx_restrict nrnb)
497 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
498 * just 0 for non-waters.
499 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
500 * jnr indices corresponding to data put in the four positions in the SIMD register.
502 int i_shift_offset,i_coord_offset,outeriter,inneriter;
503 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
504 int jnrA,jnrB,jnrC,jnrD;
505 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
506 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
507 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
509 real *shiftvec,*fshift,*x,*f;
510 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
512 __m128 fscal,rcutoff,rcutoff2,jidxall;
514 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
516 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
518 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
519 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
520 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
521 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
522 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
523 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
524 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
526 __m128 dummy_mask,cutoff_mask;
527 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
528 __m128 one = _mm_set1_ps(1.0);
529 __m128 two = _mm_set1_ps(2.0);
535 jindex = nlist->jindex;
537 shiftidx = nlist->shift;
539 shiftvec = fr->shift_vec[0];
540 fshift = fr->fshift[0];
541 facel = _mm_set1_ps(fr->epsfac);
542 charge = mdatoms->chargeA;
543 krf = _mm_set1_ps(fr->ic->k_rf);
544 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
545 crf = _mm_set1_ps(fr->ic->c_rf);
547 /* Setup water-specific parameters */
548 inr = nlist->iinr[0];
549 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
550 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
551 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
553 /* Avoid stupid compiler warnings */
554 jnrA = jnrB = jnrC = jnrD = 0;
563 for(iidx=0;iidx<4*DIM;iidx++)
568 /* Start outer loop over neighborlists */
569 for(iidx=0; iidx<nri; iidx++)
571 /* Load shift vector for this list */
572 i_shift_offset = DIM*shiftidx[iidx];
574 /* Load limits for loop over neighbors */
575 j_index_start = jindex[iidx];
576 j_index_end = jindex[iidx+1];
578 /* Get outer coordinate index */
580 i_coord_offset = DIM*inr;
582 /* Load i particle coords and add shift vector */
583 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
584 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
586 fix0 = _mm_setzero_ps();
587 fiy0 = _mm_setzero_ps();
588 fiz0 = _mm_setzero_ps();
589 fix1 = _mm_setzero_ps();
590 fiy1 = _mm_setzero_ps();
591 fiz1 = _mm_setzero_ps();
592 fix2 = _mm_setzero_ps();
593 fiy2 = _mm_setzero_ps();
594 fiz2 = _mm_setzero_ps();
596 /* Start inner kernel loop */
597 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
600 /* Get j neighbor index, and coordinate index */
605 j_coord_offsetA = DIM*jnrA;
606 j_coord_offsetB = DIM*jnrB;
607 j_coord_offsetC = DIM*jnrC;
608 j_coord_offsetD = DIM*jnrD;
610 /* load j atom coordinates */
611 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
612 x+j_coord_offsetC,x+j_coord_offsetD,
615 /* Calculate displacement vector */
616 dx00 = _mm_sub_ps(ix0,jx0);
617 dy00 = _mm_sub_ps(iy0,jy0);
618 dz00 = _mm_sub_ps(iz0,jz0);
619 dx10 = _mm_sub_ps(ix1,jx0);
620 dy10 = _mm_sub_ps(iy1,jy0);
621 dz10 = _mm_sub_ps(iz1,jz0);
622 dx20 = _mm_sub_ps(ix2,jx0);
623 dy20 = _mm_sub_ps(iy2,jy0);
624 dz20 = _mm_sub_ps(iz2,jz0);
626 /* Calculate squared distance and things based on it */
627 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
628 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
629 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
631 rinv00 = gmx_mm_invsqrt_ps(rsq00);
632 rinv10 = gmx_mm_invsqrt_ps(rsq10);
633 rinv20 = gmx_mm_invsqrt_ps(rsq20);
635 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
636 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
637 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
639 /* Load parameters for j particles */
640 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
641 charge+jnrC+0,charge+jnrD+0);
643 fjx0 = _mm_setzero_ps();
644 fjy0 = _mm_setzero_ps();
645 fjz0 = _mm_setzero_ps();
647 /**************************
648 * CALCULATE INTERACTIONS *
649 **************************/
651 /* Compute parameters for interactions between i and j atoms */
652 qq00 = _mm_mul_ps(iq0,jq0);
654 /* REACTION-FIELD ELECTROSTATICS */
655 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
659 /* Update vectorial force */
660 fix0 = _mm_macc_ps(dx00,fscal,fix0);
661 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
662 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
664 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
665 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
666 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
668 /**************************
669 * CALCULATE INTERACTIONS *
670 **************************/
672 /* Compute parameters for interactions between i and j atoms */
673 qq10 = _mm_mul_ps(iq1,jq0);
675 /* REACTION-FIELD ELECTROSTATICS */
676 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
680 /* Update vectorial force */
681 fix1 = _mm_macc_ps(dx10,fscal,fix1);
682 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
683 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
685 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
686 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
687 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
689 /**************************
690 * CALCULATE INTERACTIONS *
691 **************************/
693 /* Compute parameters for interactions between i and j atoms */
694 qq20 = _mm_mul_ps(iq2,jq0);
696 /* REACTION-FIELD ELECTROSTATICS */
697 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
701 /* Update vectorial force */
702 fix2 = _mm_macc_ps(dx20,fscal,fix2);
703 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
704 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
706 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
707 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
708 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
710 fjptrA = f+j_coord_offsetA;
711 fjptrB = f+j_coord_offsetB;
712 fjptrC = f+j_coord_offsetC;
713 fjptrD = f+j_coord_offsetD;
715 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
717 /* Inner loop uses 90 flops */
723 /* Get j neighbor index, and coordinate index */
724 jnrlistA = jjnr[jidx];
725 jnrlistB = jjnr[jidx+1];
726 jnrlistC = jjnr[jidx+2];
727 jnrlistD = jjnr[jidx+3];
728 /* Sign of each element will be negative for non-real atoms.
729 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
730 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
732 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
733 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
734 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
735 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
736 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
737 j_coord_offsetA = DIM*jnrA;
738 j_coord_offsetB = DIM*jnrB;
739 j_coord_offsetC = DIM*jnrC;
740 j_coord_offsetD = DIM*jnrD;
742 /* load j atom coordinates */
743 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
744 x+j_coord_offsetC,x+j_coord_offsetD,
747 /* Calculate displacement vector */
748 dx00 = _mm_sub_ps(ix0,jx0);
749 dy00 = _mm_sub_ps(iy0,jy0);
750 dz00 = _mm_sub_ps(iz0,jz0);
751 dx10 = _mm_sub_ps(ix1,jx0);
752 dy10 = _mm_sub_ps(iy1,jy0);
753 dz10 = _mm_sub_ps(iz1,jz0);
754 dx20 = _mm_sub_ps(ix2,jx0);
755 dy20 = _mm_sub_ps(iy2,jy0);
756 dz20 = _mm_sub_ps(iz2,jz0);
758 /* Calculate squared distance and things based on it */
759 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
760 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
761 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
763 rinv00 = gmx_mm_invsqrt_ps(rsq00);
764 rinv10 = gmx_mm_invsqrt_ps(rsq10);
765 rinv20 = gmx_mm_invsqrt_ps(rsq20);
767 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
768 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
769 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
771 /* Load parameters for j particles */
772 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
773 charge+jnrC+0,charge+jnrD+0);
775 fjx0 = _mm_setzero_ps();
776 fjy0 = _mm_setzero_ps();
777 fjz0 = _mm_setzero_ps();
779 /**************************
780 * CALCULATE INTERACTIONS *
781 **************************/
783 /* Compute parameters for interactions between i and j atoms */
784 qq00 = _mm_mul_ps(iq0,jq0);
786 /* REACTION-FIELD ELECTROSTATICS */
787 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
791 fscal = _mm_andnot_ps(dummy_mask,fscal);
793 /* Update vectorial force */
794 fix0 = _mm_macc_ps(dx00,fscal,fix0);
795 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
796 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
798 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
799 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
800 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
802 /**************************
803 * CALCULATE INTERACTIONS *
804 **************************/
806 /* Compute parameters for interactions between i and j atoms */
807 qq10 = _mm_mul_ps(iq1,jq0);
809 /* REACTION-FIELD ELECTROSTATICS */
810 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
814 fscal = _mm_andnot_ps(dummy_mask,fscal);
816 /* Update vectorial force */
817 fix1 = _mm_macc_ps(dx10,fscal,fix1);
818 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
819 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
821 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
822 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
823 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
825 /**************************
826 * CALCULATE INTERACTIONS *
827 **************************/
829 /* Compute parameters for interactions between i and j atoms */
830 qq20 = _mm_mul_ps(iq2,jq0);
832 /* REACTION-FIELD ELECTROSTATICS */
833 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
837 fscal = _mm_andnot_ps(dummy_mask,fscal);
839 /* Update vectorial force */
840 fix2 = _mm_macc_ps(dx20,fscal,fix2);
841 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
842 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
844 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
845 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
846 fjz0 = _mm_macc_ps(dz20,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(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
861 f+i_coord_offset,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_W3_F,outeriter*18 + inneriter*90);