Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecCoul_VdwLJ_GeomW3P1_avx_128_fma_double.c
1 /*
2  * Note: this file was generated by the Gromacs avx_128_fma_double kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
10  * Gromacs is a library for molecular simulation and trajectory analysis,
11  * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12  * a full list of developers and information, check out http://www.gromacs.org
13  *
14  * This program is free software; you can redistribute it and/or modify it under
15  * the terms of the GNU Lesser General Public License as published by the Free
16  * Software Foundation; either version 2 of the License, or (at your option) any
17  * later version.
18  *
19  * To help fund GROMACS development, we humbly ask that you cite
20  * the papers people have written on it - you can find them on the website.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 #include "gmx_math_x86_avx_128_fma_double.h"
34 #include "kernelutil_x86_avx_128_fma_double.h"
35
36 /*
37  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_avx_128_fma_double
38  * Electrostatics interaction: Coulomb
39  * VdW interaction:            LennardJones
40  * Geometry:                   Water3-Particle
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_VF_avx_128_fma_double
45                     (t_nblist * gmx_restrict                nlist,
46                      rvec * gmx_restrict                    xx,
47                      rvec * gmx_restrict                    ff,
48                      t_forcerec * gmx_restrict              fr,
49                      t_mdatoms * gmx_restrict               mdatoms,
50                      nb_kernel_data_t * gmx_restrict        kernel_data,
51                      t_nrnb * gmx_restrict                  nrnb)
52 {
53     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54      * just 0 for non-waters.
55      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
56      * jnr indices corresponding to data put in the four positions in the SIMD register.
57      */
58     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
59     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60     int              jnrA,jnrB;
61     int              j_coord_offsetA,j_coord_offsetB;
62     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
63     real             rcutoff_scalar;
64     real             *shiftvec,*fshift,*x,*f;
65     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
66     int              vdwioffset0;
67     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
68     int              vdwioffset1;
69     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
70     int              vdwioffset2;
71     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
72     int              vdwjidx0A,vdwjidx0B;
73     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
74     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
75     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
76     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
77     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
78     real             *charge;
79     int              nvdwtype;
80     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
81     int              *vdwtype;
82     real             *vdwparam;
83     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
84     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
85     __m128d          dummy_mask,cutoff_mask;
86     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
87     __m128d          one     = _mm_set1_pd(1.0);
88     __m128d          two     = _mm_set1_pd(2.0);
89     x                = xx[0];
90     f                = ff[0];
91
92     nri              = nlist->nri;
93     iinr             = nlist->iinr;
94     jindex           = nlist->jindex;
95     jjnr             = nlist->jjnr;
96     shiftidx         = nlist->shift;
97     gid              = nlist->gid;
98     shiftvec         = fr->shift_vec[0];
99     fshift           = fr->fshift[0];
100     facel            = _mm_set1_pd(fr->epsfac);
101     charge           = mdatoms->chargeA;
102     nvdwtype         = fr->ntype;
103     vdwparam         = fr->nbfp;
104     vdwtype          = mdatoms->typeA;
105
106     /* Setup water-specific parameters */
107     inr              = nlist->iinr[0];
108     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
109     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
110     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
111     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
112
113     /* Avoid stupid compiler warnings */
114     jnrA = jnrB = 0;
115     j_coord_offsetA = 0;
116     j_coord_offsetB = 0;
117
118     outeriter        = 0;
119     inneriter        = 0;
120
121     /* Start outer loop over neighborlists */
122     for(iidx=0; iidx<nri; iidx++)
123     {
124         /* Load shift vector for this list */
125         i_shift_offset   = DIM*shiftidx[iidx];
126
127         /* Load limits for loop over neighbors */
128         j_index_start    = jindex[iidx];
129         j_index_end      = jindex[iidx+1];
130
131         /* Get outer coordinate index */
132         inr              = iinr[iidx];
133         i_coord_offset   = DIM*inr;
134
135         /* Load i particle coords and add shift vector */
136         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
137                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
138
139         fix0             = _mm_setzero_pd();
140         fiy0             = _mm_setzero_pd();
141         fiz0             = _mm_setzero_pd();
142         fix1             = _mm_setzero_pd();
143         fiy1             = _mm_setzero_pd();
144         fiz1             = _mm_setzero_pd();
145         fix2             = _mm_setzero_pd();
146         fiy2             = _mm_setzero_pd();
147         fiz2             = _mm_setzero_pd();
148
149         /* Reset potential sums */
150         velecsum         = _mm_setzero_pd();
151         vvdwsum          = _mm_setzero_pd();
152
153         /* Start inner kernel loop */
154         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
155         {
156
157             /* Get j neighbor index, and coordinate index */
158             jnrA             = jjnr[jidx];
159             jnrB             = jjnr[jidx+1];
160             j_coord_offsetA  = DIM*jnrA;
161             j_coord_offsetB  = DIM*jnrB;
162
163             /* load j atom coordinates */
164             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
165                                               &jx0,&jy0,&jz0);
166
167             /* Calculate displacement vector */
168             dx00             = _mm_sub_pd(ix0,jx0);
169             dy00             = _mm_sub_pd(iy0,jy0);
170             dz00             = _mm_sub_pd(iz0,jz0);
171             dx10             = _mm_sub_pd(ix1,jx0);
172             dy10             = _mm_sub_pd(iy1,jy0);
173             dz10             = _mm_sub_pd(iz1,jz0);
174             dx20             = _mm_sub_pd(ix2,jx0);
175             dy20             = _mm_sub_pd(iy2,jy0);
176             dz20             = _mm_sub_pd(iz2,jz0);
177
178             /* Calculate squared distance and things based on it */
179             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
180             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
181             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
182
183             rinv00           = gmx_mm_invsqrt_pd(rsq00);
184             rinv10           = gmx_mm_invsqrt_pd(rsq10);
185             rinv20           = gmx_mm_invsqrt_pd(rsq20);
186
187             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
188             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
189             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
190
191             /* Load parameters for j particles */
192             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
193             vdwjidx0A        = 2*vdwtype[jnrA+0];
194             vdwjidx0B        = 2*vdwtype[jnrB+0];
195
196             fjx0             = _mm_setzero_pd();
197             fjy0             = _mm_setzero_pd();
198             fjz0             = _mm_setzero_pd();
199
200             /**************************
201              * CALCULATE INTERACTIONS *
202              **************************/
203
204             /* Compute parameters for interactions between i and j atoms */
205             qq00             = _mm_mul_pd(iq0,jq0);
206             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
207                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
208
209             /* COULOMB ELECTROSTATICS */
210             velec            = _mm_mul_pd(qq00,rinv00);
211             felec            = _mm_mul_pd(velec,rinvsq00);
212
213             /* LENNARD-JONES DISPERSION/REPULSION */
214
215             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
216             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
217             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
218             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
219             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
220
221             /* Update potential sum for this i atom from the interaction with this j atom. */
222             velecsum         = _mm_add_pd(velecsum,velec);
223             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
224
225             fscal            = _mm_add_pd(felec,fvdw);
226
227             /* Update vectorial force */
228             fix0             = _mm_macc_pd(dx00,fscal,fix0);
229             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
230             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
231             
232             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
233             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
234             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
235
236             /**************************
237              * CALCULATE INTERACTIONS *
238              **************************/
239
240             /* Compute parameters for interactions between i and j atoms */
241             qq10             = _mm_mul_pd(iq1,jq0);
242
243             /* COULOMB ELECTROSTATICS */
244             velec            = _mm_mul_pd(qq10,rinv10);
245             felec            = _mm_mul_pd(velec,rinvsq10);
246
247             /* Update potential sum for this i atom from the interaction with this j atom. */
248             velecsum         = _mm_add_pd(velecsum,velec);
249
250             fscal            = felec;
251
252             /* Update vectorial force */
253             fix1             = _mm_macc_pd(dx10,fscal,fix1);
254             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
255             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
256             
257             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
258             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
259             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
260
261             /**************************
262              * CALCULATE INTERACTIONS *
263              **************************/
264
265             /* Compute parameters for interactions between i and j atoms */
266             qq20             = _mm_mul_pd(iq2,jq0);
267
268             /* COULOMB ELECTROSTATICS */
269             velec            = _mm_mul_pd(qq20,rinv20);
270             felec            = _mm_mul_pd(velec,rinvsq20);
271
272             /* Update potential sum for this i atom from the interaction with this j atom. */
273             velecsum         = _mm_add_pd(velecsum,velec);
274
275             fscal            = felec;
276
277             /* Update vectorial force */
278             fix2             = _mm_macc_pd(dx20,fscal,fix2);
279             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
280             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
281             
282             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
283             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
284             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
285
286             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
287
288             /* Inner loop uses 108 flops */
289         }
290
291         if(jidx<j_index_end)
292         {
293
294             jnrA             = jjnr[jidx];
295             j_coord_offsetA  = DIM*jnrA;
296
297             /* load j atom coordinates */
298             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
299                                               &jx0,&jy0,&jz0);
300
301             /* Calculate displacement vector */
302             dx00             = _mm_sub_pd(ix0,jx0);
303             dy00             = _mm_sub_pd(iy0,jy0);
304             dz00             = _mm_sub_pd(iz0,jz0);
305             dx10             = _mm_sub_pd(ix1,jx0);
306             dy10             = _mm_sub_pd(iy1,jy0);
307             dz10             = _mm_sub_pd(iz1,jz0);
308             dx20             = _mm_sub_pd(ix2,jx0);
309             dy20             = _mm_sub_pd(iy2,jy0);
310             dz20             = _mm_sub_pd(iz2,jz0);
311
312             /* Calculate squared distance and things based on it */
313             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
314             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
315             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
316
317             rinv00           = gmx_mm_invsqrt_pd(rsq00);
318             rinv10           = gmx_mm_invsqrt_pd(rsq10);
319             rinv20           = gmx_mm_invsqrt_pd(rsq20);
320
321             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
322             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
323             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
324
325             /* Load parameters for j particles */
326             jq0              = _mm_load_sd(charge+jnrA+0);
327             vdwjidx0A        = 2*vdwtype[jnrA+0];
328
329             fjx0             = _mm_setzero_pd();
330             fjy0             = _mm_setzero_pd();
331             fjz0             = _mm_setzero_pd();
332
333             /**************************
334              * CALCULATE INTERACTIONS *
335              **************************/
336
337             /* Compute parameters for interactions between i and j atoms */
338             qq00             = _mm_mul_pd(iq0,jq0);
339             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
340
341             /* COULOMB ELECTROSTATICS */
342             velec            = _mm_mul_pd(qq00,rinv00);
343             felec            = _mm_mul_pd(velec,rinvsq00);
344
345             /* LENNARD-JONES DISPERSION/REPULSION */
346
347             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
348             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
349             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
350             vvdw             = _mm_msub_pd( vvdw12,one_twelfth, _mm_mul_pd(vvdw6,one_sixth) );
351             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
352
353             /* Update potential sum for this i atom from the interaction with this j atom. */
354             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
355             velecsum         = _mm_add_pd(velecsum,velec);
356             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
357             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
358
359             fscal            = _mm_add_pd(felec,fvdw);
360
361             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
362
363             /* Update vectorial force */
364             fix0             = _mm_macc_pd(dx00,fscal,fix0);
365             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
366             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
367             
368             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
369             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
370             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
371
372             /**************************
373              * CALCULATE INTERACTIONS *
374              **************************/
375
376             /* Compute parameters for interactions between i and j atoms */
377             qq10             = _mm_mul_pd(iq1,jq0);
378
379             /* COULOMB ELECTROSTATICS */
380             velec            = _mm_mul_pd(qq10,rinv10);
381             felec            = _mm_mul_pd(velec,rinvsq10);
382
383             /* Update potential sum for this i atom from the interaction with this j atom. */
384             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
385             velecsum         = _mm_add_pd(velecsum,velec);
386
387             fscal            = felec;
388
389             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
390
391             /* Update vectorial force */
392             fix1             = _mm_macc_pd(dx10,fscal,fix1);
393             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
394             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
395             
396             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
397             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
398             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
399
400             /**************************
401              * CALCULATE INTERACTIONS *
402              **************************/
403
404             /* Compute parameters for interactions between i and j atoms */
405             qq20             = _mm_mul_pd(iq2,jq0);
406
407             /* COULOMB ELECTROSTATICS */
408             velec            = _mm_mul_pd(qq20,rinv20);
409             felec            = _mm_mul_pd(velec,rinvsq20);
410
411             /* Update potential sum for this i atom from the interaction with this j atom. */
412             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
413             velecsum         = _mm_add_pd(velecsum,velec);
414
415             fscal            = felec;
416
417             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
418
419             /* Update vectorial force */
420             fix2             = _mm_macc_pd(dx20,fscal,fix2);
421             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
422             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
423             
424             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
425             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
426             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
427
428             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
429
430             /* Inner loop uses 108 flops */
431         }
432
433         /* End of innermost loop */
434
435         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
436                                               f+i_coord_offset,fshift+i_shift_offset);
437
438         ggid                        = gid[iidx];
439         /* Update potential energies */
440         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
441         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
442
443         /* Increment number of inner iterations */
444         inneriter                  += j_index_end - j_index_start;
445
446         /* Outer loop uses 20 flops */
447     }
448
449     /* Increment number of outer iterations */
450     outeriter        += nri;
451
452     /* Update outer/inner flops */
453
454     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_VF,outeriter*20 + inneriter*108);
455 }
456 /*
457  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_avx_128_fma_double
458  * Electrostatics interaction: Coulomb
459  * VdW interaction:            LennardJones
460  * Geometry:                   Water3-Particle
461  * Calculate force/pot:        Force
462  */
463 void
464 nb_kernel_ElecCoul_VdwLJ_GeomW3P1_F_avx_128_fma_double
465                     (t_nblist * gmx_restrict                nlist,
466                      rvec * gmx_restrict                    xx,
467                      rvec * gmx_restrict                    ff,
468                      t_forcerec * gmx_restrict              fr,
469                      t_mdatoms * gmx_restrict               mdatoms,
470                      nb_kernel_data_t * gmx_restrict        kernel_data,
471                      t_nrnb * gmx_restrict                  nrnb)
472 {
473     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
474      * just 0 for non-waters.
475      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
476      * jnr indices corresponding to data put in the four positions in the SIMD register.
477      */
478     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
479     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
480     int              jnrA,jnrB;
481     int              j_coord_offsetA,j_coord_offsetB;
482     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
483     real             rcutoff_scalar;
484     real             *shiftvec,*fshift,*x,*f;
485     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
486     int              vdwioffset0;
487     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
488     int              vdwioffset1;
489     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
490     int              vdwioffset2;
491     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
492     int              vdwjidx0A,vdwjidx0B;
493     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
494     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
495     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
496     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
497     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
498     real             *charge;
499     int              nvdwtype;
500     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
501     int              *vdwtype;
502     real             *vdwparam;
503     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
504     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
505     __m128d          dummy_mask,cutoff_mask;
506     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
507     __m128d          one     = _mm_set1_pd(1.0);
508     __m128d          two     = _mm_set1_pd(2.0);
509     x                = xx[0];
510     f                = ff[0];
511
512     nri              = nlist->nri;
513     iinr             = nlist->iinr;
514     jindex           = nlist->jindex;
515     jjnr             = nlist->jjnr;
516     shiftidx         = nlist->shift;
517     gid              = nlist->gid;
518     shiftvec         = fr->shift_vec[0];
519     fshift           = fr->fshift[0];
520     facel            = _mm_set1_pd(fr->epsfac);
521     charge           = mdatoms->chargeA;
522     nvdwtype         = fr->ntype;
523     vdwparam         = fr->nbfp;
524     vdwtype          = mdatoms->typeA;
525
526     /* Setup water-specific parameters */
527     inr              = nlist->iinr[0];
528     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
529     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
530     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
531     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
532
533     /* Avoid stupid compiler warnings */
534     jnrA = jnrB = 0;
535     j_coord_offsetA = 0;
536     j_coord_offsetB = 0;
537
538     outeriter        = 0;
539     inneriter        = 0;
540
541     /* Start outer loop over neighborlists */
542     for(iidx=0; iidx<nri; iidx++)
543     {
544         /* Load shift vector for this list */
545         i_shift_offset   = DIM*shiftidx[iidx];
546
547         /* Load limits for loop over neighbors */
548         j_index_start    = jindex[iidx];
549         j_index_end      = jindex[iidx+1];
550
551         /* Get outer coordinate index */
552         inr              = iinr[iidx];
553         i_coord_offset   = DIM*inr;
554
555         /* Load i particle coords and add shift vector */
556         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
557                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
558
559         fix0             = _mm_setzero_pd();
560         fiy0             = _mm_setzero_pd();
561         fiz0             = _mm_setzero_pd();
562         fix1             = _mm_setzero_pd();
563         fiy1             = _mm_setzero_pd();
564         fiz1             = _mm_setzero_pd();
565         fix2             = _mm_setzero_pd();
566         fiy2             = _mm_setzero_pd();
567         fiz2             = _mm_setzero_pd();
568
569         /* Start inner kernel loop */
570         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
571         {
572
573             /* Get j neighbor index, and coordinate index */
574             jnrA             = jjnr[jidx];
575             jnrB             = jjnr[jidx+1];
576             j_coord_offsetA  = DIM*jnrA;
577             j_coord_offsetB  = DIM*jnrB;
578
579             /* load j atom coordinates */
580             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
581                                               &jx0,&jy0,&jz0);
582
583             /* Calculate displacement vector */
584             dx00             = _mm_sub_pd(ix0,jx0);
585             dy00             = _mm_sub_pd(iy0,jy0);
586             dz00             = _mm_sub_pd(iz0,jz0);
587             dx10             = _mm_sub_pd(ix1,jx0);
588             dy10             = _mm_sub_pd(iy1,jy0);
589             dz10             = _mm_sub_pd(iz1,jz0);
590             dx20             = _mm_sub_pd(ix2,jx0);
591             dy20             = _mm_sub_pd(iy2,jy0);
592             dz20             = _mm_sub_pd(iz2,jz0);
593
594             /* Calculate squared distance and things based on it */
595             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
596             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
597             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
598
599             rinv00           = gmx_mm_invsqrt_pd(rsq00);
600             rinv10           = gmx_mm_invsqrt_pd(rsq10);
601             rinv20           = gmx_mm_invsqrt_pd(rsq20);
602
603             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
604             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
605             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
606
607             /* Load parameters for j particles */
608             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
609             vdwjidx0A        = 2*vdwtype[jnrA+0];
610             vdwjidx0B        = 2*vdwtype[jnrB+0];
611
612             fjx0             = _mm_setzero_pd();
613             fjy0             = _mm_setzero_pd();
614             fjz0             = _mm_setzero_pd();
615
616             /**************************
617              * CALCULATE INTERACTIONS *
618              **************************/
619
620             /* Compute parameters for interactions between i and j atoms */
621             qq00             = _mm_mul_pd(iq0,jq0);
622             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
623                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
624
625             /* COULOMB ELECTROSTATICS */
626             velec            = _mm_mul_pd(qq00,rinv00);
627             felec            = _mm_mul_pd(velec,rinvsq00);
628
629             /* LENNARD-JONES DISPERSION/REPULSION */
630
631             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
632             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
633
634             fscal            = _mm_add_pd(felec,fvdw);
635
636             /* Update vectorial force */
637             fix0             = _mm_macc_pd(dx00,fscal,fix0);
638             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
639             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
640             
641             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
642             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
643             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
644
645             /**************************
646              * CALCULATE INTERACTIONS *
647              **************************/
648
649             /* Compute parameters for interactions between i and j atoms */
650             qq10             = _mm_mul_pd(iq1,jq0);
651
652             /* COULOMB ELECTROSTATICS */
653             velec            = _mm_mul_pd(qq10,rinv10);
654             felec            = _mm_mul_pd(velec,rinvsq10);
655
656             fscal            = felec;
657
658             /* Update vectorial force */
659             fix1             = _mm_macc_pd(dx10,fscal,fix1);
660             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
661             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
662             
663             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
664             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
665             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
666
667             /**************************
668              * CALCULATE INTERACTIONS *
669              **************************/
670
671             /* Compute parameters for interactions between i and j atoms */
672             qq20             = _mm_mul_pd(iq2,jq0);
673
674             /* COULOMB ELECTROSTATICS */
675             velec            = _mm_mul_pd(qq20,rinv20);
676             felec            = _mm_mul_pd(velec,rinvsq20);
677
678             fscal            = felec;
679
680             /* Update vectorial force */
681             fix2             = _mm_macc_pd(dx20,fscal,fix2);
682             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
683             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
684             
685             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
686             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
687             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
688
689             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
690
691             /* Inner loop uses 100 flops */
692         }
693
694         if(jidx<j_index_end)
695         {
696
697             jnrA             = jjnr[jidx];
698             j_coord_offsetA  = DIM*jnrA;
699
700             /* load j atom coordinates */
701             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
702                                               &jx0,&jy0,&jz0);
703
704             /* Calculate displacement vector */
705             dx00             = _mm_sub_pd(ix0,jx0);
706             dy00             = _mm_sub_pd(iy0,jy0);
707             dz00             = _mm_sub_pd(iz0,jz0);
708             dx10             = _mm_sub_pd(ix1,jx0);
709             dy10             = _mm_sub_pd(iy1,jy0);
710             dz10             = _mm_sub_pd(iz1,jz0);
711             dx20             = _mm_sub_pd(ix2,jx0);
712             dy20             = _mm_sub_pd(iy2,jy0);
713             dz20             = _mm_sub_pd(iz2,jz0);
714
715             /* Calculate squared distance and things based on it */
716             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
717             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
718             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
719
720             rinv00           = gmx_mm_invsqrt_pd(rsq00);
721             rinv10           = gmx_mm_invsqrt_pd(rsq10);
722             rinv20           = gmx_mm_invsqrt_pd(rsq20);
723
724             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
725             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
726             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
727
728             /* Load parameters for j particles */
729             jq0              = _mm_load_sd(charge+jnrA+0);
730             vdwjidx0A        = 2*vdwtype[jnrA+0];
731
732             fjx0             = _mm_setzero_pd();
733             fjy0             = _mm_setzero_pd();
734             fjz0             = _mm_setzero_pd();
735
736             /**************************
737              * CALCULATE INTERACTIONS *
738              **************************/
739
740             /* Compute parameters for interactions between i and j atoms */
741             qq00             = _mm_mul_pd(iq0,jq0);
742             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
743
744             /* COULOMB ELECTROSTATICS */
745             velec            = _mm_mul_pd(qq00,rinv00);
746             felec            = _mm_mul_pd(velec,rinvsq00);
747
748             /* LENNARD-JONES DISPERSION/REPULSION */
749
750             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
751             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
752
753             fscal            = _mm_add_pd(felec,fvdw);
754
755             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
756
757             /* Update vectorial force */
758             fix0             = _mm_macc_pd(dx00,fscal,fix0);
759             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
760             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
761             
762             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
763             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
764             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
765
766             /**************************
767              * CALCULATE INTERACTIONS *
768              **************************/
769
770             /* Compute parameters for interactions between i and j atoms */
771             qq10             = _mm_mul_pd(iq1,jq0);
772
773             /* COULOMB ELECTROSTATICS */
774             velec            = _mm_mul_pd(qq10,rinv10);
775             felec            = _mm_mul_pd(velec,rinvsq10);
776
777             fscal            = felec;
778
779             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
780
781             /* Update vectorial force */
782             fix1             = _mm_macc_pd(dx10,fscal,fix1);
783             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
784             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
785             
786             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
787             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
788             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
789
790             /**************************
791              * CALCULATE INTERACTIONS *
792              **************************/
793
794             /* Compute parameters for interactions between i and j atoms */
795             qq20             = _mm_mul_pd(iq2,jq0);
796
797             /* COULOMB ELECTROSTATICS */
798             velec            = _mm_mul_pd(qq20,rinv20);
799             felec            = _mm_mul_pd(velec,rinvsq20);
800
801             fscal            = felec;
802
803             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
804
805             /* Update vectorial force */
806             fix2             = _mm_macc_pd(dx20,fscal,fix2);
807             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
808             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
809             
810             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
811             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
812             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
813
814             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
815
816             /* Inner loop uses 100 flops */
817         }
818
819         /* End of innermost loop */
820
821         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
822                                               f+i_coord_offset,fshift+i_shift_offset);
823
824         /* Increment number of inner iterations */
825         inneriter                  += j_index_end - j_index_start;
826
827         /* Outer loop uses 18 flops */
828     }
829
830     /* Increment number of outer iterations */
831     outeriter        += nri;
832
833     /* Update outer/inner flops */
834
835     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3_F,outeriter*18 + inneriter*100);
836 }