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