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