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