edb3898a1117d5c5b90a8048d9bec234cc3f6952
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_sse4_1_single / nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_sse4_1_single.c
1 /*
2  * Note: this file was generated by the Gromacs sse4_1_single kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
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
13  *
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
17  * later version.
18  *
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.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 #include "gmx_math_x86_sse4_1_single.h"
34 #include "kernelutil_x86_sse4_1_single.h"
35
36 /*
37  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_VF_sse4_1_single
38  * Electrostatics interaction: ReactionField
39  * VdW interaction:            LennardJones
40  * Geometry:                   Water4-Particle
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_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)
52 {
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.
57      */
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;
64     real             rcutoff_scalar;
65     real             *shiftvec,*fshift,*x,*f;
66     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
67     real             scratch[4*DIM];
68     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
69     int              vdwioffset0;
70     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
71     int              vdwioffset1;
72     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
73     int              vdwioffset2;
74     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75     int              vdwioffset3;
76     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
77     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
78     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
79     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
80     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
81     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
82     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
83     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
84     real             *charge;
85     int              nvdwtype;
86     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
87     int              *vdwtype;
88     real             *vdwparam;
89     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
90     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
91     __m128           dummy_mask,cutoff_mask;
92     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
93     __m128           one     = _mm_set1_ps(1.0);
94     __m128           two     = _mm_set1_ps(2.0);
95     x                = xx[0];
96     f                = ff[0];
97
98     nri              = nlist->nri;
99     iinr             = nlist->iinr;
100     jindex           = nlist->jindex;
101     jjnr             = nlist->jjnr;
102     shiftidx         = nlist->shift;
103     gid              = nlist->gid;
104     shiftvec         = fr->shift_vec[0];
105     fshift           = fr->fshift[0];
106     facel            = _mm_set1_ps(fr->epsfac);
107     charge           = mdatoms->chargeA;
108     krf              = _mm_set1_ps(fr->ic->k_rf);
109     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
110     crf              = _mm_set1_ps(fr->ic->c_rf);
111     nvdwtype         = fr->ntype;
112     vdwparam         = fr->nbfp;
113     vdwtype          = mdatoms->typeA;
114
115     /* Setup water-specific parameters */
116     inr              = nlist->iinr[0];
117     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
118     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
119     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
120     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
121
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->rcoulomb;
124     rcutoff          = _mm_set1_ps(rcutoff_scalar);
125     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
126
127     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
128     rvdw             = _mm_set1_ps(fr->rvdw);
129
130     /* Avoid stupid compiler warnings */
131     jnrA = jnrB = jnrC = jnrD = 0;
132     j_coord_offsetA = 0;
133     j_coord_offsetB = 0;
134     j_coord_offsetC = 0;
135     j_coord_offsetD = 0;
136
137     outeriter        = 0;
138     inneriter        = 0;
139
140     for(iidx=0;iidx<4*DIM;iidx++)
141     {
142         scratch[iidx] = 0.0;
143     }
144
145     /* Start outer loop over neighborlists */
146     for(iidx=0; iidx<nri; iidx++)
147     {
148         /* Load shift vector for this list */
149         i_shift_offset   = DIM*shiftidx[iidx];
150
151         /* Load limits for loop over neighbors */
152         j_index_start    = jindex[iidx];
153         j_index_end      = jindex[iidx+1];
154
155         /* Get outer coordinate index */
156         inr              = iinr[iidx];
157         i_coord_offset   = DIM*inr;
158
159         /* Load i particle coords and add shift vector */
160         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
161                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
162
163         fix0             = _mm_setzero_ps();
164         fiy0             = _mm_setzero_ps();
165         fiz0             = _mm_setzero_ps();
166         fix1             = _mm_setzero_ps();
167         fiy1             = _mm_setzero_ps();
168         fiz1             = _mm_setzero_ps();
169         fix2             = _mm_setzero_ps();
170         fiy2             = _mm_setzero_ps();
171         fiz2             = _mm_setzero_ps();
172         fix3             = _mm_setzero_ps();
173         fiy3             = _mm_setzero_ps();
174         fiz3             = _mm_setzero_ps();
175
176         /* Reset potential sums */
177         velecsum         = _mm_setzero_ps();
178         vvdwsum          = _mm_setzero_ps();
179
180         /* Start inner kernel loop */
181         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
182         {
183
184             /* Get j neighbor index, and coordinate index */
185             jnrA             = jjnr[jidx];
186             jnrB             = jjnr[jidx+1];
187             jnrC             = jjnr[jidx+2];
188             jnrD             = jjnr[jidx+3];
189             j_coord_offsetA  = DIM*jnrA;
190             j_coord_offsetB  = DIM*jnrB;
191             j_coord_offsetC  = DIM*jnrC;
192             j_coord_offsetD  = DIM*jnrD;
193
194             /* load j atom coordinates */
195             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
196                                               x+j_coord_offsetC,x+j_coord_offsetD,
197                                               &jx0,&jy0,&jz0);
198
199             /* Calculate displacement vector */
200             dx00             = _mm_sub_ps(ix0,jx0);
201             dy00             = _mm_sub_ps(iy0,jy0);
202             dz00             = _mm_sub_ps(iz0,jz0);
203             dx10             = _mm_sub_ps(ix1,jx0);
204             dy10             = _mm_sub_ps(iy1,jy0);
205             dz10             = _mm_sub_ps(iz1,jz0);
206             dx20             = _mm_sub_ps(ix2,jx0);
207             dy20             = _mm_sub_ps(iy2,jy0);
208             dz20             = _mm_sub_ps(iz2,jz0);
209             dx30             = _mm_sub_ps(ix3,jx0);
210             dy30             = _mm_sub_ps(iy3,jy0);
211             dz30             = _mm_sub_ps(iz3,jz0);
212
213             /* Calculate squared distance and things based on it */
214             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
215             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
216             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
217             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
218
219             rinv10           = gmx_mm_invsqrt_ps(rsq10);
220             rinv20           = gmx_mm_invsqrt_ps(rsq20);
221             rinv30           = gmx_mm_invsqrt_ps(rsq30);
222
223             rinvsq00         = gmx_mm_inv_ps(rsq00);
224             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
225             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
226             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
227
228             /* Load parameters for j particles */
229             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
230                                                               charge+jnrC+0,charge+jnrD+0);
231             vdwjidx0A        = 2*vdwtype[jnrA+0];
232             vdwjidx0B        = 2*vdwtype[jnrB+0];
233             vdwjidx0C        = 2*vdwtype[jnrC+0];
234             vdwjidx0D        = 2*vdwtype[jnrD+0];
235
236             fjx0             = _mm_setzero_ps();
237             fjy0             = _mm_setzero_ps();
238             fjz0             = _mm_setzero_ps();
239
240             /**************************
241              * CALCULATE INTERACTIONS *
242              **************************/
243
244             if (gmx_mm_any_lt(rsq00,rcutoff2))
245             {
246
247             /* Compute parameters for interactions between i and j atoms */
248             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
249                                          vdwparam+vdwioffset0+vdwjidx0B,
250                                          vdwparam+vdwioffset0+vdwjidx0C,
251                                          vdwparam+vdwioffset0+vdwjidx0D,
252                                          &c6_00,&c12_00);
253
254             /* LENNARD-JONES DISPERSION/REPULSION */
255
256             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
257             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
258             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
259             vvdw             = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
260                                           _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
261             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
262
263             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
264
265             /* Update potential sum for this i atom from the interaction with this j atom. */
266             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
267             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
268
269             fscal            = fvdw;
270
271             fscal            = _mm_and_ps(fscal,cutoff_mask);
272
273             /* Calculate temporary vectorial force */
274             tx               = _mm_mul_ps(fscal,dx00);
275             ty               = _mm_mul_ps(fscal,dy00);
276             tz               = _mm_mul_ps(fscal,dz00);
277
278             /* Update vectorial force */
279             fix0             = _mm_add_ps(fix0,tx);
280             fiy0             = _mm_add_ps(fiy0,ty);
281             fiz0             = _mm_add_ps(fiz0,tz);
282
283             fjx0             = _mm_add_ps(fjx0,tx);
284             fjy0             = _mm_add_ps(fjy0,ty);
285             fjz0             = _mm_add_ps(fjz0,tz);
286
287             }
288
289             /**************************
290              * CALCULATE INTERACTIONS *
291              **************************/
292
293             if (gmx_mm_any_lt(rsq10,rcutoff2))
294             {
295
296             /* Compute parameters for interactions between i and j atoms */
297             qq10             = _mm_mul_ps(iq1,jq0);
298
299             /* REACTION-FIELD ELECTROSTATICS */
300             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
301             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
302
303             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
304
305             /* Update potential sum for this i atom from the interaction with this j atom. */
306             velec            = _mm_and_ps(velec,cutoff_mask);
307             velecsum         = _mm_add_ps(velecsum,velec);
308
309             fscal            = felec;
310
311             fscal            = _mm_and_ps(fscal,cutoff_mask);
312
313             /* Calculate temporary vectorial force */
314             tx               = _mm_mul_ps(fscal,dx10);
315             ty               = _mm_mul_ps(fscal,dy10);
316             tz               = _mm_mul_ps(fscal,dz10);
317
318             /* Update vectorial force */
319             fix1             = _mm_add_ps(fix1,tx);
320             fiy1             = _mm_add_ps(fiy1,ty);
321             fiz1             = _mm_add_ps(fiz1,tz);
322
323             fjx0             = _mm_add_ps(fjx0,tx);
324             fjy0             = _mm_add_ps(fjy0,ty);
325             fjz0             = _mm_add_ps(fjz0,tz);
326
327             }
328
329             /**************************
330              * CALCULATE INTERACTIONS *
331              **************************/
332
333             if (gmx_mm_any_lt(rsq20,rcutoff2))
334             {
335
336             /* Compute parameters for interactions between i and j atoms */
337             qq20             = _mm_mul_ps(iq2,jq0);
338
339             /* REACTION-FIELD ELECTROSTATICS */
340             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
341             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
342
343             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
344
345             /* Update potential sum for this i atom from the interaction with this j atom. */
346             velec            = _mm_and_ps(velec,cutoff_mask);
347             velecsum         = _mm_add_ps(velecsum,velec);
348
349             fscal            = felec;
350
351             fscal            = _mm_and_ps(fscal,cutoff_mask);
352
353             /* Calculate temporary vectorial force */
354             tx               = _mm_mul_ps(fscal,dx20);
355             ty               = _mm_mul_ps(fscal,dy20);
356             tz               = _mm_mul_ps(fscal,dz20);
357
358             /* Update vectorial force */
359             fix2             = _mm_add_ps(fix2,tx);
360             fiy2             = _mm_add_ps(fiy2,ty);
361             fiz2             = _mm_add_ps(fiz2,tz);
362
363             fjx0             = _mm_add_ps(fjx0,tx);
364             fjy0             = _mm_add_ps(fjy0,ty);
365             fjz0             = _mm_add_ps(fjz0,tz);
366
367             }
368
369             /**************************
370              * CALCULATE INTERACTIONS *
371              **************************/
372
373             if (gmx_mm_any_lt(rsq30,rcutoff2))
374             {
375
376             /* Compute parameters for interactions between i and j atoms */
377             qq30             = _mm_mul_ps(iq3,jq0);
378
379             /* REACTION-FIELD ELECTROSTATICS */
380             velec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
381             felec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
382
383             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
384
385             /* Update potential sum for this i atom from the interaction with this j atom. */
386             velec            = _mm_and_ps(velec,cutoff_mask);
387             velecsum         = _mm_add_ps(velecsum,velec);
388
389             fscal            = felec;
390
391             fscal            = _mm_and_ps(fscal,cutoff_mask);
392
393             /* Calculate temporary vectorial force */
394             tx               = _mm_mul_ps(fscal,dx30);
395             ty               = _mm_mul_ps(fscal,dy30);
396             tz               = _mm_mul_ps(fscal,dz30);
397
398             /* Update vectorial force */
399             fix3             = _mm_add_ps(fix3,tx);
400             fiy3             = _mm_add_ps(fiy3,ty);
401             fiz3             = _mm_add_ps(fiz3,tz);
402
403             fjx0             = _mm_add_ps(fjx0,tx);
404             fjy0             = _mm_add_ps(fjy0,ty);
405             fjz0             = _mm_add_ps(fjz0,tz);
406
407             }
408
409             fjptrA             = f+j_coord_offsetA;
410             fjptrB             = f+j_coord_offsetB;
411             fjptrC             = f+j_coord_offsetC;
412             fjptrD             = f+j_coord_offsetD;
413
414             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
415
416             /* Inner loop uses 149 flops */
417         }
418
419         if(jidx<j_index_end)
420         {
421
422             /* Get j neighbor index, and coordinate index */
423             jnrlistA         = jjnr[jidx];
424             jnrlistB         = jjnr[jidx+1];
425             jnrlistC         = jjnr[jidx+2];
426             jnrlistD         = jjnr[jidx+3];
427             /* Sign of each element will be negative for non-real atoms.
428              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
429              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
430              */
431             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
432             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
433             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
434             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
435             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
436             j_coord_offsetA  = DIM*jnrA;
437             j_coord_offsetB  = DIM*jnrB;
438             j_coord_offsetC  = DIM*jnrC;
439             j_coord_offsetD  = DIM*jnrD;
440
441             /* load j atom coordinates */
442             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
443                                               x+j_coord_offsetC,x+j_coord_offsetD,
444                                               &jx0,&jy0,&jz0);
445
446             /* Calculate displacement vector */
447             dx00             = _mm_sub_ps(ix0,jx0);
448             dy00             = _mm_sub_ps(iy0,jy0);
449             dz00             = _mm_sub_ps(iz0,jz0);
450             dx10             = _mm_sub_ps(ix1,jx0);
451             dy10             = _mm_sub_ps(iy1,jy0);
452             dz10             = _mm_sub_ps(iz1,jz0);
453             dx20             = _mm_sub_ps(ix2,jx0);
454             dy20             = _mm_sub_ps(iy2,jy0);
455             dz20             = _mm_sub_ps(iz2,jz0);
456             dx30             = _mm_sub_ps(ix3,jx0);
457             dy30             = _mm_sub_ps(iy3,jy0);
458             dz30             = _mm_sub_ps(iz3,jz0);
459
460             /* Calculate squared distance and things based on it */
461             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
462             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
463             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
464             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
465
466             rinv10           = gmx_mm_invsqrt_ps(rsq10);
467             rinv20           = gmx_mm_invsqrt_ps(rsq20);
468             rinv30           = gmx_mm_invsqrt_ps(rsq30);
469
470             rinvsq00         = gmx_mm_inv_ps(rsq00);
471             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
472             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
473             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
474
475             /* Load parameters for j particles */
476             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
477                                                               charge+jnrC+0,charge+jnrD+0);
478             vdwjidx0A        = 2*vdwtype[jnrA+0];
479             vdwjidx0B        = 2*vdwtype[jnrB+0];
480             vdwjidx0C        = 2*vdwtype[jnrC+0];
481             vdwjidx0D        = 2*vdwtype[jnrD+0];
482
483             fjx0             = _mm_setzero_ps();
484             fjy0             = _mm_setzero_ps();
485             fjz0             = _mm_setzero_ps();
486
487             /**************************
488              * CALCULATE INTERACTIONS *
489              **************************/
490
491             if (gmx_mm_any_lt(rsq00,rcutoff2))
492             {
493
494             /* Compute parameters for interactions between i and j atoms */
495             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
496                                          vdwparam+vdwioffset0+vdwjidx0B,
497                                          vdwparam+vdwioffset0+vdwjidx0C,
498                                          vdwparam+vdwioffset0+vdwjidx0D,
499                                          &c6_00,&c12_00);
500
501             /* LENNARD-JONES DISPERSION/REPULSION */
502
503             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
504             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
505             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
506             vvdw             = _mm_sub_ps(_mm_mul_ps( _mm_sub_ps(vvdw12 , _mm_mul_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
507                                           _mm_mul_ps( _mm_sub_ps(vvdw6,_mm_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
508             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
509
510             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
511
512             /* Update potential sum for this i atom from the interaction with this j atom. */
513             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
514             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
515             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
516
517             fscal            = fvdw;
518
519             fscal            = _mm_and_ps(fscal,cutoff_mask);
520
521             fscal            = _mm_andnot_ps(dummy_mask,fscal);
522
523             /* Calculate temporary vectorial force */
524             tx               = _mm_mul_ps(fscal,dx00);
525             ty               = _mm_mul_ps(fscal,dy00);
526             tz               = _mm_mul_ps(fscal,dz00);
527
528             /* Update vectorial force */
529             fix0             = _mm_add_ps(fix0,tx);
530             fiy0             = _mm_add_ps(fiy0,ty);
531             fiz0             = _mm_add_ps(fiz0,tz);
532
533             fjx0             = _mm_add_ps(fjx0,tx);
534             fjy0             = _mm_add_ps(fjy0,ty);
535             fjz0             = _mm_add_ps(fjz0,tz);
536
537             }
538
539             /**************************
540              * CALCULATE INTERACTIONS *
541              **************************/
542
543             if (gmx_mm_any_lt(rsq10,rcutoff2))
544             {
545
546             /* Compute parameters for interactions between i and j atoms */
547             qq10             = _mm_mul_ps(iq1,jq0);
548
549             /* REACTION-FIELD ELECTROSTATICS */
550             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
551             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
552
553             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
554
555             /* Update potential sum for this i atom from the interaction with this j atom. */
556             velec            = _mm_and_ps(velec,cutoff_mask);
557             velec            = _mm_andnot_ps(dummy_mask,velec);
558             velecsum         = _mm_add_ps(velecsum,velec);
559
560             fscal            = felec;
561
562             fscal            = _mm_and_ps(fscal,cutoff_mask);
563
564             fscal            = _mm_andnot_ps(dummy_mask,fscal);
565
566             /* Calculate temporary vectorial force */
567             tx               = _mm_mul_ps(fscal,dx10);
568             ty               = _mm_mul_ps(fscal,dy10);
569             tz               = _mm_mul_ps(fscal,dz10);
570
571             /* Update vectorial force */
572             fix1             = _mm_add_ps(fix1,tx);
573             fiy1             = _mm_add_ps(fiy1,ty);
574             fiz1             = _mm_add_ps(fiz1,tz);
575
576             fjx0             = _mm_add_ps(fjx0,tx);
577             fjy0             = _mm_add_ps(fjy0,ty);
578             fjz0             = _mm_add_ps(fjz0,tz);
579
580             }
581
582             /**************************
583              * CALCULATE INTERACTIONS *
584              **************************/
585
586             if (gmx_mm_any_lt(rsq20,rcutoff2))
587             {
588
589             /* Compute parameters for interactions between i and j atoms */
590             qq20             = _mm_mul_ps(iq2,jq0);
591
592             /* REACTION-FIELD ELECTROSTATICS */
593             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
594             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
595
596             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
597
598             /* Update potential sum for this i atom from the interaction with this j atom. */
599             velec            = _mm_and_ps(velec,cutoff_mask);
600             velec            = _mm_andnot_ps(dummy_mask,velec);
601             velecsum         = _mm_add_ps(velecsum,velec);
602
603             fscal            = felec;
604
605             fscal            = _mm_and_ps(fscal,cutoff_mask);
606
607             fscal            = _mm_andnot_ps(dummy_mask,fscal);
608
609             /* Calculate temporary vectorial force */
610             tx               = _mm_mul_ps(fscal,dx20);
611             ty               = _mm_mul_ps(fscal,dy20);
612             tz               = _mm_mul_ps(fscal,dz20);
613
614             /* Update vectorial force */
615             fix2             = _mm_add_ps(fix2,tx);
616             fiy2             = _mm_add_ps(fiy2,ty);
617             fiz2             = _mm_add_ps(fiz2,tz);
618
619             fjx0             = _mm_add_ps(fjx0,tx);
620             fjy0             = _mm_add_ps(fjy0,ty);
621             fjz0             = _mm_add_ps(fjz0,tz);
622
623             }
624
625             /**************************
626              * CALCULATE INTERACTIONS *
627              **************************/
628
629             if (gmx_mm_any_lt(rsq30,rcutoff2))
630             {
631
632             /* Compute parameters for interactions between i and j atoms */
633             qq30             = _mm_mul_ps(iq3,jq0);
634
635             /* REACTION-FIELD ELECTROSTATICS */
636             velec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_add_ps(rinv30,_mm_mul_ps(krf,rsq30)),crf));
637             felec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
638
639             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
640
641             /* Update potential sum for this i atom from the interaction with this j atom. */
642             velec            = _mm_and_ps(velec,cutoff_mask);
643             velec            = _mm_andnot_ps(dummy_mask,velec);
644             velecsum         = _mm_add_ps(velecsum,velec);
645
646             fscal            = felec;
647
648             fscal            = _mm_and_ps(fscal,cutoff_mask);
649
650             fscal            = _mm_andnot_ps(dummy_mask,fscal);
651
652             /* Calculate temporary vectorial force */
653             tx               = _mm_mul_ps(fscal,dx30);
654             ty               = _mm_mul_ps(fscal,dy30);
655             tz               = _mm_mul_ps(fscal,dz30);
656
657             /* Update vectorial force */
658             fix3             = _mm_add_ps(fix3,tx);
659             fiy3             = _mm_add_ps(fiy3,ty);
660             fiz3             = _mm_add_ps(fiz3,tz);
661
662             fjx0             = _mm_add_ps(fjx0,tx);
663             fjy0             = _mm_add_ps(fjy0,ty);
664             fjz0             = _mm_add_ps(fjz0,tz);
665
666             }
667
668             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
669             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
670             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
671             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
672
673             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
674
675             /* Inner loop uses 149 flops */
676         }
677
678         /* End of innermost loop */
679
680         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
681                                               f+i_coord_offset,fshift+i_shift_offset);
682
683         ggid                        = gid[iidx];
684         /* Update potential energies */
685         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
686         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
687
688         /* Increment number of inner iterations */
689         inneriter                  += j_index_end - j_index_start;
690
691         /* Outer loop uses 26 flops */
692     }
693
694     /* Increment number of outer iterations */
695     outeriter        += nri;
696
697     /* Update outer/inner flops */
698
699     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*149);
700 }
701 /*
702  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_sse4_1_single
703  * Electrostatics interaction: ReactionField
704  * VdW interaction:            LennardJones
705  * Geometry:                   Water4-Particle
706  * Calculate force/pot:        Force
707  */
708 void
709 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_sse4_1_single
710                     (t_nblist * gmx_restrict                nlist,
711                      rvec * gmx_restrict                    xx,
712                      rvec * gmx_restrict                    ff,
713                      t_forcerec * gmx_restrict              fr,
714                      t_mdatoms * gmx_restrict               mdatoms,
715                      nb_kernel_data_t * gmx_restrict        kernel_data,
716                      t_nrnb * gmx_restrict                  nrnb)
717 {
718     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
719      * just 0 for non-waters.
720      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
721      * jnr indices corresponding to data put in the four positions in the SIMD register.
722      */
723     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
724     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
725     int              jnrA,jnrB,jnrC,jnrD;
726     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
727     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
728     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
729     real             rcutoff_scalar;
730     real             *shiftvec,*fshift,*x,*f;
731     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
732     real             scratch[4*DIM];
733     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
734     int              vdwioffset0;
735     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
736     int              vdwioffset1;
737     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
738     int              vdwioffset2;
739     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
740     int              vdwioffset3;
741     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
742     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
743     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
744     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
745     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
746     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
747     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
748     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
749     real             *charge;
750     int              nvdwtype;
751     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
752     int              *vdwtype;
753     real             *vdwparam;
754     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
755     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
756     __m128           dummy_mask,cutoff_mask;
757     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
758     __m128           one     = _mm_set1_ps(1.0);
759     __m128           two     = _mm_set1_ps(2.0);
760     x                = xx[0];
761     f                = ff[0];
762
763     nri              = nlist->nri;
764     iinr             = nlist->iinr;
765     jindex           = nlist->jindex;
766     jjnr             = nlist->jjnr;
767     shiftidx         = nlist->shift;
768     gid              = nlist->gid;
769     shiftvec         = fr->shift_vec[0];
770     fshift           = fr->fshift[0];
771     facel            = _mm_set1_ps(fr->epsfac);
772     charge           = mdatoms->chargeA;
773     krf              = _mm_set1_ps(fr->ic->k_rf);
774     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
775     crf              = _mm_set1_ps(fr->ic->c_rf);
776     nvdwtype         = fr->ntype;
777     vdwparam         = fr->nbfp;
778     vdwtype          = mdatoms->typeA;
779
780     /* Setup water-specific parameters */
781     inr              = nlist->iinr[0];
782     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
783     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
784     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
785     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
786
787     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
788     rcutoff_scalar   = fr->rcoulomb;
789     rcutoff          = _mm_set1_ps(rcutoff_scalar);
790     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
791
792     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
793     rvdw             = _mm_set1_ps(fr->rvdw);
794
795     /* Avoid stupid compiler warnings */
796     jnrA = jnrB = jnrC = jnrD = 0;
797     j_coord_offsetA = 0;
798     j_coord_offsetB = 0;
799     j_coord_offsetC = 0;
800     j_coord_offsetD = 0;
801
802     outeriter        = 0;
803     inneriter        = 0;
804
805     for(iidx=0;iidx<4*DIM;iidx++)
806     {
807         scratch[iidx] = 0.0;
808     }
809
810     /* Start outer loop over neighborlists */
811     for(iidx=0; iidx<nri; iidx++)
812     {
813         /* Load shift vector for this list */
814         i_shift_offset   = DIM*shiftidx[iidx];
815
816         /* Load limits for loop over neighbors */
817         j_index_start    = jindex[iidx];
818         j_index_end      = jindex[iidx+1];
819
820         /* Get outer coordinate index */
821         inr              = iinr[iidx];
822         i_coord_offset   = DIM*inr;
823
824         /* Load i particle coords and add shift vector */
825         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
826                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
827
828         fix0             = _mm_setzero_ps();
829         fiy0             = _mm_setzero_ps();
830         fiz0             = _mm_setzero_ps();
831         fix1             = _mm_setzero_ps();
832         fiy1             = _mm_setzero_ps();
833         fiz1             = _mm_setzero_ps();
834         fix2             = _mm_setzero_ps();
835         fiy2             = _mm_setzero_ps();
836         fiz2             = _mm_setzero_ps();
837         fix3             = _mm_setzero_ps();
838         fiy3             = _mm_setzero_ps();
839         fiz3             = _mm_setzero_ps();
840
841         /* Start inner kernel loop */
842         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
843         {
844
845             /* Get j neighbor index, and coordinate index */
846             jnrA             = jjnr[jidx];
847             jnrB             = jjnr[jidx+1];
848             jnrC             = jjnr[jidx+2];
849             jnrD             = jjnr[jidx+3];
850             j_coord_offsetA  = DIM*jnrA;
851             j_coord_offsetB  = DIM*jnrB;
852             j_coord_offsetC  = DIM*jnrC;
853             j_coord_offsetD  = DIM*jnrD;
854
855             /* load j atom coordinates */
856             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
857                                               x+j_coord_offsetC,x+j_coord_offsetD,
858                                               &jx0,&jy0,&jz0);
859
860             /* Calculate displacement vector */
861             dx00             = _mm_sub_ps(ix0,jx0);
862             dy00             = _mm_sub_ps(iy0,jy0);
863             dz00             = _mm_sub_ps(iz0,jz0);
864             dx10             = _mm_sub_ps(ix1,jx0);
865             dy10             = _mm_sub_ps(iy1,jy0);
866             dz10             = _mm_sub_ps(iz1,jz0);
867             dx20             = _mm_sub_ps(ix2,jx0);
868             dy20             = _mm_sub_ps(iy2,jy0);
869             dz20             = _mm_sub_ps(iz2,jz0);
870             dx30             = _mm_sub_ps(ix3,jx0);
871             dy30             = _mm_sub_ps(iy3,jy0);
872             dz30             = _mm_sub_ps(iz3,jz0);
873
874             /* Calculate squared distance and things based on it */
875             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
876             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
877             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
878             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
879
880             rinv10           = gmx_mm_invsqrt_ps(rsq10);
881             rinv20           = gmx_mm_invsqrt_ps(rsq20);
882             rinv30           = gmx_mm_invsqrt_ps(rsq30);
883
884             rinvsq00         = gmx_mm_inv_ps(rsq00);
885             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
886             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
887             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
888
889             /* Load parameters for j particles */
890             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
891                                                               charge+jnrC+0,charge+jnrD+0);
892             vdwjidx0A        = 2*vdwtype[jnrA+0];
893             vdwjidx0B        = 2*vdwtype[jnrB+0];
894             vdwjidx0C        = 2*vdwtype[jnrC+0];
895             vdwjidx0D        = 2*vdwtype[jnrD+0];
896
897             fjx0             = _mm_setzero_ps();
898             fjy0             = _mm_setzero_ps();
899             fjz0             = _mm_setzero_ps();
900
901             /**************************
902              * CALCULATE INTERACTIONS *
903              **************************/
904
905             if (gmx_mm_any_lt(rsq00,rcutoff2))
906             {
907
908             /* Compute parameters for interactions between i and j atoms */
909             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
910                                          vdwparam+vdwioffset0+vdwjidx0B,
911                                          vdwparam+vdwioffset0+vdwjidx0C,
912                                          vdwparam+vdwioffset0+vdwjidx0D,
913                                          &c6_00,&c12_00);
914
915             /* LENNARD-JONES DISPERSION/REPULSION */
916
917             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
918             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
919
920             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
921
922             fscal            = fvdw;
923
924             fscal            = _mm_and_ps(fscal,cutoff_mask);
925
926             /* Calculate temporary vectorial force */
927             tx               = _mm_mul_ps(fscal,dx00);
928             ty               = _mm_mul_ps(fscal,dy00);
929             tz               = _mm_mul_ps(fscal,dz00);
930
931             /* Update vectorial force */
932             fix0             = _mm_add_ps(fix0,tx);
933             fiy0             = _mm_add_ps(fiy0,ty);
934             fiz0             = _mm_add_ps(fiz0,tz);
935
936             fjx0             = _mm_add_ps(fjx0,tx);
937             fjy0             = _mm_add_ps(fjy0,ty);
938             fjz0             = _mm_add_ps(fjz0,tz);
939
940             }
941
942             /**************************
943              * CALCULATE INTERACTIONS *
944              **************************/
945
946             if (gmx_mm_any_lt(rsq10,rcutoff2))
947             {
948
949             /* Compute parameters for interactions between i and j atoms */
950             qq10             = _mm_mul_ps(iq1,jq0);
951
952             /* REACTION-FIELD ELECTROSTATICS */
953             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
954
955             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
956
957             fscal            = felec;
958
959             fscal            = _mm_and_ps(fscal,cutoff_mask);
960
961             /* Calculate temporary vectorial force */
962             tx               = _mm_mul_ps(fscal,dx10);
963             ty               = _mm_mul_ps(fscal,dy10);
964             tz               = _mm_mul_ps(fscal,dz10);
965
966             /* Update vectorial force */
967             fix1             = _mm_add_ps(fix1,tx);
968             fiy1             = _mm_add_ps(fiy1,ty);
969             fiz1             = _mm_add_ps(fiz1,tz);
970
971             fjx0             = _mm_add_ps(fjx0,tx);
972             fjy0             = _mm_add_ps(fjy0,ty);
973             fjz0             = _mm_add_ps(fjz0,tz);
974
975             }
976
977             /**************************
978              * CALCULATE INTERACTIONS *
979              **************************/
980
981             if (gmx_mm_any_lt(rsq20,rcutoff2))
982             {
983
984             /* Compute parameters for interactions between i and j atoms */
985             qq20             = _mm_mul_ps(iq2,jq0);
986
987             /* REACTION-FIELD ELECTROSTATICS */
988             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
989
990             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
991
992             fscal            = felec;
993
994             fscal            = _mm_and_ps(fscal,cutoff_mask);
995
996             /* Calculate temporary vectorial force */
997             tx               = _mm_mul_ps(fscal,dx20);
998             ty               = _mm_mul_ps(fscal,dy20);
999             tz               = _mm_mul_ps(fscal,dz20);
1000
1001             /* Update vectorial force */
1002             fix2             = _mm_add_ps(fix2,tx);
1003             fiy2             = _mm_add_ps(fiy2,ty);
1004             fiz2             = _mm_add_ps(fiz2,tz);
1005
1006             fjx0             = _mm_add_ps(fjx0,tx);
1007             fjy0             = _mm_add_ps(fjy0,ty);
1008             fjz0             = _mm_add_ps(fjz0,tz);
1009
1010             }
1011
1012             /**************************
1013              * CALCULATE INTERACTIONS *
1014              **************************/
1015
1016             if (gmx_mm_any_lt(rsq30,rcutoff2))
1017             {
1018
1019             /* Compute parameters for interactions between i and j atoms */
1020             qq30             = _mm_mul_ps(iq3,jq0);
1021
1022             /* REACTION-FIELD ELECTROSTATICS */
1023             felec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
1024
1025             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
1026
1027             fscal            = felec;
1028
1029             fscal            = _mm_and_ps(fscal,cutoff_mask);
1030
1031             /* Calculate temporary vectorial force */
1032             tx               = _mm_mul_ps(fscal,dx30);
1033             ty               = _mm_mul_ps(fscal,dy30);
1034             tz               = _mm_mul_ps(fscal,dz30);
1035
1036             /* Update vectorial force */
1037             fix3             = _mm_add_ps(fix3,tx);
1038             fiy3             = _mm_add_ps(fiy3,ty);
1039             fiz3             = _mm_add_ps(fiz3,tz);
1040
1041             fjx0             = _mm_add_ps(fjx0,tx);
1042             fjy0             = _mm_add_ps(fjy0,ty);
1043             fjz0             = _mm_add_ps(fjz0,tz);
1044
1045             }
1046
1047             fjptrA             = f+j_coord_offsetA;
1048             fjptrB             = f+j_coord_offsetB;
1049             fjptrC             = f+j_coord_offsetC;
1050             fjptrD             = f+j_coord_offsetD;
1051
1052             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1053
1054             /* Inner loop uses 120 flops */
1055         }
1056
1057         if(jidx<j_index_end)
1058         {
1059
1060             /* Get j neighbor index, and coordinate index */
1061             jnrlistA         = jjnr[jidx];
1062             jnrlistB         = jjnr[jidx+1];
1063             jnrlistC         = jjnr[jidx+2];
1064             jnrlistD         = jjnr[jidx+3];
1065             /* Sign of each element will be negative for non-real atoms.
1066              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1067              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1068              */
1069             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1070             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1071             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1072             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1073             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1074             j_coord_offsetA  = DIM*jnrA;
1075             j_coord_offsetB  = DIM*jnrB;
1076             j_coord_offsetC  = DIM*jnrC;
1077             j_coord_offsetD  = DIM*jnrD;
1078
1079             /* load j atom coordinates */
1080             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1081                                               x+j_coord_offsetC,x+j_coord_offsetD,
1082                                               &jx0,&jy0,&jz0);
1083
1084             /* Calculate displacement vector */
1085             dx00             = _mm_sub_ps(ix0,jx0);
1086             dy00             = _mm_sub_ps(iy0,jy0);
1087             dz00             = _mm_sub_ps(iz0,jz0);
1088             dx10             = _mm_sub_ps(ix1,jx0);
1089             dy10             = _mm_sub_ps(iy1,jy0);
1090             dz10             = _mm_sub_ps(iz1,jz0);
1091             dx20             = _mm_sub_ps(ix2,jx0);
1092             dy20             = _mm_sub_ps(iy2,jy0);
1093             dz20             = _mm_sub_ps(iz2,jz0);
1094             dx30             = _mm_sub_ps(ix3,jx0);
1095             dy30             = _mm_sub_ps(iy3,jy0);
1096             dz30             = _mm_sub_ps(iz3,jz0);
1097
1098             /* Calculate squared distance and things based on it */
1099             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1100             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1101             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1102             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1103
1104             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1105             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1106             rinv30           = gmx_mm_invsqrt_ps(rsq30);
1107
1108             rinvsq00         = gmx_mm_inv_ps(rsq00);
1109             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1110             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1111             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
1112
1113             /* Load parameters for j particles */
1114             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1115                                                               charge+jnrC+0,charge+jnrD+0);
1116             vdwjidx0A        = 2*vdwtype[jnrA+0];
1117             vdwjidx0B        = 2*vdwtype[jnrB+0];
1118             vdwjidx0C        = 2*vdwtype[jnrC+0];
1119             vdwjidx0D        = 2*vdwtype[jnrD+0];
1120
1121             fjx0             = _mm_setzero_ps();
1122             fjy0             = _mm_setzero_ps();
1123             fjz0             = _mm_setzero_ps();
1124
1125             /**************************
1126              * CALCULATE INTERACTIONS *
1127              **************************/
1128
1129             if (gmx_mm_any_lt(rsq00,rcutoff2))
1130             {
1131
1132             /* Compute parameters for interactions between i and j atoms */
1133             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1134                                          vdwparam+vdwioffset0+vdwjidx0B,
1135                                          vdwparam+vdwioffset0+vdwjidx0C,
1136                                          vdwparam+vdwioffset0+vdwjidx0D,
1137                                          &c6_00,&c12_00);
1138
1139             /* LENNARD-JONES DISPERSION/REPULSION */
1140
1141             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1142             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1143
1144             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1145
1146             fscal            = fvdw;
1147
1148             fscal            = _mm_and_ps(fscal,cutoff_mask);
1149
1150             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1151
1152             /* Calculate temporary vectorial force */
1153             tx               = _mm_mul_ps(fscal,dx00);
1154             ty               = _mm_mul_ps(fscal,dy00);
1155             tz               = _mm_mul_ps(fscal,dz00);
1156
1157             /* Update vectorial force */
1158             fix0             = _mm_add_ps(fix0,tx);
1159             fiy0             = _mm_add_ps(fiy0,ty);
1160             fiz0             = _mm_add_ps(fiz0,tz);
1161
1162             fjx0             = _mm_add_ps(fjx0,tx);
1163             fjy0             = _mm_add_ps(fjy0,ty);
1164             fjz0             = _mm_add_ps(fjz0,tz);
1165
1166             }
1167
1168             /**************************
1169              * CALCULATE INTERACTIONS *
1170              **************************/
1171
1172             if (gmx_mm_any_lt(rsq10,rcutoff2))
1173             {
1174
1175             /* Compute parameters for interactions between i and j atoms */
1176             qq10             = _mm_mul_ps(iq1,jq0);
1177
1178             /* REACTION-FIELD ELECTROSTATICS */
1179             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1180
1181             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1182
1183             fscal            = felec;
1184
1185             fscal            = _mm_and_ps(fscal,cutoff_mask);
1186
1187             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1188
1189             /* Calculate temporary vectorial force */
1190             tx               = _mm_mul_ps(fscal,dx10);
1191             ty               = _mm_mul_ps(fscal,dy10);
1192             tz               = _mm_mul_ps(fscal,dz10);
1193
1194             /* Update vectorial force */
1195             fix1             = _mm_add_ps(fix1,tx);
1196             fiy1             = _mm_add_ps(fiy1,ty);
1197             fiz1             = _mm_add_ps(fiz1,tz);
1198
1199             fjx0             = _mm_add_ps(fjx0,tx);
1200             fjy0             = _mm_add_ps(fjy0,ty);
1201             fjz0             = _mm_add_ps(fjz0,tz);
1202
1203             }
1204
1205             /**************************
1206              * CALCULATE INTERACTIONS *
1207              **************************/
1208
1209             if (gmx_mm_any_lt(rsq20,rcutoff2))
1210             {
1211
1212             /* Compute parameters for interactions between i and j atoms */
1213             qq20             = _mm_mul_ps(iq2,jq0);
1214
1215             /* REACTION-FIELD ELECTROSTATICS */
1216             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1217
1218             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1219
1220             fscal            = felec;
1221
1222             fscal            = _mm_and_ps(fscal,cutoff_mask);
1223
1224             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1225
1226             /* Calculate temporary vectorial force */
1227             tx               = _mm_mul_ps(fscal,dx20);
1228             ty               = _mm_mul_ps(fscal,dy20);
1229             tz               = _mm_mul_ps(fscal,dz20);
1230
1231             /* Update vectorial force */
1232             fix2             = _mm_add_ps(fix2,tx);
1233             fiy2             = _mm_add_ps(fiy2,ty);
1234             fiz2             = _mm_add_ps(fiz2,tz);
1235
1236             fjx0             = _mm_add_ps(fjx0,tx);
1237             fjy0             = _mm_add_ps(fjy0,ty);
1238             fjz0             = _mm_add_ps(fjz0,tz);
1239
1240             }
1241
1242             /**************************
1243              * CALCULATE INTERACTIONS *
1244              **************************/
1245
1246             if (gmx_mm_any_lt(rsq30,rcutoff2))
1247             {
1248
1249             /* Compute parameters for interactions between i and j atoms */
1250             qq30             = _mm_mul_ps(iq3,jq0);
1251
1252             /* REACTION-FIELD ELECTROSTATICS */
1253             felec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_mul_ps(rinv30,rinvsq30),krf2));
1254
1255             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
1256
1257             fscal            = felec;
1258
1259             fscal            = _mm_and_ps(fscal,cutoff_mask);
1260
1261             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1262
1263             /* Calculate temporary vectorial force */
1264             tx               = _mm_mul_ps(fscal,dx30);
1265             ty               = _mm_mul_ps(fscal,dy30);
1266             tz               = _mm_mul_ps(fscal,dz30);
1267
1268             /* Update vectorial force */
1269             fix3             = _mm_add_ps(fix3,tx);
1270             fiy3             = _mm_add_ps(fiy3,ty);
1271             fiz3             = _mm_add_ps(fiz3,tz);
1272
1273             fjx0             = _mm_add_ps(fjx0,tx);
1274             fjy0             = _mm_add_ps(fjy0,ty);
1275             fjz0             = _mm_add_ps(fjz0,tz);
1276
1277             }
1278
1279             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1280             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1281             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1282             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1283
1284             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1285
1286             /* Inner loop uses 120 flops */
1287         }
1288
1289         /* End of innermost loop */
1290
1291         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1292                                               f+i_coord_offset,fshift+i_shift_offset);
1293
1294         /* Increment number of inner iterations */
1295         inneriter                  += j_index_end - j_index_start;
1296
1297         /* Outer loop uses 24 flops */
1298     }
1299
1300     /* Increment number of outer iterations */
1301     outeriter        += nri;
1302
1303     /* Update outer/inner flops */
1304
1305     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*120);
1306 }