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