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