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