1f4d60787a1198eb2e1b160c3d4f4d235a35c281
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_256_double / nb_kernel_ElecEw_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_ElecEw_VdwNone_GeomP1P1_VF_avx_256_double
52  * Electrostatics interaction: Ewald
53  * VdW interaction:            None
54  * Geometry:                   Particle-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecEw_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     __m128i          ewitab;
92     __m256d          ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
93     __m256d          beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
94     real             *ewtab;
95     __m256d          dummy_mask,cutoff_mask;
96     __m128           tmpmask0,tmpmask1;
97     __m256d          signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
98     __m256d          one     = _mm256_set1_pd(1.0);
99     __m256d          two     = _mm256_set1_pd(2.0);
100     x                = xx[0];
101     f                = ff[0];
102
103     nri              = nlist->nri;
104     iinr             = nlist->iinr;
105     jindex           = nlist->jindex;
106     jjnr             = nlist->jjnr;
107     shiftidx         = nlist->shift;
108     gid              = nlist->gid;
109     shiftvec         = fr->shift_vec[0];
110     fshift           = fr->fshift[0];
111     facel            = _mm256_set1_pd(fr->epsfac);
112     charge           = mdatoms->chargeA;
113
114     sh_ewald         = _mm256_set1_pd(fr->ic->sh_ewald);
115     beta             = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
116     beta2            = _mm256_mul_pd(beta,beta);
117     beta3            = _mm256_mul_pd(beta,beta2);
118
119     ewtab            = fr->ic->tabq_coul_FDV0;
120     ewtabscale       = _mm256_set1_pd(fr->ic->tabq_scale);
121     ewtabhalfspace   = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
122
123     /* Avoid stupid compiler warnings */
124     jnrA = jnrB = jnrC = jnrD = 0;
125     j_coord_offsetA = 0;
126     j_coord_offsetB = 0;
127     j_coord_offsetC = 0;
128     j_coord_offsetD = 0;
129
130     outeriter        = 0;
131     inneriter        = 0;
132
133     for(iidx=0;iidx<4*DIM;iidx++)
134     {
135         scratch[iidx] = 0.0;
136     }
137
138     /* Start outer loop over neighborlists */
139     for(iidx=0; iidx<nri; iidx++)
140     {
141         /* Load shift vector for this list */
142         i_shift_offset   = DIM*shiftidx[iidx];
143
144         /* Load limits for loop over neighbors */
145         j_index_start    = jindex[iidx];
146         j_index_end      = jindex[iidx+1];
147
148         /* Get outer coordinate index */
149         inr              = iinr[iidx];
150         i_coord_offset   = DIM*inr;
151
152         /* Load i particle coords and add shift vector */
153         gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
154
155         fix0             = _mm256_setzero_pd();
156         fiy0             = _mm256_setzero_pd();
157         fiz0             = _mm256_setzero_pd();
158
159         /* Load parameters for i particles */
160         iq0              = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
161
162         /* Reset potential sums */
163         velecsum         = _mm256_setzero_pd();
164
165         /* Start inner kernel loop */
166         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
167         {
168
169             /* Get j neighbor index, and coordinate index */
170             jnrA             = jjnr[jidx];
171             jnrB             = jjnr[jidx+1];
172             jnrC             = jjnr[jidx+2];
173             jnrD             = jjnr[jidx+3];
174             j_coord_offsetA  = DIM*jnrA;
175             j_coord_offsetB  = DIM*jnrB;
176             j_coord_offsetC  = DIM*jnrC;
177             j_coord_offsetD  = DIM*jnrD;
178
179             /* load j atom coordinates */
180             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
181                                                  x+j_coord_offsetC,x+j_coord_offsetD,
182                                                  &jx0,&jy0,&jz0);
183
184             /* Calculate displacement vector */
185             dx00             = _mm256_sub_pd(ix0,jx0);
186             dy00             = _mm256_sub_pd(iy0,jy0);
187             dz00             = _mm256_sub_pd(iz0,jz0);
188
189             /* Calculate squared distance and things based on it */
190             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
191
192             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
193
194             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
195
196             /* Load parameters for j particles */
197             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
198                                                                  charge+jnrC+0,charge+jnrD+0);
199
200             /**************************
201              * CALCULATE INTERACTIONS *
202              **************************/
203
204             r00              = _mm256_mul_pd(rsq00,rinv00);
205
206             /* Compute parameters for interactions between i and j atoms */
207             qq00             = _mm256_mul_pd(iq0,jq0);
208
209             /* EWALD ELECTROSTATICS */
210
211             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
212             ewrt             = _mm256_mul_pd(r00,ewtabscale);
213             ewitab           = _mm256_cvttpd_epi32(ewrt);
214             eweps            = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
215             ewitab           = _mm_slli_epi32(ewitab,2);
216             ewtabF           = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
217             ewtabD           = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
218             ewtabV           = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
219             ewtabFn          = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
220             GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
221             felec            = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
222             velec            = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
223             velec            = _mm256_mul_pd(qq00,_mm256_sub_pd(rinv00,velec));
224             felec            = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
225
226             /* Update potential sum for this i atom from the interaction with this j atom. */
227             velecsum         = _mm256_add_pd(velecsum,velec);
228
229             fscal            = felec;
230
231             /* Calculate temporary vectorial force */
232             tx               = _mm256_mul_pd(fscal,dx00);
233             ty               = _mm256_mul_pd(fscal,dy00);
234             tz               = _mm256_mul_pd(fscal,dz00);
235
236             /* Update vectorial force */
237             fix0             = _mm256_add_pd(fix0,tx);
238             fiy0             = _mm256_add_pd(fiy0,ty);
239             fiz0             = _mm256_add_pd(fiz0,tz);
240
241             fjptrA             = f+j_coord_offsetA;
242             fjptrB             = f+j_coord_offsetB;
243             fjptrC             = f+j_coord_offsetC;
244             fjptrD             = f+j_coord_offsetD;
245             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
246
247             /* Inner loop uses 41 flops */
248         }
249
250         if(jidx<j_index_end)
251         {
252
253             /* Get j neighbor index, and coordinate index */
254             jnrlistA         = jjnr[jidx];
255             jnrlistB         = jjnr[jidx+1];
256             jnrlistC         = jjnr[jidx+2];
257             jnrlistD         = jjnr[jidx+3];
258             /* Sign of each element will be negative for non-real atoms.
259              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
260              * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
261              */
262             tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
263
264             tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
265             tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
266             dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
267
268             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
269             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
270             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
271             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
272             j_coord_offsetA  = DIM*jnrA;
273             j_coord_offsetB  = DIM*jnrB;
274             j_coord_offsetC  = DIM*jnrC;
275             j_coord_offsetD  = DIM*jnrD;
276
277             /* load j atom coordinates */
278             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
279                                                  x+j_coord_offsetC,x+j_coord_offsetD,
280                                                  &jx0,&jy0,&jz0);
281
282             /* Calculate displacement vector */
283             dx00             = _mm256_sub_pd(ix0,jx0);
284             dy00             = _mm256_sub_pd(iy0,jy0);
285             dz00             = _mm256_sub_pd(iz0,jz0);
286
287             /* Calculate squared distance and things based on it */
288             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
289
290             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
291
292             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
293
294             /* Load parameters for j particles */
295             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
296                                                                  charge+jnrC+0,charge+jnrD+0);
297
298             /**************************
299              * CALCULATE INTERACTIONS *
300              **************************/
301
302             r00              = _mm256_mul_pd(rsq00,rinv00);
303             r00              = _mm256_andnot_pd(dummy_mask,r00);
304
305             /* Compute parameters for interactions between i and j atoms */
306             qq00             = _mm256_mul_pd(iq0,jq0);
307
308             /* EWALD ELECTROSTATICS */
309
310             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
311             ewrt             = _mm256_mul_pd(r00,ewtabscale);
312             ewitab           = _mm256_cvttpd_epi32(ewrt);
313             eweps            = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
314             ewitab           = _mm_slli_epi32(ewitab,2);
315             ewtabF           = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,0) );
316             ewtabD           = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,1) );
317             ewtabV           = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,2) );
318             ewtabFn          = _mm256_load_pd( ewtab + _mm_extract_epi32(ewitab,3) );
319             GMX_MM256_FULLTRANSPOSE4_PD(ewtabF,ewtabD,ewtabV,ewtabFn);
320             felec            = _mm256_add_pd(ewtabF,_mm256_mul_pd(eweps,ewtabD));
321             velec            = _mm256_sub_pd(ewtabV,_mm256_mul_pd(_mm256_mul_pd(ewtabhalfspace,eweps),_mm256_add_pd(ewtabF,felec)));
322             velec            = _mm256_mul_pd(qq00,_mm256_sub_pd(rinv00,velec));
323             felec            = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
324
325             /* Update potential sum for this i atom from the interaction with this j atom. */
326             velec            = _mm256_andnot_pd(dummy_mask,velec);
327             velecsum         = _mm256_add_pd(velecsum,velec);
328
329             fscal            = felec;
330
331             fscal            = _mm256_andnot_pd(dummy_mask,fscal);
332
333             /* Calculate temporary vectorial force */
334             tx               = _mm256_mul_pd(fscal,dx00);
335             ty               = _mm256_mul_pd(fscal,dy00);
336             tz               = _mm256_mul_pd(fscal,dz00);
337
338             /* Update vectorial force */
339             fix0             = _mm256_add_pd(fix0,tx);
340             fiy0             = _mm256_add_pd(fiy0,ty);
341             fiz0             = _mm256_add_pd(fiz0,tz);
342
343             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
344             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
345             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
346             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
347             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
348
349             /* Inner loop uses 42 flops */
350         }
351
352         /* End of innermost loop */
353
354         gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
355                                                  f+i_coord_offset,fshift+i_shift_offset);
356
357         ggid                        = gid[iidx];
358         /* Update potential energies */
359         gmx_mm256_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
360
361         /* Increment number of inner iterations */
362         inneriter                  += j_index_end - j_index_start;
363
364         /* Outer loop uses 8 flops */
365     }
366
367     /* Increment number of outer iterations */
368     outeriter        += nri;
369
370     /* Update outer/inner flops */
371
372     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*42);
373 }
374 /*
375  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_256_double
376  * Electrostatics interaction: Ewald
377  * VdW interaction:            None
378  * Geometry:                   Particle-Particle
379  * Calculate force/pot:        Force
380  */
381 void
382 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_avx_256_double
383                     (t_nblist                    * gmx_restrict       nlist,
384                      rvec                        * gmx_restrict          xx,
385                      rvec                        * gmx_restrict          ff,
386                      t_forcerec                  * gmx_restrict          fr,
387                      t_mdatoms                   * gmx_restrict     mdatoms,
388                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
389                      t_nrnb                      * gmx_restrict        nrnb)
390 {
391     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
392      * just 0 for non-waters.
393      * Suffixes A,B,C,D refer to j loop unrolling done with AVX, e.g. for the four different
394      * jnr indices corresponding to data put in the four positions in the SIMD register.
395      */
396     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
397     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
398     int              jnrA,jnrB,jnrC,jnrD;
399     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
400     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
401     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
402     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
403     real             rcutoff_scalar;
404     real             *shiftvec,*fshift,*x,*f;
405     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
406     real             scratch[4*DIM];
407     __m256d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
408     real *           vdwioffsetptr0;
409     __m256d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
410     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
411     __m256d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
412     __m256d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
413     __m256d          velec,felec,velecsum,facel,crf,krf,krf2;
414     real             *charge;
415     __m128i          ewitab;
416     __m256d          ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
417     __m256d          beta,beta2,beta3,zeta2,pmecorrF,pmecorrV,rinv3;
418     real             *ewtab;
419     __m256d          dummy_mask,cutoff_mask;
420     __m128           tmpmask0,tmpmask1;
421     __m256d          signbit = _mm256_castsi256_pd( _mm256_set1_epi32(0x80000000) );
422     __m256d          one     = _mm256_set1_pd(1.0);
423     __m256d          two     = _mm256_set1_pd(2.0);
424     x                = xx[0];
425     f                = ff[0];
426
427     nri              = nlist->nri;
428     iinr             = nlist->iinr;
429     jindex           = nlist->jindex;
430     jjnr             = nlist->jjnr;
431     shiftidx         = nlist->shift;
432     gid              = nlist->gid;
433     shiftvec         = fr->shift_vec[0];
434     fshift           = fr->fshift[0];
435     facel            = _mm256_set1_pd(fr->epsfac);
436     charge           = mdatoms->chargeA;
437
438     sh_ewald         = _mm256_set1_pd(fr->ic->sh_ewald);
439     beta             = _mm256_set1_pd(fr->ic->ewaldcoeff_q);
440     beta2            = _mm256_mul_pd(beta,beta);
441     beta3            = _mm256_mul_pd(beta,beta2);
442
443     ewtab            = fr->ic->tabq_coul_F;
444     ewtabscale       = _mm256_set1_pd(fr->ic->tabq_scale);
445     ewtabhalfspace   = _mm256_set1_pd(0.5/fr->ic->tabq_scale);
446
447     /* Avoid stupid compiler warnings */
448     jnrA = jnrB = jnrC = jnrD = 0;
449     j_coord_offsetA = 0;
450     j_coord_offsetB = 0;
451     j_coord_offsetC = 0;
452     j_coord_offsetD = 0;
453
454     outeriter        = 0;
455     inneriter        = 0;
456
457     for(iidx=0;iidx<4*DIM;iidx++)
458     {
459         scratch[iidx] = 0.0;
460     }
461
462     /* Start outer loop over neighborlists */
463     for(iidx=0; iidx<nri; iidx++)
464     {
465         /* Load shift vector for this list */
466         i_shift_offset   = DIM*shiftidx[iidx];
467
468         /* Load limits for loop over neighbors */
469         j_index_start    = jindex[iidx];
470         j_index_end      = jindex[iidx+1];
471
472         /* Get outer coordinate index */
473         inr              = iinr[iidx];
474         i_coord_offset   = DIM*inr;
475
476         /* Load i particle coords and add shift vector */
477         gmx_mm256_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
478
479         fix0             = _mm256_setzero_pd();
480         fiy0             = _mm256_setzero_pd();
481         fiz0             = _mm256_setzero_pd();
482
483         /* Load parameters for i particles */
484         iq0              = _mm256_mul_pd(facel,_mm256_set1_pd(charge[inr+0]));
485
486         /* Start inner kernel loop */
487         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
488         {
489
490             /* Get j neighbor index, and coordinate index */
491             jnrA             = jjnr[jidx];
492             jnrB             = jjnr[jidx+1];
493             jnrC             = jjnr[jidx+2];
494             jnrD             = jjnr[jidx+3];
495             j_coord_offsetA  = DIM*jnrA;
496             j_coord_offsetB  = DIM*jnrB;
497             j_coord_offsetC  = DIM*jnrC;
498             j_coord_offsetD  = DIM*jnrD;
499
500             /* load j atom coordinates */
501             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
502                                                  x+j_coord_offsetC,x+j_coord_offsetD,
503                                                  &jx0,&jy0,&jz0);
504
505             /* Calculate displacement vector */
506             dx00             = _mm256_sub_pd(ix0,jx0);
507             dy00             = _mm256_sub_pd(iy0,jy0);
508             dz00             = _mm256_sub_pd(iz0,jz0);
509
510             /* Calculate squared distance and things based on it */
511             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
512
513             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
514
515             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
516
517             /* Load parameters for j particles */
518             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
519                                                                  charge+jnrC+0,charge+jnrD+0);
520
521             /**************************
522              * CALCULATE INTERACTIONS *
523              **************************/
524
525             r00              = _mm256_mul_pd(rsq00,rinv00);
526
527             /* Compute parameters for interactions between i and j atoms */
528             qq00             = _mm256_mul_pd(iq0,jq0);
529
530             /* EWALD ELECTROSTATICS */
531
532             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
533             ewrt             = _mm256_mul_pd(r00,ewtabscale);
534             ewitab           = _mm256_cvttpd_epi32(ewrt);
535             eweps            = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
536             gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
537                                             ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
538                                             &ewtabF,&ewtabFn);
539             felec            = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
540             felec            = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
541
542             fscal            = felec;
543
544             /* Calculate temporary vectorial force */
545             tx               = _mm256_mul_pd(fscal,dx00);
546             ty               = _mm256_mul_pd(fscal,dy00);
547             tz               = _mm256_mul_pd(fscal,dz00);
548
549             /* Update vectorial force */
550             fix0             = _mm256_add_pd(fix0,tx);
551             fiy0             = _mm256_add_pd(fiy0,ty);
552             fiz0             = _mm256_add_pd(fiz0,tz);
553
554             fjptrA             = f+j_coord_offsetA;
555             fjptrB             = f+j_coord_offsetB;
556             fjptrC             = f+j_coord_offsetC;
557             fjptrD             = f+j_coord_offsetD;
558             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
559
560             /* Inner loop uses 36 flops */
561         }
562
563         if(jidx<j_index_end)
564         {
565
566             /* Get j neighbor index, and coordinate index */
567             jnrlistA         = jjnr[jidx];
568             jnrlistB         = jjnr[jidx+1];
569             jnrlistC         = jjnr[jidx+2];
570             jnrlistD         = jjnr[jidx+3];
571             /* Sign of each element will be negative for non-real atoms.
572              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
573              * so use it as val = _mm_andnot_pd(mask,val) to clear dummy entries.
574              */
575             tmpmask0 = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
576
577             tmpmask1 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(3,3,2,2));
578             tmpmask0 = _mm_permute_ps(tmpmask0,_GMX_MM_PERMUTE(1,1,0,0));
579             dummy_mask = _mm256_castps_pd(gmx_mm256_set_m128(tmpmask1,tmpmask0));
580
581             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
582             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
583             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
584             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
585             j_coord_offsetA  = DIM*jnrA;
586             j_coord_offsetB  = DIM*jnrB;
587             j_coord_offsetC  = DIM*jnrC;
588             j_coord_offsetD  = DIM*jnrD;
589
590             /* load j atom coordinates */
591             gmx_mm256_load_1rvec_4ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
592                                                  x+j_coord_offsetC,x+j_coord_offsetD,
593                                                  &jx0,&jy0,&jz0);
594
595             /* Calculate displacement vector */
596             dx00             = _mm256_sub_pd(ix0,jx0);
597             dy00             = _mm256_sub_pd(iy0,jy0);
598             dz00             = _mm256_sub_pd(iz0,jz0);
599
600             /* Calculate squared distance and things based on it */
601             rsq00            = gmx_mm256_calc_rsq_pd(dx00,dy00,dz00);
602
603             rinv00           = gmx_mm256_invsqrt_pd(rsq00);
604
605             rinvsq00         = _mm256_mul_pd(rinv00,rinv00);
606
607             /* Load parameters for j particles */
608             jq0              = gmx_mm256_load_4real_swizzle_pd(charge+jnrA+0,charge+jnrB+0,
609                                                                  charge+jnrC+0,charge+jnrD+0);
610
611             /**************************
612              * CALCULATE INTERACTIONS *
613              **************************/
614
615             r00              = _mm256_mul_pd(rsq00,rinv00);
616             r00              = _mm256_andnot_pd(dummy_mask,r00);
617
618             /* Compute parameters for interactions between i and j atoms */
619             qq00             = _mm256_mul_pd(iq0,jq0);
620
621             /* EWALD ELECTROSTATICS */
622
623             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
624             ewrt             = _mm256_mul_pd(r00,ewtabscale);
625             ewitab           = _mm256_cvttpd_epi32(ewrt);
626             eweps            = _mm256_sub_pd(ewrt,_mm256_round_pd(ewrt, _MM_FROUND_FLOOR));
627             gmx_mm256_load_4pair_swizzle_pd(ewtab + _mm_extract_epi32(ewitab,0),ewtab + _mm_extract_epi32(ewitab,1),
628                                             ewtab + _mm_extract_epi32(ewitab,2),ewtab + _mm_extract_epi32(ewitab,3),
629                                             &ewtabF,&ewtabFn);
630             felec            = _mm256_add_pd(_mm256_mul_pd( _mm256_sub_pd(one,eweps),ewtabF),_mm256_mul_pd(eweps,ewtabFn));
631             felec            = _mm256_mul_pd(_mm256_mul_pd(qq00,rinv00),_mm256_sub_pd(rinvsq00,felec));
632
633             fscal            = felec;
634
635             fscal            = _mm256_andnot_pd(dummy_mask,fscal);
636
637             /* Calculate temporary vectorial force */
638             tx               = _mm256_mul_pd(fscal,dx00);
639             ty               = _mm256_mul_pd(fscal,dy00);
640             tz               = _mm256_mul_pd(fscal,dz00);
641
642             /* Update vectorial force */
643             fix0             = _mm256_add_pd(fix0,tx);
644             fiy0             = _mm256_add_pd(fiy0,ty);
645             fiz0             = _mm256_add_pd(fiz0,tz);
646
647             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
648             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
649             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
650             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
651             gmx_mm256_decrement_1rvec_4ptr_swizzle_pd(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
652
653             /* Inner loop uses 37 flops */
654         }
655
656         /* End of innermost loop */
657
658         gmx_mm256_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
659                                                  f+i_coord_offset,fshift+i_shift_offset);
660
661         /* Increment number of inner iterations */
662         inneriter                  += j_index_end - j_index_start;
663
664         /* Outer loop uses 7 flops */
665     }
666
667     /* Increment number of outer iterations */
668     outeriter        += nri;
669
670     /* Update outer/inner flops */
671
672     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*37);
673 }