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