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