Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRF_VdwLJ_GeomW4W4_avx_128_fma_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 avx_128_fma_double kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 #include "gromacs/simd/math_x86_avx_128_fma_double.h"
48 #include "kernelutil_x86_avx_128_fma_double.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwLJ_GeomW4W4_VF_avx_128_fma_double
52  * Electrostatics interaction: ReactionField
53  * VdW interaction:            LennardJones
54  * Geometry:                   Water4-Water4
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecRF_VdwLJ_GeomW4W4_VF_avx_128_fma_double
59                     (t_nblist                    * gmx_restrict       nlist,
60                      rvec                        * gmx_restrict          xx,
61                      rvec                        * gmx_restrict          ff,
62                      t_forcerec                  * gmx_restrict          fr,
63                      t_mdatoms                   * gmx_restrict     mdatoms,
64                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65                      t_nrnb                      * gmx_restrict        nrnb)
66 {
67     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68      * just 0 for non-waters.
69      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
70      * jnr indices corresponding to data put in the four positions in the SIMD register.
71      */
72     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
73     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74     int              jnrA,jnrB;
75     int              j_coord_offsetA,j_coord_offsetB;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80     int              vdwioffset0;
81     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82     int              vdwioffset1;
83     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
84     int              vdwioffset2;
85     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
86     int              vdwioffset3;
87     __m128d          ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
88     int              vdwjidx0A,vdwjidx0B;
89     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90     int              vdwjidx1A,vdwjidx1B;
91     __m128d          jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
92     int              vdwjidx2A,vdwjidx2B;
93     __m128d          jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
94     int              vdwjidx3A,vdwjidx3B;
95     __m128d          jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
96     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
97     __m128d          dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
98     __m128d          dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
99     __m128d          dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
100     __m128d          dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
101     __m128d          dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
102     __m128d          dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
103     __m128d          dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
104     __m128d          dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
105     __m128d          dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
106     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
107     real             *charge;
108     int              nvdwtype;
109     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
110     int              *vdwtype;
111     real             *vdwparam;
112     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
113     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
114     __m128d          dummy_mask,cutoff_mask;
115     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
116     __m128d          one     = _mm_set1_pd(1.0);
117     __m128d          two     = _mm_set1_pd(2.0);
118     x                = xx[0];
119     f                = ff[0];
120
121     nri              = nlist->nri;
122     iinr             = nlist->iinr;
123     jindex           = nlist->jindex;
124     jjnr             = nlist->jjnr;
125     shiftidx         = nlist->shift;
126     gid              = nlist->gid;
127     shiftvec         = fr->shift_vec[0];
128     fshift           = fr->fshift[0];
129     facel            = _mm_set1_pd(fr->epsfac);
130     charge           = mdatoms->chargeA;
131     krf              = _mm_set1_pd(fr->ic->k_rf);
132     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
133     crf              = _mm_set1_pd(fr->ic->c_rf);
134     nvdwtype         = fr->ntype;
135     vdwparam         = fr->nbfp;
136     vdwtype          = mdatoms->typeA;
137
138     /* Setup water-specific parameters */
139     inr              = nlist->iinr[0];
140     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
141     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
142     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
143     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
144
145     jq1              = _mm_set1_pd(charge[inr+1]);
146     jq2              = _mm_set1_pd(charge[inr+2]);
147     jq3              = _mm_set1_pd(charge[inr+3]);
148     vdwjidx0A        = 2*vdwtype[inr+0];
149     c6_00            = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A]);
150     c12_00           = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A+1]);
151     qq11             = _mm_mul_pd(iq1,jq1);
152     qq12             = _mm_mul_pd(iq1,jq2);
153     qq13             = _mm_mul_pd(iq1,jq3);
154     qq21             = _mm_mul_pd(iq2,jq1);
155     qq22             = _mm_mul_pd(iq2,jq2);
156     qq23             = _mm_mul_pd(iq2,jq3);
157     qq31             = _mm_mul_pd(iq3,jq1);
158     qq32             = _mm_mul_pd(iq3,jq2);
159     qq33             = _mm_mul_pd(iq3,jq3);
160
161     /* Avoid stupid compiler warnings */
162     jnrA = jnrB = 0;
163     j_coord_offsetA = 0;
164     j_coord_offsetB = 0;
165
166     outeriter        = 0;
167     inneriter        = 0;
168
169     /* Start outer loop over neighborlists */
170     for(iidx=0; iidx<nri; iidx++)
171     {
172         /* Load shift vector for this list */
173         i_shift_offset   = DIM*shiftidx[iidx];
174
175         /* Load limits for loop over neighbors */
176         j_index_start    = jindex[iidx];
177         j_index_end      = jindex[iidx+1];
178
179         /* Get outer coordinate index */
180         inr              = iinr[iidx];
181         i_coord_offset   = DIM*inr;
182
183         /* Load i particle coords and add shift vector */
184         gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
185                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
186
187         fix0             = _mm_setzero_pd();
188         fiy0             = _mm_setzero_pd();
189         fiz0             = _mm_setzero_pd();
190         fix1             = _mm_setzero_pd();
191         fiy1             = _mm_setzero_pd();
192         fiz1             = _mm_setzero_pd();
193         fix2             = _mm_setzero_pd();
194         fiy2             = _mm_setzero_pd();
195         fiz2             = _mm_setzero_pd();
196         fix3             = _mm_setzero_pd();
197         fiy3             = _mm_setzero_pd();
198         fiz3             = _mm_setzero_pd();
199
200         /* Reset potential sums */
201         velecsum         = _mm_setzero_pd();
202         vvdwsum          = _mm_setzero_pd();
203
204         /* Start inner kernel loop */
205         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
206         {
207
208             /* Get j neighbor index, and coordinate index */
209             jnrA             = jjnr[jidx];
210             jnrB             = jjnr[jidx+1];
211             j_coord_offsetA  = DIM*jnrA;
212             j_coord_offsetB  = DIM*jnrB;
213
214             /* load j atom coordinates */
215             gmx_mm_load_4rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
216                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
217                                               &jy2,&jz2,&jx3,&jy3,&jz3);
218
219             /* Calculate displacement vector */
220             dx00             = _mm_sub_pd(ix0,jx0);
221             dy00             = _mm_sub_pd(iy0,jy0);
222             dz00             = _mm_sub_pd(iz0,jz0);
223             dx11             = _mm_sub_pd(ix1,jx1);
224             dy11             = _mm_sub_pd(iy1,jy1);
225             dz11             = _mm_sub_pd(iz1,jz1);
226             dx12             = _mm_sub_pd(ix1,jx2);
227             dy12             = _mm_sub_pd(iy1,jy2);
228             dz12             = _mm_sub_pd(iz1,jz2);
229             dx13             = _mm_sub_pd(ix1,jx3);
230             dy13             = _mm_sub_pd(iy1,jy3);
231             dz13             = _mm_sub_pd(iz1,jz3);
232             dx21             = _mm_sub_pd(ix2,jx1);
233             dy21             = _mm_sub_pd(iy2,jy1);
234             dz21             = _mm_sub_pd(iz2,jz1);
235             dx22             = _mm_sub_pd(ix2,jx2);
236             dy22             = _mm_sub_pd(iy2,jy2);
237             dz22             = _mm_sub_pd(iz2,jz2);
238             dx23             = _mm_sub_pd(ix2,jx3);
239             dy23             = _mm_sub_pd(iy2,jy3);
240             dz23             = _mm_sub_pd(iz2,jz3);
241             dx31             = _mm_sub_pd(ix3,jx1);
242             dy31             = _mm_sub_pd(iy3,jy1);
243             dz31             = _mm_sub_pd(iz3,jz1);
244             dx32             = _mm_sub_pd(ix3,jx2);
245             dy32             = _mm_sub_pd(iy3,jy2);
246             dz32             = _mm_sub_pd(iz3,jz2);
247             dx33             = _mm_sub_pd(ix3,jx3);
248             dy33             = _mm_sub_pd(iy3,jy3);
249             dz33             = _mm_sub_pd(iz3,jz3);
250
251             /* Calculate squared distance and things based on it */
252             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
253             rsq11            = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
254             rsq12            = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
255             rsq13            = gmx_mm_calc_rsq_pd(dx13,dy13,dz13);
256             rsq21            = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
257             rsq22            = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
258             rsq23            = gmx_mm_calc_rsq_pd(dx23,dy23,dz23);
259             rsq31            = gmx_mm_calc_rsq_pd(dx31,dy31,dz31);
260             rsq32            = gmx_mm_calc_rsq_pd(dx32,dy32,dz32);
261             rsq33            = gmx_mm_calc_rsq_pd(dx33,dy33,dz33);
262
263             rinv11           = gmx_mm_invsqrt_pd(rsq11);
264             rinv12           = gmx_mm_invsqrt_pd(rsq12);
265             rinv13           = gmx_mm_invsqrt_pd(rsq13);
266             rinv21           = gmx_mm_invsqrt_pd(rsq21);
267             rinv22           = gmx_mm_invsqrt_pd(rsq22);
268             rinv23           = gmx_mm_invsqrt_pd(rsq23);
269             rinv31           = gmx_mm_invsqrt_pd(rsq31);
270             rinv32           = gmx_mm_invsqrt_pd(rsq32);
271             rinv33           = gmx_mm_invsqrt_pd(rsq33);
272
273             rinvsq00         = gmx_mm_inv_pd(rsq00);
274             rinvsq11         = _mm_mul_pd(rinv11,rinv11);
275             rinvsq12         = _mm_mul_pd(rinv12,rinv12);
276             rinvsq13         = _mm_mul_pd(rinv13,rinv13);
277             rinvsq21         = _mm_mul_pd(rinv21,rinv21);
278             rinvsq22         = _mm_mul_pd(rinv22,rinv22);
279             rinvsq23         = _mm_mul_pd(rinv23,rinv23);
280             rinvsq31         = _mm_mul_pd(rinv31,rinv31);
281             rinvsq32         = _mm_mul_pd(rinv32,rinv32);
282             rinvsq33         = _mm_mul_pd(rinv33,rinv33);
283
284             fjx0             = _mm_setzero_pd();
285             fjy0             = _mm_setzero_pd();
286             fjz0             = _mm_setzero_pd();
287             fjx1             = _mm_setzero_pd();
288             fjy1             = _mm_setzero_pd();
289             fjz1             = _mm_setzero_pd();
290             fjx2             = _mm_setzero_pd();
291             fjy2             = _mm_setzero_pd();
292             fjz2             = _mm_setzero_pd();
293             fjx3             = _mm_setzero_pd();
294             fjy3             = _mm_setzero_pd();
295             fjz3             = _mm_setzero_pd();
296
297             /**************************
298              * CALCULATE INTERACTIONS *
299              **************************/
300
301             /* LENNARD-JONES DISPERSION/REPULSION */
302
303             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
304             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
305             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
306             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
307             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
308
309             /* Update potential sum for this i atom from the interaction with this j atom. */
310             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
311
312             fscal            = fvdw;
313
314             /* Update vectorial force */
315             fix0             = _mm_macc_pd(dx00,fscal,fix0);
316             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
317             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
318             
319             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
320             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
321             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
322
323             /**************************
324              * CALCULATE INTERACTIONS *
325              **************************/
326
327             /* REACTION-FIELD ELECTROSTATICS */
328             velec            = _mm_mul_pd(qq11,_mm_sub_pd(_mm_macc_pd(krf,rsq11,rinv11),crf));
329             felec            = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
330
331             /* Update potential sum for this i atom from the interaction with this j atom. */
332             velecsum         = _mm_add_pd(velecsum,velec);
333
334             fscal            = felec;
335
336             /* Update vectorial force */
337             fix1             = _mm_macc_pd(dx11,fscal,fix1);
338             fiy1             = _mm_macc_pd(dy11,fscal,fiy1);
339             fiz1             = _mm_macc_pd(dz11,fscal,fiz1);
340             
341             fjx1             = _mm_macc_pd(dx11,fscal,fjx1);
342             fjy1             = _mm_macc_pd(dy11,fscal,fjy1);
343             fjz1             = _mm_macc_pd(dz11,fscal,fjz1);
344
345             /**************************
346              * CALCULATE INTERACTIONS *
347              **************************/
348
349             /* REACTION-FIELD ELECTROSTATICS */
350             velec            = _mm_mul_pd(qq12,_mm_sub_pd(_mm_macc_pd(krf,rsq12,rinv12),crf));
351             felec            = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
352
353             /* Update potential sum for this i atom from the interaction with this j atom. */
354             velecsum         = _mm_add_pd(velecsum,velec);
355
356             fscal            = felec;
357
358             /* Update vectorial force */
359             fix1             = _mm_macc_pd(dx12,fscal,fix1);
360             fiy1             = _mm_macc_pd(dy12,fscal,fiy1);
361             fiz1             = _mm_macc_pd(dz12,fscal,fiz1);
362             
363             fjx2             = _mm_macc_pd(dx12,fscal,fjx2);
364             fjy2             = _mm_macc_pd(dy12,fscal,fjy2);
365             fjz2             = _mm_macc_pd(dz12,fscal,fjz2);
366
367             /**************************
368              * CALCULATE INTERACTIONS *
369              **************************/
370
371             /* REACTION-FIELD ELECTROSTATICS */
372             velec            = _mm_mul_pd(qq13,_mm_sub_pd(_mm_macc_pd(krf,rsq13,rinv13),crf));
373             felec            = _mm_mul_pd(qq13,_mm_msub_pd(rinv13,rinvsq13,krf2));
374
375             /* Update potential sum for this i atom from the interaction with this j atom. */
376             velecsum         = _mm_add_pd(velecsum,velec);
377
378             fscal            = felec;
379
380             /* Update vectorial force */
381             fix1             = _mm_macc_pd(dx13,fscal,fix1);
382             fiy1             = _mm_macc_pd(dy13,fscal,fiy1);
383             fiz1             = _mm_macc_pd(dz13,fscal,fiz1);
384             
385             fjx3             = _mm_macc_pd(dx13,fscal,fjx3);
386             fjy3             = _mm_macc_pd(dy13,fscal,fjy3);
387             fjz3             = _mm_macc_pd(dz13,fscal,fjz3);
388
389             /**************************
390              * CALCULATE INTERACTIONS *
391              **************************/
392
393             /* REACTION-FIELD ELECTROSTATICS */
394             velec            = _mm_mul_pd(qq21,_mm_sub_pd(_mm_macc_pd(krf,rsq21,rinv21),crf));
395             felec            = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
396
397             /* Update potential sum for this i atom from the interaction with this j atom. */
398             velecsum         = _mm_add_pd(velecsum,velec);
399
400             fscal            = felec;
401
402             /* Update vectorial force */
403             fix2             = _mm_macc_pd(dx21,fscal,fix2);
404             fiy2             = _mm_macc_pd(dy21,fscal,fiy2);
405             fiz2             = _mm_macc_pd(dz21,fscal,fiz2);
406             
407             fjx1             = _mm_macc_pd(dx21,fscal,fjx1);
408             fjy1             = _mm_macc_pd(dy21,fscal,fjy1);
409             fjz1             = _mm_macc_pd(dz21,fscal,fjz1);
410
411             /**************************
412              * CALCULATE INTERACTIONS *
413              **************************/
414
415             /* REACTION-FIELD ELECTROSTATICS */
416             velec            = _mm_mul_pd(qq22,_mm_sub_pd(_mm_macc_pd(krf,rsq22,rinv22),crf));
417             felec            = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
418
419             /* Update potential sum for this i atom from the interaction with this j atom. */
420             velecsum         = _mm_add_pd(velecsum,velec);
421
422             fscal            = felec;
423
424             /* Update vectorial force */
425             fix2             = _mm_macc_pd(dx22,fscal,fix2);
426             fiy2             = _mm_macc_pd(dy22,fscal,fiy2);
427             fiz2             = _mm_macc_pd(dz22,fscal,fiz2);
428             
429             fjx2             = _mm_macc_pd(dx22,fscal,fjx2);
430             fjy2             = _mm_macc_pd(dy22,fscal,fjy2);
431             fjz2             = _mm_macc_pd(dz22,fscal,fjz2);
432
433             /**************************
434              * CALCULATE INTERACTIONS *
435              **************************/
436
437             /* REACTION-FIELD ELECTROSTATICS */
438             velec            = _mm_mul_pd(qq23,_mm_sub_pd(_mm_macc_pd(krf,rsq23,rinv23),crf));
439             felec            = _mm_mul_pd(qq23,_mm_msub_pd(rinv23,rinvsq23,krf2));
440
441             /* Update potential sum for this i atom from the interaction with this j atom. */
442             velecsum         = _mm_add_pd(velecsum,velec);
443
444             fscal            = felec;
445
446             /* Update vectorial force */
447             fix2             = _mm_macc_pd(dx23,fscal,fix2);
448             fiy2             = _mm_macc_pd(dy23,fscal,fiy2);
449             fiz2             = _mm_macc_pd(dz23,fscal,fiz2);
450             
451             fjx3             = _mm_macc_pd(dx23,fscal,fjx3);
452             fjy3             = _mm_macc_pd(dy23,fscal,fjy3);
453             fjz3             = _mm_macc_pd(dz23,fscal,fjz3);
454
455             /**************************
456              * CALCULATE INTERACTIONS *
457              **************************/
458
459             /* REACTION-FIELD ELECTROSTATICS */
460             velec            = _mm_mul_pd(qq31,_mm_sub_pd(_mm_macc_pd(krf,rsq31,rinv31),crf));
461             felec            = _mm_mul_pd(qq31,_mm_msub_pd(rinv31,rinvsq31,krf2));
462
463             /* Update potential sum for this i atom from the interaction with this j atom. */
464             velecsum         = _mm_add_pd(velecsum,velec);
465
466             fscal            = felec;
467
468             /* Update vectorial force */
469             fix3             = _mm_macc_pd(dx31,fscal,fix3);
470             fiy3             = _mm_macc_pd(dy31,fscal,fiy3);
471             fiz3             = _mm_macc_pd(dz31,fscal,fiz3);
472             
473             fjx1             = _mm_macc_pd(dx31,fscal,fjx1);
474             fjy1             = _mm_macc_pd(dy31,fscal,fjy1);
475             fjz1             = _mm_macc_pd(dz31,fscal,fjz1);
476
477             /**************************
478              * CALCULATE INTERACTIONS *
479              **************************/
480
481             /* REACTION-FIELD ELECTROSTATICS */
482             velec            = _mm_mul_pd(qq32,_mm_sub_pd(_mm_macc_pd(krf,rsq32,rinv32),crf));
483             felec            = _mm_mul_pd(qq32,_mm_msub_pd(rinv32,rinvsq32,krf2));
484
485             /* Update potential sum for this i atom from the interaction with this j atom. */
486             velecsum         = _mm_add_pd(velecsum,velec);
487
488             fscal            = felec;
489
490             /* Update vectorial force */
491             fix3             = _mm_macc_pd(dx32,fscal,fix3);
492             fiy3             = _mm_macc_pd(dy32,fscal,fiy3);
493             fiz3             = _mm_macc_pd(dz32,fscal,fiz3);
494             
495             fjx2             = _mm_macc_pd(dx32,fscal,fjx2);
496             fjy2             = _mm_macc_pd(dy32,fscal,fjy2);
497             fjz2             = _mm_macc_pd(dz32,fscal,fjz2);
498
499             /**************************
500              * CALCULATE INTERACTIONS *
501              **************************/
502
503             /* REACTION-FIELD ELECTROSTATICS */
504             velec            = _mm_mul_pd(qq33,_mm_sub_pd(_mm_macc_pd(krf,rsq33,rinv33),crf));
505             felec            = _mm_mul_pd(qq33,_mm_msub_pd(rinv33,rinvsq33,krf2));
506
507             /* Update potential sum for this i atom from the interaction with this j atom. */
508             velecsum         = _mm_add_pd(velecsum,velec);
509
510             fscal            = felec;
511
512             /* Update vectorial force */
513             fix3             = _mm_macc_pd(dx33,fscal,fix3);
514             fiy3             = _mm_macc_pd(dy33,fscal,fiy3);
515             fiz3             = _mm_macc_pd(dz33,fscal,fiz3);
516             
517             fjx3             = _mm_macc_pd(dx33,fscal,fjx3);
518             fjy3             = _mm_macc_pd(dy33,fscal,fjy3);
519             fjz3             = _mm_macc_pd(dz33,fscal,fjz3);
520
521             gmx_mm_decrement_4rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
522
523             /* Inner loop uses 353 flops */
524         }
525
526         if(jidx<j_index_end)
527         {
528
529             jnrA             = jjnr[jidx];
530             j_coord_offsetA  = DIM*jnrA;
531
532             /* load j atom coordinates */
533             gmx_mm_load_4rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
534                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
535                                               &jy2,&jz2,&jx3,&jy3,&jz3);
536
537             /* Calculate displacement vector */
538             dx00             = _mm_sub_pd(ix0,jx0);
539             dy00             = _mm_sub_pd(iy0,jy0);
540             dz00             = _mm_sub_pd(iz0,jz0);
541             dx11             = _mm_sub_pd(ix1,jx1);
542             dy11             = _mm_sub_pd(iy1,jy1);
543             dz11             = _mm_sub_pd(iz1,jz1);
544             dx12             = _mm_sub_pd(ix1,jx2);
545             dy12             = _mm_sub_pd(iy1,jy2);
546             dz12             = _mm_sub_pd(iz1,jz2);
547             dx13             = _mm_sub_pd(ix1,jx3);
548             dy13             = _mm_sub_pd(iy1,jy3);
549             dz13             = _mm_sub_pd(iz1,jz3);
550             dx21             = _mm_sub_pd(ix2,jx1);
551             dy21             = _mm_sub_pd(iy2,jy1);
552             dz21             = _mm_sub_pd(iz2,jz1);
553             dx22             = _mm_sub_pd(ix2,jx2);
554             dy22             = _mm_sub_pd(iy2,jy2);
555             dz22             = _mm_sub_pd(iz2,jz2);
556             dx23             = _mm_sub_pd(ix2,jx3);
557             dy23             = _mm_sub_pd(iy2,jy3);
558             dz23             = _mm_sub_pd(iz2,jz3);
559             dx31             = _mm_sub_pd(ix3,jx1);
560             dy31             = _mm_sub_pd(iy3,jy1);
561             dz31             = _mm_sub_pd(iz3,jz1);
562             dx32             = _mm_sub_pd(ix3,jx2);
563             dy32             = _mm_sub_pd(iy3,jy2);
564             dz32             = _mm_sub_pd(iz3,jz2);
565             dx33             = _mm_sub_pd(ix3,jx3);
566             dy33             = _mm_sub_pd(iy3,jy3);
567             dz33             = _mm_sub_pd(iz3,jz3);
568
569             /* Calculate squared distance and things based on it */
570             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
571             rsq11            = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
572             rsq12            = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
573             rsq13            = gmx_mm_calc_rsq_pd(dx13,dy13,dz13);
574             rsq21            = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
575             rsq22            = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
576             rsq23            = gmx_mm_calc_rsq_pd(dx23,dy23,dz23);
577             rsq31            = gmx_mm_calc_rsq_pd(dx31,dy31,dz31);
578             rsq32            = gmx_mm_calc_rsq_pd(dx32,dy32,dz32);
579             rsq33            = gmx_mm_calc_rsq_pd(dx33,dy33,dz33);
580
581             rinv11           = gmx_mm_invsqrt_pd(rsq11);
582             rinv12           = gmx_mm_invsqrt_pd(rsq12);
583             rinv13           = gmx_mm_invsqrt_pd(rsq13);
584             rinv21           = gmx_mm_invsqrt_pd(rsq21);
585             rinv22           = gmx_mm_invsqrt_pd(rsq22);
586             rinv23           = gmx_mm_invsqrt_pd(rsq23);
587             rinv31           = gmx_mm_invsqrt_pd(rsq31);
588             rinv32           = gmx_mm_invsqrt_pd(rsq32);
589             rinv33           = gmx_mm_invsqrt_pd(rsq33);
590
591             rinvsq00         = gmx_mm_inv_pd(rsq00);
592             rinvsq11         = _mm_mul_pd(rinv11,rinv11);
593             rinvsq12         = _mm_mul_pd(rinv12,rinv12);
594             rinvsq13         = _mm_mul_pd(rinv13,rinv13);
595             rinvsq21         = _mm_mul_pd(rinv21,rinv21);
596             rinvsq22         = _mm_mul_pd(rinv22,rinv22);
597             rinvsq23         = _mm_mul_pd(rinv23,rinv23);
598             rinvsq31         = _mm_mul_pd(rinv31,rinv31);
599             rinvsq32         = _mm_mul_pd(rinv32,rinv32);
600             rinvsq33         = _mm_mul_pd(rinv33,rinv33);
601
602             fjx0             = _mm_setzero_pd();
603             fjy0             = _mm_setzero_pd();
604             fjz0             = _mm_setzero_pd();
605             fjx1             = _mm_setzero_pd();
606             fjy1             = _mm_setzero_pd();
607             fjz1             = _mm_setzero_pd();
608             fjx2             = _mm_setzero_pd();
609             fjy2             = _mm_setzero_pd();
610             fjz2             = _mm_setzero_pd();
611             fjx3             = _mm_setzero_pd();
612             fjy3             = _mm_setzero_pd();
613             fjz3             = _mm_setzero_pd();
614
615             /**************************
616              * CALCULATE INTERACTIONS *
617              **************************/
618
619             /* LENNARD-JONES DISPERSION/REPULSION */
620
621             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
622             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
623             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
624             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
625             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
626
627             /* Update potential sum for this i atom from the interaction with this j atom. */
628             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
629             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
630
631             fscal            = fvdw;
632
633             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
634
635             /* Update vectorial force */
636             fix0             = _mm_macc_pd(dx00,fscal,fix0);
637             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
638             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
639             
640             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
641             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
642             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
643
644             /**************************
645              * CALCULATE INTERACTIONS *
646              **************************/
647
648             /* REACTION-FIELD ELECTROSTATICS */
649             velec            = _mm_mul_pd(qq11,_mm_sub_pd(_mm_macc_pd(krf,rsq11,rinv11),crf));
650             felec            = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
651
652             /* Update potential sum for this i atom from the interaction with this j atom. */
653             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
654             velecsum         = _mm_add_pd(velecsum,velec);
655
656             fscal            = felec;
657
658             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
659
660             /* Update vectorial force */
661             fix1             = _mm_macc_pd(dx11,fscal,fix1);
662             fiy1             = _mm_macc_pd(dy11,fscal,fiy1);
663             fiz1             = _mm_macc_pd(dz11,fscal,fiz1);
664             
665             fjx1             = _mm_macc_pd(dx11,fscal,fjx1);
666             fjy1             = _mm_macc_pd(dy11,fscal,fjy1);
667             fjz1             = _mm_macc_pd(dz11,fscal,fjz1);
668
669             /**************************
670              * CALCULATE INTERACTIONS *
671              **************************/
672
673             /* REACTION-FIELD ELECTROSTATICS */
674             velec            = _mm_mul_pd(qq12,_mm_sub_pd(_mm_macc_pd(krf,rsq12,rinv12),crf));
675             felec            = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
676
677             /* Update potential sum for this i atom from the interaction with this j atom. */
678             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
679             velecsum         = _mm_add_pd(velecsum,velec);
680
681             fscal            = felec;
682
683             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
684
685             /* Update vectorial force */
686             fix1             = _mm_macc_pd(dx12,fscal,fix1);
687             fiy1             = _mm_macc_pd(dy12,fscal,fiy1);
688             fiz1             = _mm_macc_pd(dz12,fscal,fiz1);
689             
690             fjx2             = _mm_macc_pd(dx12,fscal,fjx2);
691             fjy2             = _mm_macc_pd(dy12,fscal,fjy2);
692             fjz2             = _mm_macc_pd(dz12,fscal,fjz2);
693
694             /**************************
695              * CALCULATE INTERACTIONS *
696              **************************/
697
698             /* REACTION-FIELD ELECTROSTATICS */
699             velec            = _mm_mul_pd(qq13,_mm_sub_pd(_mm_macc_pd(krf,rsq13,rinv13),crf));
700             felec            = _mm_mul_pd(qq13,_mm_msub_pd(rinv13,rinvsq13,krf2));
701
702             /* Update potential sum for this i atom from the interaction with this j atom. */
703             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
704             velecsum         = _mm_add_pd(velecsum,velec);
705
706             fscal            = felec;
707
708             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
709
710             /* Update vectorial force */
711             fix1             = _mm_macc_pd(dx13,fscal,fix1);
712             fiy1             = _mm_macc_pd(dy13,fscal,fiy1);
713             fiz1             = _mm_macc_pd(dz13,fscal,fiz1);
714             
715             fjx3             = _mm_macc_pd(dx13,fscal,fjx3);
716             fjy3             = _mm_macc_pd(dy13,fscal,fjy3);
717             fjz3             = _mm_macc_pd(dz13,fscal,fjz3);
718
719             /**************************
720              * CALCULATE INTERACTIONS *
721              **************************/
722
723             /* REACTION-FIELD ELECTROSTATICS */
724             velec            = _mm_mul_pd(qq21,_mm_sub_pd(_mm_macc_pd(krf,rsq21,rinv21),crf));
725             felec            = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
726
727             /* Update potential sum for this i atom from the interaction with this j atom. */
728             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
729             velecsum         = _mm_add_pd(velecsum,velec);
730
731             fscal            = felec;
732
733             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
734
735             /* Update vectorial force */
736             fix2             = _mm_macc_pd(dx21,fscal,fix2);
737             fiy2             = _mm_macc_pd(dy21,fscal,fiy2);
738             fiz2             = _mm_macc_pd(dz21,fscal,fiz2);
739             
740             fjx1             = _mm_macc_pd(dx21,fscal,fjx1);
741             fjy1             = _mm_macc_pd(dy21,fscal,fjy1);
742             fjz1             = _mm_macc_pd(dz21,fscal,fjz1);
743
744             /**************************
745              * CALCULATE INTERACTIONS *
746              **************************/
747
748             /* REACTION-FIELD ELECTROSTATICS */
749             velec            = _mm_mul_pd(qq22,_mm_sub_pd(_mm_macc_pd(krf,rsq22,rinv22),crf));
750             felec            = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
751
752             /* Update potential sum for this i atom from the interaction with this j atom. */
753             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
754             velecsum         = _mm_add_pd(velecsum,velec);
755
756             fscal            = felec;
757
758             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
759
760             /* Update vectorial force */
761             fix2             = _mm_macc_pd(dx22,fscal,fix2);
762             fiy2             = _mm_macc_pd(dy22,fscal,fiy2);
763             fiz2             = _mm_macc_pd(dz22,fscal,fiz2);
764             
765             fjx2             = _mm_macc_pd(dx22,fscal,fjx2);
766             fjy2             = _mm_macc_pd(dy22,fscal,fjy2);
767             fjz2             = _mm_macc_pd(dz22,fscal,fjz2);
768
769             /**************************
770              * CALCULATE INTERACTIONS *
771              **************************/
772
773             /* REACTION-FIELD ELECTROSTATICS */
774             velec            = _mm_mul_pd(qq23,_mm_sub_pd(_mm_macc_pd(krf,rsq23,rinv23),crf));
775             felec            = _mm_mul_pd(qq23,_mm_msub_pd(rinv23,rinvsq23,krf2));
776
777             /* Update potential sum for this i atom from the interaction with this j atom. */
778             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
779             velecsum         = _mm_add_pd(velecsum,velec);
780
781             fscal            = felec;
782
783             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
784
785             /* Update vectorial force */
786             fix2             = _mm_macc_pd(dx23,fscal,fix2);
787             fiy2             = _mm_macc_pd(dy23,fscal,fiy2);
788             fiz2             = _mm_macc_pd(dz23,fscal,fiz2);
789             
790             fjx3             = _mm_macc_pd(dx23,fscal,fjx3);
791             fjy3             = _mm_macc_pd(dy23,fscal,fjy3);
792             fjz3             = _mm_macc_pd(dz23,fscal,fjz3);
793
794             /**************************
795              * CALCULATE INTERACTIONS *
796              **************************/
797
798             /* REACTION-FIELD ELECTROSTATICS */
799             velec            = _mm_mul_pd(qq31,_mm_sub_pd(_mm_macc_pd(krf,rsq31,rinv31),crf));
800             felec            = _mm_mul_pd(qq31,_mm_msub_pd(rinv31,rinvsq31,krf2));
801
802             /* Update potential sum for this i atom from the interaction with this j atom. */
803             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
804             velecsum         = _mm_add_pd(velecsum,velec);
805
806             fscal            = felec;
807
808             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
809
810             /* Update vectorial force */
811             fix3             = _mm_macc_pd(dx31,fscal,fix3);
812             fiy3             = _mm_macc_pd(dy31,fscal,fiy3);
813             fiz3             = _mm_macc_pd(dz31,fscal,fiz3);
814             
815             fjx1             = _mm_macc_pd(dx31,fscal,fjx1);
816             fjy1             = _mm_macc_pd(dy31,fscal,fjy1);
817             fjz1             = _mm_macc_pd(dz31,fscal,fjz1);
818
819             /**************************
820              * CALCULATE INTERACTIONS *
821              **************************/
822
823             /* REACTION-FIELD ELECTROSTATICS */
824             velec            = _mm_mul_pd(qq32,_mm_sub_pd(_mm_macc_pd(krf,rsq32,rinv32),crf));
825             felec            = _mm_mul_pd(qq32,_mm_msub_pd(rinv32,rinvsq32,krf2));
826
827             /* Update potential sum for this i atom from the interaction with this j atom. */
828             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
829             velecsum         = _mm_add_pd(velecsum,velec);
830
831             fscal            = felec;
832
833             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
834
835             /* Update vectorial force */
836             fix3             = _mm_macc_pd(dx32,fscal,fix3);
837             fiy3             = _mm_macc_pd(dy32,fscal,fiy3);
838             fiz3             = _mm_macc_pd(dz32,fscal,fiz3);
839             
840             fjx2             = _mm_macc_pd(dx32,fscal,fjx2);
841             fjy2             = _mm_macc_pd(dy32,fscal,fjy2);
842             fjz2             = _mm_macc_pd(dz32,fscal,fjz2);
843
844             /**************************
845              * CALCULATE INTERACTIONS *
846              **************************/
847
848             /* REACTION-FIELD ELECTROSTATICS */
849             velec            = _mm_mul_pd(qq33,_mm_sub_pd(_mm_macc_pd(krf,rsq33,rinv33),crf));
850             felec            = _mm_mul_pd(qq33,_mm_msub_pd(rinv33,rinvsq33,krf2));
851
852             /* Update potential sum for this i atom from the interaction with this j atom. */
853             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
854             velecsum         = _mm_add_pd(velecsum,velec);
855
856             fscal            = felec;
857
858             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
859
860             /* Update vectorial force */
861             fix3             = _mm_macc_pd(dx33,fscal,fix3);
862             fiy3             = _mm_macc_pd(dy33,fscal,fiy3);
863             fiz3             = _mm_macc_pd(dz33,fscal,fiz3);
864             
865             fjx3             = _mm_macc_pd(dx33,fscal,fjx3);
866             fjy3             = _mm_macc_pd(dy33,fscal,fjy3);
867             fjz3             = _mm_macc_pd(dz33,fscal,fjz3);
868
869             gmx_mm_decrement_4rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
870
871             /* Inner loop uses 353 flops */
872         }
873
874         /* End of innermost loop */
875
876         gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
877                                               f+i_coord_offset,fshift+i_shift_offset);
878
879         ggid                        = gid[iidx];
880         /* Update potential energies */
881         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
882         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
883
884         /* Increment number of inner iterations */
885         inneriter                  += j_index_end - j_index_start;
886
887         /* Outer loop uses 26 flops */
888     }
889
890     /* Increment number of outer iterations */
891     outeriter        += nri;
892
893     /* Update outer/inner flops */
894
895     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_VF,outeriter*26 + inneriter*353);
896 }
897 /*
898  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwLJ_GeomW4W4_F_avx_128_fma_double
899  * Electrostatics interaction: ReactionField
900  * VdW interaction:            LennardJones
901  * Geometry:                   Water4-Water4
902  * Calculate force/pot:        Force
903  */
904 void
905 nb_kernel_ElecRF_VdwLJ_GeomW4W4_F_avx_128_fma_double
906                     (t_nblist                    * gmx_restrict       nlist,
907                      rvec                        * gmx_restrict          xx,
908                      rvec                        * gmx_restrict          ff,
909                      t_forcerec                  * gmx_restrict          fr,
910                      t_mdatoms                   * gmx_restrict     mdatoms,
911                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
912                      t_nrnb                      * gmx_restrict        nrnb)
913 {
914     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
915      * just 0 for non-waters.
916      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
917      * jnr indices corresponding to data put in the four positions in the SIMD register.
918      */
919     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
920     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
921     int              jnrA,jnrB;
922     int              j_coord_offsetA,j_coord_offsetB;
923     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
924     real             rcutoff_scalar;
925     real             *shiftvec,*fshift,*x,*f;
926     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
927     int              vdwioffset0;
928     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
929     int              vdwioffset1;
930     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
931     int              vdwioffset2;
932     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
933     int              vdwioffset3;
934     __m128d          ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
935     int              vdwjidx0A,vdwjidx0B;
936     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
937     int              vdwjidx1A,vdwjidx1B;
938     __m128d          jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
939     int              vdwjidx2A,vdwjidx2B;
940     __m128d          jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
941     int              vdwjidx3A,vdwjidx3B;
942     __m128d          jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
943     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
944     __m128d          dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
945     __m128d          dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
946     __m128d          dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
947     __m128d          dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
948     __m128d          dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
949     __m128d          dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
950     __m128d          dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
951     __m128d          dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
952     __m128d          dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
953     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
954     real             *charge;
955     int              nvdwtype;
956     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
957     int              *vdwtype;
958     real             *vdwparam;
959     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
960     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
961     __m128d          dummy_mask,cutoff_mask;
962     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
963     __m128d          one     = _mm_set1_pd(1.0);
964     __m128d          two     = _mm_set1_pd(2.0);
965     x                = xx[0];
966     f                = ff[0];
967
968     nri              = nlist->nri;
969     iinr             = nlist->iinr;
970     jindex           = nlist->jindex;
971     jjnr             = nlist->jjnr;
972     shiftidx         = nlist->shift;
973     gid              = nlist->gid;
974     shiftvec         = fr->shift_vec[0];
975     fshift           = fr->fshift[0];
976     facel            = _mm_set1_pd(fr->epsfac);
977     charge           = mdatoms->chargeA;
978     krf              = _mm_set1_pd(fr->ic->k_rf);
979     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
980     crf              = _mm_set1_pd(fr->ic->c_rf);
981     nvdwtype         = fr->ntype;
982     vdwparam         = fr->nbfp;
983     vdwtype          = mdatoms->typeA;
984
985     /* Setup water-specific parameters */
986     inr              = nlist->iinr[0];
987     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
988     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
989     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
990     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
991
992     jq1              = _mm_set1_pd(charge[inr+1]);
993     jq2              = _mm_set1_pd(charge[inr+2]);
994     jq3              = _mm_set1_pd(charge[inr+3]);
995     vdwjidx0A        = 2*vdwtype[inr+0];
996     c6_00            = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A]);
997     c12_00           = _mm_set1_pd(vdwparam[vdwioffset0+vdwjidx0A+1]);
998     qq11             = _mm_mul_pd(iq1,jq1);
999     qq12             = _mm_mul_pd(iq1,jq2);
1000     qq13             = _mm_mul_pd(iq1,jq3);
1001     qq21             = _mm_mul_pd(iq2,jq1);
1002     qq22             = _mm_mul_pd(iq2,jq2);
1003     qq23             = _mm_mul_pd(iq2,jq3);
1004     qq31             = _mm_mul_pd(iq3,jq1);
1005     qq32             = _mm_mul_pd(iq3,jq2);
1006     qq33             = _mm_mul_pd(iq3,jq3);
1007
1008     /* Avoid stupid compiler warnings */
1009     jnrA = jnrB = 0;
1010     j_coord_offsetA = 0;
1011     j_coord_offsetB = 0;
1012
1013     outeriter        = 0;
1014     inneriter        = 0;
1015
1016     /* Start outer loop over neighborlists */
1017     for(iidx=0; iidx<nri; iidx++)
1018     {
1019         /* Load shift vector for this list */
1020         i_shift_offset   = DIM*shiftidx[iidx];
1021
1022         /* Load limits for loop over neighbors */
1023         j_index_start    = jindex[iidx];
1024         j_index_end      = jindex[iidx+1];
1025
1026         /* Get outer coordinate index */
1027         inr              = iinr[iidx];
1028         i_coord_offset   = DIM*inr;
1029
1030         /* Load i particle coords and add shift vector */
1031         gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
1032                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
1033
1034         fix0             = _mm_setzero_pd();
1035         fiy0             = _mm_setzero_pd();
1036         fiz0             = _mm_setzero_pd();
1037         fix1             = _mm_setzero_pd();
1038         fiy1             = _mm_setzero_pd();
1039         fiz1             = _mm_setzero_pd();
1040         fix2             = _mm_setzero_pd();
1041         fiy2             = _mm_setzero_pd();
1042         fiz2             = _mm_setzero_pd();
1043         fix3             = _mm_setzero_pd();
1044         fiy3             = _mm_setzero_pd();
1045         fiz3             = _mm_setzero_pd();
1046
1047         /* Start inner kernel loop */
1048         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
1049         {
1050
1051             /* Get j neighbor index, and coordinate index */
1052             jnrA             = jjnr[jidx];
1053             jnrB             = jjnr[jidx+1];
1054             j_coord_offsetA  = DIM*jnrA;
1055             j_coord_offsetB  = DIM*jnrB;
1056
1057             /* load j atom coordinates */
1058             gmx_mm_load_4rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
1059                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1060                                               &jy2,&jz2,&jx3,&jy3,&jz3);
1061
1062             /* Calculate displacement vector */
1063             dx00             = _mm_sub_pd(ix0,jx0);
1064             dy00             = _mm_sub_pd(iy0,jy0);
1065             dz00             = _mm_sub_pd(iz0,jz0);
1066             dx11             = _mm_sub_pd(ix1,jx1);
1067             dy11             = _mm_sub_pd(iy1,jy1);
1068             dz11             = _mm_sub_pd(iz1,jz1);
1069             dx12             = _mm_sub_pd(ix1,jx2);
1070             dy12             = _mm_sub_pd(iy1,jy2);
1071             dz12             = _mm_sub_pd(iz1,jz2);
1072             dx13             = _mm_sub_pd(ix1,jx3);
1073             dy13             = _mm_sub_pd(iy1,jy3);
1074             dz13             = _mm_sub_pd(iz1,jz3);
1075             dx21             = _mm_sub_pd(ix2,jx1);
1076             dy21             = _mm_sub_pd(iy2,jy1);
1077             dz21             = _mm_sub_pd(iz2,jz1);
1078             dx22             = _mm_sub_pd(ix2,jx2);
1079             dy22             = _mm_sub_pd(iy2,jy2);
1080             dz22             = _mm_sub_pd(iz2,jz2);
1081             dx23             = _mm_sub_pd(ix2,jx3);
1082             dy23             = _mm_sub_pd(iy2,jy3);
1083             dz23             = _mm_sub_pd(iz2,jz3);
1084             dx31             = _mm_sub_pd(ix3,jx1);
1085             dy31             = _mm_sub_pd(iy3,jy1);
1086             dz31             = _mm_sub_pd(iz3,jz1);
1087             dx32             = _mm_sub_pd(ix3,jx2);
1088             dy32             = _mm_sub_pd(iy3,jy2);
1089             dz32             = _mm_sub_pd(iz3,jz2);
1090             dx33             = _mm_sub_pd(ix3,jx3);
1091             dy33             = _mm_sub_pd(iy3,jy3);
1092             dz33             = _mm_sub_pd(iz3,jz3);
1093
1094             /* Calculate squared distance and things based on it */
1095             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1096             rsq11            = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
1097             rsq12            = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
1098             rsq13            = gmx_mm_calc_rsq_pd(dx13,dy13,dz13);
1099             rsq21            = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
1100             rsq22            = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
1101             rsq23            = gmx_mm_calc_rsq_pd(dx23,dy23,dz23);
1102             rsq31            = gmx_mm_calc_rsq_pd(dx31,dy31,dz31);
1103             rsq32            = gmx_mm_calc_rsq_pd(dx32,dy32,dz32);
1104             rsq33            = gmx_mm_calc_rsq_pd(dx33,dy33,dz33);
1105
1106             rinv11           = gmx_mm_invsqrt_pd(rsq11);
1107             rinv12           = gmx_mm_invsqrt_pd(rsq12);
1108             rinv13           = gmx_mm_invsqrt_pd(rsq13);
1109             rinv21           = gmx_mm_invsqrt_pd(rsq21);
1110             rinv22           = gmx_mm_invsqrt_pd(rsq22);
1111             rinv23           = gmx_mm_invsqrt_pd(rsq23);
1112             rinv31           = gmx_mm_invsqrt_pd(rsq31);
1113             rinv32           = gmx_mm_invsqrt_pd(rsq32);
1114             rinv33           = gmx_mm_invsqrt_pd(rsq33);
1115
1116             rinvsq00         = gmx_mm_inv_pd(rsq00);
1117             rinvsq11         = _mm_mul_pd(rinv11,rinv11);
1118             rinvsq12         = _mm_mul_pd(rinv12,rinv12);
1119             rinvsq13         = _mm_mul_pd(rinv13,rinv13);
1120             rinvsq21         = _mm_mul_pd(rinv21,rinv21);
1121             rinvsq22         = _mm_mul_pd(rinv22,rinv22);
1122             rinvsq23         = _mm_mul_pd(rinv23,rinv23);
1123             rinvsq31         = _mm_mul_pd(rinv31,rinv31);
1124             rinvsq32         = _mm_mul_pd(rinv32,rinv32);
1125             rinvsq33         = _mm_mul_pd(rinv33,rinv33);
1126
1127             fjx0             = _mm_setzero_pd();
1128             fjy0             = _mm_setzero_pd();
1129             fjz0             = _mm_setzero_pd();
1130             fjx1             = _mm_setzero_pd();
1131             fjy1             = _mm_setzero_pd();
1132             fjz1             = _mm_setzero_pd();
1133             fjx2             = _mm_setzero_pd();
1134             fjy2             = _mm_setzero_pd();
1135             fjz2             = _mm_setzero_pd();
1136             fjx3             = _mm_setzero_pd();
1137             fjy3             = _mm_setzero_pd();
1138             fjz3             = _mm_setzero_pd();
1139
1140             /**************************
1141              * CALCULATE INTERACTIONS *
1142              **************************/
1143
1144             /* LENNARD-JONES DISPERSION/REPULSION */
1145
1146             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
1147             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
1148
1149             fscal            = fvdw;
1150
1151             /* Update vectorial force */
1152             fix0             = _mm_macc_pd(dx00,fscal,fix0);
1153             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
1154             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
1155             
1156             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
1157             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
1158             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
1159
1160             /**************************
1161              * CALCULATE INTERACTIONS *
1162              **************************/
1163
1164             /* REACTION-FIELD ELECTROSTATICS */
1165             felec            = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
1166
1167             fscal            = felec;
1168
1169             /* Update vectorial force */
1170             fix1             = _mm_macc_pd(dx11,fscal,fix1);
1171             fiy1             = _mm_macc_pd(dy11,fscal,fiy1);
1172             fiz1             = _mm_macc_pd(dz11,fscal,fiz1);
1173             
1174             fjx1             = _mm_macc_pd(dx11,fscal,fjx1);
1175             fjy1             = _mm_macc_pd(dy11,fscal,fjy1);
1176             fjz1             = _mm_macc_pd(dz11,fscal,fjz1);
1177
1178             /**************************
1179              * CALCULATE INTERACTIONS *
1180              **************************/
1181
1182             /* REACTION-FIELD ELECTROSTATICS */
1183             felec            = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
1184
1185             fscal            = felec;
1186
1187             /* Update vectorial force */
1188             fix1             = _mm_macc_pd(dx12,fscal,fix1);
1189             fiy1             = _mm_macc_pd(dy12,fscal,fiy1);
1190             fiz1             = _mm_macc_pd(dz12,fscal,fiz1);
1191             
1192             fjx2             = _mm_macc_pd(dx12,fscal,fjx2);
1193             fjy2             = _mm_macc_pd(dy12,fscal,fjy2);
1194             fjz2             = _mm_macc_pd(dz12,fscal,fjz2);
1195
1196             /**************************
1197              * CALCULATE INTERACTIONS *
1198              **************************/
1199
1200             /* REACTION-FIELD ELECTROSTATICS */
1201             felec            = _mm_mul_pd(qq13,_mm_msub_pd(rinv13,rinvsq13,krf2));
1202
1203             fscal            = felec;
1204
1205             /* Update vectorial force */
1206             fix1             = _mm_macc_pd(dx13,fscal,fix1);
1207             fiy1             = _mm_macc_pd(dy13,fscal,fiy1);
1208             fiz1             = _mm_macc_pd(dz13,fscal,fiz1);
1209             
1210             fjx3             = _mm_macc_pd(dx13,fscal,fjx3);
1211             fjy3             = _mm_macc_pd(dy13,fscal,fjy3);
1212             fjz3             = _mm_macc_pd(dz13,fscal,fjz3);
1213
1214             /**************************
1215              * CALCULATE INTERACTIONS *
1216              **************************/
1217
1218             /* REACTION-FIELD ELECTROSTATICS */
1219             felec            = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
1220
1221             fscal            = felec;
1222
1223             /* Update vectorial force */
1224             fix2             = _mm_macc_pd(dx21,fscal,fix2);
1225             fiy2             = _mm_macc_pd(dy21,fscal,fiy2);
1226             fiz2             = _mm_macc_pd(dz21,fscal,fiz2);
1227             
1228             fjx1             = _mm_macc_pd(dx21,fscal,fjx1);
1229             fjy1             = _mm_macc_pd(dy21,fscal,fjy1);
1230             fjz1             = _mm_macc_pd(dz21,fscal,fjz1);
1231
1232             /**************************
1233              * CALCULATE INTERACTIONS *
1234              **************************/
1235
1236             /* REACTION-FIELD ELECTROSTATICS */
1237             felec            = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
1238
1239             fscal            = felec;
1240
1241             /* Update vectorial force */
1242             fix2             = _mm_macc_pd(dx22,fscal,fix2);
1243             fiy2             = _mm_macc_pd(dy22,fscal,fiy2);
1244             fiz2             = _mm_macc_pd(dz22,fscal,fiz2);
1245             
1246             fjx2             = _mm_macc_pd(dx22,fscal,fjx2);
1247             fjy2             = _mm_macc_pd(dy22,fscal,fjy2);
1248             fjz2             = _mm_macc_pd(dz22,fscal,fjz2);
1249
1250             /**************************
1251              * CALCULATE INTERACTIONS *
1252              **************************/
1253
1254             /* REACTION-FIELD ELECTROSTATICS */
1255             felec            = _mm_mul_pd(qq23,_mm_msub_pd(rinv23,rinvsq23,krf2));
1256
1257             fscal            = felec;
1258
1259             /* Update vectorial force */
1260             fix2             = _mm_macc_pd(dx23,fscal,fix2);
1261             fiy2             = _mm_macc_pd(dy23,fscal,fiy2);
1262             fiz2             = _mm_macc_pd(dz23,fscal,fiz2);
1263             
1264             fjx3             = _mm_macc_pd(dx23,fscal,fjx3);
1265             fjy3             = _mm_macc_pd(dy23,fscal,fjy3);
1266             fjz3             = _mm_macc_pd(dz23,fscal,fjz3);
1267
1268             /**************************
1269              * CALCULATE INTERACTIONS *
1270              **************************/
1271
1272             /* REACTION-FIELD ELECTROSTATICS */
1273             felec            = _mm_mul_pd(qq31,_mm_msub_pd(rinv31,rinvsq31,krf2));
1274
1275             fscal            = felec;
1276
1277             /* Update vectorial force */
1278             fix3             = _mm_macc_pd(dx31,fscal,fix3);
1279             fiy3             = _mm_macc_pd(dy31,fscal,fiy3);
1280             fiz3             = _mm_macc_pd(dz31,fscal,fiz3);
1281             
1282             fjx1             = _mm_macc_pd(dx31,fscal,fjx1);
1283             fjy1             = _mm_macc_pd(dy31,fscal,fjy1);
1284             fjz1             = _mm_macc_pd(dz31,fscal,fjz1);
1285
1286             /**************************
1287              * CALCULATE INTERACTIONS *
1288              **************************/
1289
1290             /* REACTION-FIELD ELECTROSTATICS */
1291             felec            = _mm_mul_pd(qq32,_mm_msub_pd(rinv32,rinvsq32,krf2));
1292
1293             fscal            = felec;
1294
1295             /* Update vectorial force */
1296             fix3             = _mm_macc_pd(dx32,fscal,fix3);
1297             fiy3             = _mm_macc_pd(dy32,fscal,fiy3);
1298             fiz3             = _mm_macc_pd(dz32,fscal,fiz3);
1299             
1300             fjx2             = _mm_macc_pd(dx32,fscal,fjx2);
1301             fjy2             = _mm_macc_pd(dy32,fscal,fjy2);
1302             fjz2             = _mm_macc_pd(dz32,fscal,fjz2);
1303
1304             /**************************
1305              * CALCULATE INTERACTIONS *
1306              **************************/
1307
1308             /* REACTION-FIELD ELECTROSTATICS */
1309             felec            = _mm_mul_pd(qq33,_mm_msub_pd(rinv33,rinvsq33,krf2));
1310
1311             fscal            = felec;
1312
1313             /* Update vectorial force */
1314             fix3             = _mm_macc_pd(dx33,fscal,fix3);
1315             fiy3             = _mm_macc_pd(dy33,fscal,fiy3);
1316             fiz3             = _mm_macc_pd(dz33,fscal,fiz3);
1317             
1318             fjx3             = _mm_macc_pd(dx33,fscal,fjx3);
1319             fjy3             = _mm_macc_pd(dy33,fscal,fjy3);
1320             fjz3             = _mm_macc_pd(dz33,fscal,fjz3);
1321
1322             gmx_mm_decrement_4rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1323
1324             /* Inner loop uses 303 flops */
1325         }
1326
1327         if(jidx<j_index_end)
1328         {
1329
1330             jnrA             = jjnr[jidx];
1331             j_coord_offsetA  = DIM*jnrA;
1332
1333             /* load j atom coordinates */
1334             gmx_mm_load_4rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
1335                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,
1336                                               &jy2,&jz2,&jx3,&jy3,&jz3);
1337
1338             /* Calculate displacement vector */
1339             dx00             = _mm_sub_pd(ix0,jx0);
1340             dy00             = _mm_sub_pd(iy0,jy0);
1341             dz00             = _mm_sub_pd(iz0,jz0);
1342             dx11             = _mm_sub_pd(ix1,jx1);
1343             dy11             = _mm_sub_pd(iy1,jy1);
1344             dz11             = _mm_sub_pd(iz1,jz1);
1345             dx12             = _mm_sub_pd(ix1,jx2);
1346             dy12             = _mm_sub_pd(iy1,jy2);
1347             dz12             = _mm_sub_pd(iz1,jz2);
1348             dx13             = _mm_sub_pd(ix1,jx3);
1349             dy13             = _mm_sub_pd(iy1,jy3);
1350             dz13             = _mm_sub_pd(iz1,jz3);
1351             dx21             = _mm_sub_pd(ix2,jx1);
1352             dy21             = _mm_sub_pd(iy2,jy1);
1353             dz21             = _mm_sub_pd(iz2,jz1);
1354             dx22             = _mm_sub_pd(ix2,jx2);
1355             dy22             = _mm_sub_pd(iy2,jy2);
1356             dz22             = _mm_sub_pd(iz2,jz2);
1357             dx23             = _mm_sub_pd(ix2,jx3);
1358             dy23             = _mm_sub_pd(iy2,jy3);
1359             dz23             = _mm_sub_pd(iz2,jz3);
1360             dx31             = _mm_sub_pd(ix3,jx1);
1361             dy31             = _mm_sub_pd(iy3,jy1);
1362             dz31             = _mm_sub_pd(iz3,jz1);
1363             dx32             = _mm_sub_pd(ix3,jx2);
1364             dy32             = _mm_sub_pd(iy3,jy2);
1365             dz32             = _mm_sub_pd(iz3,jz2);
1366             dx33             = _mm_sub_pd(ix3,jx3);
1367             dy33             = _mm_sub_pd(iy3,jy3);
1368             dz33             = _mm_sub_pd(iz3,jz3);
1369
1370             /* Calculate squared distance and things based on it */
1371             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
1372             rsq11            = gmx_mm_calc_rsq_pd(dx11,dy11,dz11);
1373             rsq12            = gmx_mm_calc_rsq_pd(dx12,dy12,dz12);
1374             rsq13            = gmx_mm_calc_rsq_pd(dx13,dy13,dz13);
1375             rsq21            = gmx_mm_calc_rsq_pd(dx21,dy21,dz21);
1376             rsq22            = gmx_mm_calc_rsq_pd(dx22,dy22,dz22);
1377             rsq23            = gmx_mm_calc_rsq_pd(dx23,dy23,dz23);
1378             rsq31            = gmx_mm_calc_rsq_pd(dx31,dy31,dz31);
1379             rsq32            = gmx_mm_calc_rsq_pd(dx32,dy32,dz32);
1380             rsq33            = gmx_mm_calc_rsq_pd(dx33,dy33,dz33);
1381
1382             rinv11           = gmx_mm_invsqrt_pd(rsq11);
1383             rinv12           = gmx_mm_invsqrt_pd(rsq12);
1384             rinv13           = gmx_mm_invsqrt_pd(rsq13);
1385             rinv21           = gmx_mm_invsqrt_pd(rsq21);
1386             rinv22           = gmx_mm_invsqrt_pd(rsq22);
1387             rinv23           = gmx_mm_invsqrt_pd(rsq23);
1388             rinv31           = gmx_mm_invsqrt_pd(rsq31);
1389             rinv32           = gmx_mm_invsqrt_pd(rsq32);
1390             rinv33           = gmx_mm_invsqrt_pd(rsq33);
1391
1392             rinvsq00         = gmx_mm_inv_pd(rsq00);
1393             rinvsq11         = _mm_mul_pd(rinv11,rinv11);
1394             rinvsq12         = _mm_mul_pd(rinv12,rinv12);
1395             rinvsq13         = _mm_mul_pd(rinv13,rinv13);
1396             rinvsq21         = _mm_mul_pd(rinv21,rinv21);
1397             rinvsq22         = _mm_mul_pd(rinv22,rinv22);
1398             rinvsq23         = _mm_mul_pd(rinv23,rinv23);
1399             rinvsq31         = _mm_mul_pd(rinv31,rinv31);
1400             rinvsq32         = _mm_mul_pd(rinv32,rinv32);
1401             rinvsq33         = _mm_mul_pd(rinv33,rinv33);
1402
1403             fjx0             = _mm_setzero_pd();
1404             fjy0             = _mm_setzero_pd();
1405             fjz0             = _mm_setzero_pd();
1406             fjx1             = _mm_setzero_pd();
1407             fjy1             = _mm_setzero_pd();
1408             fjz1             = _mm_setzero_pd();
1409             fjx2             = _mm_setzero_pd();
1410             fjy2             = _mm_setzero_pd();
1411             fjz2             = _mm_setzero_pd();
1412             fjx3             = _mm_setzero_pd();
1413             fjy3             = _mm_setzero_pd();
1414             fjz3             = _mm_setzero_pd();
1415
1416             /**************************
1417              * CALCULATE INTERACTIONS *
1418              **************************/
1419
1420             /* LENNARD-JONES DISPERSION/REPULSION */
1421
1422             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
1423             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
1424
1425             fscal            = fvdw;
1426
1427             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1428
1429             /* Update vectorial force */
1430             fix0             = _mm_macc_pd(dx00,fscal,fix0);
1431             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
1432             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
1433             
1434             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
1435             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
1436             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
1437
1438             /**************************
1439              * CALCULATE INTERACTIONS *
1440              **************************/
1441
1442             /* REACTION-FIELD ELECTROSTATICS */
1443             felec            = _mm_mul_pd(qq11,_mm_msub_pd(rinv11,rinvsq11,krf2));
1444
1445             fscal            = felec;
1446
1447             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1448
1449             /* Update vectorial force */
1450             fix1             = _mm_macc_pd(dx11,fscal,fix1);
1451             fiy1             = _mm_macc_pd(dy11,fscal,fiy1);
1452             fiz1             = _mm_macc_pd(dz11,fscal,fiz1);
1453             
1454             fjx1             = _mm_macc_pd(dx11,fscal,fjx1);
1455             fjy1             = _mm_macc_pd(dy11,fscal,fjy1);
1456             fjz1             = _mm_macc_pd(dz11,fscal,fjz1);
1457
1458             /**************************
1459              * CALCULATE INTERACTIONS *
1460              **************************/
1461
1462             /* REACTION-FIELD ELECTROSTATICS */
1463             felec            = _mm_mul_pd(qq12,_mm_msub_pd(rinv12,rinvsq12,krf2));
1464
1465             fscal            = felec;
1466
1467             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1468
1469             /* Update vectorial force */
1470             fix1             = _mm_macc_pd(dx12,fscal,fix1);
1471             fiy1             = _mm_macc_pd(dy12,fscal,fiy1);
1472             fiz1             = _mm_macc_pd(dz12,fscal,fiz1);
1473             
1474             fjx2             = _mm_macc_pd(dx12,fscal,fjx2);
1475             fjy2             = _mm_macc_pd(dy12,fscal,fjy2);
1476             fjz2             = _mm_macc_pd(dz12,fscal,fjz2);
1477
1478             /**************************
1479              * CALCULATE INTERACTIONS *
1480              **************************/
1481
1482             /* REACTION-FIELD ELECTROSTATICS */
1483             felec            = _mm_mul_pd(qq13,_mm_msub_pd(rinv13,rinvsq13,krf2));
1484
1485             fscal            = felec;
1486
1487             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1488
1489             /* Update vectorial force */
1490             fix1             = _mm_macc_pd(dx13,fscal,fix1);
1491             fiy1             = _mm_macc_pd(dy13,fscal,fiy1);
1492             fiz1             = _mm_macc_pd(dz13,fscal,fiz1);
1493             
1494             fjx3             = _mm_macc_pd(dx13,fscal,fjx3);
1495             fjy3             = _mm_macc_pd(dy13,fscal,fjy3);
1496             fjz3             = _mm_macc_pd(dz13,fscal,fjz3);
1497
1498             /**************************
1499              * CALCULATE INTERACTIONS *
1500              **************************/
1501
1502             /* REACTION-FIELD ELECTROSTATICS */
1503             felec            = _mm_mul_pd(qq21,_mm_msub_pd(rinv21,rinvsq21,krf2));
1504
1505             fscal            = felec;
1506
1507             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1508
1509             /* Update vectorial force */
1510             fix2             = _mm_macc_pd(dx21,fscal,fix2);
1511             fiy2             = _mm_macc_pd(dy21,fscal,fiy2);
1512             fiz2             = _mm_macc_pd(dz21,fscal,fiz2);
1513             
1514             fjx1             = _mm_macc_pd(dx21,fscal,fjx1);
1515             fjy1             = _mm_macc_pd(dy21,fscal,fjy1);
1516             fjz1             = _mm_macc_pd(dz21,fscal,fjz1);
1517
1518             /**************************
1519              * CALCULATE INTERACTIONS *
1520              **************************/
1521
1522             /* REACTION-FIELD ELECTROSTATICS */
1523             felec            = _mm_mul_pd(qq22,_mm_msub_pd(rinv22,rinvsq22,krf2));
1524
1525             fscal            = felec;
1526
1527             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1528
1529             /* Update vectorial force */
1530             fix2             = _mm_macc_pd(dx22,fscal,fix2);
1531             fiy2             = _mm_macc_pd(dy22,fscal,fiy2);
1532             fiz2             = _mm_macc_pd(dz22,fscal,fiz2);
1533             
1534             fjx2             = _mm_macc_pd(dx22,fscal,fjx2);
1535             fjy2             = _mm_macc_pd(dy22,fscal,fjy2);
1536             fjz2             = _mm_macc_pd(dz22,fscal,fjz2);
1537
1538             /**************************
1539              * CALCULATE INTERACTIONS *
1540              **************************/
1541
1542             /* REACTION-FIELD ELECTROSTATICS */
1543             felec            = _mm_mul_pd(qq23,_mm_msub_pd(rinv23,rinvsq23,krf2));
1544
1545             fscal            = felec;
1546
1547             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1548
1549             /* Update vectorial force */
1550             fix2             = _mm_macc_pd(dx23,fscal,fix2);
1551             fiy2             = _mm_macc_pd(dy23,fscal,fiy2);
1552             fiz2             = _mm_macc_pd(dz23,fscal,fiz2);
1553             
1554             fjx3             = _mm_macc_pd(dx23,fscal,fjx3);
1555             fjy3             = _mm_macc_pd(dy23,fscal,fjy3);
1556             fjz3             = _mm_macc_pd(dz23,fscal,fjz3);
1557
1558             /**************************
1559              * CALCULATE INTERACTIONS *
1560              **************************/
1561
1562             /* REACTION-FIELD ELECTROSTATICS */
1563             felec            = _mm_mul_pd(qq31,_mm_msub_pd(rinv31,rinvsq31,krf2));
1564
1565             fscal            = felec;
1566
1567             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1568
1569             /* Update vectorial force */
1570             fix3             = _mm_macc_pd(dx31,fscal,fix3);
1571             fiy3             = _mm_macc_pd(dy31,fscal,fiy3);
1572             fiz3             = _mm_macc_pd(dz31,fscal,fiz3);
1573             
1574             fjx1             = _mm_macc_pd(dx31,fscal,fjx1);
1575             fjy1             = _mm_macc_pd(dy31,fscal,fjy1);
1576             fjz1             = _mm_macc_pd(dz31,fscal,fjz1);
1577
1578             /**************************
1579              * CALCULATE INTERACTIONS *
1580              **************************/
1581
1582             /* REACTION-FIELD ELECTROSTATICS */
1583             felec            = _mm_mul_pd(qq32,_mm_msub_pd(rinv32,rinvsq32,krf2));
1584
1585             fscal            = felec;
1586
1587             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1588
1589             /* Update vectorial force */
1590             fix3             = _mm_macc_pd(dx32,fscal,fix3);
1591             fiy3             = _mm_macc_pd(dy32,fscal,fiy3);
1592             fiz3             = _mm_macc_pd(dz32,fscal,fiz3);
1593             
1594             fjx2             = _mm_macc_pd(dx32,fscal,fjx2);
1595             fjy2             = _mm_macc_pd(dy32,fscal,fjy2);
1596             fjz2             = _mm_macc_pd(dz32,fscal,fjz2);
1597
1598             /**************************
1599              * CALCULATE INTERACTIONS *
1600              **************************/
1601
1602             /* REACTION-FIELD ELECTROSTATICS */
1603             felec            = _mm_mul_pd(qq33,_mm_msub_pd(rinv33,rinvsq33,krf2));
1604
1605             fscal            = felec;
1606
1607             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1608
1609             /* Update vectorial force */
1610             fix3             = _mm_macc_pd(dx33,fscal,fix3);
1611             fiy3             = _mm_macc_pd(dy33,fscal,fiy3);
1612             fiz3             = _mm_macc_pd(dz33,fscal,fiz3);
1613             
1614             fjx3             = _mm_macc_pd(dx33,fscal,fjx3);
1615             fjy3             = _mm_macc_pd(dy33,fscal,fjy3);
1616             fjz3             = _mm_macc_pd(dz33,fscal,fjz3);
1617
1618             gmx_mm_decrement_4rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1619
1620             /* Inner loop uses 303 flops */
1621         }
1622
1623         /* End of innermost loop */
1624
1625         gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1626                                               f+i_coord_offset,fshift+i_shift_offset);
1627
1628         /* Increment number of inner iterations */
1629         inneriter                  += j_index_end - j_index_start;
1630
1631         /* Outer loop uses 24 flops */
1632     }
1633
1634     /* Increment number of outer iterations */
1635     outeriter        += nri;
1636
1637     /* Update outer/inner flops */
1638
1639     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4W4_F,outeriter*24 + inneriter*303);
1640 }