Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRFCut_VdwLJSh_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 "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_ElecRFCut_VdwLJSh_GeomW4P1_VF_avx_128_fma_double
52  * Electrostatics interaction: ReactionField
53  * VdW interaction:            LennardJones
54  * Geometry:                   Water4-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecRFCut_VdwLJSh_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              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              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          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93     __m128d          dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
94     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
95     real             *charge;
96     int              nvdwtype;
97     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
98     int              *vdwtype;
99     real             *vdwparam;
100     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
101     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
102     __m128d          dummy_mask,cutoff_mask;
103     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
104     __m128d          one     = _mm_set1_pd(1.0);
105     __m128d          two     = _mm_set1_pd(2.0);
106     x                = xx[0];
107     f                = ff[0];
108
109     nri              = nlist->nri;
110     iinr             = nlist->iinr;
111     jindex           = nlist->jindex;
112     jjnr             = nlist->jjnr;
113     shiftidx         = nlist->shift;
114     gid              = nlist->gid;
115     shiftvec         = fr->shift_vec[0];
116     fshift           = fr->fshift[0];
117     facel            = _mm_set1_pd(fr->epsfac);
118     charge           = mdatoms->chargeA;
119     krf              = _mm_set1_pd(fr->ic->k_rf);
120     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
121     crf              = _mm_set1_pd(fr->ic->c_rf);
122     nvdwtype         = fr->ntype;
123     vdwparam         = fr->nbfp;
124     vdwtype          = mdatoms->typeA;
125
126     /* Setup water-specific parameters */
127     inr              = nlist->iinr[0];
128     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
129     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
130     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
131     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
132
133     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
134     rcutoff_scalar   = fr->rcoulomb;
135     rcutoff          = _mm_set1_pd(rcutoff_scalar);
136     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
137
138     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
139     rvdw             = _mm_set1_pd(fr->rvdw);
140
141     /* Avoid stupid compiler warnings */
142     jnrA = jnrB = 0;
143     j_coord_offsetA = 0;
144     j_coord_offsetB = 0;
145
146     outeriter        = 0;
147     inneriter        = 0;
148
149     /* Start outer loop over neighborlists */
150     for(iidx=0; iidx<nri; iidx++)
151     {
152         /* Load shift vector for this list */
153         i_shift_offset   = DIM*shiftidx[iidx];
154
155         /* Load limits for loop over neighbors */
156         j_index_start    = jindex[iidx];
157         j_index_end      = jindex[iidx+1];
158
159         /* Get outer coordinate index */
160         inr              = iinr[iidx];
161         i_coord_offset   = DIM*inr;
162
163         /* Load i particle coords and add shift vector */
164         gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
165                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
166
167         fix0             = _mm_setzero_pd();
168         fiy0             = _mm_setzero_pd();
169         fiz0             = _mm_setzero_pd();
170         fix1             = _mm_setzero_pd();
171         fiy1             = _mm_setzero_pd();
172         fiz1             = _mm_setzero_pd();
173         fix2             = _mm_setzero_pd();
174         fiy2             = _mm_setzero_pd();
175         fiz2             = _mm_setzero_pd();
176         fix3             = _mm_setzero_pd();
177         fiy3             = _mm_setzero_pd();
178         fiz3             = _mm_setzero_pd();
179
180         /* Reset potential sums */
181         velecsum         = _mm_setzero_pd();
182         vvdwsum          = _mm_setzero_pd();
183
184         /* Start inner kernel loop */
185         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
186         {
187
188             /* Get j neighbor index, and coordinate index */
189             jnrA             = jjnr[jidx];
190             jnrB             = jjnr[jidx+1];
191             j_coord_offsetA  = DIM*jnrA;
192             j_coord_offsetB  = DIM*jnrB;
193
194             /* load j atom coordinates */
195             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
196                                               &jx0,&jy0,&jz0);
197
198             /* Calculate displacement vector */
199             dx00             = _mm_sub_pd(ix0,jx0);
200             dy00             = _mm_sub_pd(iy0,jy0);
201             dz00             = _mm_sub_pd(iz0,jz0);
202             dx10             = _mm_sub_pd(ix1,jx0);
203             dy10             = _mm_sub_pd(iy1,jy0);
204             dz10             = _mm_sub_pd(iz1,jz0);
205             dx20             = _mm_sub_pd(ix2,jx0);
206             dy20             = _mm_sub_pd(iy2,jy0);
207             dz20             = _mm_sub_pd(iz2,jz0);
208             dx30             = _mm_sub_pd(ix3,jx0);
209             dy30             = _mm_sub_pd(iy3,jy0);
210             dz30             = _mm_sub_pd(iz3,jz0);
211
212             /* Calculate squared distance and things based on it */
213             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
214             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
215             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
216             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
217
218             rinv10           = gmx_mm_invsqrt_pd(rsq10);
219             rinv20           = gmx_mm_invsqrt_pd(rsq20);
220             rinv30           = gmx_mm_invsqrt_pd(rsq30);
221
222             rinvsq00         = gmx_mm_inv_pd(rsq00);
223             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
224             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
225             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
226
227             /* Load parameters for j particles */
228             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
229             vdwjidx0A        = 2*vdwtype[jnrA+0];
230             vdwjidx0B        = 2*vdwtype[jnrB+0];
231
232             fjx0             = _mm_setzero_pd();
233             fjy0             = _mm_setzero_pd();
234             fjz0             = _mm_setzero_pd();
235
236             /**************************
237              * CALCULATE INTERACTIONS *
238              **************************/
239
240             if (gmx_mm_any_lt(rsq00,rcutoff2))
241             {
242
243             /* Compute parameters for interactions between i and j atoms */
244             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
245                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
246
247             /* LENNARD-JONES DISPERSION/REPULSION */
248
249             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
250             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
251             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
252             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
253                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
254             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
255
256             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
257
258             /* Update potential sum for this i atom from the interaction with this j atom. */
259             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
260             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
261
262             fscal            = fvdw;
263
264             fscal            = _mm_and_pd(fscal,cutoff_mask);
265
266             /* Update vectorial force */
267             fix0             = _mm_macc_pd(dx00,fscal,fix0);
268             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
269             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
270             
271             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
272             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
273             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
274
275             }
276
277             /**************************
278              * CALCULATE INTERACTIONS *
279              **************************/
280
281             if (gmx_mm_any_lt(rsq10,rcutoff2))
282             {
283
284             /* Compute parameters for interactions between i and j atoms */
285             qq10             = _mm_mul_pd(iq1,jq0);
286
287             /* REACTION-FIELD ELECTROSTATICS */
288             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
289             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
290
291             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
292
293             /* Update potential sum for this i atom from the interaction with this j atom. */
294             velec            = _mm_and_pd(velec,cutoff_mask);
295             velecsum         = _mm_add_pd(velecsum,velec);
296
297             fscal            = felec;
298
299             fscal            = _mm_and_pd(fscal,cutoff_mask);
300
301             /* Update vectorial force */
302             fix1             = _mm_macc_pd(dx10,fscal,fix1);
303             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
304             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
305             
306             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
307             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
308             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
309
310             }
311
312             /**************************
313              * CALCULATE INTERACTIONS *
314              **************************/
315
316             if (gmx_mm_any_lt(rsq20,rcutoff2))
317             {
318
319             /* Compute parameters for interactions between i and j atoms */
320             qq20             = _mm_mul_pd(iq2,jq0);
321
322             /* REACTION-FIELD ELECTROSTATICS */
323             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
324             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
325
326             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
327
328             /* Update potential sum for this i atom from the interaction with this j atom. */
329             velec            = _mm_and_pd(velec,cutoff_mask);
330             velecsum         = _mm_add_pd(velecsum,velec);
331
332             fscal            = felec;
333
334             fscal            = _mm_and_pd(fscal,cutoff_mask);
335
336             /* Update vectorial force */
337             fix2             = _mm_macc_pd(dx20,fscal,fix2);
338             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
339             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
340             
341             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
342             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
343             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
344
345             }
346
347             /**************************
348              * CALCULATE INTERACTIONS *
349              **************************/
350
351             if (gmx_mm_any_lt(rsq30,rcutoff2))
352             {
353
354             /* Compute parameters for interactions between i and j atoms */
355             qq30             = _mm_mul_pd(iq3,jq0);
356
357             /* REACTION-FIELD ELECTROSTATICS */
358             velec            = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
359             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
360
361             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
362
363             /* Update potential sum for this i atom from the interaction with this j atom. */
364             velec            = _mm_and_pd(velec,cutoff_mask);
365             velecsum         = _mm_add_pd(velecsum,velec);
366
367             fscal            = felec;
368
369             fscal            = _mm_and_pd(fscal,cutoff_mask);
370
371             /* Update vectorial force */
372             fix3             = _mm_macc_pd(dx30,fscal,fix3);
373             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
374             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
375             
376             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
377             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
378             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
379
380             }
381
382             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
383
384             /* Inner loop uses 164 flops */
385         }
386
387         if(jidx<j_index_end)
388         {
389
390             jnrA             = jjnr[jidx];
391             j_coord_offsetA  = DIM*jnrA;
392
393             /* load j atom coordinates */
394             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
395                                               &jx0,&jy0,&jz0);
396
397             /* Calculate displacement vector */
398             dx00             = _mm_sub_pd(ix0,jx0);
399             dy00             = _mm_sub_pd(iy0,jy0);
400             dz00             = _mm_sub_pd(iz0,jz0);
401             dx10             = _mm_sub_pd(ix1,jx0);
402             dy10             = _mm_sub_pd(iy1,jy0);
403             dz10             = _mm_sub_pd(iz1,jz0);
404             dx20             = _mm_sub_pd(ix2,jx0);
405             dy20             = _mm_sub_pd(iy2,jy0);
406             dz20             = _mm_sub_pd(iz2,jz0);
407             dx30             = _mm_sub_pd(ix3,jx0);
408             dy30             = _mm_sub_pd(iy3,jy0);
409             dz30             = _mm_sub_pd(iz3,jz0);
410
411             /* Calculate squared distance and things based on it */
412             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
413             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
414             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
415             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
416
417             rinv10           = gmx_mm_invsqrt_pd(rsq10);
418             rinv20           = gmx_mm_invsqrt_pd(rsq20);
419             rinv30           = gmx_mm_invsqrt_pd(rsq30);
420
421             rinvsq00         = gmx_mm_inv_pd(rsq00);
422             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
423             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
424             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
425
426             /* Load parameters for j particles */
427             jq0              = _mm_load_sd(charge+jnrA+0);
428             vdwjidx0A        = 2*vdwtype[jnrA+0];
429
430             fjx0             = _mm_setzero_pd();
431             fjy0             = _mm_setzero_pd();
432             fjz0             = _mm_setzero_pd();
433
434             /**************************
435              * CALCULATE INTERACTIONS *
436              **************************/
437
438             if (gmx_mm_any_lt(rsq00,rcutoff2))
439             {
440
441             /* Compute parameters for interactions between i and j atoms */
442             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
443
444             /* LENNARD-JONES DISPERSION/REPULSION */
445
446             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
447             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
448             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
449             vvdw             = _mm_msub_pd(_mm_nmacc_pd(c12_00,_mm_mul_pd(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
450                                            _mm_mul_pd(_mm_nmacc_pd( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
451             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
452
453             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
454
455             /* Update potential sum for this i atom from the interaction with this j atom. */
456             vvdw             = _mm_and_pd(vvdw,cutoff_mask);
457             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
458             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
459
460             fscal            = fvdw;
461
462             fscal            = _mm_and_pd(fscal,cutoff_mask);
463
464             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
465
466             /* Update vectorial force */
467             fix0             = _mm_macc_pd(dx00,fscal,fix0);
468             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
469             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
470             
471             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
472             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
473             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
474
475             }
476
477             /**************************
478              * CALCULATE INTERACTIONS *
479              **************************/
480
481             if (gmx_mm_any_lt(rsq10,rcutoff2))
482             {
483
484             /* Compute parameters for interactions between i and j atoms */
485             qq10             = _mm_mul_pd(iq1,jq0);
486
487             /* REACTION-FIELD ELECTROSTATICS */
488             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
489             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
490
491             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
492
493             /* Update potential sum for this i atom from the interaction with this j atom. */
494             velec            = _mm_and_pd(velec,cutoff_mask);
495             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
496             velecsum         = _mm_add_pd(velecsum,velec);
497
498             fscal            = felec;
499
500             fscal            = _mm_and_pd(fscal,cutoff_mask);
501
502             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
503
504             /* Update vectorial force */
505             fix1             = _mm_macc_pd(dx10,fscal,fix1);
506             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
507             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
508             
509             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
510             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
511             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
512
513             }
514
515             /**************************
516              * CALCULATE INTERACTIONS *
517              **************************/
518
519             if (gmx_mm_any_lt(rsq20,rcutoff2))
520             {
521
522             /* Compute parameters for interactions between i and j atoms */
523             qq20             = _mm_mul_pd(iq2,jq0);
524
525             /* REACTION-FIELD ELECTROSTATICS */
526             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
527             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
528
529             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
530
531             /* Update potential sum for this i atom from the interaction with this j atom. */
532             velec            = _mm_and_pd(velec,cutoff_mask);
533             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
534             velecsum         = _mm_add_pd(velecsum,velec);
535
536             fscal            = felec;
537
538             fscal            = _mm_and_pd(fscal,cutoff_mask);
539
540             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
541
542             /* Update vectorial force */
543             fix2             = _mm_macc_pd(dx20,fscal,fix2);
544             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
545             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
546             
547             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
548             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
549             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
550
551             }
552
553             /**************************
554              * CALCULATE INTERACTIONS *
555              **************************/
556
557             if (gmx_mm_any_lt(rsq30,rcutoff2))
558             {
559
560             /* Compute parameters for interactions between i and j atoms */
561             qq30             = _mm_mul_pd(iq3,jq0);
562
563             /* REACTION-FIELD ELECTROSTATICS */
564             velec            = _mm_mul_pd(qq30,_mm_sub_pd(_mm_macc_pd(krf,rsq30,rinv30),crf));
565             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
566
567             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
568
569             /* Update potential sum for this i atom from the interaction with this j atom. */
570             velec            = _mm_and_pd(velec,cutoff_mask);
571             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
572             velecsum         = _mm_add_pd(velecsum,velec);
573
574             fscal            = felec;
575
576             fscal            = _mm_and_pd(fscal,cutoff_mask);
577
578             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
579
580             /* Update vectorial force */
581             fix3             = _mm_macc_pd(dx30,fscal,fix3);
582             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
583             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
584             
585             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
586             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
587             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
588
589             }
590
591             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
592
593             /* Inner loop uses 164 flops */
594         }
595
596         /* End of innermost loop */
597
598         gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
599                                               f+i_coord_offset,fshift+i_shift_offset);
600
601         ggid                        = gid[iidx];
602         /* Update potential energies */
603         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
604         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
605
606         /* Increment number of inner iterations */
607         inneriter                  += j_index_end - j_index_start;
608
609         /* Outer loop uses 26 flops */
610     }
611
612     /* Increment number of outer iterations */
613     outeriter        += nri;
614
615     /* Update outer/inner flops */
616
617     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*164);
618 }
619 /*
620  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_avx_128_fma_double
621  * Electrostatics interaction: ReactionField
622  * VdW interaction:            LennardJones
623  * Geometry:                   Water4-Particle
624  * Calculate force/pot:        Force
625  */
626 void
627 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_avx_128_fma_double
628                     (t_nblist                    * gmx_restrict       nlist,
629                      rvec                        * gmx_restrict          xx,
630                      rvec                        * gmx_restrict          ff,
631                      t_forcerec                  * gmx_restrict          fr,
632                      t_mdatoms                   * gmx_restrict     mdatoms,
633                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
634                      t_nrnb                      * gmx_restrict        nrnb)
635 {
636     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
637      * just 0 for non-waters.
638      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
639      * jnr indices corresponding to data put in the four positions in the SIMD register.
640      */
641     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
642     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
643     int              jnrA,jnrB;
644     int              j_coord_offsetA,j_coord_offsetB;
645     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
646     real             rcutoff_scalar;
647     real             *shiftvec,*fshift,*x,*f;
648     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
649     int              vdwioffset0;
650     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
651     int              vdwioffset1;
652     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
653     int              vdwioffset2;
654     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
655     int              vdwioffset3;
656     __m128d          ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
657     int              vdwjidx0A,vdwjidx0B;
658     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
659     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
660     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
661     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
662     __m128d          dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
663     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
664     real             *charge;
665     int              nvdwtype;
666     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
667     int              *vdwtype;
668     real             *vdwparam;
669     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
670     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
671     __m128d          dummy_mask,cutoff_mask;
672     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
673     __m128d          one     = _mm_set1_pd(1.0);
674     __m128d          two     = _mm_set1_pd(2.0);
675     x                = xx[0];
676     f                = ff[0];
677
678     nri              = nlist->nri;
679     iinr             = nlist->iinr;
680     jindex           = nlist->jindex;
681     jjnr             = nlist->jjnr;
682     shiftidx         = nlist->shift;
683     gid              = nlist->gid;
684     shiftvec         = fr->shift_vec[0];
685     fshift           = fr->fshift[0];
686     facel            = _mm_set1_pd(fr->epsfac);
687     charge           = mdatoms->chargeA;
688     krf              = _mm_set1_pd(fr->ic->k_rf);
689     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
690     crf              = _mm_set1_pd(fr->ic->c_rf);
691     nvdwtype         = fr->ntype;
692     vdwparam         = fr->nbfp;
693     vdwtype          = mdatoms->typeA;
694
695     /* Setup water-specific parameters */
696     inr              = nlist->iinr[0];
697     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
698     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
699     iq3              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+3]));
700     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
701
702     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
703     rcutoff_scalar   = fr->rcoulomb;
704     rcutoff          = _mm_set1_pd(rcutoff_scalar);
705     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
706
707     sh_vdw_invrcut6  = _mm_set1_pd(fr->ic->sh_invrc6);
708     rvdw             = _mm_set1_pd(fr->rvdw);
709
710     /* Avoid stupid compiler warnings */
711     jnrA = jnrB = 0;
712     j_coord_offsetA = 0;
713     j_coord_offsetB = 0;
714
715     outeriter        = 0;
716     inneriter        = 0;
717
718     /* Start outer loop over neighborlists */
719     for(iidx=0; iidx<nri; iidx++)
720     {
721         /* Load shift vector for this list */
722         i_shift_offset   = DIM*shiftidx[iidx];
723
724         /* Load limits for loop over neighbors */
725         j_index_start    = jindex[iidx];
726         j_index_end      = jindex[iidx+1];
727
728         /* Get outer coordinate index */
729         inr              = iinr[iidx];
730         i_coord_offset   = DIM*inr;
731
732         /* Load i particle coords and add shift vector */
733         gmx_mm_load_shift_and_4rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
734                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
735
736         fix0             = _mm_setzero_pd();
737         fiy0             = _mm_setzero_pd();
738         fiz0             = _mm_setzero_pd();
739         fix1             = _mm_setzero_pd();
740         fiy1             = _mm_setzero_pd();
741         fiz1             = _mm_setzero_pd();
742         fix2             = _mm_setzero_pd();
743         fiy2             = _mm_setzero_pd();
744         fiz2             = _mm_setzero_pd();
745         fix3             = _mm_setzero_pd();
746         fiy3             = _mm_setzero_pd();
747         fiz3             = _mm_setzero_pd();
748
749         /* Start inner kernel loop */
750         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
751         {
752
753             /* Get j neighbor index, and coordinate index */
754             jnrA             = jjnr[jidx];
755             jnrB             = jjnr[jidx+1];
756             j_coord_offsetA  = DIM*jnrA;
757             j_coord_offsetB  = DIM*jnrB;
758
759             /* load j atom coordinates */
760             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
761                                               &jx0,&jy0,&jz0);
762
763             /* Calculate displacement vector */
764             dx00             = _mm_sub_pd(ix0,jx0);
765             dy00             = _mm_sub_pd(iy0,jy0);
766             dz00             = _mm_sub_pd(iz0,jz0);
767             dx10             = _mm_sub_pd(ix1,jx0);
768             dy10             = _mm_sub_pd(iy1,jy0);
769             dz10             = _mm_sub_pd(iz1,jz0);
770             dx20             = _mm_sub_pd(ix2,jx0);
771             dy20             = _mm_sub_pd(iy2,jy0);
772             dz20             = _mm_sub_pd(iz2,jz0);
773             dx30             = _mm_sub_pd(ix3,jx0);
774             dy30             = _mm_sub_pd(iy3,jy0);
775             dz30             = _mm_sub_pd(iz3,jz0);
776
777             /* Calculate squared distance and things based on it */
778             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
779             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
780             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
781             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
782
783             rinv10           = gmx_mm_invsqrt_pd(rsq10);
784             rinv20           = gmx_mm_invsqrt_pd(rsq20);
785             rinv30           = gmx_mm_invsqrt_pd(rsq30);
786
787             rinvsq00         = gmx_mm_inv_pd(rsq00);
788             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
789             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
790             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
791
792             /* Load parameters for j particles */
793             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
794             vdwjidx0A        = 2*vdwtype[jnrA+0];
795             vdwjidx0B        = 2*vdwtype[jnrB+0];
796
797             fjx0             = _mm_setzero_pd();
798             fjy0             = _mm_setzero_pd();
799             fjz0             = _mm_setzero_pd();
800
801             /**************************
802              * CALCULATE INTERACTIONS *
803              **************************/
804
805             if (gmx_mm_any_lt(rsq00,rcutoff2))
806             {
807
808             /* Compute parameters for interactions between i and j atoms */
809             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
810                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
811
812             /* LENNARD-JONES DISPERSION/REPULSION */
813
814             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
815             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
816
817             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
818
819             fscal            = fvdw;
820
821             fscal            = _mm_and_pd(fscal,cutoff_mask);
822
823             /* Update vectorial force */
824             fix0             = _mm_macc_pd(dx00,fscal,fix0);
825             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
826             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
827             
828             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
829             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
830             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
831
832             }
833
834             /**************************
835              * CALCULATE INTERACTIONS *
836              **************************/
837
838             if (gmx_mm_any_lt(rsq10,rcutoff2))
839             {
840
841             /* Compute parameters for interactions between i and j atoms */
842             qq10             = _mm_mul_pd(iq1,jq0);
843
844             /* REACTION-FIELD ELECTROSTATICS */
845             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
846
847             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
848
849             fscal            = felec;
850
851             fscal            = _mm_and_pd(fscal,cutoff_mask);
852
853             /* Update vectorial force */
854             fix1             = _mm_macc_pd(dx10,fscal,fix1);
855             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
856             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
857             
858             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
859             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
860             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
861
862             }
863
864             /**************************
865              * CALCULATE INTERACTIONS *
866              **************************/
867
868             if (gmx_mm_any_lt(rsq20,rcutoff2))
869             {
870
871             /* Compute parameters for interactions between i and j atoms */
872             qq20             = _mm_mul_pd(iq2,jq0);
873
874             /* REACTION-FIELD ELECTROSTATICS */
875             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
876
877             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
878
879             fscal            = felec;
880
881             fscal            = _mm_and_pd(fscal,cutoff_mask);
882
883             /* Update vectorial force */
884             fix2             = _mm_macc_pd(dx20,fscal,fix2);
885             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
886             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
887             
888             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
889             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
890             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
891
892             }
893
894             /**************************
895              * CALCULATE INTERACTIONS *
896              **************************/
897
898             if (gmx_mm_any_lt(rsq30,rcutoff2))
899             {
900
901             /* Compute parameters for interactions between i and j atoms */
902             qq30             = _mm_mul_pd(iq3,jq0);
903
904             /* REACTION-FIELD ELECTROSTATICS */
905             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
906
907             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
908
909             fscal            = felec;
910
911             fscal            = _mm_and_pd(fscal,cutoff_mask);
912
913             /* Update vectorial force */
914             fix3             = _mm_macc_pd(dx30,fscal,fix3);
915             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
916             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
917             
918             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
919             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
920             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
921
922             }
923
924             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
925
926             /* Inner loop uses 135 flops */
927         }
928
929         if(jidx<j_index_end)
930         {
931
932             jnrA             = jjnr[jidx];
933             j_coord_offsetA  = DIM*jnrA;
934
935             /* load j atom coordinates */
936             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
937                                               &jx0,&jy0,&jz0);
938
939             /* Calculate displacement vector */
940             dx00             = _mm_sub_pd(ix0,jx0);
941             dy00             = _mm_sub_pd(iy0,jy0);
942             dz00             = _mm_sub_pd(iz0,jz0);
943             dx10             = _mm_sub_pd(ix1,jx0);
944             dy10             = _mm_sub_pd(iy1,jy0);
945             dz10             = _mm_sub_pd(iz1,jz0);
946             dx20             = _mm_sub_pd(ix2,jx0);
947             dy20             = _mm_sub_pd(iy2,jy0);
948             dz20             = _mm_sub_pd(iz2,jz0);
949             dx30             = _mm_sub_pd(ix3,jx0);
950             dy30             = _mm_sub_pd(iy3,jy0);
951             dz30             = _mm_sub_pd(iz3,jz0);
952
953             /* Calculate squared distance and things based on it */
954             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
955             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
956             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
957             rsq30            = gmx_mm_calc_rsq_pd(dx30,dy30,dz30);
958
959             rinv10           = gmx_mm_invsqrt_pd(rsq10);
960             rinv20           = gmx_mm_invsqrt_pd(rsq20);
961             rinv30           = gmx_mm_invsqrt_pd(rsq30);
962
963             rinvsq00         = gmx_mm_inv_pd(rsq00);
964             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
965             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
966             rinvsq30         = _mm_mul_pd(rinv30,rinv30);
967
968             /* Load parameters for j particles */
969             jq0              = _mm_load_sd(charge+jnrA+0);
970             vdwjidx0A        = 2*vdwtype[jnrA+0];
971
972             fjx0             = _mm_setzero_pd();
973             fjy0             = _mm_setzero_pd();
974             fjz0             = _mm_setzero_pd();
975
976             /**************************
977              * CALCULATE INTERACTIONS *
978              **************************/
979
980             if (gmx_mm_any_lt(rsq00,rcutoff2))
981             {
982
983             /* Compute parameters for interactions between i and j atoms */
984             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
985
986             /* LENNARD-JONES DISPERSION/REPULSION */
987
988             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
989             fvdw             = _mm_mul_pd(_mm_msub_pd(c12_00,rinvsix,c6_00),_mm_mul_pd(rinvsix,rinvsq00));
990
991             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
992
993             fscal            = fvdw;
994
995             fscal            = _mm_and_pd(fscal,cutoff_mask);
996
997             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
998
999             /* Update vectorial force */
1000             fix0             = _mm_macc_pd(dx00,fscal,fix0);
1001             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
1002             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
1003             
1004             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
1005             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
1006             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
1007
1008             }
1009
1010             /**************************
1011              * CALCULATE INTERACTIONS *
1012              **************************/
1013
1014             if (gmx_mm_any_lt(rsq10,rcutoff2))
1015             {
1016
1017             /* Compute parameters for interactions between i and j atoms */
1018             qq10             = _mm_mul_pd(iq1,jq0);
1019
1020             /* REACTION-FIELD ELECTROSTATICS */
1021             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
1022
1023             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
1024
1025             fscal            = felec;
1026
1027             fscal            = _mm_and_pd(fscal,cutoff_mask);
1028
1029             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1030
1031             /* Update vectorial force */
1032             fix1             = _mm_macc_pd(dx10,fscal,fix1);
1033             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
1034             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
1035             
1036             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
1037             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
1038             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
1039
1040             }
1041
1042             /**************************
1043              * CALCULATE INTERACTIONS *
1044              **************************/
1045
1046             if (gmx_mm_any_lt(rsq20,rcutoff2))
1047             {
1048
1049             /* Compute parameters for interactions between i and j atoms */
1050             qq20             = _mm_mul_pd(iq2,jq0);
1051
1052             /* REACTION-FIELD ELECTROSTATICS */
1053             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
1054
1055             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
1056
1057             fscal            = felec;
1058
1059             fscal            = _mm_and_pd(fscal,cutoff_mask);
1060
1061             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1062
1063             /* Update vectorial force */
1064             fix2             = _mm_macc_pd(dx20,fscal,fix2);
1065             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
1066             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
1067             
1068             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
1069             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
1070             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
1071
1072             }
1073
1074             /**************************
1075              * CALCULATE INTERACTIONS *
1076              **************************/
1077
1078             if (gmx_mm_any_lt(rsq30,rcutoff2))
1079             {
1080
1081             /* Compute parameters for interactions between i and j atoms */
1082             qq30             = _mm_mul_pd(iq3,jq0);
1083
1084             /* REACTION-FIELD ELECTROSTATICS */
1085             felec            = _mm_mul_pd(qq30,_mm_msub_pd(rinv30,rinvsq30,krf2));
1086
1087             cutoff_mask      = _mm_cmplt_pd(rsq30,rcutoff2);
1088
1089             fscal            = felec;
1090
1091             fscal            = _mm_and_pd(fscal,cutoff_mask);
1092
1093             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
1094
1095             /* Update vectorial force */
1096             fix3             = _mm_macc_pd(dx30,fscal,fix3);
1097             fiy3             = _mm_macc_pd(dy30,fscal,fiy3);
1098             fiz3             = _mm_macc_pd(dz30,fscal,fiz3);
1099             
1100             fjx0             = _mm_macc_pd(dx30,fscal,fjx0);
1101             fjy0             = _mm_macc_pd(dy30,fscal,fjy0);
1102             fjz0             = _mm_macc_pd(dz30,fscal,fjz0);
1103
1104             }
1105
1106             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1107
1108             /* Inner loop uses 135 flops */
1109         }
1110
1111         /* End of innermost loop */
1112
1113         gmx_mm_update_iforce_4atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1114                                               f+i_coord_offset,fshift+i_shift_offset);
1115
1116         /* Increment number of inner iterations */
1117         inneriter                  += j_index_end - j_index_start;
1118
1119         /* Outer loop uses 24 flops */
1120     }
1121
1122     /* Increment number of outer iterations */
1123     outeriter        += nri;
1124
1125     /* Update outer/inner flops */
1126
1127     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*135);
1128 }