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