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