Remove no-inline-max-size and suppress remark
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_256_double / nb_kernel_ElecRFCut_VdwNone_GeomP1P1_avx_256_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS avx_256_double kernel generator.
37  */
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "vec.h"
47 #include "nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_256_double.h"
50 #include "kernelutil_x86_avx_256_double.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_256_double
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            None
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_256_double
61                     (t_nblist                    * gmx_restrict       nlist,
62                      rvec                        * gmx_restrict          xx,
63                      rvec                        * gmx_restrict          ff,
64                      t_forcerec                  * gmx_restrict          fr,
65                      t_mdatoms                   * gmx_restrict     mdatoms,
66                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
67                      t_nrnb                      * gmx_restrict        nrnb)
68 {
69     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
70      * just 0 for non-waters.
71      * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
72      * jnr indices corresponding to data put in the four positions in the SIMD register.
73      */
74     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
75     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
76     int              jnrA,jnrB,jnrC,jnrD;
77     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
78     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
79     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
80     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
81     real             rcutoff_scalar;
82     real             *shiftvec,*fshift,*x,*f;
83     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
84     real             scratch[4*DIM];
85     __m256d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86     real *           vdwioffsetptr0;
87     __m256d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89     __m256d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90     __m256d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91     __m256d          velec,felec,velecsum,facel,crf,krf,krf2;
92     real             *charge;
93     __m256d          dummy_mask,cutoff_mask;
94     __m128           tmpmask0,tmpmask1;
95     __m256d          signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
96     __m256d          one     = _mm256_set1_pd(1.0);
97     __m256d          two     = _mm256_set1_pd(2.0);
98     x                = xx[0];
99     f                = ff[0];
100
101     nri              = nlist->nri;
102     iinr             = nlist->iinr;
103     jindex           = nlist->jindex;
104     jjnr             = nlist->jjnr;
105     shiftidx         = nlist->shift;
106     gid              = nlist->gid;
107     shiftvec         = fr->shift_vec[0];
108     fshift           = fr->fshift[0];
109     facel            = _mm256_set1_pd(fr->epsfac);
110     charge           = mdatoms->chargeA;
111     krf              = _mm256_set1_pd(fr->ic->k_rf);
112     krf2             = _mm256_set1_pd(fr->ic->k_rf*2.0);
113     crf              = _mm256_set1_pd(fr->ic->c_rf);
114
115     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
116     rcutoff_scalar   = fr->rcoulomb;
117     rcutoff          = _mm256_set1_pd(rcutoff_scalar);
118     rcutoff2         = _mm256_mul_pd(rcutoff,rcutoff);
119
120     /* Avoid stupid compiler warnings */
121     jnrA = jnrB = jnrC = jnrD = 0;
122     j_coord_offsetA = 0;
123     j_coord_offsetB = 0;
124     j_coord_offsetC = 0;
125     j_coord_offsetD = 0;
126
127     outeriter        = 0;
128     inneriter        = 0;
129
130     for(iidx=0;iidx<4*DIM;iidx++)
131     {
132         scratch[iidx] = 0.0;
133     }
134
135     /* Start outer loop over neighborlists */
136     for(iidx=0; iidx<nri; iidx++)
137     {
138         /* Load shift vector for this list */
139         i_shift_offset   = DIM*shiftidx[iidx];
140
141         /* Load limits for loop over neighbors */
142         j_index_start    = jindex[iidx];
143         j_index_end      = jindex[iidx+1];
144
145         /* Get outer coordinate index */
146         inr              = iinr[iidx];
147         i_coord_offset   = DIM*inr;
148
149         /* Load i particle coords and add shift vector */
150         gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
151
152         fix0             = _mm256_setzero_pd();
153         fiy0             = _mm256_setzero_pd();
154         fiz0             = _mm256_setzero_pd();
155
156         /* Load parameters for i particles */
157         iq0              = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
158
159         /* Reset potential sums */
160         velecsum         = _mm256_setzero_pd();
161
162         /* Start inner kernel loop */
163         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
164         {
165
166             /* Get j neighbor index, and coordinate index */
167             jnrA             = jjnr[jidx];
168             jnrB             = jjnr[jidx+1];
169             jnrC             = jjnr[jidx+2];
170             jnrD             = jjnr[jidx+3];
171             j_coord_offsetA  = DIM*jnrA;
172             j_coord_offsetB  = DIM*jnrB;
173             j_coord_offsetC  = DIM*jnrC;
174             j_coord_offsetD  = DIM*jnrD;
175
176             /* load j atom coordinates */
177             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
178                                                  x+j_coord_offsetC,x+j_coord_offsetD,
179                                                  &jx0,&jy0,&jz0);
180
181             /* Calculate displacement vector */
182             dx00             = _mm256_sub_pd(ix0,jx0);
183             dy00             = _mm256_sub_pd(iy0,jy0);
184             dz00             = _mm256_sub_pd(iz0,jz0);
185
186             /* Calculate squared distance and things based on it */
187             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
188
189             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
190
191             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
192
193             /* Load parameters for j particles */
194             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
195                                                                  charge+jnrC+0,charge+jnrD+0);
196
197             /**************************
198              * CALCULATE INTERACTIONS *
199              **************************/
200
201             if (gmx_mm256_any_lt(rsq00,rcutoff2))
202             {
203
204             /* Compute parameters for interactions between i and j atoms */
205             qq00             = _mm256_mul_pd(iq0,jq0);
206
207             /* REACTION-FIELD ELECTROSTATICS */
208             velec            = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_add_pd(rinv00,_mm256_mul_pd(krf,rsq00)),crf));
209             felec            = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
210
211             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
212
213             /* Update potential sum for this i atom from the interaction with this j atom. */
214             velec            = _mm256_and_pd(velec,cutoff_mask);
215             velecsum         = _mm256_add_pd(velecsum,velec);
216
217             fscal            = felec;
218
219             fscal            = _mm256_and_pd(fscal,cutoff_mask);
220
221             /* Calculate temporary vectorial force */
222             tx               = _mm256_mul_pd(fscal,dx00);
223             ty               = _mm256_mul_pd(fscal,dy00);
224             tz               = _mm256_mul_pd(fscal,dz00);
225
226             /* Update vectorial force */
227             fix0             = _mm256_add_pd(fix0,tx);
228             fiy0             = _mm256_add_pd(fiy0,ty);
229             fiz0             = _mm256_add_pd(fiz0,tz);
230
231             fjptrA             = f+j_coord_offsetA;
232             fjptrB             = f+j_coord_offsetB;
233             fjptrC             = f+j_coord_offsetC;
234             fjptrD             = f+j_coord_offsetD;
235             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
236
237             }
238
239             /* Inner loop uses 36 flops */
240         }
241
242         if(jidx<j_index_end)
243         {
244
245             /* Get j neighbor index, and coordinate index */
246             jnrlistA         = jjnr[jidx];
247             jnrlistB         = jjnr[jidx+1];
248             jnrlistC         = jjnr[jidx+2];
249             jnrlistD         = jjnr[jidx+3];
250             /* Sign of each element will be negative for non-real atoms.
251              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
252              * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
253              */
254             tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
255
256             tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
257             tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
258             dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
259
260             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
261             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
262             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
263             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
264             j_coord_offsetA  = DIM*jnrA;
265             j_coord_offsetB  = DIM*jnrB;
266             j_coord_offsetC  = DIM*jnrC;
267             j_coord_offsetD  = DIM*jnrD;
268
269             /* load j atom coordinates */
270             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
271                                                  x+j_coord_offsetC,x+j_coord_offsetD,
272                                                  &jx0,&jy0,&jz0);
273
274             /* Calculate displacement vector */
275             dx00             = _mm256_sub_pd(ix0,jx0);
276             dy00             = _mm256_sub_pd(iy0,jy0);
277             dz00             = _mm256_sub_pd(iz0,jz0);
278
279             /* Calculate squared distance and things based on it */
280             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
281
282             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
283
284             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
285
286             /* Load parameters for j particles */
287             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
288                                                                  charge+jnrC+0,charge+jnrD+0);
289
290             /**************************
291              * CALCULATE INTERACTIONS *
292              **************************/
293
294             if (gmx_mm256_any_lt(rsq00,rcutoff2))
295             {
296
297             /* Compute parameters for interactions between i and j atoms */
298             qq00             = _mm256_mul_pd(iq0,jq0);
299
300             /* REACTION-FIELD ELECTROSTATICS */
301             velec            = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_add_pd(rinv00,_mm256_mul_pd(krf,rsq00)),crf));
302             felec            = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
303
304             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
305
306             /* Update potential sum for this i atom from the interaction with this j atom. */
307             velec            = _mm256_and_pd(velec,cutoff_mask);
308             velec            = _mm256_andnot_pd(dummy_mask,velec);
309             velecsum         = _mm256_add_pd(velecsum,velec);
310
311             fscal            = felec;
312
313             fscal            = _mm256_and_pd(fscal,cutoff_mask);
314
315             fscal            = _mm256_andnot_pd(dummy_mask,fscal);
316
317             /* Calculate temporary vectorial force */
318             tx               = _mm256_mul_pd(fscal,dx00);
319             ty               = _mm256_mul_pd(fscal,dy00);
320             tz               = _mm256_mul_pd(fscal,dz00);
321
322             /* Update vectorial force */
323             fix0             = _mm256_add_pd(fix0,tx);
324             fiy0             = _mm256_add_pd(fiy0,ty);
325             fiz0             = _mm256_add_pd(fiz0,tz);
326
327             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
328             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
329             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
330             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
331             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
332
333             }
334
335             /* Inner loop uses 36 flops */
336         }
337
338         /* End of innermost loop */
339
340         gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
341                                                  f+i_coord_offset,fshift+i_shift_offset);
342
343         ggid                        = gid[iidx];
344         /* Update potential energies */
345         gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
346
347         /* Increment number of inner iterations */
348         inneriter                  += j_index_end - j_index_start;
349
350         /* Outer loop uses 8 flops */
351     }
352
353     /* Increment number of outer iterations */
354     outeriter        += nri;
355
356     /* Update outer/inner flops */
357
358     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*36);
359 }
360 /*
361  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_256_double
362  * Electrostatics interaction: ReactionField
363  * VdW interaction:            None
364  * Geometry:                   Particle-Particle
365  * Calculate force/pot:        Force
366  */
367 void
368 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_256_double
369                     (t_nblist                    * gmx_restrict       nlist,
370                      rvec                        * gmx_restrict          xx,
371                      rvec                        * gmx_restrict          ff,
372                      t_forcerec                  * gmx_restrict          fr,
373                      t_mdatoms                   * gmx_restrict     mdatoms,
374                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
375                      t_nrnb                      * gmx_restrict        nrnb)
376 {
377     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
378      * just 0 for non-waters.
379      * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
380      * jnr indices corresponding to data put in the four positions in the SIMD register.
381      */
382     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
383     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
384     int              jnrA,jnrB,jnrC,jnrD;
385     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
386     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
387     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
388     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
389     real             rcutoff_scalar;
390     real             *shiftvec,*fshift,*x,*f;
391     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
392     real             scratch[4*DIM];
393     __m256d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
394     real *           vdwioffsetptr0;
395     __m256d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
396     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
397     __m256d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
398     __m256d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
399     __m256d          velec,felec,velecsum,facel,crf,krf,krf2;
400     real             *charge;
401     __m256d          dummy_mask,cutoff_mask;
402     __m128           tmpmask0,tmpmask1;
403     __m256d          signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
404     __m256d          one     = _mm256_set1_pd(1.0);
405     __m256d          two     = _mm256_set1_pd(2.0);
406     x                = xx[0];
407     f                = ff[0];
408
409     nri              = nlist->nri;
410     iinr             = nlist->iinr;
411     jindex           = nlist->jindex;
412     jjnr             = nlist->jjnr;
413     shiftidx         = nlist->shift;
414     gid              = nlist->gid;
415     shiftvec         = fr->shift_vec[0];
416     fshift           = fr->fshift[0];
417     facel            = _mm256_set1_pd(fr->epsfac);
418     charge           = mdatoms->chargeA;
419     krf              = _mm256_set1_pd(fr->ic->k_rf);
420     krf2             = _mm256_set1_pd(fr->ic->k_rf*2.0);
421     crf              = _mm256_set1_pd(fr->ic->c_rf);
422
423     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
424     rcutoff_scalar   = fr->rcoulomb;
425     rcutoff          = _mm256_set1_pd(rcutoff_scalar);
426     rcutoff2         = _mm256_mul_pd(rcutoff,rcutoff);
427
428     /* Avoid stupid compiler warnings */
429     jnrA = jnrB = jnrC = jnrD = 0;
430     j_coord_offsetA = 0;
431     j_coord_offsetB = 0;
432     j_coord_offsetC = 0;
433     j_coord_offsetD = 0;
434
435     outeriter        = 0;
436     inneriter        = 0;
437
438     for(iidx=0;iidx<4*DIM;iidx++)
439     {
440         scratch[iidx] = 0.0;
441     }
442
443     /* Start outer loop over neighborlists */
444     for(iidx=0; iidx<nri; iidx++)
445     {
446         /* Load shift vector for this list */
447         i_shift_offset   = DIM*shiftidx[iidx];
448
449         /* Load limits for loop over neighbors */
450         j_index_start    = jindex[iidx];
451         j_index_end      = jindex[iidx+1];
452
453         /* Get outer coordinate index */
454         inr              = iinr[iidx];
455         i_coord_offset   = DIM*inr;
456
457         /* Load i particle coords and add shift vector */
458         gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
459
460         fix0             = _mm256_setzero_pd();
461         fiy0             = _mm256_setzero_pd();
462         fiz0             = _mm256_setzero_pd();
463
464         /* Load parameters for i particles */
465         iq0              = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
466
467         /* Start inner kernel loop */
468         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
469         {
470
471             /* Get j neighbor index, and coordinate index */
472             jnrA             = jjnr[jidx];
473             jnrB             = jjnr[jidx+1];
474             jnrC             = jjnr[jidx+2];
475             jnrD             = jjnr[jidx+3];
476             j_coord_offsetA  = DIM*jnrA;
477             j_coord_offsetB  = DIM*jnrB;
478             j_coord_offsetC  = DIM*jnrC;
479             j_coord_offsetD  = DIM*jnrD;
480
481             /* load j atom coordinates */
482             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
483                                                  x+j_coord_offsetC,x+j_coord_offsetD,
484                                                  &jx0,&jy0,&jz0);
485
486             /* Calculate displacement vector */
487             dx00             = _mm256_sub_pd(ix0,jx0);
488             dy00             = _mm256_sub_pd(iy0,jy0);
489             dz00             = _mm256_sub_pd(iz0,jz0);
490
491             /* Calculate squared distance and things based on it */
492             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
493
494             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
495
496             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
497
498             /* Load parameters for j particles */
499             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
500                                                                  charge+jnrC+0,charge+jnrD+0);
501
502             /**************************
503              * CALCULATE INTERACTIONS *
504              **************************/
505
506             if (gmx_mm256_any_lt(rsq00,rcutoff2))
507             {
508
509             /* Compute parameters for interactions between i and j atoms */
510             qq00             = _mm256_mul_pd(iq0,jq0);
511
512             /* REACTION-FIELD ELECTROSTATICS */
513             felec            = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
514
515             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
516
517             fscal            = felec;
518
519             fscal            = _mm256_and_pd(fscal,cutoff_mask);
520
521             /* Calculate temporary vectorial force */
522             tx               = _mm256_mul_pd(fscal,dx00);
523             ty               = _mm256_mul_pd(fscal,dy00);
524             tz               = _mm256_mul_pd(fscal,dz00);
525
526             /* Update vectorial force */
527             fix0             = _mm256_add_pd(fix0,tx);
528             fiy0             = _mm256_add_pd(fiy0,ty);
529             fiz0             = _mm256_add_pd(fiz0,tz);
530
531             fjptrA             = f+j_coord_offsetA;
532             fjptrB             = f+j_coord_offsetB;
533             fjptrC             = f+j_coord_offsetC;
534             fjptrD             = f+j_coord_offsetD;
535             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
536
537             }
538
539             /* Inner loop uses 30 flops */
540         }
541
542         if(jidx<j_index_end)
543         {
544
545             /* Get j neighbor index, and coordinate index */
546             jnrlistA         = jjnr[jidx];
547             jnrlistB         = jjnr[jidx+1];
548             jnrlistC         = jjnr[jidx+2];
549             jnrlistD         = jjnr[jidx+3];
550             /* Sign of each element will be negative for non-real atoms.
551              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
552              * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
553              */
554             tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
555
556             tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
557             tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
558             dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
559
560             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
561             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
562             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
563             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
564             j_coord_offsetA  = DIM*jnrA;
565             j_coord_offsetB  = DIM*jnrB;
566             j_coord_offsetC  = DIM*jnrC;
567             j_coord_offsetD  = DIM*jnrD;
568
569             /* load j atom coordinates */
570             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
571                                                  x+j_coord_offsetC,x+j_coord_offsetD,
572                                                  &jx0,&jy0,&jz0);
573
574             /* Calculate displacement vector */
575             dx00             = _mm256_sub_pd(ix0,jx0);
576             dy00             = _mm256_sub_pd(iy0,jy0);
577             dz00             = _mm256_sub_pd(iz0,jz0);
578
579             /* Calculate squared distance and things based on it */
580             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
581
582             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
583
584             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
585
586             /* Load parameters for j particles */
587             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
588                                                                  charge+jnrC+0,charge+jnrD+0);
589
590             /**************************
591              * CALCULATE INTERACTIONS *
592              **************************/
593
594             if (gmx_mm256_any_lt(rsq00,rcutoff2))
595             {
596
597             /* Compute parameters for interactions between i and j atoms */
598             qq00             = _mm256_mul_pd(iq0,jq0);
599
600             /* REACTION-FIELD ELECTROSTATICS */
601             felec            = _mm256_mul_pd(qq00,_mm256_sub_pd(_mm256_mul_pd(rinv00,rinvsq00),krf2));
602
603             cutoff_mask      = _mm256_cmp_pd(rsq00,rcutoff2,_CMP_LT_OQ);
604
605             fscal            = felec;
606
607             fscal            = _mm256_and_pd(fscal,cutoff_mask);
608
609             fscal            = _mm256_andnot_pd(dummy_mask,fscal);
610
611             /* Calculate temporary vectorial force */
612             tx               = _mm256_mul_pd(fscal,dx00);
613             ty               = _mm256_mul_pd(fscal,dy00);
614             tz               = _mm256_mul_pd(fscal,dz00);
615
616             /* Update vectorial force */
617             fix0             = _mm256_add_pd(fix0,tx);
618             fiy0             = _mm256_add_pd(fiy0,ty);
619             fiz0             = _mm256_add_pd(fiz0,tz);
620
621             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
622             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
623             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
624             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
625             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
626
627             }
628
629             /* Inner loop uses 30 flops */
630         }
631
632         /* End of innermost loop */
633
634         gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
635                                                  f+i_coord_offset,fshift+i_shift_offset);
636
637         /* Increment number of inner iterations */
638         inneriter                  += j_index_end - j_index_start;
639
640         /* Outer loop uses 7 flops */
641     }
642
643     /* Increment number of outer iterations */
644     outeriter        += nri;
645
646     /* Update outer/inner flops */
647
648     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*30);
649 }