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