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