Use full path for legacyheaders
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_256_single / nb_kernel_ElecRF_VdwNone_GeomP1P1_avx_256_single.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_single 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_single.h"
48 #include "kernelutil_x86_avx_256_single.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwNone_GeomP1P1_VF_avx_256_single
52  * Electrostatics interaction: ReactionField
53  * VdW interaction:            None
54  * Geometry:                   Particle-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecRF_VdwNone_GeomP1P1_VF_avx_256_single
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,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight 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              jnrE,jnrF,jnrG,jnrH;
76     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
77     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
78     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79     int              j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
80     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
81     real             rcutoff_scalar;
82     real             *shiftvec,*fshift,*x,*f;
83     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
84     real             scratch[4*DIM];
85     __m256           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
86     real *           vdwioffsetptr0;
87     __m256           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
88     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
89     __m256           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90     __m256           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91     __m256           velec,felec,velecsum,facel,crf,krf,krf2;
92     real             *charge;
93     __m256           dummy_mask,cutoff_mask;
94     __m256           signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
95     __m256           one     = _mm256_set1_ps(1.0);
96     __m256           two     = _mm256_set1_ps(2.0);
97     x                = xx[0];
98     f                = ff[0];
99
100     nri              = nlist->nri;
101     iinr             = nlist->iinr;
102     jindex           = nlist->jindex;
103     jjnr             = nlist->jjnr;
104     shiftidx         = nlist->shift;
105     gid              = nlist->gid;
106     shiftvec         = fr->shift_vec[0];
107     fshift           = fr->fshift[0];
108     facel            = _mm256_set1_ps(fr->epsfac);
109     charge           = mdatoms->chargeA;
110     krf              = _mm256_set1_ps(fr->ic->k_rf);
111     krf2             = _mm256_set1_ps(fr->ic->k_rf*2.0);
112     crf              = _mm256_set1_ps(fr->ic->c_rf);
113
114     /* Avoid stupid compiler warnings */
115     jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
116     j_coord_offsetA = 0;
117     j_coord_offsetB = 0;
118     j_coord_offsetC = 0;
119     j_coord_offsetD = 0;
120     j_coord_offsetE = 0;
121     j_coord_offsetF = 0;
122     j_coord_offsetG = 0;
123     j_coord_offsetH = 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_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
149
150         fix0             = _mm256_setzero_ps();
151         fiy0             = _mm256_setzero_ps();
152         fiz0             = _mm256_setzero_ps();
153
154         /* Load parameters for i particles */
155         iq0              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
156
157         /* Reset potential sums */
158         velecsum         = _mm256_setzero_ps();
159
160         /* Start inner kernel loop */
161         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
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             jnrE             = jjnr[jidx+4];
170             jnrF             = jjnr[jidx+5];
171             jnrG             = jjnr[jidx+6];
172             jnrH             = jjnr[jidx+7];
173             j_coord_offsetA  = DIM*jnrA;
174             j_coord_offsetB  = DIM*jnrB;
175             j_coord_offsetC  = DIM*jnrC;
176             j_coord_offsetD  = DIM*jnrD;
177             j_coord_offsetE  = DIM*jnrE;
178             j_coord_offsetF  = DIM*jnrF;
179             j_coord_offsetG  = DIM*jnrG;
180             j_coord_offsetH  = DIM*jnrH;
181
182             /* load j atom coordinates */
183             gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
184                                                  x+j_coord_offsetC,x+j_coord_offsetD,
185                                                  x+j_coord_offsetE,x+j_coord_offsetF,
186                                                  x+j_coord_offsetG,x+j_coord_offsetH,
187                                                  &jx0,&jy0,&jz0);
188
189             /* Calculate displacement vector */
190             dx00             = _mm256_sub_ps(ix0,jx0);
191             dy00             = _mm256_sub_ps(iy0,jy0);
192             dz00             = _mm256_sub_ps(iz0,jz0);
193
194             /* Calculate squared distance and things based on it */
195             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
196
197             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
198
199             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
200
201             /* Load parameters for j particles */
202             jq0              = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
203                                                                  charge+jnrC+0,charge+jnrD+0,
204                                                                  charge+jnrE+0,charge+jnrF+0,
205                                                                  charge+jnrG+0,charge+jnrH+0);
206
207             /**************************
208              * CALCULATE INTERACTIONS *
209              **************************/
210
211             /* Compute parameters for interactions between i and j atoms */
212             qq00             = _mm256_mul_ps(iq0,jq0);
213
214             /* REACTION-FIELD ELECTROSTATICS */
215             velec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
216             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
217
218             /* Update potential sum for this i atom from the interaction with this j atom. */
219             velecsum         = _mm256_add_ps(velecsum,velec);
220
221             fscal            = felec;
222
223             /* Calculate temporary vectorial force */
224             tx               = _mm256_mul_ps(fscal,dx00);
225             ty               = _mm256_mul_ps(fscal,dy00);
226             tz               = _mm256_mul_ps(fscal,dz00);
227
228             /* Update vectorial force */
229             fix0             = _mm256_add_ps(fix0,tx);
230             fiy0             = _mm256_add_ps(fiy0,ty);
231             fiz0             = _mm256_add_ps(fiz0,tz);
232
233             fjptrA             = f+j_coord_offsetA;
234             fjptrB             = f+j_coord_offsetB;
235             fjptrC             = f+j_coord_offsetC;
236             fjptrD             = f+j_coord_offsetD;
237             fjptrE             = f+j_coord_offsetE;
238             fjptrF             = f+j_coord_offsetF;
239             fjptrG             = f+j_coord_offsetG;
240             fjptrH             = f+j_coord_offsetH;
241             gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
242
243             /* Inner loop uses 32 flops */
244         }
245
246         if(jidx<j_index_end)
247         {
248
249             /* Get j neighbor index, and coordinate index */
250             jnrlistA         = jjnr[jidx];
251             jnrlistB         = jjnr[jidx+1];
252             jnrlistC         = jjnr[jidx+2];
253             jnrlistD         = jjnr[jidx+3];
254             jnrlistE         = jjnr[jidx+4];
255             jnrlistF         = jjnr[jidx+5];
256             jnrlistG         = jjnr[jidx+6];
257             jnrlistH         = jjnr[jidx+7];
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_ps(mask,val) to clear dummy entries.
261              */
262             dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
263                                             gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
264                                             
265             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
266             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
267             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
268             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
269             jnrE       = (jnrlistE>=0) ? jnrlistE : 0;
270             jnrF       = (jnrlistF>=0) ? jnrlistF : 0;
271             jnrG       = (jnrlistG>=0) ? jnrlistG : 0;
272             jnrH       = (jnrlistH>=0) ? jnrlistH : 0;
273             j_coord_offsetA  = DIM*jnrA;
274             j_coord_offsetB  = DIM*jnrB;
275             j_coord_offsetC  = DIM*jnrC;
276             j_coord_offsetD  = DIM*jnrD;
277             j_coord_offsetE  = DIM*jnrE;
278             j_coord_offsetF  = DIM*jnrF;
279             j_coord_offsetG  = DIM*jnrG;
280             j_coord_offsetH  = DIM*jnrH;
281
282             /* load j atom coordinates */
283             gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
284                                                  x+j_coord_offsetC,x+j_coord_offsetD,
285                                                  x+j_coord_offsetE,x+j_coord_offsetF,
286                                                  x+j_coord_offsetG,x+j_coord_offsetH,
287                                                  &jx0,&jy0,&jz0);
288
289             /* Calculate displacement vector */
290             dx00             = _mm256_sub_ps(ix0,jx0);
291             dy00             = _mm256_sub_ps(iy0,jy0);
292             dz00             = _mm256_sub_ps(iz0,jz0);
293
294             /* Calculate squared distance and things based on it */
295             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
296
297             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
298
299             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
300
301             /* Load parameters for j particles */
302             jq0              = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
303                                                                  charge+jnrC+0,charge+jnrD+0,
304                                                                  charge+jnrE+0,charge+jnrF+0,
305                                                                  charge+jnrG+0,charge+jnrH+0);
306
307             /**************************
308              * CALCULATE INTERACTIONS *
309              **************************/
310
311             /* Compute parameters for interactions between i and j atoms */
312             qq00             = _mm256_mul_ps(iq0,jq0);
313
314             /* REACTION-FIELD ELECTROSTATICS */
315             velec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_add_ps(rinv00,_mm256_mul_ps(krf,rsq00)),crf));
316             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
317
318             /* Update potential sum for this i atom from the interaction with this j atom. */
319             velec            = _mm256_andnot_ps(dummy_mask,velec);
320             velecsum         = _mm256_add_ps(velecsum,velec);
321
322             fscal            = felec;
323
324             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
325
326             /* Calculate temporary vectorial force */
327             tx               = _mm256_mul_ps(fscal,dx00);
328             ty               = _mm256_mul_ps(fscal,dy00);
329             tz               = _mm256_mul_ps(fscal,dz00);
330
331             /* Update vectorial force */
332             fix0             = _mm256_add_ps(fix0,tx);
333             fiy0             = _mm256_add_ps(fiy0,ty);
334             fiz0             = _mm256_add_ps(fiz0,tz);
335
336             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
337             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
338             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
339             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
340             fjptrE             = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
341             fjptrF             = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
342             fjptrG             = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
343             fjptrH             = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
344             gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
345
346             /* Inner loop uses 32 flops */
347         }
348
349         /* End of innermost loop */
350
351         gmx_mm256_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
352                                                  f+i_coord_offset,fshift+i_shift_offset);
353
354         ggid                        = gid[iidx];
355         /* Update potential energies */
356         gmx_mm256_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
357
358         /* Increment number of inner iterations */
359         inneriter                  += j_index_end - j_index_start;
360
361         /* Outer loop uses 8 flops */
362     }
363
364     /* Increment number of outer iterations */
365     outeriter        += nri;
366
367     /* Update outer/inner flops */
368
369     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*32);
370 }
371 /*
372  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwNone_GeomP1P1_F_avx_256_single
373  * Electrostatics interaction: ReactionField
374  * VdW interaction:            None
375  * Geometry:                   Particle-Particle
376  * Calculate force/pot:        Force
377  */
378 void
379 nb_kernel_ElecRF_VdwNone_GeomP1P1_F_avx_256_single
380                     (t_nblist                    * gmx_restrict       nlist,
381                      rvec                        * gmx_restrict          xx,
382                      rvec                        * gmx_restrict          ff,
383                      t_forcerec                  * gmx_restrict          fr,
384                      t_mdatoms                   * gmx_restrict     mdatoms,
385                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
386                      t_nrnb                      * gmx_restrict        nrnb)
387 {
388     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
389      * just 0 for non-waters.
390      * Suffixes A,B,C,D,E,F,G,H refer to j loop unrolling done with AVX, e.g. for the eight different
391      * jnr indices corresponding to data put in the four positions in the SIMD register.
392      */
393     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
394     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
395     int              jnrA,jnrB,jnrC,jnrD;
396     int              jnrE,jnrF,jnrG,jnrH;
397     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
398     int              jnrlistE,jnrlistF,jnrlistG,jnrlistH;
399     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
400     int              j_coord_offsetE,j_coord_offsetF,j_coord_offsetG,j_coord_offsetH;
401     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
402     real             rcutoff_scalar;
403     real             *shiftvec,*fshift,*x,*f;
404     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD,*fjptrE,*fjptrF,*fjptrG,*fjptrH;
405     real             scratch[4*DIM];
406     __m256           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
407     real *           vdwioffsetptr0;
408     __m256           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
409     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D,vdwjidx0E,vdwjidx0F,vdwjidx0G,vdwjidx0H;
410     __m256           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
411     __m256           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
412     __m256           velec,felec,velecsum,facel,crf,krf,krf2;
413     real             *charge;
414     __m256           dummy_mask,cutoff_mask;
415     __m256           signbit = _mm256_castsi256_ps( _mm256_set1_epi32(0x80000000) );
416     __m256           one     = _mm256_set1_ps(1.0);
417     __m256           two     = _mm256_set1_ps(2.0);
418     x                = xx[0];
419     f                = ff[0];
420
421     nri              = nlist->nri;
422     iinr             = nlist->iinr;
423     jindex           = nlist->jindex;
424     jjnr             = nlist->jjnr;
425     shiftidx         = nlist->shift;
426     gid              = nlist->gid;
427     shiftvec         = fr->shift_vec[0];
428     fshift           = fr->fshift[0];
429     facel            = _mm256_set1_ps(fr->epsfac);
430     charge           = mdatoms->chargeA;
431     krf              = _mm256_set1_ps(fr->ic->k_rf);
432     krf2             = _mm256_set1_ps(fr->ic->k_rf*2.0);
433     crf              = _mm256_set1_ps(fr->ic->c_rf);
434
435     /* Avoid stupid compiler warnings */
436     jnrA = jnrB = jnrC = jnrD = jnrE = jnrF = jnrG = jnrH = 0;
437     j_coord_offsetA = 0;
438     j_coord_offsetB = 0;
439     j_coord_offsetC = 0;
440     j_coord_offsetD = 0;
441     j_coord_offsetE = 0;
442     j_coord_offsetF = 0;
443     j_coord_offsetG = 0;
444     j_coord_offsetH = 0;
445
446     outeriter        = 0;
447     inneriter        = 0;
448
449     for(iidx=0;iidx<4*DIM;iidx++)
450     {
451         scratch[iidx] = 0.0;
452     }
453
454     /* Start outer loop over neighborlists */
455     for(iidx=0; iidx<nri; iidx++)
456     {
457         /* Load shift vector for this list */
458         i_shift_offset   = DIM*shiftidx[iidx];
459
460         /* Load limits for loop over neighbors */
461         j_index_start    = jindex[iidx];
462         j_index_end      = jindex[iidx+1];
463
464         /* Get outer coordinate index */
465         inr              = iinr[iidx];
466         i_coord_offset   = DIM*inr;
467
468         /* Load i particle coords and add shift vector */
469         gmx_mm256_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
470
471         fix0             = _mm256_setzero_ps();
472         fiy0             = _mm256_setzero_ps();
473         fiz0             = _mm256_setzero_ps();
474
475         /* Load parameters for i particles */
476         iq0              = _mm256_mul_ps(facel,_mm256_set1_ps(charge[inr+0]));
477
478         /* Start inner kernel loop */
479         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+7]>=0; jidx+=8)
480         {
481
482             /* Get j neighbor index, and coordinate index */
483             jnrA             = jjnr[jidx];
484             jnrB             = jjnr[jidx+1];
485             jnrC             = jjnr[jidx+2];
486             jnrD             = jjnr[jidx+3];
487             jnrE             = jjnr[jidx+4];
488             jnrF             = jjnr[jidx+5];
489             jnrG             = jjnr[jidx+6];
490             jnrH             = jjnr[jidx+7];
491             j_coord_offsetA  = DIM*jnrA;
492             j_coord_offsetB  = DIM*jnrB;
493             j_coord_offsetC  = DIM*jnrC;
494             j_coord_offsetD  = DIM*jnrD;
495             j_coord_offsetE  = DIM*jnrE;
496             j_coord_offsetF  = DIM*jnrF;
497             j_coord_offsetG  = DIM*jnrG;
498             j_coord_offsetH  = DIM*jnrH;
499
500             /* load j atom coordinates */
501             gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
502                                                  x+j_coord_offsetC,x+j_coord_offsetD,
503                                                  x+j_coord_offsetE,x+j_coord_offsetF,
504                                                  x+j_coord_offsetG,x+j_coord_offsetH,
505                                                  &jx0,&jy0,&jz0);
506
507             /* Calculate displacement vector */
508             dx00             = _mm256_sub_ps(ix0,jx0);
509             dy00             = _mm256_sub_ps(iy0,jy0);
510             dz00             = _mm256_sub_ps(iz0,jz0);
511
512             /* Calculate squared distance and things based on it */
513             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
514
515             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
516
517             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
518
519             /* Load parameters for j particles */
520             jq0              = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
521                                                                  charge+jnrC+0,charge+jnrD+0,
522                                                                  charge+jnrE+0,charge+jnrF+0,
523                                                                  charge+jnrG+0,charge+jnrH+0);
524
525             /**************************
526              * CALCULATE INTERACTIONS *
527              **************************/
528
529             /* Compute parameters for interactions between i and j atoms */
530             qq00             = _mm256_mul_ps(iq0,jq0);
531
532             /* REACTION-FIELD ELECTROSTATICS */
533             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
534
535             fscal            = felec;
536
537             /* Calculate temporary vectorial force */
538             tx               = _mm256_mul_ps(fscal,dx00);
539             ty               = _mm256_mul_ps(fscal,dy00);
540             tz               = _mm256_mul_ps(fscal,dz00);
541
542             /* Update vectorial force */
543             fix0             = _mm256_add_ps(fix0,tx);
544             fiy0             = _mm256_add_ps(fiy0,ty);
545             fiz0             = _mm256_add_ps(fiz0,tz);
546
547             fjptrA             = f+j_coord_offsetA;
548             fjptrB             = f+j_coord_offsetB;
549             fjptrC             = f+j_coord_offsetC;
550             fjptrD             = f+j_coord_offsetD;
551             fjptrE             = f+j_coord_offsetE;
552             fjptrF             = f+j_coord_offsetF;
553             fjptrG             = f+j_coord_offsetG;
554             fjptrH             = f+j_coord_offsetH;
555             gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
556
557             /* Inner loop uses 27 flops */
558         }
559
560         if(jidx<j_index_end)
561         {
562
563             /* Get j neighbor index, and coordinate index */
564             jnrlistA         = jjnr[jidx];
565             jnrlistB         = jjnr[jidx+1];
566             jnrlistC         = jjnr[jidx+2];
567             jnrlistD         = jjnr[jidx+3];
568             jnrlistE         = jjnr[jidx+4];
569             jnrlistF         = jjnr[jidx+5];
570             jnrlistG         = jjnr[jidx+6];
571             jnrlistH         = jjnr[jidx+7];
572             /* Sign of each element will be negative for non-real atoms.
573              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
574              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
575              */
576             dummy_mask = gmx_mm256_set_m128(gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx+4)),_mm_setzero_si128())),
577                                             gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128())));
578                                             
579             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
580             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
581             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
582             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
583             jnrE       = (jnrlistE>=0) ? jnrlistE : 0;
584             jnrF       = (jnrlistF>=0) ? jnrlistF : 0;
585             jnrG       = (jnrlistG>=0) ? jnrlistG : 0;
586             jnrH       = (jnrlistH>=0) ? jnrlistH : 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             j_coord_offsetE  = DIM*jnrE;
592             j_coord_offsetF  = DIM*jnrF;
593             j_coord_offsetG  = DIM*jnrG;
594             j_coord_offsetH  = DIM*jnrH;
595
596             /* load j atom coordinates */
597             gmx_mm256_load_1rvec_8ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
598                                                  x+j_coord_offsetC,x+j_coord_offsetD,
599                                                  x+j_coord_offsetE,x+j_coord_offsetF,
600                                                  x+j_coord_offsetG,x+j_coord_offsetH,
601                                                  &jx0,&jy0,&jz0);
602
603             /* Calculate displacement vector */
604             dx00             = _mm256_sub_ps(ix0,jx0);
605             dy00             = _mm256_sub_ps(iy0,jy0);
606             dz00             = _mm256_sub_ps(iz0,jz0);
607
608             /* Calculate squared distance and things based on it */
609             rsq00            = gmx_mm256_calc_rsq_ps(dx00,dy00,dz00);
610
611             rinv00           = gmx_mm256_invsqrt_ps(rsq00);
612
613             rinvsq00         = _mm256_mul_ps(rinv00,rinv00);
614
615             /* Load parameters for j particles */
616             jq0              = gmx_mm256_load_8real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
617                                                                  charge+jnrC+0,charge+jnrD+0,
618                                                                  charge+jnrE+0,charge+jnrF+0,
619                                                                  charge+jnrG+0,charge+jnrH+0);
620
621             /**************************
622              * CALCULATE INTERACTIONS *
623              **************************/
624
625             /* Compute parameters for interactions between i and j atoms */
626             qq00             = _mm256_mul_ps(iq0,jq0);
627
628             /* REACTION-FIELD ELECTROSTATICS */
629             felec            = _mm256_mul_ps(qq00,_mm256_sub_ps(_mm256_mul_ps(rinv00,rinvsq00),krf2));
630
631             fscal            = felec;
632
633             fscal            = _mm256_andnot_ps(dummy_mask,fscal);
634
635             /* Calculate temporary vectorial force */
636             tx               = _mm256_mul_ps(fscal,dx00);
637             ty               = _mm256_mul_ps(fscal,dy00);
638             tz               = _mm256_mul_ps(fscal,dz00);
639
640             /* Update vectorial force */
641             fix0             = _mm256_add_ps(fix0,tx);
642             fiy0             = _mm256_add_ps(fiy0,ty);
643             fiz0             = _mm256_add_ps(fiz0,tz);
644
645             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
646             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
647             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
648             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
649             fjptrE             = (jnrlistE>=0) ? f+j_coord_offsetE : scratch;
650             fjptrF             = (jnrlistF>=0) ? f+j_coord_offsetF : scratch;
651             fjptrG             = (jnrlistG>=0) ? f+j_coord_offsetG : scratch;
652             fjptrH             = (jnrlistH>=0) ? f+j_coord_offsetH : scratch;
653             gmx_mm256_decrement_1rvec_8ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjptrE,fjptrF,fjptrG,fjptrH,tx,ty,tz);
654
655             /* Inner loop uses 27 flops */
656         }
657
658         /* End of innermost loop */
659
660         gmx_mm256_update_iforce_1atom_swizzle_ps(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*27);
675 }