Remove nb-parameters from t_forcerec
[gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_single / nb_kernel_ElecRFCut_VdwNone_GeomW4P1_sse2_single.c
blob53fe023bda4cedc5396e548263fd3f74f61eb1f6
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_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_sse2_single.h"
50 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_sse2_single
51 * Electrostatics interaction: ReactionField
52 * VdW interaction: None
53 * Geometry: Water4-Particle
54 * Calculate force/pot: PotentialAndForce
56 void
57 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_VF_sse2_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 SSE, 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 tx,ty,tz,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 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
123 rcutoff_scalar = fr->ic->rcoulomb;
124 rcutoff = _mm_set1_ps(rcutoff_scalar);
125 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
127 /* Avoid stupid compiler warnings */
128 jnrA = jnrB = jnrC = jnrD = 0;
129 j_coord_offsetA = 0;
130 j_coord_offsetB = 0;
131 j_coord_offsetC = 0;
132 j_coord_offsetD = 0;
134 outeriter = 0;
135 inneriter = 0;
137 for(iidx=0;iidx<4*DIM;iidx++)
139 scratch[iidx] = 0.0;
142 /* Start outer loop over neighborlists */
143 for(iidx=0; iidx<nri; iidx++)
145 /* Load shift vector for this list */
146 i_shift_offset = DIM*shiftidx[iidx];
148 /* Load limits for loop over neighbors */
149 j_index_start = jindex[iidx];
150 j_index_end = jindex[iidx+1];
152 /* Get outer coordinate index */
153 inr = iinr[iidx];
154 i_coord_offset = DIM*inr;
156 /* Load i particle coords and add shift vector */
157 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
158 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
160 fix1 = _mm_setzero_ps();
161 fiy1 = _mm_setzero_ps();
162 fiz1 = _mm_setzero_ps();
163 fix2 = _mm_setzero_ps();
164 fiy2 = _mm_setzero_ps();
165 fiz2 = _mm_setzero_ps();
166 fix3 = _mm_setzero_ps();
167 fiy3 = _mm_setzero_ps();
168 fiz3 = _mm_setzero_ps();
170 /* Reset potential sums */
171 velecsum = _mm_setzero_ps();
173 /* Start inner kernel loop */
174 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
177 /* Get j neighbor index, and coordinate index */
178 jnrA = jjnr[jidx];
179 jnrB = jjnr[jidx+1];
180 jnrC = jjnr[jidx+2];
181 jnrD = jjnr[jidx+3];
182 j_coord_offsetA = DIM*jnrA;
183 j_coord_offsetB = DIM*jnrB;
184 j_coord_offsetC = DIM*jnrC;
185 j_coord_offsetD = DIM*jnrD;
187 /* load j atom coordinates */
188 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
189 x+j_coord_offsetC,x+j_coord_offsetD,
190 &jx0,&jy0,&jz0);
192 /* Calculate displacement vector */
193 dx10 = _mm_sub_ps(ix1,jx0);
194 dy10 = _mm_sub_ps(iy1,jy0);
195 dz10 = _mm_sub_ps(iz1,jz0);
196 dx20 = _mm_sub_ps(ix2,jx0);
197 dy20 = _mm_sub_ps(iy2,jy0);
198 dz20 = _mm_sub_ps(iz2,jz0);
199 dx30 = _mm_sub_ps(ix3,jx0);
200 dy30 = _mm_sub_ps(iy3,jy0);
201 dz30 = _mm_sub_ps(iz3,jz0);
203 /* Calculate squared distance and things based on it */
204 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
205 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
206 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
208 rinv10 = sse2_invsqrt_f(rsq10);
209 rinv20 = sse2_invsqrt_f(rsq20);
210 rinv30 = sse2_invsqrt_f(rsq30);
212 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
213 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
214 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
216 /* Load parameters for j particles */
217 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
218 charge+jnrC+0,charge+jnrD+0);
220 fjx0 = _mm_setzero_ps();
221 fjy0 = _mm_setzero_ps();
222 fjz0 = _mm_setzero_ps();
224 /**************************
225 * CALCULATE INTERACTIONS *
226 **************************/
228 if (gmx_mm_any_lt(rsq10,rcutoff2))
231 /* Compute parameters for interactions between i and j atoms */
232 qq10 = _mm_mul_ps(iq1,jq0);
234 /* REACTION-FIELD ELECTROSTATICS */
235 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
236 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
238 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
240 /* Update potential sum for this i atom from the interaction with this j atom. */
241 velec = _mm_and_ps(velec,cutoff_mask);
242 velecsum = _mm_add_ps(velecsum,velec);
244 fscal = felec;
246 fscal = _mm_and_ps(fscal,cutoff_mask);
248 /* Calculate temporary vectorial force */
249 tx = _mm_mul_ps(fscal,dx10);
250 ty = _mm_mul_ps(fscal,dy10);
251 tz = _mm_mul_ps(fscal,dz10);
253 /* Update vectorial force */
254 fix1 = _mm_add_ps(fix1,tx);
255 fiy1 = _mm_add_ps(fiy1,ty);
256 fiz1 = _mm_add_ps(fiz1,tz);
258 fjx0 = _mm_add_ps(fjx0,tx);
259 fjy0 = _mm_add_ps(fjy0,ty);
260 fjz0 = _mm_add_ps(fjz0,tz);
264 /**************************
265 * CALCULATE INTERACTIONS *
266 **************************/
268 if (gmx_mm_any_lt(rsq20,rcutoff2))
271 /* Compute parameters for interactions between i and j atoms */
272 qq20 = _mm_mul_ps(iq2,jq0);
274 /* REACTION-FIELD ELECTROSTATICS */
275 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
276 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
278 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
280 /* Update potential sum for this i atom from the interaction with this j atom. */
281 velec = _mm_and_ps(velec,cutoff_mask);
282 velecsum = _mm_add_ps(velecsum,velec);
284 fscal = felec;
286 fscal = _mm_and_ps(fscal,cutoff_mask);
288 /* Calculate temporary vectorial force */
289 tx = _mm_mul_ps(fscal,dx20);
290 ty = _mm_mul_ps(fscal,dy20);
291 tz = _mm_mul_ps(fscal,dz20);
293 /* Update vectorial force */
294 fix2 = _mm_add_ps(fix2,tx);
295 fiy2 = _mm_add_ps(fiy2,ty);
296 fiz2 = _mm_add_ps(fiz2,tz);
298 fjx0 = _mm_add_ps(fjx0,tx);
299 fjy0 = _mm_add_ps(fjy0,ty);
300 fjz0 = _mm_add_ps(fjz0,tz);
304 /**************************
305 * CALCULATE INTERACTIONS *
306 **************************/
308 if (gmx_mm_any_lt(rsq30,rcutoff2))
311 /* Compute parameters for interactions between i and j atoms */
312 qq30 = _mm_mul_ps(iq3,jq0);
314 /* REACTION-FIELD ELECTROSTATICS */
315 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
316 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
318 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
320 /* Update potential sum for this i atom from the interaction with this j atom. */
321 velec = _mm_and_ps(velec,cutoff_mask);
322 velecsum = _mm_add_ps(velecsum,velec);
324 fscal = felec;
326 fscal = _mm_and_ps(fscal,cutoff_mask);
328 /* Calculate temporary vectorial force */
329 tx = _mm_mul_ps(fscal,dx30);
330 ty = _mm_mul_ps(fscal,dy30);
331 tz = _mm_mul_ps(fscal,dz30);
333 /* Update vectorial force */
334 fix3 = _mm_add_ps(fix3,tx);
335 fiy3 = _mm_add_ps(fiy3,ty);
336 fiz3 = _mm_add_ps(fiz3,tz);
338 fjx0 = _mm_add_ps(fjx0,tx);
339 fjy0 = _mm_add_ps(fjy0,ty);
340 fjz0 = _mm_add_ps(fjz0,tz);
344 fjptrA = f+j_coord_offsetA;
345 fjptrB = f+j_coord_offsetB;
346 fjptrC = f+j_coord_offsetC;
347 fjptrD = f+j_coord_offsetD;
349 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
351 /* Inner loop uses 108 flops */
354 if(jidx<j_index_end)
357 /* Get j neighbor index, and coordinate index */
358 jnrlistA = jjnr[jidx];
359 jnrlistB = jjnr[jidx+1];
360 jnrlistC = jjnr[jidx+2];
361 jnrlistD = jjnr[jidx+3];
362 /* Sign of each element will be negative for non-real atoms.
363 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
364 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
366 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
367 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
368 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
369 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
370 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
371 j_coord_offsetA = DIM*jnrA;
372 j_coord_offsetB = DIM*jnrB;
373 j_coord_offsetC = DIM*jnrC;
374 j_coord_offsetD = DIM*jnrD;
376 /* load j atom coordinates */
377 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
378 x+j_coord_offsetC,x+j_coord_offsetD,
379 &jx0,&jy0,&jz0);
381 /* Calculate displacement vector */
382 dx10 = _mm_sub_ps(ix1,jx0);
383 dy10 = _mm_sub_ps(iy1,jy0);
384 dz10 = _mm_sub_ps(iz1,jz0);
385 dx20 = _mm_sub_ps(ix2,jx0);
386 dy20 = _mm_sub_ps(iy2,jy0);
387 dz20 = _mm_sub_ps(iz2,jz0);
388 dx30 = _mm_sub_ps(ix3,jx0);
389 dy30 = _mm_sub_ps(iy3,jy0);
390 dz30 = _mm_sub_ps(iz3,jz0);
392 /* Calculate squared distance and things based on it */
393 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
394 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
395 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
397 rinv10 = sse2_invsqrt_f(rsq10);
398 rinv20 = sse2_invsqrt_f(rsq20);
399 rinv30 = sse2_invsqrt_f(rsq30);
401 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
402 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
403 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
405 /* Load parameters for j particles */
406 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
407 charge+jnrC+0,charge+jnrD+0);
409 fjx0 = _mm_setzero_ps();
410 fjy0 = _mm_setzero_ps();
411 fjz0 = _mm_setzero_ps();
413 /**************************
414 * CALCULATE INTERACTIONS *
415 **************************/
417 if (gmx_mm_any_lt(rsq10,rcutoff2))
420 /* Compute parameters for interactions between i and j atoms */
421 qq10 = _mm_mul_ps(iq1,jq0);
423 /* REACTION-FIELD ELECTROSTATICS */
424 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
425 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
427 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
429 /* Update potential sum for this i atom from the interaction with this j atom. */
430 velec = _mm_and_ps(velec,cutoff_mask);
431 velec = _mm_andnot_ps(dummy_mask,velec);
432 velecsum = _mm_add_ps(velecsum,velec);
434 fscal = felec;
436 fscal = _mm_and_ps(fscal,cutoff_mask);
438 fscal = _mm_andnot_ps(dummy_mask,fscal);
440 /* Calculate temporary vectorial force */
441 tx = _mm_mul_ps(fscal,dx10);
442 ty = _mm_mul_ps(fscal,dy10);
443 tz = _mm_mul_ps(fscal,dz10);
445 /* Update vectorial force */
446 fix1 = _mm_add_ps(fix1,tx);
447 fiy1 = _mm_add_ps(fiy1,ty);
448 fiz1 = _mm_add_ps(fiz1,tz);
450 fjx0 = _mm_add_ps(fjx0,tx);
451 fjy0 = _mm_add_ps(fjy0,ty);
452 fjz0 = _mm_add_ps(fjz0,tz);
456 /**************************
457 * CALCULATE INTERACTIONS *
458 **************************/
460 if (gmx_mm_any_lt(rsq20,rcutoff2))
463 /* Compute parameters for interactions between i and j atoms */
464 qq20 = _mm_mul_ps(iq2,jq0);
466 /* REACTION-FIELD ELECTROSTATICS */
467 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
468 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
470 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
472 /* Update potential sum for this i atom from the interaction with this j atom. */
473 velec = _mm_and_ps(velec,cutoff_mask);
474 velec = _mm_andnot_ps(dummy_mask,velec);
475 velecsum = _mm_add_ps(velecsum,velec);
477 fscal = felec;
479 fscal = _mm_and_ps(fscal,cutoff_mask);
481 fscal = _mm_andnot_ps(dummy_mask,fscal);
483 /* Calculate temporary vectorial force */
484 tx = _mm_mul_ps(fscal,dx20);
485 ty = _mm_mul_ps(fscal,dy20);
486 tz = _mm_mul_ps(fscal,dz20);
488 /* Update vectorial force */
489 fix2 = _mm_add_ps(fix2,tx);
490 fiy2 = _mm_add_ps(fiy2,ty);
491 fiz2 = _mm_add_ps(fiz2,tz);
493 fjx0 = _mm_add_ps(fjx0,tx);
494 fjy0 = _mm_add_ps(fjy0,ty);
495 fjz0 = _mm_add_ps(fjz0,tz);
499 /**************************
500 * CALCULATE INTERACTIONS *
501 **************************/
503 if (gmx_mm_any_lt(rsq30,rcutoff2))
506 /* Compute parameters for interactions between i and j atoms */
507 qq30 = _mm_mul_ps(iq3,jq0);
509 /* REACTION-FIELD ELECTROSTATICS */
510 velec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
511 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
513 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
515 /* Update potential sum for this i atom from the interaction with this j atom. */
516 velec = _mm_and_ps(velec,cutoff_mask);
517 velec = _mm_andnot_ps(dummy_mask,velec);
518 velecsum = _mm_add_ps(velecsum,velec);
520 fscal = felec;
522 fscal = _mm_and_ps(fscal,cutoff_mask);
524 fscal = _mm_andnot_ps(dummy_mask,fscal);
526 /* Calculate temporary vectorial force */
527 tx = _mm_mul_ps(fscal,dx30);
528 ty = _mm_mul_ps(fscal,dy30);
529 tz = _mm_mul_ps(fscal,dz30);
531 /* Update vectorial force */
532 fix3 = _mm_add_ps(fix3,tx);
533 fiy3 = _mm_add_ps(fiy3,ty);
534 fiz3 = _mm_add_ps(fiz3,tz);
536 fjx0 = _mm_add_ps(fjx0,tx);
537 fjy0 = _mm_add_ps(fjy0,ty);
538 fjz0 = _mm_add_ps(fjz0,tz);
542 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
543 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
544 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
545 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
547 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
549 /* Inner loop uses 108 flops */
552 /* End of innermost loop */
554 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
555 f+i_coord_offset+DIM,fshift+i_shift_offset);
557 ggid = gid[iidx];
558 /* Update potential energies */
559 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
561 /* Increment number of inner iterations */
562 inneriter += j_index_end - j_index_start;
564 /* Outer loop uses 19 flops */
567 /* Increment number of outer iterations */
568 outeriter += nri;
570 /* Update outer/inner flops */
572 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_VF,outeriter*19 + inneriter*108);
575 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_sse2_single
576 * Electrostatics interaction: ReactionField
577 * VdW interaction: None
578 * Geometry: Water4-Particle
579 * Calculate force/pot: Force
581 void
582 nb_kernel_ElecRFCut_VdwNone_GeomW4P1_F_sse2_single
583 (t_nblist * gmx_restrict nlist,
584 rvec * gmx_restrict xx,
585 rvec * gmx_restrict ff,
586 struct t_forcerec * gmx_restrict fr,
587 t_mdatoms * gmx_restrict mdatoms,
588 nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
589 t_nrnb * gmx_restrict nrnb)
591 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
592 * just 0 for non-waters.
593 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
594 * jnr indices corresponding to data put in the four positions in the SIMD register.
596 int i_shift_offset,i_coord_offset,outeriter,inneriter;
597 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
598 int jnrA,jnrB,jnrC,jnrD;
599 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
600 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
601 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
602 real rcutoff_scalar;
603 real *shiftvec,*fshift,*x,*f;
604 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
605 real scratch[4*DIM];
606 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
607 int vdwioffset1;
608 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
609 int vdwioffset2;
610 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
611 int vdwioffset3;
612 __m128 ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
613 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
614 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
615 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
616 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
617 __m128 dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
618 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
619 real *charge;
620 __m128 dummy_mask,cutoff_mask;
621 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
622 __m128 one = _mm_set1_ps(1.0);
623 __m128 two = _mm_set1_ps(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_ps(fr->ic->epsfac);
636 charge = mdatoms->chargeA;
637 krf = _mm_set1_ps(fr->ic->k_rf);
638 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
639 crf = _mm_set1_ps(fr->ic->c_rf);
641 /* Setup water-specific parameters */
642 inr = nlist->iinr[0];
643 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
644 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
645 iq3 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
647 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
648 rcutoff_scalar = fr->ic->rcoulomb;
649 rcutoff = _mm_set1_ps(rcutoff_scalar);
650 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
652 /* Avoid stupid compiler warnings */
653 jnrA = jnrB = jnrC = jnrD = 0;
654 j_coord_offsetA = 0;
655 j_coord_offsetB = 0;
656 j_coord_offsetC = 0;
657 j_coord_offsetD = 0;
659 outeriter = 0;
660 inneriter = 0;
662 for(iidx=0;iidx<4*DIM;iidx++)
664 scratch[iidx] = 0.0;
667 /* Start outer loop over neighborlists */
668 for(iidx=0; iidx<nri; iidx++)
670 /* Load shift vector for this list */
671 i_shift_offset = DIM*shiftidx[iidx];
673 /* Load limits for loop over neighbors */
674 j_index_start = jindex[iidx];
675 j_index_end = jindex[iidx+1];
677 /* Get outer coordinate index */
678 inr = iinr[iidx];
679 i_coord_offset = DIM*inr;
681 /* Load i particle coords and add shift vector */
682 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
683 &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
685 fix1 = _mm_setzero_ps();
686 fiy1 = _mm_setzero_ps();
687 fiz1 = _mm_setzero_ps();
688 fix2 = _mm_setzero_ps();
689 fiy2 = _mm_setzero_ps();
690 fiz2 = _mm_setzero_ps();
691 fix3 = _mm_setzero_ps();
692 fiy3 = _mm_setzero_ps();
693 fiz3 = _mm_setzero_ps();
695 /* Start inner kernel loop */
696 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
699 /* Get j neighbor index, and coordinate index */
700 jnrA = jjnr[jidx];
701 jnrB = jjnr[jidx+1];
702 jnrC = jjnr[jidx+2];
703 jnrD = jjnr[jidx+3];
704 j_coord_offsetA = DIM*jnrA;
705 j_coord_offsetB = DIM*jnrB;
706 j_coord_offsetC = DIM*jnrC;
707 j_coord_offsetD = DIM*jnrD;
709 /* load j atom coordinates */
710 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
711 x+j_coord_offsetC,x+j_coord_offsetD,
712 &jx0,&jy0,&jz0);
714 /* Calculate displacement vector */
715 dx10 = _mm_sub_ps(ix1,jx0);
716 dy10 = _mm_sub_ps(iy1,jy0);
717 dz10 = _mm_sub_ps(iz1,jz0);
718 dx20 = _mm_sub_ps(ix2,jx0);
719 dy20 = _mm_sub_ps(iy2,jy0);
720 dz20 = _mm_sub_ps(iz2,jz0);
721 dx30 = _mm_sub_ps(ix3,jx0);
722 dy30 = _mm_sub_ps(iy3,jy0);
723 dz30 = _mm_sub_ps(iz3,jz0);
725 /* Calculate squared distance and things based on it */
726 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
727 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
728 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
730 rinv10 = sse2_invsqrt_f(rsq10);
731 rinv20 = sse2_invsqrt_f(rsq20);
732 rinv30 = sse2_invsqrt_f(rsq30);
734 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
735 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
736 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
738 /* Load parameters for j particles */
739 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
740 charge+jnrC+0,charge+jnrD+0);
742 fjx0 = _mm_setzero_ps();
743 fjy0 = _mm_setzero_ps();
744 fjz0 = _mm_setzero_ps();
746 /**************************
747 * CALCULATE INTERACTIONS *
748 **************************/
750 if (gmx_mm_any_lt(rsq10,rcutoff2))
753 /* Compute parameters for interactions between i and j atoms */
754 qq10 = _mm_mul_ps(iq1,jq0);
756 /* REACTION-FIELD ELECTROSTATICS */
757 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
759 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
761 fscal = felec;
763 fscal = _mm_and_ps(fscal,cutoff_mask);
765 /* Calculate temporary vectorial force */
766 tx = _mm_mul_ps(fscal,dx10);
767 ty = _mm_mul_ps(fscal,dy10);
768 tz = _mm_mul_ps(fscal,dz10);
770 /* Update vectorial force */
771 fix1 = _mm_add_ps(fix1,tx);
772 fiy1 = _mm_add_ps(fiy1,ty);
773 fiz1 = _mm_add_ps(fiz1,tz);
775 fjx0 = _mm_add_ps(fjx0,tx);
776 fjy0 = _mm_add_ps(fjy0,ty);
777 fjz0 = _mm_add_ps(fjz0,tz);
781 /**************************
782 * CALCULATE INTERACTIONS *
783 **************************/
785 if (gmx_mm_any_lt(rsq20,rcutoff2))
788 /* Compute parameters for interactions between i and j atoms */
789 qq20 = _mm_mul_ps(iq2,jq0);
791 /* REACTION-FIELD ELECTROSTATICS */
792 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
794 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
796 fscal = felec;
798 fscal = _mm_and_ps(fscal,cutoff_mask);
800 /* Calculate temporary vectorial force */
801 tx = _mm_mul_ps(fscal,dx20);
802 ty = _mm_mul_ps(fscal,dy20);
803 tz = _mm_mul_ps(fscal,dz20);
805 /* Update vectorial force */
806 fix2 = _mm_add_ps(fix2,tx);
807 fiy2 = _mm_add_ps(fiy2,ty);
808 fiz2 = _mm_add_ps(fiz2,tz);
810 fjx0 = _mm_add_ps(fjx0,tx);
811 fjy0 = _mm_add_ps(fjy0,ty);
812 fjz0 = _mm_add_ps(fjz0,tz);
816 /**************************
817 * CALCULATE INTERACTIONS *
818 **************************/
820 if (gmx_mm_any_lt(rsq30,rcutoff2))
823 /* Compute parameters for interactions between i and j atoms */
824 qq30 = _mm_mul_ps(iq3,jq0);
826 /* REACTION-FIELD ELECTROSTATICS */
827 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
829 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
831 fscal = felec;
833 fscal = _mm_and_ps(fscal,cutoff_mask);
835 /* Calculate temporary vectorial force */
836 tx = _mm_mul_ps(fscal,dx30);
837 ty = _mm_mul_ps(fscal,dy30);
838 tz = _mm_mul_ps(fscal,dz30);
840 /* Update vectorial force */
841 fix3 = _mm_add_ps(fix3,tx);
842 fiy3 = _mm_add_ps(fiy3,ty);
843 fiz3 = _mm_add_ps(fiz3,tz);
845 fjx0 = _mm_add_ps(fjx0,tx);
846 fjy0 = _mm_add_ps(fjy0,ty);
847 fjz0 = _mm_add_ps(fjz0,tz);
851 fjptrA = f+j_coord_offsetA;
852 fjptrB = f+j_coord_offsetB;
853 fjptrC = f+j_coord_offsetC;
854 fjptrD = f+j_coord_offsetD;
856 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
858 /* Inner loop uses 90 flops */
861 if(jidx<j_index_end)
864 /* Get j neighbor index, and coordinate index */
865 jnrlistA = jjnr[jidx];
866 jnrlistB = jjnr[jidx+1];
867 jnrlistC = jjnr[jidx+2];
868 jnrlistD = jjnr[jidx+3];
869 /* Sign of each element will be negative for non-real atoms.
870 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
871 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
873 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
874 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
875 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
876 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
877 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
878 j_coord_offsetA = DIM*jnrA;
879 j_coord_offsetB = DIM*jnrB;
880 j_coord_offsetC = DIM*jnrC;
881 j_coord_offsetD = DIM*jnrD;
883 /* load j atom coordinates */
884 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
885 x+j_coord_offsetC,x+j_coord_offsetD,
886 &jx0,&jy0,&jz0);
888 /* Calculate displacement vector */
889 dx10 = _mm_sub_ps(ix1,jx0);
890 dy10 = _mm_sub_ps(iy1,jy0);
891 dz10 = _mm_sub_ps(iz1,jz0);
892 dx20 = _mm_sub_ps(ix2,jx0);
893 dy20 = _mm_sub_ps(iy2,jy0);
894 dz20 = _mm_sub_ps(iz2,jz0);
895 dx30 = _mm_sub_ps(ix3,jx0);
896 dy30 = _mm_sub_ps(iy3,jy0);
897 dz30 = _mm_sub_ps(iz3,jz0);
899 /* Calculate squared distance and things based on it */
900 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
901 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
902 rsq30 = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
904 rinv10 = sse2_invsqrt_f(rsq10);
905 rinv20 = sse2_invsqrt_f(rsq20);
906 rinv30 = sse2_invsqrt_f(rsq30);
908 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
909 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
910 rinvsq30 = _mm_mul_ps(rinv30,rinv30);
912 /* Load parameters for j particles */
913 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
914 charge+jnrC+0,charge+jnrD+0);
916 fjx0 = _mm_setzero_ps();
917 fjy0 = _mm_setzero_ps();
918 fjz0 = _mm_setzero_ps();
920 /**************************
921 * CALCULATE INTERACTIONS *
922 **************************/
924 if (gmx_mm_any_lt(rsq10,rcutoff2))
927 /* Compute parameters for interactions between i and j atoms */
928 qq10 = _mm_mul_ps(iq1,jq0);
930 /* REACTION-FIELD ELECTROSTATICS */
931 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
933 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
935 fscal = felec;
937 fscal = _mm_and_ps(fscal,cutoff_mask);
939 fscal = _mm_andnot_ps(dummy_mask,fscal);
941 /* Calculate temporary vectorial force */
942 tx = _mm_mul_ps(fscal,dx10);
943 ty = _mm_mul_ps(fscal,dy10);
944 tz = _mm_mul_ps(fscal,dz10);
946 /* Update vectorial force */
947 fix1 = _mm_add_ps(fix1,tx);
948 fiy1 = _mm_add_ps(fiy1,ty);
949 fiz1 = _mm_add_ps(fiz1,tz);
951 fjx0 = _mm_add_ps(fjx0,tx);
952 fjy0 = _mm_add_ps(fjy0,ty);
953 fjz0 = _mm_add_ps(fjz0,tz);
957 /**************************
958 * CALCULATE INTERACTIONS *
959 **************************/
961 if (gmx_mm_any_lt(rsq20,rcutoff2))
964 /* Compute parameters for interactions between i and j atoms */
965 qq20 = _mm_mul_ps(iq2,jq0);
967 /* REACTION-FIELD ELECTROSTATICS */
968 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
970 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
972 fscal = felec;
974 fscal = _mm_and_ps(fscal,cutoff_mask);
976 fscal = _mm_andnot_ps(dummy_mask,fscal);
978 /* Calculate temporary vectorial force */
979 tx = _mm_mul_ps(fscal,dx20);
980 ty = _mm_mul_ps(fscal,dy20);
981 tz = _mm_mul_ps(fscal,dz20);
983 /* Update vectorial force */
984 fix2 = _mm_add_ps(fix2,tx);
985 fiy2 = _mm_add_ps(fiy2,ty);
986 fiz2 = _mm_add_ps(fiz2,tz);
988 fjx0 = _mm_add_ps(fjx0,tx);
989 fjy0 = _mm_add_ps(fjy0,ty);
990 fjz0 = _mm_add_ps(fjz0,tz);
994 /**************************
995 * CALCULATE INTERACTIONS *
996 **************************/
998 if (gmx_mm_any_lt(rsq30,rcutoff2))
1001 /* Compute parameters for interactions between i and j atoms */
1002 qq30 = _mm_mul_ps(iq3,jq0);
1004 /* REACTION-FIELD ELECTROSTATICS */
1005 felec = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
1007 cutoff_mask = _mm_cmplt_ps(rsq30,rcutoff2);
1009 fscal = felec;
1011 fscal = _mm_and_ps(fscal,cutoff_mask);
1013 fscal = _mm_andnot_ps(dummy_mask,fscal);
1015 /* Calculate temporary vectorial force */
1016 tx = _mm_mul_ps(fscal,dx30);
1017 ty = _mm_mul_ps(fscal,dy30);
1018 tz = _mm_mul_ps(fscal,dz30);
1020 /* Update vectorial force */
1021 fix3 = _mm_add_ps(fix3,tx);
1022 fiy3 = _mm_add_ps(fiy3,ty);
1023 fiz3 = _mm_add_ps(fiz3,tz);
1025 fjx0 = _mm_add_ps(fjx0,tx);
1026 fjy0 = _mm_add_ps(fjy0,ty);
1027 fjz0 = _mm_add_ps(fjz0,tz);
1031 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1032 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1033 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1034 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1036 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1038 /* Inner loop uses 90 flops */
1041 /* End of innermost loop */
1043 gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1044 f+i_coord_offset+DIM,fshift+i_shift_offset);
1046 /* Increment number of inner iterations */
1047 inneriter += j_index_end - j_index_start;
1049 /* Outer loop uses 18 flops */
1052 /* Increment number of outer iterations */
1053 outeriter += nri;
1055 /* Update outer/inner flops */
1057 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4_F,outeriter*18 + inneriter*90);