Remove nb-parameters from t_forcerec
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRF_VdwNone_GeomW4P1_avx_128_fma_single.c
blob26a26c3efc821c7562b6827ef74b4facbfca5fe3
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014,2015,2017, 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.
38 #include "gmxpre.h"
40 #include "config.h"
42 #include <math.h>
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
47 #include "kernelutil_x86_avx_128_fma_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomW4P1_VF_avx_128_fma_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: None
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
56 void
57 nb_kernel_ElecRF_VdwNone_GeomW4P1_VF_avx_128_fma_single
58 (t_nblist * gmx_restrict nlist,
59 rvec * gmx_restrict xx,
60 rvec * gmx_restrict ff,
61 struct t_forcerec * gmx_restrict fr,
62 t_mdatoms * gmx_restrict mdatoms,
63 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64 t_nrnb * gmx_restrict nrnb)
66 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
67 * just 0 for non-waters.
68 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
69 * jnr indices corresponding to data put in the four positions in the SIMD register.
71 int i_shift_offset,i_coord_offset,outeriter,inneriter;
72 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73 int jnrA,jnrB,jnrC,jnrD;
74 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real rcutoff_scalar;
78 real *shiftvec,*fshift,*x,*f;
79 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
80 real scratch[4*DIM];
81 __m128 fscal,rcutoff,rcutoff2,jidxall;
82 int vdwioffset1;
83 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
84 int vdwioffset2;
85 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86 int vdwioffset3;
87 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
91 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
92 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
93 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
94 real *charge;
95 __m128 dummy_mask,cutoff_mask;
96 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
97 __m128 one = _mm_set1_ps(1.0);
98 __m128 two = _mm_set1_ps(2.0);
99 x = xx[0];
100 f = ff[0];
102 nri = nlist->nri;
103 iinr = nlist->iinr;
104 jindex = nlist->jindex;
105 jjnr = nlist->jjnr;
106 shiftidx = nlist->shift;
107 gid = nlist->gid;
108 shiftvec = fr->shift_vec[0];
109 fshift = fr->fshift[0];
110 facel = _mm_set1_ps(fr->ic->epsfac);
111 charge = mdatoms->chargeA;
112 krf = _mm_set1_ps(fr->ic->k_rf);
113 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
114 crf = _mm_set1_ps(fr->ic->c_rf);
116 /* Setup water-specific parameters */
117 inr = nlist->iinr[0];
118 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
119 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
120 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
122 /* Avoid stupid compiler warnings */
123 jnrA = jnrB = jnrC = jnrD = 0;
124 j_coord_offsetA = 0;
125 j_coord_offsetB = 0;
126 j_coord_offsetC = 0;
127 j_coord_offsetD = 0;
129 outeriter = 0;
130 inneriter = 0;
132 for(iidx=0;iidx<4*DIM;iidx++)
134 scratch[iidx] = 0.0;
137 /* Start outer loop over neighborlists */
138 for(iidx=0; iidx<nri; iidx++)
140 /* Load shift vector for this list */
141 i_shift_offset = DIM*shiftidx[iidx];
143 /* Load limits for loop over neighbors */
144 j_index_start = jindex[iidx];
145 j_index_end = jindex[iidx+1];
147 /* Get outer coordinate index */
148 inr = iinr[iidx];
149 i_coord_offset = DIM*inr;
151 /* Load i particle coords and add shift vector */
152 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
153 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
155 fix1 = _mm_setzero_ps();
156 fiy1 = _mm_setzero_ps();
157 fiz1 = _mm_setzero_ps();
158 fix2 = _mm_setzero_ps();
159 fiy2 = _mm_setzero_ps();
160 fiz2 = _mm_setzero_ps();
161 fix3 = _mm_setzero_ps();
162 fiy3 = _mm_setzero_ps();
163 fiz3 = _mm_setzero_ps();
165 /* Reset potential sums */
166 velecsum = _mm_setzero_ps();
168 /* Start inner kernel loop */
169 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
172 /* Get j neighbor index, and coordinate index */
173 jnrA = jjnr[jidx];
174 jnrB = jjnr[jidx+1];
175 jnrC = jjnr[jidx+2];
176 jnrD = jjnr[jidx+3];
177 j_coord_offsetA = DIM*jnrA;
178 j_coord_offsetB = DIM*jnrB;
179 j_coord_offsetC = DIM*jnrC;
180 j_coord_offsetD = DIM*jnrD;
182 /* load j atom coordinates */
183 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
184 x+j_coord_offsetC,x+j_coord_offsetD,
185 &jx0,&jy0,&jz0);
187 /* Calculate displacement vector */
188 dx10 = _mm_sub_ps(ix1,jx0);
189 dy10 = _mm_sub_ps(iy1,jy0);
190 dz10 = _mm_sub_ps(iz1,jz0);
191 dx20 = _mm_sub_ps(ix2,jx0);
192 dy20 = _mm_sub_ps(iy2,jy0);
193 dz20 = _mm_sub_ps(iz2,jz0);
194 dx30 = _mm_sub_ps(ix3,jx0);
195 dy30 = _mm_sub_ps(iy3,jy0);
196 dz30 = _mm_sub_ps(iz3,jz0);
198 /* Calculate squared distance and things based on it */
199 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
200 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
201 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
203 rinv10 = avx128fma_invsqrt_f(rsq10);
204 rinv20 = avx128fma_invsqrt_f(rsq20);
205 rinv30 = avx128fma_invsqrt_f(rsq30);
207 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
208 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
209 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
211 /* Load parameters for j particles */
212 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
213 charge+jnrC+0,charge+jnrD+0);
215 fjx0 = _mm_setzero_ps();
216 fjy0 = _mm_setzero_ps();
217 fjz0 = _mm_setzero_ps();
219 /**************************
220 * CALCULATE INTERACTIONS *
221 **************************/
223 /* Compute parameters for interactions between i and j atoms */
224 qq10 = _mm_mul_ps(iq1,jq0);
226 /* REACTION-FIELD ELECTROSTATICS */
227 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
228 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
230 /* Update potential sum for this i atom from the interaction with this j atom. */
231 velecsum = _mm_add_ps(velecsum,velec);
233 fscal = felec;
235 /* Update vectorial force */
236 fix1 = _mm_macc_ps(dx10,fscal,fix1);
237 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
238 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
240 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
241 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
242 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
244 /**************************
245 * CALCULATE INTERACTIONS *
246 **************************/
248 /* Compute parameters for interactions between i and j atoms */
249 qq20 = _mm_mul_ps(iq2,jq0);
251 /* REACTION-FIELD ELECTROSTATICS */
252 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
253 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
255 /* Update potential sum for this i atom from the interaction with this j atom. */
256 velecsum = _mm_add_ps(velecsum,velec);
258 fscal = felec;
260 /* Update vectorial force */
261 fix2 = _mm_macc_ps(dx20,fscal,fix2);
262 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
263 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
265 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
266 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
267 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
269 /**************************
270 * CALCULATE INTERACTIONS *
271 **************************/
273 /* Compute parameters for interactions between i and j atoms */
274 qq30 = _mm_mul_ps(iq3,jq0);
276 /* REACTION-FIELD ELECTROSTATICS */
277 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
278 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
280 /* Update potential sum for this i atom from the interaction with this j atom. */
281 velecsum = _mm_add_ps(velecsum,velec);
283 fscal = felec;
285 /* Update vectorial force */
286 fix3 = _mm_macc_ps(dx30,fscal,fix3);
287 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
288 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
290 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
291 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
292 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
294 fjptrA = f+j_coord_offsetA;
295 fjptrB = f+j_coord_offsetB;
296 fjptrC = f+j_coord_offsetC;
297 fjptrD = f+j_coord_offsetD;
299 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
301 /* Inner loop uses 105 flops */
304 if(jidx<j_index_end)
307 /* Get j neighbor index, and coordinate index */
308 jnrlistA = jjnr[jidx];
309 jnrlistB = jjnr[jidx+1];
310 jnrlistC = jjnr[jidx+2];
311 jnrlistD = jjnr[jidx+3];
312 /* Sign of each element will be negative for non-real atoms.
313 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
314 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
316 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
317 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
318 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
319 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
320 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
321 j_coord_offsetA = DIM*jnrA;
322 j_coord_offsetB = DIM*jnrB;
323 j_coord_offsetC = DIM*jnrC;
324 j_coord_offsetD = DIM*jnrD;
326 /* load j atom coordinates */
327 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
328 x+j_coord_offsetC,x+j_coord_offsetD,
329 &jx0,&jy0,&jz0);
331 /* Calculate displacement vector */
332 dx10 = _mm_sub_ps(ix1,jx0);
333 dy10 = _mm_sub_ps(iy1,jy0);
334 dz10 = _mm_sub_ps(iz1,jz0);
335 dx20 = _mm_sub_ps(ix2,jx0);
336 dy20 = _mm_sub_ps(iy2,jy0);
337 dz20 = _mm_sub_ps(iz2,jz0);
338 dx30 = _mm_sub_ps(ix3,jx0);
339 dy30 = _mm_sub_ps(iy3,jy0);
340 dz30 = _mm_sub_ps(iz3,jz0);
342 /* Calculate squared distance and things based on it */
343 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
344 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
345 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
347 rinv10 = avx128fma_invsqrt_f(rsq10);
348 rinv20 = avx128fma_invsqrt_f(rsq20);
349 rinv30 = avx128fma_invsqrt_f(rsq30);
351 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
352 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
353 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
355 /* Load parameters for j particles */
356 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
357 charge+jnrC+0,charge+jnrD+0);
359 fjx0 = _mm_setzero_ps();
360 fjy0 = _mm_setzero_ps();
361 fjz0 = _mm_setzero_ps();
363 /**************************
364 * CALCULATE INTERACTIONS *
365 **************************/
367 /* Compute parameters for interactions between i and j atoms */
368 qq10 = _mm_mul_ps(iq1,jq0);
370 /* REACTION-FIELD ELECTROSTATICS */
371 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
372 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
374 /* Update potential sum for this i atom from the interaction with this j atom. */
375 velec = _mm_andnot_ps(dummy_mask,velec);
376 velecsum = _mm_add_ps(velecsum,velec);
378 fscal = felec;
380 fscal = _mm_andnot_ps(dummy_mask,fscal);
382 /* Update vectorial force */
383 fix1 = _mm_macc_ps(dx10,fscal,fix1);
384 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
385 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
387 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
388 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
389 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
391 /**************************
392 * CALCULATE INTERACTIONS *
393 **************************/
395 /* Compute parameters for interactions between i and j atoms */
396 qq20 = _mm_mul_ps(iq2,jq0);
398 /* REACTION-FIELD ELECTROSTATICS */
399 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
400 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
402 /* Update potential sum for this i atom from the interaction with this j atom. */
403 velec = _mm_andnot_ps(dummy_mask,velec);
404 velecsum = _mm_add_ps(velecsum,velec);
406 fscal = felec;
408 fscal = _mm_andnot_ps(dummy_mask,fscal);
410 /* Update vectorial force */
411 fix2 = _mm_macc_ps(dx20,fscal,fix2);
412 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
413 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
415 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
416 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
417 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
419 /**************************
420 * CALCULATE INTERACTIONS *
421 **************************/
423 /* Compute parameters for interactions between i and j atoms */
424 qq30 = _mm_mul_ps(iq3,jq0);
426 /* REACTION-FIELD ELECTROSTATICS */
427 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
428 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
430 /* Update potential sum for this i atom from the interaction with this j atom. */
431 velec = _mm_andnot_ps(dummy_mask,velec);
432 velecsum = _mm_add_ps(velecsum,velec);
434 fscal = felec;
436 fscal = _mm_andnot_ps(dummy_mask,fscal);
438 /* Update vectorial force */
439 fix3 = _mm_macc_ps(dx30,fscal,fix3);
440 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
441 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
443 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
444 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
445 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
447 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
448 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
449 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
450 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
452 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
454 /* Inner loop uses 105 flops */
457 /* End of innermost loop */
459 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
460 f+i_coord_offset+DIM,fshift+i_shift_offset);
462 ggid = gid[iidx];
463 /* Update potential energies */
464 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
466 /* Increment number of inner iterations */
467 inneriter += j_index_end - j_index_start;
469 /* Outer loop uses 19 flops */
472 /* Increment number of outer iterations */
473 outeriter += nri;
475 /* Update outer/inner flops */
477 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*105);
480 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwNone_GeomW4P1_F_avx_128_fma_single
481 * Electrostatics interaction: ReactionField
482 * VdW interaction: None
483 * Geometry: Water4-Particle
484 * Calculate force/pot: Force
486 void
487 nb_kernel_ElecRF_VdwNone_GeomW4P1_F_avx_128_fma_single
488 (t_nblist * gmx_restrict nlist,
489 rvec * gmx_restrict xx,
490 rvec * gmx_restrict ff,
491 struct t_forcerec * gmx_restrict fr,
492 t_mdatoms * gmx_restrict mdatoms,
493 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
494 t_nrnb * gmx_restrict nrnb)
496 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
497 * just 0 for non-waters.
498 * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
499 * jnr indices corresponding to data put in the four positions in the SIMD register.
501 int i_shift_offset,i_coord_offset,outeriter,inneriter;
502 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
503 int jnrA,jnrB,jnrC,jnrD;
504 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
505 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
506 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
507 real rcutoff_scalar;
508 real *shiftvec,*fshift,*x,*f;
509 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
510 real scratch[4*DIM];
511 __m128 fscal,rcutoff,rcutoff2,jidxall;
512 int vdwioffset1;
513 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
514 int vdwioffset2;
515 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
516 int vdwioffset3;
517 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
518 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
519 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
520 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
521 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
522 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
523 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
524 real *charge;
525 __m128 dummy_mask,cutoff_mask;
526 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
527 __m128 one = _mm_set1_ps(1.0);
528 __m128 two = _mm_set1_ps(2.0);
529 x = xx[0];
530 f = ff[0];
532 nri = nlist->nri;
533 iinr = nlist->iinr;
534 jindex = nlist->jindex;
535 jjnr = nlist->jjnr;
536 shiftidx = nlist->shift;
537 gid = nlist->gid;
538 shiftvec = fr->shift_vec[0];
539 fshift = fr->fshift[0];
540 facel = _mm_set1_ps(fr->ic->epsfac);
541 charge = mdatoms->chargeA;
542 krf = _mm_set1_ps(fr->ic->k_rf);
543 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
544 crf = _mm_set1_ps(fr->ic->c_rf);
546 /* Setup water-specific parameters */
547 inr = nlist->iinr[0];
548 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
549 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
550 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
552 /* Avoid stupid compiler warnings */
553 jnrA = jnrB = jnrC = jnrD = 0;
554 j_coord_offsetA = 0;
555 j_coord_offsetB = 0;
556 j_coord_offsetC = 0;
557 j_coord_offsetD = 0;
559 outeriter = 0;
560 inneriter = 0;
562 for(iidx=0;iidx<4*DIM;iidx++)
564 scratch[iidx] = 0.0;
567 /* Start outer loop over neighborlists */
568 for(iidx=0; iidx<nri; iidx++)
570 /* Load shift vector for this list */
571 i_shift_offset = DIM*shiftidx[iidx];
573 /* Load limits for loop over neighbors */
574 j_index_start = jindex[iidx];
575 j_index_end = jindex[iidx+1];
577 /* Get outer coordinate index */
578 inr = iinr[iidx];
579 i_coord_offset = DIM*inr;
581 /* Load i particle coords and add shift vector */
582 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
583 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
585 fix1 = _mm_setzero_ps();
586 fiy1 = _mm_setzero_ps();
587 fiz1 = _mm_setzero_ps();
588 fix2 = _mm_setzero_ps();
589 fiy2 = _mm_setzero_ps();
590 fiz2 = _mm_setzero_ps();
591 fix3 = _mm_setzero_ps();
592 fiy3 = _mm_setzero_ps();
593 fiz3 = _mm_setzero_ps();
595 /* Start inner kernel loop */
596 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
599 /* Get j neighbor index, and coordinate index */
600 jnrA = jjnr[jidx];
601 jnrB = jjnr[jidx+1];
602 jnrC = jjnr[jidx+2];
603 jnrD = jjnr[jidx+3];
604 j_coord_offsetA = DIM*jnrA;
605 j_coord_offsetB = DIM*jnrB;
606 j_coord_offsetC = DIM*jnrC;
607 j_coord_offsetD = DIM*jnrD;
609 /* load j atom coordinates */
610 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
611 x+j_coord_offsetC,x+j_coord_offsetD,
612 &jx0,&jy0,&jz0);
614 /* Calculate displacement vector */
615 dx10 = _mm_sub_ps(ix1,jx0);
616 dy10 = _mm_sub_ps(iy1,jy0);
617 dz10 = _mm_sub_ps(iz1,jz0);
618 dx20 = _mm_sub_ps(ix2,jx0);
619 dy20 = _mm_sub_ps(iy2,jy0);
620 dz20 = _mm_sub_ps(iz2,jz0);
621 dx30 = _mm_sub_ps(ix3,jx0);
622 dy30 = _mm_sub_ps(iy3,jy0);
623 dz30 = _mm_sub_ps(iz3,jz0);
625 /* Calculate squared distance and things based on it */
626 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
627 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
628 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
630 rinv10 = avx128fma_invsqrt_f(rsq10);
631 rinv20 = avx128fma_invsqrt_f(rsq20);
632 rinv30 = avx128fma_invsqrt_f(rsq30);
634 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
635 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
636 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
638 /* Load parameters for j particles */
639 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
640 charge+jnrC+0,charge+jnrD+0);
642 fjx0 = _mm_setzero_ps();
643 fjy0 = _mm_setzero_ps();
644 fjz0 = _mm_setzero_ps();
646 /**************************
647 * CALCULATE INTERACTIONS *
648 **************************/
650 /* Compute parameters for interactions between i and j atoms */
651 qq10 = _mm_mul_ps(iq1,jq0);
653 /* REACTION-FIELD ELECTROSTATICS */
654 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
656 fscal = felec;
658 /* Update vectorial force */
659 fix1 = _mm_macc_ps(dx10,fscal,fix1);
660 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
661 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
663 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
664 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
665 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
667 /**************************
668 * CALCULATE INTERACTIONS *
669 **************************/
671 /* Compute parameters for interactions between i and j atoms */
672 qq20 = _mm_mul_ps(iq2,jq0);
674 /* REACTION-FIELD ELECTROSTATICS */
675 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
677 fscal = felec;
679 /* Update vectorial force */
680 fix2 = _mm_macc_ps(dx20,fscal,fix2);
681 fiy2 = _mm_macc_ps(dy20,fscal,fiy2);
682 fiz2 = _mm_macc_ps(dz20,fscal,fiz2);
684 fjx0 = _mm_macc_ps(dx20,fscal,fjx0);
685 fjy0 = _mm_macc_ps(dy20,fscal,fjy0);
686 fjz0 = _mm_macc_ps(dz20,fscal,fjz0);
688 /**************************
689 * CALCULATE INTERACTIONS *
690 **************************/
692 /* Compute parameters for interactions between i and j atoms */
693 qq30 = _mm_mul_ps(iq3,jq0);
695 /* REACTION-FIELD ELECTROSTATICS */
696 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
698 fscal = felec;
700 /* Update vectorial force */
701 fix3 = _mm_macc_ps(dx30,fscal,fix3);
702 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
703 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
705 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
706 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
707 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
709 fjptrA = f+j_coord_offsetA;
710 fjptrB = f+j_coord_offsetB;
711 fjptrC = f+j_coord_offsetC;
712 fjptrD = f+j_coord_offsetD;
714 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
716 /* Inner loop uses 90 flops */
719 if(jidx<j_index_end)
722 /* Get j neighbor index, and coordinate index */
723 jnrlistA = jjnr[jidx];
724 jnrlistB = jjnr[jidx+1];
725 jnrlistC = jjnr[jidx+2];
726 jnrlistD = jjnr[jidx+3];
727 /* Sign of each element will be negative for non-real atoms.
728 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
729 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
731 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
732 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
733 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
734 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
735 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
736 j_coord_offsetA = DIM*jnrA;
737 j_coord_offsetB = DIM*jnrB;
738 j_coord_offsetC = DIM*jnrC;
739 j_coord_offsetD = DIM*jnrD;
741 /* load j atom coordinates */
742 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
743 x+j_coord_offsetC,x+j_coord_offsetD,
744 &jx0,&jy0,&jz0);
746 /* Calculate displacement vector */
747 dx10 = _mm_sub_ps(ix1,jx0);
748 dy10 = _mm_sub_ps(iy1,jy0);
749 dz10 = _mm_sub_ps(iz1,jz0);
750 dx20 = _mm_sub_ps(ix2,jx0);
751 dy20 = _mm_sub_ps(iy2,jy0);
752 dz20 = _mm_sub_ps(iz2,jz0);
753 dx30 = _mm_sub_ps(ix3,jx0);
754 dy30 = _mm_sub_ps(iy3,jy0);
755 dz30 = _mm_sub_ps(iz3,jz0);
757 /* Calculate squared distance and things based on it */
758 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
759 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
760 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
762 rinv10 = avx128fma_invsqrt_f(rsq10);
763 rinv20 = avx128fma_invsqrt_f(rsq20);
764 rinv30 = avx128fma_invsqrt_f(rsq30);
766 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
767 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
768 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
770 /* Load parameters for j particles */
771 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
772 charge+jnrC+0,charge+jnrD+0);
774 fjx0 = _mm_setzero_ps();
775 fjy0 = _mm_setzero_ps();
776 fjz0 = _mm_setzero_ps();
778 /**************************
779 * CALCULATE INTERACTIONS *
780 **************************/
782 /* Compute parameters for interactions between i and j atoms */
783 qq10 = _mm_mul_ps(iq1,jq0);
785 /* REACTION-FIELD ELECTROSTATICS */
786 felec = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
788 fscal = felec;
790 fscal = _mm_andnot_ps(dummy_mask,fscal);
792 /* Update vectorial force */
793 fix1 = _mm_macc_ps(dx10,fscal,fix1);
794 fiy1 = _mm_macc_ps(dy10,fscal,fiy1);
795 fiz1 = _mm_macc_ps(dz10,fscal,fiz1);
797 fjx0 = _mm_macc_ps(dx10,fscal,fjx0);
798 fjy0 = _mm_macc_ps(dy10,fscal,fjy0);
799 fjz0 = _mm_macc_ps(dz10,fscal,fjz0);
801 /**************************
802 * CALCULATE INTERACTIONS *
803 **************************/
805 /* Compute parameters for interactions between i and j atoms */
806 qq20 = _mm_mul_ps(iq2,jq0);
808 /* REACTION-FIELD ELECTROSTATICS */
809 felec = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
811 fscal = felec;
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 /* REACTION-FIELD ELECTROSTATICS */
832 felec = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
834 fscal = felec;
836 fscal = _mm_andnot_ps(dummy_mask,fscal);
838 /* Update vectorial force */
839 fix3 = _mm_macc_ps(dx30,fscal,fix3);
840 fiy3 = _mm_macc_ps(dy30,fscal,fiy3);
841 fiz3 = _mm_macc_ps(dz30,fscal,fiz3);
843 fjx0 = _mm_macc_ps(dx30,fscal,fjx0);
844 fjy0 = _mm_macc_ps(dy30,fscal,fjy0);
845 fjz0 = _mm_macc_ps(dz30,fscal,fjz0);
847 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
848 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
849 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
850 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
852 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
854 /* Inner loop uses 90 flops */
857 /* End of innermost loop */
859 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
860 f+i_coord_offset+DIM,fshift+i_shift_offset);
862 /* Increment number of inner iterations */
863 inneriter += j_index_end - j_index_start;
865 /* Outer loop uses 18 flops */
868 /* Increment number of outer iterations */
869 outeriter += nri;
871 /* Update outer/inner flops */
873 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*90);