80ca880c942c599679bf6c936d59f282d254882c
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sparc64_hpc_ace_double / nb_kernel_ElecRF_VdwCSTab_GeomW4P1_sparc64_hpc_ace_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*
36  * Note: this file was generated by the GROMACS sparc64_hpc_ace_double kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 #include "kernelutil_sparc64_hpc_ace_double.h"
48
49 /*
50  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwCSTab_GeomW4P1_VF_sparc64_hpc_ace_double
51  * Electrostatics interaction: ReactionField
52  * VdW interaction:            CubicSplineTable
53  * Geometry:                   Water4-Particle
54  * Calculate force/pot:        PotentialAndForce
55  */
56 void
57 nb_kernel_ElecRF_VdwCSTab_GeomW4P1_VF_sparc64_hpc_ace_double
58                     (t_nblist                    * gmx_restrict       nlist,
59                      rvec                        * gmx_restrict          xx,
60                      rvec                        * gmx_restrict          ff,
61                      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       rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
102     real             *vftab;
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->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     vftab            = kernel_data->table_vdw->data;
130     vftabscale       = gmx_fjsp_set1_v2r8(kernel_data->table_vdw->scale);
131
132     /* Setup water-specific parameters */
133     inr              = nlist->iinr[0];
134     iq1              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+1]));
135     iq2              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+2]));
136     iq3              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+3]));
137     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
138
139     /* Avoid stupid compiler warnings */
140     jnrA = jnrB = 0;
141     j_coord_offsetA = 0;
142     j_coord_offsetB = 0;
143
144     outeriter        = 0;
145     inneriter        = 0;
146
147     /* Start outer loop over neighborlists */
148     for(iidx=0; iidx<nri; iidx++)
149     {
150         /* Load shift vector for this list */
151         i_shift_offset   = DIM*shiftidx[iidx];
152
153         /* Load limits for loop over neighbors */
154         j_index_start    = jindex[iidx];
155         j_index_end      = jindex[iidx+1];
156
157         /* Get outer coordinate index */
158         inr              = iinr[iidx];
159         i_coord_offset   = DIM*inr;
160
161         /* Load i particle coords and add shift vector */
162         gmx_fjsp_load_shift_and_4rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
163                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
164
165         fix0             = _fjsp_setzero_v2r8();
166         fiy0             = _fjsp_setzero_v2r8();
167         fiz0             = _fjsp_setzero_v2r8();
168         fix1             = _fjsp_setzero_v2r8();
169         fiy1             = _fjsp_setzero_v2r8();
170         fiz1             = _fjsp_setzero_v2r8();
171         fix2             = _fjsp_setzero_v2r8();
172         fiy2             = _fjsp_setzero_v2r8();
173         fiz2             = _fjsp_setzero_v2r8();
174         fix3             = _fjsp_setzero_v2r8();
175         fiy3             = _fjsp_setzero_v2r8();
176         fiz3             = _fjsp_setzero_v2r8();
177
178         /* Reset potential sums */
179         velecsum         = _fjsp_setzero_v2r8();
180         vvdwsum          = _fjsp_setzero_v2r8();
181
182         /* Start inner kernel loop */
183         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
184         {
185
186             /* Get j neighbor index, and coordinate index */
187             jnrA             = jjnr[jidx];
188             jnrB             = jjnr[jidx+1];
189             j_coord_offsetA  = DIM*jnrA;
190             j_coord_offsetB  = DIM*jnrB;
191
192             /* load j atom coordinates */
193             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
194                                               &jx0,&jy0,&jz0);
195
196             /* Calculate displacement vector */
197             dx00             = _fjsp_sub_v2r8(ix0,jx0);
198             dy00             = _fjsp_sub_v2r8(iy0,jy0);
199             dz00             = _fjsp_sub_v2r8(iz0,jz0);
200             dx10             = _fjsp_sub_v2r8(ix1,jx0);
201             dy10             = _fjsp_sub_v2r8(iy1,jy0);
202             dz10             = _fjsp_sub_v2r8(iz1,jz0);
203             dx20             = _fjsp_sub_v2r8(ix2,jx0);
204             dy20             = _fjsp_sub_v2r8(iy2,jy0);
205             dz20             = _fjsp_sub_v2r8(iz2,jz0);
206             dx30             = _fjsp_sub_v2r8(ix3,jx0);
207             dy30             = _fjsp_sub_v2r8(iy3,jy0);
208             dz30             = _fjsp_sub_v2r8(iz3,jz0);
209
210             /* Calculate squared distance and things based on it */
211             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
212             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
213             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
214             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
215
216             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
217             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
218             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
219             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
220
221             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
222             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
223             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
224
225             /* Load parameters for j particles */
226             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
227             vdwjidx0A        = 2*vdwtype[jnrA+0];
228             vdwjidx0B        = 2*vdwtype[jnrB+0];
229
230             fjx0             = _fjsp_setzero_v2r8();
231             fjy0             = _fjsp_setzero_v2r8();
232             fjz0             = _fjsp_setzero_v2r8();
233
234             /**************************
235              * CALCULATE INTERACTIONS *
236              **************************/
237
238             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
239
240             /* Compute parameters for interactions between i and j atoms */
241             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
242                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
243
244             /* Calculate table index by multiplying r with table scale and truncate to integer */
245             rt               = _fjsp_mul_v2r8(r00,vftabscale);
246             itab_tmp         = _fjsp_dtox_v2r8(rt);
247             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
248             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
249             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
250
251             vfconv.i[0]     *= 8;
252             vfconv.i[1]     *= 8;
253
254             /* CUBIC SPLINE TABLE DISPERSION */
255             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
256             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] );
257             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
258             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
259             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 2 );
260             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
261             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
262             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
263             vvdw6            = _fjsp_mul_v2r8(c6_00,VV);
264             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
265             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
266
267             /* CUBIC SPLINE TABLE REPULSION */
268             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
269             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 4 );
270             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
271             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
272             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 6 );
273             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
274             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
275             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
276             vvdw12           = _fjsp_mul_v2r8(c12_00,VV);
277             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
278             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
279             vvdw             = _fjsp_add_v2r8(vvdw12,vvdw6);
280             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
281
282             /* Update potential sum for this i atom from the interaction with this j atom. */
283             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
284
285             fscal            = fvdw;
286
287             /* Update vectorial force */
288             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
289             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
290             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
291             
292             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
293             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
294             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
295
296             /**************************
297              * CALCULATE INTERACTIONS *
298              **************************/
299
300             /* Compute parameters for interactions between i and j atoms */
301             qq10             = _fjsp_mul_v2r8(iq1,jq0);
302
303             /* REACTION-FIELD ELECTROSTATICS */
304             velec            = _fjsp_mul_v2r8(qq10,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq10,rinv10),crf));
305             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
306
307             /* Update potential sum for this i atom from the interaction with this j atom. */
308             velecsum         = _fjsp_add_v2r8(velecsum,velec);
309
310             fscal            = felec;
311
312             /* Update vectorial force */
313             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
314             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
315             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
316             
317             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
318             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
319             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
320
321             /**************************
322              * CALCULATE INTERACTIONS *
323              **************************/
324
325             /* Compute parameters for interactions between i and j atoms */
326             qq20             = _fjsp_mul_v2r8(iq2,jq0);
327
328             /* REACTION-FIELD ELECTROSTATICS */
329             velec            = _fjsp_mul_v2r8(qq20,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq20,rinv20),crf));
330             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
331
332             /* Update potential sum for this i atom from the interaction with this j atom. */
333             velecsum         = _fjsp_add_v2r8(velecsum,velec);
334
335             fscal            = felec;
336
337             /* Update vectorial force */
338             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
339             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
340             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
341             
342             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
343             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
344             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
345
346             /**************************
347              * CALCULATE INTERACTIONS *
348              **************************/
349
350             /* Compute parameters for interactions between i and j atoms */
351             qq30             = _fjsp_mul_v2r8(iq3,jq0);
352
353             /* REACTION-FIELD ELECTROSTATICS */
354             velec            = _fjsp_mul_v2r8(qq30,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq30,rinv30),crf));
355             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
356
357             /* Update potential sum for this i atom from the interaction with this j atom. */
358             velecsum         = _fjsp_add_v2r8(velecsum,velec);
359
360             fscal            = felec;
361
362             /* Update vectorial force */
363             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
364             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
365             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
366             
367             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
368             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
369             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
370
371             gmx_fjsp_decrement_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
372
373             /* Inner loop uses 167 flops */
374         }
375
376         if(jidx<j_index_end)
377         {
378
379             jnrA             = jjnr[jidx];
380             j_coord_offsetA  = DIM*jnrA;
381
382             /* load j atom coordinates */
383             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
384                                               &jx0,&jy0,&jz0);
385
386             /* Calculate displacement vector */
387             dx00             = _fjsp_sub_v2r8(ix0,jx0);
388             dy00             = _fjsp_sub_v2r8(iy0,jy0);
389             dz00             = _fjsp_sub_v2r8(iz0,jz0);
390             dx10             = _fjsp_sub_v2r8(ix1,jx0);
391             dy10             = _fjsp_sub_v2r8(iy1,jy0);
392             dz10             = _fjsp_sub_v2r8(iz1,jz0);
393             dx20             = _fjsp_sub_v2r8(ix2,jx0);
394             dy20             = _fjsp_sub_v2r8(iy2,jy0);
395             dz20             = _fjsp_sub_v2r8(iz2,jz0);
396             dx30             = _fjsp_sub_v2r8(ix3,jx0);
397             dy30             = _fjsp_sub_v2r8(iy3,jy0);
398             dz30             = _fjsp_sub_v2r8(iz3,jz0);
399
400             /* Calculate squared distance and things based on it */
401             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
402             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
403             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
404             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
405
406             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
407             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
408             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
409             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
410
411             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
412             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
413             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
414
415             /* Load parameters for j particles */
416             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
417             vdwjidx0A        = 2*vdwtype[jnrA+0];
418
419             fjx0             = _fjsp_setzero_v2r8();
420             fjy0             = _fjsp_setzero_v2r8();
421             fjz0             = _fjsp_setzero_v2r8();
422
423             /**************************
424              * CALCULATE INTERACTIONS *
425              **************************/
426
427             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
428
429             /* Compute parameters for interactions between i and j atoms */
430             gmx_fjsp_load_1pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
431
432             /* Calculate table index by multiplying r with table scale and truncate to integer */
433             rt               = _fjsp_mul_v2r8(r00,vftabscale);
434             itab_tmp         = _fjsp_dtox_v2r8(rt);
435             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
436             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
437             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
438
439             vfconv.i[0]     *= 8;
440             vfconv.i[1]     *= 8;
441
442             /* CUBIC SPLINE TABLE DISPERSION */
443             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
444             F                = _fjsp_setzero_v2r8();
445             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
446             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
447             H                = _fjsp_setzero_v2r8();
448             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
449             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
450             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
451             vvdw6            = _fjsp_mul_v2r8(c6_00,VV);
452             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
453             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
454
455             /* CUBIC SPLINE TABLE REPULSION */
456             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
457             F                = _fjsp_setzero_v2r8();
458             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
459             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
460             H                = _fjsp_setzero_v2r8();
461             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
462             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
463             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
464             vvdw12           = _fjsp_mul_v2r8(c12_00,VV);
465             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
466             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
467             vvdw             = _fjsp_add_v2r8(vvdw12,vvdw6);
468             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
469
470             /* Update potential sum for this i atom from the interaction with this j atom. */
471             vvdw             = _fjsp_unpacklo_v2r8(vvdw,_fjsp_setzero_v2r8());
472             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
473
474             fscal            = fvdw;
475
476             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
477
478             /* Update vectorial force */
479             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
480             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
481             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
482             
483             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
484             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
485             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
486
487             /**************************
488              * CALCULATE INTERACTIONS *
489              **************************/
490
491             /* Compute parameters for interactions between i and j atoms */
492             qq10             = _fjsp_mul_v2r8(iq1,jq0);
493
494             /* REACTION-FIELD ELECTROSTATICS */
495             velec            = _fjsp_mul_v2r8(qq10,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq10,rinv10),crf));
496             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
497
498             /* Update potential sum for this i atom from the interaction with this j atom. */
499             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
500             velecsum         = _fjsp_add_v2r8(velecsum,velec);
501
502             fscal            = felec;
503
504             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
505
506             /* Update vectorial force */
507             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
508             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
509             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
510             
511             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
512             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
513             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
514
515             /**************************
516              * CALCULATE INTERACTIONS *
517              **************************/
518
519             /* Compute parameters for interactions between i and j atoms */
520             qq20             = _fjsp_mul_v2r8(iq2,jq0);
521
522             /* REACTION-FIELD ELECTROSTATICS */
523             velec            = _fjsp_mul_v2r8(qq20,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq20,rinv20),crf));
524             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
525
526             /* Update potential sum for this i atom from the interaction with this j atom. */
527             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
528             velecsum         = _fjsp_add_v2r8(velecsum,velec);
529
530             fscal            = felec;
531
532             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
533
534             /* Update vectorial force */
535             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
536             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
537             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
538             
539             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
540             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
541             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
542
543             /**************************
544              * CALCULATE INTERACTIONS *
545              **************************/
546
547             /* Compute parameters for interactions between i and j atoms */
548             qq30             = _fjsp_mul_v2r8(iq3,jq0);
549
550             /* REACTION-FIELD ELECTROSTATICS */
551             velec            = _fjsp_mul_v2r8(qq30,_fjsp_sub_v2r8(_fjsp_madd_v2r8(krf,rsq30,rinv30),crf));
552             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
553
554             /* Update potential sum for this i atom from the interaction with this j atom. */
555             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
556             velecsum         = _fjsp_add_v2r8(velecsum,velec);
557
558             fscal            = felec;
559
560             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
561
562             /* Update vectorial force */
563             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
564             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
565             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
566             
567             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
568             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
569             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
570
571             gmx_fjsp_decrement_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0);
572
573             /* Inner loop uses 167 flops */
574         }
575
576         /* End of innermost loop */
577
578         gmx_fjsp_update_iforce_4atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
579                                               f+i_coord_offset,fshift+i_shift_offset);
580
581         ggid                        = gid[iidx];
582         /* Update potential energies */
583         gmx_fjsp_update_1pot_v2r8(velecsum,kernel_data->energygrp_elec+ggid);
584         gmx_fjsp_update_1pot_v2r8(vvdwsum,kernel_data->energygrp_vdw+ggid);
585
586         /* Increment number of inner iterations */
587         inneriter                  += j_index_end - j_index_start;
588
589         /* Outer loop uses 26 flops */
590     }
591
592     /* Increment number of outer iterations */
593     outeriter        += nri;
594
595     /* Update outer/inner flops */
596
597     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*167);
598 }
599 /*
600  * Gromacs nonbonded kernel:   nb_kernel_ElecRF_VdwCSTab_GeomW4P1_F_sparc64_hpc_ace_double
601  * Electrostatics interaction: ReactionField
602  * VdW interaction:            CubicSplineTable
603  * Geometry:                   Water4-Particle
604  * Calculate force/pot:        Force
605  */
606 void
607 nb_kernel_ElecRF_VdwCSTab_GeomW4P1_F_sparc64_hpc_ace_double
608                     (t_nblist                    * gmx_restrict       nlist,
609                      rvec                        * gmx_restrict          xx,
610                      rvec                        * gmx_restrict          ff,
611                      t_forcerec                  * gmx_restrict          fr,
612                      t_mdatoms                   * gmx_restrict     mdatoms,
613                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
614                      t_nrnb                      * gmx_restrict        nrnb)
615 {
616     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
617      * just 0 for non-waters.
618      * Suffixes A,B refer to j loop unrolling done with double precision SIMD, e.g. for the two different
619      * jnr indices corresponding to data put in the four positions in the SIMD register.
620      */
621     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
622     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
623     int              jnrA,jnrB;
624     int              j_coord_offsetA,j_coord_offsetB;
625     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
626     real             rcutoff_scalar;
627     real             *shiftvec,*fshift,*x,*f;
628     _fjsp_v2r8       tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
629     int              vdwioffset0;
630     _fjsp_v2r8       ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
631     int              vdwioffset1;
632     _fjsp_v2r8       ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
633     int              vdwioffset2;
634     _fjsp_v2r8       ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
635     int              vdwioffset3;
636     _fjsp_v2r8       ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
637     int              vdwjidx0A,vdwjidx0B;
638     _fjsp_v2r8       jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
639     _fjsp_v2r8       dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
640     _fjsp_v2r8       dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
641     _fjsp_v2r8       dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
642     _fjsp_v2r8       dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
643     _fjsp_v2r8       velec,felec,velecsum,facel,crf,krf,krf2;
644     real             *charge;
645     int              nvdwtype;
646     _fjsp_v2r8       rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
647     int              *vdwtype;
648     real             *vdwparam;
649     _fjsp_v2r8       one_sixth   = gmx_fjsp_set1_v2r8(1.0/6.0);
650     _fjsp_v2r8       one_twelfth = gmx_fjsp_set1_v2r8(1.0/12.0);
651     _fjsp_v2r8       rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
652     real             *vftab;
653     _fjsp_v2r8       itab_tmp;
654     _fjsp_v2r8       dummy_mask,cutoff_mask;
655     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
656     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
657     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
658
659     x                = xx[0];
660     f                = ff[0];
661
662     nri              = nlist->nri;
663     iinr             = nlist->iinr;
664     jindex           = nlist->jindex;
665     jjnr             = nlist->jjnr;
666     shiftidx         = nlist->shift;
667     gid              = nlist->gid;
668     shiftvec         = fr->shift_vec[0];
669     fshift           = fr->fshift[0];
670     facel            = gmx_fjsp_set1_v2r8(fr->epsfac);
671     charge           = mdatoms->chargeA;
672     krf              = gmx_fjsp_set1_v2r8(fr->ic->k_rf);
673     krf2             = gmx_fjsp_set1_v2r8(fr->ic->k_rf*2.0);
674     crf              = gmx_fjsp_set1_v2r8(fr->ic->c_rf);
675     nvdwtype         = fr->ntype;
676     vdwparam         = fr->nbfp;
677     vdwtype          = mdatoms->typeA;
678
679     vftab            = kernel_data->table_vdw->data;
680     vftabscale       = gmx_fjsp_set1_v2r8(kernel_data->table_vdw->scale);
681
682     /* Setup water-specific parameters */
683     inr              = nlist->iinr[0];
684     iq1              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+1]));
685     iq2              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+2]));
686     iq3              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+3]));
687     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
688
689     /* Avoid stupid compiler warnings */
690     jnrA = jnrB = 0;
691     j_coord_offsetA = 0;
692     j_coord_offsetB = 0;
693
694     outeriter        = 0;
695     inneriter        = 0;
696
697     /* Start outer loop over neighborlists */
698     for(iidx=0; iidx<nri; iidx++)
699     {
700         /* Load shift vector for this list */
701         i_shift_offset   = DIM*shiftidx[iidx];
702
703         /* Load limits for loop over neighbors */
704         j_index_start    = jindex[iidx];
705         j_index_end      = jindex[iidx+1];
706
707         /* Get outer coordinate index */
708         inr              = iinr[iidx];
709         i_coord_offset   = DIM*inr;
710
711         /* Load i particle coords and add shift vector */
712         gmx_fjsp_load_shift_and_4rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
713                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
714
715         fix0             = _fjsp_setzero_v2r8();
716         fiy0             = _fjsp_setzero_v2r8();
717         fiz0             = _fjsp_setzero_v2r8();
718         fix1             = _fjsp_setzero_v2r8();
719         fiy1             = _fjsp_setzero_v2r8();
720         fiz1             = _fjsp_setzero_v2r8();
721         fix2             = _fjsp_setzero_v2r8();
722         fiy2             = _fjsp_setzero_v2r8();
723         fiz2             = _fjsp_setzero_v2r8();
724         fix3             = _fjsp_setzero_v2r8();
725         fiy3             = _fjsp_setzero_v2r8();
726         fiz3             = _fjsp_setzero_v2r8();
727
728         /* Start inner kernel loop */
729         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
730         {
731
732             /* Get j neighbor index, and coordinate index */
733             jnrA             = jjnr[jidx];
734             jnrB             = jjnr[jidx+1];
735             j_coord_offsetA  = DIM*jnrA;
736             j_coord_offsetB  = DIM*jnrB;
737
738             /* load j atom coordinates */
739             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
740                                               &jx0,&jy0,&jz0);
741
742             /* Calculate displacement vector */
743             dx00             = _fjsp_sub_v2r8(ix0,jx0);
744             dy00             = _fjsp_sub_v2r8(iy0,jy0);
745             dz00             = _fjsp_sub_v2r8(iz0,jz0);
746             dx10             = _fjsp_sub_v2r8(ix1,jx0);
747             dy10             = _fjsp_sub_v2r8(iy1,jy0);
748             dz10             = _fjsp_sub_v2r8(iz1,jz0);
749             dx20             = _fjsp_sub_v2r8(ix2,jx0);
750             dy20             = _fjsp_sub_v2r8(iy2,jy0);
751             dz20             = _fjsp_sub_v2r8(iz2,jz0);
752             dx30             = _fjsp_sub_v2r8(ix3,jx0);
753             dy30             = _fjsp_sub_v2r8(iy3,jy0);
754             dz30             = _fjsp_sub_v2r8(iz3,jz0);
755
756             /* Calculate squared distance and things based on it */
757             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
758             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
759             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
760             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
761
762             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
763             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
764             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
765             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
766
767             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
768             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
769             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
770
771             /* Load parameters for j particles */
772             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
773             vdwjidx0A        = 2*vdwtype[jnrA+0];
774             vdwjidx0B        = 2*vdwtype[jnrB+0];
775
776             fjx0             = _fjsp_setzero_v2r8();
777             fjy0             = _fjsp_setzero_v2r8();
778             fjz0             = _fjsp_setzero_v2r8();
779
780             /**************************
781              * CALCULATE INTERACTIONS *
782              **************************/
783
784             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
785
786             /* Compute parameters for interactions between i and j atoms */
787             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
788                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
789
790             /* Calculate table index by multiplying r with table scale and truncate to integer */
791             rt               = _fjsp_mul_v2r8(r00,vftabscale);
792             itab_tmp         = _fjsp_dtox_v2r8(rt);
793             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
794             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
795             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
796
797             vfconv.i[0]     *= 8;
798             vfconv.i[1]     *= 8;
799
800             /* CUBIC SPLINE TABLE DISPERSION */
801             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
802             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] );
803             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
804             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
805             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 2 );
806             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
807             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
808             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
809             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
810
811             /* CUBIC SPLINE TABLE REPULSION */
812             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
813             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 4 );
814             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
815             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
816             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 6 );
817             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
818             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
819             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
820             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
821             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
822
823             fscal            = fvdw;
824
825             /* Update vectorial force */
826             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
827             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
828             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
829             
830             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
831             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
832             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
833
834             /**************************
835              * CALCULATE INTERACTIONS *
836              **************************/
837
838             /* Compute parameters for interactions between i and j atoms */
839             qq10             = _fjsp_mul_v2r8(iq1,jq0);
840
841             /* REACTION-FIELD ELECTROSTATICS */
842             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
843
844             fscal            = felec;
845
846             /* Update vectorial force */
847             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
848             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
849             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
850             
851             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
852             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
853             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
854
855             /**************************
856              * CALCULATE INTERACTIONS *
857              **************************/
858
859             /* Compute parameters for interactions between i and j atoms */
860             qq20             = _fjsp_mul_v2r8(iq2,jq0);
861
862             /* REACTION-FIELD ELECTROSTATICS */
863             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
864
865             fscal            = felec;
866
867             /* Update vectorial force */
868             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
869             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
870             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
871             
872             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
873             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
874             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
875
876             /**************************
877              * CALCULATE INTERACTIONS *
878              **************************/
879
880             /* Compute parameters for interactions between i and j atoms */
881             qq30             = _fjsp_mul_v2r8(iq3,jq0);
882
883             /* REACTION-FIELD ELECTROSTATICS */
884             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
885
886             fscal            = felec;
887
888             /* Update vectorial force */
889             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
890             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
891             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
892             
893             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
894             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
895             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
896
897             gmx_fjsp_decrement_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
898
899             /* Inner loop uses 144 flops */
900         }
901
902         if(jidx<j_index_end)
903         {
904
905             jnrA             = jjnr[jidx];
906             j_coord_offsetA  = DIM*jnrA;
907
908             /* load j atom coordinates */
909             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
910                                               &jx0,&jy0,&jz0);
911
912             /* Calculate displacement vector */
913             dx00             = _fjsp_sub_v2r8(ix0,jx0);
914             dy00             = _fjsp_sub_v2r8(iy0,jy0);
915             dz00             = _fjsp_sub_v2r8(iz0,jz0);
916             dx10             = _fjsp_sub_v2r8(ix1,jx0);
917             dy10             = _fjsp_sub_v2r8(iy1,jy0);
918             dz10             = _fjsp_sub_v2r8(iz1,jz0);
919             dx20             = _fjsp_sub_v2r8(ix2,jx0);
920             dy20             = _fjsp_sub_v2r8(iy2,jy0);
921             dz20             = _fjsp_sub_v2r8(iz2,jz0);
922             dx30             = _fjsp_sub_v2r8(ix3,jx0);
923             dy30             = _fjsp_sub_v2r8(iy3,jy0);
924             dz30             = _fjsp_sub_v2r8(iz3,jz0);
925
926             /* Calculate squared distance and things based on it */
927             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
928             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
929             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
930             rsq30            = gmx_fjsp_calc_rsq_v2r8(dx30,dy30,dz30);
931
932             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
933             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
934             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
935             rinv30           = gmx_fjsp_invsqrt_v2r8(rsq30);
936
937             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
938             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
939             rinvsq30         = _fjsp_mul_v2r8(rinv30,rinv30);
940
941             /* Load parameters for j particles */
942             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
943             vdwjidx0A        = 2*vdwtype[jnrA+0];
944
945             fjx0             = _fjsp_setzero_v2r8();
946             fjy0             = _fjsp_setzero_v2r8();
947             fjz0             = _fjsp_setzero_v2r8();
948
949             /**************************
950              * CALCULATE INTERACTIONS *
951              **************************/
952
953             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
954
955             /* Compute parameters for interactions between i and j atoms */
956             gmx_fjsp_load_1pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
957
958             /* Calculate table index by multiplying r with table scale and truncate to integer */
959             rt               = _fjsp_mul_v2r8(r00,vftabscale);
960             itab_tmp         = _fjsp_dtox_v2r8(rt);
961             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
962             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
963             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
964
965             vfconv.i[0]     *= 8;
966             vfconv.i[1]     *= 8;
967
968             /* CUBIC SPLINE TABLE DISPERSION */
969             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
970             F                = _fjsp_setzero_v2r8();
971             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
972             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
973             H                = _fjsp_setzero_v2r8();
974             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
975             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
976             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
977             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
978
979             /* CUBIC SPLINE TABLE REPULSION */
980             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
981             F                = _fjsp_setzero_v2r8();
982             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
983             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
984             H                = _fjsp_setzero_v2r8();
985             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
986             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
987             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
988             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
989             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
990
991             fscal            = fvdw;
992
993             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
994
995             /* Update vectorial force */
996             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
997             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
998             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
999             
1000             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
1001             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
1002             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
1003
1004             /**************************
1005              * CALCULATE INTERACTIONS *
1006              **************************/
1007
1008             /* Compute parameters for interactions between i and j atoms */
1009             qq10             = _fjsp_mul_v2r8(iq1,jq0);
1010
1011             /* REACTION-FIELD ELECTROSTATICS */
1012             felec            = _fjsp_mul_v2r8(qq10,_fjsp_msub_v2r8(rinv10,rinvsq10,krf2));
1013
1014             fscal            = felec;
1015
1016             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
1017
1018             /* Update vectorial force */
1019             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
1020             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
1021             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
1022             
1023             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
1024             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
1025             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
1026
1027             /**************************
1028              * CALCULATE INTERACTIONS *
1029              **************************/
1030
1031             /* Compute parameters for interactions between i and j atoms */
1032             qq20             = _fjsp_mul_v2r8(iq2,jq0);
1033
1034             /* REACTION-FIELD ELECTROSTATICS */
1035             felec            = _fjsp_mul_v2r8(qq20,_fjsp_msub_v2r8(rinv20,rinvsq20,krf2));
1036
1037             fscal            = felec;
1038
1039             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
1040
1041             /* Update vectorial force */
1042             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
1043             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
1044             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
1045             
1046             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
1047             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
1048             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
1049
1050             /**************************
1051              * CALCULATE INTERACTIONS *
1052              **************************/
1053
1054             /* Compute parameters for interactions between i and j atoms */
1055             qq30             = _fjsp_mul_v2r8(iq3,jq0);
1056
1057             /* REACTION-FIELD ELECTROSTATICS */
1058             felec            = _fjsp_mul_v2r8(qq30,_fjsp_msub_v2r8(rinv30,rinvsq30,krf2));
1059
1060             fscal            = felec;
1061
1062             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
1063
1064             /* Update vectorial force */
1065             fix3             = _fjsp_madd_v2r8(dx30,fscal,fix3);
1066             fiy3             = _fjsp_madd_v2r8(dy30,fscal,fiy3);
1067             fiz3             = _fjsp_madd_v2r8(dz30,fscal,fiz3);
1068             
1069             fjx0             = _fjsp_madd_v2r8(dx30,fscal,fjx0);
1070             fjy0             = _fjsp_madd_v2r8(dy30,fscal,fjy0);
1071             fjz0             = _fjsp_madd_v2r8(dz30,fscal,fjz0);
1072
1073             gmx_fjsp_decrement_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0);
1074
1075             /* Inner loop uses 144 flops */
1076         }
1077
1078         /* End of innermost loop */
1079
1080         gmx_fjsp_update_iforce_4atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1081                                               f+i_coord_offset,fshift+i_shift_offset);
1082
1083         /* Increment number of inner iterations */
1084         inneriter                  += j_index_end - j_index_start;
1085
1086         /* Outer loop uses 24 flops */
1087     }
1088
1089     /* Increment number of outer iterations */
1090     outeriter        += nri;
1091
1092     /* Update outer/inner flops */
1093
1094     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*144);
1095 }