Compile nonbonded kernels as C++
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sparc64_hpc_ace_double / nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_sparc64_hpc_ace_double.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014,2015,2017,2018, 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 sparc64_hpc_ace_double 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_sparc64_hpc_ace_double.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_VF_sparc64_hpc_ace_double
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            LennardJones
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_VF_sparc64_hpc_ace_double
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 refer to j loop unrolling done with double precision SIMD, e.g. for the two 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;
74     int              j_coord_offsetA,j_coord_offsetB;
75     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
76     real             rcutoff_scalar;
77     real             *shiftvec,*fshift,*x,*f;
78     _fjsp_v2r8       tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
79     int              vdwioffset0;
80     _fjsp_v2r8       ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
81     int              vdwioffset1;
82     _fjsp_v2r8       ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
83     int              vdwioffset2;
84     _fjsp_v2r8       ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
85     int              vdwioffset3;
86     _fjsp_v2r8       ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
87     int              vdwjidx0A,vdwjidx0B;
88     _fjsp_v2r8       jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
89     _fjsp_v2r8       dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
90     _fjsp_v2r8       dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
91     _fjsp_v2r8       dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
92     _fjsp_v2r8       dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
93     _fjsp_v2r8       velec,felec,velecsum,facel,crf,krf,krf2;
94     real             *charge;
95     int              nvdwtype;
96     _fjsp_v2r8       rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
97     int              *vdwtype;
98     real             *vdwparam;
99     _fjsp_v2r8       one_sixth   = gmx_fjsp_set1_v2r8(1.0/6.0);
100     _fjsp_v2r8       one_twelfth = gmx_fjsp_set1_v2r8(1.0/12.0);
101     _fjsp_v2r8       rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
102     real             rswitch_scalar,d_scalar;
103     _fjsp_v2r8       itab_tmp;
104     _fjsp_v2r8       dummy_mask,cutoff_mask;
105     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
106     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
107     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
108
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            = gmx_fjsp_set1_v2r8(fr->ic->epsfac);
121     charge           = mdatoms->chargeA;
122     krf              = gmx_fjsp_set1_v2r8(fr->ic->k_rf);
123     krf2             = gmx_fjsp_set1_v2r8(fr->ic->k_rf*2.0);
124     crf              = gmx_fjsp_set1_v2r8(fr->ic->c_rf);
125     nvdwtype         = fr->ntype;
126     vdwparam         = fr->nbfp;
127     vdwtype          = mdatoms->typeA;
128
129     /* Setup water-specific parameters */
130     inr              = nlist->iinr[0];
131     iq1              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+1]));
132     iq2              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+2]));
133     iq3              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+3]));
134     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
135
136     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
137     rcutoff_scalar   = fr->ic->rcoulomb;
138     rcutoff          = gmx_fjsp_set1_v2r8(rcutoff_scalar);
139     rcutoff2         = _fjsp_mul_v2r8(rcutoff,rcutoff);
140
141     rswitch_scalar   = fr->ic->rvdw_switch;
142     rswitch          = gmx_fjsp_set1_v2r8(rswitch_scalar);
143     /* Setup switch parameters */
144     d_scalar         = rcutoff_scalar-rswitch_scalar;
145     d                = gmx_fjsp_set1_v2r8(d_scalar);
146     swV3             = gmx_fjsp_set1_v2r8(-10.0/(d_scalar*d_scalar*d_scalar));
147     swV4             = gmx_fjsp_set1_v2r8( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
148     swV5             = gmx_fjsp_set1_v2r8( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
149     swF2             = gmx_fjsp_set1_v2r8(-30.0/(d_scalar*d_scalar*d_scalar));
150     swF3             = gmx_fjsp_set1_v2r8( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
151     swF4             = gmx_fjsp_set1_v2r8(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
152
153     /* Avoid stupid compiler warnings */
154     jnrA = jnrB = 0;
155     j_coord_offsetA = 0;
156     j_coord_offsetB = 0;
157
158     outeriter        = 0;
159     inneriter        = 0;
160
161     /* Start outer loop over neighborlists */
162     for(iidx=0; iidx<nri; iidx++)
163     {
164         /* Load shift vector for this list */
165         i_shift_offset   = DIM*shiftidx[iidx];
166
167         /* Load limits for loop over neighbors */
168         j_index_start    = jindex[iidx];
169         j_index_end      = jindex[iidx+1];
170
171         /* Get outer coordinate index */
172         inr              = iinr[iidx];
173         i_coord_offset   = DIM*inr;
174
175         /* Load i particle coords and add shift vector */
176         gmx_fjsp_load_shift_and_4rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
177                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
178
179         fix0             = _fjsp_setzero_v2r8();
180         fiy0             = _fjsp_setzero_v2r8();
181         fiz0             = _fjsp_setzero_v2r8();
182         fix1             = _fjsp_setzero_v2r8();
183         fiy1             = _fjsp_setzero_v2r8();
184         fiz1             = _fjsp_setzero_v2r8();
185         fix2             = _fjsp_setzero_v2r8();
186         fiy2             = _fjsp_setzero_v2r8();
187         fiz2             = _fjsp_setzero_v2r8();
188         fix3             = _fjsp_setzero_v2r8();
189         fiy3             = _fjsp_setzero_v2r8();
190         fiz3             = _fjsp_setzero_v2r8();
191
192         /* Reset potential sums */
193         velecsum         = _fjsp_setzero_v2r8();
194         vvdwsum          = _fjsp_setzero_v2r8();
195
196         /* Start inner kernel loop */
197         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
198         {
199
200             /* Get j neighbor index, and coordinate index */
201             jnrA             = jjnr[jidx];
202             jnrB             = jjnr[jidx+1];
203             j_coord_offsetA  = DIM*jnrA;
204             j_coord_offsetB  = DIM*jnrB;
205
206             /* load j atom coordinates */
207             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
208                                               &jx0,&jy0,&jz0);
209
210             /* Calculate displacement vector */
211             dx00             = _fjsp_sub_v2r8(ix0,jx0);
212             dy00             = _fjsp_sub_v2r8(iy0,jy0);
213             dz00             = _fjsp_sub_v2r8(iz0,jz0);
214             dx10             = _fjsp_sub_v2r8(ix1,jx0);
215             dy10             = _fjsp_sub_v2r8(iy1,jy0);
216             dz10             = _fjsp_sub_v2r8(iz1,jz0);
217             dx20             = _fjsp_sub_v2r8(ix2,jx0);
218             dy20             = _fjsp_sub_v2r8(iy2,jy0);
219             dz20             = _fjsp_sub_v2r8(iz2,jz0);
220             dx30             = _fjsp_sub_v2r8(ix3,jx0);
221             dy30             = _fjsp_sub_v2r8(iy3,jy0);
222             dz30             = _fjsp_sub_v2r8(iz3,jz0);
223
224             /* Calculate squared distance and things based on it */
225             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
226             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
227             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
228             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
229
230             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
231             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
232             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
233             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
234
235             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
236             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
237             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
238             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
239
240             /* Load parameters for j particles */
241             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
242             vdwjidx0A        = 2*vdwtype[jnrA+0];
243             vdwjidx0B        = 2*vdwtype[jnrB+0];
244
245             fjx0             = _fjsp_setzero_v2r8();
246             fjy0             = _fjsp_setzero_v2r8();
247             fjz0             = _fjsp_setzero_v2r8();
248
249             /**************************
250              * CALCULATE INTERACTIONS *
251              **************************/
252
253             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
254             {
255
256             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
257
258             /* Compute parameters for interactions between i and j atoms */
259             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
260                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
261
262             /* LENNARD-JONES DISPERSION/REPULSION */
263
264             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
265             vvdw6            = _fjsp_mul_v2r8(c6_00,rinvsix);
266             vvdw12           = _fjsp_mul_v2r8(c12_00,_fjsp_mul_v2r8(rinvsix,rinvsix));
267             vvdw             = _fjsp_msub_v2r8( vvdw12,one_twelfth, _fjsp_mul_v2r8(vvdw6,one_sixth) );
268             fvdw             = _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw12,vvdw6),rinvsq00);
269
270             d                = _fjsp_sub_v2r8(r00,rswitch);
271             d                = _fjsp_max_v2r8(d,_fjsp_setzero_v2r8());
272             d2               = _fjsp_mul_v2r8(d,d);
273             sw               = _fjsp_add_v2r8(one,_fjsp_mul_v2r8(d2,_fjsp_mul_v2r8(d,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swV5,swV4),swV3))));
274
275             dsw              = _fjsp_mul_v2r8(d2,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swF4,swF3),swF2));
276
277             /* Evaluate switch function */
278             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
279             fvdw             = _fjsp_msub_v2r8( fvdw,sw , _fjsp_mul_v2r8(rinv00,_fjsp_mul_v2r8(vvdw,dsw)) );
280             vvdw             = _fjsp_mul_v2r8(vvdw,sw);
281             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
282
283             /* Update potential sum for this i atom from the interaction with this j atom. */
284             vvdw             = _fjsp_and_v2r8(vvdw,cutoff_mask);
285             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
286
287             fscal            = fvdw;
288
289             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
290
291             /* Update vectorial force */
292             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
293             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
294             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
295             
296             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
297             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
298             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
299
300             }
301
302             /**************************
303              * CALCULATE INTERACTIONS *
304              **************************/
305
306             if (gmx_fjsp_any_lt_v2r8(rsq10,rcutoff2))
307             {
308
309             /* Compute parameters for interactions between i and j atoms */
310             qq10             = _fjsp_mul_v2r8(iq1,jq0);
311
312             /* REACTION-FIELD ELECTROSTATICS */
313             velec            = _fjsp_mul_v2r8(qq10,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq10,rinv10),crf));
314             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
315
316             cutoff_mask      = _fjsp_cmplt_v2r8(rsq10,rcutoff2);
317
318             /* Update potential sum for this i atom from the interaction with this j atom. */
319             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
320             velecsum         = _fjsp_add_v2r8(velecsum,velec);
321
322             fscal            = felec;
323
324             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
325
326             /* Update vectorial force */
327             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
328             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
329             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
330             
331             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
332             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
333             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
334
335             }
336
337             /**************************
338              * CALCULATE INTERACTIONS *
339              **************************/
340
341             if (gmx_fjsp_any_lt_v2r8(rsq20,rcutoff2))
342             {
343
344             /* Compute parameters for interactions between i and j atoms */
345             qq20             = _fjsp_mul_v2r8(iq2,jq0);
346
347             /* REACTION-FIELD ELECTROSTATICS */
348             velec            = _fjsp_mul_v2r8(qq20,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq20,rinv20),crf));
349             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
350
351             cutoff_mask      = _fjsp_cmplt_v2r8(rsq20,rcutoff2);
352
353             /* Update potential sum for this i atom from the interaction with this j atom. */
354             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
355             velecsum         = _fjsp_add_v2r8(velecsum,velec);
356
357             fscal            = felec;
358
359             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
360
361             /* Update vectorial force */
362             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
363             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
364             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
365             
366             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
367             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
368             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
369
370             }
371
372             /**************************
373              * CALCULATE INTERACTIONS *
374              **************************/
375
376             if (gmx_fjsp_any_lt_v2r8(rsq30,rcutoff2))
377             {
378
379             /* Compute parameters for interactions between i and j atoms */
380             qq30             = _fjsp_mul_v2r8(iq3,jq0);
381
382             /* REACTION-FIELD ELECTROSTATICS */
383             velec            = _fjsp_mul_v2r8(qq30,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq30,rinv30),crf));
384             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
385
386             cutoff_mask      = _fjsp_cmplt_v2r8(rsq30,rcutoff2);
387
388             /* Update potential sum for this i atom from the interaction with this j atom. */
389             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
390             velecsum         = _fjsp_add_v2r8(velecsum,velec);
391
392             fscal            = felec;
393
394             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
395
396             /* Update vectorial force */
397             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
398             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
399             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
400             
401             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
402             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
403             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
404
405             }
406
407             gmx_fjsp_decrement_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
408
409             /* Inner loop uses 182 flops */
410         }
411
412         if(jidx<j_index_end)
413         {
414
415             jnrA             = jjnr[jidx];
416             j_coord_offsetA  = DIM*jnrA;
417
418             /* load j atom coordinates */
419             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
420                                               &jx0,&jy0,&jz0);
421
422             /* Calculate displacement vector */
423             dx00             = _fjsp_sub_v2r8(ix0,jx0);
424             dy00             = _fjsp_sub_v2r8(iy0,jy0);
425             dz00             = _fjsp_sub_v2r8(iz0,jz0);
426             dx10             = _fjsp_sub_v2r8(ix1,jx0);
427             dy10             = _fjsp_sub_v2r8(iy1,jy0);
428             dz10             = _fjsp_sub_v2r8(iz1,jz0);
429             dx20             = _fjsp_sub_v2r8(ix2,jx0);
430             dy20             = _fjsp_sub_v2r8(iy2,jy0);
431             dz20             = _fjsp_sub_v2r8(iz2,jz0);
432             dx30             = _fjsp_sub_v2r8(ix3,jx0);
433             dy30             = _fjsp_sub_v2r8(iy3,jy0);
434             dz30             = _fjsp_sub_v2r8(iz3,jz0);
435
436             /* Calculate squared distance and things based on it */
437             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
438             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
439             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
440             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
441
442             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
443             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
444             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
445             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
446
447             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
448             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
449             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
450             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
451
452             /* Load parameters for j particles */
453             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
454             vdwjidx0A        = 2*vdwtype[jnrA+0];
455
456             fjx0             = _fjsp_setzero_v2r8();
457             fjy0             = _fjsp_setzero_v2r8();
458             fjz0             = _fjsp_setzero_v2r8();
459
460             /**************************
461              * CALCULATE INTERACTIONS *
462              **************************/
463
464             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
465             {
466
467             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
468
469             /* Compute parameters for interactions between i and j atoms */
470             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
471                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
472
473             /* LENNARD-JONES DISPERSION/REPULSION */
474
475             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
476             vvdw6            = _fjsp_mul_v2r8(c6_00,rinvsix);
477             vvdw12           = _fjsp_mul_v2r8(c12_00,_fjsp_mul_v2r8(rinvsix,rinvsix));
478             vvdw             = _fjsp_msub_v2r8( vvdw12,one_twelfth, _fjsp_mul_v2r8(vvdw6,one_sixth) );
479             fvdw             = _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw12,vvdw6),rinvsq00);
480
481             d                = _fjsp_sub_v2r8(r00,rswitch);
482             d                = _fjsp_max_v2r8(d,_fjsp_setzero_v2r8());
483             d2               = _fjsp_mul_v2r8(d,d);
484             sw               = _fjsp_add_v2r8(one,_fjsp_mul_v2r8(d2,_fjsp_mul_v2r8(d,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swV5,swV4),swV3))));
485
486             dsw              = _fjsp_mul_v2r8(d2,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swF4,swF3),swF2));
487
488             /* Evaluate switch function */
489             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
490             fvdw             = _fjsp_msub_v2r8( fvdw,sw , _fjsp_mul_v2r8(rinv00,_fjsp_mul_v2r8(vvdw,dsw)) );
491             vvdw             = _fjsp_mul_v2r8(vvdw,sw);
492             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
493
494             /* Update potential sum for this i atom from the interaction with this j atom. */
495             vvdw             = _fjsp_and_v2r8(vvdw,cutoff_mask);
496             vvdw             = _fjsp_unpacklo_v2r8(vvdw,_fjsp_setzero_v2r8());
497             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
498
499             fscal            = fvdw;
500
501             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
502
503             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
504
505             /* Update vectorial force */
506             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
507             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
508             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
509             
510             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
511             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
512             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
513
514             }
515
516             /**************************
517              * CALCULATE INTERACTIONS *
518              **************************/
519
520             if (gmx_fjsp_any_lt_v2r8(rsq10,rcutoff2))
521             {
522
523             /* Compute parameters for interactions between i and j atoms */
524             qq10             = _fjsp_mul_v2r8(iq1,jq0);
525
526             /* REACTION-FIELD ELECTROSTATICS */
527             velec            = _fjsp_mul_v2r8(qq10,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq10,rinv10),crf));
528             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
529
530             cutoff_mask      = _fjsp_cmplt_v2r8(rsq10,rcutoff2);
531
532             /* Update potential sum for this i atom from the interaction with this j atom. */
533             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
534             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
535             velecsum         = _fjsp_add_v2r8(velecsum,velec);
536
537             fscal            = felec;
538
539             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
540
541             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
542
543             /* Update vectorial force */
544             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
545             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
546             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
547             
548             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
549             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
550             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
551
552             }
553
554             /**************************
555              * CALCULATE INTERACTIONS *
556              **************************/
557
558             if (gmx_fjsp_any_lt_v2r8(rsq20,rcutoff2))
559             {
560
561             /* Compute parameters for interactions between i and j atoms */
562             qq20             = _fjsp_mul_v2r8(iq2,jq0);
563
564             /* REACTION-FIELD ELECTROSTATICS */
565             velec            = _fjsp_mul_v2r8(qq20,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq20,rinv20),crf));
566             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
567
568             cutoff_mask      = _fjsp_cmplt_v2r8(rsq20,rcutoff2);
569
570             /* Update potential sum for this i atom from the interaction with this j atom. */
571             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
572             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
573             velecsum         = _fjsp_add_v2r8(velecsum,velec);
574
575             fscal            = felec;
576
577             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
578
579             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
580
581             /* Update vectorial force */
582             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
583             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
584             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
585             
586             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
587             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
588             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
589
590             }
591
592             /**************************
593              * CALCULATE INTERACTIONS *
594              **************************/
595
596             if (gmx_fjsp_any_lt_v2r8(rsq30,rcutoff2))
597             {
598
599             /* Compute parameters for interactions between i and j atoms */
600             qq30             = _fjsp_mul_v2r8(iq3,jq0);
601
602             /* REACTION-FIELD ELECTROSTATICS */
603             velec            = _fjsp_mul_v2r8(qq30,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq30,rinv30),crf));
604             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
605
606             cutoff_mask      = _fjsp_cmplt_v2r8(rsq30,rcutoff2);
607
608             /* Update potential sum for this i atom from the interaction with this j atom. */
609             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
610             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
611             velecsum         = _fjsp_add_v2r8(velecsum,velec);
612
613             fscal            = felec;
614
615             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
616
617             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
618
619             /* Update vectorial force */
620             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
621             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
622             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
623             
624             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
625             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
626             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
627
628             }
629
630             gmx_fjsp_decrement_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0);
631
632             /* Inner loop uses 182 flops */
633         }
634
635         /* End of innermost loop */
636
637         gmx_fjsp_update_iforce_4atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
638                                               f+i_coord_offset,fshift+i_shift_offset);
639
640         ggid                        = gid[iidx];
641         /* Update potential energies */
642         gmx_fjsp_update_1pot_v2r8(velecsum,kernel_data->energygrp_elec+ggid);
643         gmx_fjsp_update_1pot_v2r8(vvdwsum,kernel_data->energygrp_vdw+ggid);
644
645         /* Increment number of inner iterations */
646         inneriter                  += j_index_end - j_index_start;
647
648         /* Outer loop uses 26 flops */
649     }
650
651     /* Increment number of outer iterations */
652     outeriter        += nri;
653
654     /* Update outer/inner flops */
655
656     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*182);
657 }
658 /*
659  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_sparc64_hpc_ace_double
660  * Electrostatics interaction: ReactionField
661  * VdW interaction:            LennardJones
662  * Geometry:                   Water4-Particle
663  * Calculate force/pot:        Force
664  */
665 void
666 nb_kernel_ElecRFCut_VdwLJSw_GeomW4P1_F_sparc64_hpc_ace_double
667                     (t_nblist                    * gmx_restrict       nlist,
668                      rvec                        * gmx_restrict          xx,
669                      rvec                        * gmx_restrict          ff,
670                      struct t_forcerec           * gmx_restrict          fr,
671                      t_mdatoms                   * gmx_restrict     mdatoms,
672                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
673                      t_nrnb                      * gmx_restrict        nrnb)
674 {
675     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
676      * just 0 for non-waters.
677      * Suffixes A,B refer to j loop unrolling done with double precision SIMD, e.g. for the two different
678      * jnr indices corresponding to data put in the four positions in the SIMD register.
679      */
680     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
681     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
682     int              jnrA,jnrB;
683     int              j_coord_offsetA,j_coord_offsetB;
684     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
685     real             rcutoff_scalar;
686     real             *shiftvec,*fshift,*x,*f;
687     _fjsp_v2r8       tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
688     int              vdwioffset0;
689     _fjsp_v2r8       ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
690     int              vdwioffset1;
691     _fjsp_v2r8       ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
692     int              vdwioffset2;
693     _fjsp_v2r8       ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
694     int              vdwioffset3;
695     _fjsp_v2r8       ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
696     int              vdwjidx0A,vdwjidx0B;
697     _fjsp_v2r8       jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
698     _fjsp_v2r8       dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
699     _fjsp_v2r8       dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
700     _fjsp_v2r8       dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
701     _fjsp_v2r8       dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
702     _fjsp_v2r8       velec,felec,velecsum,facel,crf,krf,krf2;
703     real             *charge;
704     int              nvdwtype;
705     _fjsp_v2r8       rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
706     int              *vdwtype;
707     real             *vdwparam;
708     _fjsp_v2r8       one_sixth   = gmx_fjsp_set1_v2r8(1.0/6.0);
709     _fjsp_v2r8       one_twelfth = gmx_fjsp_set1_v2r8(1.0/12.0);
710     _fjsp_v2r8       rswitch,swV3,swV4,swV5,swF2,swF3,swF4,d,d2,sw,dsw;
711     real             rswitch_scalar,d_scalar;
712     _fjsp_v2r8       itab_tmp;
713     _fjsp_v2r8       dummy_mask,cutoff_mask;
714     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
715     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
716     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
717
718     x                = xx[0];
719     f                = ff[0];
720
721     nri              = nlist->nri;
722     iinr             = nlist->iinr;
723     jindex           = nlist->jindex;
724     jjnr             = nlist->jjnr;
725     shiftidx         = nlist->shift;
726     gid              = nlist->gid;
727     shiftvec         = fr->shift_vec[0];
728     fshift           = fr->fshift[0];
729     facel            = gmx_fjsp_set1_v2r8(fr->ic->epsfac);
730     charge           = mdatoms->chargeA;
731     krf              = gmx_fjsp_set1_v2r8(fr->ic->k_rf);
732     krf2             = gmx_fjsp_set1_v2r8(fr->ic->k_rf*2.0);
733     crf              = gmx_fjsp_set1_v2r8(fr->ic->c_rf);
734     nvdwtype         = fr->ntype;
735     vdwparam         = fr->nbfp;
736     vdwtype          = mdatoms->typeA;
737
738     /* Setup water-specific parameters */
739     inr              = nlist->iinr[0];
740     iq1              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+1]));
741     iq2              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+2]));
742     iq3              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+3]));
743     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
744
745     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
746     rcutoff_scalar   = fr->ic->rcoulomb;
747     rcutoff          = gmx_fjsp_set1_v2r8(rcutoff_scalar);
748     rcutoff2         = _fjsp_mul_v2r8(rcutoff,rcutoff);
749
750     rswitch_scalar   = fr->ic->rvdw_switch;
751     rswitch          = gmx_fjsp_set1_v2r8(rswitch_scalar);
752     /* Setup switch parameters */
753     d_scalar         = rcutoff_scalar-rswitch_scalar;
754     d                = gmx_fjsp_set1_v2r8(d_scalar);
755     swV3             = gmx_fjsp_set1_v2r8(-10.0/(d_scalar*d_scalar*d_scalar));
756     swV4             = gmx_fjsp_set1_v2r8( 15.0/(d_scalar*d_scalar*d_scalar*d_scalar));
757     swV5             = gmx_fjsp_set1_v2r8( -6.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
758     swF2             = gmx_fjsp_set1_v2r8(-30.0/(d_scalar*d_scalar*d_scalar));
759     swF3             = gmx_fjsp_set1_v2r8( 60.0/(d_scalar*d_scalar*d_scalar*d_scalar));
760     swF4             = gmx_fjsp_set1_v2r8(-30.0/(d_scalar*d_scalar*d_scalar*d_scalar*d_scalar));
761
762     /* Avoid stupid compiler warnings */
763     jnrA = jnrB = 0;
764     j_coord_offsetA = 0;
765     j_coord_offsetB = 0;
766
767     outeriter        = 0;
768     inneriter        = 0;
769
770     /* Start outer loop over neighborlists */
771     for(iidx=0; iidx<nri; iidx++)
772     {
773         /* Load shift vector for this list */
774         i_shift_offset   = DIM*shiftidx[iidx];
775
776         /* Load limits for loop over neighbors */
777         j_index_start    = jindex[iidx];
778         j_index_end      = jindex[iidx+1];
779
780         /* Get outer coordinate index */
781         inr              = iinr[iidx];
782         i_coord_offset   = DIM*inr;
783
784         /* Load i particle coords and add shift vector */
785         gmx_fjsp_load_shift_and_4rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
786                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
787
788         fix0             = _fjsp_setzero_v2r8();
789         fiy0             = _fjsp_setzero_v2r8();
790         fiz0             = _fjsp_setzero_v2r8();
791         fix1             = _fjsp_setzero_v2r8();
792         fiy1             = _fjsp_setzero_v2r8();
793         fiz1             = _fjsp_setzero_v2r8();
794         fix2             = _fjsp_setzero_v2r8();
795         fiy2             = _fjsp_setzero_v2r8();
796         fiz2             = _fjsp_setzero_v2r8();
797         fix3             = _fjsp_setzero_v2r8();
798         fiy3             = _fjsp_setzero_v2r8();
799         fiz3             = _fjsp_setzero_v2r8();
800
801         /* Start inner kernel loop */
802         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
803         {
804
805             /* Get j neighbor index, and coordinate index */
806             jnrA             = jjnr[jidx];
807             jnrB             = jjnr[jidx+1];
808             j_coord_offsetA  = DIM*jnrA;
809             j_coord_offsetB  = DIM*jnrB;
810
811             /* load j atom coordinates */
812             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
813                                               &jx0,&jy0,&jz0);
814
815             /* Calculate displacement vector */
816             dx00             = _fjsp_sub_v2r8(ix0,jx0);
817             dy00             = _fjsp_sub_v2r8(iy0,jy0);
818             dz00             = _fjsp_sub_v2r8(iz0,jz0);
819             dx10             = _fjsp_sub_v2r8(ix1,jx0);
820             dy10             = _fjsp_sub_v2r8(iy1,jy0);
821             dz10             = _fjsp_sub_v2r8(iz1,jz0);
822             dx20             = _fjsp_sub_v2r8(ix2,jx0);
823             dy20             = _fjsp_sub_v2r8(iy2,jy0);
824             dz20             = _fjsp_sub_v2r8(iz2,jz0);
825             dx30             = _fjsp_sub_v2r8(ix3,jx0);
826             dy30             = _fjsp_sub_v2r8(iy3,jy0);
827             dz30             = _fjsp_sub_v2r8(iz3,jz0);
828
829             /* Calculate squared distance and things based on it */
830             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
831             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
832             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
833             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
834
835             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
836             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
837             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
838             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
839
840             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
841             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
842             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
843             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
844
845             /* Load parameters for j particles */
846             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
847             vdwjidx0A        = 2*vdwtype[jnrA+0];
848             vdwjidx0B        = 2*vdwtype[jnrB+0];
849
850             fjx0             = _fjsp_setzero_v2r8();
851             fjy0             = _fjsp_setzero_v2r8();
852             fjz0             = _fjsp_setzero_v2r8();
853
854             /**************************
855              * CALCULATE INTERACTIONS *
856              **************************/
857
858             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
859             {
860
861             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
862
863             /* Compute parameters for interactions between i and j atoms */
864             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
865                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
866
867             /* LENNARD-JONES DISPERSION/REPULSION */
868
869             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
870             vvdw6            = _fjsp_mul_v2r8(c6_00,rinvsix);
871             vvdw12           = _fjsp_mul_v2r8(c12_00,_fjsp_mul_v2r8(rinvsix,rinvsix));
872             vvdw             = _fjsp_msub_v2r8( vvdw12,one_twelfth, _fjsp_mul_v2r8(vvdw6,one_sixth) );
873             fvdw             = _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw12,vvdw6),rinvsq00);
874
875             d                = _fjsp_sub_v2r8(r00,rswitch);
876             d                = _fjsp_max_v2r8(d,_fjsp_setzero_v2r8());
877             d2               = _fjsp_mul_v2r8(d,d);
878             sw               = _fjsp_add_v2r8(one,_fjsp_mul_v2r8(d2,_fjsp_mul_v2r8(d,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swV5,swV4),swV3))));
879
880             dsw              = _fjsp_mul_v2r8(d2,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swF4,swF3),swF2));
881
882             /* Evaluate switch function */
883             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
884             fvdw             = _fjsp_msub_v2r8( fvdw,sw , _fjsp_mul_v2r8(rinv00,_fjsp_mul_v2r8(vvdw,dsw)) );
885             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
886
887             fscal            = fvdw;
888
889             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
890
891             /* Update vectorial force */
892             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
893             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
894             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
895             
896             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
897             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
898             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
899
900             }
901
902             /**************************
903              * CALCULATE INTERACTIONS *
904              **************************/
905
906             if (gmx_fjsp_any_lt_v2r8(rsq10,rcutoff2))
907             {
908
909             /* Compute parameters for interactions between i and j atoms */
910             qq10             = _fjsp_mul_v2r8(iq1,jq0);
911
912             /* REACTION-FIELD ELECTROSTATICS */
913             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
914
915             cutoff_mask      = _fjsp_cmplt_v2r8(rsq10,rcutoff2);
916
917             fscal            = felec;
918
919             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
920
921             /* Update vectorial force */
922             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
923             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
924             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
925             
926             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
927             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
928             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
929
930             }
931
932             /**************************
933              * CALCULATE INTERACTIONS *
934              **************************/
935
936             if (gmx_fjsp_any_lt_v2r8(rsq20,rcutoff2))
937             {
938
939             /* Compute parameters for interactions between i and j atoms */
940             qq20             = _fjsp_mul_v2r8(iq2,jq0);
941
942             /* REACTION-FIELD ELECTROSTATICS */
943             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
944
945             cutoff_mask      = _fjsp_cmplt_v2r8(rsq20,rcutoff2);
946
947             fscal            = felec;
948
949             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
950
951             /* Update vectorial force */
952             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
953             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
954             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
955             
956             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
957             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
958             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
959
960             }
961
962             /**************************
963              * CALCULATE INTERACTIONS *
964              **************************/
965
966             if (gmx_fjsp_any_lt_v2r8(rsq30,rcutoff2))
967             {
968
969             /* Compute parameters for interactions between i and j atoms */
970             qq30             = _fjsp_mul_v2r8(iq3,jq0);
971
972             /* REACTION-FIELD ELECTROSTATICS */
973             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
974
975             cutoff_mask      = _fjsp_cmplt_v2r8(rsq30,rcutoff2);
976
977             fscal            = felec;
978
979             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
980
981             /* Update vectorial force */
982             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
983             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
984             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
985             
986             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
987             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
988             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
989
990             }
991
992             gmx_fjsp_decrement_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
993
994             /* Inner loop uses 161 flops */
995         }
996
997         if(jidx<j_index_end)
998         {
999
1000             jnrA             = jjnr[jidx];
1001             j_coord_offsetA  = DIM*jnrA;
1002
1003             /* load j atom coordinates */
1004             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
1005                                               &jx0,&jy0,&jz0);
1006
1007             /* Calculate displacement vector */
1008             dx00             = _fjsp_sub_v2r8(ix0,jx0);
1009             dy00             = _fjsp_sub_v2r8(iy0,jy0);
1010             dz00             = _fjsp_sub_v2r8(iz0,jz0);
1011             dx10             = _fjsp_sub_v2r8(ix1,jx0);
1012             dy10             = _fjsp_sub_v2r8(iy1,jy0);
1013             dz10             = _fjsp_sub_v2r8(iz1,jz0);
1014             dx20             = _fjsp_sub_v2r8(ix2,jx0);
1015             dy20             = _fjsp_sub_v2r8(iy2,jy0);
1016             dz20             = _fjsp_sub_v2r8(iz2,jz0);
1017             dx30             = _fjsp_sub_v2r8(ix3,jx0);
1018             dy30             = _fjsp_sub_v2r8(iy3,jy0);
1019             dz30             = _fjsp_sub_v2r8(iz3,jz0);
1020
1021             /* Calculate squared distance and things based on it */
1022             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
1023             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
1024             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
1025             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
1026
1027             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
1028             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
1029             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
1030             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
1031
1032             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
1033             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
1034             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
1035             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
1036
1037             /* Load parameters for j particles */
1038             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
1039             vdwjidx0A        = 2*vdwtype[jnrA+0];
1040
1041             fjx0             = _fjsp_setzero_v2r8();
1042             fjy0             = _fjsp_setzero_v2r8();
1043             fjz0             = _fjsp_setzero_v2r8();
1044
1045             /**************************
1046              * CALCULATE INTERACTIONS *
1047              **************************/
1048
1049             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
1050             {
1051
1052             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
1053
1054             /* Compute parameters for interactions between i and j atoms */
1055             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
1056                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
1057
1058             /* LENNARD-JONES DISPERSION/REPULSION */
1059
1060             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
1061             vvdw6            = _fjsp_mul_v2r8(c6_00,rinvsix);
1062             vvdw12           = _fjsp_mul_v2r8(c12_00,_fjsp_mul_v2r8(rinvsix,rinvsix));
1063             vvdw             = _fjsp_msub_v2r8( vvdw12,one_twelfth, _fjsp_mul_v2r8(vvdw6,one_sixth) );
1064             fvdw             = _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw12,vvdw6),rinvsq00);
1065
1066             d                = _fjsp_sub_v2r8(r00,rswitch);
1067             d                = _fjsp_max_v2r8(d,_fjsp_setzero_v2r8());
1068             d2               = _fjsp_mul_v2r8(d,d);
1069             sw               = _fjsp_add_v2r8(one,_fjsp_mul_v2r8(d2,_fjsp_mul_v2r8(d,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swV5,swV4),swV3))));
1070
1071             dsw              = _fjsp_mul_v2r8(d2,_fjsp_madd_v2r8(d,_fjsp_madd_v2r8(d,swF4,swF3),swF2));
1072
1073             /* Evaluate switch function */
1074             /* fscal'=f'/r=-(v*sw)'/r=-(v'*sw+v*dsw)/r=-v'*sw/r-v*dsw/r=fscal*sw-v*dsw/r */
1075             fvdw             = _fjsp_msub_v2r8( fvdw,sw , _fjsp_mul_v2r8(rinv00,_fjsp_mul_v2r8(vvdw,dsw)) );
1076             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
1077
1078             fscal            = fvdw;
1079
1080             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
1081
1082             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
1083
1084             /* Update vectorial force */
1085             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
1086             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
1087             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
1088             
1089             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
1090             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
1091             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
1092
1093             }
1094
1095             /**************************
1096              * CALCULATE INTERACTIONS *
1097              **************************/
1098
1099             if (gmx_fjsp_any_lt_v2r8(rsq10,rcutoff2))
1100             {
1101
1102             /* Compute parameters for interactions between i and j atoms */
1103             qq10             = _fjsp_mul_v2r8(iq1,jq0);
1104
1105             /* REACTION-FIELD ELECTROSTATICS */
1106             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
1107
1108             cutoff_mask      = _fjsp_cmplt_v2r8(rsq10,rcutoff2);
1109
1110             fscal            = felec;
1111
1112             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
1113
1114             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
1115
1116             /* Update vectorial force */
1117             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
1118             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
1119             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
1120             
1121             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
1122             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
1123             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
1124
1125             }
1126
1127             /**************************
1128              * CALCULATE INTERACTIONS *
1129              **************************/
1130
1131             if (gmx_fjsp_any_lt_v2r8(rsq20,rcutoff2))
1132             {
1133
1134             /* Compute parameters for interactions between i and j atoms */
1135             qq20             = _fjsp_mul_v2r8(iq2,jq0);
1136
1137             /* REACTION-FIELD ELECTROSTATICS */
1138             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
1139
1140             cutoff_mask      = _fjsp_cmplt_v2r8(rsq20,rcutoff2);
1141
1142             fscal            = felec;
1143
1144             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
1145
1146             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
1147
1148             /* Update vectorial force */
1149             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
1150             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
1151             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
1152             
1153             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
1154             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
1155             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
1156
1157             }
1158
1159             /**************************
1160              * CALCULATE INTERACTIONS *
1161              **************************/
1162
1163             if (gmx_fjsp_any_lt_v2r8(rsq30,rcutoff2))
1164             {
1165
1166             /* Compute parameters for interactions between i and j atoms */
1167             qq30             = _fjsp_mul_v2r8(iq3,jq0);
1168
1169             /* REACTION-FIELD ELECTROSTATICS */
1170             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
1171
1172             cutoff_mask      = _fjsp_cmplt_v2r8(rsq30,rcutoff2);
1173
1174             fscal            = felec;
1175
1176             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
1177
1178             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
1179
1180             /* Update vectorial force */
1181             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
1182             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
1183             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
1184             
1185             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
1186             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
1187             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
1188
1189             }
1190
1191             gmx_fjsp_decrement_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1192
1193             /* Inner loop uses 161 flops */
1194         }
1195
1196         /* End of innermost loop */
1197
1198         gmx_fjsp_update_iforce_4atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1199                                               f+i_coord_offset,fshift+i_shift_offset);
1200
1201         /* Increment number of inner iterations */
1202         inneriter                  += j_index_end - j_index_start;
1203
1204         /* Outer loop uses 24 flops */
1205     }
1206
1207     /* Increment number of outer iterations */
1208     outeriter        += nri;
1209
1210     /* Update outer/inner flops */
1211
1212     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*161);
1213 }