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