Merge release-5-0 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRFCut_VdwNone_GeomP1P1_avx_128_fma_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_128_fma_single kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/legacyheaders/types/simple.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/legacyheaders/nrnb.h"
48
49 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
50 #include "kernelutil_x86_avx_128_fma_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_single
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            None
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_VF_avx_128_fma_single
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_128, 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              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
79     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
80     real             rcutoff_scalar;
81     real             *shiftvec,*fshift,*x,*f;
82     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
83     real             scratch[4*DIM];
84     __m128           fscal,rcutoff,rcutoff2,jidxall;
85     int              vdwioffset0;
86     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
87     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
88     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
91     real             *charge;
92     __m128           dummy_mask,cutoff_mask;
93     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
94     __m128           one     = _mm_set1_ps(1.0);
95     __m128           two     = _mm_set1_ps(2.0);
96     x                = xx[0];
97     f                = ff[0];
98
99     nri              = nlist->nri;
100     iinr             = nlist->iinr;
101     jindex           = nlist->jindex;
102     jjnr             = nlist->jjnr;
103     shiftidx         = nlist->shift;
104     gid              = nlist->gid;
105     shiftvec         = fr->shift_vec[0];
106     fshift           = fr->fshift[0];
107     facel            = _mm_set1_ps(fr->epsfac);
108     charge           = mdatoms->chargeA;
109     krf              = _mm_set1_ps(fr->ic->k_rf);
110     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
111     crf              = _mm_set1_ps(fr->ic->c_rf);
112
113     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
114     rcutoff_scalar   = fr->rcoulomb;
115     rcutoff          = _mm_set1_ps(rcutoff_scalar);
116     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
117
118     /* Avoid stupid compiler warnings */
119     jnrA = jnrB = jnrC = jnrD = 0;
120     j_coord_offsetA = 0;
121     j_coord_offsetB = 0;
122     j_coord_offsetC = 0;
123     j_coord_offsetD = 0;
124
125     outeriter        = 0;
126     inneriter        = 0;
127
128     for(iidx=0;iidx<4*DIM;iidx++)
129     {
130         scratch[iidx] = 0.0;
131     }
132
133     /* Start outer loop over neighborlists */
134     for(iidx=0; iidx<nri; iidx++)
135     {
136         /* Load shift vector for this list */
137         i_shift_offset   = DIM*shiftidx[iidx];
138
139         /* Load limits for loop over neighbors */
140         j_index_start    = jindex[iidx];
141         j_index_end      = jindex[iidx+1];
142
143         /* Get outer coordinate index */
144         inr              = iinr[iidx];
145         i_coord_offset   = DIM*inr;
146
147         /* Load i particle coords and add shift vector */
148         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
149
150         fix0             = _mm_setzero_ps();
151         fiy0             = _mm_setzero_ps();
152         fiz0             = _mm_setzero_ps();
153
154         /* Load parameters for i particles */
155         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
156
157         /* Reset potential sums */
158         velecsum         = _mm_setzero_ps();
159
160         /* Start inner kernel loop */
161         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
162         {
163
164             /* Get j neighbor index, and coordinate index */
165             jnrA             = jjnr[jidx];
166             jnrB             = jjnr[jidx+1];
167             jnrC             = jjnr[jidx+2];
168             jnrD             = jjnr[jidx+3];
169             j_coord_offsetA  = DIM*jnrA;
170             j_coord_offsetB  = DIM*jnrB;
171             j_coord_offsetC  = DIM*jnrC;
172             j_coord_offsetD  = DIM*jnrD;
173
174             /* load j atom coordinates */
175             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
176                                               x+j_coord_offsetC,x+j_coord_offsetD,
177                                               &jx0,&jy0,&jz0);
178
179             /* Calculate displacement vector */
180             dx00             = _mm_sub_ps(ix0,jx0);
181             dy00             = _mm_sub_ps(iy0,jy0);
182             dz00             = _mm_sub_ps(iz0,jz0);
183
184             /* Calculate squared distance and things based on it */
185             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
186
187             rinv00           = gmx_mm_invsqrt_ps(rsq00);
188
189             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
190
191             /* Load parameters for j particles */
192             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
193                                                               charge+jnrC+0,charge+jnrD+0);
194
195             /**************************
196              * CALCULATE INTERACTIONS *
197              **************************/
198
199             if (gmx_mm_any_lt(rsq00,rcutoff2))
200             {
201
202             /* Compute parameters for interactions between i and j atoms */
203             qq00             = _mm_mul_ps(iq0,jq0);
204
205             /* REACTION-FIELD ELECTROSTATICS */
206             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
207             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
208
209             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
210
211             /* Update potential sum for this i atom from the interaction with this j atom. */
212             velec            = _mm_and_ps(velec,cutoff_mask);
213             velecsum         = _mm_add_ps(velecsum,velec);
214
215             fscal            = felec;
216
217             fscal            = _mm_and_ps(fscal,cutoff_mask);
218
219              /* Update vectorial force */
220             fix0             = _mm_macc_ps(dx00,fscal,fix0);
221             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
222             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
223
224             fjptrA             = f+j_coord_offsetA;
225             fjptrB             = f+j_coord_offsetB;
226             fjptrC             = f+j_coord_offsetC;
227             fjptrD             = f+j_coord_offsetD;
228             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
229                                                    _mm_mul_ps(dx00,fscal),
230                                                    _mm_mul_ps(dy00,fscal),
231                                                    _mm_mul_ps(dz00,fscal));
232
233             }
234
235             /* Inner loop uses 39 flops */
236         }
237
238         if(jidx<j_index_end)
239         {
240
241             /* Get j neighbor index, and coordinate index */
242             jnrlistA         = jjnr[jidx];
243             jnrlistB         = jjnr[jidx+1];
244             jnrlistC         = jjnr[jidx+2];
245             jnrlistD         = jjnr[jidx+3];
246             /* Sign of each element will be negative for non-real atoms.
247              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
248              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
249              */
250             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
251             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
252             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
253             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
254             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
255             j_coord_offsetA  = DIM*jnrA;
256             j_coord_offsetB  = DIM*jnrB;
257             j_coord_offsetC  = DIM*jnrC;
258             j_coord_offsetD  = DIM*jnrD;
259
260             /* load j atom coordinates */
261             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
262                                               x+j_coord_offsetC,x+j_coord_offsetD,
263                                               &jx0,&jy0,&jz0);
264
265             /* Calculate displacement vector */
266             dx00             = _mm_sub_ps(ix0,jx0);
267             dy00             = _mm_sub_ps(iy0,jy0);
268             dz00             = _mm_sub_ps(iz0,jz0);
269
270             /* Calculate squared distance and things based on it */
271             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
272
273             rinv00           = gmx_mm_invsqrt_ps(rsq00);
274
275             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
276
277             /* Load parameters for j particles */
278             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
279                                                               charge+jnrC+0,charge+jnrD+0);
280
281             /**************************
282              * CALCULATE INTERACTIONS *
283              **************************/
284
285             if (gmx_mm_any_lt(rsq00,rcutoff2))
286             {
287
288             /* Compute parameters for interactions between i and j atoms */
289             qq00             = _mm_mul_ps(iq0,jq0);
290
291             /* REACTION-FIELD ELECTROSTATICS */
292             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
293             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
294
295             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
296
297             /* Update potential sum for this i atom from the interaction with this j atom. */
298             velec            = _mm_and_ps(velec,cutoff_mask);
299             velec            = _mm_andnot_ps(dummy_mask,velec);
300             velecsum         = _mm_add_ps(velecsum,velec);
301
302             fscal            = felec;
303
304             fscal            = _mm_and_ps(fscal,cutoff_mask);
305
306             fscal            = _mm_andnot_ps(dummy_mask,fscal);
307
308              /* Update vectorial force */
309             fix0             = _mm_macc_ps(dx00,fscal,fix0);
310             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
311             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
312
313             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
314             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
315             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
316             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
317             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
318                                                    _mm_mul_ps(dx00,fscal),
319                                                    _mm_mul_ps(dy00,fscal),
320                                                    _mm_mul_ps(dz00,fscal));
321
322             }
323
324             /* Inner loop uses 39 flops */
325         }
326
327         /* End of innermost loop */
328
329         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
330                                               f+i_coord_offset,fshift+i_shift_offset);
331
332         ggid                        = gid[iidx];
333         /* Update potential energies */
334         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
335
336         /* Increment number of inner iterations */
337         inneriter                  += j_index_end - j_index_start;
338
339         /* Outer loop uses 8 flops */
340     }
341
342     /* Increment number of outer iterations */
343     outeriter        += nri;
344
345     /* Update outer/inner flops */
346
347     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*39);
348 }
349 /*
350  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_single
351  * Electrostatics interaction: ReactionField
352  * VdW interaction:            None
353  * Geometry:                   Particle-Particle
354  * Calculate force/pot:        Force
355  */
356 void
357 nb_kernel_ElecRFCut_VdwNone_GeomP1P1_F_avx_128_fma_single
358                     (t_nblist                    * gmx_restrict       nlist,
359                      rvec                        * gmx_restrict          xx,
360                      rvec                        * gmx_restrict          ff,
361                      t_forcerec                  * gmx_restrict          fr,
362                      t_mdatoms                   * gmx_restrict     mdatoms,
363                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
364                      t_nrnb                      * gmx_restrict        nrnb)
365 {
366     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
367      * just 0 for non-waters.
368      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
369      * jnr indices corresponding to data put in the four positions in the SIMD register.
370      */
371     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
372     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
373     int              jnrA,jnrB,jnrC,jnrD;
374     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
375     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
376     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
377     real             rcutoff_scalar;
378     real             *shiftvec,*fshift,*x,*f;
379     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
380     real             scratch[4*DIM];
381     __m128           fscal,rcutoff,rcutoff2,jidxall;
382     int              vdwioffset0;
383     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
384     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
385     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
386     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
387     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
388     real             *charge;
389     __m128           dummy_mask,cutoff_mask;
390     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
391     __m128           one     = _mm_set1_ps(1.0);
392     __m128           two     = _mm_set1_ps(2.0);
393     x                = xx[0];
394     f                = ff[0];
395
396     nri              = nlist->nri;
397     iinr             = nlist->iinr;
398     jindex           = nlist->jindex;
399     jjnr             = nlist->jjnr;
400     shiftidx         = nlist->shift;
401     gid              = nlist->gid;
402     shiftvec         = fr->shift_vec[0];
403     fshift           = fr->fshift[0];
404     facel            = _mm_set1_ps(fr->epsfac);
405     charge           = mdatoms->chargeA;
406     krf              = _mm_set1_ps(fr->ic->k_rf);
407     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
408     crf              = _mm_set1_ps(fr->ic->c_rf);
409
410     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
411     rcutoff_scalar   = fr->rcoulomb;
412     rcutoff          = _mm_set1_ps(rcutoff_scalar);
413     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
414
415     /* Avoid stupid compiler warnings */
416     jnrA = jnrB = jnrC = jnrD = 0;
417     j_coord_offsetA = 0;
418     j_coord_offsetB = 0;
419     j_coord_offsetC = 0;
420     j_coord_offsetD = 0;
421
422     outeriter        = 0;
423     inneriter        = 0;
424
425     for(iidx=0;iidx<4*DIM;iidx++)
426     {
427         scratch[iidx] = 0.0;
428     }
429
430     /* Start outer loop over neighborlists */
431     for(iidx=0; iidx<nri; iidx++)
432     {
433         /* Load shift vector for this list */
434         i_shift_offset   = DIM*shiftidx[iidx];
435
436         /* Load limits for loop over neighbors */
437         j_index_start    = jindex[iidx];
438         j_index_end      = jindex[iidx+1];
439
440         /* Get outer coordinate index */
441         inr              = iinr[iidx];
442         i_coord_offset   = DIM*inr;
443
444         /* Load i particle coords and add shift vector */
445         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
446
447         fix0             = _mm_setzero_ps();
448         fiy0             = _mm_setzero_ps();
449         fiz0             = _mm_setzero_ps();
450
451         /* Load parameters for i particles */
452         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
453
454         /* Start inner kernel loop */
455         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
456         {
457
458             /* Get j neighbor index, and coordinate index */
459             jnrA             = jjnr[jidx];
460             jnrB             = jjnr[jidx+1];
461             jnrC             = jjnr[jidx+2];
462             jnrD             = jjnr[jidx+3];
463             j_coord_offsetA  = DIM*jnrA;
464             j_coord_offsetB  = DIM*jnrB;
465             j_coord_offsetC  = DIM*jnrC;
466             j_coord_offsetD  = DIM*jnrD;
467
468             /* load j atom coordinates */
469             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
470                                               x+j_coord_offsetC,x+j_coord_offsetD,
471                                               &jx0,&jy0,&jz0);
472
473             /* Calculate displacement vector */
474             dx00             = _mm_sub_ps(ix0,jx0);
475             dy00             = _mm_sub_ps(iy0,jy0);
476             dz00             = _mm_sub_ps(iz0,jz0);
477
478             /* Calculate squared distance and things based on it */
479             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
480
481             rinv00           = gmx_mm_invsqrt_ps(rsq00);
482
483             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
484
485             /* Load parameters for j particles */
486             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
487                                                               charge+jnrC+0,charge+jnrD+0);
488
489             /**************************
490              * CALCULATE INTERACTIONS *
491              **************************/
492
493             if (gmx_mm_any_lt(rsq00,rcutoff2))
494             {
495
496             /* Compute parameters for interactions between i and j atoms */
497             qq00             = _mm_mul_ps(iq0,jq0);
498
499             /* REACTION-FIELD ELECTROSTATICS */
500             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
501
502             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
503
504             fscal            = felec;
505
506             fscal            = _mm_and_ps(fscal,cutoff_mask);
507
508              /* Update vectorial force */
509             fix0             = _mm_macc_ps(dx00,fscal,fix0);
510             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
511             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
512
513             fjptrA             = f+j_coord_offsetA;
514             fjptrB             = f+j_coord_offsetB;
515             fjptrC             = f+j_coord_offsetC;
516             fjptrD             = f+j_coord_offsetD;
517             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
518                                                    _mm_mul_ps(dx00,fscal),
519                                                    _mm_mul_ps(dy00,fscal),
520                                                    _mm_mul_ps(dz00,fscal));
521
522             }
523
524             /* Inner loop uses 33 flops */
525         }
526
527         if(jidx<j_index_end)
528         {
529
530             /* Get j neighbor index, and coordinate index */
531             jnrlistA         = jjnr[jidx];
532             jnrlistB         = jjnr[jidx+1];
533             jnrlistC         = jjnr[jidx+2];
534             jnrlistD         = jjnr[jidx+3];
535             /* Sign of each element will be negative for non-real atoms.
536              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
537              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
538              */
539             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
540             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
541             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
542             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
543             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
544             j_coord_offsetA  = DIM*jnrA;
545             j_coord_offsetB  = DIM*jnrB;
546             j_coord_offsetC  = DIM*jnrC;
547             j_coord_offsetD  = DIM*jnrD;
548
549             /* load j atom coordinates */
550             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
551                                               x+j_coord_offsetC,x+j_coord_offsetD,
552                                               &jx0,&jy0,&jz0);
553
554             /* Calculate displacement vector */
555             dx00             = _mm_sub_ps(ix0,jx0);
556             dy00             = _mm_sub_ps(iy0,jy0);
557             dz00             = _mm_sub_ps(iz0,jz0);
558
559             /* Calculate squared distance and things based on it */
560             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
561
562             rinv00           = gmx_mm_invsqrt_ps(rsq00);
563
564             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
565
566             /* Load parameters for j particles */
567             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
568                                                               charge+jnrC+0,charge+jnrD+0);
569
570             /**************************
571              * CALCULATE INTERACTIONS *
572              **************************/
573
574             if (gmx_mm_any_lt(rsq00,rcutoff2))
575             {
576
577             /* Compute parameters for interactions between i and j atoms */
578             qq00             = _mm_mul_ps(iq0,jq0);
579
580             /* REACTION-FIELD ELECTROSTATICS */
581             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
582
583             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
584
585             fscal            = felec;
586
587             fscal            = _mm_and_ps(fscal,cutoff_mask);
588
589             fscal            = _mm_andnot_ps(dummy_mask,fscal);
590
591              /* Update vectorial force */
592             fix0             = _mm_macc_ps(dx00,fscal,fix0);
593             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
594             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
595
596             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
597             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
598             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
599             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
600             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
601                                                    _mm_mul_ps(dx00,fscal),
602                                                    _mm_mul_ps(dy00,fscal),
603                                                    _mm_mul_ps(dz00,fscal));
604
605             }
606
607             /* Inner loop uses 33 flops */
608         }
609
610         /* End of innermost loop */
611
612         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
613                                               f+i_coord_offset,fshift+i_shift_offset);
614
615         /* Increment number of inner iterations */
616         inneriter                  += j_index_end - j_index_start;
617
618         /* Outer loop uses 7 flops */
619     }
620
621     /* Increment number of outer iterations */
622     outeriter        += nri;
623
624     /* Update outer/inner flops */
625
626     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*33);
627 }