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