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