2 * Note: this file was generated by the Gromacs avx_128_fma_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_avx_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_single
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: None
40 * Geometry: Water3-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_single
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
65 real *shiftvec,*fshift,*x,*f;
66 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
68 __m128 fscal,rcutoff,rcutoff2,jidxall;
70 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
76 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
77 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
78 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
79 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
80 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
82 __m128 dummy_mask,cutoff_mask;
83 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
84 __m128 one = _mm_set1_ps(1.0);
85 __m128 two = _mm_set1_ps(2.0);
91 jindex = nlist->jindex;
93 shiftidx = nlist->shift;
95 shiftvec = fr->shift_vec[0];
96 fshift = fr->fshift[0];
97 facel = _mm_set1_ps(fr->epsfac);
98 charge = mdatoms->chargeA;
99 krf = _mm_set1_ps(fr->ic->k_rf);
100 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
101 crf = _mm_set1_ps(fr->ic->c_rf);
103 /* Setup water-specific parameters */
104 inr = nlist->iinr[0];
105 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
106 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
107 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
109 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
110 rcutoff_scalar = fr->rcoulomb;
111 rcutoff = _mm_set1_ps(rcutoff_scalar);
112 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
114 /* Avoid stupid compiler warnings */
115 jnrA = jnrB = jnrC = jnrD = 0;
124 for(iidx=0;iidx<4*DIM;iidx++)
129 /* Start outer loop over neighborlists */
130 for(iidx=0; iidx<nri; iidx++)
132 /* Load shift vector for this list */
133 i_shift_offset = DIM*shiftidx[iidx];
135 /* Load limits for loop over neighbors */
136 j_index_start = jindex[iidx];
137 j_index_end = jindex[iidx+1];
139 /* Get outer coordinate index */
141 i_coord_offset = DIM*inr;
143 /* Load i particle coords and add shift vector */
144 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
145 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
147 fix0 = _mm_setzero_ps();
148 fiy0 = _mm_setzero_ps();
149 fiz0 = _mm_setzero_ps();
150 fix1 = _mm_setzero_ps();
151 fiy1 = _mm_setzero_ps();
152 fiz1 = _mm_setzero_ps();
153 fix2 = _mm_setzero_ps();
154 fiy2 = _mm_setzero_ps();
155 fiz2 = _mm_setzero_ps();
157 /* Reset potential sums */
158 velecsum = _mm_setzero_ps();
160 /* Start inner kernel loop */
161 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
164 /* Get j neighbor index, and coordinate index */
169 j_coord_offsetA = DIM*jnrA;
170 j_coord_offsetB = DIM*jnrB;
171 j_coord_offsetC = DIM*jnrC;
172 j_coord_offsetD = DIM*jnrD;
174 /* load j atom coordinates */
175 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
176 x+j_coord_offsetC,x+j_coord_offsetD,
179 /* Calculate displacement vector */
180 dx00 = _mm_sub_ps(ix0,jx0);
181 dy00 = _mm_sub_ps(iy0,jy0);
182 dz00 = _mm_sub_ps(iz0,jz0);
183 dx10 = _mm_sub_ps(ix1,jx0);
184 dy10 = _mm_sub_ps(iy1,jy0);
185 dz10 = _mm_sub_ps(iz1,jz0);
186 dx20 = _mm_sub_ps(ix2,jx0);
187 dy20 = _mm_sub_ps(iy2,jy0);
188 dz20 = _mm_sub_ps(iz2,jz0);
190 /* Calculate squared distance and things based on it */
191 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
192 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
193 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
195 rinv00 = gmx_mm_invsqrt_ps(rsq00);
196 rinv10 = gmx_mm_invsqrt_ps(rsq10);
197 rinv20 = gmx_mm_invsqrt_ps(rsq20);
199 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
200 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
201 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
203 /* Load parameters for j particles */
204 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
205 charge+jnrC+0,charge+jnrD+0);
207 fjx0 = _mm_setzero_ps();
208 fjy0 = _mm_setzero_ps();
209 fjz0 = _mm_setzero_ps();
211 /**************************
212 * CALCULATE INTERACTIONS *
213 **************************/
215 if (gmx_mm_any_lt(rsq00,rcutoff2))
218 /* Compute parameters for interactions between i and j atoms */
219 qq00 = _mm_mul_ps(iq0,jq0);
221 /* REACTION-FIELD ELECTROSTATICS */
222 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
223 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
225 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
227 /* Update potential sum for this i atom from the interaction with this j atom. */
228 velec = _mm_and_ps(velec,cutoff_mask);
229 velecsum = _mm_add_ps(velecsum,velec);
233 fscal = _mm_and_ps(fscal,cutoff_mask);
235 /* Update vectorial force */
236 fix0 = _mm_macc_ps(dx00,fscal,fix0);
237 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
238 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
240 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
241 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
242 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
246 /**************************
247 * CALCULATE INTERACTIONS *
248 **************************/
250 if (gmx_mm_any_lt(rsq10,rcutoff2))
253 /* Compute parameters for interactions between i and j atoms */
254 qq10 = _mm_mul_ps(iq1,jq0);
256 /* REACTION-FIELD ELECTROSTATICS */
257 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
258 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
260 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
262 /* Update potential sum for this i atom from the interaction with this j atom. */
263 velec = _mm_and_ps(velec,cutoff_mask);
264 velecsum = _mm_add_ps(velecsum,velec);
268 fscal = _mm_and_ps(fscal,cutoff_mask);
270 /* Update vectorial force */
271 fix1 = _mm_macc_ps(dx10,fscal,fix1);
272 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
273 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
275 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
276 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
277 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
281 /**************************
282 * CALCULATE INTERACTIONS *
283 **************************/
285 if (gmx_mm_any_lt(rsq20,rcutoff2))
288 /* Compute parameters for interactions between i and j atoms */
289 qq20 = _mm_mul_ps(iq2,jq0);
291 /* REACTION-FIELD ELECTROSTATICS */
292 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
293 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
295 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
297 /* Update potential sum for this i atom from the interaction with this j atom. */
298 velec = _mm_and_ps(velec,cutoff_mask);
299 velecsum = _mm_add_ps(velecsum,velec);
303 fscal = _mm_and_ps(fscal,cutoff_mask);
305 /* Update vectorial force */
306 fix2 = _mm_macc_ps(dx20,fscal,fix2);
307 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
308 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
310 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
311 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
312 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
316 fjptrA = f+j_coord_offsetA;
317 fjptrB = f+j_coord_offsetB;
318 fjptrC = f+j_coord_offsetC;
319 fjptrD = f+j_coord_offsetD;
321 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
323 /* Inner loop uses 117 flops */
329 /* Get j neighbor index, and coordinate index */
330 jnrlistA = jjnr[jidx];
331 jnrlistB = jjnr[jidx+1];
332 jnrlistC = jjnr[jidx+2];
333 jnrlistD = jjnr[jidx+3];
334 /* Sign of each element will be negative for non-real atoms.
335 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
336 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
338 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
339 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
340 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
341 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
342 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
343 j_coord_offsetA = DIM*jnrA;
344 j_coord_offsetB = DIM*jnrB;
345 j_coord_offsetC = DIM*jnrC;
346 j_coord_offsetD = DIM*jnrD;
348 /* load j atom coordinates */
349 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
350 x+j_coord_offsetC,x+j_coord_offsetD,
353 /* Calculate displacement vector */
354 dx00 = _mm_sub_ps(ix0,jx0);
355 dy00 = _mm_sub_ps(iy0,jy0);
356 dz00 = _mm_sub_ps(iz0,jz0);
357 dx10 = _mm_sub_ps(ix1,jx0);
358 dy10 = _mm_sub_ps(iy1,jy0);
359 dz10 = _mm_sub_ps(iz1,jz0);
360 dx20 = _mm_sub_ps(ix2,jx0);
361 dy20 = _mm_sub_ps(iy2,jy0);
362 dz20 = _mm_sub_ps(iz2,jz0);
364 /* Calculate squared distance and things based on it */
365 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
366 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
367 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
369 rinv00 = gmx_mm_invsqrt_ps(rsq00);
370 rinv10 = gmx_mm_invsqrt_ps(rsq10);
371 rinv20 = gmx_mm_invsqrt_ps(rsq20);
373 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
374 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
375 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
377 /* Load parameters for j particles */
378 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
379 charge+jnrC+0,charge+jnrD+0);
381 fjx0 = _mm_setzero_ps();
382 fjy0 = _mm_setzero_ps();
383 fjz0 = _mm_setzero_ps();
385 /**************************
386 * CALCULATE INTERACTIONS *
387 **************************/
389 if (gmx_mm_any_lt(rsq00,rcutoff2))
392 /* Compute parameters for interactions between i and j atoms */
393 qq00 = _mm_mul_ps(iq0,jq0);
395 /* REACTION-FIELD ELECTROSTATICS */
396 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
397 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
399 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
401 /* Update potential sum for this i atom from the interaction with this j atom. */
402 velec = _mm_and_ps(velec,cutoff_mask);
403 velec = _mm_andnot_ps(dummy_mask,velec);
404 velecsum = _mm_add_ps(velecsum,velec);
408 fscal = _mm_and_ps(fscal,cutoff_mask);
410 fscal = _mm_andnot_ps(dummy_mask,fscal);
412 /* Update vectorial force */
413 fix0 = _mm_macc_ps(dx00,fscal,fix0);
414 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
415 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
417 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
418 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
419 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
423 /**************************
424 * CALCULATE INTERACTIONS *
425 **************************/
427 if (gmx_mm_any_lt(rsq10,rcutoff2))
430 /* Compute parameters for interactions between i and j atoms */
431 qq10 = _mm_mul_ps(iq1,jq0);
433 /* REACTION-FIELD ELECTROSTATICS */
434 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
435 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
437 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
439 /* Update potential sum for this i atom from the interaction with this j atom. */
440 velec = _mm_and_ps(velec,cutoff_mask);
441 velec = _mm_andnot_ps(dummy_mask,velec);
442 velecsum = _mm_add_ps(velecsum,velec);
446 fscal = _mm_and_ps(fscal,cutoff_mask);
448 fscal = _mm_andnot_ps(dummy_mask,fscal);
450 /* Update vectorial force */
451 fix1 = _mm_macc_ps(dx10,fscal,fix1);
452 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
453 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
455 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
456 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
457 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
461 /**************************
462 * CALCULATE INTERACTIONS *
463 **************************/
465 if (gmx_mm_any_lt(rsq20,rcutoff2))
468 /* Compute parameters for interactions between i and j atoms */
469 qq20 = _mm_mul_ps(iq2,jq0);
471 /* REACTION-FIELD ELECTROSTATICS */
472 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
473 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
475 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
477 /* Update potential sum for this i atom from the interaction with this j atom. */
478 velec = _mm_and_ps(velec,cutoff_mask);
479 velec = _mm_andnot_ps(dummy_mask,velec);
480 velecsum = _mm_add_ps(velecsum,velec);
484 fscal = _mm_and_ps(fscal,cutoff_mask);
486 fscal = _mm_andnot_ps(dummy_mask,fscal);
488 /* Update vectorial force */
489 fix2 = _mm_macc_ps(dx20,fscal,fix2);
490 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
491 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
493 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
494 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
495 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
499 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
500 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
501 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
502 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
504 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
506 /* Inner loop uses 117 flops */
509 /* End of innermost loop */
511 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
512 f+i_coord_offset,fshift+i_shift_offset);
515 /* Update potential energies */
516 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
518 /* Increment number of inner iterations */
519 inneriter += j_index_end - j_index_start;
521 /* Outer loop uses 19 flops */
524 /* Increment number of outer iterations */
527 /* Update outer/inner flops */
529 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*117);
532 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
533 * Electrostatics interaction: ReactionField
534 * VdW interaction: None
535 * Geometry: Water3-Particle
536 * Calculate force/pot: Force
539 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
540 (t_nblist * gmx_restrict nlist,
541 rvec * gmx_restrict xx,
542 rvec * gmx_restrict ff,
543 t_forcerec * gmx_restrict fr,
544 t_mdatoms * gmx_restrict mdatoms,
545 nb_kernel_data_t * gmx_restrict kernel_data,
546 t_nrnb * gmx_restrict nrnb)
548 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
549 * just 0 for non-waters.
550 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
551 * jnr indices corresponding to data put in the four positions in the SIMD register.
553 int i_shift_offset,i_coord_offset,outeriter,inneriter;
554 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
555 int jnrA,jnrB,jnrC,jnrD;
556 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
557 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
558 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
560 real *shiftvec,*fshift,*x,*f;
561 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
563 __m128 fscal,rcutoff,rcutoff2,jidxall;
565 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
567 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
569 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
570 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
571 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
572 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
573 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
574 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
575 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
577 __m128 dummy_mask,cutoff_mask;
578 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
579 __m128 one = _mm_set1_ps(1.0);
580 __m128 two = _mm_set1_ps(2.0);
586 jindex = nlist->jindex;
588 shiftidx = nlist->shift;
590 shiftvec = fr->shift_vec[0];
591 fshift = fr->fshift[0];
592 facel = _mm_set1_ps(fr->epsfac);
593 charge = mdatoms->chargeA;
594 krf = _mm_set1_ps(fr->ic->k_rf);
595 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
596 crf = _mm_set1_ps(fr->ic->c_rf);
598 /* Setup water-specific parameters */
599 inr = nlist->iinr[0];
600 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
601 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
602 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
604 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
605 rcutoff_scalar = fr->rcoulomb;
606 rcutoff = _mm_set1_ps(rcutoff_scalar);
607 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
609 /* Avoid stupid compiler warnings */
610 jnrA = jnrB = jnrC = jnrD = 0;
619 for(iidx=0;iidx<4*DIM;iidx++)
624 /* Start outer loop over neighborlists */
625 for(iidx=0; iidx<nri; iidx++)
627 /* Load shift vector for this list */
628 i_shift_offset = DIM*shiftidx[iidx];
630 /* Load limits for loop over neighbors */
631 j_index_start = jindex[iidx];
632 j_index_end = jindex[iidx+1];
634 /* Get outer coordinate index */
636 i_coord_offset = DIM*inr;
638 /* Load i particle coords and add shift vector */
639 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
640 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
642 fix0 = _mm_setzero_ps();
643 fiy0 = _mm_setzero_ps();
644 fiz0 = _mm_setzero_ps();
645 fix1 = _mm_setzero_ps();
646 fiy1 = _mm_setzero_ps();
647 fiz1 = _mm_setzero_ps();
648 fix2 = _mm_setzero_ps();
649 fiy2 = _mm_setzero_ps();
650 fiz2 = _mm_setzero_ps();
652 /* Start inner kernel loop */
653 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
656 /* Get j neighbor index, and coordinate index */
661 j_coord_offsetA = DIM*jnrA;
662 j_coord_offsetB = DIM*jnrB;
663 j_coord_offsetC = DIM*jnrC;
664 j_coord_offsetD = DIM*jnrD;
666 /* load j atom coordinates */
667 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
668 x+j_coord_offsetC,x+j_coord_offsetD,
671 /* Calculate displacement vector */
672 dx00 = _mm_sub_ps(ix0,jx0);
673 dy00 = _mm_sub_ps(iy0,jy0);
674 dz00 = _mm_sub_ps(iz0,jz0);
675 dx10 = _mm_sub_ps(ix1,jx0);
676 dy10 = _mm_sub_ps(iy1,jy0);
677 dz10 = _mm_sub_ps(iz1,jz0);
678 dx20 = _mm_sub_ps(ix2,jx0);
679 dy20 = _mm_sub_ps(iy2,jy0);
680 dz20 = _mm_sub_ps(iz2,jz0);
682 /* Calculate squared distance and things based on it */
683 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
684 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
685 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
687 rinv00 = gmx_mm_invsqrt_ps(rsq00);
688 rinv10 = gmx_mm_invsqrt_ps(rsq10);
689 rinv20 = gmx_mm_invsqrt_ps(rsq20);
691 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
692 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
693 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
695 /* Load parameters for j particles */
696 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
697 charge+jnrC+0,charge+jnrD+0);
699 fjx0 = _mm_setzero_ps();
700 fjy0 = _mm_setzero_ps();
701 fjz0 = _mm_setzero_ps();
703 /**************************
704 * CALCULATE INTERACTIONS *
705 **************************/
707 if (gmx_mm_any_lt(rsq00,rcutoff2))
710 /* Compute parameters for interactions between i and j atoms */
711 qq00 = _mm_mul_ps(iq0,jq0);
713 /* REACTION-FIELD ELECTROSTATICS */
714 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
716 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
720 fscal = _mm_and_ps(fscal,cutoff_mask);
722 /* Update vectorial force */
723 fix0 = _mm_macc_ps(dx00,fscal,fix0);
724 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
725 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
727 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
728 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
729 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
733 /**************************
734 * CALCULATE INTERACTIONS *
735 **************************/
737 if (gmx_mm_any_lt(rsq10,rcutoff2))
740 /* Compute parameters for interactions between i and j atoms */
741 qq10 = _mm_mul_ps(iq1,jq0);
743 /* REACTION-FIELD ELECTROSTATICS */
744 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
746 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
750 fscal = _mm_and_ps(fscal,cutoff_mask);
752 /* Update vectorial force */
753 fix1 = _mm_macc_ps(dx10,fscal,fix1);
754 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
755 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
757 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
758 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
759 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
763 /**************************
764 * CALCULATE INTERACTIONS *
765 **************************/
767 if (gmx_mm_any_lt(rsq20,rcutoff2))
770 /* Compute parameters for interactions between i and j atoms */
771 qq20 = _mm_mul_ps(iq2,jq0);
773 /* REACTION-FIELD ELECTROSTATICS */
774 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
776 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
780 fscal = _mm_and_ps(fscal,cutoff_mask);
782 /* Update vectorial force */
783 fix2 = _mm_macc_ps(dx20,fscal,fix2);
784 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
785 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
787 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
788 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
789 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
793 fjptrA = f+j_coord_offsetA;
794 fjptrB = f+j_coord_offsetB;
795 fjptrC = f+j_coord_offsetC;
796 fjptrD = f+j_coord_offsetD;
798 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
800 /* Inner loop uses 99 flops */
806 /* Get j neighbor index, and coordinate index */
807 jnrlistA = jjnr[jidx];
808 jnrlistB = jjnr[jidx+1];
809 jnrlistC = jjnr[jidx+2];
810 jnrlistD = jjnr[jidx+3];
811 /* Sign of each element will be negative for non-real atoms.
812 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
813 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
815 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
816 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
817 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
818 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
819 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
820 j_coord_offsetA = DIM*jnrA;
821 j_coord_offsetB = DIM*jnrB;
822 j_coord_offsetC = DIM*jnrC;
823 j_coord_offsetD = DIM*jnrD;
825 /* load j atom coordinates */
826 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
827 x+j_coord_offsetC,x+j_coord_offsetD,
830 /* Calculate displacement vector */
831 dx00 = _mm_sub_ps(ix0,jx0);
832 dy00 = _mm_sub_ps(iy0,jy0);
833 dz00 = _mm_sub_ps(iz0,jz0);
834 dx10 = _mm_sub_ps(ix1,jx0);
835 dy10 = _mm_sub_ps(iy1,jy0);
836 dz10 = _mm_sub_ps(iz1,jz0);
837 dx20 = _mm_sub_ps(ix2,jx0);
838 dy20 = _mm_sub_ps(iy2,jy0);
839 dz20 = _mm_sub_ps(iz2,jz0);
841 /* Calculate squared distance and things based on it */
842 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
843 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
844 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
846 rinv00 = gmx_mm_invsqrt_ps(rsq00);
847 rinv10 = gmx_mm_invsqrt_ps(rsq10);
848 rinv20 = gmx_mm_invsqrt_ps(rsq20);
850 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
851 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
852 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
854 /* Load parameters for j particles */
855 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
856 charge+jnrC+0,charge+jnrD+0);
858 fjx0 = _mm_setzero_ps();
859 fjy0 = _mm_setzero_ps();
860 fjz0 = _mm_setzero_ps();
862 /**************************
863 * CALCULATE INTERACTIONS *
864 **************************/
866 if (gmx_mm_any_lt(rsq00,rcutoff2))
869 /* Compute parameters for interactions between i and j atoms */
870 qq00 = _mm_mul_ps(iq0,jq0);
872 /* REACTION-FIELD ELECTROSTATICS */
873 felec = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
875 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
879 fscal = _mm_and_ps(fscal,cutoff_mask);
881 fscal = _mm_andnot_ps(dummy_mask,fscal);
883 /* Update vectorial force */
884 fix0 = _mm_macc_ps(dx00,fscal,fix0);
885 fiy0 = _mm_macc_ps(dy00,fscal,fiy0);
886 fiz0 = _mm_macc_ps(dz00,fscal,fiz0);
888 fjx0 = _mm_macc_ps(dx00,fscal,fjx0);
889 fjy0 = _mm_macc_ps(dy00,fscal,fjy0);
890 fjz0 = _mm_macc_ps(dz00,fscal,fjz0);
894 /**************************
895 * CALCULATE INTERACTIONS *
896 **************************/
898 if (gmx_mm_any_lt(rsq10,rcutoff2))
901 /* Compute parameters for interactions between i and j atoms */
902 qq10 = _mm_mul_ps(iq1,jq0);
904 /* REACTION-FIELD ELECTROSTATICS */
905 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
907 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
911 fscal = _mm_and_ps(fscal,cutoff_mask);
913 fscal = _mm_andnot_ps(dummy_mask,fscal);
915 /* Update vectorial force */
916 fix1 = _mm_macc_ps(dx10,fscal,fix1);
917 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
918 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
920 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
921 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
922 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
926 /**************************
927 * CALCULATE INTERACTIONS *
928 **************************/
930 if (gmx_mm_any_lt(rsq20,rcutoff2))
933 /* Compute parameters for interactions between i and j atoms */
934 qq20 = _mm_mul_ps(iq2,jq0);
936 /* REACTION-FIELD ELECTROSTATICS */
937 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
939 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
943 fscal = _mm_and_ps(fscal,cutoff_mask);
945 fscal = _mm_andnot_ps(dummy_mask,fscal);
947 /* Update vectorial force */
948 fix2 = _mm_macc_ps(dx20,fscal,fix2);
949 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
950 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
952 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
953 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
954 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
958 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
959 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
960 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
961 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
963 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
965 /* Inner loop uses 99 flops */
968 /* End of innermost loop */
970 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
971 f+i_coord_offset,fshift+i_shift_offset);
973 /* Increment number of inner iterations */
974 inneriter += j_index_end - j_index_start;
976 /* Outer loop uses 18 flops */
979 /* Increment number of outer iterations */
982 /* Update outer/inner flops */
984 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*99);