Introduce gmxpre.h for truly global definitions
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse4_1_single / nb_kernel_ElecEw_VdwNone_GeomP1P1_sse4_1_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 sse4_1_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_sse4_1_single.h"
50 #include "kernelutil_x86_sse4_1_single.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_sse4_1_single
54  * Electrostatics interaction: Ewald
55  * VdW interaction:            None
56  * Geometry:                   Particle-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecEw_VdwNone_GeomP1P1_VF_sse4_1_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 SSE, 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           tx,ty,tz,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     __m128i          ewitab;
93     __m128           ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
94     real             *ewtab;
95     __m128           dummy_mask,cutoff_mask;
96     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
97     __m128           one     = _mm_set1_ps(1.0);
98     __m128           two     = _mm_set1_ps(2.0);
99     x                = xx[0];
100     f                = ff[0];
101
102     nri              = nlist->nri;
103     iinr             = nlist->iinr;
104     jindex           = nlist->jindex;
105     jjnr             = nlist->jjnr;
106     shiftidx         = nlist->shift;
107     gid              = nlist->gid;
108     shiftvec         = fr->shift_vec[0];
109     fshift           = fr->fshift[0];
110     facel            = _mm_set1_ps(fr->epsfac);
111     charge           = mdatoms->chargeA;
112
113     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
114     ewtab            = fr->ic->tabq_coul_FDV0;
115     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
116     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
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             r00              = _mm_mul_ps(rsq00,rinv00);
200
201             /* Compute parameters for interactions between i and j atoms */
202             qq00             = _mm_mul_ps(iq0,jq0);
203
204             /* EWALD ELECTROSTATICS */
205
206             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
207             ewrt             = _mm_mul_ps(r00,ewtabscale);
208             ewitab           = _mm_cvttps_epi32(ewrt);
209             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
210             ewitab           = _mm_slli_epi32(ewitab,2);
211             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
212             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
213             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
214             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
215             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
216             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
217             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
218             velec            = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
219             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
220
221             /* Update potential sum for this i atom from the interaction with this j atom. */
222             velecsum         = _mm_add_ps(velecsum,velec);
223
224             fscal            = felec;
225
226             /* Calculate temporary vectorial force */
227             tx               = _mm_mul_ps(fscal,dx00);
228             ty               = _mm_mul_ps(fscal,dy00);
229             tz               = _mm_mul_ps(fscal,dz00);
230
231             /* Update vectorial force */
232             fix0             = _mm_add_ps(fix0,tx);
233             fiy0             = _mm_add_ps(fiy0,ty);
234             fiz0             = _mm_add_ps(fiz0,tz);
235
236             fjptrA             = f+j_coord_offsetA;
237             fjptrB             = f+j_coord_offsetB;
238             fjptrC             = f+j_coord_offsetC;
239             fjptrD             = f+j_coord_offsetD;
240             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
241
242             /* Inner loop uses 41 flops */
243         }
244
245         if(jidx<j_index_end)
246         {
247
248             /* Get j neighbor index, and coordinate index */
249             jnrlistA         = jjnr[jidx];
250             jnrlistB         = jjnr[jidx+1];
251             jnrlistC         = jjnr[jidx+2];
252             jnrlistD         = jjnr[jidx+3];
253             /* Sign of each element will be negative for non-real atoms.
254              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
255              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
256              */
257             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
258             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
259             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
260             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
261             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
262             j_coord_offsetA  = DIM*jnrA;
263             j_coord_offsetB  = DIM*jnrB;
264             j_coord_offsetC  = DIM*jnrC;
265             j_coord_offsetD  = DIM*jnrD;
266
267             /* load j atom coordinates */
268             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
269                                               x+j_coord_offsetC,x+j_coord_offsetD,
270                                               &jx0,&jy0,&jz0);
271
272             /* Calculate displacement vector */
273             dx00             = _mm_sub_ps(ix0,jx0);
274             dy00             = _mm_sub_ps(iy0,jy0);
275             dz00             = _mm_sub_ps(iz0,jz0);
276
277             /* Calculate squared distance and things based on it */
278             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
279
280             rinv00           = gmx_mm_invsqrt_ps(rsq00);
281
282             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
283
284             /* Load parameters for j particles */
285             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
286                                                               charge+jnrC+0,charge+jnrD+0);
287
288             /**************************
289              * CALCULATE INTERACTIONS *
290              **************************/
291
292             r00              = _mm_mul_ps(rsq00,rinv00);
293             r00              = _mm_andnot_ps(dummy_mask,r00);
294
295             /* Compute parameters for interactions between i and j atoms */
296             qq00             = _mm_mul_ps(iq0,jq0);
297
298             /* EWALD ELECTROSTATICS */
299
300             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
301             ewrt             = _mm_mul_ps(r00,ewtabscale);
302             ewitab           = _mm_cvttps_epi32(ewrt);
303             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
304             ewitab           = _mm_slli_epi32(ewitab,2);
305             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
306             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
307             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
308             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
309             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
310             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
311             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
312             velec            = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
313             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
314
315             /* Update potential sum for this i atom from the interaction with this j atom. */
316             velec            = _mm_andnot_ps(dummy_mask,velec);
317             velecsum         = _mm_add_ps(velecsum,velec);
318
319             fscal            = felec;
320
321             fscal            = _mm_andnot_ps(dummy_mask,fscal);
322
323             /* Calculate temporary vectorial force */
324             tx               = _mm_mul_ps(fscal,dx00);
325             ty               = _mm_mul_ps(fscal,dy00);
326             tz               = _mm_mul_ps(fscal,dz00);
327
328             /* Update vectorial force */
329             fix0             = _mm_add_ps(fix0,tx);
330             fiy0             = _mm_add_ps(fiy0,ty);
331             fiz0             = _mm_add_ps(fiz0,tz);
332
333             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
334             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
335             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
336             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
337             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
338
339             /* Inner loop uses 42 flops */
340         }
341
342         /* End of innermost loop */
343
344         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
345                                               f+i_coord_offset,fshift+i_shift_offset);
346
347         ggid                        = gid[iidx];
348         /* Update potential energies */
349         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
350
351         /* Increment number of inner iterations */
352         inneriter                  += j_index_end - j_index_start;
353
354         /* Outer loop uses 8 flops */
355     }
356
357     /* Increment number of outer iterations */
358     outeriter        += nri;
359
360     /* Update outer/inner flops */
361
362     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VF,outeriter*8 + inneriter*42);
363 }
364 /*
365  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwNone_GeomP1P1_F_sse4_1_single
366  * Electrostatics interaction: Ewald
367  * VdW interaction:            None
368  * Geometry:                   Particle-Particle
369  * Calculate force/pot:        Force
370  */
371 void
372 nb_kernel_ElecEw_VdwNone_GeomP1P1_F_sse4_1_single
373                     (t_nblist                    * gmx_restrict       nlist,
374                      rvec                        * gmx_restrict          xx,
375                      rvec                        * gmx_restrict          ff,
376                      t_forcerec                  * gmx_restrict          fr,
377                      t_mdatoms                   * gmx_restrict     mdatoms,
378                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
379                      t_nrnb                      * gmx_restrict        nrnb)
380 {
381     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
382      * just 0 for non-waters.
383      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
384      * jnr indices corresponding to data put in the four positions in the SIMD register.
385      */
386     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
387     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
388     int              jnrA,jnrB,jnrC,jnrD;
389     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
390     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
391     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
392     real             rcutoff_scalar;
393     real             *shiftvec,*fshift,*x,*f;
394     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
395     real             scratch[4*DIM];
396     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
397     int              vdwioffset0;
398     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
399     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
400     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
401     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
402     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
403     real             *charge;
404     __m128i          ewitab;
405     __m128           ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
406     real             *ewtab;
407     __m128           dummy_mask,cutoff_mask;
408     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
409     __m128           one     = _mm_set1_ps(1.0);
410     __m128           two     = _mm_set1_ps(2.0);
411     x                = xx[0];
412     f                = ff[0];
413
414     nri              = nlist->nri;
415     iinr             = nlist->iinr;
416     jindex           = nlist->jindex;
417     jjnr             = nlist->jjnr;
418     shiftidx         = nlist->shift;
419     gid              = nlist->gid;
420     shiftvec         = fr->shift_vec[0];
421     fshift           = fr->fshift[0];
422     facel            = _mm_set1_ps(fr->epsfac);
423     charge           = mdatoms->chargeA;
424
425     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
426     ewtab            = fr->ic->tabq_coul_F;
427     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
428     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
429
430     /* Avoid stupid compiler warnings */
431     jnrA = jnrB = jnrC = jnrD = 0;
432     j_coord_offsetA = 0;
433     j_coord_offsetB = 0;
434     j_coord_offsetC = 0;
435     j_coord_offsetD = 0;
436
437     outeriter        = 0;
438     inneriter        = 0;
439
440     for(iidx=0;iidx<4*DIM;iidx++)
441     {
442         scratch[iidx] = 0.0;
443     }
444
445     /* Start outer loop over neighborlists */
446     for(iidx=0; iidx<nri; iidx++)
447     {
448         /* Load shift vector for this list */
449         i_shift_offset   = DIM*shiftidx[iidx];
450
451         /* Load limits for loop over neighbors */
452         j_index_start    = jindex[iidx];
453         j_index_end      = jindex[iidx+1];
454
455         /* Get outer coordinate index */
456         inr              = iinr[iidx];
457         i_coord_offset   = DIM*inr;
458
459         /* Load i particle coords and add shift vector */
460         gmx_mm_load_shift_and_1rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
461
462         fix0             = _mm_setzero_ps();
463         fiy0             = _mm_setzero_ps();
464         fiz0             = _mm_setzero_ps();
465
466         /* Load parameters for i particles */
467         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
468
469         /* Start inner kernel loop */
470         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
471         {
472
473             /* Get j neighbor index, and coordinate index */
474             jnrA             = jjnr[jidx];
475             jnrB             = jjnr[jidx+1];
476             jnrC             = jjnr[jidx+2];
477             jnrD             = jjnr[jidx+3];
478             j_coord_offsetA  = DIM*jnrA;
479             j_coord_offsetB  = DIM*jnrB;
480             j_coord_offsetC  = DIM*jnrC;
481             j_coord_offsetD  = DIM*jnrD;
482
483             /* load j atom coordinates */
484             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
485                                               x+j_coord_offsetC,x+j_coord_offsetD,
486                                               &jx0,&jy0,&jz0);
487
488             /* Calculate displacement vector */
489             dx00             = _mm_sub_ps(ix0,jx0);
490             dy00             = _mm_sub_ps(iy0,jy0);
491             dz00             = _mm_sub_ps(iz0,jz0);
492
493             /* Calculate squared distance and things based on it */
494             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
495
496             rinv00           = gmx_mm_invsqrt_ps(rsq00);
497
498             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
499
500             /* Load parameters for j particles */
501             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
502                                                               charge+jnrC+0,charge+jnrD+0);
503
504             /**************************
505              * CALCULATE INTERACTIONS *
506              **************************/
507
508             r00              = _mm_mul_ps(rsq00,rinv00);
509
510             /* Compute parameters for interactions between i and j atoms */
511             qq00             = _mm_mul_ps(iq0,jq0);
512
513             /* EWALD ELECTROSTATICS */
514
515             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
516             ewrt             = _mm_mul_ps(r00,ewtabscale);
517             ewitab           = _mm_cvttps_epi32(ewrt);
518             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
519             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
520                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
521                                          &ewtabF,&ewtabFn);
522             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
523             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
524
525             fscal            = felec;
526
527             /* Calculate temporary vectorial force */
528             tx               = _mm_mul_ps(fscal,dx00);
529             ty               = _mm_mul_ps(fscal,dy00);
530             tz               = _mm_mul_ps(fscal,dz00);
531
532             /* Update vectorial force */
533             fix0             = _mm_add_ps(fix0,tx);
534             fiy0             = _mm_add_ps(fiy0,ty);
535             fiz0             = _mm_add_ps(fiz0,tz);
536
537             fjptrA             = f+j_coord_offsetA;
538             fjptrB             = f+j_coord_offsetB;
539             fjptrC             = f+j_coord_offsetC;
540             fjptrD             = f+j_coord_offsetD;
541             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
542
543             /* Inner loop uses 36 flops */
544         }
545
546         if(jidx<j_index_end)
547         {
548
549             /* Get j neighbor index, and coordinate index */
550             jnrlistA         = jjnr[jidx];
551             jnrlistB         = jjnr[jidx+1];
552             jnrlistC         = jjnr[jidx+2];
553             jnrlistD         = jjnr[jidx+3];
554             /* Sign of each element will be negative for non-real atoms.
555              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
556              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
557              */
558             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
559             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
560             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
561             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
562             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
563             j_coord_offsetA  = DIM*jnrA;
564             j_coord_offsetB  = DIM*jnrB;
565             j_coord_offsetC  = DIM*jnrC;
566             j_coord_offsetD  = DIM*jnrD;
567
568             /* load j atom coordinates */
569             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
570                                               x+j_coord_offsetC,x+j_coord_offsetD,
571                                               &jx0,&jy0,&jz0);
572
573             /* Calculate displacement vector */
574             dx00             = _mm_sub_ps(ix0,jx0);
575             dy00             = _mm_sub_ps(iy0,jy0);
576             dz00             = _mm_sub_ps(iz0,jz0);
577
578             /* Calculate squared distance and things based on it */
579             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
580
581             rinv00           = gmx_mm_invsqrt_ps(rsq00);
582
583             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
584
585             /* Load parameters for j particles */
586             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
587                                                               charge+jnrC+0,charge+jnrD+0);
588
589             /**************************
590              * CALCULATE INTERACTIONS *
591              **************************/
592
593             r00              = _mm_mul_ps(rsq00,rinv00);
594             r00              = _mm_andnot_ps(dummy_mask,r00);
595
596             /* Compute parameters for interactions between i and j atoms */
597             qq00             = _mm_mul_ps(iq0,jq0);
598
599             /* EWALD ELECTROSTATICS */
600
601             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
602             ewrt             = _mm_mul_ps(r00,ewtabscale);
603             ewitab           = _mm_cvttps_epi32(ewrt);
604             eweps            = _mm_sub_ps(ewrt,_mm_round_ps(ewrt, _MM_FROUND_FLOOR));
605             gmx_mm_load_4pair_swizzle_ps(ewtab + gmx_mm_extract_epi32(ewitab,0),ewtab + gmx_mm_extract_epi32(ewitab,1),
606                                          ewtab + gmx_mm_extract_epi32(ewitab,2),ewtab + gmx_mm_extract_epi32(ewitab,3),
607                                          &ewtabF,&ewtabFn);
608             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
609             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
610
611             fscal            = felec;
612
613             fscal            = _mm_andnot_ps(dummy_mask,fscal);
614
615             /* Calculate temporary vectorial force */
616             tx               = _mm_mul_ps(fscal,dx00);
617             ty               = _mm_mul_ps(fscal,dy00);
618             tz               = _mm_mul_ps(fscal,dz00);
619
620             /* Update vectorial force */
621             fix0             = _mm_add_ps(fix0,tx);
622             fiy0             = _mm_add_ps(fiy0,ty);
623             fiz0             = _mm_add_ps(fiz0,tz);
624
625             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
626             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
627             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
628             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
629             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,tx,ty,tz);
630
631             /* Inner loop uses 37 flops */
632         }
633
634         /* End of innermost loop */
635
636         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
637                                               f+i_coord_offset,fshift+i_shift_offset);
638
639         /* Increment number of inner iterations */
640         inneriter                  += j_index_end - j_index_start;
641
642         /* Outer loop uses 7 flops */
643     }
644
645     /* Increment number of outer iterations */
646     outeriter        += nri;
647
648     /* Update outer/inner flops */
649
650     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_F,outeriter*7 + inneriter*37);
651 }