Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRF_VdwNone_GeomW4W4_avx_128_fma_single.c
1 /*
2  * Note: this file was generated by the Gromacs avx_128_fma_single kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
10  * Gromacs is a library for molecular simulation and trajectory analysis,
11  * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12  * a full list of developers and information, check out http://www.gromacs.org
13  *
14  * This program is free software; you can redistribute it and/or modify it under
15  * the terms of the GNU Lesser General Public License as published by the Free
16  * Software Foundation; either version 2 of the License, or (at your option) any
17  * later version.
18  *
19  * To help fund GROMACS development, we humbly ask that you cite
20  * the papers people have written on it - you can find them on the website.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 #include "gmx_math_x86_avx_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
35
36 /*
37  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwNone_GeomW4W4_VF_avx_128_fma_single
38  * Electrostatics interaction: ReactionField
39  * VdW interaction:            None
40  * Geometry:                   Water4-Water4
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecRF_VdwNone_GeomW4W4_VF_avx_128_fma_single
45                     (t_nblist * gmx_restrict                nlist,
46                      rvec * gmx_restrict                    xx,
47                      rvec * gmx_restrict                    ff,
48                      t_forcerec * gmx_restrict              fr,
49                      t_mdatoms * gmx_restrict               mdatoms,
50                      nb_kernel_data_t * gmx_restrict        kernel_data,
51                      t_nrnb * gmx_restrict                  nrnb)
52 {
53     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54      * just 0 for non-waters.
55      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
56      * jnr indices corresponding to data put in the four positions in the SIMD register.
57      */
58     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
59     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60     int              jnrA,jnrB,jnrC,jnrD;
61     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
64     real             rcutoff_scalar;
65     real             *shiftvec,*fshift,*x,*f;
66     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
67     real             scratch[4*DIM];
68     __m128           fscal,rcutoff,rcutoff2,jidxall;
69     int              vdwioffset1;
70     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
71     int              vdwioffset2;
72     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
73     int              vdwioffset3;
74     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
75     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
76     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
77     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
78     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
79     int              vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
80     __m128           jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
81     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
82     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
83     __m128           dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
84     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
85     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
86     __m128           dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
87     __m128           dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
88     __m128           dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
89     __m128           dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
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     /* Setup water-specific parameters */
114     inr              = nlist->iinr[0];
115     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
116     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
117     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
118
119     jq1              = _mm_set1_ps(charge[inr+1]);
120     jq2              = _mm_set1_ps(charge[inr+2]);
121     jq3              = _mm_set1_ps(charge[inr+3]);
122     qq11             = _mm_mul_ps(iq1,jq1);
123     qq12             = _mm_mul_ps(iq1,jq2);
124     qq13             = _mm_mul_ps(iq1,jq3);
125     qq21             = _mm_mul_ps(iq2,jq1);
126     qq22             = _mm_mul_ps(iq2,jq2);
127     qq23             = _mm_mul_ps(iq2,jq3);
128     qq31             = _mm_mul_ps(iq3,jq1);
129     qq32             = _mm_mul_ps(iq3,jq2);
130     qq33             = _mm_mul_ps(iq3,jq3);
131
132     /* Avoid stupid compiler warnings */
133     jnrA = jnrB = jnrC = jnrD = 0;
134     j_coord_offsetA = 0;
135     j_coord_offsetB = 0;
136     j_coord_offsetC = 0;
137     j_coord_offsetD = 0;
138
139     outeriter        = 0;
140     inneriter        = 0;
141
142     for(iidx=0;iidx<4*DIM;iidx++)
143     {
144         scratch[iidx] = 0.0;
145     }
146
147     /* Start outer loop over neighborlists */
148     for(iidx=0; iidx<nri; iidx++)
149     {
150         /* Load shift vector for this list */
151         i_shift_offset   = DIM*shiftidx[iidx];
152
153         /* Load limits for loop over neighbors */
154         j_index_start    = jindex[iidx];
155         j_index_end      = jindex[iidx+1];
156
157         /* Get outer coordinate index */
158         inr              = iinr[iidx];
159         i_coord_offset   = DIM*inr;
160
161         /* Load i particle coords and add shift vector */
162         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
163                                                  &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
164
165         fix1             = _mm_setzero_ps();
166         fiy1             = _mm_setzero_ps();
167         fiz1             = _mm_setzero_ps();
168         fix2             = _mm_setzero_ps();
169         fiy2             = _mm_setzero_ps();
170         fiz2             = _mm_setzero_ps();
171         fix3             = _mm_setzero_ps();
172         fiy3             = _mm_setzero_ps();
173         fiz3             = _mm_setzero_ps();
174
175         /* Reset potential sums */
176         velecsum         = _mm_setzero_ps();
177
178         /* Start inner kernel loop */
179         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
180         {
181
182             /* Get j neighbor index, and coordinate index */
183             jnrA             = jjnr[jidx];
184             jnrB             = jjnr[jidx+1];
185             jnrC             = jjnr[jidx+2];
186             jnrD             = jjnr[jidx+3];
187             j_coord_offsetA  = DIM*jnrA;
188             j_coord_offsetB  = DIM*jnrB;
189             j_coord_offsetC  = DIM*jnrC;
190             j_coord_offsetD  = DIM*jnrD;
191
192             /* load j atom coordinates */
193             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
194                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
195                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
196
197             /* Calculate displacement vector */
198             dx11             = _mm_sub_ps(ix1,jx1);
199             dy11             = _mm_sub_ps(iy1,jy1);
200             dz11             = _mm_sub_ps(iz1,jz1);
201             dx12             = _mm_sub_ps(ix1,jx2);
202             dy12             = _mm_sub_ps(iy1,jy2);
203             dz12             = _mm_sub_ps(iz1,jz2);
204             dx13             = _mm_sub_ps(ix1,jx3);
205             dy13             = _mm_sub_ps(iy1,jy3);
206             dz13             = _mm_sub_ps(iz1,jz3);
207             dx21             = _mm_sub_ps(ix2,jx1);
208             dy21             = _mm_sub_ps(iy2,jy1);
209             dz21             = _mm_sub_ps(iz2,jz1);
210             dx22             = _mm_sub_ps(ix2,jx2);
211             dy22             = _mm_sub_ps(iy2,jy2);
212             dz22             = _mm_sub_ps(iz2,jz2);
213             dx23             = _mm_sub_ps(ix2,jx3);
214             dy23             = _mm_sub_ps(iy2,jy3);
215             dz23             = _mm_sub_ps(iz2,jz3);
216             dx31             = _mm_sub_ps(ix3,jx1);
217             dy31             = _mm_sub_ps(iy3,jy1);
218             dz31             = _mm_sub_ps(iz3,jz1);
219             dx32             = _mm_sub_ps(ix3,jx2);
220             dy32             = _mm_sub_ps(iy3,jy2);
221             dz32             = _mm_sub_ps(iz3,jz2);
222             dx33             = _mm_sub_ps(ix3,jx3);
223             dy33             = _mm_sub_ps(iy3,jy3);
224             dz33             = _mm_sub_ps(iz3,jz3);
225
226             /* Calculate squared distance and things based on it */
227             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
228             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
229             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
230             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
231             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
232             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
233             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
234             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
235             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
236
237             rinv11           = gmx_mm_invsqrt_ps(rsq11);
238             rinv12           = gmx_mm_invsqrt_ps(rsq12);
239             rinv13           = gmx_mm_invsqrt_ps(rsq13);
240             rinv21           = gmx_mm_invsqrt_ps(rsq21);
241             rinv22           = gmx_mm_invsqrt_ps(rsq22);
242             rinv23           = gmx_mm_invsqrt_ps(rsq23);
243             rinv31           = gmx_mm_invsqrt_ps(rsq31);
244             rinv32           = gmx_mm_invsqrt_ps(rsq32);
245             rinv33           = gmx_mm_invsqrt_ps(rsq33);
246
247             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
248             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
249             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
250             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
251             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
252             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
253             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
254             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
255             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
256
257             fjx1             = _mm_setzero_ps();
258             fjy1             = _mm_setzero_ps();
259             fjz1             = _mm_setzero_ps();
260             fjx2             = _mm_setzero_ps();
261             fjy2             = _mm_setzero_ps();
262             fjz2             = _mm_setzero_ps();
263             fjx3             = _mm_setzero_ps();
264             fjy3             = _mm_setzero_ps();
265             fjz3             = _mm_setzero_ps();
266
267             /**************************
268              * CALCULATE INTERACTIONS *
269              **************************/
270
271             /* REACTION-FIELD ELECTROSTATICS */
272             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
273             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
274
275             /* Update potential sum for this i atom from the interaction with this j atom. */
276             velecsum         = _mm_add_ps(velecsum,velec);
277
278             fscal            = felec;
279
280              /* Update vectorial force */
281             fix1             = _mm_macc_ps(dx11,fscal,fix1);
282             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
283             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
284
285             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
286             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
287             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
288
289             /**************************
290              * CALCULATE INTERACTIONS *
291              **************************/
292
293             /* REACTION-FIELD ELECTROSTATICS */
294             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
295             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
296
297             /* Update potential sum for this i atom from the interaction with this j atom. */
298             velecsum         = _mm_add_ps(velecsum,velec);
299
300             fscal            = felec;
301
302              /* Update vectorial force */
303             fix1             = _mm_macc_ps(dx12,fscal,fix1);
304             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
305             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
306
307             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
308             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
309             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
310
311             /**************************
312              * CALCULATE INTERACTIONS *
313              **************************/
314
315             /* REACTION-FIELD ELECTROSTATICS */
316             velec            = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
317             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
318
319             /* Update potential sum for this i atom from the interaction with this j atom. */
320             velecsum         = _mm_add_ps(velecsum,velec);
321
322             fscal            = felec;
323
324              /* Update vectorial force */
325             fix1             = _mm_macc_ps(dx13,fscal,fix1);
326             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
327             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
328
329             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
330             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
331             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
332
333             /**************************
334              * CALCULATE INTERACTIONS *
335              **************************/
336
337             /* REACTION-FIELD ELECTROSTATICS */
338             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
339             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
340
341             /* Update potential sum for this i atom from the interaction with this j atom. */
342             velecsum         = _mm_add_ps(velecsum,velec);
343
344             fscal            = felec;
345
346              /* Update vectorial force */
347             fix2             = _mm_macc_ps(dx21,fscal,fix2);
348             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
349             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
350
351             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
352             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
353             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
354
355             /**************************
356              * CALCULATE INTERACTIONS *
357              **************************/
358
359             /* REACTION-FIELD ELECTROSTATICS */
360             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
361             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
362
363             /* Update potential sum for this i atom from the interaction with this j atom. */
364             velecsum         = _mm_add_ps(velecsum,velec);
365
366             fscal            = felec;
367
368              /* Update vectorial force */
369             fix2             = _mm_macc_ps(dx22,fscal,fix2);
370             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
371             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
372
373             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
374             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
375             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
376
377             /**************************
378              * CALCULATE INTERACTIONS *
379              **************************/
380
381             /* REACTION-FIELD ELECTROSTATICS */
382             velec            = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
383             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
384
385             /* Update potential sum for this i atom from the interaction with this j atom. */
386             velecsum         = _mm_add_ps(velecsum,velec);
387
388             fscal            = felec;
389
390              /* Update vectorial force */
391             fix2             = _mm_macc_ps(dx23,fscal,fix2);
392             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
393             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
394
395             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
396             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
397             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
398
399             /**************************
400              * CALCULATE INTERACTIONS *
401              **************************/
402
403             /* REACTION-FIELD ELECTROSTATICS */
404             velec            = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
405             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
406
407             /* Update potential sum for this i atom from the interaction with this j atom. */
408             velecsum         = _mm_add_ps(velecsum,velec);
409
410             fscal            = felec;
411
412              /* Update vectorial force */
413             fix3             = _mm_macc_ps(dx31,fscal,fix3);
414             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
415             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
416
417             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
418             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
419             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
420
421             /**************************
422              * CALCULATE INTERACTIONS *
423              **************************/
424
425             /* REACTION-FIELD ELECTROSTATICS */
426             velec            = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
427             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
428
429             /* Update potential sum for this i atom from the interaction with this j atom. */
430             velecsum         = _mm_add_ps(velecsum,velec);
431
432             fscal            = felec;
433
434              /* Update vectorial force */
435             fix3             = _mm_macc_ps(dx32,fscal,fix3);
436             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
437             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
438
439             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
440             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
441             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
442
443             /**************************
444              * CALCULATE INTERACTIONS *
445              **************************/
446
447             /* REACTION-FIELD ELECTROSTATICS */
448             velec            = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
449             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
450
451             /* Update potential sum for this i atom from the interaction with this j atom. */
452             velecsum         = _mm_add_ps(velecsum,velec);
453
454             fscal            = felec;
455
456              /* Update vectorial force */
457             fix3             = _mm_macc_ps(dx33,fscal,fix3);
458             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
459             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
460
461             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
462             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
463             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
464
465             fjptrA             = f+j_coord_offsetA;
466             fjptrB             = f+j_coord_offsetB;
467             fjptrC             = f+j_coord_offsetC;
468             fjptrD             = f+j_coord_offsetD;
469
470             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
471                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
472
473             /* Inner loop uses 315 flops */
474         }
475
476         if(jidx<j_index_end)
477         {
478
479             /* Get j neighbor index, and coordinate index */
480             jnrlistA         = jjnr[jidx];
481             jnrlistB         = jjnr[jidx+1];
482             jnrlistC         = jjnr[jidx+2];
483             jnrlistD         = jjnr[jidx+3];
484             /* Sign of each element will be negative for non-real atoms.
485              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
486              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
487              */
488             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
489             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
490             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
491             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
492             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
493             j_coord_offsetA  = DIM*jnrA;
494             j_coord_offsetB  = DIM*jnrB;
495             j_coord_offsetC  = DIM*jnrC;
496             j_coord_offsetD  = DIM*jnrD;
497
498             /* load j atom coordinates */
499             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
500                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
501                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
502
503             /* Calculate displacement vector */
504             dx11             = _mm_sub_ps(ix1,jx1);
505             dy11             = _mm_sub_ps(iy1,jy1);
506             dz11             = _mm_sub_ps(iz1,jz1);
507             dx12             = _mm_sub_ps(ix1,jx2);
508             dy12             = _mm_sub_ps(iy1,jy2);
509             dz12             = _mm_sub_ps(iz1,jz2);
510             dx13             = _mm_sub_ps(ix1,jx3);
511             dy13             = _mm_sub_ps(iy1,jy3);
512             dz13             = _mm_sub_ps(iz1,jz3);
513             dx21             = _mm_sub_ps(ix2,jx1);
514             dy21             = _mm_sub_ps(iy2,jy1);
515             dz21             = _mm_sub_ps(iz2,jz1);
516             dx22             = _mm_sub_ps(ix2,jx2);
517             dy22             = _mm_sub_ps(iy2,jy2);
518             dz22             = _mm_sub_ps(iz2,jz2);
519             dx23             = _mm_sub_ps(ix2,jx3);
520             dy23             = _mm_sub_ps(iy2,jy3);
521             dz23             = _mm_sub_ps(iz2,jz3);
522             dx31             = _mm_sub_ps(ix3,jx1);
523             dy31             = _mm_sub_ps(iy3,jy1);
524             dz31             = _mm_sub_ps(iz3,jz1);
525             dx32             = _mm_sub_ps(ix3,jx2);
526             dy32             = _mm_sub_ps(iy3,jy2);
527             dz32             = _mm_sub_ps(iz3,jz2);
528             dx33             = _mm_sub_ps(ix3,jx3);
529             dy33             = _mm_sub_ps(iy3,jy3);
530             dz33             = _mm_sub_ps(iz3,jz3);
531
532             /* Calculate squared distance and things based on it */
533             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
534             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
535             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
536             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
537             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
538             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
539             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
540             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
541             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
542
543             rinv11           = gmx_mm_invsqrt_ps(rsq11);
544             rinv12           = gmx_mm_invsqrt_ps(rsq12);
545             rinv13           = gmx_mm_invsqrt_ps(rsq13);
546             rinv21           = gmx_mm_invsqrt_ps(rsq21);
547             rinv22           = gmx_mm_invsqrt_ps(rsq22);
548             rinv23           = gmx_mm_invsqrt_ps(rsq23);
549             rinv31           = gmx_mm_invsqrt_ps(rsq31);
550             rinv32           = gmx_mm_invsqrt_ps(rsq32);
551             rinv33           = gmx_mm_invsqrt_ps(rsq33);
552
553             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
554             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
555             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
556             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
557             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
558             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
559             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
560             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
561             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
562
563             fjx1             = _mm_setzero_ps();
564             fjy1             = _mm_setzero_ps();
565             fjz1             = _mm_setzero_ps();
566             fjx2             = _mm_setzero_ps();
567             fjy2             = _mm_setzero_ps();
568             fjz2             = _mm_setzero_ps();
569             fjx3             = _mm_setzero_ps();
570             fjy3             = _mm_setzero_ps();
571             fjz3             = _mm_setzero_ps();
572
573             /**************************
574              * CALCULATE INTERACTIONS *
575              **************************/
576
577             /* REACTION-FIELD ELECTROSTATICS */
578             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
579             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
580
581             /* Update potential sum for this i atom from the interaction with this j atom. */
582             velec            = _mm_andnot_ps(dummy_mask,velec);
583             velecsum         = _mm_add_ps(velecsum,velec);
584
585             fscal            = felec;
586
587             fscal            = _mm_andnot_ps(dummy_mask,fscal);
588
589              /* Update vectorial force */
590             fix1             = _mm_macc_ps(dx11,fscal,fix1);
591             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
592             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
593
594             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
595             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
596             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
597
598             /**************************
599              * CALCULATE INTERACTIONS *
600              **************************/
601
602             /* REACTION-FIELD ELECTROSTATICS */
603             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
604             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
605
606             /* Update potential sum for this i atom from the interaction with this j atom. */
607             velec            = _mm_andnot_ps(dummy_mask,velec);
608             velecsum         = _mm_add_ps(velecsum,velec);
609
610             fscal            = felec;
611
612             fscal            = _mm_andnot_ps(dummy_mask,fscal);
613
614              /* Update vectorial force */
615             fix1             = _mm_macc_ps(dx12,fscal,fix1);
616             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
617             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
618
619             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
620             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
621             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
622
623             /**************************
624              * CALCULATE INTERACTIONS *
625              **************************/
626
627             /* REACTION-FIELD ELECTROSTATICS */
628             velec            = _mm_mul_ps(qq13,_mm_sub_ps(_mm_macc_ps(krf,rsq13,rinv13),crf));
629             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
630
631             /* Update potential sum for this i atom from the interaction with this j atom. */
632             velec            = _mm_andnot_ps(dummy_mask,velec);
633             velecsum         = _mm_add_ps(velecsum,velec);
634
635             fscal            = felec;
636
637             fscal            = _mm_andnot_ps(dummy_mask,fscal);
638
639              /* Update vectorial force */
640             fix1             = _mm_macc_ps(dx13,fscal,fix1);
641             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
642             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
643
644             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
645             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
646             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
647
648             /**************************
649              * CALCULATE INTERACTIONS *
650              **************************/
651
652             /* REACTION-FIELD ELECTROSTATICS */
653             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
654             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
655
656             /* Update potential sum for this i atom from the interaction with this j atom. */
657             velec            = _mm_andnot_ps(dummy_mask,velec);
658             velecsum         = _mm_add_ps(velecsum,velec);
659
660             fscal            = felec;
661
662             fscal            = _mm_andnot_ps(dummy_mask,fscal);
663
664              /* Update vectorial force */
665             fix2             = _mm_macc_ps(dx21,fscal,fix2);
666             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
667             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
668
669             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
670             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
671             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
672
673             /**************************
674              * CALCULATE INTERACTIONS *
675              **************************/
676
677             /* REACTION-FIELD ELECTROSTATICS */
678             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
679             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
680
681             /* Update potential sum for this i atom from the interaction with this j atom. */
682             velec            = _mm_andnot_ps(dummy_mask,velec);
683             velecsum         = _mm_add_ps(velecsum,velec);
684
685             fscal            = felec;
686
687             fscal            = _mm_andnot_ps(dummy_mask,fscal);
688
689              /* Update vectorial force */
690             fix2             = _mm_macc_ps(dx22,fscal,fix2);
691             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
692             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
693
694             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
695             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
696             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
697
698             /**************************
699              * CALCULATE INTERACTIONS *
700              **************************/
701
702             /* REACTION-FIELD ELECTROSTATICS */
703             velec            = _mm_mul_ps(qq23,_mm_sub_ps(_mm_macc_ps(krf,rsq23,rinv23),crf));
704             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
705
706             /* Update potential sum for this i atom from the interaction with this j atom. */
707             velec            = _mm_andnot_ps(dummy_mask,velec);
708             velecsum         = _mm_add_ps(velecsum,velec);
709
710             fscal            = felec;
711
712             fscal            = _mm_andnot_ps(dummy_mask,fscal);
713
714              /* Update vectorial force */
715             fix2             = _mm_macc_ps(dx23,fscal,fix2);
716             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
717             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
718
719             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
720             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
721             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
722
723             /**************************
724              * CALCULATE INTERACTIONS *
725              **************************/
726
727             /* REACTION-FIELD ELECTROSTATICS */
728             velec            = _mm_mul_ps(qq31,_mm_sub_ps(_mm_macc_ps(krf,rsq31,rinv31),crf));
729             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
730
731             /* Update potential sum for this i atom from the interaction with this j atom. */
732             velec            = _mm_andnot_ps(dummy_mask,velec);
733             velecsum         = _mm_add_ps(velecsum,velec);
734
735             fscal            = felec;
736
737             fscal            = _mm_andnot_ps(dummy_mask,fscal);
738
739              /* Update vectorial force */
740             fix3             = _mm_macc_ps(dx31,fscal,fix3);
741             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
742             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
743
744             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
745             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
746             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
747
748             /**************************
749              * CALCULATE INTERACTIONS *
750              **************************/
751
752             /* REACTION-FIELD ELECTROSTATICS */
753             velec            = _mm_mul_ps(qq32,_mm_sub_ps(_mm_macc_ps(krf,rsq32,rinv32),crf));
754             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
755
756             /* Update potential sum for this i atom from the interaction with this j atom. */
757             velec            = _mm_andnot_ps(dummy_mask,velec);
758             velecsum         = _mm_add_ps(velecsum,velec);
759
760             fscal            = felec;
761
762             fscal            = _mm_andnot_ps(dummy_mask,fscal);
763
764              /* Update vectorial force */
765             fix3             = _mm_macc_ps(dx32,fscal,fix3);
766             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
767             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
768
769             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
770             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
771             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
772
773             /**************************
774              * CALCULATE INTERACTIONS *
775              **************************/
776
777             /* REACTION-FIELD ELECTROSTATICS */
778             velec            = _mm_mul_ps(qq33,_mm_sub_ps(_mm_macc_ps(krf,rsq33,rinv33),crf));
779             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
780
781             /* Update potential sum for this i atom from the interaction with this j atom. */
782             velec            = _mm_andnot_ps(dummy_mask,velec);
783             velecsum         = _mm_add_ps(velecsum,velec);
784
785             fscal            = felec;
786
787             fscal            = _mm_andnot_ps(dummy_mask,fscal);
788
789              /* Update vectorial force */
790             fix3             = _mm_macc_ps(dx33,fscal,fix3);
791             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
792             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
793
794             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
795             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
796             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
797
798             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
799             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
800             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
801             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
802
803             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
804                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
805
806             /* Inner loop uses 315 flops */
807         }
808
809         /* End of innermost loop */
810
811         gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
812                                               f+i_coord_offset+DIM,fshift+i_shift_offset);
813
814         ggid                        = gid[iidx];
815         /* Update potential energies */
816         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
817
818         /* Increment number of inner iterations */
819         inneriter                  += j_index_end - j_index_start;
820
821         /* Outer loop uses 19 flops */
822     }
823
824     /* Increment number of outer iterations */
825     outeriter        += nri;
826
827     /* Update outer/inner flops */
828
829     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4W4_VF,outeriter*19 + inneriter*315);
830 }
831 /*
832  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwNone_GeomW4W4_F_avx_128_fma_single
833  * Electrostatics interaction: ReactionField
834  * VdW interaction:            None
835  * Geometry:                   Water4-Water4
836  * Calculate force/pot:        Force
837  */
838 void
839 nb_kernel_ElecRF_VdwNone_GeomW4W4_F_avx_128_fma_single
840                     (t_nblist * gmx_restrict                nlist,
841                      rvec * gmx_restrict                    xx,
842                      rvec * gmx_restrict                    ff,
843                      t_forcerec * gmx_restrict              fr,
844                      t_mdatoms * gmx_restrict               mdatoms,
845                      nb_kernel_data_t * gmx_restrict        kernel_data,
846                      t_nrnb * gmx_restrict                  nrnb)
847 {
848     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
849      * just 0 for non-waters.
850      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
851      * jnr indices corresponding to data put in the four positions in the SIMD register.
852      */
853     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
854     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
855     int              jnrA,jnrB,jnrC,jnrD;
856     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
857     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
858     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
859     real             rcutoff_scalar;
860     real             *shiftvec,*fshift,*x,*f;
861     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
862     real             scratch[4*DIM];
863     __m128           fscal,rcutoff,rcutoff2,jidxall;
864     int              vdwioffset1;
865     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
866     int              vdwioffset2;
867     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
868     int              vdwioffset3;
869     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
870     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
871     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
872     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
873     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
874     int              vdwjidx3A,vdwjidx3B,vdwjidx3C,vdwjidx3D;
875     __m128           jx3,jy3,jz3,fjx3,fjy3,fjz3,jq3,isaj3;
876     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
877     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
878     __m128           dx13,dy13,dz13,rsq13,rinv13,rinvsq13,r13,qq13,c6_13,c12_13;
879     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
880     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
881     __m128           dx23,dy23,dz23,rsq23,rinv23,rinvsq23,r23,qq23,c6_23,c12_23;
882     __m128           dx31,dy31,dz31,rsq31,rinv31,rinvsq31,r31,qq31,c6_31,c12_31;
883     __m128           dx32,dy32,dz32,rsq32,rinv32,rinvsq32,r32,qq32,c6_32,c12_32;
884     __m128           dx33,dy33,dz33,rsq33,rinv33,rinvsq33,r33,qq33,c6_33,c12_33;
885     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
886     real             *charge;
887     __m128           dummy_mask,cutoff_mask;
888     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
889     __m128           one     = _mm_set1_ps(1.0);
890     __m128           two     = _mm_set1_ps(2.0);
891     x                = xx[0];
892     f                = ff[0];
893
894     nri              = nlist->nri;
895     iinr             = nlist->iinr;
896     jindex           = nlist->jindex;
897     jjnr             = nlist->jjnr;
898     shiftidx         = nlist->shift;
899     gid              = nlist->gid;
900     shiftvec         = fr->shift_vec[0];
901     fshift           = fr->fshift[0];
902     facel            = _mm_set1_ps(fr->epsfac);
903     charge           = mdatoms->chargeA;
904     krf              = _mm_set1_ps(fr->ic->k_rf);
905     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
906     crf              = _mm_set1_ps(fr->ic->c_rf);
907
908     /* Setup water-specific parameters */
909     inr              = nlist->iinr[0];
910     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
911     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
912     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
913
914     jq1              = _mm_set1_ps(charge[inr+1]);
915     jq2              = _mm_set1_ps(charge[inr+2]);
916     jq3              = _mm_set1_ps(charge[inr+3]);
917     qq11             = _mm_mul_ps(iq1,jq1);
918     qq12             = _mm_mul_ps(iq1,jq2);
919     qq13             = _mm_mul_ps(iq1,jq3);
920     qq21             = _mm_mul_ps(iq2,jq1);
921     qq22             = _mm_mul_ps(iq2,jq2);
922     qq23             = _mm_mul_ps(iq2,jq3);
923     qq31             = _mm_mul_ps(iq3,jq1);
924     qq32             = _mm_mul_ps(iq3,jq2);
925     qq33             = _mm_mul_ps(iq3,jq3);
926
927     /* Avoid stupid compiler warnings */
928     jnrA = jnrB = jnrC = jnrD = 0;
929     j_coord_offsetA = 0;
930     j_coord_offsetB = 0;
931     j_coord_offsetC = 0;
932     j_coord_offsetD = 0;
933
934     outeriter        = 0;
935     inneriter        = 0;
936
937     for(iidx=0;iidx<4*DIM;iidx++)
938     {
939         scratch[iidx] = 0.0;
940     }
941
942     /* Start outer loop over neighborlists */
943     for(iidx=0; iidx<nri; iidx++)
944     {
945         /* Load shift vector for this list */
946         i_shift_offset   = DIM*shiftidx[iidx];
947
948         /* Load limits for loop over neighbors */
949         j_index_start    = jindex[iidx];
950         j_index_end      = jindex[iidx+1];
951
952         /* Get outer coordinate index */
953         inr              = iinr[iidx];
954         i_coord_offset   = DIM*inr;
955
956         /* Load i particle coords and add shift vector */
957         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset+DIM,
958                                                  &ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
959
960         fix1             = _mm_setzero_ps();
961         fiy1             = _mm_setzero_ps();
962         fiz1             = _mm_setzero_ps();
963         fix2             = _mm_setzero_ps();
964         fiy2             = _mm_setzero_ps();
965         fiz2             = _mm_setzero_ps();
966         fix3             = _mm_setzero_ps();
967         fiy3             = _mm_setzero_ps();
968         fiz3             = _mm_setzero_ps();
969
970         /* Start inner kernel loop */
971         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
972         {
973
974             /* Get j neighbor index, and coordinate index */
975             jnrA             = jjnr[jidx];
976             jnrB             = jjnr[jidx+1];
977             jnrC             = jjnr[jidx+2];
978             jnrD             = jjnr[jidx+3];
979             j_coord_offsetA  = DIM*jnrA;
980             j_coord_offsetB  = DIM*jnrB;
981             j_coord_offsetC  = DIM*jnrC;
982             j_coord_offsetD  = DIM*jnrD;
983
984             /* load j atom coordinates */
985             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
986                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
987                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
988
989             /* Calculate displacement vector */
990             dx11             = _mm_sub_ps(ix1,jx1);
991             dy11             = _mm_sub_ps(iy1,jy1);
992             dz11             = _mm_sub_ps(iz1,jz1);
993             dx12             = _mm_sub_ps(ix1,jx2);
994             dy12             = _mm_sub_ps(iy1,jy2);
995             dz12             = _mm_sub_ps(iz1,jz2);
996             dx13             = _mm_sub_ps(ix1,jx3);
997             dy13             = _mm_sub_ps(iy1,jy3);
998             dz13             = _mm_sub_ps(iz1,jz3);
999             dx21             = _mm_sub_ps(ix2,jx1);
1000             dy21             = _mm_sub_ps(iy2,jy1);
1001             dz21             = _mm_sub_ps(iz2,jz1);
1002             dx22             = _mm_sub_ps(ix2,jx2);
1003             dy22             = _mm_sub_ps(iy2,jy2);
1004             dz22             = _mm_sub_ps(iz2,jz2);
1005             dx23             = _mm_sub_ps(ix2,jx3);
1006             dy23             = _mm_sub_ps(iy2,jy3);
1007             dz23             = _mm_sub_ps(iz2,jz3);
1008             dx31             = _mm_sub_ps(ix3,jx1);
1009             dy31             = _mm_sub_ps(iy3,jy1);
1010             dz31             = _mm_sub_ps(iz3,jz1);
1011             dx32             = _mm_sub_ps(ix3,jx2);
1012             dy32             = _mm_sub_ps(iy3,jy2);
1013             dz32             = _mm_sub_ps(iz3,jz2);
1014             dx33             = _mm_sub_ps(ix3,jx3);
1015             dy33             = _mm_sub_ps(iy3,jy3);
1016             dz33             = _mm_sub_ps(iz3,jz3);
1017
1018             /* Calculate squared distance and things based on it */
1019             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1020             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1021             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1022             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1023             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1024             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1025             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1026             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1027             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1028
1029             rinv11           = gmx_mm_invsqrt_ps(rsq11);
1030             rinv12           = gmx_mm_invsqrt_ps(rsq12);
1031             rinv13           = gmx_mm_invsqrt_ps(rsq13);
1032             rinv21           = gmx_mm_invsqrt_ps(rsq21);
1033             rinv22           = gmx_mm_invsqrt_ps(rsq22);
1034             rinv23           = gmx_mm_invsqrt_ps(rsq23);
1035             rinv31           = gmx_mm_invsqrt_ps(rsq31);
1036             rinv32           = gmx_mm_invsqrt_ps(rsq32);
1037             rinv33           = gmx_mm_invsqrt_ps(rsq33);
1038
1039             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1040             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1041             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
1042             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1043             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1044             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
1045             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
1046             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
1047             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
1048
1049             fjx1             = _mm_setzero_ps();
1050             fjy1             = _mm_setzero_ps();
1051             fjz1             = _mm_setzero_ps();
1052             fjx2             = _mm_setzero_ps();
1053             fjy2             = _mm_setzero_ps();
1054             fjz2             = _mm_setzero_ps();
1055             fjx3             = _mm_setzero_ps();
1056             fjy3             = _mm_setzero_ps();
1057             fjz3             = _mm_setzero_ps();
1058
1059             /**************************
1060              * CALCULATE INTERACTIONS *
1061              **************************/
1062
1063             /* REACTION-FIELD ELECTROSTATICS */
1064             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1065
1066             fscal            = felec;
1067
1068              /* Update vectorial force */
1069             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1070             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1071             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1072
1073             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1074             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1075             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1076
1077             /**************************
1078              * CALCULATE INTERACTIONS *
1079              **************************/
1080
1081             /* REACTION-FIELD ELECTROSTATICS */
1082             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1083
1084             fscal            = felec;
1085
1086              /* Update vectorial force */
1087             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1088             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1089             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1090
1091             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1092             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1093             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1094
1095             /**************************
1096              * CALCULATE INTERACTIONS *
1097              **************************/
1098
1099             /* REACTION-FIELD ELECTROSTATICS */
1100             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1101
1102             fscal            = felec;
1103
1104              /* Update vectorial force */
1105             fix1             = _mm_macc_ps(dx13,fscal,fix1);
1106             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
1107             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
1108
1109             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
1110             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
1111             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
1112
1113             /**************************
1114              * CALCULATE INTERACTIONS *
1115              **************************/
1116
1117             /* REACTION-FIELD ELECTROSTATICS */
1118             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1119
1120             fscal            = felec;
1121
1122              /* Update vectorial force */
1123             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1124             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1125             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1126
1127             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1128             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1129             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1130
1131             /**************************
1132              * CALCULATE INTERACTIONS *
1133              **************************/
1134
1135             /* REACTION-FIELD ELECTROSTATICS */
1136             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1137
1138             fscal            = felec;
1139
1140              /* Update vectorial force */
1141             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1142             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1143             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1144
1145             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1146             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1147             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1148
1149             /**************************
1150              * CALCULATE INTERACTIONS *
1151              **************************/
1152
1153             /* REACTION-FIELD ELECTROSTATICS */
1154             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1155
1156             fscal            = felec;
1157
1158              /* Update vectorial force */
1159             fix2             = _mm_macc_ps(dx23,fscal,fix2);
1160             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
1161             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
1162
1163             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
1164             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
1165             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
1166
1167             /**************************
1168              * CALCULATE INTERACTIONS *
1169              **************************/
1170
1171             /* REACTION-FIELD ELECTROSTATICS */
1172             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1173
1174             fscal            = felec;
1175
1176              /* Update vectorial force */
1177             fix3             = _mm_macc_ps(dx31,fscal,fix3);
1178             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
1179             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
1180
1181             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
1182             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
1183             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
1184
1185             /**************************
1186              * CALCULATE INTERACTIONS *
1187              **************************/
1188
1189             /* REACTION-FIELD ELECTROSTATICS */
1190             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1191
1192             fscal            = felec;
1193
1194              /* Update vectorial force */
1195             fix3             = _mm_macc_ps(dx32,fscal,fix3);
1196             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
1197             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
1198
1199             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
1200             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
1201             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
1202
1203             /**************************
1204              * CALCULATE INTERACTIONS *
1205              **************************/
1206
1207             /* REACTION-FIELD ELECTROSTATICS */
1208             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1209
1210             fscal            = felec;
1211
1212              /* Update vectorial force */
1213             fix3             = _mm_macc_ps(dx33,fscal,fix3);
1214             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
1215             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
1216
1217             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
1218             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
1219             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
1220
1221             fjptrA             = f+j_coord_offsetA;
1222             fjptrB             = f+j_coord_offsetB;
1223             fjptrC             = f+j_coord_offsetC;
1224             fjptrD             = f+j_coord_offsetD;
1225
1226             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1227                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1228
1229             /* Inner loop uses 270 flops */
1230         }
1231
1232         if(jidx<j_index_end)
1233         {
1234
1235             /* Get j neighbor index, and coordinate index */
1236             jnrlistA         = jjnr[jidx];
1237             jnrlistB         = jjnr[jidx+1];
1238             jnrlistC         = jjnr[jidx+2];
1239             jnrlistD         = jjnr[jidx+3];
1240             /* Sign of each element will be negative for non-real atoms.
1241              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1242              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1243              */
1244             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1245             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1246             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1247             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1248             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1249             j_coord_offsetA  = DIM*jnrA;
1250             j_coord_offsetB  = DIM*jnrB;
1251             j_coord_offsetC  = DIM*jnrC;
1252             j_coord_offsetD  = DIM*jnrD;
1253
1254             /* load j atom coordinates */
1255             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA+DIM,x+j_coord_offsetB+DIM,
1256                                               x+j_coord_offsetC+DIM,x+j_coord_offsetD+DIM,
1257                                               &jx1,&jy1,&jz1,&jx2,&jy2,&jz2,&jx3,&jy3,&jz3);
1258
1259             /* Calculate displacement vector */
1260             dx11             = _mm_sub_ps(ix1,jx1);
1261             dy11             = _mm_sub_ps(iy1,jy1);
1262             dz11             = _mm_sub_ps(iz1,jz1);
1263             dx12             = _mm_sub_ps(ix1,jx2);
1264             dy12             = _mm_sub_ps(iy1,jy2);
1265             dz12             = _mm_sub_ps(iz1,jz2);
1266             dx13             = _mm_sub_ps(ix1,jx3);
1267             dy13             = _mm_sub_ps(iy1,jy3);
1268             dz13             = _mm_sub_ps(iz1,jz3);
1269             dx21             = _mm_sub_ps(ix2,jx1);
1270             dy21             = _mm_sub_ps(iy2,jy1);
1271             dz21             = _mm_sub_ps(iz2,jz1);
1272             dx22             = _mm_sub_ps(ix2,jx2);
1273             dy22             = _mm_sub_ps(iy2,jy2);
1274             dz22             = _mm_sub_ps(iz2,jz2);
1275             dx23             = _mm_sub_ps(ix2,jx3);
1276             dy23             = _mm_sub_ps(iy2,jy3);
1277             dz23             = _mm_sub_ps(iz2,jz3);
1278             dx31             = _mm_sub_ps(ix3,jx1);
1279             dy31             = _mm_sub_ps(iy3,jy1);
1280             dz31             = _mm_sub_ps(iz3,jz1);
1281             dx32             = _mm_sub_ps(ix3,jx2);
1282             dy32             = _mm_sub_ps(iy3,jy2);
1283             dz32             = _mm_sub_ps(iz3,jz2);
1284             dx33             = _mm_sub_ps(ix3,jx3);
1285             dy33             = _mm_sub_ps(iy3,jy3);
1286             dz33             = _mm_sub_ps(iz3,jz3);
1287
1288             /* Calculate squared distance and things based on it */
1289             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1290             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1291             rsq13            = gmx_mm_calc_rsq_ps(dx13,dy13,dz13);
1292             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1293             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1294             rsq23            = gmx_mm_calc_rsq_ps(dx23,dy23,dz23);
1295             rsq31            = gmx_mm_calc_rsq_ps(dx31,dy31,dz31);
1296             rsq32            = gmx_mm_calc_rsq_ps(dx32,dy32,dz32);
1297             rsq33            = gmx_mm_calc_rsq_ps(dx33,dy33,dz33);
1298
1299             rinv11           = gmx_mm_invsqrt_ps(rsq11);
1300             rinv12           = gmx_mm_invsqrt_ps(rsq12);
1301             rinv13           = gmx_mm_invsqrt_ps(rsq13);
1302             rinv21           = gmx_mm_invsqrt_ps(rsq21);
1303             rinv22           = gmx_mm_invsqrt_ps(rsq22);
1304             rinv23           = gmx_mm_invsqrt_ps(rsq23);
1305             rinv31           = gmx_mm_invsqrt_ps(rsq31);
1306             rinv32           = gmx_mm_invsqrt_ps(rsq32);
1307             rinv33           = gmx_mm_invsqrt_ps(rsq33);
1308
1309             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1310             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1311             rinvsq13         = _mm_mul_ps(rinv13,rinv13);
1312             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1313             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1314             rinvsq23         = _mm_mul_ps(rinv23,rinv23);
1315             rinvsq31         = _mm_mul_ps(rinv31,rinv31);
1316             rinvsq32         = _mm_mul_ps(rinv32,rinv32);
1317             rinvsq33         = _mm_mul_ps(rinv33,rinv33);
1318
1319             fjx1             = _mm_setzero_ps();
1320             fjy1             = _mm_setzero_ps();
1321             fjz1             = _mm_setzero_ps();
1322             fjx2             = _mm_setzero_ps();
1323             fjy2             = _mm_setzero_ps();
1324             fjz2             = _mm_setzero_ps();
1325             fjx3             = _mm_setzero_ps();
1326             fjy3             = _mm_setzero_ps();
1327             fjz3             = _mm_setzero_ps();
1328
1329             /**************************
1330              * CALCULATE INTERACTIONS *
1331              **************************/
1332
1333             /* REACTION-FIELD ELECTROSTATICS */
1334             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1335
1336             fscal            = felec;
1337
1338             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1339
1340              /* Update vectorial force */
1341             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1342             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1343             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1344
1345             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1346             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1347             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1348
1349             /**************************
1350              * CALCULATE INTERACTIONS *
1351              **************************/
1352
1353             /* REACTION-FIELD ELECTROSTATICS */
1354             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1355
1356             fscal            = felec;
1357
1358             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1359
1360              /* Update vectorial force */
1361             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1362             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1363             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1364
1365             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1366             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1367             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1368
1369             /**************************
1370              * CALCULATE INTERACTIONS *
1371              **************************/
1372
1373             /* REACTION-FIELD ELECTROSTATICS */
1374             felec            = _mm_mul_ps(qq13,_mm_msub_ps(rinv13,rinvsq13,krf2));
1375
1376             fscal            = felec;
1377
1378             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1379
1380              /* Update vectorial force */
1381             fix1             = _mm_macc_ps(dx13,fscal,fix1);
1382             fiy1             = _mm_macc_ps(dy13,fscal,fiy1);
1383             fiz1             = _mm_macc_ps(dz13,fscal,fiz1);
1384
1385             fjx3             = _mm_macc_ps(dx13,fscal,fjx3);
1386             fjy3             = _mm_macc_ps(dy13,fscal,fjy3);
1387             fjz3             = _mm_macc_ps(dz13,fscal,fjz3);
1388
1389             /**************************
1390              * CALCULATE INTERACTIONS *
1391              **************************/
1392
1393             /* REACTION-FIELD ELECTROSTATICS */
1394             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1395
1396             fscal            = felec;
1397
1398             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1399
1400              /* Update vectorial force */
1401             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1402             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1403             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1404
1405             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1406             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1407             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1408
1409             /**************************
1410              * CALCULATE INTERACTIONS *
1411              **************************/
1412
1413             /* REACTION-FIELD ELECTROSTATICS */
1414             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1415
1416             fscal            = felec;
1417
1418             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1419
1420              /* Update vectorial force */
1421             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1422             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1423             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1424
1425             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1426             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1427             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
1428
1429             /**************************
1430              * CALCULATE INTERACTIONS *
1431              **************************/
1432
1433             /* REACTION-FIELD ELECTROSTATICS */
1434             felec            = _mm_mul_ps(qq23,_mm_msub_ps(rinv23,rinvsq23,krf2));
1435
1436             fscal            = felec;
1437
1438             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1439
1440              /* Update vectorial force */
1441             fix2             = _mm_macc_ps(dx23,fscal,fix2);
1442             fiy2             = _mm_macc_ps(dy23,fscal,fiy2);
1443             fiz2             = _mm_macc_ps(dz23,fscal,fiz2);
1444
1445             fjx3             = _mm_macc_ps(dx23,fscal,fjx3);
1446             fjy3             = _mm_macc_ps(dy23,fscal,fjy3);
1447             fjz3             = _mm_macc_ps(dz23,fscal,fjz3);
1448
1449             /**************************
1450              * CALCULATE INTERACTIONS *
1451              **************************/
1452
1453             /* REACTION-FIELD ELECTROSTATICS */
1454             felec            = _mm_mul_ps(qq31,_mm_msub_ps(rinv31,rinvsq31,krf2));
1455
1456             fscal            = felec;
1457
1458             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1459
1460              /* Update vectorial force */
1461             fix3             = _mm_macc_ps(dx31,fscal,fix3);
1462             fiy3             = _mm_macc_ps(dy31,fscal,fiy3);
1463             fiz3             = _mm_macc_ps(dz31,fscal,fiz3);
1464
1465             fjx1             = _mm_macc_ps(dx31,fscal,fjx1);
1466             fjy1             = _mm_macc_ps(dy31,fscal,fjy1);
1467             fjz1             = _mm_macc_ps(dz31,fscal,fjz1);
1468
1469             /**************************
1470              * CALCULATE INTERACTIONS *
1471              **************************/
1472
1473             /* REACTION-FIELD ELECTROSTATICS */
1474             felec            = _mm_mul_ps(qq32,_mm_msub_ps(rinv32,rinvsq32,krf2));
1475
1476             fscal            = felec;
1477
1478             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1479
1480              /* Update vectorial force */
1481             fix3             = _mm_macc_ps(dx32,fscal,fix3);
1482             fiy3             = _mm_macc_ps(dy32,fscal,fiy3);
1483             fiz3             = _mm_macc_ps(dz32,fscal,fiz3);
1484
1485             fjx2             = _mm_macc_ps(dx32,fscal,fjx2);
1486             fjy2             = _mm_macc_ps(dy32,fscal,fjy2);
1487             fjz2             = _mm_macc_ps(dz32,fscal,fjz2);
1488
1489             /**************************
1490              * CALCULATE INTERACTIONS *
1491              **************************/
1492
1493             /* REACTION-FIELD ELECTROSTATICS */
1494             felec            = _mm_mul_ps(qq33,_mm_msub_ps(rinv33,rinvsq33,krf2));
1495
1496             fscal            = felec;
1497
1498             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1499
1500              /* Update vectorial force */
1501             fix3             = _mm_macc_ps(dx33,fscal,fix3);
1502             fiy3             = _mm_macc_ps(dy33,fscal,fiy3);
1503             fiz3             = _mm_macc_ps(dz33,fscal,fiz3);
1504
1505             fjx3             = _mm_macc_ps(dx33,fscal,fjx3);
1506             fjy3             = _mm_macc_ps(dy33,fscal,fjy3);
1507             fjz3             = _mm_macc_ps(dz33,fscal,fjz3);
1508
1509             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1510             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1511             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1512             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1513
1514             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA+DIM,fjptrB+DIM,fjptrC+DIM,fjptrD+DIM,
1515                                                    fjx1,fjy1,fjz1,fjx2,fjy2,fjz2,fjx3,fjy3,fjz3);
1516
1517             /* Inner loop uses 270 flops */
1518         }
1519
1520         /* End of innermost loop */
1521
1522         gmx_mm_update_iforce_3atom_swizzle_ps(fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1523                                               f+i_coord_offset+DIM,fshift+i_shift_offset);
1524
1525         /* Increment number of inner iterations */
1526         inneriter                  += j_index_end - j_index_start;
1527
1528         /* Outer loop uses 18 flops */
1529     }
1530
1531     /* Increment number of outer iterations */
1532     outeriter        += nri;
1533
1534     /* Update outer/inner flops */
1535
1536     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W4W4_F,outeriter*18 + inneriter*270);
1537 }