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