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