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