2 * Note: this file was generated by the Gromacs sse4_1_single kernel generator.
4 * This source code is part of
8 * Copyright (c) 2001-2012, The GROMACS Development Team
10 * Gromacs is a library for molecular simulation and trajectory analysis,
11 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12 * a full list of developers and information, check out http://www.gromacs.org
14 * This program is free software; you can redistribute it and/or modify it under
15 * the terms of the GNU Lesser General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option) any
19 * To help fund GROMACS development, we humbly ask that you cite
20 * the papers people have written on it - you can find them on the website.
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
33 #include "gmx_math_x86_sse4_1_single.h"
34 #include "kernelutil_x86_sse4_1_single.h"
37 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_sse4_1_single
38 * Electrostatics interaction: ReactionField
39 * VdW interaction: None
40 * Geometry: Water3-Particle
41 * Calculate force/pot: PotentialAndForce
44 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_sse4_1_single
45 (t_nblist * gmx_restrict nlist,
46 rvec * gmx_restrict xx,
47 rvec * gmx_restrict ff,
48 t_forcerec * gmx_restrict fr,
49 t_mdatoms * gmx_restrict mdatoms,
50 nb_kernel_data_t * gmx_restrict kernel_data,
51 t_nrnb * gmx_restrict nrnb)
53 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54 * just 0 for non-waters.
55 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
56 * jnr indices corresponding to data put in the four positions in the SIMD register.
58 int i_shift_offset,i_coord_offset,outeriter,inneriter;
59 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60 int jnrA,jnrB,jnrC,jnrD;
61 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
65 real *shiftvec,*fshift,*x,*f;
66 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
68 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
70 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
72 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
74 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
76 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
77 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
78 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
79 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
80 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
82 __m128 dummy_mask,cutoff_mask;
83 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
84 __m128 one = _mm_set1_ps(1.0);
85 __m128 two = _mm_set1_ps(2.0);
91 jindex = nlist->jindex;
93 shiftidx = nlist->shift;
95 shiftvec = fr->shift_vec[0];
96 fshift = fr->fshift[0];
97 facel = _mm_set1_ps(fr->epsfac);
98 charge = mdatoms->chargeA;
99 krf = _mm_set1_ps(fr->ic->k_rf);
100 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
101 crf = _mm_set1_ps(fr->ic->c_rf);
103 /* Setup water-specific parameters */
104 inr = nlist->iinr[0];
105 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
106 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
107 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
109 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
110 rcutoff_scalar = fr->rcoulomb;
111 rcutoff = _mm_set1_ps(rcutoff_scalar);
112 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
114 /* Avoid stupid compiler warnings */
115 jnrA = jnrB = jnrC = jnrD = 0;
124 for(iidx=0;iidx<4*DIM;iidx++)
129 /* Start outer loop over neighborlists */
130 for(iidx=0; iidx<nri; iidx++)
132 /* Load shift vector for this list */
133 i_shift_offset = DIM*shiftidx[iidx];
135 /* Load limits for loop over neighbors */
136 j_index_start = jindex[iidx];
137 j_index_end = jindex[iidx+1];
139 /* Get outer coordinate index */
141 i_coord_offset = DIM*inr;
143 /* Load i particle coords and add shift vector */
144 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
145 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
147 fix0 = _mm_setzero_ps();
148 fiy0 = _mm_setzero_ps();
149 fiz0 = _mm_setzero_ps();
150 fix1 = _mm_setzero_ps();
151 fiy1 = _mm_setzero_ps();
152 fiz1 = _mm_setzero_ps();
153 fix2 = _mm_setzero_ps();
154 fiy2 = _mm_setzero_ps();
155 fiz2 = _mm_setzero_ps();
157 /* Reset potential sums */
158 velecsum = _mm_setzero_ps();
160 /* Start inner kernel loop */
161 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
164 /* Get j neighbor index, and coordinate index */
169 j_coord_offsetA = DIM*jnrA;
170 j_coord_offsetB = DIM*jnrB;
171 j_coord_offsetC = DIM*jnrC;
172 j_coord_offsetD = DIM*jnrD;
174 /* load j atom coordinates */
175 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
176 x+j_coord_offsetC,x+j_coord_offsetD,
179 /* Calculate displacement vector */
180 dx00 = _mm_sub_ps(ix0,jx0);
181 dy00 = _mm_sub_ps(iy0,jy0);
182 dz00 = _mm_sub_ps(iz0,jz0);
183 dx10 = _mm_sub_ps(ix1,jx0);
184 dy10 = _mm_sub_ps(iy1,jy0);
185 dz10 = _mm_sub_ps(iz1,jz0);
186 dx20 = _mm_sub_ps(ix2,jx0);
187 dy20 = _mm_sub_ps(iy2,jy0);
188 dz20 = _mm_sub_ps(iz2,jz0);
190 /* Calculate squared distance and things based on it */
191 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
192 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
193 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
195 rinv00 = gmx_mm_invsqrt_ps(rsq00);
196 rinv10 = gmx_mm_invsqrt_ps(rsq10);
197 rinv20 = gmx_mm_invsqrt_ps(rsq20);
199 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
200 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
201 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
203 /* Load parameters for j particles */
204 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
205 charge+jnrC+0,charge+jnrD+0);
207 fjx0 = _mm_setzero_ps();
208 fjy0 = _mm_setzero_ps();
209 fjz0 = _mm_setzero_ps();
211 /**************************
212 * CALCULATE INTERACTIONS *
213 **************************/
215 if (gmx_mm_any_lt(rsq00,rcutoff2))
218 /* Compute parameters for interactions between i and j atoms */
219 qq00 = _mm_mul_ps(iq0,jq0);
221 /* REACTION-FIELD ELECTROSTATICS */
222 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
223 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
225 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
227 /* Update potential sum for this i atom from the interaction with this j atom. */
228 velec = _mm_and_ps(velec,cutoff_mask);
229 velecsum = _mm_add_ps(velecsum,velec);
233 fscal = _mm_and_ps(fscal,cutoff_mask);
235 /* Calculate temporary vectorial force */
236 tx = _mm_mul_ps(fscal,dx00);
237 ty = _mm_mul_ps(fscal,dy00);
238 tz = _mm_mul_ps(fscal,dz00);
240 /* Update vectorial force */
241 fix0 = _mm_add_ps(fix0,tx);
242 fiy0 = _mm_add_ps(fiy0,ty);
243 fiz0 = _mm_add_ps(fiz0,tz);
245 fjx0 = _mm_add_ps(fjx0,tx);
246 fjy0 = _mm_add_ps(fjy0,ty);
247 fjz0 = _mm_add_ps(fjz0,tz);
251 /**************************
252 * CALCULATE INTERACTIONS *
253 **************************/
255 if (gmx_mm_any_lt(rsq10,rcutoff2))
258 /* Compute parameters for interactions between i and j atoms */
259 qq10 = _mm_mul_ps(iq1,jq0);
261 /* REACTION-FIELD ELECTROSTATICS */
262 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
263 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
265 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
267 /* Update potential sum for this i atom from the interaction with this j atom. */
268 velec = _mm_and_ps(velec,cutoff_mask);
269 velecsum = _mm_add_ps(velecsum,velec);
273 fscal = _mm_and_ps(fscal,cutoff_mask);
275 /* Calculate temporary vectorial force */
276 tx = _mm_mul_ps(fscal,dx10);
277 ty = _mm_mul_ps(fscal,dy10);
278 tz = _mm_mul_ps(fscal,dz10);
280 /* Update vectorial force */
281 fix1 = _mm_add_ps(fix1,tx);
282 fiy1 = _mm_add_ps(fiy1,ty);
283 fiz1 = _mm_add_ps(fiz1,tz);
285 fjx0 = _mm_add_ps(fjx0,tx);
286 fjy0 = _mm_add_ps(fjy0,ty);
287 fjz0 = _mm_add_ps(fjz0,tz);
291 /**************************
292 * CALCULATE INTERACTIONS *
293 **************************/
295 if (gmx_mm_any_lt(rsq20,rcutoff2))
298 /* Compute parameters for interactions between i and j atoms */
299 qq20 = _mm_mul_ps(iq2,jq0);
301 /* REACTION-FIELD ELECTROSTATICS */
302 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
303 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
305 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
307 /* Update potential sum for this i atom from the interaction with this j atom. */
308 velec = _mm_and_ps(velec,cutoff_mask);
309 velecsum = _mm_add_ps(velecsum,velec);
313 fscal = _mm_and_ps(fscal,cutoff_mask);
315 /* Calculate temporary vectorial force */
316 tx = _mm_mul_ps(fscal,dx20);
317 ty = _mm_mul_ps(fscal,dy20);
318 tz = _mm_mul_ps(fscal,dz20);
320 /* Update vectorial force */
321 fix2 = _mm_add_ps(fix2,tx);
322 fiy2 = _mm_add_ps(fiy2,ty);
323 fiz2 = _mm_add_ps(fiz2,tz);
325 fjx0 = _mm_add_ps(fjx0,tx);
326 fjy0 = _mm_add_ps(fjy0,ty);
327 fjz0 = _mm_add_ps(fjz0,tz);
331 fjptrA = f+j_coord_offsetA;
332 fjptrB = f+j_coord_offsetB;
333 fjptrC = f+j_coord_offsetC;
334 fjptrD = f+j_coord_offsetD;
336 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
338 /* Inner loop uses 108 flops */
344 /* Get j neighbor index, and coordinate index */
345 jnrlistA = jjnr[jidx];
346 jnrlistB = jjnr[jidx+1];
347 jnrlistC = jjnr[jidx+2];
348 jnrlistD = jjnr[jidx+3];
349 /* Sign of each element will be negative for non-real atoms.
350 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
351 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
353 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
354 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
355 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
356 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
357 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
358 j_coord_offsetA = DIM*jnrA;
359 j_coord_offsetB = DIM*jnrB;
360 j_coord_offsetC = DIM*jnrC;
361 j_coord_offsetD = DIM*jnrD;
363 /* load j atom coordinates */
364 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
365 x+j_coord_offsetC,x+j_coord_offsetD,
368 /* Calculate displacement vector */
369 dx00 = _mm_sub_ps(ix0,jx0);
370 dy00 = _mm_sub_ps(iy0,jy0);
371 dz00 = _mm_sub_ps(iz0,jz0);
372 dx10 = _mm_sub_ps(ix1,jx0);
373 dy10 = _mm_sub_ps(iy1,jy0);
374 dz10 = _mm_sub_ps(iz1,jz0);
375 dx20 = _mm_sub_ps(ix2,jx0);
376 dy20 = _mm_sub_ps(iy2,jy0);
377 dz20 = _mm_sub_ps(iz2,jz0);
379 /* Calculate squared distance and things based on it */
380 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
381 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
382 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
384 rinv00 = gmx_mm_invsqrt_ps(rsq00);
385 rinv10 = gmx_mm_invsqrt_ps(rsq10);
386 rinv20 = gmx_mm_invsqrt_ps(rsq20);
388 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
389 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
390 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
392 /* Load parameters for j particles */
393 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
394 charge+jnrC+0,charge+jnrD+0);
396 fjx0 = _mm_setzero_ps();
397 fjy0 = _mm_setzero_ps();
398 fjz0 = _mm_setzero_ps();
400 /**************************
401 * CALCULATE INTERACTIONS *
402 **************************/
404 if (gmx_mm_any_lt(rsq00,rcutoff2))
407 /* Compute parameters for interactions between i and j atoms */
408 qq00 = _mm_mul_ps(iq0,jq0);
410 /* REACTION-FIELD ELECTROSTATICS */
411 velec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
412 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
414 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
416 /* Update potential sum for this i atom from the interaction with this j atom. */
417 velec = _mm_and_ps(velec,cutoff_mask);
418 velec = _mm_andnot_ps(dummy_mask,velec);
419 velecsum = _mm_add_ps(velecsum,velec);
423 fscal = _mm_and_ps(fscal,cutoff_mask);
425 fscal = _mm_andnot_ps(dummy_mask,fscal);
427 /* Calculate temporary vectorial force */
428 tx = _mm_mul_ps(fscal,dx00);
429 ty = _mm_mul_ps(fscal,dy00);
430 tz = _mm_mul_ps(fscal,dz00);
432 /* Update vectorial force */
433 fix0 = _mm_add_ps(fix0,tx);
434 fiy0 = _mm_add_ps(fiy0,ty);
435 fiz0 = _mm_add_ps(fiz0,tz);
437 fjx0 = _mm_add_ps(fjx0,tx);
438 fjy0 = _mm_add_ps(fjy0,ty);
439 fjz0 = _mm_add_ps(fjz0,tz);
443 /**************************
444 * CALCULATE INTERACTIONS *
445 **************************/
447 if (gmx_mm_any_lt(rsq10,rcutoff2))
450 /* Compute parameters for interactions between i and j atoms */
451 qq10 = _mm_mul_ps(iq1,jq0);
453 /* REACTION-FIELD ELECTROSTATICS */
454 velec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
455 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
457 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
459 /* Update potential sum for this i atom from the interaction with this j atom. */
460 velec = _mm_and_ps(velec,cutoff_mask);
461 velec = _mm_andnot_ps(dummy_mask,velec);
462 velecsum = _mm_add_ps(velecsum,velec);
466 fscal = _mm_and_ps(fscal,cutoff_mask);
468 fscal = _mm_andnot_ps(dummy_mask,fscal);
470 /* Calculate temporary vectorial force */
471 tx = _mm_mul_ps(fscal,dx10);
472 ty = _mm_mul_ps(fscal,dy10);
473 tz = _mm_mul_ps(fscal,dz10);
475 /* Update vectorial force */
476 fix1 = _mm_add_ps(fix1,tx);
477 fiy1 = _mm_add_ps(fiy1,ty);
478 fiz1 = _mm_add_ps(fiz1,tz);
480 fjx0 = _mm_add_ps(fjx0,tx);
481 fjy0 = _mm_add_ps(fjy0,ty);
482 fjz0 = _mm_add_ps(fjz0,tz);
486 /**************************
487 * CALCULATE INTERACTIONS *
488 **************************/
490 if (gmx_mm_any_lt(rsq20,rcutoff2))
493 /* Compute parameters for interactions between i and j atoms */
494 qq20 = _mm_mul_ps(iq2,jq0);
496 /* REACTION-FIELD ELECTROSTATICS */
497 velec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
498 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
500 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
502 /* Update potential sum for this i atom from the interaction with this j atom. */
503 velec = _mm_and_ps(velec,cutoff_mask);
504 velec = _mm_andnot_ps(dummy_mask,velec);
505 velecsum = _mm_add_ps(velecsum,velec);
509 fscal = _mm_and_ps(fscal,cutoff_mask);
511 fscal = _mm_andnot_ps(dummy_mask,fscal);
513 /* Calculate temporary vectorial force */
514 tx = _mm_mul_ps(fscal,dx20);
515 ty = _mm_mul_ps(fscal,dy20);
516 tz = _mm_mul_ps(fscal,dz20);
518 /* Update vectorial force */
519 fix2 = _mm_add_ps(fix2,tx);
520 fiy2 = _mm_add_ps(fiy2,ty);
521 fiz2 = _mm_add_ps(fiz2,tz);
523 fjx0 = _mm_add_ps(fjx0,tx);
524 fjy0 = _mm_add_ps(fjy0,ty);
525 fjz0 = _mm_add_ps(fjz0,tz);
529 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
530 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
531 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
532 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
534 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
536 /* Inner loop uses 108 flops */
539 /* End of innermost loop */
541 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
542 f+i_coord_offset,fshift+i_shift_offset);
545 /* Update potential energies */
546 gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
548 /* Increment number of inner iterations */
549 inneriter += j_index_end - j_index_start;
551 /* Outer loop uses 19 flops */
554 /* Increment number of outer iterations */
557 /* Update outer/inner flops */
559 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*108);
562 * Gromacs nonbonded kernel: nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_sse4_1_single
563 * Electrostatics interaction: ReactionField
564 * VdW interaction: None
565 * Geometry: Water3-Particle
566 * Calculate force/pot: Force
569 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_sse4_1_single
570 (t_nblist * gmx_restrict nlist,
571 rvec * gmx_restrict xx,
572 rvec * gmx_restrict ff,
573 t_forcerec * gmx_restrict fr,
574 t_mdatoms * gmx_restrict mdatoms,
575 nb_kernel_data_t * gmx_restrict kernel_data,
576 t_nrnb * gmx_restrict nrnb)
578 /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
579 * just 0 for non-waters.
580 * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
581 * jnr indices corresponding to data put in the four positions in the SIMD register.
583 int i_shift_offset,i_coord_offset,outeriter,inneriter;
584 int j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
585 int jnrA,jnrB,jnrC,jnrD;
586 int jnrlistA,jnrlistB,jnrlistC,jnrlistD;
587 int j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
588 int *iinr,*jindex,*jjnr,*shiftidx,*gid;
590 real *shiftvec,*fshift,*x,*f;
591 real *fjptrA,*fjptrB,*fjptrC,*fjptrD;
593 __m128 tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
595 __m128 ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
597 __m128 ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
599 __m128 ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
600 int vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
601 __m128 jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
602 __m128 dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
603 __m128 dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
604 __m128 dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
605 __m128 velec,felec,velecsum,facel,crf,krf,krf2;
607 __m128 dummy_mask,cutoff_mask;
608 __m128 signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
609 __m128 one = _mm_set1_ps(1.0);
610 __m128 two = _mm_set1_ps(2.0);
616 jindex = nlist->jindex;
618 shiftidx = nlist->shift;
620 shiftvec = fr->shift_vec[0];
621 fshift = fr->fshift[0];
622 facel = _mm_set1_ps(fr->epsfac);
623 charge = mdatoms->chargeA;
624 krf = _mm_set1_ps(fr->ic->k_rf);
625 krf2 = _mm_set1_ps(fr->ic->k_rf*2.0);
626 crf = _mm_set1_ps(fr->ic->c_rf);
628 /* Setup water-specific parameters */
629 inr = nlist->iinr[0];
630 iq0 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
631 iq1 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
632 iq2 = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
634 /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
635 rcutoff_scalar = fr->rcoulomb;
636 rcutoff = _mm_set1_ps(rcutoff_scalar);
637 rcutoff2 = _mm_mul_ps(rcutoff,rcutoff);
639 /* Avoid stupid compiler warnings */
640 jnrA = jnrB = jnrC = jnrD = 0;
649 for(iidx=0;iidx<4*DIM;iidx++)
654 /* Start outer loop over neighborlists */
655 for(iidx=0; iidx<nri; iidx++)
657 /* Load shift vector for this list */
658 i_shift_offset = DIM*shiftidx[iidx];
660 /* Load limits for loop over neighbors */
661 j_index_start = jindex[iidx];
662 j_index_end = jindex[iidx+1];
664 /* Get outer coordinate index */
666 i_coord_offset = DIM*inr;
668 /* Load i particle coords and add shift vector */
669 gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
670 &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
672 fix0 = _mm_setzero_ps();
673 fiy0 = _mm_setzero_ps();
674 fiz0 = _mm_setzero_ps();
675 fix1 = _mm_setzero_ps();
676 fiy1 = _mm_setzero_ps();
677 fiz1 = _mm_setzero_ps();
678 fix2 = _mm_setzero_ps();
679 fiy2 = _mm_setzero_ps();
680 fiz2 = _mm_setzero_ps();
682 /* Start inner kernel loop */
683 for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
686 /* Get j neighbor index, and coordinate index */
691 j_coord_offsetA = DIM*jnrA;
692 j_coord_offsetB = DIM*jnrB;
693 j_coord_offsetC = DIM*jnrC;
694 j_coord_offsetD = DIM*jnrD;
696 /* load j atom coordinates */
697 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
698 x+j_coord_offsetC,x+j_coord_offsetD,
701 /* Calculate displacement vector */
702 dx00 = _mm_sub_ps(ix0,jx0);
703 dy00 = _mm_sub_ps(iy0,jy0);
704 dz00 = _mm_sub_ps(iz0,jz0);
705 dx10 = _mm_sub_ps(ix1,jx0);
706 dy10 = _mm_sub_ps(iy1,jy0);
707 dz10 = _mm_sub_ps(iz1,jz0);
708 dx20 = _mm_sub_ps(ix2,jx0);
709 dy20 = _mm_sub_ps(iy2,jy0);
710 dz20 = _mm_sub_ps(iz2,jz0);
712 /* Calculate squared distance and things based on it */
713 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
714 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
715 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
717 rinv00 = gmx_mm_invsqrt_ps(rsq00);
718 rinv10 = gmx_mm_invsqrt_ps(rsq10);
719 rinv20 = gmx_mm_invsqrt_ps(rsq20);
721 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
722 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
723 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
725 /* Load parameters for j particles */
726 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
727 charge+jnrC+0,charge+jnrD+0);
729 fjx0 = _mm_setzero_ps();
730 fjy0 = _mm_setzero_ps();
731 fjz0 = _mm_setzero_ps();
733 /**************************
734 * CALCULATE INTERACTIONS *
735 **************************/
737 if (gmx_mm_any_lt(rsq00,rcutoff2))
740 /* Compute parameters for interactions between i and j atoms */
741 qq00 = _mm_mul_ps(iq0,jq0);
743 /* REACTION-FIELD ELECTROSTATICS */
744 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
746 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
750 fscal = _mm_and_ps(fscal,cutoff_mask);
752 /* Calculate temporary vectorial force */
753 tx = _mm_mul_ps(fscal,dx00);
754 ty = _mm_mul_ps(fscal,dy00);
755 tz = _mm_mul_ps(fscal,dz00);
757 /* Update vectorial force */
758 fix0 = _mm_add_ps(fix0,tx);
759 fiy0 = _mm_add_ps(fiy0,ty);
760 fiz0 = _mm_add_ps(fiz0,tz);
762 fjx0 = _mm_add_ps(fjx0,tx);
763 fjy0 = _mm_add_ps(fjy0,ty);
764 fjz0 = _mm_add_ps(fjz0,tz);
768 /**************************
769 * CALCULATE INTERACTIONS *
770 **************************/
772 if (gmx_mm_any_lt(rsq10,rcutoff2))
775 /* Compute parameters for interactions between i and j atoms */
776 qq10 = _mm_mul_ps(iq1,jq0);
778 /* REACTION-FIELD ELECTROSTATICS */
779 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
781 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
785 fscal = _mm_and_ps(fscal,cutoff_mask);
787 /* Calculate temporary vectorial force */
788 tx = _mm_mul_ps(fscal,dx10);
789 ty = _mm_mul_ps(fscal,dy10);
790 tz = _mm_mul_ps(fscal,dz10);
792 /* Update vectorial force */
793 fix1 = _mm_add_ps(fix1,tx);
794 fiy1 = _mm_add_ps(fiy1,ty);
795 fiz1 = _mm_add_ps(fiz1,tz);
797 fjx0 = _mm_add_ps(fjx0,tx);
798 fjy0 = _mm_add_ps(fjy0,ty);
799 fjz0 = _mm_add_ps(fjz0,tz);
803 /**************************
804 * CALCULATE INTERACTIONS *
805 **************************/
807 if (gmx_mm_any_lt(rsq20,rcutoff2))
810 /* Compute parameters for interactions between i and j atoms */
811 qq20 = _mm_mul_ps(iq2,jq0);
813 /* REACTION-FIELD ELECTROSTATICS */
814 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
816 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
820 fscal = _mm_and_ps(fscal,cutoff_mask);
822 /* Calculate temporary vectorial force */
823 tx = _mm_mul_ps(fscal,dx20);
824 ty = _mm_mul_ps(fscal,dy20);
825 tz = _mm_mul_ps(fscal,dz20);
827 /* Update vectorial force */
828 fix2 = _mm_add_ps(fix2,tx);
829 fiy2 = _mm_add_ps(fiy2,ty);
830 fiz2 = _mm_add_ps(fiz2,tz);
832 fjx0 = _mm_add_ps(fjx0,tx);
833 fjy0 = _mm_add_ps(fjy0,ty);
834 fjz0 = _mm_add_ps(fjz0,tz);
838 fjptrA = f+j_coord_offsetA;
839 fjptrB = f+j_coord_offsetB;
840 fjptrC = f+j_coord_offsetC;
841 fjptrD = f+j_coord_offsetD;
843 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
845 /* Inner loop uses 90 flops */
851 /* Get j neighbor index, and coordinate index */
852 jnrlistA = jjnr[jidx];
853 jnrlistB = jjnr[jidx+1];
854 jnrlistC = jjnr[jidx+2];
855 jnrlistD = jjnr[jidx+3];
856 /* Sign of each element will be negative for non-real atoms.
857 * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
858 * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
860 dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
861 jnrA = (jnrlistA>=0) ? jnrlistA : 0;
862 jnrB = (jnrlistB>=0) ? jnrlistB : 0;
863 jnrC = (jnrlistC>=0) ? jnrlistC : 0;
864 jnrD = (jnrlistD>=0) ? jnrlistD : 0;
865 j_coord_offsetA = DIM*jnrA;
866 j_coord_offsetB = DIM*jnrB;
867 j_coord_offsetC = DIM*jnrC;
868 j_coord_offsetD = DIM*jnrD;
870 /* load j atom coordinates */
871 gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
872 x+j_coord_offsetC,x+j_coord_offsetD,
875 /* Calculate displacement vector */
876 dx00 = _mm_sub_ps(ix0,jx0);
877 dy00 = _mm_sub_ps(iy0,jy0);
878 dz00 = _mm_sub_ps(iz0,jz0);
879 dx10 = _mm_sub_ps(ix1,jx0);
880 dy10 = _mm_sub_ps(iy1,jy0);
881 dz10 = _mm_sub_ps(iz1,jz0);
882 dx20 = _mm_sub_ps(ix2,jx0);
883 dy20 = _mm_sub_ps(iy2,jy0);
884 dz20 = _mm_sub_ps(iz2,jz0);
886 /* Calculate squared distance and things based on it */
887 rsq00 = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
888 rsq10 = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
889 rsq20 = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
891 rinv00 = gmx_mm_invsqrt_ps(rsq00);
892 rinv10 = gmx_mm_invsqrt_ps(rsq10);
893 rinv20 = gmx_mm_invsqrt_ps(rsq20);
895 rinvsq00 = _mm_mul_ps(rinv00,rinv00);
896 rinvsq10 = _mm_mul_ps(rinv10,rinv10);
897 rinvsq20 = _mm_mul_ps(rinv20,rinv20);
899 /* Load parameters for j particles */
900 jq0 = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
901 charge+jnrC+0,charge+jnrD+0);
903 fjx0 = _mm_setzero_ps();
904 fjy0 = _mm_setzero_ps();
905 fjz0 = _mm_setzero_ps();
907 /**************************
908 * CALCULATE INTERACTIONS *
909 **************************/
911 if (gmx_mm_any_lt(rsq00,rcutoff2))
914 /* Compute parameters for interactions between i and j atoms */
915 qq00 = _mm_mul_ps(iq0,jq0);
917 /* REACTION-FIELD ELECTROSTATICS */
918 felec = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
920 cutoff_mask = _mm_cmplt_ps(rsq00,rcutoff2);
924 fscal = _mm_and_ps(fscal,cutoff_mask);
926 fscal = _mm_andnot_ps(dummy_mask,fscal);
928 /* Calculate temporary vectorial force */
929 tx = _mm_mul_ps(fscal,dx00);
930 ty = _mm_mul_ps(fscal,dy00);
931 tz = _mm_mul_ps(fscal,dz00);
933 /* Update vectorial force */
934 fix0 = _mm_add_ps(fix0,tx);
935 fiy0 = _mm_add_ps(fiy0,ty);
936 fiz0 = _mm_add_ps(fiz0,tz);
938 fjx0 = _mm_add_ps(fjx0,tx);
939 fjy0 = _mm_add_ps(fjy0,ty);
940 fjz0 = _mm_add_ps(fjz0,tz);
944 /**************************
945 * CALCULATE INTERACTIONS *
946 **************************/
948 if (gmx_mm_any_lt(rsq10,rcutoff2))
951 /* Compute parameters for interactions between i and j atoms */
952 qq10 = _mm_mul_ps(iq1,jq0);
954 /* REACTION-FIELD ELECTROSTATICS */
955 felec = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
957 cutoff_mask = _mm_cmplt_ps(rsq10,rcutoff2);
961 fscal = _mm_and_ps(fscal,cutoff_mask);
963 fscal = _mm_andnot_ps(dummy_mask,fscal);
965 /* Calculate temporary vectorial force */
966 tx = _mm_mul_ps(fscal,dx10);
967 ty = _mm_mul_ps(fscal,dy10);
968 tz = _mm_mul_ps(fscal,dz10);
970 /* Update vectorial force */
971 fix1 = _mm_add_ps(fix1,tx);
972 fiy1 = _mm_add_ps(fiy1,ty);
973 fiz1 = _mm_add_ps(fiz1,tz);
975 fjx0 = _mm_add_ps(fjx0,tx);
976 fjy0 = _mm_add_ps(fjy0,ty);
977 fjz0 = _mm_add_ps(fjz0,tz);
981 /**************************
982 * CALCULATE INTERACTIONS *
983 **************************/
985 if (gmx_mm_any_lt(rsq20,rcutoff2))
988 /* Compute parameters for interactions between i and j atoms */
989 qq20 = _mm_mul_ps(iq2,jq0);
991 /* REACTION-FIELD ELECTROSTATICS */
992 felec = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
994 cutoff_mask = _mm_cmplt_ps(rsq20,rcutoff2);
998 fscal = _mm_and_ps(fscal,cutoff_mask);
1000 fscal = _mm_andnot_ps(dummy_mask,fscal);
1002 /* Calculate temporary vectorial force */
1003 tx = _mm_mul_ps(fscal,dx20);
1004 ty = _mm_mul_ps(fscal,dy20);
1005 tz = _mm_mul_ps(fscal,dz20);
1007 /* Update vectorial force */
1008 fix2 = _mm_add_ps(fix2,tx);
1009 fiy2 = _mm_add_ps(fiy2,ty);
1010 fiz2 = _mm_add_ps(fiz2,tz);
1012 fjx0 = _mm_add_ps(fjx0,tx);
1013 fjy0 = _mm_add_ps(fjy0,ty);
1014 fjz0 = _mm_add_ps(fjz0,tz);
1018 fjptrA = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1019 fjptrB = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1020 fjptrC = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1021 fjptrD = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1023 gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1025 /* Inner loop uses 90 flops */
1028 /* End of innermost loop */
1030 gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1031 f+i_coord_offset,fshift+i_shift_offset);
1033 /* Increment number of inner iterations */
1034 inneriter += j_index_end - j_index_start;
1036 /* Outer loop uses 18 flops */
1039 /* Increment number of outer iterations */
1042 /* Update outer/inner flops */
1044 inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*90);