d6e6167ef7d333b33bc26e0b265394c1fffa809d
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sparc64_hpc_ace_double / nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_sparc64_hpc_ace_double.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, 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 "vec.h"
47 #include "nrnb.h"
48
49 #include "kernelutil_sparc64_hpc_ace_double.h"
50
51 /*
52  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_VF_sparc64_hpc_ace_double
53  * Electrostatics interaction: Ewald
54  * VdW interaction:            LennardJones
55  * Geometry:                   Particle-Particle
56  * Calculate force/pot:        PotentialAndForce
57  */
58 void
59 nb_kernel_ElecEwSh_VdwLJSh_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       ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
95     real             *ewtab;
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     sh_ewald         = gmx_fjsp_set1_v2r8(fr->ic->sh_ewald);
120     ewtab            = fr->ic->tabq_coul_FDV0;
121     ewtabscale       = gmx_fjsp_set1_v2r8(fr->ic->tabq_scale);
122     ewtabhalfspace   = gmx_fjsp_set1_v2r8(0.5/fr->ic->tabq_scale);
123
124     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
125     rcutoff_scalar   = fr->rcoulomb;
126     rcutoff          = gmx_fjsp_set1_v2r8(rcutoff_scalar);
127     rcutoff2         = _fjsp_mul_v2r8(rcutoff,rcutoff);
128
129     sh_vdw_invrcut6  = gmx_fjsp_set1_v2r8(fr->ic->sh_invrc6);
130     rvdw             = gmx_fjsp_set1_v2r8(fr->rvdw);
131
132     /* Avoid stupid compiler warnings */
133     jnrA = jnrB = 0;
134     j_coord_offsetA = 0;
135     j_coord_offsetB = 0;
136
137     outeriter        = 0;
138     inneriter        = 0;
139
140     /* Start outer loop over neighborlists */
141     for(iidx=0; iidx<nri; iidx++)
142     {
143         /* Load shift vector for this list */
144         i_shift_offset   = DIM*shiftidx[iidx];
145
146         /* Load limits for loop over neighbors */
147         j_index_start    = jindex[iidx];
148         j_index_end      = jindex[iidx+1];
149
150         /* Get outer coordinate index */
151         inr              = iinr[iidx];
152         i_coord_offset   = DIM*inr;
153
154         /* Load i particle coords and add shift vector */
155         gmx_fjsp_load_shift_and_1rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
156
157         fix0             = _fjsp_setzero_v2r8();
158         fiy0             = _fjsp_setzero_v2r8();
159         fiz0             = _fjsp_setzero_v2r8();
160
161         /* Load parameters for i particles */
162         iq0              = _fjsp_mul_v2r8(facel,gmx_fjsp_load1_v2r8(charge+inr+0));
163         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
164
165         /* Reset potential sums */
166         velecsum         = _fjsp_setzero_v2r8();
167         vvdwsum          = _fjsp_setzero_v2r8();
168
169         /* Start inner kernel loop */
170         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
171         {
172
173             /* Get j neighbor index, and coordinate index */
174             jnrA             = jjnr[jidx];
175             jnrB             = jjnr[jidx+1];
176             j_coord_offsetA  = DIM*jnrA;
177             j_coord_offsetB  = DIM*jnrB;
178
179             /* load j atom coordinates */
180             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
181                                               &jx0,&jy0,&jz0);
182
183             /* Calculate displacement vector */
184             dx00             = _fjsp_sub_v2r8(ix0,jx0);
185             dy00             = _fjsp_sub_v2r8(iy0,jy0);
186             dz00             = _fjsp_sub_v2r8(iz0,jz0);
187
188             /* Calculate squared distance and things based on it */
189             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
190
191             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
192
193             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
194
195             /* Load parameters for j particles */
196             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
197             vdwjidx0A        = 2*vdwtype[jnrA+0];
198             vdwjidx0B        = 2*vdwtype[jnrB+0];
199
200             /**************************
201              * CALCULATE INTERACTIONS *
202              **************************/
203
204             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
205             {
206
207             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
208
209             /* Compute parameters for interactions between i and j atoms */
210             qq00             = _fjsp_mul_v2r8(iq0,jq0);
211             gmx_fjsp_load_2pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,
212                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
213
214             /* EWALD ELECTROSTATICS */
215
216             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
217             ewrt             = _fjsp_mul_v2r8(r00,ewtabscale);
218             itab_tmp         = _fjsp_dtox_v2r8(ewrt);
219             eweps            = _fjsp_sub_v2r8(ewrt,_fjsp_xtod_v2r8(itab_tmp));
220             _fjsp_store_v2r8(&ewconv.simd,itab_tmp);
221
222             ewtabF           = _fjsp_load_v2r8( ewtab + 4*ewconv.i[0] );
223             ewtabD           = _fjsp_load_v2r8( ewtab + 4*ewconv.i[1] );
224             GMX_FJSP_TRANSPOSE2_V2R8(ewtabF,ewtabD);
225             ewtabV           = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(), ewtab + 4*ewconv.i[0] +2);
226             ewtabFn          = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(), ewtab + 4*ewconv.i[1] +2);
227             GMX_FJSP_TRANSPOSE2_V2R8(ewtabV,ewtabFn);
228             felec            = _fjsp_madd_v2r8(eweps,ewtabD,ewtabF);
229             velec            = _fjsp_nmsub_v2r8(_fjsp_mul_v2r8(ewtabhalfspace,eweps) ,_fjsp_add_v2r8(ewtabF,felec), ewtabV);
230             velec            = _fjsp_mul_v2r8(qq00,_fjsp_sub_v2r8(_fjsp_sub_v2r8(rinv00,sh_ewald),velec));
231             felec            = _fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,rinv00),_fjsp_sub_v2r8(rinvsq00,felec));
232
233             /* LENNARD-JONES DISPERSION/REPULSION */
234
235             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
236             vvdw6            = _fjsp_mul_v2r8(c6_00,rinvsix);
237             vvdw12           = _fjsp_mul_v2r8(c12_00,_fjsp_mul_v2r8(rinvsix,rinvsix));
238             vvdw             = _fjsp_msub_v2r8(_fjsp_nmsub_v2r8(c12_00,_fjsp_mul_v2r8(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
239                                            _fjsp_mul_v2r8(_fjsp_nmsub_v2r8( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
240             fvdw             = _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw12,vvdw6),rinvsq00);
241
242             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
243
244             /* Update potential sum for this i atom from the interaction with this j atom. */
245             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
246             velecsum         = _fjsp_add_v2r8(velecsum,velec);
247             vvdw             = _fjsp_and_v2r8(vvdw,cutoff_mask);
248             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
249
250             fscal            = _fjsp_add_v2r8(felec,fvdw);
251
252             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
253
254             /* Update vectorial force */
255             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
256             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
257             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
258             
259             gmx_fjsp_decrement_fma_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fscal,dx00,dy00,dz00);
260
261             }
262
263             /* Inner loop uses 67 flops */
264         }
265
266         if(jidx<j_index_end)
267         {
268
269             jnrA             = jjnr[jidx];
270             j_coord_offsetA  = DIM*jnrA;
271
272             /* load j atom coordinates */
273             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
274                                               &jx0,&jy0,&jz0);
275
276             /* Calculate displacement vector */
277             dx00             = _fjsp_sub_v2r8(ix0,jx0);
278             dy00             = _fjsp_sub_v2r8(iy0,jy0);
279             dz00             = _fjsp_sub_v2r8(iz0,jz0);
280
281             /* Calculate squared distance and things based on it */
282             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
283
284             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
285
286             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
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             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
297             {
298
299             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
300
301             /* Compute parameters for interactions between i and j atoms */
302             qq00             = _fjsp_mul_v2r8(iq0,jq0);
303             gmx_fjsp_load_1pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
304
305             /* EWALD ELECTROSTATICS */
306
307             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
308             ewrt             = _fjsp_mul_v2r8(r00,ewtabscale);
309             itab_tmp         = _fjsp_dtox_v2r8(ewrt);
310             eweps            = _fjsp_sub_v2r8(ewrt,_fjsp_xtod_v2r8(itab_tmp));
311             _fjsp_store_v2r8(&ewconv.simd,itab_tmp);
312
313             ewtabF           = _fjsp_load_v2r8( ewtab + 4*ewconv.i[0] );
314             ewtabD           = _fjsp_setzero_v2r8();
315             GMX_FJSP_TRANSPOSE2_V2R8(ewtabF,ewtabD);
316             ewtabV           = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(), ewtab + 4*ewconv.i[0] +2);
317             ewtabFn          = _fjsp_setzero_v2r8();
318             GMX_FJSP_TRANSPOSE2_V2R8(ewtabV,ewtabFn);
319             felec            = _fjsp_madd_v2r8(eweps,ewtabD,ewtabF);
320             velec            = _fjsp_nmsub_v2r8(_fjsp_mul_v2r8(ewtabhalfspace,eweps) ,_fjsp_add_v2r8(ewtabF,felec), ewtabV);
321             velec            = _fjsp_mul_v2r8(qq00,_fjsp_sub_v2r8(_fjsp_sub_v2r8(rinv00,sh_ewald),velec));
322             felec            = _fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,rinv00),_fjsp_sub_v2r8(rinvsq00,felec));
323
324             /* LENNARD-JONES DISPERSION/REPULSION */
325
326             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
327             vvdw6            = _fjsp_mul_v2r8(c6_00,rinvsix);
328             vvdw12           = _fjsp_mul_v2r8(c12_00,_fjsp_mul_v2r8(rinvsix,rinvsix));
329             vvdw             = _fjsp_msub_v2r8(_fjsp_nmsub_v2r8(c12_00,_fjsp_mul_v2r8(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
330                                            _fjsp_mul_v2r8(_fjsp_nmsub_v2r8( c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
331             fvdw             = _fjsp_mul_v2r8(_fjsp_sub_v2r8(vvdw12,vvdw6),rinvsq00);
332
333             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
334
335             /* Update potential sum for this i atom from the interaction with this j atom. */
336             velec            = _fjsp_and_v2r8(velec,cutoff_mask);
337             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
338             velecsum         = _fjsp_add_v2r8(velecsum,velec);
339             vvdw             = _fjsp_and_v2r8(vvdw,cutoff_mask);
340             vvdw             = _fjsp_unpacklo_v2r8(vvdw,_fjsp_setzero_v2r8());
341             vvdwsum          = _fjsp_add_v2r8(vvdwsum,vvdw);
342
343             fscal            = _fjsp_add_v2r8(felec,fvdw);
344
345             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
346
347             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
348
349             /* Update vectorial force */
350             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
351             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
352             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
353             
354             gmx_fjsp_decrement_fma_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fscal,dx00,dy00,dz00);
355
356             }
357
358             /* Inner loop uses 67 flops */
359         }
360
361         /* End of innermost loop */
362
363         gmx_fjsp_update_iforce_1atom_swizzle_v2r8(fix0,fiy0,fiz0,
364                                               f+i_coord_offset,fshift+i_shift_offset);
365
366         ggid                        = gid[iidx];
367         /* Update potential energies */
368         gmx_fjsp_update_1pot_v2r8(velecsum,kernel_data->energygrp_elec+ggid);
369         gmx_fjsp_update_1pot_v2r8(vvdwsum,kernel_data->energygrp_vdw+ggid);
370
371         /* Increment number of inner iterations */
372         inneriter                  += j_index_end - j_index_start;
373
374         /* Outer loop uses 9 flops */
375     }
376
377     /* Increment number of outer iterations */
378     outeriter        += nri;
379
380     /* Update outer/inner flops */
381
382     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*67);
383 }
384 /*
385  * Gromacs nonbonded kernel:   nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_sparc64_hpc_ace_double
386  * Electrostatics interaction: Ewald
387  * VdW interaction:            LennardJones
388  * Geometry:                   Particle-Particle
389  * Calculate force/pot:        Force
390  */
391 void
392 nb_kernel_ElecEwSh_VdwLJSh_GeomP1P1_F_sparc64_hpc_ace_double
393                     (t_nblist                    * gmx_restrict       nlist,
394                      rvec                        * gmx_restrict          xx,
395                      rvec                        * gmx_restrict          ff,
396                      t_forcerec                  * gmx_restrict          fr,
397                      t_mdatoms                   * gmx_restrict     mdatoms,
398                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
399                      t_nrnb                      * gmx_restrict        nrnb)
400 {
401     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
402      * just 0 for non-waters.
403      * Suffixes A,B refer to j loop unrolling done with double precision SIMD, e.g. for the two different
404      * jnr indices corresponding to data put in the four positions in the SIMD register.
405      */
406     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
407     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
408     int              jnrA,jnrB;
409     int              j_coord_offsetA,j_coord_offsetB;
410     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
411     real             rcutoff_scalar;
412     real             *shiftvec,*fshift,*x,*f;
413     _fjsp_v2r8       tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
414     int              vdwioffset0;
415     _fjsp_v2r8       ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
416     int              vdwjidx0A,vdwjidx0B;
417     _fjsp_v2r8       jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
418     _fjsp_v2r8       dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
419     _fjsp_v2r8       velec,felec,velecsum,facel,crf,krf,krf2;
420     real             *charge;
421     int              nvdwtype;
422     _fjsp_v2r8       rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
423     int              *vdwtype;
424     real             *vdwparam;
425     _fjsp_v2r8       one_sixth   = gmx_fjsp_set1_v2r8(1.0/6.0);
426     _fjsp_v2r8       one_twelfth = gmx_fjsp_set1_v2r8(1.0/12.0);
427     _fjsp_v2r8       ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
428     real             *ewtab;
429     _fjsp_v2r8       itab_tmp;
430     _fjsp_v2r8       dummy_mask,cutoff_mask;
431     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
432     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
433     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
434
435     x                = xx[0];
436     f                = ff[0];
437
438     nri              = nlist->nri;
439     iinr             = nlist->iinr;
440     jindex           = nlist->jindex;
441     jjnr             = nlist->jjnr;
442     shiftidx         = nlist->shift;
443     gid              = nlist->gid;
444     shiftvec         = fr->shift_vec[0];
445     fshift           = fr->fshift[0];
446     facel            = gmx_fjsp_set1_v2r8(fr->epsfac);
447     charge           = mdatoms->chargeA;
448     nvdwtype         = fr->ntype;
449     vdwparam         = fr->nbfp;
450     vdwtype          = mdatoms->typeA;
451
452     sh_ewald         = gmx_fjsp_set1_v2r8(fr->ic->sh_ewald);
453     ewtab            = fr->ic->tabq_coul_F;
454     ewtabscale       = gmx_fjsp_set1_v2r8(fr->ic->tabq_scale);
455     ewtabhalfspace   = gmx_fjsp_set1_v2r8(0.5/fr->ic->tabq_scale);
456
457     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
458     rcutoff_scalar   = fr->rcoulomb;
459     rcutoff          = gmx_fjsp_set1_v2r8(rcutoff_scalar);
460     rcutoff2         = _fjsp_mul_v2r8(rcutoff,rcutoff);
461
462     sh_vdw_invrcut6  = gmx_fjsp_set1_v2r8(fr->ic->sh_invrc6);
463     rvdw             = gmx_fjsp_set1_v2r8(fr->rvdw);
464
465     /* Avoid stupid compiler warnings */
466     jnrA = jnrB = 0;
467     j_coord_offsetA = 0;
468     j_coord_offsetB = 0;
469
470     outeriter        = 0;
471     inneriter        = 0;
472
473     /* Start outer loop over neighborlists */
474     for(iidx=0; iidx<nri; iidx++)
475     {
476         /* Load shift vector for this list */
477         i_shift_offset   = DIM*shiftidx[iidx];
478
479         /* Load limits for loop over neighbors */
480         j_index_start    = jindex[iidx];
481         j_index_end      = jindex[iidx+1];
482
483         /* Get outer coordinate index */
484         inr              = iinr[iidx];
485         i_coord_offset   = DIM*inr;
486
487         /* Load i particle coords and add shift vector */
488         gmx_fjsp_load_shift_and_1rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
489
490         fix0             = _fjsp_setzero_v2r8();
491         fiy0             = _fjsp_setzero_v2r8();
492         fiz0             = _fjsp_setzero_v2r8();
493
494         /* Load parameters for i particles */
495         iq0              = _fjsp_mul_v2r8(facel,gmx_fjsp_load1_v2r8(charge+inr+0));
496         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
497
498         /* Start inner kernel loop */
499         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
500         {
501
502             /* Get j neighbor index, and coordinate index */
503             jnrA             = jjnr[jidx];
504             jnrB             = jjnr[jidx+1];
505             j_coord_offsetA  = DIM*jnrA;
506             j_coord_offsetB  = DIM*jnrB;
507
508             /* load j atom coordinates */
509             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
510                                               &jx0,&jy0,&jz0);
511
512             /* Calculate displacement vector */
513             dx00             = _fjsp_sub_v2r8(ix0,jx0);
514             dy00             = _fjsp_sub_v2r8(iy0,jy0);
515             dz00             = _fjsp_sub_v2r8(iz0,jz0);
516
517             /* Calculate squared distance and things based on it */
518             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
519
520             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
521
522             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
523
524             /* Load parameters for j particles */
525             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
526             vdwjidx0A        = 2*vdwtype[jnrA+0];
527             vdwjidx0B        = 2*vdwtype[jnrB+0];
528
529             /**************************
530              * CALCULATE INTERACTIONS *
531              **************************/
532
533             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
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             /* EWALD ELECTROSTATICS */
544
545             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
546             ewrt             = _fjsp_mul_v2r8(r00,ewtabscale);
547             itab_tmp         = _fjsp_dtox_v2r8(ewrt);
548             eweps            = _fjsp_sub_v2r8(ewrt,_fjsp_xtod_v2r8(itab_tmp));
549             _fjsp_store_v2r8(&ewconv.simd,itab_tmp);
550
551             gmx_fjsp_load_2pair_swizzle_v2r8(ewtab+ewconv.i[0],ewtab+ewconv.i[1],
552                                          &ewtabF,&ewtabFn);
553             felec            = _fjsp_madd_v2r8(eweps,ewtabFn,_fjsp_nmsub_v2r8(eweps,ewtabF,ewtabF));
554             felec            = _fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,rinv00),_fjsp_sub_v2r8(rinvsq00,felec));
555
556             /* LENNARD-JONES DISPERSION/REPULSION */
557
558             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
559             fvdw             = _fjsp_mul_v2r8(_fjsp_msub_v2r8(c12_00,rinvsix,c6_00),_fjsp_mul_v2r8(rinvsix,rinvsq00));
560
561             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
562
563             fscal            = _fjsp_add_v2r8(felec,fvdw);
564
565             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
566
567             /* Update vectorial force */
568             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
569             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
570             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
571             
572             gmx_fjsp_decrement_fma_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fscal,dx00,dy00,dz00);
573
574             }
575
576             /* Inner loop uses 49 flops */
577         }
578
579         if(jidx<j_index_end)
580         {
581
582             jnrA             = jjnr[jidx];
583             j_coord_offsetA  = DIM*jnrA;
584
585             /* load j atom coordinates */
586             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
587                                               &jx0,&jy0,&jz0);
588
589             /* Calculate displacement vector */
590             dx00             = _fjsp_sub_v2r8(ix0,jx0);
591             dy00             = _fjsp_sub_v2r8(iy0,jy0);
592             dz00             = _fjsp_sub_v2r8(iz0,jz0);
593
594             /* Calculate squared distance and things based on it */
595             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
596
597             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
598
599             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
600
601             /* Load parameters for j particles */
602             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
603             vdwjidx0A        = 2*vdwtype[jnrA+0];
604
605             /**************************
606              * CALCULATE INTERACTIONS *
607              **************************/
608
609             if (gmx_fjsp_any_lt_v2r8(rsq00,rcutoff2))
610             {
611
612             r00              = _fjsp_mul_v2r8(rsq00,rinv00);
613
614             /* Compute parameters for interactions between i and j atoms */
615             qq00             = _fjsp_mul_v2r8(iq0,jq0);
616             gmx_fjsp_load_1pair_swizzle_v2r8(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
617
618             /* EWALD ELECTROSTATICS */
619
620             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
621             ewrt             = _fjsp_mul_v2r8(r00,ewtabscale);
622             itab_tmp         = _fjsp_dtox_v2r8(ewrt);
623             eweps            = _fjsp_sub_v2r8(ewrt,_fjsp_xtod_v2r8(itab_tmp));
624             _fjsp_store_v2r8(&ewconv.simd,itab_tmp);
625
626             gmx_fjsp_load_1pair_swizzle_v2r8(ewtab+ewconv.i[0],&ewtabF,&ewtabFn);
627             felec            = _fjsp_madd_v2r8(eweps,ewtabFn,_fjsp_nmsub_v2r8(eweps,ewtabF,ewtabF));
628             felec            = _fjsp_mul_v2r8(_fjsp_mul_v2r8(qq00,rinv00),_fjsp_sub_v2r8(rinvsq00,felec));
629
630             /* LENNARD-JONES DISPERSION/REPULSION */
631
632             rinvsix          = _fjsp_mul_v2r8(_fjsp_mul_v2r8(rinvsq00,rinvsq00),rinvsq00);
633             fvdw             = _fjsp_mul_v2r8(_fjsp_msub_v2r8(c12_00,rinvsix,c6_00),_fjsp_mul_v2r8(rinvsix,rinvsq00));
634
635             cutoff_mask      = _fjsp_cmplt_v2r8(rsq00,rcutoff2);
636
637             fscal            = _fjsp_add_v2r8(felec,fvdw);
638
639             fscal            = _fjsp_and_v2r8(fscal,cutoff_mask);
640
641             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
642
643             /* Update vectorial force */
644             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
645             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
646             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
647             
648             gmx_fjsp_decrement_fma_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fscal,dx00,dy00,dz00);
649
650             }
651
652             /* Inner loop uses 49 flops */
653         }
654
655         /* End of innermost loop */
656
657         gmx_fjsp_update_iforce_1atom_swizzle_v2r8(fix0,fiy0,fiz0,
658                                               f+i_coord_offset,fshift+i_shift_offset);
659
660         /* Increment number of inner iterations */
661         inneriter                  += j_index_end - j_index_start;
662
663         /* Outer loop uses 7 flops */
664     }
665
666     /* Increment number of outer iterations */
667     outeriter        += nri;
668
669     /* Update outer/inner flops */
670
671     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*49);
672 }