Remove nb-parameters from t_forcerec
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_double / nb_kernel_ElecRF_VdwLJ_GeomW4P1_sse2_double.c
blob933a2801e74560f81e8660e2e769bcd67ed1403a
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 sse2_double 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_sse2_double.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW4P1_VF_sse2_double
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: LennardJones
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
56 void
57 nb_kernel_ElecRF_VdwLJ_GeomW4P1_VF_sse2_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
74 int j_coord_offsetA,j_coord_offsetB;
75 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
76 real rcutoff_scalar;
77 real *shiftvec,*fshift,*x,*f;
78 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
79 int vdwioffset0;
80 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81 int vdwioffset1;
82 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
83 int vdwioffset2;
84 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
85 int vdwioffset3;
86 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
87 int vdwjidx0A,vdwjidx0B;
88 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
91 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
92 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
93 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
94 real *charge;
95 int nvdwtype;
96 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97 int *vdwtype;
98 real *vdwparam;
99 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
100 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
101 __m128d dummy_mask,cutoff_mask;
102 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
103 __m128d one = _mm_set1_pd(1.0);
104 __m128d two = _mm_set1_pd(2.0);
105 x = xx[0];
106 f = ff[0];
108 nri = nlist->nri;
109 iinr = nlist->iinr;
110 jindex = nlist->jindex;
111 jjnr = nlist->jjnr;
112 shiftidx = nlist->shift;
113 gid = nlist->gid;
114 shiftvec = fr->shift_vec[0];
115 fshift = fr->fshift[0];
116 facel = _mm_set1_pd(fr->ic->epsfac);
117 charge = mdatoms->chargeA;
118 krf = _mm_set1_pd(fr->ic->k_rf);
119 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
120 crf = _mm_set1_pd(fr->ic->c_rf);
121 nvdwtype = fr->ntype;
122 vdwparam = fr->nbfp;
123 vdwtype = mdatoms->typeA;
125 /* Setup water-specific parameters */
126 inr = nlist->iinr[0];
127 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
128 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
129 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
130 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
132 /* Avoid stupid compiler warnings */
133 jnrA = jnrB = 0;
134 j_coord_offsetA = 0;
135 j_coord_offsetB = 0;
137 outeriter = 0;
138 inneriter = 0;
140 /* Start outer loop over neighborlists */
141 for(iidx=0; iidx<nri; iidx++)
143 /* Load shift vector for this list */
144 i_shift_offset = DIM*shiftidx[iidx];
146 /* Load limits for loop over neighbors */
147 j_index_start = jindex[iidx];
148 j_index_end = jindex[iidx+1];
150 /* Get outer coordinate index */
151 inr = iinr[iidx];
152 i_coord_offset = DIM*inr;
154 /* Load i particle coords and add shift vector */
155 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
156 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
158 fix0 = _mm_setzero_pd();
159 fiy0 = _mm_setzero_pd();
160 fiz0 = _mm_setzero_pd();
161 fix1 = _mm_setzero_pd();
162 fiy1 = _mm_setzero_pd();
163 fiz1 = _mm_setzero_pd();
164 fix2 = _mm_setzero_pd();
165 fiy2 = _mm_setzero_pd();
166 fiz2 = _mm_setzero_pd();
167 fix3 = _mm_setzero_pd();
168 fiy3 = _mm_setzero_pd();
169 fiz3 = _mm_setzero_pd();
171 /* Reset potential sums */
172 velecsum = _mm_setzero_pd();
173 vvdwsum = _mm_setzero_pd();
175 /* Start inner kernel loop */
176 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
179 /* Get j neighbor index, and coordinate index */
180 jnrA = jjnr[jidx];
181 jnrB = jjnr[jidx+1];
182 j_coord_offsetA = DIM*jnrA;
183 j_coord_offsetB = DIM*jnrB;
185 /* load j atom coordinates */
186 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
187 &jx0,&jy0,&jz0);
189 /* Calculate displacement vector */
190 dx00 = _mm_sub_pd(ix0,jx0);
191 dy00 = _mm_sub_pd(iy0,jy0);
192 dz00 = _mm_sub_pd(iz0,jz0);
193 dx10 = _mm_sub_pd(ix1,jx0);
194 dy10 = _mm_sub_pd(iy1,jy0);
195 dz10 = _mm_sub_pd(iz1,jz0);
196 dx20 = _mm_sub_pd(ix2,jx0);
197 dy20 = _mm_sub_pd(iy2,jy0);
198 dz20 = _mm_sub_pd(iz2,jz0);
199 dx30 = _mm_sub_pd(ix3,jx0);
200 dy30 = _mm_sub_pd(iy3,jy0);
201 dz30 = _mm_sub_pd(iz3,jz0);
203 /* Calculate squared distance and things based on it */
204 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
205 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
206 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
207 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
209 rinv10 = sse2_invsqrt_d(rsq10);
210 rinv20 = sse2_invsqrt_d(rsq20);
211 rinv30 = sse2_invsqrt_d(rsq30);
213 rinvsq00 = sse2_inv_d(rsq00);
214 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
215 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
216 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
218 /* Load parameters for j particles */
219 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
220 vdwjidx0A = 2*vdwtype[jnrA+0];
221 vdwjidx0B = 2*vdwtype[jnrB+0];
223 fjx0 = _mm_setzero_pd();
224 fjy0 = _mm_setzero_pd();
225 fjz0 = _mm_setzero_pd();
227 /**************************
228 * CALCULATE INTERACTIONS *
229 **************************/
231 /* Compute parameters for interactions between i and j atoms */
232 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
233 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
235 /* LENNARD-JONES DISPERSION/REPULSION */
237 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
238 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
239 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
240 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
241 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
243 /* Update potential sum for this i atom from the interaction with this j atom. */
244 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
246 fscal = fvdw;
248 /* Calculate temporary vectorial force */
249 tx = _mm_mul_pd(fscal,dx00);
250 ty = _mm_mul_pd(fscal,dy00);
251 tz = _mm_mul_pd(fscal,dz00);
253 /* Update vectorial force */
254 fix0 = _mm_add_pd(fix0,tx);
255 fiy0 = _mm_add_pd(fiy0,ty);
256 fiz0 = _mm_add_pd(fiz0,tz);
258 fjx0 = _mm_add_pd(fjx0,tx);
259 fjy0 = _mm_add_pd(fjy0,ty);
260 fjz0 = _mm_add_pd(fjz0,tz);
262 /**************************
263 * CALCULATE INTERACTIONS *
264 **************************/
266 /* Compute parameters for interactions between i and j atoms */
267 qq10 = _mm_mul_pd(iq1,jq0);
269 /* REACTION-FIELD ELECTROSTATICS */
270 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_add_pd(rinv10,_mm_mul_pd(krf,rsq10)),crf));
271 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
273 /* Update potential sum for this i atom from the interaction with this j atom. */
274 velecsum = _mm_add_pd(velecsum,velec);
276 fscal = felec;
278 /* Calculate temporary vectorial force */
279 tx = _mm_mul_pd(fscal,dx10);
280 ty = _mm_mul_pd(fscal,dy10);
281 tz = _mm_mul_pd(fscal,dz10);
283 /* Update vectorial force */
284 fix1 = _mm_add_pd(fix1,tx);
285 fiy1 = _mm_add_pd(fiy1,ty);
286 fiz1 = _mm_add_pd(fiz1,tz);
288 fjx0 = _mm_add_pd(fjx0,tx);
289 fjy0 = _mm_add_pd(fjy0,ty);
290 fjz0 = _mm_add_pd(fjz0,tz);
292 /**************************
293 * CALCULATE INTERACTIONS *
294 **************************/
296 /* Compute parameters for interactions between i and j atoms */
297 qq20 = _mm_mul_pd(iq2,jq0);
299 /* REACTION-FIELD ELECTROSTATICS */
300 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_add_pd(rinv20,_mm_mul_pd(krf,rsq20)),crf));
301 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
303 /* Update potential sum for this i atom from the interaction with this j atom. */
304 velecsum = _mm_add_pd(velecsum,velec);
306 fscal = felec;
308 /* Calculate temporary vectorial force */
309 tx = _mm_mul_pd(fscal,dx20);
310 ty = _mm_mul_pd(fscal,dy20);
311 tz = _mm_mul_pd(fscal,dz20);
313 /* Update vectorial force */
314 fix2 = _mm_add_pd(fix2,tx);
315 fiy2 = _mm_add_pd(fiy2,ty);
316 fiz2 = _mm_add_pd(fiz2,tz);
318 fjx0 = _mm_add_pd(fjx0,tx);
319 fjy0 = _mm_add_pd(fjy0,ty);
320 fjz0 = _mm_add_pd(fjz0,tz);
322 /**************************
323 * CALCULATE INTERACTIONS *
324 **************************/
326 /* Compute parameters for interactions between i and j atoms */
327 qq30 = _mm_mul_pd(iq3,jq0);
329 /* REACTION-FIELD ELECTROSTATICS */
330 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_add_pd(rinv30,_mm_mul_pd(krf,rsq30)),crf));
331 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
333 /* Update potential sum for this i atom from the interaction with this j atom. */
334 velecsum = _mm_add_pd(velecsum,velec);
336 fscal = felec;
338 /* Calculate temporary vectorial force */
339 tx = _mm_mul_pd(fscal,dx30);
340 ty = _mm_mul_pd(fscal,dy30);
341 tz = _mm_mul_pd(fscal,dz30);
343 /* Update vectorial force */
344 fix3 = _mm_add_pd(fix3,tx);
345 fiy3 = _mm_add_pd(fiy3,ty);
346 fiz3 = _mm_add_pd(fiz3,tz);
348 fjx0 = _mm_add_pd(fjx0,tx);
349 fjy0 = _mm_add_pd(fjy0,ty);
350 fjz0 = _mm_add_pd(fjz0,tz);
352 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
354 /* Inner loop uses 131 flops */
357 if(jidx<j_index_end)
360 jnrA = jjnr[jidx];
361 j_coord_offsetA = DIM*jnrA;
363 /* load j atom coordinates */
364 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
365 &jx0,&jy0,&jz0);
367 /* Calculate displacement vector */
368 dx00 = _mm_sub_pd(ix0,jx0);
369 dy00 = _mm_sub_pd(iy0,jy0);
370 dz00 = _mm_sub_pd(iz0,jz0);
371 dx10 = _mm_sub_pd(ix1,jx0);
372 dy10 = _mm_sub_pd(iy1,jy0);
373 dz10 = _mm_sub_pd(iz1,jz0);
374 dx20 = _mm_sub_pd(ix2,jx0);
375 dy20 = _mm_sub_pd(iy2,jy0);
376 dz20 = _mm_sub_pd(iz2,jz0);
377 dx30 = _mm_sub_pd(ix3,jx0);
378 dy30 = _mm_sub_pd(iy3,jy0);
379 dz30 = _mm_sub_pd(iz3,jz0);
381 /* Calculate squared distance and things based on it */
382 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
383 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
384 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
385 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
387 rinv10 = sse2_invsqrt_d(rsq10);
388 rinv20 = sse2_invsqrt_d(rsq20);
389 rinv30 = sse2_invsqrt_d(rsq30);
391 rinvsq00 = sse2_inv_d(rsq00);
392 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
393 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
394 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
396 /* Load parameters for j particles */
397 jq0 = _mm_load_sd(charge+jnrA+0);
398 vdwjidx0A = 2*vdwtype[jnrA+0];
400 fjx0 = _mm_setzero_pd();
401 fjy0 = _mm_setzero_pd();
402 fjz0 = _mm_setzero_pd();
404 /**************************
405 * CALCULATE INTERACTIONS *
406 **************************/
408 /* Compute parameters for interactions between i and j atoms */
409 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
411 /* LENNARD-JONES DISPERSION/REPULSION */
413 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
414 vvdw6 = _mm_mul_pd(c6_00,rinvsix);
415 vvdw12 = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
416 vvdw = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
417 fvdw = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
419 /* Update potential sum for this i atom from the interaction with this j atom. */
420 vvdw = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
421 vvdwsum = _mm_add_pd(vvdwsum,vvdw);
423 fscal = fvdw;
425 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
427 /* Calculate temporary vectorial force */
428 tx = _mm_mul_pd(fscal,dx00);
429 ty = _mm_mul_pd(fscal,dy00);
430 tz = _mm_mul_pd(fscal,dz00);
432 /* Update vectorial force */
433 fix0 = _mm_add_pd(fix0,tx);
434 fiy0 = _mm_add_pd(fiy0,ty);
435 fiz0 = _mm_add_pd(fiz0,tz);
437 fjx0 = _mm_add_pd(fjx0,tx);
438 fjy0 = _mm_add_pd(fjy0,ty);
439 fjz0 = _mm_add_pd(fjz0,tz);
441 /**************************
442 * CALCULATE INTERACTIONS *
443 **************************/
445 /* Compute parameters for interactions between i and j atoms */
446 qq10 = _mm_mul_pd(iq1,jq0);
448 /* REACTION-FIELD ELECTROSTATICS */
449 velec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_add_pd(rinv10,_mm_mul_pd(krf,rsq10)),crf));
450 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
452 /* Update potential sum for this i atom from the interaction with this j atom. */
453 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
454 velecsum = _mm_add_pd(velecsum,velec);
456 fscal = felec;
458 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
460 /* Calculate temporary vectorial force */
461 tx = _mm_mul_pd(fscal,dx10);
462 ty = _mm_mul_pd(fscal,dy10);
463 tz = _mm_mul_pd(fscal,dz10);
465 /* Update vectorial force */
466 fix1 = _mm_add_pd(fix1,tx);
467 fiy1 = _mm_add_pd(fiy1,ty);
468 fiz1 = _mm_add_pd(fiz1,tz);
470 fjx0 = _mm_add_pd(fjx0,tx);
471 fjy0 = _mm_add_pd(fjy0,ty);
472 fjz0 = _mm_add_pd(fjz0,tz);
474 /**************************
475 * CALCULATE INTERACTIONS *
476 **************************/
478 /* Compute parameters for interactions between i and j atoms */
479 qq20 = _mm_mul_pd(iq2,jq0);
481 /* REACTION-FIELD ELECTROSTATICS */
482 velec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_add_pd(rinv20,_mm_mul_pd(krf,rsq20)),crf));
483 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
485 /* Update potential sum for this i atom from the interaction with this j atom. */
486 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
487 velecsum = _mm_add_pd(velecsum,velec);
489 fscal = felec;
491 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
493 /* Calculate temporary vectorial force */
494 tx = _mm_mul_pd(fscal,dx20);
495 ty = _mm_mul_pd(fscal,dy20);
496 tz = _mm_mul_pd(fscal,dz20);
498 /* Update vectorial force */
499 fix2 = _mm_add_pd(fix2,tx);
500 fiy2 = _mm_add_pd(fiy2,ty);
501 fiz2 = _mm_add_pd(fiz2,tz);
503 fjx0 = _mm_add_pd(fjx0,tx);
504 fjy0 = _mm_add_pd(fjy0,ty);
505 fjz0 = _mm_add_pd(fjz0,tz);
507 /**************************
508 * CALCULATE INTERACTIONS *
509 **************************/
511 /* Compute parameters for interactions between i and j atoms */
512 qq30 = _mm_mul_pd(iq3,jq0);
514 /* REACTION-FIELD ELECTROSTATICS */
515 velec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_add_pd(rinv30,_mm_mul_pd(krf,rsq30)),crf));
516 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
518 /* Update potential sum for this i atom from the interaction with this j atom. */
519 velec = _mm_unpacklo_pd(velec,_mm_setzero_pd());
520 velecsum = _mm_add_pd(velecsum,velec);
522 fscal = felec;
524 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
526 /* Calculate temporary vectorial force */
527 tx = _mm_mul_pd(fscal,dx30);
528 ty = _mm_mul_pd(fscal,dy30);
529 tz = _mm_mul_pd(fscal,dz30);
531 /* Update vectorial force */
532 fix3 = _mm_add_pd(fix3,tx);
533 fiy3 = _mm_add_pd(fiy3,ty);
534 fiz3 = _mm_add_pd(fiz3,tz);
536 fjx0 = _mm_add_pd(fjx0,tx);
537 fjy0 = _mm_add_pd(fjy0,ty);
538 fjz0 = _mm_add_pd(fjz0,tz);
540 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
542 /* Inner loop uses 131 flops */
545 /* End of innermost loop */
547 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
548 f+i_coord_offset,fshift+i_shift_offset);
550 ggid = gid[iidx];
551 /* Update potential energies */
552 gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
553 gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
555 /* Increment number of inner iterations */
556 inneriter += j_index_end - j_index_start;
558 /* Outer loop uses 26 flops */
561 /* Increment number of outer iterations */
562 outeriter += nri;
564 /* Update outer/inner flops */
566 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*131);
569 * Gromacs nonbonded kernel: nb_kernel_ElecRF_VdwLJ_GeomW4P1_F_sse2_double
570 * Electrostatics interaction: ReactionField
571 * VdW interaction: LennardJones
572 * Geometry: Water4-Particle
573 * Calculate force/pot: Force
575 void
576 nb_kernel_ElecRF_VdwLJ_GeomW4P1_F_sse2_double
577 (t_nblist * gmx_restrict nlist,
578 rvec * gmx_restrict xx,
579 rvec * gmx_restrict ff,
580 struct t_forcerec * gmx_restrict fr,
581 t_mdatoms * gmx_restrict mdatoms,
582 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
583 t_nrnb * gmx_restrict nrnb)
585 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
586 * just 0 for non-waters.
587 * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
588 * jnr indices corresponding to data put in the four positions in the SIMD register.
590 int i_shift_offset,i_coord_offset,outeriter,inneriter;
591 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
592 int jnrA,jnrB;
593 int j_coord_offsetA,j_coord_offsetB;
594 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
595 real rcutoff_scalar;
596 real *shiftvec,*fshift,*x,*f;
597 __m128d tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
598 int vdwioffset0;
599 __m128d ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
600 int vdwioffset1;
601 __m128d ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
602 int vdwioffset2;
603 __m128d ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
604 int vdwioffset3;
605 __m128d ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
606 int vdwjidx0A,vdwjidx0B;
607 __m128d jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
608 __m128d dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
609 __m128d dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
610 __m128d dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
611 __m128d dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
612 __m128d velec,felec,velecsum,facel,crf,krf,krf2;
613 real *charge;
614 int nvdwtype;
615 __m128d rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
616 int *vdwtype;
617 real *vdwparam;
618 __m128d one_sixth = _mm_set1_pd(1.0/6.0);
619 __m128d one_twelfth = _mm_set1_pd(1.0/12.0);
620 __m128d dummy_mask,cutoff_mask;
621 __m128d signbit = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
622 __m128d one = _mm_set1_pd(1.0);
623 __m128d two = _mm_set1_pd(2.0);
624 x = xx[0];
625 f = ff[0];
627 nri = nlist->nri;
628 iinr = nlist->iinr;
629 jindex = nlist->jindex;
630 jjnr = nlist->jjnr;
631 shiftidx = nlist->shift;
632 gid = nlist->gid;
633 shiftvec = fr->shift_vec[0];
634 fshift = fr->fshift[0];
635 facel = _mm_set1_pd(fr->ic->epsfac);
636 charge = mdatoms->chargeA;
637 krf = _mm_set1_pd(fr->ic->k_rf);
638 krf2 = _mm_set1_pd(fr->ic->k_rf*2.0);
639 crf = _mm_set1_pd(fr->ic->c_rf);
640 nvdwtype = fr->ntype;
641 vdwparam = fr->nbfp;
642 vdwtype = mdatoms->typeA;
644 /* Setup water-specific parameters */
645 inr = nlist->iinr[0];
646 iq1 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
647 iq2 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
648 iq3 = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
649 vdwioffset0 = 2*nvdwtype*vdwtype[inr+0];
651 /* Avoid stupid compiler warnings */
652 jnrA = jnrB = 0;
653 j_coord_offsetA = 0;
654 j_coord_offsetB = 0;
656 outeriter = 0;
657 inneriter = 0;
659 /* Start outer loop over neighborlists */
660 for(iidx=0; iidx<nri; iidx++)
662 /* Load shift vector for this list */
663 i_shift_offset = DIM*shiftidx[iidx];
665 /* Load limits for loop over neighbors */
666 j_index_start = jindex[iidx];
667 j_index_end = jindex[iidx+1];
669 /* Get outer coordinate index */
670 inr = iinr[iidx];
671 i_coord_offset = DIM*inr;
673 /* Load i particle coords and add shift vector */
674 gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
675 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
677 fix0 = _mm_setzero_pd();
678 fiy0 = _mm_setzero_pd();
679 fiz0 = _mm_setzero_pd();
680 fix1 = _mm_setzero_pd();
681 fiy1 = _mm_setzero_pd();
682 fiz1 = _mm_setzero_pd();
683 fix2 = _mm_setzero_pd();
684 fiy2 = _mm_setzero_pd();
685 fiz2 = _mm_setzero_pd();
686 fix3 = _mm_setzero_pd();
687 fiy3 = _mm_setzero_pd();
688 fiz3 = _mm_setzero_pd();
690 /* Start inner kernel loop */
691 for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
694 /* Get j neighbor index, and coordinate index */
695 jnrA = jjnr[jidx];
696 jnrB = jjnr[jidx+1];
697 j_coord_offsetA = DIM*jnrA;
698 j_coord_offsetB = DIM*jnrB;
700 /* load j atom coordinates */
701 gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
702 &jx0,&jy0,&jz0);
704 /* Calculate displacement vector */
705 dx00 = _mm_sub_pd(ix0,jx0);
706 dy00 = _mm_sub_pd(iy0,jy0);
707 dz00 = _mm_sub_pd(iz0,jz0);
708 dx10 = _mm_sub_pd(ix1,jx0);
709 dy10 = _mm_sub_pd(iy1,jy0);
710 dz10 = _mm_sub_pd(iz1,jz0);
711 dx20 = _mm_sub_pd(ix2,jx0);
712 dy20 = _mm_sub_pd(iy2,jy0);
713 dz20 = _mm_sub_pd(iz2,jz0);
714 dx30 = _mm_sub_pd(ix3,jx0);
715 dy30 = _mm_sub_pd(iy3,jy0);
716 dz30 = _mm_sub_pd(iz3,jz0);
718 /* Calculate squared distance and things based on it */
719 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
720 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
721 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
722 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
724 rinv10 = sse2_invsqrt_d(rsq10);
725 rinv20 = sse2_invsqrt_d(rsq20);
726 rinv30 = sse2_invsqrt_d(rsq30);
728 rinvsq00 = sse2_inv_d(rsq00);
729 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
730 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
731 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
733 /* Load parameters for j particles */
734 jq0 = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
735 vdwjidx0A = 2*vdwtype[jnrA+0];
736 vdwjidx0B = 2*vdwtype[jnrB+0];
738 fjx0 = _mm_setzero_pd();
739 fjy0 = _mm_setzero_pd();
740 fjz0 = _mm_setzero_pd();
742 /**************************
743 * CALCULATE INTERACTIONS *
744 **************************/
746 /* Compute parameters for interactions between i and j atoms */
747 gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
748 vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
750 /* LENNARD-JONES DISPERSION/REPULSION */
752 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
753 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
755 fscal = fvdw;
757 /* Calculate temporary vectorial force */
758 tx = _mm_mul_pd(fscal,dx00);
759 ty = _mm_mul_pd(fscal,dy00);
760 tz = _mm_mul_pd(fscal,dz00);
762 /* Update vectorial force */
763 fix0 = _mm_add_pd(fix0,tx);
764 fiy0 = _mm_add_pd(fiy0,ty);
765 fiz0 = _mm_add_pd(fiz0,tz);
767 fjx0 = _mm_add_pd(fjx0,tx);
768 fjy0 = _mm_add_pd(fjy0,ty);
769 fjz0 = _mm_add_pd(fjz0,tz);
771 /**************************
772 * CALCULATE INTERACTIONS *
773 **************************/
775 /* Compute parameters for interactions between i and j atoms */
776 qq10 = _mm_mul_pd(iq1,jq0);
778 /* REACTION-FIELD ELECTROSTATICS */
779 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
781 fscal = felec;
783 /* Calculate temporary vectorial force */
784 tx = _mm_mul_pd(fscal,dx10);
785 ty = _mm_mul_pd(fscal,dy10);
786 tz = _mm_mul_pd(fscal,dz10);
788 /* Update vectorial force */
789 fix1 = _mm_add_pd(fix1,tx);
790 fiy1 = _mm_add_pd(fiy1,ty);
791 fiz1 = _mm_add_pd(fiz1,tz);
793 fjx0 = _mm_add_pd(fjx0,tx);
794 fjy0 = _mm_add_pd(fjy0,ty);
795 fjz0 = _mm_add_pd(fjz0,tz);
797 /**************************
798 * CALCULATE INTERACTIONS *
799 **************************/
801 /* Compute parameters for interactions between i and j atoms */
802 qq20 = _mm_mul_pd(iq2,jq0);
804 /* REACTION-FIELD ELECTROSTATICS */
805 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
807 fscal = felec;
809 /* Calculate temporary vectorial force */
810 tx = _mm_mul_pd(fscal,dx20);
811 ty = _mm_mul_pd(fscal,dy20);
812 tz = _mm_mul_pd(fscal,dz20);
814 /* Update vectorial force */
815 fix2 = _mm_add_pd(fix2,tx);
816 fiy2 = _mm_add_pd(fiy2,ty);
817 fiz2 = _mm_add_pd(fiz2,tz);
819 fjx0 = _mm_add_pd(fjx0,tx);
820 fjy0 = _mm_add_pd(fjy0,ty);
821 fjz0 = _mm_add_pd(fjz0,tz);
823 /**************************
824 * CALCULATE INTERACTIONS *
825 **************************/
827 /* Compute parameters for interactions between i and j atoms */
828 qq30 = _mm_mul_pd(iq3,jq0);
830 /* REACTION-FIELD ELECTROSTATICS */
831 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
833 fscal = felec;
835 /* Calculate temporary vectorial force */
836 tx = _mm_mul_pd(fscal,dx30);
837 ty = _mm_mul_pd(fscal,dy30);
838 tz = _mm_mul_pd(fscal,dz30);
840 /* Update vectorial force */
841 fix3 = _mm_add_pd(fix3,tx);
842 fiy3 = _mm_add_pd(fiy3,ty);
843 fiz3 = _mm_add_pd(fiz3,tz);
845 fjx0 = _mm_add_pd(fjx0,tx);
846 fjy0 = _mm_add_pd(fjy0,ty);
847 fjz0 = _mm_add_pd(fjz0,tz);
849 gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
851 /* Inner loop uses 111 flops */
854 if(jidx<j_index_end)
857 jnrA = jjnr[jidx];
858 j_coord_offsetA = DIM*jnrA;
860 /* load j atom coordinates */
861 gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
862 &jx0,&jy0,&jz0);
864 /* Calculate displacement vector */
865 dx00 = _mm_sub_pd(ix0,jx0);
866 dy00 = _mm_sub_pd(iy0,jy0);
867 dz00 = _mm_sub_pd(iz0,jz0);
868 dx10 = _mm_sub_pd(ix1,jx0);
869 dy10 = _mm_sub_pd(iy1,jy0);
870 dz10 = _mm_sub_pd(iz1,jz0);
871 dx20 = _mm_sub_pd(ix2,jx0);
872 dy20 = _mm_sub_pd(iy2,jy0);
873 dz20 = _mm_sub_pd(iz2,jz0);
874 dx30 = _mm_sub_pd(ix3,jx0);
875 dy30 = _mm_sub_pd(iy3,jy0);
876 dz30 = _mm_sub_pd(iz3,jz0);
878 /* Calculate squared distance and things based on it */
879 rsq00 = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
880 rsq10 = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
881 rsq20 = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
882 rsq30 = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
884 rinv10 = sse2_invsqrt_d(rsq10);
885 rinv20 = sse2_invsqrt_d(rsq20);
886 rinv30 = sse2_invsqrt_d(rsq30);
888 rinvsq00 = sse2_inv_d(rsq00);
889 rinvsq10 = _mm_mul_pd(rinv10,rinv10);
890 rinvsq20 = _mm_mul_pd(rinv20,rinv20);
891 rinvsq30 = _mm_mul_pd(rinv30,rinv30);
893 /* Load parameters for j particles */
894 jq0 = _mm_load_sd(charge+jnrA+0);
895 vdwjidx0A = 2*vdwtype[jnrA+0];
897 fjx0 = _mm_setzero_pd();
898 fjy0 = _mm_setzero_pd();
899 fjz0 = _mm_setzero_pd();
901 /**************************
902 * CALCULATE INTERACTIONS *
903 **************************/
905 /* Compute parameters for interactions between i and j atoms */
906 gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
908 /* LENNARD-JONES DISPERSION/REPULSION */
910 rinvsix = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
911 fvdw = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
913 fscal = fvdw;
915 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
917 /* Calculate temporary vectorial force */
918 tx = _mm_mul_pd(fscal,dx00);
919 ty = _mm_mul_pd(fscal,dy00);
920 tz = _mm_mul_pd(fscal,dz00);
922 /* Update vectorial force */
923 fix0 = _mm_add_pd(fix0,tx);
924 fiy0 = _mm_add_pd(fiy0,ty);
925 fiz0 = _mm_add_pd(fiz0,tz);
927 fjx0 = _mm_add_pd(fjx0,tx);
928 fjy0 = _mm_add_pd(fjy0,ty);
929 fjz0 = _mm_add_pd(fjz0,tz);
931 /**************************
932 * CALCULATE INTERACTIONS *
933 **************************/
935 /* Compute parameters for interactions between i and j atoms */
936 qq10 = _mm_mul_pd(iq1,jq0);
938 /* REACTION-FIELD ELECTROSTATICS */
939 felec = _mm_mul_pd(qq10,_mm_sub_pd(_mm_mul_pd(rinv10,rinvsq10),krf2));
941 fscal = felec;
943 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
945 /* Calculate temporary vectorial force */
946 tx = _mm_mul_pd(fscal,dx10);
947 ty = _mm_mul_pd(fscal,dy10);
948 tz = _mm_mul_pd(fscal,dz10);
950 /* Update vectorial force */
951 fix1 = _mm_add_pd(fix1,tx);
952 fiy1 = _mm_add_pd(fiy1,ty);
953 fiz1 = _mm_add_pd(fiz1,tz);
955 fjx0 = _mm_add_pd(fjx0,tx);
956 fjy0 = _mm_add_pd(fjy0,ty);
957 fjz0 = _mm_add_pd(fjz0,tz);
959 /**************************
960 * CALCULATE INTERACTIONS *
961 **************************/
963 /* Compute parameters for interactions between i and j atoms */
964 qq20 = _mm_mul_pd(iq2,jq0);
966 /* REACTION-FIELD ELECTROSTATICS */
967 felec = _mm_mul_pd(qq20,_mm_sub_pd(_mm_mul_pd(rinv20,rinvsq20),krf2));
969 fscal = felec;
971 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
973 /* Calculate temporary vectorial force */
974 tx = _mm_mul_pd(fscal,dx20);
975 ty = _mm_mul_pd(fscal,dy20);
976 tz = _mm_mul_pd(fscal,dz20);
978 /* Update vectorial force */
979 fix2 = _mm_add_pd(fix2,tx);
980 fiy2 = _mm_add_pd(fiy2,ty);
981 fiz2 = _mm_add_pd(fiz2,tz);
983 fjx0 = _mm_add_pd(fjx0,tx);
984 fjy0 = _mm_add_pd(fjy0,ty);
985 fjz0 = _mm_add_pd(fjz0,tz);
987 /**************************
988 * CALCULATE INTERACTIONS *
989 **************************/
991 /* Compute parameters for interactions between i and j atoms */
992 qq30 = _mm_mul_pd(iq3,jq0);
994 /* REACTION-FIELD ELECTROSTATICS */
995 felec = _mm_mul_pd(qq30,_mm_sub_pd(_mm_mul_pd(rinv30,rinvsq30),krf2));
997 fscal = felec;
999 fscal = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1001 /* Calculate temporary vectorial force */
1002 tx = _mm_mul_pd(fscal,dx30);
1003 ty = _mm_mul_pd(fscal,dy30);
1004 tz = _mm_mul_pd(fscal,dz30);
1006 /* Update vectorial force */
1007 fix3 = _mm_add_pd(fix3,tx);
1008 fiy3 = _mm_add_pd(fiy3,ty);
1009 fiz3 = _mm_add_pd(fiz3,tz);
1011 fjx0 = _mm_add_pd(fjx0,tx);
1012 fjy0 = _mm_add_pd(fjy0,ty);
1013 fjz0 = _mm_add_pd(fjz0,tz);
1015 gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1017 /* Inner loop uses 111 flops */
1020 /* End of innermost loop */
1022 gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1023 f+i_coord_offset,fshift+i_shift_offset);
1025 /* Increment number of inner iterations */
1026 inneriter += j_index_end - j_index_start;
1028 /* Outer loop uses 24 flops */
1031 /* Increment number of outer iterations */
1032 outeriter += nri;
1034 /* Update outer/inner flops */
1036 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*111);