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