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