Added option to gmx nmeig to print ZPE.
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_single / nb_kernel_ElecRFCut_VdwNone_GeomW3W3_sse2_single.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2017, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS sse2_single kernel generator.
37  */
38 #include "gmxpre.h"
39
40 #include "config.h"
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "gromacs/gmxlib/nrnb.h"
46
47 #include "kernelutil_x86_sse2_single.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW3W3_VF_sse2_single
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            None
53  * Geometry:                   Water3-Water3
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRFCut_VdwNone_GeomW3W3_VF_sse2_single
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      struct t_forcerec           * gmx_restrict          fr,
62                      t_mdatoms                   * gmx_restrict     mdatoms,
63                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
64                      t_nrnb                      * gmx_restrict        nrnb)
65 {
66     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
67      * just 0 for non-waters.
68      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
69      * jnr indices corresponding to data put in the four positions in the SIMD register.
70      */
71     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
72     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
73     int              jnrA,jnrB,jnrC,jnrD;
74     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
75     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
80     real             scratch[4*DIM];
81     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
82     int              vdwioffset0;
83     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
84     int              vdwioffset1;
85     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
86     int              vdwioffset2;
87     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
89     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
91     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
92     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
93     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
94     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
95     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
96     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
97     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
98     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
99     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
100     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
101     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
102     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
103     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
104     real             *charge;
105     __m128           dummy_mask,cutoff_mask;
106     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
107     __m128           one     = _mm_set1_ps(1.0);
108     __m128           two     = _mm_set1_ps(2.0);
109     x                = xx[0];
110     f                = ff[0];
111
112     nri              = nlist->nri;
113     iinr             = nlist->iinr;
114     jindex           = nlist->jindex;
115     jjnr             = nlist->jjnr;
116     shiftidx         = nlist->shift;
117     gid              = nlist->gid;
118     shiftvec         = fr->shift_vec[0];
119     fshift           = fr->fshift[0];
120     facel            = _mm_set1_ps(fr->ic->epsfac);
121     charge           = mdatoms->chargeA;
122     krf              = _mm_set1_ps(fr->ic->k_rf);
123     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
124     crf              = _mm_set1_ps(fr->ic->c_rf);
125
126     /* Setup water-specific parameters */
127     inr              = nlist->iinr[0];
128     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
129     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
130     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
131
132     jq0              = _mm_set1_ps(charge[inr+0]);
133     jq1              = _mm_set1_ps(charge[inr+1]);
134     jq2              = _mm_set1_ps(charge[inr+2]);
135     qq00             = _mm_mul_ps(iq0,jq0);
136     qq01             = _mm_mul_ps(iq0,jq1);
137     qq02             = _mm_mul_ps(iq0,jq2);
138     qq10             = _mm_mul_ps(iq1,jq0);
139     qq11             = _mm_mul_ps(iq1,jq1);
140     qq12             = _mm_mul_ps(iq1,jq2);
141     qq20             = _mm_mul_ps(iq2,jq0);
142     qq21             = _mm_mul_ps(iq2,jq1);
143     qq22             = _mm_mul_ps(iq2,jq2);
144
145     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
146     rcutoff_scalar   = fr->ic->rcoulomb;
147     rcutoff          = _mm_set1_ps(rcutoff_scalar);
148     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
149
150     /* Avoid stupid compiler warnings */
151     jnrA = jnrB = jnrC = jnrD = 0;
152     j_coord_offsetA = 0;
153     j_coord_offsetB = 0;
154     j_coord_offsetC = 0;
155     j_coord_offsetD = 0;
156
157     outeriter        = 0;
158     inneriter        = 0;
159
160     for(iidx=0;iidx<4*DIM;iidx++)
161     {
162         scratch[iidx] = 0.0;
163     }  
164
165     /* Start outer loop over neighborlists */
166     for(iidx=0; iidx<nri; iidx++)
167     {
168         /* Load shift vector for this list */
169         i_shift_offset   = DIM*shiftidx[iidx];
170
171         /* Load limits for loop over neighbors */
172         j_index_start    = jindex[iidx];
173         j_index_end      = jindex[iidx+1];
174
175         /* Get outer coordinate index */
176         inr              = iinr[iidx];
177         i_coord_offset   = DIM*inr;
178
179         /* Load i particle coords and add shift vector */
180         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
181                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
182         
183         fix0             = _mm_setzero_ps();
184         fiy0             = _mm_setzero_ps();
185         fiz0             = _mm_setzero_ps();
186         fix1             = _mm_setzero_ps();
187         fiy1             = _mm_setzero_ps();
188         fiz1             = _mm_setzero_ps();
189         fix2             = _mm_setzero_ps();
190         fiy2             = _mm_setzero_ps();
191         fiz2             = _mm_setzero_ps();
192
193         /* Reset potential sums */
194         velecsum         = _mm_setzero_ps();
195
196         /* Start inner kernel loop */
197         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
198         {
199
200             /* Get j neighbor index, and coordinate index */
201             jnrA             = jjnr[jidx];
202             jnrB             = jjnr[jidx+1];
203             jnrC             = jjnr[jidx+2];
204             jnrD             = jjnr[jidx+3];
205             j_coord_offsetA  = DIM*jnrA;
206             j_coord_offsetB  = DIM*jnrB;
207             j_coord_offsetC  = DIM*jnrC;
208             j_coord_offsetD  = DIM*jnrD;
209
210             /* load j atom coordinates */
211             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
212                                               x+j_coord_offsetC,x+j_coord_offsetD,
213                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
214
215             /* Calculate displacement vector */
216             dx00             = _mm_sub_ps(ix0,jx0);
217             dy00             = _mm_sub_ps(iy0,jy0);
218             dz00             = _mm_sub_ps(iz0,jz0);
219             dx01             = _mm_sub_ps(ix0,jx1);
220             dy01             = _mm_sub_ps(iy0,jy1);
221             dz01             = _mm_sub_ps(iz0,jz1);
222             dx02             = _mm_sub_ps(ix0,jx2);
223             dy02             = _mm_sub_ps(iy0,jy2);
224             dz02             = _mm_sub_ps(iz0,jz2);
225             dx10             = _mm_sub_ps(ix1,jx0);
226             dy10             = _mm_sub_ps(iy1,jy0);
227             dz10             = _mm_sub_ps(iz1,jz0);
228             dx11             = _mm_sub_ps(ix1,jx1);
229             dy11             = _mm_sub_ps(iy1,jy1);
230             dz11             = _mm_sub_ps(iz1,jz1);
231             dx12             = _mm_sub_ps(ix1,jx2);
232             dy12             = _mm_sub_ps(iy1,jy2);
233             dz12             = _mm_sub_ps(iz1,jz2);
234             dx20             = _mm_sub_ps(ix2,jx0);
235             dy20             = _mm_sub_ps(iy2,jy0);
236             dz20             = _mm_sub_ps(iz2,jz0);
237             dx21             = _mm_sub_ps(ix2,jx1);
238             dy21             = _mm_sub_ps(iy2,jy1);
239             dz21             = _mm_sub_ps(iz2,jz1);
240             dx22             = _mm_sub_ps(ix2,jx2);
241             dy22             = _mm_sub_ps(iy2,jy2);
242             dz22             = _mm_sub_ps(iz2,jz2);
243
244             /* Calculate squared distance and things based on it */
245             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
246             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
247             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
248             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
249             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
250             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
251             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
252             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
253             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
254
255             rinv00           = sse2_invsqrt_f(rsq00);
256             rinv01           = sse2_invsqrt_f(rsq01);
257             rinv02           = sse2_invsqrt_f(rsq02);
258             rinv10           = sse2_invsqrt_f(rsq10);
259             rinv11           = sse2_invsqrt_f(rsq11);
260             rinv12           = sse2_invsqrt_f(rsq12);
261             rinv20           = sse2_invsqrt_f(rsq20);
262             rinv21           = sse2_invsqrt_f(rsq21);
263             rinv22           = sse2_invsqrt_f(rsq22);
264
265             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
266             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
267             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
268             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
269             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
270             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
271             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
272             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
273             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
274
275             fjx0             = _mm_setzero_ps();
276             fjy0             = _mm_setzero_ps();
277             fjz0             = _mm_setzero_ps();
278             fjx1             = _mm_setzero_ps();
279             fjy1             = _mm_setzero_ps();
280             fjz1             = _mm_setzero_ps();
281             fjx2             = _mm_setzero_ps();
282             fjy2             = _mm_setzero_ps();
283             fjz2             = _mm_setzero_ps();
284
285             /**************************
286              * CALCULATE INTERACTIONS *
287              **************************/
288
289             if (gmx_mm_any_lt(rsq00,rcutoff2))
290             {
291
292             /* REACTION-FIELD ELECTROSTATICS */
293             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
294             felec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
295
296             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
297
298             /* Update potential sum for this i atom from the interaction with this j atom. */
299             velec            = _mm_and_ps(velec,cutoff_mask);
300             velecsum         = _mm_add_ps(velecsum,velec);
301
302             fscal            = felec;
303
304             fscal            = _mm_and_ps(fscal,cutoff_mask);
305
306             /* Calculate temporary vectorial force */
307             tx               = _mm_mul_ps(fscal,dx00);
308             ty               = _mm_mul_ps(fscal,dy00);
309             tz               = _mm_mul_ps(fscal,dz00);
310
311             /* Update vectorial force */
312             fix0             = _mm_add_ps(fix0,tx);
313             fiy0             = _mm_add_ps(fiy0,ty);
314             fiz0             = _mm_add_ps(fiz0,tz);
315
316             fjx0             = _mm_add_ps(fjx0,tx);
317             fjy0             = _mm_add_ps(fjy0,ty);
318             fjz0             = _mm_add_ps(fjz0,tz);
319             
320             }
321
322             /**************************
323              * CALCULATE INTERACTIONS *
324              **************************/
325
326             if (gmx_mm_any_lt(rsq01,rcutoff2))
327             {
328
329             /* REACTION-FIELD ELECTROSTATICS */
330             velec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
331             felec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
332
333             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
334
335             /* Update potential sum for this i atom from the interaction with this j atom. */
336             velec            = _mm_and_ps(velec,cutoff_mask);
337             velecsum         = _mm_add_ps(velecsum,velec);
338
339             fscal            = felec;
340
341             fscal            = _mm_and_ps(fscal,cutoff_mask);
342
343             /* Calculate temporary vectorial force */
344             tx               = _mm_mul_ps(fscal,dx01);
345             ty               = _mm_mul_ps(fscal,dy01);
346             tz               = _mm_mul_ps(fscal,dz01);
347
348             /* Update vectorial force */
349             fix0             = _mm_add_ps(fix0,tx);
350             fiy0             = _mm_add_ps(fiy0,ty);
351             fiz0             = _mm_add_ps(fiz0,tz);
352
353             fjx1             = _mm_add_ps(fjx1,tx);
354             fjy1             = _mm_add_ps(fjy1,ty);
355             fjz1             = _mm_add_ps(fjz1,tz);
356             
357             }
358
359             /**************************
360              * CALCULATE INTERACTIONS *
361              **************************/
362
363             if (gmx_mm_any_lt(rsq02,rcutoff2))
364             {
365
366             /* REACTION-FIELD ELECTROSTATICS */
367             velec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
368             felec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
369
370             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
371
372             /* Update potential sum for this i atom from the interaction with this j atom. */
373             velec            = _mm_and_ps(velec,cutoff_mask);
374             velecsum         = _mm_add_ps(velecsum,velec);
375
376             fscal            = felec;
377
378             fscal            = _mm_and_ps(fscal,cutoff_mask);
379
380             /* Calculate temporary vectorial force */
381             tx               = _mm_mul_ps(fscal,dx02);
382             ty               = _mm_mul_ps(fscal,dy02);
383             tz               = _mm_mul_ps(fscal,dz02);
384
385             /* Update vectorial force */
386             fix0             = _mm_add_ps(fix0,tx);
387             fiy0             = _mm_add_ps(fiy0,ty);
388             fiz0             = _mm_add_ps(fiz0,tz);
389
390             fjx2             = _mm_add_ps(fjx2,tx);
391             fjy2             = _mm_add_ps(fjy2,ty);
392             fjz2             = _mm_add_ps(fjz2,tz);
393             
394             }
395
396             /**************************
397              * CALCULATE INTERACTIONS *
398              **************************/
399
400             if (gmx_mm_any_lt(rsq10,rcutoff2))
401             {
402
403             /* REACTION-FIELD ELECTROSTATICS */
404             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
405             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
406
407             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
408
409             /* Update potential sum for this i atom from the interaction with this j atom. */
410             velec            = _mm_and_ps(velec,cutoff_mask);
411             velecsum         = _mm_add_ps(velecsum,velec);
412
413             fscal            = felec;
414
415             fscal            = _mm_and_ps(fscal,cutoff_mask);
416
417             /* Calculate temporary vectorial force */
418             tx               = _mm_mul_ps(fscal,dx10);
419             ty               = _mm_mul_ps(fscal,dy10);
420             tz               = _mm_mul_ps(fscal,dz10);
421
422             /* Update vectorial force */
423             fix1             = _mm_add_ps(fix1,tx);
424             fiy1             = _mm_add_ps(fiy1,ty);
425             fiz1             = _mm_add_ps(fiz1,tz);
426
427             fjx0             = _mm_add_ps(fjx0,tx);
428             fjy0             = _mm_add_ps(fjy0,ty);
429             fjz0             = _mm_add_ps(fjz0,tz);
430             
431             }
432
433             /**************************
434              * CALCULATE INTERACTIONS *
435              **************************/
436
437             if (gmx_mm_any_lt(rsq11,rcutoff2))
438             {
439
440             /* REACTION-FIELD ELECTROSTATICS */
441             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
442             felec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
443
444             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
445
446             /* Update potential sum for this i atom from the interaction with this j atom. */
447             velec            = _mm_and_ps(velec,cutoff_mask);
448             velecsum         = _mm_add_ps(velecsum,velec);
449
450             fscal            = felec;
451
452             fscal            = _mm_and_ps(fscal,cutoff_mask);
453
454             /* Calculate temporary vectorial force */
455             tx               = _mm_mul_ps(fscal,dx11);
456             ty               = _mm_mul_ps(fscal,dy11);
457             tz               = _mm_mul_ps(fscal,dz11);
458
459             /* Update vectorial force */
460             fix1             = _mm_add_ps(fix1,tx);
461             fiy1             = _mm_add_ps(fiy1,ty);
462             fiz1             = _mm_add_ps(fiz1,tz);
463
464             fjx1             = _mm_add_ps(fjx1,tx);
465             fjy1             = _mm_add_ps(fjy1,ty);
466             fjz1             = _mm_add_ps(fjz1,tz);
467             
468             }
469
470             /**************************
471              * CALCULATE INTERACTIONS *
472              **************************/
473
474             if (gmx_mm_any_lt(rsq12,rcutoff2))
475             {
476
477             /* REACTION-FIELD ELECTROSTATICS */
478             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
479             felec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
480
481             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
482
483             /* Update potential sum for this i atom from the interaction with this j atom. */
484             velec            = _mm_and_ps(velec,cutoff_mask);
485             velecsum         = _mm_add_ps(velecsum,velec);
486
487             fscal            = felec;
488
489             fscal            = _mm_and_ps(fscal,cutoff_mask);
490
491             /* Calculate temporary vectorial force */
492             tx               = _mm_mul_ps(fscal,dx12);
493             ty               = _mm_mul_ps(fscal,dy12);
494             tz               = _mm_mul_ps(fscal,dz12);
495
496             /* Update vectorial force */
497             fix1             = _mm_add_ps(fix1,tx);
498             fiy1             = _mm_add_ps(fiy1,ty);
499             fiz1             = _mm_add_ps(fiz1,tz);
500
501             fjx2             = _mm_add_ps(fjx2,tx);
502             fjy2             = _mm_add_ps(fjy2,ty);
503             fjz2             = _mm_add_ps(fjz2,tz);
504             
505             }
506
507             /**************************
508              * CALCULATE INTERACTIONS *
509              **************************/
510
511             if (gmx_mm_any_lt(rsq20,rcutoff2))
512             {
513
514             /* REACTION-FIELD ELECTROSTATICS */
515             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
516             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
517
518             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
519
520             /* Update potential sum for this i atom from the interaction with this j atom. */
521             velec            = _mm_and_ps(velec,cutoff_mask);
522             velecsum         = _mm_add_ps(velecsum,velec);
523
524             fscal            = felec;
525
526             fscal            = _mm_and_ps(fscal,cutoff_mask);
527
528             /* Calculate temporary vectorial force */
529             tx               = _mm_mul_ps(fscal,dx20);
530             ty               = _mm_mul_ps(fscal,dy20);
531             tz               = _mm_mul_ps(fscal,dz20);
532
533             /* Update vectorial force */
534             fix2             = _mm_add_ps(fix2,tx);
535             fiy2             = _mm_add_ps(fiy2,ty);
536             fiz2             = _mm_add_ps(fiz2,tz);
537
538             fjx0             = _mm_add_ps(fjx0,tx);
539             fjy0             = _mm_add_ps(fjy0,ty);
540             fjz0             = _mm_add_ps(fjz0,tz);
541             
542             }
543
544             /**************************
545              * CALCULATE INTERACTIONS *
546              **************************/
547
548             if (gmx_mm_any_lt(rsq21,rcutoff2))
549             {
550
551             /* REACTION-FIELD ELECTROSTATICS */
552             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
553             felec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
554
555             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
556
557             /* Update potential sum for this i atom from the interaction with this j atom. */
558             velec            = _mm_and_ps(velec,cutoff_mask);
559             velecsum         = _mm_add_ps(velecsum,velec);
560
561             fscal            = felec;
562
563             fscal            = _mm_and_ps(fscal,cutoff_mask);
564
565             /* Calculate temporary vectorial force */
566             tx               = _mm_mul_ps(fscal,dx21);
567             ty               = _mm_mul_ps(fscal,dy21);
568             tz               = _mm_mul_ps(fscal,dz21);
569
570             /* Update vectorial force */
571             fix2             = _mm_add_ps(fix2,tx);
572             fiy2             = _mm_add_ps(fiy2,ty);
573             fiz2             = _mm_add_ps(fiz2,tz);
574
575             fjx1             = _mm_add_ps(fjx1,tx);
576             fjy1             = _mm_add_ps(fjy1,ty);
577             fjz1             = _mm_add_ps(fjz1,tz);
578             
579             }
580
581             /**************************
582              * CALCULATE INTERACTIONS *
583              **************************/
584
585             if (gmx_mm_any_lt(rsq22,rcutoff2))
586             {
587
588             /* REACTION-FIELD ELECTROSTATICS */
589             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
590             felec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
591
592             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
593
594             /* Update potential sum for this i atom from the interaction with this j atom. */
595             velec            = _mm_and_ps(velec,cutoff_mask);
596             velecsum         = _mm_add_ps(velecsum,velec);
597
598             fscal            = felec;
599
600             fscal            = _mm_and_ps(fscal,cutoff_mask);
601
602             /* Calculate temporary vectorial force */
603             tx               = _mm_mul_ps(fscal,dx22);
604             ty               = _mm_mul_ps(fscal,dy22);
605             tz               = _mm_mul_ps(fscal,dz22);
606
607             /* Update vectorial force */
608             fix2             = _mm_add_ps(fix2,tx);
609             fiy2             = _mm_add_ps(fiy2,ty);
610             fiz2             = _mm_add_ps(fiz2,tz);
611
612             fjx2             = _mm_add_ps(fjx2,tx);
613             fjy2             = _mm_add_ps(fjy2,ty);
614             fjz2             = _mm_add_ps(fjz2,tz);
615             
616             }
617
618             fjptrA             = f+j_coord_offsetA;
619             fjptrB             = f+j_coord_offsetB;
620             fjptrC             = f+j_coord_offsetC;
621             fjptrD             = f+j_coord_offsetD;
622
623             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
624                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
625
626             /* Inner loop uses 324 flops */
627         }
628
629         if(jidx<j_index_end)
630         {
631
632             /* Get j neighbor index, and coordinate index */
633             jnrlistA         = jjnr[jidx];
634             jnrlistB         = jjnr[jidx+1];
635             jnrlistC         = jjnr[jidx+2];
636             jnrlistD         = jjnr[jidx+3];
637             /* Sign of each element will be negative for non-real atoms.
638              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
639              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
640              */
641             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
642             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
643             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
644             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
645             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
646             j_coord_offsetA  = DIM*jnrA;
647             j_coord_offsetB  = DIM*jnrB;
648             j_coord_offsetC  = DIM*jnrC;
649             j_coord_offsetD  = DIM*jnrD;
650
651             /* load j atom coordinates */
652             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
653                                               x+j_coord_offsetC,x+j_coord_offsetD,
654                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
655
656             /* Calculate displacement vector */
657             dx00             = _mm_sub_ps(ix0,jx0);
658             dy00             = _mm_sub_ps(iy0,jy0);
659             dz00             = _mm_sub_ps(iz0,jz0);
660             dx01             = _mm_sub_ps(ix0,jx1);
661             dy01             = _mm_sub_ps(iy0,jy1);
662             dz01             = _mm_sub_ps(iz0,jz1);
663             dx02             = _mm_sub_ps(ix0,jx2);
664             dy02             = _mm_sub_ps(iy0,jy2);
665             dz02             = _mm_sub_ps(iz0,jz2);
666             dx10             = _mm_sub_ps(ix1,jx0);
667             dy10             = _mm_sub_ps(iy1,jy0);
668             dz10             = _mm_sub_ps(iz1,jz0);
669             dx11             = _mm_sub_ps(ix1,jx1);
670             dy11             = _mm_sub_ps(iy1,jy1);
671             dz11             = _mm_sub_ps(iz1,jz1);
672             dx12             = _mm_sub_ps(ix1,jx2);
673             dy12             = _mm_sub_ps(iy1,jy2);
674             dz12             = _mm_sub_ps(iz1,jz2);
675             dx20             = _mm_sub_ps(ix2,jx0);
676             dy20             = _mm_sub_ps(iy2,jy0);
677             dz20             = _mm_sub_ps(iz2,jz0);
678             dx21             = _mm_sub_ps(ix2,jx1);
679             dy21             = _mm_sub_ps(iy2,jy1);
680             dz21             = _mm_sub_ps(iz2,jz1);
681             dx22             = _mm_sub_ps(ix2,jx2);
682             dy22             = _mm_sub_ps(iy2,jy2);
683             dz22             = _mm_sub_ps(iz2,jz2);
684
685             /* Calculate squared distance and things based on it */
686             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
687             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
688             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
689             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
690             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
691             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
692             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
693             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
694             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
695
696             rinv00           = sse2_invsqrt_f(rsq00);
697             rinv01           = sse2_invsqrt_f(rsq01);
698             rinv02           = sse2_invsqrt_f(rsq02);
699             rinv10           = sse2_invsqrt_f(rsq10);
700             rinv11           = sse2_invsqrt_f(rsq11);
701             rinv12           = sse2_invsqrt_f(rsq12);
702             rinv20           = sse2_invsqrt_f(rsq20);
703             rinv21           = sse2_invsqrt_f(rsq21);
704             rinv22           = sse2_invsqrt_f(rsq22);
705
706             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
707             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
708             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
709             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
710             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
711             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
712             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
713             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
714             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
715
716             fjx0             = _mm_setzero_ps();
717             fjy0             = _mm_setzero_ps();
718             fjz0             = _mm_setzero_ps();
719             fjx1             = _mm_setzero_ps();
720             fjy1             = _mm_setzero_ps();
721             fjz1             = _mm_setzero_ps();
722             fjx2             = _mm_setzero_ps();
723             fjy2             = _mm_setzero_ps();
724             fjz2             = _mm_setzero_ps();
725
726             /**************************
727              * CALCULATE INTERACTIONS *
728              **************************/
729
730             if (gmx_mm_any_lt(rsq00,rcutoff2))
731             {
732
733             /* REACTION-FIELD ELECTROSTATICS */
734             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_add_ps(rinv00,_mm_mul_ps(krf,rsq00)),crf));
735             felec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
736
737             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
738
739             /* Update potential sum for this i atom from the interaction with this j atom. */
740             velec            = _mm_and_ps(velec,cutoff_mask);
741             velec            = _mm_andnot_ps(dummy_mask,velec);
742             velecsum         = _mm_add_ps(velecsum,velec);
743
744             fscal            = felec;
745
746             fscal            = _mm_and_ps(fscal,cutoff_mask);
747
748             fscal            = _mm_andnot_ps(dummy_mask,fscal);
749
750             /* Calculate temporary vectorial force */
751             tx               = _mm_mul_ps(fscal,dx00);
752             ty               = _mm_mul_ps(fscal,dy00);
753             tz               = _mm_mul_ps(fscal,dz00);
754
755             /* Update vectorial force */
756             fix0             = _mm_add_ps(fix0,tx);
757             fiy0             = _mm_add_ps(fiy0,ty);
758             fiz0             = _mm_add_ps(fiz0,tz);
759
760             fjx0             = _mm_add_ps(fjx0,tx);
761             fjy0             = _mm_add_ps(fjy0,ty);
762             fjz0             = _mm_add_ps(fjz0,tz);
763             
764             }
765
766             /**************************
767              * CALCULATE INTERACTIONS *
768              **************************/
769
770             if (gmx_mm_any_lt(rsq01,rcutoff2))
771             {
772
773             /* REACTION-FIELD ELECTROSTATICS */
774             velec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_add_ps(rinv01,_mm_mul_ps(krf,rsq01)),crf));
775             felec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
776
777             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
778
779             /* Update potential sum for this i atom from the interaction with this j atom. */
780             velec            = _mm_and_ps(velec,cutoff_mask);
781             velec            = _mm_andnot_ps(dummy_mask,velec);
782             velecsum         = _mm_add_ps(velecsum,velec);
783
784             fscal            = felec;
785
786             fscal            = _mm_and_ps(fscal,cutoff_mask);
787
788             fscal            = _mm_andnot_ps(dummy_mask,fscal);
789
790             /* Calculate temporary vectorial force */
791             tx               = _mm_mul_ps(fscal,dx01);
792             ty               = _mm_mul_ps(fscal,dy01);
793             tz               = _mm_mul_ps(fscal,dz01);
794
795             /* Update vectorial force */
796             fix0             = _mm_add_ps(fix0,tx);
797             fiy0             = _mm_add_ps(fiy0,ty);
798             fiz0             = _mm_add_ps(fiz0,tz);
799
800             fjx1             = _mm_add_ps(fjx1,tx);
801             fjy1             = _mm_add_ps(fjy1,ty);
802             fjz1             = _mm_add_ps(fjz1,tz);
803             
804             }
805
806             /**************************
807              * CALCULATE INTERACTIONS *
808              **************************/
809
810             if (gmx_mm_any_lt(rsq02,rcutoff2))
811             {
812
813             /* REACTION-FIELD ELECTROSTATICS */
814             velec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_add_ps(rinv02,_mm_mul_ps(krf,rsq02)),crf));
815             felec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
816
817             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
818
819             /* Update potential sum for this i atom from the interaction with this j atom. */
820             velec            = _mm_and_ps(velec,cutoff_mask);
821             velec            = _mm_andnot_ps(dummy_mask,velec);
822             velecsum         = _mm_add_ps(velecsum,velec);
823
824             fscal            = felec;
825
826             fscal            = _mm_and_ps(fscal,cutoff_mask);
827
828             fscal            = _mm_andnot_ps(dummy_mask,fscal);
829
830             /* Calculate temporary vectorial force */
831             tx               = _mm_mul_ps(fscal,dx02);
832             ty               = _mm_mul_ps(fscal,dy02);
833             tz               = _mm_mul_ps(fscal,dz02);
834
835             /* Update vectorial force */
836             fix0             = _mm_add_ps(fix0,tx);
837             fiy0             = _mm_add_ps(fiy0,ty);
838             fiz0             = _mm_add_ps(fiz0,tz);
839
840             fjx2             = _mm_add_ps(fjx2,tx);
841             fjy2             = _mm_add_ps(fjy2,ty);
842             fjz2             = _mm_add_ps(fjz2,tz);
843             
844             }
845
846             /**************************
847              * CALCULATE INTERACTIONS *
848              **************************/
849
850             if (gmx_mm_any_lt(rsq10,rcutoff2))
851             {
852
853             /* REACTION-FIELD ELECTROSTATICS */
854             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_add_ps(rinv10,_mm_mul_ps(krf,rsq10)),crf));
855             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
856
857             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
858
859             /* Update potential sum for this i atom from the interaction with this j atom. */
860             velec            = _mm_and_ps(velec,cutoff_mask);
861             velec            = _mm_andnot_ps(dummy_mask,velec);
862             velecsum         = _mm_add_ps(velecsum,velec);
863
864             fscal            = felec;
865
866             fscal            = _mm_and_ps(fscal,cutoff_mask);
867
868             fscal            = _mm_andnot_ps(dummy_mask,fscal);
869
870             /* Calculate temporary vectorial force */
871             tx               = _mm_mul_ps(fscal,dx10);
872             ty               = _mm_mul_ps(fscal,dy10);
873             tz               = _mm_mul_ps(fscal,dz10);
874
875             /* Update vectorial force */
876             fix1             = _mm_add_ps(fix1,tx);
877             fiy1             = _mm_add_ps(fiy1,ty);
878             fiz1             = _mm_add_ps(fiz1,tz);
879
880             fjx0             = _mm_add_ps(fjx0,tx);
881             fjy0             = _mm_add_ps(fjy0,ty);
882             fjz0             = _mm_add_ps(fjz0,tz);
883             
884             }
885
886             /**************************
887              * CALCULATE INTERACTIONS *
888              **************************/
889
890             if (gmx_mm_any_lt(rsq11,rcutoff2))
891             {
892
893             /* REACTION-FIELD ELECTROSTATICS */
894             velec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_add_ps(rinv11,_mm_mul_ps(krf,rsq11)),crf));
895             felec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
896
897             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
898
899             /* Update potential sum for this i atom from the interaction with this j atom. */
900             velec            = _mm_and_ps(velec,cutoff_mask);
901             velec            = _mm_andnot_ps(dummy_mask,velec);
902             velecsum         = _mm_add_ps(velecsum,velec);
903
904             fscal            = felec;
905
906             fscal            = _mm_and_ps(fscal,cutoff_mask);
907
908             fscal            = _mm_andnot_ps(dummy_mask,fscal);
909
910             /* Calculate temporary vectorial force */
911             tx               = _mm_mul_ps(fscal,dx11);
912             ty               = _mm_mul_ps(fscal,dy11);
913             tz               = _mm_mul_ps(fscal,dz11);
914
915             /* Update vectorial force */
916             fix1             = _mm_add_ps(fix1,tx);
917             fiy1             = _mm_add_ps(fiy1,ty);
918             fiz1             = _mm_add_ps(fiz1,tz);
919
920             fjx1             = _mm_add_ps(fjx1,tx);
921             fjy1             = _mm_add_ps(fjy1,ty);
922             fjz1             = _mm_add_ps(fjz1,tz);
923             
924             }
925
926             /**************************
927              * CALCULATE INTERACTIONS *
928              **************************/
929
930             if (gmx_mm_any_lt(rsq12,rcutoff2))
931             {
932
933             /* REACTION-FIELD ELECTROSTATICS */
934             velec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_add_ps(rinv12,_mm_mul_ps(krf,rsq12)),crf));
935             felec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
936
937             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
938
939             /* Update potential sum for this i atom from the interaction with this j atom. */
940             velec            = _mm_and_ps(velec,cutoff_mask);
941             velec            = _mm_andnot_ps(dummy_mask,velec);
942             velecsum         = _mm_add_ps(velecsum,velec);
943
944             fscal            = felec;
945
946             fscal            = _mm_and_ps(fscal,cutoff_mask);
947
948             fscal            = _mm_andnot_ps(dummy_mask,fscal);
949
950             /* Calculate temporary vectorial force */
951             tx               = _mm_mul_ps(fscal,dx12);
952             ty               = _mm_mul_ps(fscal,dy12);
953             tz               = _mm_mul_ps(fscal,dz12);
954
955             /* Update vectorial force */
956             fix1             = _mm_add_ps(fix1,tx);
957             fiy1             = _mm_add_ps(fiy1,ty);
958             fiz1             = _mm_add_ps(fiz1,tz);
959
960             fjx2             = _mm_add_ps(fjx2,tx);
961             fjy2             = _mm_add_ps(fjy2,ty);
962             fjz2             = _mm_add_ps(fjz2,tz);
963             
964             }
965
966             /**************************
967              * CALCULATE INTERACTIONS *
968              **************************/
969
970             if (gmx_mm_any_lt(rsq20,rcutoff2))
971             {
972
973             /* REACTION-FIELD ELECTROSTATICS */
974             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_add_ps(rinv20,_mm_mul_ps(krf,rsq20)),crf));
975             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
976
977             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
978
979             /* Update potential sum for this i atom from the interaction with this j atom. */
980             velec            = _mm_and_ps(velec,cutoff_mask);
981             velec            = _mm_andnot_ps(dummy_mask,velec);
982             velecsum         = _mm_add_ps(velecsum,velec);
983
984             fscal            = felec;
985
986             fscal            = _mm_and_ps(fscal,cutoff_mask);
987
988             fscal            = _mm_andnot_ps(dummy_mask,fscal);
989
990             /* Calculate temporary vectorial force */
991             tx               = _mm_mul_ps(fscal,dx20);
992             ty               = _mm_mul_ps(fscal,dy20);
993             tz               = _mm_mul_ps(fscal,dz20);
994
995             /* Update vectorial force */
996             fix2             = _mm_add_ps(fix2,tx);
997             fiy2             = _mm_add_ps(fiy2,ty);
998             fiz2             = _mm_add_ps(fiz2,tz);
999
1000             fjx0             = _mm_add_ps(fjx0,tx);
1001             fjy0             = _mm_add_ps(fjy0,ty);
1002             fjz0             = _mm_add_ps(fjz0,tz);
1003             
1004             }
1005
1006             /**************************
1007              * CALCULATE INTERACTIONS *
1008              **************************/
1009
1010             if (gmx_mm_any_lt(rsq21,rcutoff2))
1011             {
1012
1013             /* REACTION-FIELD ELECTROSTATICS */
1014             velec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_add_ps(rinv21,_mm_mul_ps(krf,rsq21)),crf));
1015             felec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1016
1017             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
1018
1019             /* Update potential sum for this i atom from the interaction with this j atom. */
1020             velec            = _mm_and_ps(velec,cutoff_mask);
1021             velec            = _mm_andnot_ps(dummy_mask,velec);
1022             velecsum         = _mm_add_ps(velecsum,velec);
1023
1024             fscal            = felec;
1025
1026             fscal            = _mm_and_ps(fscal,cutoff_mask);
1027
1028             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1029
1030             /* Calculate temporary vectorial force */
1031             tx               = _mm_mul_ps(fscal,dx21);
1032             ty               = _mm_mul_ps(fscal,dy21);
1033             tz               = _mm_mul_ps(fscal,dz21);
1034
1035             /* Update vectorial force */
1036             fix2             = _mm_add_ps(fix2,tx);
1037             fiy2             = _mm_add_ps(fiy2,ty);
1038             fiz2             = _mm_add_ps(fiz2,tz);
1039
1040             fjx1             = _mm_add_ps(fjx1,tx);
1041             fjy1             = _mm_add_ps(fjy1,ty);
1042             fjz1             = _mm_add_ps(fjz1,tz);
1043             
1044             }
1045
1046             /**************************
1047              * CALCULATE INTERACTIONS *
1048              **************************/
1049
1050             if (gmx_mm_any_lt(rsq22,rcutoff2))
1051             {
1052
1053             /* REACTION-FIELD ELECTROSTATICS */
1054             velec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_add_ps(rinv22,_mm_mul_ps(krf,rsq22)),crf));
1055             felec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1056
1057             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
1058
1059             /* Update potential sum for this i atom from the interaction with this j atom. */
1060             velec            = _mm_and_ps(velec,cutoff_mask);
1061             velec            = _mm_andnot_ps(dummy_mask,velec);
1062             velecsum         = _mm_add_ps(velecsum,velec);
1063
1064             fscal            = felec;
1065
1066             fscal            = _mm_and_ps(fscal,cutoff_mask);
1067
1068             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1069
1070             /* Calculate temporary vectorial force */
1071             tx               = _mm_mul_ps(fscal,dx22);
1072             ty               = _mm_mul_ps(fscal,dy22);
1073             tz               = _mm_mul_ps(fscal,dz22);
1074
1075             /* Update vectorial force */
1076             fix2             = _mm_add_ps(fix2,tx);
1077             fiy2             = _mm_add_ps(fiy2,ty);
1078             fiz2             = _mm_add_ps(fiz2,tz);
1079
1080             fjx2             = _mm_add_ps(fjx2,tx);
1081             fjy2             = _mm_add_ps(fjy2,ty);
1082             fjz2             = _mm_add_ps(fjz2,tz);
1083             
1084             }
1085
1086             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1087             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1088             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1089             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1090
1091             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1092                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1093
1094             /* Inner loop uses 324 flops */
1095         }
1096
1097         /* End of innermost loop */
1098
1099         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
1100                                               f+i_coord_offset,fshift+i_shift_offset);
1101
1102         ggid                        = gid[iidx];
1103         /* Update potential energies */
1104         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
1105
1106         /* Increment number of inner iterations */
1107         inneriter                  += j_index_end - j_index_start;
1108
1109         /* Outer loop uses 19 flops */
1110     }
1111
1112     /* Increment number of outer iterations */
1113     outeriter        += nri;
1114
1115     /* Update outer/inner flops */
1116
1117     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_VF,outeriter*19 + inneriter*324);
1118 }
1119 /*
1120  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW3W3_F_sse2_single
1121  * Electrostatics interaction: ReactionField
1122  * VdW interaction:            None
1123  * Geometry:                   Water3-Water3
1124  * Calculate force/pot:        Force
1125  */
1126 void
1127 nb_kernel_ElecRFCut_VdwNone_GeomW3W3_F_sse2_single
1128                     (t_nblist                    * gmx_restrict       nlist,
1129                      rvec                        * gmx_restrict          xx,
1130                      rvec                        * gmx_restrict          ff,
1131                      struct t_forcerec           * gmx_restrict          fr,
1132                      t_mdatoms                   * gmx_restrict     mdatoms,
1133                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
1134                      t_nrnb                      * gmx_restrict        nrnb)
1135 {
1136     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
1137      * just 0 for non-waters.
1138      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
1139      * jnr indices corresponding to data put in the four positions in the SIMD register.
1140      */
1141     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
1142     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
1143     int              jnrA,jnrB,jnrC,jnrD;
1144     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
1145     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
1146     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
1147     real             rcutoff_scalar;
1148     real             *shiftvec,*fshift,*x,*f;
1149     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
1150     real             scratch[4*DIM];
1151     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
1152     int              vdwioffset0;
1153     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
1154     int              vdwioffset1;
1155     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
1156     int              vdwioffset2;
1157     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
1158     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
1159     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
1160     int              vdwjidx1A,vdwjidx1B,vdwjidx1C,vdwjidx1D;
1161     __m128           jx1,jy1,jz1,fjx1,fjy1,fjz1,jq1,isaj1;
1162     int              vdwjidx2A,vdwjidx2B,vdwjidx2C,vdwjidx2D;
1163     __m128           jx2,jy2,jz2,fjx2,fjy2,fjz2,jq2,isaj2;
1164     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
1165     __m128           dx01,dy01,dz01,rsq01,rinv01,rinvsq01,r01,qq01,c6_01,c12_01;
1166     __m128           dx02,dy02,dz02,rsq02,rinv02,rinvsq02,r02,qq02,c6_02,c12_02;
1167     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
1168     __m128           dx11,dy11,dz11,rsq11,rinv11,rinvsq11,r11,qq11,c6_11,c12_11;
1169     __m128           dx12,dy12,dz12,rsq12,rinv12,rinvsq12,r12,qq12,c6_12,c12_12;
1170     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
1171     __m128           dx21,dy21,dz21,rsq21,rinv21,rinvsq21,r21,qq21,c6_21,c12_21;
1172     __m128           dx22,dy22,dz22,rsq22,rinv22,rinvsq22,r22,qq22,c6_22,c12_22;
1173     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
1174     real             *charge;
1175     __m128           dummy_mask,cutoff_mask;
1176     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
1177     __m128           one     = _mm_set1_ps(1.0);
1178     __m128           two     = _mm_set1_ps(2.0);
1179     x                = xx[0];
1180     f                = ff[0];
1181
1182     nri              = nlist->nri;
1183     iinr             = nlist->iinr;
1184     jindex           = nlist->jindex;
1185     jjnr             = nlist->jjnr;
1186     shiftidx         = nlist->shift;
1187     gid              = nlist->gid;
1188     shiftvec         = fr->shift_vec[0];
1189     fshift           = fr->fshift[0];
1190     facel            = _mm_set1_ps(fr->ic->epsfac);
1191     charge           = mdatoms->chargeA;
1192     krf              = _mm_set1_ps(fr->ic->k_rf);
1193     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
1194     crf              = _mm_set1_ps(fr->ic->c_rf);
1195
1196     /* Setup water-specific parameters */
1197     inr              = nlist->iinr[0];
1198     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
1199     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
1200     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
1201
1202     jq0              = _mm_set1_ps(charge[inr+0]);
1203     jq1              = _mm_set1_ps(charge[inr+1]);
1204     jq2              = _mm_set1_ps(charge[inr+2]);
1205     qq00             = _mm_mul_ps(iq0,jq0);
1206     qq01             = _mm_mul_ps(iq0,jq1);
1207     qq02             = _mm_mul_ps(iq0,jq2);
1208     qq10             = _mm_mul_ps(iq1,jq0);
1209     qq11             = _mm_mul_ps(iq1,jq1);
1210     qq12             = _mm_mul_ps(iq1,jq2);
1211     qq20             = _mm_mul_ps(iq2,jq0);
1212     qq21             = _mm_mul_ps(iq2,jq1);
1213     qq22             = _mm_mul_ps(iq2,jq2);
1214
1215     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
1216     rcutoff_scalar   = fr->ic->rcoulomb;
1217     rcutoff          = _mm_set1_ps(rcutoff_scalar);
1218     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
1219
1220     /* Avoid stupid compiler warnings */
1221     jnrA = jnrB = jnrC = jnrD = 0;
1222     j_coord_offsetA = 0;
1223     j_coord_offsetB = 0;
1224     j_coord_offsetC = 0;
1225     j_coord_offsetD = 0;
1226
1227     outeriter        = 0;
1228     inneriter        = 0;
1229
1230     for(iidx=0;iidx<4*DIM;iidx++)
1231     {
1232         scratch[iidx] = 0.0;
1233     }  
1234
1235     /* Start outer loop over neighborlists */
1236     for(iidx=0; iidx<nri; iidx++)
1237     {
1238         /* Load shift vector for this list */
1239         i_shift_offset   = DIM*shiftidx[iidx];
1240
1241         /* Load limits for loop over neighbors */
1242         j_index_start    = jindex[iidx];
1243         j_index_end      = jindex[iidx+1];
1244
1245         /* Get outer coordinate index */
1246         inr              = iinr[iidx];
1247         i_coord_offset   = DIM*inr;
1248
1249         /* Load i particle coords and add shift vector */
1250         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
1251                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
1252         
1253         fix0             = _mm_setzero_ps();
1254         fiy0             = _mm_setzero_ps();
1255         fiz0             = _mm_setzero_ps();
1256         fix1             = _mm_setzero_ps();
1257         fiy1             = _mm_setzero_ps();
1258         fiz1             = _mm_setzero_ps();
1259         fix2             = _mm_setzero_ps();
1260         fiy2             = _mm_setzero_ps();
1261         fiz2             = _mm_setzero_ps();
1262
1263         /* Start inner kernel loop */
1264         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
1265         {
1266
1267             /* Get j neighbor index, and coordinate index */
1268             jnrA             = jjnr[jidx];
1269             jnrB             = jjnr[jidx+1];
1270             jnrC             = jjnr[jidx+2];
1271             jnrD             = jjnr[jidx+3];
1272             j_coord_offsetA  = DIM*jnrA;
1273             j_coord_offsetB  = DIM*jnrB;
1274             j_coord_offsetC  = DIM*jnrC;
1275             j_coord_offsetD  = DIM*jnrD;
1276
1277             /* load j atom coordinates */
1278             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1279                                               x+j_coord_offsetC,x+j_coord_offsetD,
1280                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1281
1282             /* Calculate displacement vector */
1283             dx00             = _mm_sub_ps(ix0,jx0);
1284             dy00             = _mm_sub_ps(iy0,jy0);
1285             dz00             = _mm_sub_ps(iz0,jz0);
1286             dx01             = _mm_sub_ps(ix0,jx1);
1287             dy01             = _mm_sub_ps(iy0,jy1);
1288             dz01             = _mm_sub_ps(iz0,jz1);
1289             dx02             = _mm_sub_ps(ix0,jx2);
1290             dy02             = _mm_sub_ps(iy0,jy2);
1291             dz02             = _mm_sub_ps(iz0,jz2);
1292             dx10             = _mm_sub_ps(ix1,jx0);
1293             dy10             = _mm_sub_ps(iy1,jy0);
1294             dz10             = _mm_sub_ps(iz1,jz0);
1295             dx11             = _mm_sub_ps(ix1,jx1);
1296             dy11             = _mm_sub_ps(iy1,jy1);
1297             dz11             = _mm_sub_ps(iz1,jz1);
1298             dx12             = _mm_sub_ps(ix1,jx2);
1299             dy12             = _mm_sub_ps(iy1,jy2);
1300             dz12             = _mm_sub_ps(iz1,jz2);
1301             dx20             = _mm_sub_ps(ix2,jx0);
1302             dy20             = _mm_sub_ps(iy2,jy0);
1303             dz20             = _mm_sub_ps(iz2,jz0);
1304             dx21             = _mm_sub_ps(ix2,jx1);
1305             dy21             = _mm_sub_ps(iy2,jy1);
1306             dz21             = _mm_sub_ps(iz2,jz1);
1307             dx22             = _mm_sub_ps(ix2,jx2);
1308             dy22             = _mm_sub_ps(iy2,jy2);
1309             dz22             = _mm_sub_ps(iz2,jz2);
1310
1311             /* Calculate squared distance and things based on it */
1312             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1313             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1314             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1315             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1316             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1317             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1318             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1319             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1320             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1321
1322             rinv00           = sse2_invsqrt_f(rsq00);
1323             rinv01           = sse2_invsqrt_f(rsq01);
1324             rinv02           = sse2_invsqrt_f(rsq02);
1325             rinv10           = sse2_invsqrt_f(rsq10);
1326             rinv11           = sse2_invsqrt_f(rsq11);
1327             rinv12           = sse2_invsqrt_f(rsq12);
1328             rinv20           = sse2_invsqrt_f(rsq20);
1329             rinv21           = sse2_invsqrt_f(rsq21);
1330             rinv22           = sse2_invsqrt_f(rsq22);
1331
1332             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1333             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1334             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1335             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1336             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1337             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1338             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1339             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1340             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1341
1342             fjx0             = _mm_setzero_ps();
1343             fjy0             = _mm_setzero_ps();
1344             fjz0             = _mm_setzero_ps();
1345             fjx1             = _mm_setzero_ps();
1346             fjy1             = _mm_setzero_ps();
1347             fjz1             = _mm_setzero_ps();
1348             fjx2             = _mm_setzero_ps();
1349             fjy2             = _mm_setzero_ps();
1350             fjz2             = _mm_setzero_ps();
1351
1352             /**************************
1353              * CALCULATE INTERACTIONS *
1354              **************************/
1355
1356             if (gmx_mm_any_lt(rsq00,rcutoff2))
1357             {
1358
1359             /* REACTION-FIELD ELECTROSTATICS */
1360             felec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1361
1362             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1363
1364             fscal            = felec;
1365
1366             fscal            = _mm_and_ps(fscal,cutoff_mask);
1367
1368             /* Calculate temporary vectorial force */
1369             tx               = _mm_mul_ps(fscal,dx00);
1370             ty               = _mm_mul_ps(fscal,dy00);
1371             tz               = _mm_mul_ps(fscal,dz00);
1372
1373             /* Update vectorial force */
1374             fix0             = _mm_add_ps(fix0,tx);
1375             fiy0             = _mm_add_ps(fiy0,ty);
1376             fiz0             = _mm_add_ps(fiz0,tz);
1377
1378             fjx0             = _mm_add_ps(fjx0,tx);
1379             fjy0             = _mm_add_ps(fjy0,ty);
1380             fjz0             = _mm_add_ps(fjz0,tz);
1381             
1382             }
1383
1384             /**************************
1385              * CALCULATE INTERACTIONS *
1386              **************************/
1387
1388             if (gmx_mm_any_lt(rsq01,rcutoff2))
1389             {
1390
1391             /* REACTION-FIELD ELECTROSTATICS */
1392             felec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1393
1394             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
1395
1396             fscal            = felec;
1397
1398             fscal            = _mm_and_ps(fscal,cutoff_mask);
1399
1400             /* Calculate temporary vectorial force */
1401             tx               = _mm_mul_ps(fscal,dx01);
1402             ty               = _mm_mul_ps(fscal,dy01);
1403             tz               = _mm_mul_ps(fscal,dz01);
1404
1405             /* Update vectorial force */
1406             fix0             = _mm_add_ps(fix0,tx);
1407             fiy0             = _mm_add_ps(fiy0,ty);
1408             fiz0             = _mm_add_ps(fiz0,tz);
1409
1410             fjx1             = _mm_add_ps(fjx1,tx);
1411             fjy1             = _mm_add_ps(fjy1,ty);
1412             fjz1             = _mm_add_ps(fjz1,tz);
1413             
1414             }
1415
1416             /**************************
1417              * CALCULATE INTERACTIONS *
1418              **************************/
1419
1420             if (gmx_mm_any_lt(rsq02,rcutoff2))
1421             {
1422
1423             /* REACTION-FIELD ELECTROSTATICS */
1424             felec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
1425
1426             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
1427
1428             fscal            = felec;
1429
1430             fscal            = _mm_and_ps(fscal,cutoff_mask);
1431
1432             /* Calculate temporary vectorial force */
1433             tx               = _mm_mul_ps(fscal,dx02);
1434             ty               = _mm_mul_ps(fscal,dy02);
1435             tz               = _mm_mul_ps(fscal,dz02);
1436
1437             /* Update vectorial force */
1438             fix0             = _mm_add_ps(fix0,tx);
1439             fiy0             = _mm_add_ps(fiy0,ty);
1440             fiz0             = _mm_add_ps(fiz0,tz);
1441
1442             fjx2             = _mm_add_ps(fjx2,tx);
1443             fjy2             = _mm_add_ps(fjy2,ty);
1444             fjz2             = _mm_add_ps(fjz2,tz);
1445             
1446             }
1447
1448             /**************************
1449              * CALCULATE INTERACTIONS *
1450              **************************/
1451
1452             if (gmx_mm_any_lt(rsq10,rcutoff2))
1453             {
1454
1455             /* REACTION-FIELD ELECTROSTATICS */
1456             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1457
1458             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1459
1460             fscal            = felec;
1461
1462             fscal            = _mm_and_ps(fscal,cutoff_mask);
1463
1464             /* Calculate temporary vectorial force */
1465             tx               = _mm_mul_ps(fscal,dx10);
1466             ty               = _mm_mul_ps(fscal,dy10);
1467             tz               = _mm_mul_ps(fscal,dz10);
1468
1469             /* Update vectorial force */
1470             fix1             = _mm_add_ps(fix1,tx);
1471             fiy1             = _mm_add_ps(fiy1,ty);
1472             fiz1             = _mm_add_ps(fiz1,tz);
1473
1474             fjx0             = _mm_add_ps(fjx0,tx);
1475             fjy0             = _mm_add_ps(fjy0,ty);
1476             fjz0             = _mm_add_ps(fjz0,tz);
1477             
1478             }
1479
1480             /**************************
1481              * CALCULATE INTERACTIONS *
1482              **************************/
1483
1484             if (gmx_mm_any_lt(rsq11,rcutoff2))
1485             {
1486
1487             /* REACTION-FIELD ELECTROSTATICS */
1488             felec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1489
1490             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
1491
1492             fscal            = felec;
1493
1494             fscal            = _mm_and_ps(fscal,cutoff_mask);
1495
1496             /* Calculate temporary vectorial force */
1497             tx               = _mm_mul_ps(fscal,dx11);
1498             ty               = _mm_mul_ps(fscal,dy11);
1499             tz               = _mm_mul_ps(fscal,dz11);
1500
1501             /* Update vectorial force */
1502             fix1             = _mm_add_ps(fix1,tx);
1503             fiy1             = _mm_add_ps(fiy1,ty);
1504             fiz1             = _mm_add_ps(fiz1,tz);
1505
1506             fjx1             = _mm_add_ps(fjx1,tx);
1507             fjy1             = _mm_add_ps(fjy1,ty);
1508             fjz1             = _mm_add_ps(fjz1,tz);
1509             
1510             }
1511
1512             /**************************
1513              * CALCULATE INTERACTIONS *
1514              **************************/
1515
1516             if (gmx_mm_any_lt(rsq12,rcutoff2))
1517             {
1518
1519             /* REACTION-FIELD ELECTROSTATICS */
1520             felec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1521
1522             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
1523
1524             fscal            = felec;
1525
1526             fscal            = _mm_and_ps(fscal,cutoff_mask);
1527
1528             /* Calculate temporary vectorial force */
1529             tx               = _mm_mul_ps(fscal,dx12);
1530             ty               = _mm_mul_ps(fscal,dy12);
1531             tz               = _mm_mul_ps(fscal,dz12);
1532
1533             /* Update vectorial force */
1534             fix1             = _mm_add_ps(fix1,tx);
1535             fiy1             = _mm_add_ps(fiy1,ty);
1536             fiz1             = _mm_add_ps(fiz1,tz);
1537
1538             fjx2             = _mm_add_ps(fjx2,tx);
1539             fjy2             = _mm_add_ps(fjy2,ty);
1540             fjz2             = _mm_add_ps(fjz2,tz);
1541             
1542             }
1543
1544             /**************************
1545              * CALCULATE INTERACTIONS *
1546              **************************/
1547
1548             if (gmx_mm_any_lt(rsq20,rcutoff2))
1549             {
1550
1551             /* REACTION-FIELD ELECTROSTATICS */
1552             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1553
1554             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1555
1556             fscal            = felec;
1557
1558             fscal            = _mm_and_ps(fscal,cutoff_mask);
1559
1560             /* Calculate temporary vectorial force */
1561             tx               = _mm_mul_ps(fscal,dx20);
1562             ty               = _mm_mul_ps(fscal,dy20);
1563             tz               = _mm_mul_ps(fscal,dz20);
1564
1565             /* Update vectorial force */
1566             fix2             = _mm_add_ps(fix2,tx);
1567             fiy2             = _mm_add_ps(fiy2,ty);
1568             fiz2             = _mm_add_ps(fiz2,tz);
1569
1570             fjx0             = _mm_add_ps(fjx0,tx);
1571             fjy0             = _mm_add_ps(fjy0,ty);
1572             fjz0             = _mm_add_ps(fjz0,tz);
1573             
1574             }
1575
1576             /**************************
1577              * CALCULATE INTERACTIONS *
1578              **************************/
1579
1580             if (gmx_mm_any_lt(rsq21,rcutoff2))
1581             {
1582
1583             /* REACTION-FIELD ELECTROSTATICS */
1584             felec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1585
1586             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
1587
1588             fscal            = felec;
1589
1590             fscal            = _mm_and_ps(fscal,cutoff_mask);
1591
1592             /* Calculate temporary vectorial force */
1593             tx               = _mm_mul_ps(fscal,dx21);
1594             ty               = _mm_mul_ps(fscal,dy21);
1595             tz               = _mm_mul_ps(fscal,dz21);
1596
1597             /* Update vectorial force */
1598             fix2             = _mm_add_ps(fix2,tx);
1599             fiy2             = _mm_add_ps(fiy2,ty);
1600             fiz2             = _mm_add_ps(fiz2,tz);
1601
1602             fjx1             = _mm_add_ps(fjx1,tx);
1603             fjy1             = _mm_add_ps(fjy1,ty);
1604             fjz1             = _mm_add_ps(fjz1,tz);
1605             
1606             }
1607
1608             /**************************
1609              * CALCULATE INTERACTIONS *
1610              **************************/
1611
1612             if (gmx_mm_any_lt(rsq22,rcutoff2))
1613             {
1614
1615             /* REACTION-FIELD ELECTROSTATICS */
1616             felec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
1617
1618             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
1619
1620             fscal            = felec;
1621
1622             fscal            = _mm_and_ps(fscal,cutoff_mask);
1623
1624             /* Calculate temporary vectorial force */
1625             tx               = _mm_mul_ps(fscal,dx22);
1626             ty               = _mm_mul_ps(fscal,dy22);
1627             tz               = _mm_mul_ps(fscal,dz22);
1628
1629             /* Update vectorial force */
1630             fix2             = _mm_add_ps(fix2,tx);
1631             fiy2             = _mm_add_ps(fiy2,ty);
1632             fiz2             = _mm_add_ps(fiz2,tz);
1633
1634             fjx2             = _mm_add_ps(fjx2,tx);
1635             fjy2             = _mm_add_ps(fjy2,ty);
1636             fjz2             = _mm_add_ps(fjz2,tz);
1637             
1638             }
1639
1640             fjptrA             = f+j_coord_offsetA;
1641             fjptrB             = f+j_coord_offsetB;
1642             fjptrC             = f+j_coord_offsetC;
1643             fjptrD             = f+j_coord_offsetD;
1644
1645             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
1646                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
1647
1648             /* Inner loop uses 270 flops */
1649         }
1650
1651         if(jidx<j_index_end)
1652         {
1653
1654             /* Get j neighbor index, and coordinate index */
1655             jnrlistA         = jjnr[jidx];
1656             jnrlistB         = jjnr[jidx+1];
1657             jnrlistC         = jjnr[jidx+2];
1658             jnrlistD         = jjnr[jidx+3];
1659             /* Sign of each element will be negative for non-real atoms.
1660              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1661              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1662              */
1663             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1664             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1665             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1666             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1667             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1668             j_coord_offsetA  = DIM*jnrA;
1669             j_coord_offsetB  = DIM*jnrB;
1670             j_coord_offsetC  = DIM*jnrC;
1671             j_coord_offsetD  = DIM*jnrD;
1672
1673             /* load j atom coordinates */
1674             gmx_mm_load_3rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1675                                               x+j_coord_offsetC,x+j_coord_offsetD,
1676                                               &jx0,&jy0,&jz0,&jx1,&jy1,&jz1,&jx2,&jy2,&jz2);
1677
1678             /* Calculate displacement vector */
1679             dx00             = _mm_sub_ps(ix0,jx0);
1680             dy00             = _mm_sub_ps(iy0,jy0);
1681             dz00             = _mm_sub_ps(iz0,jz0);
1682             dx01             = _mm_sub_ps(ix0,jx1);
1683             dy01             = _mm_sub_ps(iy0,jy1);
1684             dz01             = _mm_sub_ps(iz0,jz1);
1685             dx02             = _mm_sub_ps(ix0,jx2);
1686             dy02             = _mm_sub_ps(iy0,jy2);
1687             dz02             = _mm_sub_ps(iz0,jz2);
1688             dx10             = _mm_sub_ps(ix1,jx0);
1689             dy10             = _mm_sub_ps(iy1,jy0);
1690             dz10             = _mm_sub_ps(iz1,jz0);
1691             dx11             = _mm_sub_ps(ix1,jx1);
1692             dy11             = _mm_sub_ps(iy1,jy1);
1693             dz11             = _mm_sub_ps(iz1,jz1);
1694             dx12             = _mm_sub_ps(ix1,jx2);
1695             dy12             = _mm_sub_ps(iy1,jy2);
1696             dz12             = _mm_sub_ps(iz1,jz2);
1697             dx20             = _mm_sub_ps(ix2,jx0);
1698             dy20             = _mm_sub_ps(iy2,jy0);
1699             dz20             = _mm_sub_ps(iz2,jz0);
1700             dx21             = _mm_sub_ps(ix2,jx1);
1701             dy21             = _mm_sub_ps(iy2,jy1);
1702             dz21             = _mm_sub_ps(iz2,jz1);
1703             dx22             = _mm_sub_ps(ix2,jx2);
1704             dy22             = _mm_sub_ps(iy2,jy2);
1705             dz22             = _mm_sub_ps(iz2,jz2);
1706
1707             /* Calculate squared distance and things based on it */
1708             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1709             rsq01            = gmx_mm_calc_rsq_ps(dx01,dy01,dz01);
1710             rsq02            = gmx_mm_calc_rsq_ps(dx02,dy02,dz02);
1711             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1712             rsq11            = gmx_mm_calc_rsq_ps(dx11,dy11,dz11);
1713             rsq12            = gmx_mm_calc_rsq_ps(dx12,dy12,dz12);
1714             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1715             rsq21            = gmx_mm_calc_rsq_ps(dx21,dy21,dz21);
1716             rsq22            = gmx_mm_calc_rsq_ps(dx22,dy22,dz22);
1717
1718             rinv00           = sse2_invsqrt_f(rsq00);
1719             rinv01           = sse2_invsqrt_f(rsq01);
1720             rinv02           = sse2_invsqrt_f(rsq02);
1721             rinv10           = sse2_invsqrt_f(rsq10);
1722             rinv11           = sse2_invsqrt_f(rsq11);
1723             rinv12           = sse2_invsqrt_f(rsq12);
1724             rinv20           = sse2_invsqrt_f(rsq20);
1725             rinv21           = sse2_invsqrt_f(rsq21);
1726             rinv22           = sse2_invsqrt_f(rsq22);
1727
1728             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
1729             rinvsq01         = _mm_mul_ps(rinv01,rinv01);
1730             rinvsq02         = _mm_mul_ps(rinv02,rinv02);
1731             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1732             rinvsq11         = _mm_mul_ps(rinv11,rinv11);
1733             rinvsq12         = _mm_mul_ps(rinv12,rinv12);
1734             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1735             rinvsq21         = _mm_mul_ps(rinv21,rinv21);
1736             rinvsq22         = _mm_mul_ps(rinv22,rinv22);
1737
1738             fjx0             = _mm_setzero_ps();
1739             fjy0             = _mm_setzero_ps();
1740             fjz0             = _mm_setzero_ps();
1741             fjx1             = _mm_setzero_ps();
1742             fjy1             = _mm_setzero_ps();
1743             fjz1             = _mm_setzero_ps();
1744             fjx2             = _mm_setzero_ps();
1745             fjy2             = _mm_setzero_ps();
1746             fjz2             = _mm_setzero_ps();
1747
1748             /**************************
1749              * CALCULATE INTERACTIONS *
1750              **************************/
1751
1752             if (gmx_mm_any_lt(rsq00,rcutoff2))
1753             {
1754
1755             /* REACTION-FIELD ELECTROSTATICS */
1756             felec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_mul_ps(rinv00,rinvsq00),krf2));
1757
1758             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1759
1760             fscal            = felec;
1761
1762             fscal            = _mm_and_ps(fscal,cutoff_mask);
1763
1764             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1765
1766             /* Calculate temporary vectorial force */
1767             tx               = _mm_mul_ps(fscal,dx00);
1768             ty               = _mm_mul_ps(fscal,dy00);
1769             tz               = _mm_mul_ps(fscal,dz00);
1770
1771             /* Update vectorial force */
1772             fix0             = _mm_add_ps(fix0,tx);
1773             fiy0             = _mm_add_ps(fiy0,ty);
1774             fiz0             = _mm_add_ps(fiz0,tz);
1775
1776             fjx0             = _mm_add_ps(fjx0,tx);
1777             fjy0             = _mm_add_ps(fjy0,ty);
1778             fjz0             = _mm_add_ps(fjz0,tz);
1779             
1780             }
1781
1782             /**************************
1783              * CALCULATE INTERACTIONS *
1784              **************************/
1785
1786             if (gmx_mm_any_lt(rsq01,rcutoff2))
1787             {
1788
1789             /* REACTION-FIELD ELECTROSTATICS */
1790             felec            = _mm_mul_ps(qq01,_mm_sub_ps(_mm_mul_ps(rinv01,rinvsq01),krf2));
1791
1792             cutoff_mask      = _mm_cmplt_ps(rsq01,rcutoff2);
1793
1794             fscal            = felec;
1795
1796             fscal            = _mm_and_ps(fscal,cutoff_mask);
1797
1798             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1799
1800             /* Calculate temporary vectorial force */
1801             tx               = _mm_mul_ps(fscal,dx01);
1802             ty               = _mm_mul_ps(fscal,dy01);
1803             tz               = _mm_mul_ps(fscal,dz01);
1804
1805             /* Update vectorial force */
1806             fix0             = _mm_add_ps(fix0,tx);
1807             fiy0             = _mm_add_ps(fiy0,ty);
1808             fiz0             = _mm_add_ps(fiz0,tz);
1809
1810             fjx1             = _mm_add_ps(fjx1,tx);
1811             fjy1             = _mm_add_ps(fjy1,ty);
1812             fjz1             = _mm_add_ps(fjz1,tz);
1813             
1814             }
1815
1816             /**************************
1817              * CALCULATE INTERACTIONS *
1818              **************************/
1819
1820             if (gmx_mm_any_lt(rsq02,rcutoff2))
1821             {
1822
1823             /* REACTION-FIELD ELECTROSTATICS */
1824             felec            = _mm_mul_ps(qq02,_mm_sub_ps(_mm_mul_ps(rinv02,rinvsq02),krf2));
1825
1826             cutoff_mask      = _mm_cmplt_ps(rsq02,rcutoff2);
1827
1828             fscal            = felec;
1829
1830             fscal            = _mm_and_ps(fscal,cutoff_mask);
1831
1832             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1833
1834             /* Calculate temporary vectorial force */
1835             tx               = _mm_mul_ps(fscal,dx02);
1836             ty               = _mm_mul_ps(fscal,dy02);
1837             tz               = _mm_mul_ps(fscal,dz02);
1838
1839             /* Update vectorial force */
1840             fix0             = _mm_add_ps(fix0,tx);
1841             fiy0             = _mm_add_ps(fiy0,ty);
1842             fiz0             = _mm_add_ps(fiz0,tz);
1843
1844             fjx2             = _mm_add_ps(fjx2,tx);
1845             fjy2             = _mm_add_ps(fjy2,ty);
1846             fjz2             = _mm_add_ps(fjz2,tz);
1847             
1848             }
1849
1850             /**************************
1851              * CALCULATE INTERACTIONS *
1852              **************************/
1853
1854             if (gmx_mm_any_lt(rsq10,rcutoff2))
1855             {
1856
1857             /* REACTION-FIELD ELECTROSTATICS */
1858             felec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_mul_ps(rinv10,rinvsq10),krf2));
1859
1860             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1861
1862             fscal            = felec;
1863
1864             fscal            = _mm_and_ps(fscal,cutoff_mask);
1865
1866             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1867
1868             /* Calculate temporary vectorial force */
1869             tx               = _mm_mul_ps(fscal,dx10);
1870             ty               = _mm_mul_ps(fscal,dy10);
1871             tz               = _mm_mul_ps(fscal,dz10);
1872
1873             /* Update vectorial force */
1874             fix1             = _mm_add_ps(fix1,tx);
1875             fiy1             = _mm_add_ps(fiy1,ty);
1876             fiz1             = _mm_add_ps(fiz1,tz);
1877
1878             fjx0             = _mm_add_ps(fjx0,tx);
1879             fjy0             = _mm_add_ps(fjy0,ty);
1880             fjz0             = _mm_add_ps(fjz0,tz);
1881             
1882             }
1883
1884             /**************************
1885              * CALCULATE INTERACTIONS *
1886              **************************/
1887
1888             if (gmx_mm_any_lt(rsq11,rcutoff2))
1889             {
1890
1891             /* REACTION-FIELD ELECTROSTATICS */
1892             felec            = _mm_mul_ps(qq11,_mm_sub_ps(_mm_mul_ps(rinv11,rinvsq11),krf2));
1893
1894             cutoff_mask      = _mm_cmplt_ps(rsq11,rcutoff2);
1895
1896             fscal            = felec;
1897
1898             fscal            = _mm_and_ps(fscal,cutoff_mask);
1899
1900             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1901
1902             /* Calculate temporary vectorial force */
1903             tx               = _mm_mul_ps(fscal,dx11);
1904             ty               = _mm_mul_ps(fscal,dy11);
1905             tz               = _mm_mul_ps(fscal,dz11);
1906
1907             /* Update vectorial force */
1908             fix1             = _mm_add_ps(fix1,tx);
1909             fiy1             = _mm_add_ps(fiy1,ty);
1910             fiz1             = _mm_add_ps(fiz1,tz);
1911
1912             fjx1             = _mm_add_ps(fjx1,tx);
1913             fjy1             = _mm_add_ps(fjy1,ty);
1914             fjz1             = _mm_add_ps(fjz1,tz);
1915             
1916             }
1917
1918             /**************************
1919              * CALCULATE INTERACTIONS *
1920              **************************/
1921
1922             if (gmx_mm_any_lt(rsq12,rcutoff2))
1923             {
1924
1925             /* REACTION-FIELD ELECTROSTATICS */
1926             felec            = _mm_mul_ps(qq12,_mm_sub_ps(_mm_mul_ps(rinv12,rinvsq12),krf2));
1927
1928             cutoff_mask      = _mm_cmplt_ps(rsq12,rcutoff2);
1929
1930             fscal            = felec;
1931
1932             fscal            = _mm_and_ps(fscal,cutoff_mask);
1933
1934             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1935
1936             /* Calculate temporary vectorial force */
1937             tx               = _mm_mul_ps(fscal,dx12);
1938             ty               = _mm_mul_ps(fscal,dy12);
1939             tz               = _mm_mul_ps(fscal,dz12);
1940
1941             /* Update vectorial force */
1942             fix1             = _mm_add_ps(fix1,tx);
1943             fiy1             = _mm_add_ps(fiy1,ty);
1944             fiz1             = _mm_add_ps(fiz1,tz);
1945
1946             fjx2             = _mm_add_ps(fjx2,tx);
1947             fjy2             = _mm_add_ps(fjy2,ty);
1948             fjz2             = _mm_add_ps(fjz2,tz);
1949             
1950             }
1951
1952             /**************************
1953              * CALCULATE INTERACTIONS *
1954              **************************/
1955
1956             if (gmx_mm_any_lt(rsq20,rcutoff2))
1957             {
1958
1959             /* REACTION-FIELD ELECTROSTATICS */
1960             felec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_mul_ps(rinv20,rinvsq20),krf2));
1961
1962             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1963
1964             fscal            = felec;
1965
1966             fscal            = _mm_and_ps(fscal,cutoff_mask);
1967
1968             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1969
1970             /* Calculate temporary vectorial force */
1971             tx               = _mm_mul_ps(fscal,dx20);
1972             ty               = _mm_mul_ps(fscal,dy20);
1973             tz               = _mm_mul_ps(fscal,dz20);
1974
1975             /* Update vectorial force */
1976             fix2             = _mm_add_ps(fix2,tx);
1977             fiy2             = _mm_add_ps(fiy2,ty);
1978             fiz2             = _mm_add_ps(fiz2,tz);
1979
1980             fjx0             = _mm_add_ps(fjx0,tx);
1981             fjy0             = _mm_add_ps(fjy0,ty);
1982             fjz0             = _mm_add_ps(fjz0,tz);
1983             
1984             }
1985
1986             /**************************
1987              * CALCULATE INTERACTIONS *
1988              **************************/
1989
1990             if (gmx_mm_any_lt(rsq21,rcutoff2))
1991             {
1992
1993             /* REACTION-FIELD ELECTROSTATICS */
1994             felec            = _mm_mul_ps(qq21,_mm_sub_ps(_mm_mul_ps(rinv21,rinvsq21),krf2));
1995
1996             cutoff_mask      = _mm_cmplt_ps(rsq21,rcutoff2);
1997
1998             fscal            = felec;
1999
2000             fscal            = _mm_and_ps(fscal,cutoff_mask);
2001
2002             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2003
2004             /* Calculate temporary vectorial force */
2005             tx               = _mm_mul_ps(fscal,dx21);
2006             ty               = _mm_mul_ps(fscal,dy21);
2007             tz               = _mm_mul_ps(fscal,dz21);
2008
2009             /* Update vectorial force */
2010             fix2             = _mm_add_ps(fix2,tx);
2011             fiy2             = _mm_add_ps(fiy2,ty);
2012             fiz2             = _mm_add_ps(fiz2,tz);
2013
2014             fjx1             = _mm_add_ps(fjx1,tx);
2015             fjy1             = _mm_add_ps(fjy1,ty);
2016             fjz1             = _mm_add_ps(fjz1,tz);
2017             
2018             }
2019
2020             /**************************
2021              * CALCULATE INTERACTIONS *
2022              **************************/
2023
2024             if (gmx_mm_any_lt(rsq22,rcutoff2))
2025             {
2026
2027             /* REACTION-FIELD ELECTROSTATICS */
2028             felec            = _mm_mul_ps(qq22,_mm_sub_ps(_mm_mul_ps(rinv22,rinvsq22),krf2));
2029
2030             cutoff_mask      = _mm_cmplt_ps(rsq22,rcutoff2);
2031
2032             fscal            = felec;
2033
2034             fscal            = _mm_and_ps(fscal,cutoff_mask);
2035
2036             fscal            = _mm_andnot_ps(dummy_mask,fscal);
2037
2038             /* Calculate temporary vectorial force */
2039             tx               = _mm_mul_ps(fscal,dx22);
2040             ty               = _mm_mul_ps(fscal,dy22);
2041             tz               = _mm_mul_ps(fscal,dz22);
2042
2043             /* Update vectorial force */
2044             fix2             = _mm_add_ps(fix2,tx);
2045             fiy2             = _mm_add_ps(fiy2,ty);
2046             fiz2             = _mm_add_ps(fiz2,tz);
2047
2048             fjx2             = _mm_add_ps(fjx2,tx);
2049             fjy2             = _mm_add_ps(fjy2,ty);
2050             fjz2             = _mm_add_ps(fjz2,tz);
2051             
2052             }
2053
2054             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
2055             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
2056             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
2057             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
2058
2059             gmx_mm_decrement_3rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,
2060                                                    fjx0,fjy0,fjz0,fjx1,fjy1,fjz1,fjx2,fjy2,fjz2);
2061
2062             /* Inner loop uses 270 flops */
2063         }
2064
2065         /* End of innermost loop */
2066
2067         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
2068                                               f+i_coord_offset,fshift+i_shift_offset);
2069
2070         /* Increment number of inner iterations */
2071         inneriter                  += j_index_end - j_index_start;
2072
2073         /* Outer loop uses 18 flops */
2074     }
2075
2076     /* Increment number of outer iterations */
2077     outeriter        += nri;
2078
2079     /* Update outer/inner flops */
2080
2081     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3W3_F,outeriter*18 + inneriter*270);
2082 }