Remove all unnecessary HAVE_CONFIG_H
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRF_VdwLJ_GeomW3P1_avx_128_fma_double.c
blob9313483e79d901b736de4eddf6aabe13df8c3944
1 /*
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_double kernel generator.
38 #include "config.h"
40 #include <math.h>
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
47 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
51 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW3P1_VF_avx_128_fma_double
52 * Electrostatics interaction: ReactionField
53 * VdW interaction: LennardJones
54 * Geometry: Water3-Particle
55 * Calculate force/pot: PotentialAndForce
57 void
58 nb_kernel_ElecRF_VdwLJ_GeomW3P1_VF_avx_128_fma_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
75 int j_coord_offsetA,j_coord_offsetB;
76 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
77 real rcutoff_scalar;
78 real *shiftvec,*fshift,*x,*f;
79 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80 int vdwioffset0;
81 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82 int vdwioffset1;
83 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
84 int vdwioffset2;
85 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86 int vdwjidx0A,vdwjidx0B;
87 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
88 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
89 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
90 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
91 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
92 real *charge;
93 int nvdwtype;
94 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
95 int *vdwtype;
96 real *vdwparam;
97 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
98 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
99 __m128d dummy_mask,cutoff_mask;
100 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
101 __m128d one = _mm_set1_pd(1.0);
102 __m128d two = _mm_set1_pd(2.0);
103 x = xx[0];
104 f = ff[0];
106 nri = nlist->nri;
107 iinr = nlist->iinr;
108 jindex = nlist->jindex;
109 jjnr = nlist->jjnr;
110 shiftidx = nlist->shift;
111 gid = nlist->gid;
112 shiftvec = fr->shift_vec[0];
113 fshift = fr->fshift[0];
114 facel = _mm_set1_pd(fr->epsfac);
115 charge = mdatoms->chargeA;
116 krf = _mm_set1_pd(fr->ic->k_rf);
117 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
118 crf = _mm_set1_pd(fr->ic->c_rf);
119 nvdwtype = fr->ntype;
120 vdwparam = fr->nbfp;
121 vdwtype = mdatoms->typeA;
123 /* Setup water-specific parameters */
124 inr = nlist->iinr[0];
125 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
126 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
127 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
128 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
130 /* Avoid stupid compiler warnings */
131 jnrA = jnrB = 0;
132 j_coord_offsetA = 0;
133 j_coord_offsetB = 0;
135 outeriter = 0;
136 inneriter = 0;
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 */
149 inr = iinr[iidx];
150 i_coord_offset = DIM*inr;
152 /* Load i particle coords and add shift vector */
153 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
154 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
156 fix0 = _mm_setzero_pd();
157 fiy0 = _mm_setzero_pd();
158 fiz0 = _mm_setzero_pd();
159 fix1 = _mm_setzero_pd();
160 fiy1 = _mm_setzero_pd();
161 fiz1 = _mm_setzero_pd();
162 fix2 = _mm_setzero_pd();
163 fiy2 = _mm_setzero_pd();
164 fiz2 = _mm_setzero_pd();
166 /* Reset potential sums */
167 velecsum = _mm_setzero_pd();
168 vvdwsum = _mm_setzero_pd();
170 /* Start inner kernel loop */
171 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
174 /* Get j neighbor index, and coordinate index */
175 jnrA = jjnr[jidx];
176 jnrB = jjnr[jidx+1];
177 j_coord_offsetA = DIM*jnrA;
178 j_coord_offsetB = DIM*jnrB;
180 /* load j atom coordinates */
181 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
182 &jx0,&jy0,&jz0);
184 /* Calculate displacement vector */
185 dx00 = _mm_sub_pd(ix0,jx0);
186 dy00 = _mm_sub_pd(iy0,jy0);
187 dz00 = _mm_sub_pd(iz0,jz0);
188 dx10 = _mm_sub_pd(ix1,jx0);
189 dy10 = _mm_sub_pd(iy1,jy0);
190 dz10 = _mm_sub_pd(iz1,jz0);
191 dx20 = _mm_sub_pd(ix2,jx0);
192 dy20 = _mm_sub_pd(iy2,jy0);
193 dz20 = _mm_sub_pd(iz2,jz0);
195 /* Calculate squared distance and things based on it */
196 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
197 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
198 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
200 rinv00 = gmx_mm_invsqrt_pd(rsq00);
201 rinv10 = gmx_mm_invsqrt_pd(rsq10);
202 rinv20 = gmx_mm_invsqrt_pd(rsq20);
204 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
205 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
206 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
208 /* Load parameters for j particles */
209 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
210 vdwjidx0A = 2*vdwtype[jnrA+0];
211 vdwjidx0B = 2*vdwtype[jnrB+0];
213 fjx0 = _mm_setzero_pd();
214 fjy0 = _mm_setzero_pd();
215 fjz0 = _mm_setzero_pd();
217 /**************************
218 * CALCULATE INTERACTIONS *
219 **************************/
221 /* Compute parameters for interactions between i and j atoms */
222 qq00 = _mm_mul_pd(iq0,jq0);
223 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
224 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
226 /* REACTION-FIELD ELECTROSTATICS */
227 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
228 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
230 /* LENNARD-JONES DISPERSION/REPULSION */
232 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
233 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
234 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
235 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
236 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
238 /* Update potential sum for this i atom from the interaction with this j atom. */
239 velecsum = _mm_add_pd(velecsum,velec);
240 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
242 fscal = _mm_add_pd(felec,fvdw);
244 /* Update vectorial force */
245 fix0 = _mm_macc_pd(dx00,fscal,fix0);
246 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
247 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
249 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
250 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
251 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
253 /**************************
254 * CALCULATE INTERACTIONS *
255 **************************/
257 /* Compute parameters for interactions between i and j atoms */
258 qq10 = _mm_mul_pd(iq1,jq0);
260 /* REACTION-FIELD ELECTROSTATICS */
261 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
262 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
264 /* Update potential sum for this i atom from the interaction with this j atom. */
265 velecsum = _mm_add_pd(velecsum,velec);
267 fscal = felec;
269 /* Update vectorial force */
270 fix1 = _mm_macc_pd(dx10,fscal,fix1);
271 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
272 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
274 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
275 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
276 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
278 /**************************
279 * CALCULATE INTERACTIONS *
280 **************************/
282 /* Compute parameters for interactions between i and j atoms */
283 qq20 = _mm_mul_pd(iq2,jq0);
285 /* REACTION-FIELD ELECTROSTATICS */
286 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
287 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
289 /* Update potential sum for this i atom from the interaction with this j atom. */
290 velecsum = _mm_add_pd(velecsum,velec);
292 fscal = felec;
294 /* Update vectorial force */
295 fix2 = _mm_macc_pd(dx20,fscal,fix2);
296 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
297 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
299 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
300 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
301 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
303 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
305 /* Inner loop uses 120 flops */
308 if(jidx<j_index_end)
311 jnrA = jjnr[jidx];
312 j_coord_offsetA = DIM*jnrA;
314 /* load j atom coordinates */
315 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
316 &jx0,&jy0,&jz0);
318 /* Calculate displacement vector */
319 dx00 = _mm_sub_pd(ix0,jx0);
320 dy00 = _mm_sub_pd(iy0,jy0);
321 dz00 = _mm_sub_pd(iz0,jz0);
322 dx10 = _mm_sub_pd(ix1,jx0);
323 dy10 = _mm_sub_pd(iy1,jy0);
324 dz10 = _mm_sub_pd(iz1,jz0);
325 dx20 = _mm_sub_pd(ix2,jx0);
326 dy20 = _mm_sub_pd(iy2,jy0);
327 dz20 = _mm_sub_pd(iz2,jz0);
329 /* Calculate squared distance and things based on it */
330 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
331 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
332 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
334 rinv00 = gmx_mm_invsqrt_pd(rsq00);
335 rinv10 = gmx_mm_invsqrt_pd(rsq10);
336 rinv20 = gmx_mm_invsqrt_pd(rsq20);
338 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
339 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
340 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
342 /* Load parameters for j particles */
343 jq0 = _mm_load_sd(charge+jnrA+0);
344 vdwjidx0A = 2*vdwtype[jnrA+0];
346 fjx0 = _mm_setzero_pd();
347 fjy0 = _mm_setzero_pd();
348 fjz0 = _mm_setzero_pd();
350 /**************************
351 * CALCULATE INTERACTIONS *
352 **************************/
354 /* Compute parameters for interactions between i and j atoms */
355 qq00 = _mm_mul_pd(iq0,jq0);
356 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
358 /* REACTION-FIELD ELECTROSTATICS */
359 velec = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
360 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
362 /* LENNARD-JONES DISPERSION/REPULSION */
364 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
365 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
366 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
367 vvdw = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
368 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
370 /* Update potential sum for this i atom from the interaction with this j atom. */
371 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
372 velecsum = _mm_add_pd(velecsum,velec);
373 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
374 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
376 fscal = _mm_add_pd(felec,fvdw);
378 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
380 /* Update vectorial force */
381 fix0 = _mm_macc_pd(dx00,fscal,fix0);
382 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
383 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
385 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
386 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
387 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
389 /**************************
390 * CALCULATE INTERACTIONS *
391 **************************/
393 /* Compute parameters for interactions between i and j atoms */
394 qq10 = _mm_mul_pd(iq1,jq0);
396 /* REACTION-FIELD ELECTROSTATICS */
397 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
398 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
400 /* Update potential sum for this i atom from the interaction with this j atom. */
401 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
402 velecsum = _mm_add_pd(velecsum,velec);
404 fscal = felec;
406 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
408 /* Update vectorial force */
409 fix1 = _mm_macc_pd(dx10,fscal,fix1);
410 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
411 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
413 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
414 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
415 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
417 /**************************
418 * CALCULATE INTERACTIONS *
419 **************************/
421 /* Compute parameters for interactions between i and j atoms */
422 qq20 = _mm_mul_pd(iq2,jq0);
424 /* REACTION-FIELD ELECTROSTATICS */
425 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
426 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
428 /* Update potential sum for this i atom from the interaction with this j atom. */
429 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
430 velecsum = _mm_add_pd(velecsum,velec);
432 fscal = felec;
434 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
436 /* Update vectorial force */
437 fix2 = _mm_macc_pd(dx20,fscal,fix2);
438 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
439 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
441 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
442 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
443 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
445 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
447 /* Inner loop uses 120 flops */
450 /* End of innermost loop */
452 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
453 f+i_coord_offset,fshift+i_shift_offset);
455 ggid = gid[iidx];
456 /* Update potential energies */
457 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
458 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
460 /* Increment number of inner iterations */
461 inneriter += j_index_end - j_index_start;
463 /* Outer loop uses 20 flops */
466 /* Increment number of outer iterations */
467 outeriter += nri;
469 /* Update outer/inner flops */
471 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*120);
474 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_double
475 * Electrostatics interaction: ReactionField
476 * VdW interaction: LennardJones
477 * Geometry: Water3-Particle
478 * Calculate force/pot: Force
480 void
481 nb_kernel_ElecRF_VdwLJ_GeomW3P1_F_avx_128_fma_double
482 (t_nblist * gmx_restrict nlist,
483 rvec * gmx_restrict xx,
484 rvec * gmx_restrict ff,
485 t_forcerec * gmx_restrict fr,
486 t_mdatoms * gmx_restrict mdatoms,
487 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
488 t_nrnb * gmx_restrict nrnb)
490 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
491 * just 0 for non-waters.
492 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
493 * jnr indices corresponding to data put in the four positions in the SIMD register.
495 int i_shift_offset,i_coord_offset,outeriter,inneriter;
496 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
497 int jnrA,jnrB;
498 int j_coord_offsetA,j_coord_offsetB;
499 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
500 real rcutoff_scalar;
501 real *shiftvec,*fshift,*x,*f;
502 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
503 int vdwioffset0;
504 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
505 int vdwioffset1;
506 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
507 int vdwioffset2;
508 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
509 int vdwjidx0A,vdwjidx0B;
510 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
511 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
512 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
513 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
514 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
515 real *charge;
516 int nvdwtype;
517 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
518 int *vdwtype;
519 real *vdwparam;
520 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
521 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
522 __m128d dummy_mask,cutoff_mask;
523 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
524 __m128d one = _mm_set1_pd(1.0);
525 __m128d two = _mm_set1_pd(2.0);
526 x = xx[0];
527 f = ff[0];
529 nri = nlist->nri;
530 iinr = nlist->iinr;
531 jindex = nlist->jindex;
532 jjnr = nlist->jjnr;
533 shiftidx = nlist->shift;
534 gid = nlist->gid;
535 shiftvec = fr->shift_vec[0];
536 fshift = fr->fshift[0];
537 facel = _mm_set1_pd(fr->epsfac);
538 charge = mdatoms->chargeA;
539 krf = _mm_set1_pd(fr->ic->k_rf);
540 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
541 crf = _mm_set1_pd(fr->ic->c_rf);
542 nvdwtype = fr->ntype;
543 vdwparam = fr->nbfp;
544 vdwtype = mdatoms->typeA;
546 /* Setup water-specific parameters */
547 inr = nlist->iinr[0];
548 iq0 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
549 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
550 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
551 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
553 /* Avoid stupid compiler warnings */
554 jnrA = jnrB = 0;
555 j_coord_offsetA = 0;
556 j_coord_offsetB = 0;
558 outeriter = 0;
559 inneriter = 0;
561 /* Start outer loop over neighborlists */
562 for(iidx=0; iidx<nri; iidx++)
564 /* Load shift vector for this list */
565 i_shift_offset = DIM*shiftidx[iidx];
567 /* Load limits for loop over neighbors */
568 j_index_start = jindex[iidx];
569 j_index_end = jindex[iidx+1];
571 /* Get outer coordinate index */
572 inr = iinr[iidx];
573 i_coord_offset = DIM*inr;
575 /* Load i particle coords and add shift vector */
576 gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
577 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
579 fix0 = _mm_setzero_pd();
580 fiy0 = _mm_setzero_pd();
581 fiz0 = _mm_setzero_pd();
582 fix1 = _mm_setzero_pd();
583 fiy1 = _mm_setzero_pd();
584 fiz1 = _mm_setzero_pd();
585 fix2 = _mm_setzero_pd();
586 fiy2 = _mm_setzero_pd();
587 fiz2 = _mm_setzero_pd();
589 /* Start inner kernel loop */
590 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
593 /* Get j neighbor index, and coordinate index */
594 jnrA = jjnr[jidx];
595 jnrB = jjnr[jidx+1];
596 j_coord_offsetA = DIM*jnrA;
597 j_coord_offsetB = DIM*jnrB;
599 /* load j atom coordinates */
600 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
601 &jx0,&jy0,&jz0);
603 /* Calculate displacement vector */
604 dx00 = _mm_sub_pd(ix0,jx0);
605 dy00 = _mm_sub_pd(iy0,jy0);
606 dz00 = _mm_sub_pd(iz0,jz0);
607 dx10 = _mm_sub_pd(ix1,jx0);
608 dy10 = _mm_sub_pd(iy1,jy0);
609 dz10 = _mm_sub_pd(iz1,jz0);
610 dx20 = _mm_sub_pd(ix2,jx0);
611 dy20 = _mm_sub_pd(iy2,jy0);
612 dz20 = _mm_sub_pd(iz2,jz0);
614 /* Calculate squared distance and things based on it */
615 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
616 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
617 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
619 rinv00 = gmx_mm_invsqrt_pd(rsq00);
620 rinv10 = gmx_mm_invsqrt_pd(rsq10);
621 rinv20 = gmx_mm_invsqrt_pd(rsq20);
623 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
624 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
625 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
627 /* Load parameters for j particles */
628 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
629 vdwjidx0A = 2*vdwtype[jnrA+0];
630 vdwjidx0B = 2*vdwtype[jnrB+0];
632 fjx0 = _mm_setzero_pd();
633 fjy0 = _mm_setzero_pd();
634 fjz0 = _mm_setzero_pd();
636 /**************************
637 * CALCULATE INTERACTIONS *
638 **************************/
640 /* Compute parameters for interactions between i and j atoms */
641 qq00 = _mm_mul_pd(iq0,jq0);
642 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
643 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
645 /* REACTION-FIELD ELECTROSTATICS */
646 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
648 /* LENNARD-JONES DISPERSION/REPULSION */
650 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
651 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
653 fscal = _mm_add_pd(felec,fvdw);
655 /* Update vectorial force */
656 fix0 = _mm_macc_pd(dx00,fscal,fix0);
657 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
658 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
660 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
661 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
662 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
664 /**************************
665 * CALCULATE INTERACTIONS *
666 **************************/
668 /* Compute parameters for interactions between i and j atoms */
669 qq10 = _mm_mul_pd(iq1,jq0);
671 /* REACTION-FIELD ELECTROSTATICS */
672 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
674 fscal = felec;
676 /* Update vectorial force */
677 fix1 = _mm_macc_pd(dx10,fscal,fix1);
678 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
679 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
681 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
682 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
683 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
685 /**************************
686 * CALCULATE INTERACTIONS *
687 **************************/
689 /* Compute parameters for interactions between i and j atoms */
690 qq20 = _mm_mul_pd(iq2,jq0);
692 /* REACTION-FIELD ELECTROSTATICS */
693 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
695 fscal = felec;
697 /* Update vectorial force */
698 fix2 = _mm_macc_pd(dx20,fscal,fix2);
699 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
700 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
702 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
703 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
704 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
706 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
708 /* Inner loop uses 100 flops */
711 if(jidx<j_index_end)
714 jnrA = jjnr[jidx];
715 j_coord_offsetA = DIM*jnrA;
717 /* load j atom coordinates */
718 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
719 &jx0,&jy0,&jz0);
721 /* Calculate displacement vector */
722 dx00 = _mm_sub_pd(ix0,jx0);
723 dy00 = _mm_sub_pd(iy0,jy0);
724 dz00 = _mm_sub_pd(iz0,jz0);
725 dx10 = _mm_sub_pd(ix1,jx0);
726 dy10 = _mm_sub_pd(iy1,jy0);
727 dz10 = _mm_sub_pd(iz1,jz0);
728 dx20 = _mm_sub_pd(ix2,jx0);
729 dy20 = _mm_sub_pd(iy2,jy0);
730 dz20 = _mm_sub_pd(iz2,jz0);
732 /* Calculate squared distance and things based on it */
733 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
734 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
735 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
737 rinv00 = gmx_mm_invsqrt_pd(rsq00);
738 rinv10 = gmx_mm_invsqrt_pd(rsq10);
739 rinv20 = gmx_mm_invsqrt_pd(rsq20);
741 rinvsq00 = _mm_mul_pd(rinv00,rinv00);
742 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
743 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
745 /* Load parameters for j particles */
746 jq0 = _mm_load_sd(charge+jnrA+0);
747 vdwjidx0A = 2*vdwtype[jnrA+0];
749 fjx0 = _mm_setzero_pd();
750 fjy0 = _mm_setzero_pd();
751 fjz0 = _mm_setzero_pd();
753 /**************************
754 * CALCULATE INTERACTIONS *
755 **************************/
757 /* Compute parameters for interactions between i and j atoms */
758 qq00 = _mm_mul_pd(iq0,jq0);
759 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
761 /* REACTION-FIELD ELECTROSTATICS */
762 felec = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
764 /* LENNARD-JONES DISPERSION/REPULSION */
766 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
767 fvdw = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
769 fscal = _mm_add_pd(felec,fvdw);
771 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
773 /* Update vectorial force */
774 fix0 = _mm_macc_pd(dx00,fscal,fix0);
775 fiy0 = _mm_macc_pd(dy00,fscal,fiy0);
776 fiz0 = _mm_macc_pd(dz00,fscal,fiz0);
778 fjx0 = _mm_macc_pd(dx00,fscal,fjx0);
779 fjy0 = _mm_macc_pd(dy00,fscal,fjy0);
780 fjz0 = _mm_macc_pd(dz00,fscal,fjz0);
782 /**************************
783 * CALCULATE INTERACTIONS *
784 **************************/
786 /* Compute parameters for interactions between i and j atoms */
787 qq10 = _mm_mul_pd(iq1,jq0);
789 /* REACTION-FIELD ELECTROSTATICS */
790 felec = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
792 fscal = felec;
794 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
796 /* Update vectorial force */
797 fix1 = _mm_macc_pd(dx10,fscal,fix1);
798 fiy1 = _mm_macc_pd(dy10,fscal,fiy1);
799 fiz1 = _mm_macc_pd(dz10,fscal,fiz1);
801 fjx0 = _mm_macc_pd(dx10,fscal,fjx0);
802 fjy0 = _mm_macc_pd(dy10,fscal,fjy0);
803 fjz0 = _mm_macc_pd(dz10,fscal,fjz0);
805 /**************************
806 * CALCULATE INTERACTIONS *
807 **************************/
809 /* Compute parameters for interactions between i and j atoms */
810 qq20 = _mm_mul_pd(iq2,jq0);
812 /* REACTION-FIELD ELECTROSTATICS */
813 felec = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
815 fscal = felec;
817 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
819 /* Update vectorial force */
820 fix2 = _mm_macc_pd(dx20,fscal,fix2);
821 fiy2 = _mm_macc_pd(dy20,fscal,fiy2);
822 fiz2 = _mm_macc_pd(dz20,fscal,fiz2);
824 fjx0 = _mm_macc_pd(dx20,fscal,fjx0);
825 fjy0 = _mm_macc_pd(dy20,fscal,fjy0);
826 fjz0 = _mm_macc_pd(dz20,fscal,fjz0);
828 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
830 /* Inner loop uses 100 flops */
833 /* End of innermost loop */
835 gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
836 f+i_coord_offset,fshift+i_shift_offset);
838 /* Increment number of inner iterations */
839 inneriter += j_index_end - j_index_start;
841 /* Outer loop uses 18 flops */
844 /* Increment number of outer iterations */
845 outeriter += nri;
847 /* Update outer/inner flops */
849 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*100);