Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_256_single / nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_avx_256_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_256_single kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_256_single.h"
50 #include "kernelutil_x86_avx_256_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_256_single
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            LennardJones
56  * Geometry:                   Water3-Water3
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_VF_avx_256_single
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
70      * just 0 for non-waters.
71      * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB,jnrC,jnrD;
77     int              jnrE,jnrF,jnrG,jnrH;
78     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
79     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
80     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
81     int              j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
82     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
83     real             rcutoff_scalar;
84     real             *shiftvec,*fshift,*x,*f;
85     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
86     real             scratch[4*DIM];
87     __m256           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
88     real *           vdwioffsetptr0;
89     __m256           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
90     real *           vdwioffsetptr1;
91     __m256           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
92     real *           vdwioffsetptr2;
93     __m256           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
94     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
95     __m256           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
96     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
97     __m256           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
98     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
99     __m256           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
100     __m256           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
101     __m256           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
102     __m256           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
103     __m256           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
104     __m256           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
105     __m256           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
106     __m256           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
107     __m256           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
108     __m256           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
109     __m256           velec,felec,velecsum,facel,crf,krf,krf2;
110     real             *charge;
111     int              nvdwtype;
112     __m256           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
113     int              *vdwtype;
114     real             *vdwparam;
115     __m256           one_sixth   = _mm256_set1_ps(1.0/6.0);
116     __m256           one_twelfth = _mm256_set1_ps(1.0/12.0);
117     __m256           dummy_mask,cutoff_mask;
118     __m256           signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
119     __m256           one     = _mm256_set1_ps(1.0);
120     __m256           two     = _mm256_set1_ps(2.0);
121     x                = xx[0];
122     f                = ff[0];
123
124     nri              = nlist->nri;
125     iinr             = nlist->iinr;
126     jindex           = nlist->jindex;
127     jjnr             = nlist->jjnr;
128     shiftidx         = nlist->shift;
129     gid              = nlist->gid;
130     shiftvec         = fr->shift_vec[0];
131     fshift           = fr->fshift[0];
132     facel            = _mm256_set1_ps(fr->epsfac);
133     charge           = mdatoms->chargeA;
134     krf              = _mm256_set1_ps(fr->ic->k_rf);
135     krf2             = _mm256_set1_ps(fr->ic->k_rf*2.0);
136     crf              = _mm256_set1_ps(fr->ic->c_rf);
137     nvdwtype         = fr->ntype;
138     vdwparam         = fr->nbfp;
139     vdwtype          = mdatoms->typeA;
140
141     /* Setup water-specific parameters */
142     inr              = nlist->iinr[0];
143     iq0              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
144     iq1              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
145     iq2              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
146     vdwioffsetptr0   = vdwparam+2*nvdwtype*vdwtype[inr+0];
147
148     jq0              = _mm256_set1_ps(charge[inr+0]);
149     jq1              = _mm256_set1_ps(charge[inr+1]);
150     jq2              = _mm256_set1_ps(charge[inr+2]);
151     vdwjidx0A        = 2*vdwtype[inr+0];
152     qq00             = _mm256_mul_ps(iq0,jq0);
153     c6_00            = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
154     c12_00           = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
155     qq01             = _mm256_mul_ps(iq0,jq1);
156     qq02             = _mm256_mul_ps(iq0,jq2);
157     qq10             = _mm256_mul_ps(iq1,jq0);
158     qq11             = _mm256_mul_ps(iq1,jq1);
159     qq12             = _mm256_mul_ps(iq1,jq2);
160     qq20             = _mm256_mul_ps(iq2,jq0);
161     qq21             = _mm256_mul_ps(iq2,jq1);
162     qq22             = _mm256_mul_ps(iq2,jq2);
163
164     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
165     rcutoff_scalar   = fr->rcoulomb;
166     rcutoff          = _mm256_set1_ps(rcutoff_scalar);
167     rcutoff2         = _mm256_mul_ps(rcutoff,rcutoff);
168
169     sh_vdw_invrcut6  = _mm256_set1_ps(fr->ic->sh_invrc6);
170     rvdw             = _mm256_set1_ps(fr->rvdw);
171
172     /* Avoid stupid compiler warnings */
173     jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
174     j_coord_offsetA = 0;
175     j_coord_offsetB = 0;
176     j_coord_offsetC = 0;
177     j_coord_offsetD = 0;
178     j_coord_offsetE = 0;
179     j_coord_offsetF = 0;
180     j_coord_offsetG = 0;
181     j_coord_offsetH = 0;
182
183     outeriter        = 0;
184     inneriter        = 0;
185
186     for(iidx=0;iidx<4*DIM;iidx++)
187     {
188         scratch[iidx] = 0.0;
189     }
190
191     /* Start outer loop over neighborlists */
192     for(iidx=0; iidx<nri; iidx++)
193     {
194         /* Load shift vector for this list */
195         i_shift_offset   = DIM*shiftidx[iidx];
196
197         /* Load limits for loop over neighbors */
198         j_index_start    = jindex[iidx];
199         j_index_end      = jindex[iidx+1];
200
201         /* Get outer coordinate index */
202         inr              = iinr[iidx];
203         i_coord_offset   = DIM*inr;
204
205         /* Load i particle coords and add shift vector */
206         gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
207                                                     &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
208
209         fix0             = _mm256_setzero_ps();
210         fiy0             = _mm256_setzero_ps();
211         fiz0             = _mm256_setzero_ps();
212         fix1             = _mm256_setzero_ps();
213         fiy1             = _mm256_setzero_ps();
214         fiz1             = _mm256_setzero_ps();
215         fix2             = _mm256_setzero_ps();
216         fiy2             = _mm256_setzero_ps();
217         fiz2             = _mm256_setzero_ps();
218
219         /* Reset potential sums */
220         velecsum         = _mm256_setzero_ps();
221         vvdwsum          = _mm256_setzero_ps();
222
223         /* Start inner kernel loop */
224         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
225         {
226
227             /* Get j neighbor index, and coordinate index */
228             jnrA             = jjnr[jidx];
229             jnrB             = jjnr[jidx+1];
230             jnrC             = jjnr[jidx+2];
231             jnrD             = jjnr[jidx+3];
232             jnrE             = jjnr[jidx+4];
233             jnrF             = jjnr[jidx+5];
234             jnrG             = jjnr[jidx+6];
235             jnrH             = jjnr[jidx+7];
236             j_coord_offsetA  = DIM*jnrA;
237             j_coord_offsetB  = DIM*jnrB;
238             j_coord_offsetC  = DIM*jnrC;
239             j_coord_offsetD  = DIM*jnrD;
240             j_coord_offsetE  = DIM*jnrE;
241             j_coord_offsetF  = DIM*jnrF;
242             j_coord_offsetG  = DIM*jnrG;
243             j_coord_offsetH  = DIM*jnrH;
244
245             /* load j atom coordinates */
246             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
247                                                  x+j_coord_offsetC,x+j_coord_offsetD,
248                                                  x+j_coord_offsetE,x+j_coord_offsetF,
249                                                  x+j_coord_offsetG,x+j_coord_offsetH,
250                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
251
252             /* Calculate displacement vector */
253             dx00             = _mm256_sub_ps(ix0,jx0);
254             dy00             = _mm256_sub_ps(iy0,jy0);
255             dz00             = _mm256_sub_ps(iz0,jz0);
256             dx01             = _mm256_sub_ps(ix0,jx1);
257             dy01             = _mm256_sub_ps(iy0,jy1);
258             dz01             = _mm256_sub_ps(iz0,jz1);
259             dx02             = _mm256_sub_ps(ix0,jx2);
260             dy02             = _mm256_sub_ps(iy0,jy2);
261             dz02             = _mm256_sub_ps(iz0,jz2);
262             dx10             = _mm256_sub_ps(ix1,jx0);
263             dy10             = _mm256_sub_ps(iy1,jy0);
264             dz10             = _mm256_sub_ps(iz1,jz0);
265             dx11             = _mm256_sub_ps(ix1,jx1);
266             dy11             = _mm256_sub_ps(iy1,jy1);
267             dz11             = _mm256_sub_ps(iz1,jz1);
268             dx12             = _mm256_sub_ps(ix1,jx2);
269             dy12             = _mm256_sub_ps(iy1,jy2);
270             dz12             = _mm256_sub_ps(iz1,jz2);
271             dx20             = _mm256_sub_ps(ix2,jx0);
272             dy20             = _mm256_sub_ps(iy2,jy0);
273             dz20             = _mm256_sub_ps(iz2,jz0);
274             dx21             = _mm256_sub_ps(ix2,jx1);
275             dy21             = _mm256_sub_ps(iy2,jy1);
276             dz21             = _mm256_sub_ps(iz2,jz1);
277             dx22             = _mm256_sub_ps(ix2,jx2);
278             dy22             = _mm256_sub_ps(iy2,jy2);
279             dz22             = _mm256_sub_ps(iz2,jz2);
280
281             /* Calculate squared distance and things based on it */
282             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
283             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
284             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
285             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
286             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
287             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
288             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
289             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
290             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
291
292             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
293             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
294             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
295             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
296             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
297             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
298             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
299             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
300             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
301
302             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
303             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
304             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
305             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
306             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
307             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
308             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
309             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
310             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
311
312             fjx0             = _mm256_setzero_ps();
313             fjy0             = _mm256_setzero_ps();
314             fjz0             = _mm256_setzero_ps();
315             fjx1             = _mm256_setzero_ps();
316             fjy1             = _mm256_setzero_ps();
317             fjz1             = _mm256_setzero_ps();
318             fjx2             = _mm256_setzero_ps();
319             fjy2             = _mm256_setzero_ps();
320             fjz2             = _mm256_setzero_ps();
321
322             /**************************
323              * CALCULATE INTERACTIONS *
324              **************************/
325
326             if (gmx_mm256_any_lt(rsq00,rcutoff2))
327             {
328
329             /* REACTION-FIELD ELECTROSTATICS */
330             velec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
331             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
332
333             /* LENNARD-JONES DISPERSION/REPULSION */
334
335             rinvsix          = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
336             vvdw6            = _mm256_mul_ps(c6_00,rinvsix);
337             vvdw12           = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
338             vvdw             = _mm256_sub_ps(_mm256_mul_ps( _mm256_sub_ps(vvdw12 , _mm256_mul_ps(c12_00,_mm256_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
339                                           _mm256_mul_ps( _mm256_sub_ps(vvdw6,_mm256_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
340             fvdw             = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
341
342             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
343
344             /* Update potential sum for this i atom from the interaction with this j atom. */
345             velec            = _mm256_and_ps(velec,cutoff_mask);
346             velecsum         = _mm256_add_ps(velecsum,velec);
347             vvdw             = _mm256_and_ps(vvdw,cutoff_mask);
348             vvdwsum          = _mm256_add_ps(vvdwsum,vvdw);
349
350             fscal            = _mm256_add_ps(felec,fvdw);
351
352             fscal            = _mm256_and_ps(fscal,cutoff_mask);
353
354             /* Calculate temporary vectorial force */
355             tx               = _mm256_mul_ps(fscal,dx00);
356             ty               = _mm256_mul_ps(fscal,dy00);
357             tz               = _mm256_mul_ps(fscal,dz00);
358
359             /* Update vectorial force */
360             fix0             = _mm256_add_ps(fix0,tx);
361             fiy0             = _mm256_add_ps(fiy0,ty);
362             fiz0             = _mm256_add_ps(fiz0,tz);
363
364             fjx0             = _mm256_add_ps(fjx0,tx);
365             fjy0             = _mm256_add_ps(fjy0,ty);
366             fjz0             = _mm256_add_ps(fjz0,tz);
367
368             }
369
370             /**************************
371              * CALCULATE INTERACTIONS *
372              **************************/
373
374             if (gmx_mm256_any_lt(rsq01,rcutoff2))
375             {
376
377             /* REACTION-FIELD ELECTROSTATICS */
378             velec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
379             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
380
381             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
382
383             /* Update potential sum for this i atom from the interaction with this j atom. */
384             velec            = _mm256_and_ps(velec,cutoff_mask);
385             velecsum         = _mm256_add_ps(velecsum,velec);
386
387             fscal            = felec;
388
389             fscal            = _mm256_and_ps(fscal,cutoff_mask);
390
391             /* Calculate temporary vectorial force */
392             tx               = _mm256_mul_ps(fscal,dx01);
393             ty               = _mm256_mul_ps(fscal,dy01);
394             tz               = _mm256_mul_ps(fscal,dz01);
395
396             /* Update vectorial force */
397             fix0             = _mm256_add_ps(fix0,tx);
398             fiy0             = _mm256_add_ps(fiy0,ty);
399             fiz0             = _mm256_add_ps(fiz0,tz);
400
401             fjx1             = _mm256_add_ps(fjx1,tx);
402             fjy1             = _mm256_add_ps(fjy1,ty);
403             fjz1             = _mm256_add_ps(fjz1,tz);
404
405             }
406
407             /**************************
408              * CALCULATE INTERACTIONS *
409              **************************/
410
411             if (gmx_mm256_any_lt(rsq02,rcutoff2))
412             {
413
414             /* REACTION-FIELD ELECTROSTATICS */
415             velec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
416             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
417
418             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
419
420             /* Update potential sum for this i atom from the interaction with this j atom. */
421             velec            = _mm256_and_ps(velec,cutoff_mask);
422             velecsum         = _mm256_add_ps(velecsum,velec);
423
424             fscal            = felec;
425
426             fscal            = _mm256_and_ps(fscal,cutoff_mask);
427
428             /* Calculate temporary vectorial force */
429             tx               = _mm256_mul_ps(fscal,dx02);
430             ty               = _mm256_mul_ps(fscal,dy02);
431             tz               = _mm256_mul_ps(fscal,dz02);
432
433             /* Update vectorial force */
434             fix0             = _mm256_add_ps(fix0,tx);
435             fiy0             = _mm256_add_ps(fiy0,ty);
436             fiz0             = _mm256_add_ps(fiz0,tz);
437
438             fjx2             = _mm256_add_ps(fjx2,tx);
439             fjy2             = _mm256_add_ps(fjy2,ty);
440             fjz2             = _mm256_add_ps(fjz2,tz);
441
442             }
443
444             /**************************
445              * CALCULATE INTERACTIONS *
446              **************************/
447
448             if (gmx_mm256_any_lt(rsq10,rcutoff2))
449             {
450
451             /* REACTION-FIELD ELECTROSTATICS */
452             velec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
453             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
454
455             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
456
457             /* Update potential sum for this i atom from the interaction with this j atom. */
458             velec            = _mm256_and_ps(velec,cutoff_mask);
459             velecsum         = _mm256_add_ps(velecsum,velec);
460
461             fscal            = felec;
462
463             fscal            = _mm256_and_ps(fscal,cutoff_mask);
464
465             /* Calculate temporary vectorial force */
466             tx               = _mm256_mul_ps(fscal,dx10);
467             ty               = _mm256_mul_ps(fscal,dy10);
468             tz               = _mm256_mul_ps(fscal,dz10);
469
470             /* Update vectorial force */
471             fix1             = _mm256_add_ps(fix1,tx);
472             fiy1             = _mm256_add_ps(fiy1,ty);
473             fiz1             = _mm256_add_ps(fiz1,tz);
474
475             fjx0             = _mm256_add_ps(fjx0,tx);
476             fjy0             = _mm256_add_ps(fjy0,ty);
477             fjz0             = _mm256_add_ps(fjz0,tz);
478
479             }
480
481             /**************************
482              * CALCULATE INTERACTIONS *
483              **************************/
484
485             if (gmx_mm256_any_lt(rsq11,rcutoff2))
486             {
487
488             /* REACTION-FIELD ELECTROSTATICS */
489             velec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
490             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
491
492             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
493
494             /* Update potential sum for this i atom from the interaction with this j atom. */
495             velec            = _mm256_and_ps(velec,cutoff_mask);
496             velecsum         = _mm256_add_ps(velecsum,velec);
497
498             fscal            = felec;
499
500             fscal            = _mm256_and_ps(fscal,cutoff_mask);
501
502             /* Calculate temporary vectorial force */
503             tx               = _mm256_mul_ps(fscal,dx11);
504             ty               = _mm256_mul_ps(fscal,dy11);
505             tz               = _mm256_mul_ps(fscal,dz11);
506
507             /* Update vectorial force */
508             fix1             = _mm256_add_ps(fix1,tx);
509             fiy1             = _mm256_add_ps(fiy1,ty);
510             fiz1             = _mm256_add_ps(fiz1,tz);
511
512             fjx1             = _mm256_add_ps(fjx1,tx);
513             fjy1             = _mm256_add_ps(fjy1,ty);
514             fjz1             = _mm256_add_ps(fjz1,tz);
515
516             }
517
518             /**************************
519              * CALCULATE INTERACTIONS *
520              **************************/
521
522             if (gmx_mm256_any_lt(rsq12,rcutoff2))
523             {
524
525             /* REACTION-FIELD ELECTROSTATICS */
526             velec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
527             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
528
529             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
530
531             /* Update potential sum for this i atom from the interaction with this j atom. */
532             velec            = _mm256_and_ps(velec,cutoff_mask);
533             velecsum         = _mm256_add_ps(velecsum,velec);
534
535             fscal            = felec;
536
537             fscal            = _mm256_and_ps(fscal,cutoff_mask);
538
539             /* Calculate temporary vectorial force */
540             tx               = _mm256_mul_ps(fscal,dx12);
541             ty               = _mm256_mul_ps(fscal,dy12);
542             tz               = _mm256_mul_ps(fscal,dz12);
543
544             /* Update vectorial force */
545             fix1             = _mm256_add_ps(fix1,tx);
546             fiy1             = _mm256_add_ps(fiy1,ty);
547             fiz1             = _mm256_add_ps(fiz1,tz);
548
549             fjx2             = _mm256_add_ps(fjx2,tx);
550             fjy2             = _mm256_add_ps(fjy2,ty);
551             fjz2             = _mm256_add_ps(fjz2,tz);
552
553             }
554
555             /**************************
556              * CALCULATE INTERACTIONS *
557              **************************/
558
559             if (gmx_mm256_any_lt(rsq20,rcutoff2))
560             {
561
562             /* REACTION-FIELD ELECTROSTATICS */
563             velec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
564             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
565
566             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
567
568             /* Update potential sum for this i atom from the interaction with this j atom. */
569             velec            = _mm256_and_ps(velec,cutoff_mask);
570             velecsum         = _mm256_add_ps(velecsum,velec);
571
572             fscal            = felec;
573
574             fscal            = _mm256_and_ps(fscal,cutoff_mask);
575
576             /* Calculate temporary vectorial force */
577             tx               = _mm256_mul_ps(fscal,dx20);
578             ty               = _mm256_mul_ps(fscal,dy20);
579             tz               = _mm256_mul_ps(fscal,dz20);
580
581             /* Update vectorial force */
582             fix2             = _mm256_add_ps(fix2,tx);
583             fiy2             = _mm256_add_ps(fiy2,ty);
584             fiz2             = _mm256_add_ps(fiz2,tz);
585
586             fjx0             = _mm256_add_ps(fjx0,tx);
587             fjy0             = _mm256_add_ps(fjy0,ty);
588             fjz0             = _mm256_add_ps(fjz0,tz);
589
590             }
591
592             /**************************
593              * CALCULATE INTERACTIONS *
594              **************************/
595
596             if (gmx_mm256_any_lt(rsq21,rcutoff2))
597             {
598
599             /* REACTION-FIELD ELECTROSTATICS */
600             velec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
601             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
602
603             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
604
605             /* Update potential sum for this i atom from the interaction with this j atom. */
606             velec            = _mm256_and_ps(velec,cutoff_mask);
607             velecsum         = _mm256_add_ps(velecsum,velec);
608
609             fscal            = felec;
610
611             fscal            = _mm256_and_ps(fscal,cutoff_mask);
612
613             /* Calculate temporary vectorial force */
614             tx               = _mm256_mul_ps(fscal,dx21);
615             ty               = _mm256_mul_ps(fscal,dy21);
616             tz               = _mm256_mul_ps(fscal,dz21);
617
618             /* Update vectorial force */
619             fix2             = _mm256_add_ps(fix2,tx);
620             fiy2             = _mm256_add_ps(fiy2,ty);
621             fiz2             = _mm256_add_ps(fiz2,tz);
622
623             fjx1             = _mm256_add_ps(fjx1,tx);
624             fjy1             = _mm256_add_ps(fjy1,ty);
625             fjz1             = _mm256_add_ps(fjz1,tz);
626
627             }
628
629             /**************************
630              * CALCULATE INTERACTIONS *
631              **************************/
632
633             if (gmx_mm256_any_lt(rsq22,rcutoff2))
634             {
635
636             /* REACTION-FIELD ELECTROSTATICS */
637             velec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
638             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
639
640             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
641
642             /* Update potential sum for this i atom from the interaction with this j atom. */
643             velec            = _mm256_and_ps(velec,cutoff_mask);
644             velecsum         = _mm256_add_ps(velecsum,velec);
645
646             fscal            = felec;
647
648             fscal            = _mm256_and_ps(fscal,cutoff_mask);
649
650             /* Calculate temporary vectorial force */
651             tx               = _mm256_mul_ps(fscal,dx22);
652             ty               = _mm256_mul_ps(fscal,dy22);
653             tz               = _mm256_mul_ps(fscal,dz22);
654
655             /* Update vectorial force */
656             fix2             = _mm256_add_ps(fix2,tx);
657             fiy2             = _mm256_add_ps(fiy2,ty);
658             fiz2             = _mm256_add_ps(fiz2,tz);
659
660             fjx2             = _mm256_add_ps(fjx2,tx);
661             fjy2             = _mm256_add_ps(fjy2,ty);
662             fjz2             = _mm256_add_ps(fjz2,tz);
663
664             }
665
666             fjptrA             = f+j_coord_offsetA;
667             fjptrB             = f+j_coord_offsetB;
668             fjptrC             = f+j_coord_offsetC;
669             fjptrD             = f+j_coord_offsetD;
670             fjptrE             = f+j_coord_offsetE;
671             fjptrF             = f+j_coord_offsetF;
672             fjptrG             = f+j_coord_offsetG;
673             fjptrH             = f+j_coord_offsetH;
674
675             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
676                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
677
678             /* Inner loop uses 342 flops */
679         }
680
681         if(jidx<j_index_end)
682         {
683
684             /* Get j neighbor index, and coordinate index */
685             jnrlistA         = jjnr[jidx];
686             jnrlistB         = jjnr[jidx+1];
687             jnrlistC         = jjnr[jidx+2];
688             jnrlistD         = jjnr[jidx+3];
689             jnrlistE         = jjnr[jidx+4];
690             jnrlistF         = jjnr[jidx+5];
691             jnrlistG         = jjnr[jidx+6];
692             jnrlistH         = jjnr[jidx+7];
693             /* Sign of each element will be negative for non-real atoms.
694              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
695              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
696              */
697             dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
698                                             gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
699                                             
700             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
701             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
702             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
703             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
704             jnrE       = (jnrlistE>=0) ? jnrlistE : 0;
705             jnrF       = (jnrlistF>=0) ? jnrlistF : 0;
706             jnrG       = (jnrlistG>=0) ? jnrlistG : 0;
707             jnrH       = (jnrlistH>=0) ? jnrlistH : 0;
708             j_coord_offsetA  = DIM*jnrA;
709             j_coord_offsetB  = DIM*jnrB;
710             j_coord_offsetC  = DIM*jnrC;
711             j_coord_offsetD  = DIM*jnrD;
712             j_coord_offsetE  = DIM*jnrE;
713             j_coord_offsetF  = DIM*jnrF;
714             j_coord_offsetG  = DIM*jnrG;
715             j_coord_offsetH  = DIM*jnrH;
716
717             /* load j atom coordinates */
718             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
719                                                  x+j_coord_offsetC,x+j_coord_offsetD,
720                                                  x+j_coord_offsetE,x+j_coord_offsetF,
721                                                  x+j_coord_offsetG,x+j_coord_offsetH,
722                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
723
724             /* Calculate displacement vector */
725             dx00             = _mm256_sub_ps(ix0,jx0);
726             dy00             = _mm256_sub_ps(iy0,jy0);
727             dz00             = _mm256_sub_ps(iz0,jz0);
728             dx01             = _mm256_sub_ps(ix0,jx1);
729             dy01             = _mm256_sub_ps(iy0,jy1);
730             dz01             = _mm256_sub_ps(iz0,jz1);
731             dx02             = _mm256_sub_ps(ix0,jx2);
732             dy02             = _mm256_sub_ps(iy0,jy2);
733             dz02             = _mm256_sub_ps(iz0,jz2);
734             dx10             = _mm256_sub_ps(ix1,jx0);
735             dy10             = _mm256_sub_ps(iy1,jy0);
736             dz10             = _mm256_sub_ps(iz1,jz0);
737             dx11             = _mm256_sub_ps(ix1,jx1);
738             dy11             = _mm256_sub_ps(iy1,jy1);
739             dz11             = _mm256_sub_ps(iz1,jz1);
740             dx12             = _mm256_sub_ps(ix1,jx2);
741             dy12             = _mm256_sub_ps(iy1,jy2);
742             dz12             = _mm256_sub_ps(iz1,jz2);
743             dx20             = _mm256_sub_ps(ix2,jx0);
744             dy20             = _mm256_sub_ps(iy2,jy0);
745             dz20             = _mm256_sub_ps(iz2,jz0);
746             dx21             = _mm256_sub_ps(ix2,jx1);
747             dy21             = _mm256_sub_ps(iy2,jy1);
748             dz21             = _mm256_sub_ps(iz2,jz1);
749             dx22             = _mm256_sub_ps(ix2,jx2);
750             dy22             = _mm256_sub_ps(iy2,jy2);
751             dz22             = _mm256_sub_ps(iz2,jz2);
752
753             /* Calculate squared distance and things based on it */
754             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
755             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
756             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
757             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
758             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
759             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
760             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
761             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
762             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
763
764             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
765             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
766             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
767             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
768             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
769             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
770             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
771             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
772             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
773
774             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
775             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
776             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
777             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
778             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
779             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
780             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
781             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
782             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
783
784             fjx0             = _mm256_setzero_ps();
785             fjy0             = _mm256_setzero_ps();
786             fjz0             = _mm256_setzero_ps();
787             fjx1             = _mm256_setzero_ps();
788             fjy1             = _mm256_setzero_ps();
789             fjz1             = _mm256_setzero_ps();
790             fjx2             = _mm256_setzero_ps();
791             fjy2             = _mm256_setzero_ps();
792             fjz2             = _mm256_setzero_ps();
793
794             /**************************
795              * CALCULATE INTERACTIONS *
796              **************************/
797
798             if (gmx_mm256_any_lt(rsq00,rcutoff2))
799             {
800
801             /* REACTION-FIELD ELECTROSTATICS */
802             velec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
803             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
804
805             /* LENNARD-JONES DISPERSION/REPULSION */
806
807             rinvsix          = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
808             vvdw6            = _mm256_mul_ps(c6_00,rinvsix);
809             vvdw12           = _mm256_mul_ps(c12_00,_mm256_mul_ps(rinvsix,rinvsix));
810             vvdw             = _mm256_sub_ps(_mm256_mul_ps( _mm256_sub_ps(vvdw12 , _mm256_mul_ps(c12_00,_mm256_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6))), one_twelfth) ,
811                                           _mm256_mul_ps( _mm256_sub_ps(vvdw6,_mm256_mul_ps(c6_00,sh_vdw_invrcut6)),one_sixth));
812             fvdw             = _mm256_mul_ps(_mm256_sub_ps(vvdw12,vvdw6),rinvsq00);
813
814             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
815
816             /* Update potential sum for this i atom from the interaction with this j atom. */
817             velec            = _mm256_and_ps(velec,cutoff_mask);
818             velec            = _mm256_andnot_ps(dummy_mask,velec);
819             velecsum         = _mm256_add_ps(velecsum,velec);
820             vvdw             = _mm256_and_ps(vvdw,cutoff_mask);
821             vvdw             = _mm256_andnot_ps(dummy_mask,vvdw);
822             vvdwsum          = _mm256_add_ps(vvdwsum,vvdw);
823
824             fscal            = _mm256_add_ps(felec,fvdw);
825
826             fscal            = _mm256_and_ps(fscal,cutoff_mask);
827
828             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
829
830             /* Calculate temporary vectorial force */
831             tx               = _mm256_mul_ps(fscal,dx00);
832             ty               = _mm256_mul_ps(fscal,dy00);
833             tz               = _mm256_mul_ps(fscal,dz00);
834
835             /* Update vectorial force */
836             fix0             = _mm256_add_ps(fix0,tx);
837             fiy0             = _mm256_add_ps(fiy0,ty);
838             fiz0             = _mm256_add_ps(fiz0,tz);
839
840             fjx0             = _mm256_add_ps(fjx0,tx);
841             fjy0             = _mm256_add_ps(fjy0,ty);
842             fjz0             = _mm256_add_ps(fjz0,tz);
843
844             }
845
846             /**************************
847              * CALCULATE INTERACTIONS *
848              **************************/
849
850             if (gmx_mm256_any_lt(rsq01,rcutoff2))
851             {
852
853             /* REACTION-FIELD ELECTROSTATICS */
854             velec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_add_ps(rinv01,_mm256_mul_ps(krf,rsq01)),crf));
855             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
856
857             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
858
859             /* Update potential sum for this i atom from the interaction with this j atom. */
860             velec            = _mm256_and_ps(velec,cutoff_mask);
861             velec            = _mm256_andnot_ps(dummy_mask,velec);
862             velecsum         = _mm256_add_ps(velecsum,velec);
863
864             fscal            = felec;
865
866             fscal            = _mm256_and_ps(fscal,cutoff_mask);
867
868             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
869
870             /* Calculate temporary vectorial force */
871             tx               = _mm256_mul_ps(fscal,dx01);
872             ty               = _mm256_mul_ps(fscal,dy01);
873             tz               = _mm256_mul_ps(fscal,dz01);
874
875             /* Update vectorial force */
876             fix0             = _mm256_add_ps(fix0,tx);
877             fiy0             = _mm256_add_ps(fiy0,ty);
878             fiz0             = _mm256_add_ps(fiz0,tz);
879
880             fjx1             = _mm256_add_ps(fjx1,tx);
881             fjy1             = _mm256_add_ps(fjy1,ty);
882             fjz1             = _mm256_add_ps(fjz1,tz);
883
884             }
885
886             /**************************
887              * CALCULATE INTERACTIONS *
888              **************************/
889
890             if (gmx_mm256_any_lt(rsq02,rcutoff2))
891             {
892
893             /* REACTION-FIELD ELECTROSTATICS */
894             velec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_add_ps(rinv02,_mm256_mul_ps(krf,rsq02)),crf));
895             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
896
897             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
898
899             /* Update potential sum for this i atom from the interaction with this j atom. */
900             velec            = _mm256_and_ps(velec,cutoff_mask);
901             velec            = _mm256_andnot_ps(dummy_mask,velec);
902             velecsum         = _mm256_add_ps(velecsum,velec);
903
904             fscal            = felec;
905
906             fscal            = _mm256_and_ps(fscal,cutoff_mask);
907
908             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
909
910             /* Calculate temporary vectorial force */
911             tx               = _mm256_mul_ps(fscal,dx02);
912             ty               = _mm256_mul_ps(fscal,dy02);
913             tz               = _mm256_mul_ps(fscal,dz02);
914
915             /* Update vectorial force */
916             fix0             = _mm256_add_ps(fix0,tx);
917             fiy0             = _mm256_add_ps(fiy0,ty);
918             fiz0             = _mm256_add_ps(fiz0,tz);
919
920             fjx2             = _mm256_add_ps(fjx2,tx);
921             fjy2             = _mm256_add_ps(fjy2,ty);
922             fjz2             = _mm256_add_ps(fjz2,tz);
923
924             }
925
926             /**************************
927              * CALCULATE INTERACTIONS *
928              **************************/
929
930             if (gmx_mm256_any_lt(rsq10,rcutoff2))
931             {
932
933             /* REACTION-FIELD ELECTROSTATICS */
934             velec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_add_ps(rinv10,_mm256_mul_ps(krf,rsq10)),crf));
935             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
936
937             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
938
939             /* Update potential sum for this i atom from the interaction with this j atom. */
940             velec            = _mm256_and_ps(velec,cutoff_mask);
941             velec            = _mm256_andnot_ps(dummy_mask,velec);
942             velecsum         = _mm256_add_ps(velecsum,velec);
943
944             fscal            = felec;
945
946             fscal            = _mm256_and_ps(fscal,cutoff_mask);
947
948             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
949
950             /* Calculate temporary vectorial force */
951             tx               = _mm256_mul_ps(fscal,dx10);
952             ty               = _mm256_mul_ps(fscal,dy10);
953             tz               = _mm256_mul_ps(fscal,dz10);
954
955             /* Update vectorial force */
956             fix1             = _mm256_add_ps(fix1,tx);
957             fiy1             = _mm256_add_ps(fiy1,ty);
958             fiz1             = _mm256_add_ps(fiz1,tz);
959
960             fjx0             = _mm256_add_ps(fjx0,tx);
961             fjy0             = _mm256_add_ps(fjy0,ty);
962             fjz0             = _mm256_add_ps(fjz0,tz);
963
964             }
965
966             /**************************
967              * CALCULATE INTERACTIONS *
968              **************************/
969
970             if (gmx_mm256_any_lt(rsq11,rcutoff2))
971             {
972
973             /* REACTION-FIELD ELECTROSTATICS */
974             velec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_add_ps(rinv11,_mm256_mul_ps(krf,rsq11)),crf));
975             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
976
977             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
978
979             /* Update potential sum for this i atom from the interaction with this j atom. */
980             velec            = _mm256_and_ps(velec,cutoff_mask);
981             velec            = _mm256_andnot_ps(dummy_mask,velec);
982             velecsum         = _mm256_add_ps(velecsum,velec);
983
984             fscal            = felec;
985
986             fscal            = _mm256_and_ps(fscal,cutoff_mask);
987
988             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
989
990             /* Calculate temporary vectorial force */
991             tx               = _mm256_mul_ps(fscal,dx11);
992             ty               = _mm256_mul_ps(fscal,dy11);
993             tz               = _mm256_mul_ps(fscal,dz11);
994
995             /* Update vectorial force */
996             fix1             = _mm256_add_ps(fix1,tx);
997             fiy1             = _mm256_add_ps(fiy1,ty);
998             fiz1             = _mm256_add_ps(fiz1,tz);
999
1000             fjx1             = _mm256_add_ps(fjx1,tx);
1001             fjy1             = _mm256_add_ps(fjy1,ty);
1002             fjz1             = _mm256_add_ps(fjz1,tz);
1003
1004             }
1005
1006             /**************************
1007              * CALCULATE INTERACTIONS *
1008              **************************/
1009
1010             if (gmx_mm256_any_lt(rsq12,rcutoff2))
1011             {
1012
1013             /* REACTION-FIELD ELECTROSTATICS */
1014             velec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_add_ps(rinv12,_mm256_mul_ps(krf,rsq12)),crf));
1015             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1016
1017             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1018
1019             /* Update potential sum for this i atom from the interaction with this j atom. */
1020             velec            = _mm256_and_ps(velec,cutoff_mask);
1021             velec            = _mm256_andnot_ps(dummy_mask,velec);
1022             velecsum         = _mm256_add_ps(velecsum,velec);
1023
1024             fscal            = felec;
1025
1026             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1027
1028             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1029
1030             /* Calculate temporary vectorial force */
1031             tx               = _mm256_mul_ps(fscal,dx12);
1032             ty               = _mm256_mul_ps(fscal,dy12);
1033             tz               = _mm256_mul_ps(fscal,dz12);
1034
1035             /* Update vectorial force */
1036             fix1             = _mm256_add_ps(fix1,tx);
1037             fiy1             = _mm256_add_ps(fiy1,ty);
1038             fiz1             = _mm256_add_ps(fiz1,tz);
1039
1040             fjx2             = _mm256_add_ps(fjx2,tx);
1041             fjy2             = _mm256_add_ps(fjy2,ty);
1042             fjz2             = _mm256_add_ps(fjz2,tz);
1043
1044             }
1045
1046             /**************************
1047              * CALCULATE INTERACTIONS *
1048              **************************/
1049
1050             if (gmx_mm256_any_lt(rsq20,rcutoff2))
1051             {
1052
1053             /* REACTION-FIELD ELECTROSTATICS */
1054             velec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_add_ps(rinv20,_mm256_mul_ps(krf,rsq20)),crf));
1055             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1056
1057             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1058
1059             /* Update potential sum for this i atom from the interaction with this j atom. */
1060             velec            = _mm256_and_ps(velec,cutoff_mask);
1061             velec            = _mm256_andnot_ps(dummy_mask,velec);
1062             velecsum         = _mm256_add_ps(velecsum,velec);
1063
1064             fscal            = felec;
1065
1066             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1067
1068             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1069
1070             /* Calculate temporary vectorial force */
1071             tx               = _mm256_mul_ps(fscal,dx20);
1072             ty               = _mm256_mul_ps(fscal,dy20);
1073             tz               = _mm256_mul_ps(fscal,dz20);
1074
1075             /* Update vectorial force */
1076             fix2             = _mm256_add_ps(fix2,tx);
1077             fiy2             = _mm256_add_ps(fiy2,ty);
1078             fiz2             = _mm256_add_ps(fiz2,tz);
1079
1080             fjx0             = _mm256_add_ps(fjx0,tx);
1081             fjy0             = _mm256_add_ps(fjy0,ty);
1082             fjz0             = _mm256_add_ps(fjz0,tz);
1083
1084             }
1085
1086             /**************************
1087              * CALCULATE INTERACTIONS *
1088              **************************/
1089
1090             if (gmx_mm256_any_lt(rsq21,rcutoff2))
1091             {
1092
1093             /* REACTION-FIELD ELECTROSTATICS */
1094             velec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_add_ps(rinv21,_mm256_mul_ps(krf,rsq21)),crf));
1095             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1096
1097             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1098
1099             /* Update potential sum for this i atom from the interaction with this j atom. */
1100             velec            = _mm256_and_ps(velec,cutoff_mask);
1101             velec            = _mm256_andnot_ps(dummy_mask,velec);
1102             velecsum         = _mm256_add_ps(velecsum,velec);
1103
1104             fscal            = felec;
1105
1106             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1107
1108             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1109
1110             /* Calculate temporary vectorial force */
1111             tx               = _mm256_mul_ps(fscal,dx21);
1112             ty               = _mm256_mul_ps(fscal,dy21);
1113             tz               = _mm256_mul_ps(fscal,dz21);
1114
1115             /* Update vectorial force */
1116             fix2             = _mm256_add_ps(fix2,tx);
1117             fiy2             = _mm256_add_ps(fiy2,ty);
1118             fiz2             = _mm256_add_ps(fiz2,tz);
1119
1120             fjx1             = _mm256_add_ps(fjx1,tx);
1121             fjy1             = _mm256_add_ps(fjy1,ty);
1122             fjz1             = _mm256_add_ps(fjz1,tz);
1123
1124             }
1125
1126             /**************************
1127              * CALCULATE INTERACTIONS *
1128              **************************/
1129
1130             if (gmx_mm256_any_lt(rsq22,rcutoff2))
1131             {
1132
1133             /* REACTION-FIELD ELECTROSTATICS */
1134             velec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_add_ps(rinv22,_mm256_mul_ps(krf,rsq22)),crf));
1135             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1136
1137             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1138
1139             /* Update potential sum for this i atom from the interaction with this j atom. */
1140             velec            = _mm256_and_ps(velec,cutoff_mask);
1141             velec            = _mm256_andnot_ps(dummy_mask,velec);
1142             velecsum         = _mm256_add_ps(velecsum,velec);
1143
1144             fscal            = felec;
1145
1146             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1147
1148             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1149
1150             /* Calculate temporary vectorial force */
1151             tx               = _mm256_mul_ps(fscal,dx22);
1152             ty               = _mm256_mul_ps(fscal,dy22);
1153             tz               = _mm256_mul_ps(fscal,dz22);
1154
1155             /* Update vectorial force */
1156             fix2             = _mm256_add_ps(fix2,tx);
1157             fiy2             = _mm256_add_ps(fiy2,ty);
1158             fiz2             = _mm256_add_ps(fiz2,tz);
1159
1160             fjx2             = _mm256_add_ps(fjx2,tx);
1161             fjy2             = _mm256_add_ps(fjy2,ty);
1162             fjz2             = _mm256_add_ps(fjz2,tz);
1163
1164             }
1165
1166             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1167             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1168             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1169             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1170             fjptrE             = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
1171             fjptrF             = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
1172             fjptrG             = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
1173             fjptrH             = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
1174
1175             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1176                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1177
1178             /* Inner loop uses 342 flops */
1179         }
1180
1181         /* End of innermost loop */
1182
1183         gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1184                                                  f+i_coord_offset,fshift+i_shift_offset);
1185
1186         ggid                        = gid[iidx];
1187         /* Update potential energies */
1188         gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1189         gmx_mm256_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
1190
1191         /* Increment number of inner iterations */
1192         inneriter                  += j_index_end - j_index_start;
1193
1194         /* Outer loop uses 20 flops */
1195     }
1196
1197     /* Increment number of outer iterations */
1198     outeriter        += nri;
1199
1200     /* Update outer/inner flops */
1201
1202     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_VF,outeriter*20 + inneriter*342);
1203 }
1204 /*
1205  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_256_single
1206  * Electrostatics interaction: ReactionField
1207  * VdW interaction:            LennardJones
1208  * Geometry:                   Water3-Water3
1209  * Calculate force/pot:        Force
1210  */
1211 void
1212 nb_kernel_ElecRFCut_VdwLJSh_GeomW3W3_F_avx_256_single
1213                     (t_nblist                    * gmx_restrict       nlist,
1214                      rvec                        * gmx_restrict          xx,
1215                      rvec                        * gmx_restrict          ff,
1216                      t_forcerec                  * gmx_restrict          fr,
1217                      t_mdatoms                   * gmx_restrict     mdatoms,
1218                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1219                      t_nrnb                      * gmx_restrict        nrnb)
1220 {
1221     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
1222      * just 0 for non-waters.
1223      * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
1224      * jnr indices corresponding to data put in the four positions in the SIMD register.
1225      */
1226     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
1227     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1228     int              jnrA,jnrB,jnrC,jnrD;
1229     int              jnrE,jnrF,jnrG,jnrH;
1230     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1231     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
1232     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1233     int              j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
1234     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
1235     real             rcutoff_scalar;
1236     real             *shiftvec,*fshift,*x,*f;
1237     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
1238     real             scratch[4*DIM];
1239     __m256           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1240     real *           vdwioffsetptr0;
1241     __m256           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1242     real *           vdwioffsetptr1;
1243     __m256           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1244     real *           vdwioffsetptr2;
1245     __m256           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1246     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
1247     __m256           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1248     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D,vdwjidx1E,vdwjidx1F,vdwjidx1G,vdwjidx1H;
1249     __m256           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1250     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D,vdwjidx2E,vdwjidx2F,vdwjidx2G,vdwjidx2H;
1251     __m256           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1252     __m256           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1253     __m256           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1254     __m256           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1255     __m256           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1256     __m256           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1257     __m256           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1258     __m256           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1259     __m256           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1260     __m256           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1261     __m256           velec,felec,velecsum,facel,crf,krf,krf2;
1262     real             *charge;
1263     int              nvdwtype;
1264     __m256           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
1265     int              *vdwtype;
1266     real             *vdwparam;
1267     __m256           one_sixth   = _mm256_set1_ps(1.0/6.0);
1268     __m256           one_twelfth = _mm256_set1_ps(1.0/12.0);
1269     __m256           dummy_mask,cutoff_mask;
1270     __m256           signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
1271     __m256           one     = _mm256_set1_ps(1.0);
1272     __m256           two     = _mm256_set1_ps(2.0);
1273     x                = xx[0];
1274     f                = ff[0];
1275
1276     nri              = nlist->nri;
1277     iinr             = nlist->iinr;
1278     jindex           = nlist->jindex;
1279     jjnr             = nlist->jjnr;
1280     shiftidx         = nlist->shift;
1281     gid              = nlist->gid;
1282     shiftvec         = fr->shift_vec[0];
1283     fshift           = fr->fshift[0];
1284     facel            = _mm256_set1_ps(fr->epsfac);
1285     charge           = mdatoms->chargeA;
1286     krf              = _mm256_set1_ps(fr->ic->k_rf);
1287     krf2             = _mm256_set1_ps(fr->ic->k_rf*2.0);
1288     crf              = _mm256_set1_ps(fr->ic->c_rf);
1289     nvdwtype         = fr->ntype;
1290     vdwparam         = fr->nbfp;
1291     vdwtype          = mdatoms->typeA;
1292
1293     /* Setup water-specific parameters */
1294     inr              = nlist->iinr[0];
1295     iq0              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
1296     iq1              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+1]));
1297     iq2              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+2]));
1298     vdwioffsetptr0   = vdwparam+2*nvdwtype*vdwtype[inr+0];
1299
1300     jq0              = _mm256_set1_ps(charge[inr+0]);
1301     jq1              = _mm256_set1_ps(charge[inr+1]);
1302     jq2              = _mm256_set1_ps(charge[inr+2]);
1303     vdwjidx0A        = 2*vdwtype[inr+0];
1304     qq00             = _mm256_mul_ps(iq0,jq0);
1305     c6_00            = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A]);
1306     c12_00           = _mm256_set1_ps(vdwioffsetptr0[vdwjidx0A+1]);
1307     qq01             = _mm256_mul_ps(iq0,jq1);
1308     qq02             = _mm256_mul_ps(iq0,jq2);
1309     qq10             = _mm256_mul_ps(iq1,jq0);
1310     qq11             = _mm256_mul_ps(iq1,jq1);
1311     qq12             = _mm256_mul_ps(iq1,jq2);
1312     qq20             = _mm256_mul_ps(iq2,jq0);
1313     qq21             = _mm256_mul_ps(iq2,jq1);
1314     qq22             = _mm256_mul_ps(iq2,jq2);
1315
1316     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1317     rcutoff_scalar   = fr->rcoulomb;
1318     rcutoff          = _mm256_set1_ps(rcutoff_scalar);
1319     rcutoff2         = _mm256_mul_ps(rcutoff,rcutoff);
1320
1321     sh_vdw_invrcut6  = _mm256_set1_ps(fr->ic->sh_invrc6);
1322     rvdw             = _mm256_set1_ps(fr->rvdw);
1323
1324     /* Avoid stupid compiler warnings */
1325     jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
1326     j_coord_offsetA = 0;
1327     j_coord_offsetB = 0;
1328     j_coord_offsetC = 0;
1329     j_coord_offsetD = 0;
1330     j_coord_offsetE = 0;
1331     j_coord_offsetF = 0;
1332     j_coord_offsetG = 0;
1333     j_coord_offsetH = 0;
1334
1335     outeriter        = 0;
1336     inneriter        = 0;
1337
1338     for(iidx=0;iidx<4*DIM;iidx++)
1339     {
1340         scratch[iidx] = 0.0;
1341     }
1342
1343     /* Start outer loop over neighborlists */
1344     for(iidx=0; iidx<nri; iidx++)
1345     {
1346         /* Load shift vector for this list */
1347         i_shift_offset   = DIM*shiftidx[iidx];
1348
1349         /* Load limits for loop over neighbors */
1350         j_index_start    = jindex[iidx];
1351         j_index_end      = jindex[iidx+1];
1352
1353         /* Get outer coordinate index */
1354         inr              = iinr[iidx];
1355         i_coord_offset   = DIM*inr;
1356
1357         /* Load i particle coords and add shift vector */
1358         gmx_mm256_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1359                                                     &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1360
1361         fix0             = _mm256_setzero_ps();
1362         fiy0             = _mm256_setzero_ps();
1363         fiz0             = _mm256_setzero_ps();
1364         fix1             = _mm256_setzero_ps();
1365         fiy1             = _mm256_setzero_ps();
1366         fiz1             = _mm256_setzero_ps();
1367         fix2             = _mm256_setzero_ps();
1368         fiy2             = _mm256_setzero_ps();
1369         fiz2             = _mm256_setzero_ps();
1370
1371         /* Start inner kernel loop */
1372         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
1373         {
1374
1375             /* Get j neighbor index, and coordinate index */
1376             jnrA             = jjnr[jidx];
1377             jnrB             = jjnr[jidx+1];
1378             jnrC             = jjnr[jidx+2];
1379             jnrD             = jjnr[jidx+3];
1380             jnrE             = jjnr[jidx+4];
1381             jnrF             = jjnr[jidx+5];
1382             jnrG             = jjnr[jidx+6];
1383             jnrH             = jjnr[jidx+7];
1384             j_coord_offsetA  = DIM*jnrA;
1385             j_coord_offsetB  = DIM*jnrB;
1386             j_coord_offsetC  = DIM*jnrC;
1387             j_coord_offsetD  = DIM*jnrD;
1388             j_coord_offsetE  = DIM*jnrE;
1389             j_coord_offsetF  = DIM*jnrF;
1390             j_coord_offsetG  = DIM*jnrG;
1391             j_coord_offsetH  = DIM*jnrH;
1392
1393             /* load j atom coordinates */
1394             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1395                                                  x+j_coord_offsetC,x+j_coord_offsetD,
1396                                                  x+j_coord_offsetE,x+j_coord_offsetF,
1397                                                  x+j_coord_offsetG,x+j_coord_offsetH,
1398                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1399
1400             /* Calculate displacement vector */
1401             dx00             = _mm256_sub_ps(ix0,jx0);
1402             dy00             = _mm256_sub_ps(iy0,jy0);
1403             dz00             = _mm256_sub_ps(iz0,jz0);
1404             dx01             = _mm256_sub_ps(ix0,jx1);
1405             dy01             = _mm256_sub_ps(iy0,jy1);
1406             dz01             = _mm256_sub_ps(iz0,jz1);
1407             dx02             = _mm256_sub_ps(ix0,jx2);
1408             dy02             = _mm256_sub_ps(iy0,jy2);
1409             dz02             = _mm256_sub_ps(iz0,jz2);
1410             dx10             = _mm256_sub_ps(ix1,jx0);
1411             dy10             = _mm256_sub_ps(iy1,jy0);
1412             dz10             = _mm256_sub_ps(iz1,jz0);
1413             dx11             = _mm256_sub_ps(ix1,jx1);
1414             dy11             = _mm256_sub_ps(iy1,jy1);
1415             dz11             = _mm256_sub_ps(iz1,jz1);
1416             dx12             = _mm256_sub_ps(ix1,jx2);
1417             dy12             = _mm256_sub_ps(iy1,jy2);
1418             dz12             = _mm256_sub_ps(iz1,jz2);
1419             dx20             = _mm256_sub_ps(ix2,jx0);
1420             dy20             = _mm256_sub_ps(iy2,jy0);
1421             dz20             = _mm256_sub_ps(iz2,jz0);
1422             dx21             = _mm256_sub_ps(ix2,jx1);
1423             dy21             = _mm256_sub_ps(iy2,jy1);
1424             dz21             = _mm256_sub_ps(iz2,jz1);
1425             dx22             = _mm256_sub_ps(ix2,jx2);
1426             dy22             = _mm256_sub_ps(iy2,jy2);
1427             dz22             = _mm256_sub_ps(iz2,jz2);
1428
1429             /* Calculate squared distance and things based on it */
1430             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1431             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1432             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1433             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1434             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1435             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1436             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1437             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1438             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1439
1440             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
1441             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
1442             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
1443             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
1444             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
1445             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
1446             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
1447             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
1448             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
1449
1450             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
1451             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
1452             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
1453             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
1454             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
1455             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
1456             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
1457             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
1458             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
1459
1460             fjx0             = _mm256_setzero_ps();
1461             fjy0             = _mm256_setzero_ps();
1462             fjz0             = _mm256_setzero_ps();
1463             fjx1             = _mm256_setzero_ps();
1464             fjy1             = _mm256_setzero_ps();
1465             fjz1             = _mm256_setzero_ps();
1466             fjx2             = _mm256_setzero_ps();
1467             fjy2             = _mm256_setzero_ps();
1468             fjz2             = _mm256_setzero_ps();
1469
1470             /**************************
1471              * CALCULATE INTERACTIONS *
1472              **************************/
1473
1474             if (gmx_mm256_any_lt(rsq00,rcutoff2))
1475             {
1476
1477             /* REACTION-FIELD ELECTROSTATICS */
1478             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
1479
1480             /* LENNARD-JONES DISPERSION/REPULSION */
1481
1482             rinvsix          = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1483             fvdw             = _mm256_mul_ps(_mm256_sub_ps(_mm256_mul_ps(c12_00,rinvsix),c6_00),_mm256_mul_ps(rinvsix,rinvsq00));
1484
1485             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1486
1487             fscal            = _mm256_add_ps(felec,fvdw);
1488
1489             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1490
1491             /* Calculate temporary vectorial force */
1492             tx               = _mm256_mul_ps(fscal,dx00);
1493             ty               = _mm256_mul_ps(fscal,dy00);
1494             tz               = _mm256_mul_ps(fscal,dz00);
1495
1496             /* Update vectorial force */
1497             fix0             = _mm256_add_ps(fix0,tx);
1498             fiy0             = _mm256_add_ps(fiy0,ty);
1499             fiz0             = _mm256_add_ps(fiz0,tz);
1500
1501             fjx0             = _mm256_add_ps(fjx0,tx);
1502             fjy0             = _mm256_add_ps(fjy0,ty);
1503             fjz0             = _mm256_add_ps(fjz0,tz);
1504
1505             }
1506
1507             /**************************
1508              * CALCULATE INTERACTIONS *
1509              **************************/
1510
1511             if (gmx_mm256_any_lt(rsq01,rcutoff2))
1512             {
1513
1514             /* REACTION-FIELD ELECTROSTATICS */
1515             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
1516
1517             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
1518
1519             fscal            = felec;
1520
1521             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1522
1523             /* Calculate temporary vectorial force */
1524             tx               = _mm256_mul_ps(fscal,dx01);
1525             ty               = _mm256_mul_ps(fscal,dy01);
1526             tz               = _mm256_mul_ps(fscal,dz01);
1527
1528             /* Update vectorial force */
1529             fix0             = _mm256_add_ps(fix0,tx);
1530             fiy0             = _mm256_add_ps(fiy0,ty);
1531             fiz0             = _mm256_add_ps(fiz0,tz);
1532
1533             fjx1             = _mm256_add_ps(fjx1,tx);
1534             fjy1             = _mm256_add_ps(fjy1,ty);
1535             fjz1             = _mm256_add_ps(fjz1,tz);
1536
1537             }
1538
1539             /**************************
1540              * CALCULATE INTERACTIONS *
1541              **************************/
1542
1543             if (gmx_mm256_any_lt(rsq02,rcutoff2))
1544             {
1545
1546             /* REACTION-FIELD ELECTROSTATICS */
1547             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
1548
1549             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
1550
1551             fscal            = felec;
1552
1553             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1554
1555             /* Calculate temporary vectorial force */
1556             tx               = _mm256_mul_ps(fscal,dx02);
1557             ty               = _mm256_mul_ps(fscal,dy02);
1558             tz               = _mm256_mul_ps(fscal,dz02);
1559
1560             /* Update vectorial force */
1561             fix0             = _mm256_add_ps(fix0,tx);
1562             fiy0             = _mm256_add_ps(fiy0,ty);
1563             fiz0             = _mm256_add_ps(fiz0,tz);
1564
1565             fjx2             = _mm256_add_ps(fjx2,tx);
1566             fjy2             = _mm256_add_ps(fjy2,ty);
1567             fjz2             = _mm256_add_ps(fjz2,tz);
1568
1569             }
1570
1571             /**************************
1572              * CALCULATE INTERACTIONS *
1573              **************************/
1574
1575             if (gmx_mm256_any_lt(rsq10,rcutoff2))
1576             {
1577
1578             /* REACTION-FIELD ELECTROSTATICS */
1579             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
1580
1581             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
1582
1583             fscal            = felec;
1584
1585             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1586
1587             /* Calculate temporary vectorial force */
1588             tx               = _mm256_mul_ps(fscal,dx10);
1589             ty               = _mm256_mul_ps(fscal,dy10);
1590             tz               = _mm256_mul_ps(fscal,dz10);
1591
1592             /* Update vectorial force */
1593             fix1             = _mm256_add_ps(fix1,tx);
1594             fiy1             = _mm256_add_ps(fiy1,ty);
1595             fiz1             = _mm256_add_ps(fiz1,tz);
1596
1597             fjx0             = _mm256_add_ps(fjx0,tx);
1598             fjy0             = _mm256_add_ps(fjy0,ty);
1599             fjz0             = _mm256_add_ps(fjz0,tz);
1600
1601             }
1602
1603             /**************************
1604              * CALCULATE INTERACTIONS *
1605              **************************/
1606
1607             if (gmx_mm256_any_lt(rsq11,rcutoff2))
1608             {
1609
1610             /* REACTION-FIELD ELECTROSTATICS */
1611             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
1612
1613             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
1614
1615             fscal            = felec;
1616
1617             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1618
1619             /* Calculate temporary vectorial force */
1620             tx               = _mm256_mul_ps(fscal,dx11);
1621             ty               = _mm256_mul_ps(fscal,dy11);
1622             tz               = _mm256_mul_ps(fscal,dz11);
1623
1624             /* Update vectorial force */
1625             fix1             = _mm256_add_ps(fix1,tx);
1626             fiy1             = _mm256_add_ps(fiy1,ty);
1627             fiz1             = _mm256_add_ps(fiz1,tz);
1628
1629             fjx1             = _mm256_add_ps(fjx1,tx);
1630             fjy1             = _mm256_add_ps(fjy1,ty);
1631             fjz1             = _mm256_add_ps(fjz1,tz);
1632
1633             }
1634
1635             /**************************
1636              * CALCULATE INTERACTIONS *
1637              **************************/
1638
1639             if (gmx_mm256_any_lt(rsq12,rcutoff2))
1640             {
1641
1642             /* REACTION-FIELD ELECTROSTATICS */
1643             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
1644
1645             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
1646
1647             fscal            = felec;
1648
1649             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1650
1651             /* Calculate temporary vectorial force */
1652             tx               = _mm256_mul_ps(fscal,dx12);
1653             ty               = _mm256_mul_ps(fscal,dy12);
1654             tz               = _mm256_mul_ps(fscal,dz12);
1655
1656             /* Update vectorial force */
1657             fix1             = _mm256_add_ps(fix1,tx);
1658             fiy1             = _mm256_add_ps(fiy1,ty);
1659             fiz1             = _mm256_add_ps(fiz1,tz);
1660
1661             fjx2             = _mm256_add_ps(fjx2,tx);
1662             fjy2             = _mm256_add_ps(fjy2,ty);
1663             fjz2             = _mm256_add_ps(fjz2,tz);
1664
1665             }
1666
1667             /**************************
1668              * CALCULATE INTERACTIONS *
1669              **************************/
1670
1671             if (gmx_mm256_any_lt(rsq20,rcutoff2))
1672             {
1673
1674             /* REACTION-FIELD ELECTROSTATICS */
1675             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
1676
1677             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
1678
1679             fscal            = felec;
1680
1681             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1682
1683             /* Calculate temporary vectorial force */
1684             tx               = _mm256_mul_ps(fscal,dx20);
1685             ty               = _mm256_mul_ps(fscal,dy20);
1686             tz               = _mm256_mul_ps(fscal,dz20);
1687
1688             /* Update vectorial force */
1689             fix2             = _mm256_add_ps(fix2,tx);
1690             fiy2             = _mm256_add_ps(fiy2,ty);
1691             fiz2             = _mm256_add_ps(fiz2,tz);
1692
1693             fjx0             = _mm256_add_ps(fjx0,tx);
1694             fjy0             = _mm256_add_ps(fjy0,ty);
1695             fjz0             = _mm256_add_ps(fjz0,tz);
1696
1697             }
1698
1699             /**************************
1700              * CALCULATE INTERACTIONS *
1701              **************************/
1702
1703             if (gmx_mm256_any_lt(rsq21,rcutoff2))
1704             {
1705
1706             /* REACTION-FIELD ELECTROSTATICS */
1707             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
1708
1709             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
1710
1711             fscal            = felec;
1712
1713             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1714
1715             /* Calculate temporary vectorial force */
1716             tx               = _mm256_mul_ps(fscal,dx21);
1717             ty               = _mm256_mul_ps(fscal,dy21);
1718             tz               = _mm256_mul_ps(fscal,dz21);
1719
1720             /* Update vectorial force */
1721             fix2             = _mm256_add_ps(fix2,tx);
1722             fiy2             = _mm256_add_ps(fiy2,ty);
1723             fiz2             = _mm256_add_ps(fiz2,tz);
1724
1725             fjx1             = _mm256_add_ps(fjx1,tx);
1726             fjy1             = _mm256_add_ps(fjy1,ty);
1727             fjz1             = _mm256_add_ps(fjz1,tz);
1728
1729             }
1730
1731             /**************************
1732              * CALCULATE INTERACTIONS *
1733              **************************/
1734
1735             if (gmx_mm256_any_lt(rsq22,rcutoff2))
1736             {
1737
1738             /* REACTION-FIELD ELECTROSTATICS */
1739             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
1740
1741             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
1742
1743             fscal            = felec;
1744
1745             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1746
1747             /* Calculate temporary vectorial force */
1748             tx               = _mm256_mul_ps(fscal,dx22);
1749             ty               = _mm256_mul_ps(fscal,dy22);
1750             tz               = _mm256_mul_ps(fscal,dz22);
1751
1752             /* Update vectorial force */
1753             fix2             = _mm256_add_ps(fix2,tx);
1754             fiy2             = _mm256_add_ps(fiy2,ty);
1755             fiz2             = _mm256_add_ps(fiz2,tz);
1756
1757             fjx2             = _mm256_add_ps(fjx2,tx);
1758             fjy2             = _mm256_add_ps(fjy2,ty);
1759             fjz2             = _mm256_add_ps(fjz2,tz);
1760
1761             }
1762
1763             fjptrA             = f+j_coord_offsetA;
1764             fjptrB             = f+j_coord_offsetB;
1765             fjptrC             = f+j_coord_offsetC;
1766             fjptrD             = f+j_coord_offsetD;
1767             fjptrE             = f+j_coord_offsetE;
1768             fjptrF             = f+j_coord_offsetF;
1769             fjptrG             = f+j_coord_offsetG;
1770             fjptrH             = f+j_coord_offsetH;
1771
1772             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
1773                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1774
1775             /* Inner loop uses 277 flops */
1776         }
1777
1778         if(jidx<j_index_end)
1779         {
1780
1781             /* Get j neighbor index, and coordinate index */
1782             jnrlistA         = jjnr[jidx];
1783             jnrlistB         = jjnr[jidx+1];
1784             jnrlistC         = jjnr[jidx+2];
1785             jnrlistD         = jjnr[jidx+3];
1786             jnrlistE         = jjnr[jidx+4];
1787             jnrlistF         = jjnr[jidx+5];
1788             jnrlistG         = jjnr[jidx+6];
1789             jnrlistH         = jjnr[jidx+7];
1790             /* Sign of each element will be negative for non-real atoms.
1791              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1792              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1793              */
1794             dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
1795                                             gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
1796                                             
1797             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1798             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1799             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1800             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1801             jnrE       = (jnrlistE>=0) ? jnrlistE : 0;
1802             jnrF       = (jnrlistF>=0) ? jnrlistF : 0;
1803             jnrG       = (jnrlistG>=0) ? jnrlistG : 0;
1804             jnrH       = (jnrlistH>=0) ? jnrlistH : 0;
1805             j_coord_offsetA  = DIM*jnrA;
1806             j_coord_offsetB  = DIM*jnrB;
1807             j_coord_offsetC  = DIM*jnrC;
1808             j_coord_offsetD  = DIM*jnrD;
1809             j_coord_offsetE  = DIM*jnrE;
1810             j_coord_offsetF  = DIM*jnrF;
1811             j_coord_offsetG  = DIM*jnrG;
1812             j_coord_offsetH  = DIM*jnrH;
1813
1814             /* load j atom coordinates */
1815             gmx_mm256_load_3rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1816                                                  x+j_coord_offsetC,x+j_coord_offsetD,
1817                                                  x+j_coord_offsetE,x+j_coord_offsetF,
1818                                                  x+j_coord_offsetG,x+j_coord_offsetH,
1819                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1820
1821             /* Calculate displacement vector */
1822             dx00             = _mm256_sub_ps(ix0,jx0);
1823             dy00             = _mm256_sub_ps(iy0,jy0);
1824             dz00             = _mm256_sub_ps(iz0,jz0);
1825             dx01             = _mm256_sub_ps(ix0,jx1);
1826             dy01             = _mm256_sub_ps(iy0,jy1);
1827             dz01             = _mm256_sub_ps(iz0,jz1);
1828             dx02             = _mm256_sub_ps(ix0,jx2);
1829             dy02             = _mm256_sub_ps(iy0,jy2);
1830             dz02             = _mm256_sub_ps(iz0,jz2);
1831             dx10             = _mm256_sub_ps(ix1,jx0);
1832             dy10             = _mm256_sub_ps(iy1,jy0);
1833             dz10             = _mm256_sub_ps(iz1,jz0);
1834             dx11             = _mm256_sub_ps(ix1,jx1);
1835             dy11             = _mm256_sub_ps(iy1,jy1);
1836             dz11             = _mm256_sub_ps(iz1,jz1);
1837             dx12             = _mm256_sub_ps(ix1,jx2);
1838             dy12             = _mm256_sub_ps(iy1,jy2);
1839             dz12             = _mm256_sub_ps(iz1,jz2);
1840             dx20             = _mm256_sub_ps(ix2,jx0);
1841             dy20             = _mm256_sub_ps(iy2,jy0);
1842             dz20             = _mm256_sub_ps(iz2,jz0);
1843             dx21             = _mm256_sub_ps(ix2,jx1);
1844             dy21             = _mm256_sub_ps(iy2,jy1);
1845             dz21             = _mm256_sub_ps(iz2,jz1);
1846             dx22             = _mm256_sub_ps(ix2,jx2);
1847             dy22             = _mm256_sub_ps(iy2,jy2);
1848             dz22             = _mm256_sub_ps(iz2,jz2);
1849
1850             /* Calculate squared distance and things based on it */
1851             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
1852             rsq01            = gmx_mm256_calc_rsq_ps(dx01,dy01,dz01);
1853             rsq02            = gmx_mm256_calc_rsq_ps(dx02,dy02,dz02);
1854             rsq10            = gmx_mm256_calc_rsq_ps(dx10,dy10,dz10);
1855             rsq11            = gmx_mm256_calc_rsq_ps(dx11,dy11,dz11);
1856             rsq12            = gmx_mm256_calc_rsq_ps(dx12,dy12,dz12);
1857             rsq20            = gmx_mm256_calc_rsq_ps(dx20,dy20,dz20);
1858             rsq21            = gmx_mm256_calc_rsq_ps(dx21,dy21,dz21);
1859             rsq22            = gmx_mm256_calc_rsq_ps(dx22,dy22,dz22);
1860
1861             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
1862             rinv01           = gmx_mm256_invsqrt_ps(rsq01);
1863             rinv02           = gmx_mm256_invsqrt_ps(rsq02);
1864             rinv10           = gmx_mm256_invsqrt_ps(rsq10);
1865             rinv11           = gmx_mm256_invsqrt_ps(rsq11);
1866             rinv12           = gmx_mm256_invsqrt_ps(rsq12);
1867             rinv20           = gmx_mm256_invsqrt_ps(rsq20);
1868             rinv21           = gmx_mm256_invsqrt_ps(rsq21);
1869             rinv22           = gmx_mm256_invsqrt_ps(rsq22);
1870
1871             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
1872             rinvsq01         = _mm256_mul_ps(rinv01,rinv01);
1873             rinvsq02         = _mm256_mul_ps(rinv02,rinv02);
1874             rinvsq10         = _mm256_mul_ps(rinv10,rinv10);
1875             rinvsq11         = _mm256_mul_ps(rinv11,rinv11);
1876             rinvsq12         = _mm256_mul_ps(rinv12,rinv12);
1877             rinvsq20         = _mm256_mul_ps(rinv20,rinv20);
1878             rinvsq21         = _mm256_mul_ps(rinv21,rinv21);
1879             rinvsq22         = _mm256_mul_ps(rinv22,rinv22);
1880
1881             fjx0             = _mm256_setzero_ps();
1882             fjy0             = _mm256_setzero_ps();
1883             fjz0             = _mm256_setzero_ps();
1884             fjx1             = _mm256_setzero_ps();
1885             fjy1             = _mm256_setzero_ps();
1886             fjz1             = _mm256_setzero_ps();
1887             fjx2             = _mm256_setzero_ps();
1888             fjy2             = _mm256_setzero_ps();
1889             fjz2             = _mm256_setzero_ps();
1890
1891             /**************************
1892              * CALCULATE INTERACTIONS *
1893              **************************/
1894
1895             if (gmx_mm256_any_lt(rsq00,rcutoff2))
1896             {
1897
1898             /* REACTION-FIELD ELECTROSTATICS */
1899             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
1900
1901             /* LENNARD-JONES DISPERSION/REPULSION */
1902
1903             rinvsix          = _mm256_mul_ps(_mm256_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1904             fvdw             = _mm256_mul_ps(_mm256_sub_ps(_mm256_mul_ps(c12_00,rinvsix),c6_00),_mm256_mul_ps(rinvsix,rinvsq00));
1905
1906             cutoff_mask      = _mm256_cmp_ps(rsq00,rcutoff2,_CMP_LT_OQ);
1907
1908             fscal            = _mm256_add_ps(felec,fvdw);
1909
1910             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1911
1912             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1913
1914             /* Calculate temporary vectorial force */
1915             tx               = _mm256_mul_ps(fscal,dx00);
1916             ty               = _mm256_mul_ps(fscal,dy00);
1917             tz               = _mm256_mul_ps(fscal,dz00);
1918
1919             /* Update vectorial force */
1920             fix0             = _mm256_add_ps(fix0,tx);
1921             fiy0             = _mm256_add_ps(fiy0,ty);
1922             fiz0             = _mm256_add_ps(fiz0,tz);
1923
1924             fjx0             = _mm256_add_ps(fjx0,tx);
1925             fjy0             = _mm256_add_ps(fjy0,ty);
1926             fjz0             = _mm256_add_ps(fjz0,tz);
1927
1928             }
1929
1930             /**************************
1931              * CALCULATE INTERACTIONS *
1932              **************************/
1933
1934             if (gmx_mm256_any_lt(rsq01,rcutoff2))
1935             {
1936
1937             /* REACTION-FIELD ELECTROSTATICS */
1938             felec            = _mm256_mul_ps(qq01,_mm256_sub_ps(_mm256_mul_ps(rinv01,rinvsq01),krf2));
1939
1940             cutoff_mask      = _mm256_cmp_ps(rsq01,rcutoff2,_CMP_LT_OQ);
1941
1942             fscal            = felec;
1943
1944             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1945
1946             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1947
1948             /* Calculate temporary vectorial force */
1949             tx               = _mm256_mul_ps(fscal,dx01);
1950             ty               = _mm256_mul_ps(fscal,dy01);
1951             tz               = _mm256_mul_ps(fscal,dz01);
1952
1953             /* Update vectorial force */
1954             fix0             = _mm256_add_ps(fix0,tx);
1955             fiy0             = _mm256_add_ps(fiy0,ty);
1956             fiz0             = _mm256_add_ps(fiz0,tz);
1957
1958             fjx1             = _mm256_add_ps(fjx1,tx);
1959             fjy1             = _mm256_add_ps(fjy1,ty);
1960             fjz1             = _mm256_add_ps(fjz1,tz);
1961
1962             }
1963
1964             /**************************
1965              * CALCULATE INTERACTIONS *
1966              **************************/
1967
1968             if (gmx_mm256_any_lt(rsq02,rcutoff2))
1969             {
1970
1971             /* REACTION-FIELD ELECTROSTATICS */
1972             felec            = _mm256_mul_ps(qq02,_mm256_sub_ps(_mm256_mul_ps(rinv02,rinvsq02),krf2));
1973
1974             cutoff_mask      = _mm256_cmp_ps(rsq02,rcutoff2,_CMP_LT_OQ);
1975
1976             fscal            = felec;
1977
1978             fscal            = _mm256_and_ps(fscal,cutoff_mask);
1979
1980             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
1981
1982             /* Calculate temporary vectorial force */
1983             tx               = _mm256_mul_ps(fscal,dx02);
1984             ty               = _mm256_mul_ps(fscal,dy02);
1985             tz               = _mm256_mul_ps(fscal,dz02);
1986
1987             /* Update vectorial force */
1988             fix0             = _mm256_add_ps(fix0,tx);
1989             fiy0             = _mm256_add_ps(fiy0,ty);
1990             fiz0             = _mm256_add_ps(fiz0,tz);
1991
1992             fjx2             = _mm256_add_ps(fjx2,tx);
1993             fjy2             = _mm256_add_ps(fjy2,ty);
1994             fjz2             = _mm256_add_ps(fjz2,tz);
1995
1996             }
1997
1998             /**************************
1999              * CALCULATE INTERACTIONS *
2000              **************************/
2001
2002             if (gmx_mm256_any_lt(rsq10,rcutoff2))
2003             {
2004
2005             /* REACTION-FIELD ELECTROSTATICS */
2006             felec            = _mm256_mul_ps(qq10,_mm256_sub_ps(_mm256_mul_ps(rinv10,rinvsq10),krf2));
2007
2008             cutoff_mask      = _mm256_cmp_ps(rsq10,rcutoff2,_CMP_LT_OQ);
2009
2010             fscal            = felec;
2011
2012             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2013
2014             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2015
2016             /* Calculate temporary vectorial force */
2017             tx               = _mm256_mul_ps(fscal,dx10);
2018             ty               = _mm256_mul_ps(fscal,dy10);
2019             tz               = _mm256_mul_ps(fscal,dz10);
2020
2021             /* Update vectorial force */
2022             fix1             = _mm256_add_ps(fix1,tx);
2023             fiy1             = _mm256_add_ps(fiy1,ty);
2024             fiz1             = _mm256_add_ps(fiz1,tz);
2025
2026             fjx0             = _mm256_add_ps(fjx0,tx);
2027             fjy0             = _mm256_add_ps(fjy0,ty);
2028             fjz0             = _mm256_add_ps(fjz0,tz);
2029
2030             }
2031
2032             /**************************
2033              * CALCULATE INTERACTIONS *
2034              **************************/
2035
2036             if (gmx_mm256_any_lt(rsq11,rcutoff2))
2037             {
2038
2039             /* REACTION-FIELD ELECTROSTATICS */
2040             felec            = _mm256_mul_ps(qq11,_mm256_sub_ps(_mm256_mul_ps(rinv11,rinvsq11),krf2));
2041
2042             cutoff_mask      = _mm256_cmp_ps(rsq11,rcutoff2,_CMP_LT_OQ);
2043
2044             fscal            = felec;
2045
2046             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2047
2048             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2049
2050             /* Calculate temporary vectorial force */
2051             tx               = _mm256_mul_ps(fscal,dx11);
2052             ty               = _mm256_mul_ps(fscal,dy11);
2053             tz               = _mm256_mul_ps(fscal,dz11);
2054
2055             /* Update vectorial force */
2056             fix1             = _mm256_add_ps(fix1,tx);
2057             fiy1             = _mm256_add_ps(fiy1,ty);
2058             fiz1             = _mm256_add_ps(fiz1,tz);
2059
2060             fjx1             = _mm256_add_ps(fjx1,tx);
2061             fjy1             = _mm256_add_ps(fjy1,ty);
2062             fjz1             = _mm256_add_ps(fjz1,tz);
2063
2064             }
2065
2066             /**************************
2067              * CALCULATE INTERACTIONS *
2068              **************************/
2069
2070             if (gmx_mm256_any_lt(rsq12,rcutoff2))
2071             {
2072
2073             /* REACTION-FIELD ELECTROSTATICS */
2074             felec            = _mm256_mul_ps(qq12,_mm256_sub_ps(_mm256_mul_ps(rinv12,rinvsq12),krf2));
2075
2076             cutoff_mask      = _mm256_cmp_ps(rsq12,rcutoff2,_CMP_LT_OQ);
2077
2078             fscal            = felec;
2079
2080             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2081
2082             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2083
2084             /* Calculate temporary vectorial force */
2085             tx               = _mm256_mul_ps(fscal,dx12);
2086             ty               = _mm256_mul_ps(fscal,dy12);
2087             tz               = _mm256_mul_ps(fscal,dz12);
2088
2089             /* Update vectorial force */
2090             fix1             = _mm256_add_ps(fix1,tx);
2091             fiy1             = _mm256_add_ps(fiy1,ty);
2092             fiz1             = _mm256_add_ps(fiz1,tz);
2093
2094             fjx2             = _mm256_add_ps(fjx2,tx);
2095             fjy2             = _mm256_add_ps(fjy2,ty);
2096             fjz2             = _mm256_add_ps(fjz2,tz);
2097
2098             }
2099
2100             /**************************
2101              * CALCULATE INTERACTIONS *
2102              **************************/
2103
2104             if (gmx_mm256_any_lt(rsq20,rcutoff2))
2105             {
2106
2107             /* REACTION-FIELD ELECTROSTATICS */
2108             felec            = _mm256_mul_ps(qq20,_mm256_sub_ps(_mm256_mul_ps(rinv20,rinvsq20),krf2));
2109
2110             cutoff_mask      = _mm256_cmp_ps(rsq20,rcutoff2,_CMP_LT_OQ);
2111
2112             fscal            = felec;
2113
2114             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2115
2116             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2117
2118             /* Calculate temporary vectorial force */
2119             tx               = _mm256_mul_ps(fscal,dx20);
2120             ty               = _mm256_mul_ps(fscal,dy20);
2121             tz               = _mm256_mul_ps(fscal,dz20);
2122
2123             /* Update vectorial force */
2124             fix2             = _mm256_add_ps(fix2,tx);
2125             fiy2             = _mm256_add_ps(fiy2,ty);
2126             fiz2             = _mm256_add_ps(fiz2,tz);
2127
2128             fjx0             = _mm256_add_ps(fjx0,tx);
2129             fjy0             = _mm256_add_ps(fjy0,ty);
2130             fjz0             = _mm256_add_ps(fjz0,tz);
2131
2132             }
2133
2134             /**************************
2135              * CALCULATE INTERACTIONS *
2136              **************************/
2137
2138             if (gmx_mm256_any_lt(rsq21,rcutoff2))
2139             {
2140
2141             /* REACTION-FIELD ELECTROSTATICS */
2142             felec            = _mm256_mul_ps(qq21,_mm256_sub_ps(_mm256_mul_ps(rinv21,rinvsq21),krf2));
2143
2144             cutoff_mask      = _mm256_cmp_ps(rsq21,rcutoff2,_CMP_LT_OQ);
2145
2146             fscal            = felec;
2147
2148             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2149
2150             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2151
2152             /* Calculate temporary vectorial force */
2153             tx               = _mm256_mul_ps(fscal,dx21);
2154             ty               = _mm256_mul_ps(fscal,dy21);
2155             tz               = _mm256_mul_ps(fscal,dz21);
2156
2157             /* Update vectorial force */
2158             fix2             = _mm256_add_ps(fix2,tx);
2159             fiy2             = _mm256_add_ps(fiy2,ty);
2160             fiz2             = _mm256_add_ps(fiz2,tz);
2161
2162             fjx1             = _mm256_add_ps(fjx1,tx);
2163             fjy1             = _mm256_add_ps(fjy1,ty);
2164             fjz1             = _mm256_add_ps(fjz1,tz);
2165
2166             }
2167
2168             /**************************
2169              * CALCULATE INTERACTIONS *
2170              **************************/
2171
2172             if (gmx_mm256_any_lt(rsq22,rcutoff2))
2173             {
2174
2175             /* REACTION-FIELD ELECTROSTATICS */
2176             felec            = _mm256_mul_ps(qq22,_mm256_sub_ps(_mm256_mul_ps(rinv22,rinvsq22),krf2));
2177
2178             cutoff_mask      = _mm256_cmp_ps(rsq22,rcutoff2,_CMP_LT_OQ);
2179
2180             fscal            = felec;
2181
2182             fscal            = _mm256_and_ps(fscal,cutoff_mask);
2183
2184             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
2185
2186             /* Calculate temporary vectorial force */
2187             tx               = _mm256_mul_ps(fscal,dx22);
2188             ty               = _mm256_mul_ps(fscal,dy22);
2189             tz               = _mm256_mul_ps(fscal,dz22);
2190
2191             /* Update vectorial force */
2192             fix2             = _mm256_add_ps(fix2,tx);
2193             fiy2             = _mm256_add_ps(fiy2,ty);
2194             fiz2             = _mm256_add_ps(fiz2,tz);
2195
2196             fjx2             = _mm256_add_ps(fjx2,tx);
2197             fjy2             = _mm256_add_ps(fjy2,ty);
2198             fjz2             = _mm256_add_ps(fjz2,tz);
2199
2200             }
2201
2202             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2203             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2204             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2205             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2206             fjptrE             = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
2207             fjptrF             = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
2208             fjptrG             = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
2209             fjptrH             = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
2210
2211             gmx_mm256_decrement_3rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,
2212                                                       fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2213
2214             /* Inner loop uses 277 flops */
2215         }
2216
2217         /* End of innermost loop */
2218
2219         gmx_mm256_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2220                                                  f+i_coord_offset,fshift+i_shift_offset);
2221
2222         /* Increment number of inner iterations */
2223         inneriter                  += j_index_end - j_index_start;
2224
2225         /* Outer loop uses 18 flops */
2226     }
2227
2228     /* Increment number of outer iterations */
2229     outeriter        += nri;
2230
2231     /* Update outer/inner flops */
2232
2233     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W3W3_F,outeriter*18 + inneriter*277);
2234 }