K-computer specific modifications
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sparc64_hpc_ace_double / nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_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 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include <math.h>
43
44 #include "../nb_kernel.h"
45 #include "types/simple.h"
46 #include "gromacs/legacyheaders/vec.h"
47 #include "nrnb.h"
48
49 #include "kernelutil_sparc64_hpc_ace_double.h"
50
51 /*
52  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_VF_sparc64_hpc_ace_double
53  * Electrostatics interaction: CubicSplineTable
54  * VdW interaction:            CubicSplineTable
55  * Geometry:                   Particle-Particle
56  * Calculate force/pot:        PotentialAndForce
57  */
58 void
59 nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_VF_sparc64_hpc_ace_double
60                     (t_nblist                    * gmx_restrict       nlist,
61                      rvec                        * gmx_restrict          xx,
62                      rvec                        * gmx_restrict          ff,
63                      t_forcerec                  * gmx_restrict          fr,
64                      t_mdatoms                   * gmx_restrict     mdatoms,
65                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
66                      t_nrnb                      * gmx_restrict        nrnb)
67 {
68     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
69      * just 0 for non-waters.
70      * Suffixes A,B refer to j loop unrolling done with double precision SIMD, e.g. for the two different
71      * jnr indices corresponding to data put in the four positions in the SIMD register.
72      */
73     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
74     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
75     int              jnrA,jnrB;
76     int              j_coord_offsetA,j_coord_offsetB;
77     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
78     real             rcutoff_scalar;
79     real             *shiftvec,*fshift,*x,*f;
80     _fjsp_v2r8       tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
81     int              vdwioffset0;
82     _fjsp_v2r8       ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
83     int              vdwjidx0A,vdwjidx0B;
84     _fjsp_v2r8       jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
85     _fjsp_v2r8       dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
86     _fjsp_v2r8       velec,felec,velecsum,facel,crf,krf,krf2;
87     real             *charge;
88     int              nvdwtype;
89     _fjsp_v2r8       rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
90     int              *vdwtype;
91     real             *vdwparam;
92     _fjsp_v2r8       one_sixth   = gmx_fjsp_set1_v2r8(1.0/6.0);
93     _fjsp_v2r8       one_twelfth = gmx_fjsp_set1_v2r8(1.0/12.0);
94     _fjsp_v2r8       rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
95     real             *vftab;
96     _fjsp_v2r8       itab_tmp;
97     _fjsp_v2r8       dummy_mask,cutoff_mask;
98     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
99     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
100     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
101
102     x                = xx[0];
103     f                = ff[0];
104
105     nri              = nlist->nri;
106     iinr             = nlist->iinr;
107     jindex           = nlist->jindex;
108     jjnr             = nlist->jjnr;
109     shiftidx         = nlist->shift;
110     gid              = nlist->gid;
111     shiftvec         = fr->shift_vec[0];
112     fshift           = fr->fshift[0];
113     facel            = gmx_fjsp_set1_v2r8(fr->epsfac);
114     charge           = mdatoms->chargeA;
115     nvdwtype         = fr->ntype;
116     vdwparam         = fr->nbfp;
117     vdwtype          = mdatoms->typeA;
118
119     vftab            = kernel_data->table_elec_vdw->data;
120     vftabscale       = gmx_fjsp_set1_v2r8(kernel_data->table_elec_vdw->scale);
121
122     /* Avoid stupid compiler warnings */
123     jnrA = jnrB = 0;
124     j_coord_offsetA = 0;
125     j_coord_offsetB = 0;
126
127     outeriter        = 0;
128     inneriter        = 0;
129
130     /* Start outer loop over neighborlists */
131     for(iidx=0; iidx<nri; iidx++)
132     {
133         /* Load shift vector for this list */
134         i_shift_offset   = DIM*shiftidx[iidx];
135
136         /* Load limits for loop over neighbors */
137         j_index_start    = jindex[iidx];
138         j_index_end      = jindex[iidx+1];
139
140         /* Get outer coordinate index */
141         inr              = iinr[iidx];
142         i_coord_offset   = DIM*inr;
143
144         /* Load i particle coords and add shift vector */
145         gmx_fjsp_load_shift_and_1rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
146
147         fix0             = _fjsp_setzero_v2r8();
148         fiy0             = _fjsp_setzero_v2r8();
149         fiz0             = _fjsp_setzero_v2r8();
150
151         /* Load parameters for i particles */
152         iq0              = _fjsp_mul_v2r8(facel,gmx_fjsp_load1_v2r8(charge+inr+0));
153         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
154
155         /* Reset potential sums */
156         velecsum         = _fjsp_setzero_v2r8();
157         vvdwsum          = _fjsp_setzero_v2r8();
158
159         /* Start inner kernel loop */
160         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
161         {
162
163             /* Get j neighbor index, and coordinate index */
164             jnrA             = jjnr[jidx];
165             jnrB             = jjnr[jidx+1];
166             j_coord_offsetA  = DIM*jnrA;
167             j_coord_offsetB  = DIM*jnrB;
168
169             /* load j atom coordinates */
170             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
171                                               &jx0,&jy0,&jz0);
172
173             /* Calculate displacement vector */
174             dx00             = _fjsp_sub_v2r8(ix0,jx0);
175             dy00             = _fjsp_sub_v2r8(iy0,jy0);
176             dz00             = _fjsp_sub_v2r8(iz0,jz0);
177
178             /* Calculate squared distance and things based on it */
179             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
180
181             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
182
183             /* Load parameters for j particles */
184             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
185             vdwjidx0A        = 2*vdwtype[jnrA+0];
186             vdwjidx0B        = 2*vdwtype[jnrB+0];
187
188             /**************************
189              * CALCULATE INTERACTIONS *
190              **************************/
191
192             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
193
194             /* Compute parameters for interactions between i and j atoms */
195             qq00             = _fjsp_mul_v2r8(iq0,jq0);
196             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
197                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
198
199             /* Calculate table index by multiplying r with table scale and truncate to integer */
200             rt               = _fjsp_mul_v2r8(r00,vftabscale);
201             itab_tmp         = _fjsp_dtox_v2r8(rt);
202             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
203             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
204             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
205
206             vfconv.i[0]     *= 12;
207             vfconv.i[1]     *= 12;
208
209             /* CUBIC SPLINE TABLE ELECTROSTATICS */
210             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
211             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] );
212             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
213             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] +2);
214             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] +2);
215             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
216             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(vfeps,H,G),F);
217             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
218             velec            = _fjsp_mul_v2r8(qq00,VV);
219             FF               = _fjsp_madd_v2r8(_fjsp_madd_v2r8(twovfeps,H,G),vfeps,Fp);
220             felec            = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,FF),_fjsp_mul_v2r8(vftabscale,rinv00)));
221
222             /* CUBIC SPLINE TABLE DISPERSION */
223             vfconv.i[0]       += 4;
224             vfconv.i[1]       += 4;
225             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
226             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] );
227             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
228             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
229             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 2 );
230             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
231             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
232             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
233             vvdw6            = _fjsp_mul_v2r8(c6_00,VV);
234             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
235             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
236
237             /* CUBIC SPLINE TABLE REPULSION */
238             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
239             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 4 );
240             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
241             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
242             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 6 );
243             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
244             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
245             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
246             vvdw12           = _fjsp_mul_v2r8(c12_00,VV);
247             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
248             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
249             vvdw             = _fjsp_add_v2r8(vvdw12,vvdw6);
250             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
251
252             /* Update potential sum for this i atom from the interaction with this j atom. */
253             velecsum         = _fjsp_add_v2r8(velecsum,velec);
254             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
255
256             fscal            = _fjsp_add_v2r8(felec,fvdw);
257
258             /* Update vectorial force */
259             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
260             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
261             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
262             
263             gmx_fjsp_decrement_fma_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fscal,dx00,dy00,dz00);
264
265             /* Inner loop uses 76 flops */
266         }
267
268         if(jidx<j_index_end)
269         {
270
271             jnrA             = jjnr[jidx];
272             j_coord_offsetA  = DIM*jnrA;
273
274             /* load j atom coordinates */
275             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
276                                               &jx0,&jy0,&jz0);
277
278             /* Calculate displacement vector */
279             dx00             = _fjsp_sub_v2r8(ix0,jx0);
280             dy00             = _fjsp_sub_v2r8(iy0,jy0);
281             dz00             = _fjsp_sub_v2r8(iz0,jz0);
282
283             /* Calculate squared distance and things based on it */
284             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
285
286             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
287
288             /* Load parameters for j particles */
289             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
290             vdwjidx0A        = 2*vdwtype[jnrA+0];
291
292             /**************************
293              * CALCULATE INTERACTIONS *
294              **************************/
295
296             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
297
298             /* Compute parameters for interactions between i and j atoms */
299             qq00             = _fjsp_mul_v2r8(iq0,jq0);
300             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
301                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
302
303             /* Calculate table index by multiplying r with table scale and truncate to integer */
304             rt               = _fjsp_mul_v2r8(r00,vftabscale);
305             itab_tmp         = _fjsp_dtox_v2r8(rt);
306             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
307             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
308             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
309
310             vfconv.i[0]     *= 12;
311             vfconv.i[1]     *= 12;
312
313             /* CUBIC SPLINE TABLE ELECTROSTATICS */
314             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
315             F                = _fjsp_setzero_v2r8();
316             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
317             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] +2);
318             H                = _fjsp_setzero_v2r8();
319             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
320             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(vfeps,H,G),F);
321             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
322             velec            = _fjsp_mul_v2r8(qq00,VV);
323             FF               = _fjsp_madd_v2r8(_fjsp_madd_v2r8(twovfeps,H,G),vfeps,Fp);
324             felec            = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,FF),_fjsp_mul_v2r8(vftabscale,rinv00)));
325
326             /* CUBIC SPLINE TABLE DISPERSION */
327             vfconv.i[0]       += 4;
328             vfconv.i[1]       += 4;
329             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
330             F                = _fjsp_setzero_v2r8();
331             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
332             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
333             H                = _fjsp_setzero_v2r8();
334             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
335             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
336             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
337             vvdw6            = _fjsp_mul_v2r8(c6_00,VV);
338             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
339             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
340
341             /* CUBIC SPLINE TABLE REPULSION */
342             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
343             F                = _fjsp_setzero_v2r8();
344             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
345             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
346             H                = _fjsp_setzero_v2r8();
347             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
348             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
349             VV               = _fjsp_madd_v2r8(vfeps,Fp,Y);
350             vvdw12           = _fjsp_mul_v2r8(c12_00,VV);
351             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
352             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
353             vvdw             = _fjsp_add_v2r8(vvdw12,vvdw6);
354             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
355
356             /* Update potential sum for this i atom from the interaction with this j atom. */
357             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
358             velecsum         = _fjsp_add_v2r8(velecsum,velec);
359             vvdw             = _fjsp_unpacklo_v2r8(vvdw,_fjsp_setzero_v2r8());
360             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
361
362             fscal            = _fjsp_add_v2r8(felec,fvdw);
363
364             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
365
366             /* Update vectorial force */
367             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
368             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
369             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
370             
371             gmx_fjsp_decrement_fma_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fscal,dx00,dy00,dz00);
372
373             /* Inner loop uses 76 flops */
374         }
375
376         /* End of innermost loop */
377
378         gmx_fjsp_update_iforce_1atom_swizzle_v2r8(fix0,fiy0,fiz0,
379                                               f+i_coord_offset,fshift+i_shift_offset);
380
381         ggid                        = gid[iidx];
382         /* Update potential energies */
383         gmx_fjsp_update_1pot_v2r8(velecsum,kernel_data->energygrp_elec+ggid);
384         gmx_fjsp_update_1pot_v2r8(vvdwsum,kernel_data->energygrp_vdw+ggid);
385
386         /* Increment number of inner iterations */
387         inneriter                  += j_index_end - j_index_start;
388
389         /* Outer loop uses 9 flops */
390     }
391
392     /* Increment number of outer iterations */
393     outeriter        += nri;
394
395     /* Update outer/inner flops */
396
397     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*76);
398 }
399 /*
400  * Gromacs nonbonded kernel:   nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_F_sparc64_hpc_ace_double
401  * Electrostatics interaction: CubicSplineTable
402  * VdW interaction:            CubicSplineTable
403  * Geometry:                   Particle-Particle
404  * Calculate force/pot:        Force
405  */
406 void
407 nb_kernel_ElecCSTab_VdwCSTab_GeomP1P1_F_sparc64_hpc_ace_double
408                     (t_nblist                    * gmx_restrict       nlist,
409                      rvec                        * gmx_restrict          xx,
410                      rvec                        * gmx_restrict          ff,
411                      t_forcerec                  * gmx_restrict          fr,
412                      t_mdatoms                   * gmx_restrict     mdatoms,
413                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
414                      t_nrnb                      * gmx_restrict        nrnb)
415 {
416     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
417      * just 0 for non-waters.
418      * Suffixes A,B refer to j loop unrolling done with double precision SIMD, e.g. for the two different
419      * jnr indices corresponding to data put in the four positions in the SIMD register.
420      */
421     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
422     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
423     int              jnrA,jnrB;
424     int              j_coord_offsetA,j_coord_offsetB;
425     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
426     real             rcutoff_scalar;
427     real             *shiftvec,*fshift,*x,*f;
428     _fjsp_v2r8       tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
429     int              vdwioffset0;
430     _fjsp_v2r8       ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
431     int              vdwjidx0A,vdwjidx0B;
432     _fjsp_v2r8       jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
433     _fjsp_v2r8       dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
434     _fjsp_v2r8       velec,felec,velecsum,facel,crf,krf,krf2;
435     real             *charge;
436     int              nvdwtype;
437     _fjsp_v2r8       rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
438     int              *vdwtype;
439     real             *vdwparam;
440     _fjsp_v2r8       one_sixth   = gmx_fjsp_set1_v2r8(1.0/6.0);
441     _fjsp_v2r8       one_twelfth = gmx_fjsp_set1_v2r8(1.0/12.0);
442     _fjsp_v2r8       rt,vfeps,vftabscale,Y,F,G,H,Heps,Fp,VV,FF,twovfeps;
443     real             *vftab;
444     _fjsp_v2r8       itab_tmp;
445     _fjsp_v2r8       dummy_mask,cutoff_mask;
446     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
447     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
448     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
449
450     x                = xx[0];
451     f                = ff[0];
452
453     nri              = nlist->nri;
454     iinr             = nlist->iinr;
455     jindex           = nlist->jindex;
456     jjnr             = nlist->jjnr;
457     shiftidx         = nlist->shift;
458     gid              = nlist->gid;
459     shiftvec         = fr->shift_vec[0];
460     fshift           = fr->fshift[0];
461     facel            = gmx_fjsp_set1_v2r8(fr->epsfac);
462     charge           = mdatoms->chargeA;
463     nvdwtype         = fr->ntype;
464     vdwparam         = fr->nbfp;
465     vdwtype          = mdatoms->typeA;
466
467     vftab            = kernel_data->table_elec_vdw->data;
468     vftabscale       = gmx_fjsp_set1_v2r8(kernel_data->table_elec_vdw->scale);
469
470     /* Avoid stupid compiler warnings */
471     jnrA = jnrB = 0;
472     j_coord_offsetA = 0;
473     j_coord_offsetB = 0;
474
475     outeriter        = 0;
476     inneriter        = 0;
477
478     /* Start outer loop over neighborlists */
479     for(iidx=0; iidx<nri; iidx++)
480     {
481         /* Load shift vector for this list */
482         i_shift_offset   = DIM*shiftidx[iidx];
483
484         /* Load limits for loop over neighbors */
485         j_index_start    = jindex[iidx];
486         j_index_end      = jindex[iidx+1];
487
488         /* Get outer coordinate index */
489         inr              = iinr[iidx];
490         i_coord_offset   = DIM*inr;
491
492         /* Load i particle coords and add shift vector */
493         gmx_fjsp_load_shift_and_1rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
494
495         fix0             = _fjsp_setzero_v2r8();
496         fiy0             = _fjsp_setzero_v2r8();
497         fiz0             = _fjsp_setzero_v2r8();
498
499         /* Load parameters for i particles */
500         iq0              = _fjsp_mul_v2r8(facel,gmx_fjsp_load1_v2r8(charge+inr+0));
501         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
502
503         /* Start inner kernel loop */
504         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
505         {
506
507             /* Get j neighbor index, and coordinate index */
508             jnrA             = jjnr[jidx];
509             jnrB             = jjnr[jidx+1];
510             j_coord_offsetA  = DIM*jnrA;
511             j_coord_offsetB  = DIM*jnrB;
512
513             /* load j atom coordinates */
514             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
515                                               &jx0,&jy0,&jz0);
516
517             /* Calculate displacement vector */
518             dx00             = _fjsp_sub_v2r8(ix0,jx0);
519             dy00             = _fjsp_sub_v2r8(iy0,jy0);
520             dz00             = _fjsp_sub_v2r8(iz0,jz0);
521
522             /* Calculate squared distance and things based on it */
523             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
524
525             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
526
527             /* Load parameters for j particles */
528             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
529             vdwjidx0A        = 2*vdwtype[jnrA+0];
530             vdwjidx0B        = 2*vdwtype[jnrB+0];
531
532             /**************************
533              * CALCULATE INTERACTIONS *
534              **************************/
535
536             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
537
538             /* Compute parameters for interactions between i and j atoms */
539             qq00             = _fjsp_mul_v2r8(iq0,jq0);
540             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
541                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
542
543             /* Calculate table index by multiplying r with table scale and truncate to integer */
544             rt               = _fjsp_mul_v2r8(r00,vftabscale);
545             itab_tmp         = _fjsp_dtox_v2r8(rt);
546             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
547             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
548             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
549
550             vfconv.i[0]     *= 12;
551             vfconv.i[1]     *= 12;
552
553             /* CUBIC SPLINE TABLE ELECTROSTATICS */
554             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
555             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] );
556             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
557             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] +2);
558             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] +2);
559             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
560             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(vfeps,H,G),F);
561             FF               = _fjsp_madd_v2r8(_fjsp_madd_v2r8(twovfeps,H,G),vfeps,Fp);
562             felec            = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,FF),_fjsp_mul_v2r8(vftabscale,rinv00)));
563
564             /* CUBIC SPLINE TABLE DISPERSION */
565             vfconv.i[0]       += 4;
566             vfconv.i[1]       += 4;
567             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
568             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] );
569             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
570             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
571             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 2 );
572             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
573             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
574             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
575             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
576
577             /* CUBIC SPLINE TABLE REPULSION */
578             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
579             F                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 4 );
580             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
581             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
582             H                = _fjsp_load_v2r8( vftab + vfconv.i[1] + 6 );
583             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
584             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
585             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
586             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
587             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
588
589             fscal            = _fjsp_add_v2r8(felec,fvdw);
590
591             /* Update vectorial force */
592             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
593             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
594             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
595             
596             gmx_fjsp_decrement_fma_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fscal,dx00,dy00,dz00);
597
598             /* Inner loop uses 64 flops */
599         }
600
601         if(jidx<j_index_end)
602         {
603
604             jnrA             = jjnr[jidx];
605             j_coord_offsetA  = DIM*jnrA;
606
607             /* load j atom coordinates */
608             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
609                                               &jx0,&jy0,&jz0);
610
611             /* Calculate displacement vector */
612             dx00             = _fjsp_sub_v2r8(ix0,jx0);
613             dy00             = _fjsp_sub_v2r8(iy0,jy0);
614             dz00             = _fjsp_sub_v2r8(iz0,jz0);
615
616             /* Calculate squared distance and things based on it */
617             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
618
619             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
620
621             /* Load parameters for j particles */
622             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
623             vdwjidx0A        = 2*vdwtype[jnrA+0];
624
625             /**************************
626              * CALCULATE INTERACTIONS *
627              **************************/
628
629             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
630
631             /* Compute parameters for interactions between i and j atoms */
632             qq00             = _fjsp_mul_v2r8(iq0,jq0);
633             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
634                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
635
636             /* Calculate table index by multiplying r with table scale and truncate to integer */
637             rt               = _fjsp_mul_v2r8(r00,vftabscale);
638             itab_tmp         = _fjsp_dtox_v2r8(rt);
639             vfeps            = _fjsp_sub_v2r8(rt, _fjsp_xtod_v2r8(itab_tmp));
640             twovfeps         = _fjsp_add_v2r8(vfeps,vfeps);
641             _fjsp_store_v2r8(&vfconv.simd,itab_tmp);
642
643             vfconv.i[0]     *= 12;
644             vfconv.i[1]     *= 12;
645
646             /* CUBIC SPLINE TABLE ELECTROSTATICS */
647             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
648             F                = _fjsp_setzero_v2r8();
649             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
650             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] +2);
651             H                = _fjsp_setzero_v2r8();
652             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
653             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(vfeps,H,G),F);
654             FF               = _fjsp_madd_v2r8(_fjsp_madd_v2r8(twovfeps,H,G),vfeps,Fp);
655             felec            = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,FF),_fjsp_mul_v2r8(vftabscale,rinv00)));
656
657             /* CUBIC SPLINE TABLE DISPERSION */
658             vfconv.i[0]       += 4;
659             vfconv.i[1]       += 4;
660             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] );
661             F                = _fjsp_setzero_v2r8();
662             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
663             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 2 );
664             H                = _fjsp_setzero_v2r8();
665             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
666             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
667             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
668             fvdw6            = _fjsp_mul_v2r8(c6_00,FF);
669
670             /* CUBIC SPLINE TABLE REPULSION */
671             Y                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 4 );
672             F                = _fjsp_setzero_v2r8();
673             GMX_FJSP_TRANSPOSE2_V2R8(Y,F);
674             G                = _fjsp_load_v2r8( vftab + vfconv.i[0] + 6 );
675             H                = _fjsp_setzero_v2r8();
676             GMX_FJSP_TRANSPOSE2_V2R8(G,H);
677             Fp               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(H,vfeps,G),F);
678             FF               = _fjsp_madd_v2r8(vfeps,_fjsp_madd_v2r8(twovfeps,H,G),Fp);
679             fvdw12           = _fjsp_mul_v2r8(c12_00,FF);
680             fvdw             = _fjsp_neg_v2r8(_fjsp_mul_v2r8(_fjsp_add_v2r8(fvdw6,fvdw12),_fjsp_mul_v2r8(vftabscale,rinv00)));
681
682             fscal            = _fjsp_add_v2r8(felec,fvdw);
683
684             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
685
686             /* Update vectorial force */
687             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
688             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
689             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
690             
691             gmx_fjsp_decrement_fma_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fscal,dx00,dy00,dz00);
692
693             /* Inner loop uses 64 flops */
694         }
695
696         /* End of innermost loop */
697
698         gmx_fjsp_update_iforce_1atom_swizzle_v2r8(fix0,fiy0,fiz0,
699                                               f+i_coord_offset,fshift+i_shift_offset);
700
701         /* Increment number of inner iterations */
702         inneriter                  += j_index_end - j_index_start;
703
704         /* Outer loop uses 7 flops */
705     }
706
707     /* Increment number of outer iterations */
708     outeriter        += nri;
709
710     /* Update outer/inner flops */
711
712     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*64);
713 }