8133f357b338de69a0a1dad4f4bd755978d19791
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRF_VdwNone_GeomW3W3_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_GeomW3W3_VF_avx_128_fma_single
38  * Electrostatics interaction: ReactionField
39  * VdW interaction:            None
40  * Geometry:                   Water3-Water3
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecRF_VdwNone_GeomW3W3_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              vdwioffset0;
70     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
71     int              vdwioffset1;
72     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
73     int              vdwioffset2;
74     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
76     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
77     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
78     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
79     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
80     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
81     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
82     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
83     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
84     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
85     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
86     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
87     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
88     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
89     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
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     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
116     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
117     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
118
119     jq0              = _mm_set1_ps(charge[inr+0]);
120     jq1              = _mm_set1_ps(charge[inr+1]);
121     jq2              = _mm_set1_ps(charge[inr+2]);
122     qq00             = _mm_mul_ps(iq0,jq0);
123     qq01             = _mm_mul_ps(iq0,jq1);
124     qq02             = _mm_mul_ps(iq0,jq2);
125     qq10             = _mm_mul_ps(iq1,jq0);
126     qq11             = _mm_mul_ps(iq1,jq1);
127     qq12             = _mm_mul_ps(iq1,jq2);
128     qq20             = _mm_mul_ps(iq2,jq0);
129     qq21             = _mm_mul_ps(iq2,jq1);
130     qq22             = _mm_mul_ps(iq2,jq2);
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,
163                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
164
165         fix0             = _mm_setzero_ps();
166         fiy0             = _mm_setzero_ps();
167         fiz0             = _mm_setzero_ps();
168         fix1             = _mm_setzero_ps();
169         fiy1             = _mm_setzero_ps();
170         fiz1             = _mm_setzero_ps();
171         fix2             = _mm_setzero_ps();
172         fiy2             = _mm_setzero_ps();
173         fiz2             = _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,x+j_coord_offsetB,
194                                               x+j_coord_offsetC,x+j_coord_offsetD,
195                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
196
197             /* Calculate displacement vector */
198             dx00             = _mm_sub_ps(ix0,jx0);
199             dy00             = _mm_sub_ps(iy0,jy0);
200             dz00             = _mm_sub_ps(iz0,jz0);
201             dx01             = _mm_sub_ps(ix0,jx1);
202             dy01             = _mm_sub_ps(iy0,jy1);
203             dz01             = _mm_sub_ps(iz0,jz1);
204             dx02             = _mm_sub_ps(ix0,jx2);
205             dy02             = _mm_sub_ps(iy0,jy2);
206             dz02             = _mm_sub_ps(iz0,jz2);
207             dx10             = _mm_sub_ps(ix1,jx0);
208             dy10             = _mm_sub_ps(iy1,jy0);
209             dz10             = _mm_sub_ps(iz1,jz0);
210             dx11             = _mm_sub_ps(ix1,jx1);
211             dy11             = _mm_sub_ps(iy1,jy1);
212             dz11             = _mm_sub_ps(iz1,jz1);
213             dx12             = _mm_sub_ps(ix1,jx2);
214             dy12             = _mm_sub_ps(iy1,jy2);
215             dz12             = _mm_sub_ps(iz1,jz2);
216             dx20             = _mm_sub_ps(ix2,jx0);
217             dy20             = _mm_sub_ps(iy2,jy0);
218             dz20             = _mm_sub_ps(iz2,jz0);
219             dx21             = _mm_sub_ps(ix2,jx1);
220             dy21             = _mm_sub_ps(iy2,jy1);
221             dz21             = _mm_sub_ps(iz2,jz1);
222             dx22             = _mm_sub_ps(ix2,jx2);
223             dy22             = _mm_sub_ps(iy2,jy2);
224             dz22             = _mm_sub_ps(iz2,jz2);
225
226             /* Calculate squared distance and things based on it */
227             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
228             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
229             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
230             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
231             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
232             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
233             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
234             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
235             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
236
237             rinv00           = gmx_mm_invsqrt_ps(rsq00);
238             rinv01           = gmx_mm_invsqrt_ps(rsq01);
239             rinv02           = gmx_mm_invsqrt_ps(rsq02);
240             rinv10           = gmx_mm_invsqrt_ps(rsq10);
241             rinv11           = gmx_mm_invsqrt_ps(rsq11);
242             rinv12           = gmx_mm_invsqrt_ps(rsq12);
243             rinv20           = gmx_mm_invsqrt_ps(rsq20);
244             rinv21           = gmx_mm_invsqrt_ps(rsq21);
245             rinv22           = gmx_mm_invsqrt_ps(rsq22);
246
247             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
248             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
249             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
250             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
251             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
252             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
253             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
254             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
255             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
256
257             fjx0             = _mm_setzero_ps();
258             fjy0             = _mm_setzero_ps();
259             fjz0             = _mm_setzero_ps();
260             fjx1             = _mm_setzero_ps();
261             fjy1             = _mm_setzero_ps();
262             fjz1             = _mm_setzero_ps();
263             fjx2             = _mm_setzero_ps();
264             fjy2             = _mm_setzero_ps();
265             fjz2             = _mm_setzero_ps();
266
267             /**************************
268              * CALCULATE INTERACTIONS *
269              **************************/
270
271             /* REACTION-FIELD ELECTROSTATICS */
272             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
273             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,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             fix0             = _mm_macc_ps(dx00,fscal,fix0);
282             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
283             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
284
285             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
286             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
287             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
288
289             /**************************
290              * CALCULATE INTERACTIONS *
291              **************************/
292
293             /* REACTION-FIELD ELECTROSTATICS */
294             velec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
295             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,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             fix0             = _mm_macc_ps(dx01,fscal,fix0);
304             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
305             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
306
307             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
308             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
309             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
310
311             /**************************
312              * CALCULATE INTERACTIONS *
313              **************************/
314
315             /* REACTION-FIELD ELECTROSTATICS */
316             velec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
317             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,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             fix0             = _mm_macc_ps(dx02,fscal,fix0);
326             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
327             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
328
329             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
330             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
331             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
332
333             /**************************
334              * CALCULATE INTERACTIONS *
335              **************************/
336
337             /* REACTION-FIELD ELECTROSTATICS */
338             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
339             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,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             fix1             = _mm_macc_ps(dx10,fscal,fix1);
348             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
349             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
350
351             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
352             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
353             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
354
355             /**************************
356              * CALCULATE INTERACTIONS *
357              **************************/
358
359             /* REACTION-FIELD ELECTROSTATICS */
360             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
361             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,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             fix1             = _mm_macc_ps(dx11,fscal,fix1);
370             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
371             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
372
373             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
374             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
375             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
376
377             /**************************
378              * CALCULATE INTERACTIONS *
379              **************************/
380
381             /* REACTION-FIELD ELECTROSTATICS */
382             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
383             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,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             fix1             = _mm_macc_ps(dx12,fscal,fix1);
392             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
393             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
394
395             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
396             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
397             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
398
399             /**************************
400              * CALCULATE INTERACTIONS *
401              **************************/
402
403             /* REACTION-FIELD ELECTROSTATICS */
404             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
405             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,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             fix2             = _mm_macc_ps(dx20,fscal,fix2);
414             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
415             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
416
417             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
418             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
419             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
420
421             /**************************
422              * CALCULATE INTERACTIONS *
423              **************************/
424
425             /* REACTION-FIELD ELECTROSTATICS */
426             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
427             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,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             fix2             = _mm_macc_ps(dx21,fscal,fix2);
436             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
437             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
438
439             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
440             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
441             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
442
443             /**************************
444              * CALCULATE INTERACTIONS *
445              **************************/
446
447             /* REACTION-FIELD ELECTROSTATICS */
448             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
449             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,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             fix2             = _mm_macc_ps(dx22,fscal,fix2);
458             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
459             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
460
461             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
462             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
463             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
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,fjptrB,fjptrC,fjptrD,
471                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
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,x+j_coord_offsetB,
500                                               x+j_coord_offsetC,x+j_coord_offsetD,
501                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
502
503             /* Calculate displacement vector */
504             dx00             = _mm_sub_ps(ix0,jx0);
505             dy00             = _mm_sub_ps(iy0,jy0);
506             dz00             = _mm_sub_ps(iz0,jz0);
507             dx01             = _mm_sub_ps(ix0,jx1);
508             dy01             = _mm_sub_ps(iy0,jy1);
509             dz01             = _mm_sub_ps(iz0,jz1);
510             dx02             = _mm_sub_ps(ix0,jx2);
511             dy02             = _mm_sub_ps(iy0,jy2);
512             dz02             = _mm_sub_ps(iz0,jz2);
513             dx10             = _mm_sub_ps(ix1,jx0);
514             dy10             = _mm_sub_ps(iy1,jy0);
515             dz10             = _mm_sub_ps(iz1,jz0);
516             dx11             = _mm_sub_ps(ix1,jx1);
517             dy11             = _mm_sub_ps(iy1,jy1);
518             dz11             = _mm_sub_ps(iz1,jz1);
519             dx12             = _mm_sub_ps(ix1,jx2);
520             dy12             = _mm_sub_ps(iy1,jy2);
521             dz12             = _mm_sub_ps(iz1,jz2);
522             dx20             = _mm_sub_ps(ix2,jx0);
523             dy20             = _mm_sub_ps(iy2,jy0);
524             dz20             = _mm_sub_ps(iz2,jz0);
525             dx21             = _mm_sub_ps(ix2,jx1);
526             dy21             = _mm_sub_ps(iy2,jy1);
527             dz21             = _mm_sub_ps(iz2,jz1);
528             dx22             = _mm_sub_ps(ix2,jx2);
529             dy22             = _mm_sub_ps(iy2,jy2);
530             dz22             = _mm_sub_ps(iz2,jz2);
531
532             /* Calculate squared distance and things based on it */
533             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
534             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
535             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
536             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
537             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
538             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
539             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
540             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
541             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
542
543             rinv00           = gmx_mm_invsqrt_ps(rsq00);
544             rinv01           = gmx_mm_invsqrt_ps(rsq01);
545             rinv02           = gmx_mm_invsqrt_ps(rsq02);
546             rinv10           = gmx_mm_invsqrt_ps(rsq10);
547             rinv11           = gmx_mm_invsqrt_ps(rsq11);
548             rinv12           = gmx_mm_invsqrt_ps(rsq12);
549             rinv20           = gmx_mm_invsqrt_ps(rsq20);
550             rinv21           = gmx_mm_invsqrt_ps(rsq21);
551             rinv22           = gmx_mm_invsqrt_ps(rsq22);
552
553             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
554             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
555             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
556             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
557             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
558             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
559             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
560             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
561             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
562
563             fjx0             = _mm_setzero_ps();
564             fjy0             = _mm_setzero_ps();
565             fjz0             = _mm_setzero_ps();
566             fjx1             = _mm_setzero_ps();
567             fjy1             = _mm_setzero_ps();
568             fjz1             = _mm_setzero_ps();
569             fjx2             = _mm_setzero_ps();
570             fjy2             = _mm_setzero_ps();
571             fjz2             = _mm_setzero_ps();
572
573             /**************************
574              * CALCULATE INTERACTIONS *
575              **************************/
576
577             /* REACTION-FIELD ELECTROSTATICS */
578             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
579             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,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             fix0             = _mm_macc_ps(dx00,fscal,fix0);
591             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
592             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
593
594             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
595             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
596             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
597
598             /**************************
599              * CALCULATE INTERACTIONS *
600              **************************/
601
602             /* REACTION-FIELD ELECTROSTATICS */
603             velec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_macc_ps(krf,rsq01,rinv01),crf));
604             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,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             fix0             = _mm_macc_ps(dx01,fscal,fix0);
616             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
617             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
618
619             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
620             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
621             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
622
623             /**************************
624              * CALCULATE INTERACTIONS *
625              **************************/
626
627             /* REACTION-FIELD ELECTROSTATICS */
628             velec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_macc_ps(krf,rsq02,rinv02),crf));
629             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,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             fix0             = _mm_macc_ps(dx02,fscal,fix0);
641             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
642             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
643
644             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
645             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
646             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
647
648             /**************************
649              * CALCULATE INTERACTIONS *
650              **************************/
651
652             /* REACTION-FIELD ELECTROSTATICS */
653             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
654             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,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             fix1             = _mm_macc_ps(dx10,fscal,fix1);
666             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
667             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
668
669             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
670             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
671             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
672
673             /**************************
674              * CALCULATE INTERACTIONS *
675              **************************/
676
677             /* REACTION-FIELD ELECTROSTATICS */
678             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_macc_ps(krf,rsq11,rinv11),crf));
679             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,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             fix1             = _mm_macc_ps(dx11,fscal,fix1);
691             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
692             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
693
694             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
695             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
696             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
697
698             /**************************
699              * CALCULATE INTERACTIONS *
700              **************************/
701
702             /* REACTION-FIELD ELECTROSTATICS */
703             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_macc_ps(krf,rsq12,rinv12),crf));
704             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,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             fix1             = _mm_macc_ps(dx12,fscal,fix1);
716             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
717             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
718
719             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
720             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
721             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
722
723             /**************************
724              * CALCULATE INTERACTIONS *
725              **************************/
726
727             /* REACTION-FIELD ELECTROSTATICS */
728             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
729             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,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             fix2             = _mm_macc_ps(dx20,fscal,fix2);
741             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
742             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
743
744             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
745             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
746             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
747
748             /**************************
749              * CALCULATE INTERACTIONS *
750              **************************/
751
752             /* REACTION-FIELD ELECTROSTATICS */
753             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_macc_ps(krf,rsq21,rinv21),crf));
754             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,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             fix2             = _mm_macc_ps(dx21,fscal,fix2);
766             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
767             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
768
769             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
770             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
771             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
772
773             /**************************
774              * CALCULATE INTERACTIONS *
775              **************************/
776
777             /* REACTION-FIELD ELECTROSTATICS */
778             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_macc_ps(krf,rsq22,rinv22),crf));
779             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,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             fix2             = _mm_macc_ps(dx22,fscal,fix2);
791             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
792             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
793
794             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
795             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
796             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
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,fjptrB,fjptrC,fjptrD,
804                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
805
806             /* Inner loop uses 315 flops */
807         }
808
809         /* End of innermost loop */
810
811         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
812                                               f+i_coord_offset,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_W3W3_VF,outeriter*19 + inneriter*315);
830 }
831 /*
832  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwNone_GeomW3W3_F_avx_128_fma_single
833  * Electrostatics interaction: ReactionField
834  * VdW interaction:            None
835  * Geometry:                   Water3-Water3
836  * Calculate force/pot:        Force
837  */
838 void
839 nb_kernel_ElecRF_VdwNone_GeomW3W3_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              vdwioffset0;
865     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
866     int              vdwioffset1;
867     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
868     int              vdwioffset2;
869     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
870     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
871     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
872     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
873     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
874     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
875     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
876     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
877     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
878     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
879     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
880     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
881     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
882     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
883     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
884     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
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     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
911     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
912     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
913
914     jq0              = _mm_set1_ps(charge[inr+0]);
915     jq1              = _mm_set1_ps(charge[inr+1]);
916     jq2              = _mm_set1_ps(charge[inr+2]);
917     qq00             = _mm_mul_ps(iq0,jq0);
918     qq01             = _mm_mul_ps(iq0,jq1);
919     qq02             = _mm_mul_ps(iq0,jq2);
920     qq10             = _mm_mul_ps(iq1,jq0);
921     qq11             = _mm_mul_ps(iq1,jq1);
922     qq12             = _mm_mul_ps(iq1,jq2);
923     qq20             = _mm_mul_ps(iq2,jq0);
924     qq21             = _mm_mul_ps(iq2,jq1);
925     qq22             = _mm_mul_ps(iq2,jq2);
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,
958                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
959
960         fix0             = _mm_setzero_ps();
961         fiy0             = _mm_setzero_ps();
962         fiz0             = _mm_setzero_ps();
963         fix1             = _mm_setzero_ps();
964         fiy1             = _mm_setzero_ps();
965         fiz1             = _mm_setzero_ps();
966         fix2             = _mm_setzero_ps();
967         fiy2             = _mm_setzero_ps();
968         fiz2             = _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,x+j_coord_offsetB,
986                                               x+j_coord_offsetC,x+j_coord_offsetD,
987                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
988
989             /* Calculate displacement vector */
990             dx00             = _mm_sub_ps(ix0,jx0);
991             dy00             = _mm_sub_ps(iy0,jy0);
992             dz00             = _mm_sub_ps(iz0,jz0);
993             dx01             = _mm_sub_ps(ix0,jx1);
994             dy01             = _mm_sub_ps(iy0,jy1);
995             dz01             = _mm_sub_ps(iz0,jz1);
996             dx02             = _mm_sub_ps(ix0,jx2);
997             dy02             = _mm_sub_ps(iy0,jy2);
998             dz02             = _mm_sub_ps(iz0,jz2);
999             dx10             = _mm_sub_ps(ix1,jx0);
1000             dy10             = _mm_sub_ps(iy1,jy0);
1001             dz10             = _mm_sub_ps(iz1,jz0);
1002             dx11             = _mm_sub_ps(ix1,jx1);
1003             dy11             = _mm_sub_ps(iy1,jy1);
1004             dz11             = _mm_sub_ps(iz1,jz1);
1005             dx12             = _mm_sub_ps(ix1,jx2);
1006             dy12             = _mm_sub_ps(iy1,jy2);
1007             dz12             = _mm_sub_ps(iz1,jz2);
1008             dx20             = _mm_sub_ps(ix2,jx0);
1009             dy20             = _mm_sub_ps(iy2,jy0);
1010             dz20             = _mm_sub_ps(iz2,jz0);
1011             dx21             = _mm_sub_ps(ix2,jx1);
1012             dy21             = _mm_sub_ps(iy2,jy1);
1013             dz21             = _mm_sub_ps(iz2,jz1);
1014             dx22             = _mm_sub_ps(ix2,jx2);
1015             dy22             = _mm_sub_ps(iy2,jy2);
1016             dz22             = _mm_sub_ps(iz2,jz2);
1017
1018             /* Calculate squared distance and things based on it */
1019             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1020             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1021             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1022             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1023             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1024             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1025             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1026             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1027             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1028
1029             rinv00           = gmx_mm_invsqrt_ps(rsq00);
1030             rinv01           = gmx_mm_invsqrt_ps(rsq01);
1031             rinv02           = gmx_mm_invsqrt_ps(rsq02);
1032             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1033             rinv11           = gmx_mm_invsqrt_ps(rsq11);
1034             rinv12           = gmx_mm_invsqrt_ps(rsq12);
1035             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1036             rinv21           = gmx_mm_invsqrt_ps(rsq21);
1037             rinv22           = gmx_mm_invsqrt_ps(rsq22);
1038
1039             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1040             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1041             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1042             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1043             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1044             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1045             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1046             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1047             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1048
1049             fjx0             = _mm_setzero_ps();
1050             fjy0             = _mm_setzero_ps();
1051             fjz0             = _mm_setzero_ps();
1052             fjx1             = _mm_setzero_ps();
1053             fjy1             = _mm_setzero_ps();
1054             fjz1             = _mm_setzero_ps();
1055             fjx2             = _mm_setzero_ps();
1056             fjy2             = _mm_setzero_ps();
1057             fjz2             = _mm_setzero_ps();
1058
1059             /**************************
1060              * CALCULATE INTERACTIONS *
1061              **************************/
1062
1063             /* REACTION-FIELD ELECTROSTATICS */
1064             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1065
1066             fscal            = felec;
1067
1068              /* Update vectorial force */
1069             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1070             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1071             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1072
1073             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1074             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1075             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1076
1077             /**************************
1078              * CALCULATE INTERACTIONS *
1079              **************************/
1080
1081             /* REACTION-FIELD ELECTROSTATICS */
1082             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1083
1084             fscal            = felec;
1085
1086              /* Update vectorial force */
1087             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1088             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1089             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1090
1091             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1092             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1093             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1094
1095             /**************************
1096              * CALCULATE INTERACTIONS *
1097              **************************/
1098
1099             /* REACTION-FIELD ELECTROSTATICS */
1100             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1101
1102             fscal            = felec;
1103
1104              /* Update vectorial force */
1105             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1106             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1107             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1108
1109             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
1110             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
1111             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
1112
1113             /**************************
1114              * CALCULATE INTERACTIONS *
1115              **************************/
1116
1117             /* REACTION-FIELD ELECTROSTATICS */
1118             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1119
1120             fscal            = felec;
1121
1122              /* Update vectorial force */
1123             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1124             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1125             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1126
1127             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1128             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1129             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1130
1131             /**************************
1132              * CALCULATE INTERACTIONS *
1133              **************************/
1134
1135             /* REACTION-FIELD ELECTROSTATICS */
1136             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1137
1138             fscal            = felec;
1139
1140              /* Update vectorial force */
1141             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1142             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1143             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1144
1145             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1146             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1147             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1148
1149             /**************************
1150              * CALCULATE INTERACTIONS *
1151              **************************/
1152
1153             /* REACTION-FIELD ELECTROSTATICS */
1154             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1155
1156             fscal            = felec;
1157
1158              /* Update vectorial force */
1159             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1160             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1161             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1162
1163             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1164             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1165             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1166
1167             /**************************
1168              * CALCULATE INTERACTIONS *
1169              **************************/
1170
1171             /* REACTION-FIELD ELECTROSTATICS */
1172             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1173
1174             fscal            = felec;
1175
1176              /* Update vectorial force */
1177             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1178             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1179             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1180
1181             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1182             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1183             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1184
1185             /**************************
1186              * CALCULATE INTERACTIONS *
1187              **************************/
1188
1189             /* REACTION-FIELD ELECTROSTATICS */
1190             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1191
1192             fscal            = felec;
1193
1194              /* Update vectorial force */
1195             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1196             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1197             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1198
1199             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1200             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1201             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1202
1203             /**************************
1204              * CALCULATE INTERACTIONS *
1205              **************************/
1206
1207             /* REACTION-FIELD ELECTROSTATICS */
1208             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1209
1210             fscal            = felec;
1211
1212              /* Update vectorial force */
1213             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1214             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1215             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1216
1217             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1218             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1219             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
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,fjptrB,fjptrC,fjptrD,
1227                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
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,x+j_coord_offsetB,
1256                                               x+j_coord_offsetC,x+j_coord_offsetD,
1257                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1258
1259             /* Calculate displacement vector */
1260             dx00             = _mm_sub_ps(ix0,jx0);
1261             dy00             = _mm_sub_ps(iy0,jy0);
1262             dz00             = _mm_sub_ps(iz0,jz0);
1263             dx01             = _mm_sub_ps(ix0,jx1);
1264             dy01             = _mm_sub_ps(iy0,jy1);
1265             dz01             = _mm_sub_ps(iz0,jz1);
1266             dx02             = _mm_sub_ps(ix0,jx2);
1267             dy02             = _mm_sub_ps(iy0,jy2);
1268             dz02             = _mm_sub_ps(iz0,jz2);
1269             dx10             = _mm_sub_ps(ix1,jx0);
1270             dy10             = _mm_sub_ps(iy1,jy0);
1271             dz10             = _mm_sub_ps(iz1,jz0);
1272             dx11             = _mm_sub_ps(ix1,jx1);
1273             dy11             = _mm_sub_ps(iy1,jy1);
1274             dz11             = _mm_sub_ps(iz1,jz1);
1275             dx12             = _mm_sub_ps(ix1,jx2);
1276             dy12             = _mm_sub_ps(iy1,jy2);
1277             dz12             = _mm_sub_ps(iz1,jz2);
1278             dx20             = _mm_sub_ps(ix2,jx0);
1279             dy20             = _mm_sub_ps(iy2,jy0);
1280             dz20             = _mm_sub_ps(iz2,jz0);
1281             dx21             = _mm_sub_ps(ix2,jx1);
1282             dy21             = _mm_sub_ps(iy2,jy1);
1283             dz21             = _mm_sub_ps(iz2,jz1);
1284             dx22             = _mm_sub_ps(ix2,jx2);
1285             dy22             = _mm_sub_ps(iy2,jy2);
1286             dz22             = _mm_sub_ps(iz2,jz2);
1287
1288             /* Calculate squared distance and things based on it */
1289             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1290             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1291             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1292             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1293             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1294             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1295             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1296             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1297             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1298
1299             rinv00           = gmx_mm_invsqrt_ps(rsq00);
1300             rinv01           = gmx_mm_invsqrt_ps(rsq01);
1301             rinv02           = gmx_mm_invsqrt_ps(rsq02);
1302             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1303             rinv11           = gmx_mm_invsqrt_ps(rsq11);
1304             rinv12           = gmx_mm_invsqrt_ps(rsq12);
1305             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1306             rinv21           = gmx_mm_invsqrt_ps(rsq21);
1307             rinv22           = gmx_mm_invsqrt_ps(rsq22);
1308
1309             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1310             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1311             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1312             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1313             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1314             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1315             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1316             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1317             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1318
1319             fjx0             = _mm_setzero_ps();
1320             fjy0             = _mm_setzero_ps();
1321             fjz0             = _mm_setzero_ps();
1322             fjx1             = _mm_setzero_ps();
1323             fjy1             = _mm_setzero_ps();
1324             fjz1             = _mm_setzero_ps();
1325             fjx2             = _mm_setzero_ps();
1326             fjy2             = _mm_setzero_ps();
1327             fjz2             = _mm_setzero_ps();
1328
1329             /**************************
1330              * CALCULATE INTERACTIONS *
1331              **************************/
1332
1333             /* REACTION-FIELD ELECTROSTATICS */
1334             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
1335
1336             fscal            = felec;
1337
1338             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1339
1340              /* Update vectorial force */
1341             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1342             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1343             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1344
1345             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1346             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1347             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1348
1349             /**************************
1350              * CALCULATE INTERACTIONS *
1351              **************************/
1352
1353             /* REACTION-FIELD ELECTROSTATICS */
1354             felec            = _mm_mul_ps(qq01,_mm_msub_ps(rinv01,rinvsq01,krf2));
1355
1356             fscal            = felec;
1357
1358             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1359
1360              /* Update vectorial force */
1361             fix0             = _mm_macc_ps(dx01,fscal,fix0);
1362             fiy0             = _mm_macc_ps(dy01,fscal,fiy0);
1363             fiz0             = _mm_macc_ps(dz01,fscal,fiz0);
1364
1365             fjx1             = _mm_macc_ps(dx01,fscal,fjx1);
1366             fjy1             = _mm_macc_ps(dy01,fscal,fjy1);
1367             fjz1             = _mm_macc_ps(dz01,fscal,fjz1);
1368
1369             /**************************
1370              * CALCULATE INTERACTIONS *
1371              **************************/
1372
1373             /* REACTION-FIELD ELECTROSTATICS */
1374             felec            = _mm_mul_ps(qq02,_mm_msub_ps(rinv02,rinvsq02,krf2));
1375
1376             fscal            = felec;
1377
1378             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1379
1380              /* Update vectorial force */
1381             fix0             = _mm_macc_ps(dx02,fscal,fix0);
1382             fiy0             = _mm_macc_ps(dy02,fscal,fiy0);
1383             fiz0             = _mm_macc_ps(dz02,fscal,fiz0);
1384
1385             fjx2             = _mm_macc_ps(dx02,fscal,fjx2);
1386             fjy2             = _mm_macc_ps(dy02,fscal,fjy2);
1387             fjz2             = _mm_macc_ps(dz02,fscal,fjz2);
1388
1389             /**************************
1390              * CALCULATE INTERACTIONS *
1391              **************************/
1392
1393             /* REACTION-FIELD ELECTROSTATICS */
1394             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1395
1396             fscal            = felec;
1397
1398             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1399
1400              /* Update vectorial force */
1401             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1402             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1403             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1404
1405             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1406             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1407             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1408
1409             /**************************
1410              * CALCULATE INTERACTIONS *
1411              **************************/
1412
1413             /* REACTION-FIELD ELECTROSTATICS */
1414             felec            = _mm_mul_ps(qq11,_mm_msub_ps(rinv11,rinvsq11,krf2));
1415
1416             fscal            = felec;
1417
1418             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1419
1420              /* Update vectorial force */
1421             fix1             = _mm_macc_ps(dx11,fscal,fix1);
1422             fiy1             = _mm_macc_ps(dy11,fscal,fiy1);
1423             fiz1             = _mm_macc_ps(dz11,fscal,fiz1);
1424
1425             fjx1             = _mm_macc_ps(dx11,fscal,fjx1);
1426             fjy1             = _mm_macc_ps(dy11,fscal,fjy1);
1427             fjz1             = _mm_macc_ps(dz11,fscal,fjz1);
1428
1429             /**************************
1430              * CALCULATE INTERACTIONS *
1431              **************************/
1432
1433             /* REACTION-FIELD ELECTROSTATICS */
1434             felec            = _mm_mul_ps(qq12,_mm_msub_ps(rinv12,rinvsq12,krf2));
1435
1436             fscal            = felec;
1437
1438             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1439
1440              /* Update vectorial force */
1441             fix1             = _mm_macc_ps(dx12,fscal,fix1);
1442             fiy1             = _mm_macc_ps(dy12,fscal,fiy1);
1443             fiz1             = _mm_macc_ps(dz12,fscal,fiz1);
1444
1445             fjx2             = _mm_macc_ps(dx12,fscal,fjx2);
1446             fjy2             = _mm_macc_ps(dy12,fscal,fjy2);
1447             fjz2             = _mm_macc_ps(dz12,fscal,fjz2);
1448
1449             /**************************
1450              * CALCULATE INTERACTIONS *
1451              **************************/
1452
1453             /* REACTION-FIELD ELECTROSTATICS */
1454             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1455
1456             fscal            = felec;
1457
1458             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1459
1460              /* Update vectorial force */
1461             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1462             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1463             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1464
1465             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1466             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1467             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1468
1469             /**************************
1470              * CALCULATE INTERACTIONS *
1471              **************************/
1472
1473             /* REACTION-FIELD ELECTROSTATICS */
1474             felec            = _mm_mul_ps(qq21,_mm_msub_ps(rinv21,rinvsq21,krf2));
1475
1476             fscal            = felec;
1477
1478             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1479
1480              /* Update vectorial force */
1481             fix2             = _mm_macc_ps(dx21,fscal,fix2);
1482             fiy2             = _mm_macc_ps(dy21,fscal,fiy2);
1483             fiz2             = _mm_macc_ps(dz21,fscal,fiz2);
1484
1485             fjx1             = _mm_macc_ps(dx21,fscal,fjx1);
1486             fjy1             = _mm_macc_ps(dy21,fscal,fjy1);
1487             fjz1             = _mm_macc_ps(dz21,fscal,fjz1);
1488
1489             /**************************
1490              * CALCULATE INTERACTIONS *
1491              **************************/
1492
1493             /* REACTION-FIELD ELECTROSTATICS */
1494             felec            = _mm_mul_ps(qq22,_mm_msub_ps(rinv22,rinvsq22,krf2));
1495
1496             fscal            = felec;
1497
1498             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1499
1500              /* Update vectorial force */
1501             fix2             = _mm_macc_ps(dx22,fscal,fix2);
1502             fiy2             = _mm_macc_ps(dy22,fscal,fiy2);
1503             fiz2             = _mm_macc_ps(dz22,fscal,fiz2);
1504
1505             fjx2             = _mm_macc_ps(dx22,fscal,fjx2);
1506             fjy2             = _mm_macc_ps(dy22,fscal,fjy2);
1507             fjz2             = _mm_macc_ps(dz22,fscal,fjz2);
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,fjptrB,fjptrC,fjptrD,
1515                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1516
1517             /* Inner loop uses 270 flops */
1518         }
1519
1520         /* End of innermost loop */
1521
1522         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1523                                               f+i_coord_offset,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_W3W3_F,outeriter*18 + inneriter*270);
1537 }