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