K-computer specific modifications
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sparc64_hpc_ace_double / nb_kernel_ElecCoul_VdwNone_GeomW3P1_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_ElecCoul_VdwNone_GeomW3P1_VF_sparc64_hpc_ace_double
53  * Electrostatics interaction: Coulomb
54  * VdW interaction:            None
55  * Geometry:                   Water3-Particle
56  * Calculate force/pot:        PotentialAndForce
57  */
58 void
59 nb_kernel_ElecCoul_VdwNone_GeomW3P1_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              vdwioffset1;
84     _fjsp_v2r8       ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
85     int              vdwioffset2;
86     _fjsp_v2r8       ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
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       velec,felec,velecsum,facel,crf,krf,krf2;
93     real             *charge;
94     _fjsp_v2r8       itab_tmp;
95     _fjsp_v2r8       dummy_mask,cutoff_mask;
96     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
97     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
98     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
99
100     x                = xx[0];
101     f                = ff[0];
102
103     nri              = nlist->nri;
104     iinr             = nlist->iinr;
105     jindex           = nlist->jindex;
106     jjnr             = nlist->jjnr;
107     shiftidx         = nlist->shift;
108     gid              = nlist->gid;
109     shiftvec         = fr->shift_vec[0];
110     fshift           = fr->fshift[0];
111     facel            = gmx_fjsp_set1_v2r8(fr->epsfac);
112     charge           = mdatoms->chargeA;
113
114     /* Setup water-specific parameters */
115     inr              = nlist->iinr[0];
116     iq0              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+0]));
117     iq1              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+1]));
118     iq2              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+2]));
119
120     /* Avoid stupid compiler warnings */
121     jnrA = jnrB = 0;
122     j_coord_offsetA = 0;
123     j_coord_offsetB = 0;
124
125     outeriter        = 0;
126     inneriter        = 0;
127
128     /* Start outer loop over neighborlists */
129     for(iidx=0; iidx<nri; iidx++)
130     {
131         /* Load shift vector for this list */
132         i_shift_offset   = DIM*shiftidx[iidx];
133
134         /* Load limits for loop over neighbors */
135         j_index_start    = jindex[iidx];
136         j_index_end      = jindex[iidx+1];
137
138         /* Get outer coordinate index */
139         inr              = iinr[iidx];
140         i_coord_offset   = DIM*inr;
141
142         /* Load i particle coords and add shift vector */
143         gmx_fjsp_load_shift_and_3rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
144                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
145
146         fix0             = _fjsp_setzero_v2r8();
147         fiy0             = _fjsp_setzero_v2r8();
148         fiz0             = _fjsp_setzero_v2r8();
149         fix1             = _fjsp_setzero_v2r8();
150         fiy1             = _fjsp_setzero_v2r8();
151         fiz1             = _fjsp_setzero_v2r8();
152         fix2             = _fjsp_setzero_v2r8();
153         fiy2             = _fjsp_setzero_v2r8();
154         fiz2             = _fjsp_setzero_v2r8();
155
156         /* Reset potential sums */
157         velecsum         = _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             dx10             = _fjsp_sub_v2r8(ix1,jx0);
178             dy10             = _fjsp_sub_v2r8(iy1,jy0);
179             dz10             = _fjsp_sub_v2r8(iz1,jz0);
180             dx20             = _fjsp_sub_v2r8(ix2,jx0);
181             dy20             = _fjsp_sub_v2r8(iy2,jy0);
182             dz20             = _fjsp_sub_v2r8(iz2,jz0);
183
184             /* Calculate squared distance and things based on it */
185             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
186             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
187             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
188
189             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
190             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
191             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
192
193             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
194             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
195             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
196
197             /* Load parameters for j particles */
198             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
199
200             fjx0             = _fjsp_setzero_v2r8();
201             fjy0             = _fjsp_setzero_v2r8();
202             fjz0             = _fjsp_setzero_v2r8();
203
204             /**************************
205              * CALCULATE INTERACTIONS *
206              **************************/
207
208             /* Compute parameters for interactions between i and j atoms */
209             qq00             = _fjsp_mul_v2r8(iq0,jq0);
210
211             /* COULOMB ELECTROSTATICS */
212             velec            = _fjsp_mul_v2r8(qq00,rinv00);
213             felec            = _fjsp_mul_v2r8(velec,rinvsq00);
214
215             /* Update potential sum for this i atom from the interaction with this j atom. */
216             velecsum         = _fjsp_add_v2r8(velecsum,velec);
217
218             fscal            = felec;
219
220             /* Update vectorial force */
221             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
222             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
223             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
224             
225             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
226             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
227             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
228
229             /**************************
230              * CALCULATE INTERACTIONS *
231              **************************/
232
233             /* Compute parameters for interactions between i and j atoms */
234             qq10             = _fjsp_mul_v2r8(iq1,jq0);
235
236             /* COULOMB ELECTROSTATICS */
237             velec            = _fjsp_mul_v2r8(qq10,rinv10);
238             felec            = _fjsp_mul_v2r8(velec,rinvsq10);
239
240             /* Update potential sum for this i atom from the interaction with this j atom. */
241             velecsum         = _fjsp_add_v2r8(velecsum,velec);
242
243             fscal            = felec;
244
245             /* Update vectorial force */
246             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
247             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
248             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
249             
250             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
251             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
252             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
253
254             /**************************
255              * CALCULATE INTERACTIONS *
256              **************************/
257
258             /* Compute parameters for interactions between i and j atoms */
259             qq20             = _fjsp_mul_v2r8(iq2,jq0);
260
261             /* COULOMB ELECTROSTATICS */
262             velec            = _fjsp_mul_v2r8(qq20,rinv20);
263             felec            = _fjsp_mul_v2r8(velec,rinvsq20);
264
265             /* Update potential sum for this i atom from the interaction with this j atom. */
266             velecsum         = _fjsp_add_v2r8(velecsum,velec);
267
268             fscal            = felec;
269
270             /* Update vectorial force */
271             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
272             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
273             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
274             
275             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
276             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
277             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
278
279             gmx_fjsp_decrement_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
280
281             /* Inner loop uses 96 flops */
282         }
283
284         if(jidx<j_index_end)
285         {
286
287             jnrA             = jjnr[jidx];
288             j_coord_offsetA  = DIM*jnrA;
289
290             /* load j atom coordinates */
291             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
292                                               &jx0,&jy0,&jz0);
293
294             /* Calculate displacement vector */
295             dx00             = _fjsp_sub_v2r8(ix0,jx0);
296             dy00             = _fjsp_sub_v2r8(iy0,jy0);
297             dz00             = _fjsp_sub_v2r8(iz0,jz0);
298             dx10             = _fjsp_sub_v2r8(ix1,jx0);
299             dy10             = _fjsp_sub_v2r8(iy1,jy0);
300             dz10             = _fjsp_sub_v2r8(iz1,jz0);
301             dx20             = _fjsp_sub_v2r8(ix2,jx0);
302             dy20             = _fjsp_sub_v2r8(iy2,jy0);
303             dz20             = _fjsp_sub_v2r8(iz2,jz0);
304
305             /* Calculate squared distance and things based on it */
306             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
307             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
308             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
309
310             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
311             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
312             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
313
314             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
315             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
316             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
317
318             /* Load parameters for j particles */
319             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
320
321             fjx0             = _fjsp_setzero_v2r8();
322             fjy0             = _fjsp_setzero_v2r8();
323             fjz0             = _fjsp_setzero_v2r8();
324
325             /**************************
326              * CALCULATE INTERACTIONS *
327              **************************/
328
329             /* Compute parameters for interactions between i and j atoms */
330             qq00             = _fjsp_mul_v2r8(iq0,jq0);
331
332             /* COULOMB ELECTROSTATICS */
333             velec            = _fjsp_mul_v2r8(qq00,rinv00);
334             felec            = _fjsp_mul_v2r8(velec,rinvsq00);
335
336             /* Update potential sum for this i atom from the interaction with this j atom. */
337             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
338             velecsum         = _fjsp_add_v2r8(velecsum,velec);
339
340             fscal            = felec;
341
342             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
343
344             /* Update vectorial force */
345             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
346             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
347             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
348             
349             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
350             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
351             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
352
353             /**************************
354              * CALCULATE INTERACTIONS *
355              **************************/
356
357             /* Compute parameters for interactions between i and j atoms */
358             qq10             = _fjsp_mul_v2r8(iq1,jq0);
359
360             /* COULOMB ELECTROSTATICS */
361             velec            = _fjsp_mul_v2r8(qq10,rinv10);
362             felec            = _fjsp_mul_v2r8(velec,rinvsq10);
363
364             /* Update potential sum for this i atom from the interaction with this j atom. */
365             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
366             velecsum         = _fjsp_add_v2r8(velecsum,velec);
367
368             fscal            = felec;
369
370             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
371
372             /* Update vectorial force */
373             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
374             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
375             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
376             
377             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
378             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
379             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
380
381             /**************************
382              * CALCULATE INTERACTIONS *
383              **************************/
384
385             /* Compute parameters for interactions between i and j atoms */
386             qq20             = _fjsp_mul_v2r8(iq2,jq0);
387
388             /* COULOMB ELECTROSTATICS */
389             velec            = _fjsp_mul_v2r8(qq20,rinv20);
390             felec            = _fjsp_mul_v2r8(velec,rinvsq20);
391
392             /* Update potential sum for this i atom from the interaction with this j atom. */
393             velec            = _fjsp_unpacklo_v2r8(velec,_fjsp_setzero_v2r8());
394             velecsum         = _fjsp_add_v2r8(velecsum,velec);
395
396             fscal            = felec;
397
398             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
399
400             /* Update vectorial force */
401             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
402             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
403             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
404             
405             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
406             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
407             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
408
409             gmx_fjsp_decrement_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0);
410
411             /* Inner loop uses 96 flops */
412         }
413
414         /* End of innermost loop */
415
416         gmx_fjsp_update_iforce_3atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
417                                               f+i_coord_offset,fshift+i_shift_offset);
418
419         ggid                        = gid[iidx];
420         /* Update potential energies */
421         gmx_fjsp_update_1pot_v2r8(velecsum,kernel_data->energygrp_elec+ggid);
422
423         /* Increment number of inner iterations */
424         inneriter                  += j_index_end - j_index_start;
425
426         /* Outer loop uses 19 flops */
427     }
428
429     /* Increment number of outer iterations */
430     outeriter        += nri;
431
432     /* Update outer/inner flops */
433
434     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*96);
435 }
436 /*
437  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwNone_GeomW3P1_F_sparc64_hpc_ace_double
438  * Electrostatics interaction: Coulomb
439  * VdW interaction:            None
440  * Geometry:                   Water3-Particle
441  * Calculate force/pot:        Force
442  */
443 void
444 nb_kernel_ElecCoul_VdwNone_GeomW3P1_F_sparc64_hpc_ace_double
445                     (t_nblist                    * gmx_restrict       nlist,
446                      rvec                        * gmx_restrict          xx,
447                      rvec                        * gmx_restrict          ff,
448                      t_forcerec                  * gmx_restrict          fr,
449                      t_mdatoms                   * gmx_restrict     mdatoms,
450                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
451                      t_nrnb                      * gmx_restrict        nrnb)
452 {
453     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
454      * just 0 for non-waters.
455      * Suffixes A,B refer to j loop unrolling done with double precision SIMD, e.g. for the two different
456      * jnr indices corresponding to data put in the four positions in the SIMD register.
457      */
458     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
459     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
460     int              jnrA,jnrB;
461     int              j_coord_offsetA,j_coord_offsetB;
462     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
463     real             rcutoff_scalar;
464     real             *shiftvec,*fshift,*x,*f;
465     _fjsp_v2r8       tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
466     int              vdwioffset0;
467     _fjsp_v2r8       ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
468     int              vdwioffset1;
469     _fjsp_v2r8       ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
470     int              vdwioffset2;
471     _fjsp_v2r8       ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
472     int              vdwjidx0A,vdwjidx0B;
473     _fjsp_v2r8       jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
474     _fjsp_v2r8       dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
475     _fjsp_v2r8       dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
476     _fjsp_v2r8       dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
477     _fjsp_v2r8       velec,felec,velecsum,facel,crf,krf,krf2;
478     real             *charge;
479     _fjsp_v2r8       itab_tmp;
480     _fjsp_v2r8       dummy_mask,cutoff_mask;
481     _fjsp_v2r8       one     = gmx_fjsp_set1_v2r8(1.0);
482     _fjsp_v2r8       two     = gmx_fjsp_set1_v2r8(2.0);
483     union { _fjsp_v2r8 simd; long long int i[2]; } vfconv,gbconv,ewconv;
484
485     x                = xx[0];
486     f                = ff[0];
487
488     nri              = nlist->nri;
489     iinr             = nlist->iinr;
490     jindex           = nlist->jindex;
491     jjnr             = nlist->jjnr;
492     shiftidx         = nlist->shift;
493     gid              = nlist->gid;
494     shiftvec         = fr->shift_vec[0];
495     fshift           = fr->fshift[0];
496     facel            = gmx_fjsp_set1_v2r8(fr->epsfac);
497     charge           = mdatoms->chargeA;
498
499     /* Setup water-specific parameters */
500     inr              = nlist->iinr[0];
501     iq0              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+0]));
502     iq1              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+1]));
503     iq2              = _fjsp_mul_v2r8(facel,gmx_fjsp_set1_v2r8(charge[inr+2]));
504
505     /* Avoid stupid compiler warnings */
506     jnrA = jnrB = 0;
507     j_coord_offsetA = 0;
508     j_coord_offsetB = 0;
509
510     outeriter        = 0;
511     inneriter        = 0;
512
513     /* Start outer loop over neighborlists */
514     for(iidx=0; iidx<nri; iidx++)
515     {
516         /* Load shift vector for this list */
517         i_shift_offset   = DIM*shiftidx[iidx];
518
519         /* Load limits for loop over neighbors */
520         j_index_start    = jindex[iidx];
521         j_index_end      = jindex[iidx+1];
522
523         /* Get outer coordinate index */
524         inr              = iinr[iidx];
525         i_coord_offset   = DIM*inr;
526
527         /* Load i particle coords and add shift vector */
528         gmx_fjsp_load_shift_and_3rvec_broadcast_v2r8(shiftvec+i_shift_offset,x+i_coord_offset,
529                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
530
531         fix0             = _fjsp_setzero_v2r8();
532         fiy0             = _fjsp_setzero_v2r8();
533         fiz0             = _fjsp_setzero_v2r8();
534         fix1             = _fjsp_setzero_v2r8();
535         fiy1             = _fjsp_setzero_v2r8();
536         fiz1             = _fjsp_setzero_v2r8();
537         fix2             = _fjsp_setzero_v2r8();
538         fiy2             = _fjsp_setzero_v2r8();
539         fiz2             = _fjsp_setzero_v2r8();
540
541         /* Start inner kernel loop */
542         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
543         {
544
545             /* Get j neighbor index, and coordinate index */
546             jnrA             = jjnr[jidx];
547             jnrB             = jjnr[jidx+1];
548             j_coord_offsetA  = DIM*jnrA;
549             j_coord_offsetB  = DIM*jnrB;
550
551             /* load j atom coordinates */
552             gmx_fjsp_load_1rvec_2ptr_swizzle_v2r8(x+j_coord_offsetA,x+j_coord_offsetB,
553                                               &jx0,&jy0,&jz0);
554
555             /* Calculate displacement vector */
556             dx00             = _fjsp_sub_v2r8(ix0,jx0);
557             dy00             = _fjsp_sub_v2r8(iy0,jy0);
558             dz00             = _fjsp_sub_v2r8(iz0,jz0);
559             dx10             = _fjsp_sub_v2r8(ix1,jx0);
560             dy10             = _fjsp_sub_v2r8(iy1,jy0);
561             dz10             = _fjsp_sub_v2r8(iz1,jz0);
562             dx20             = _fjsp_sub_v2r8(ix2,jx0);
563             dy20             = _fjsp_sub_v2r8(iy2,jy0);
564             dz20             = _fjsp_sub_v2r8(iz2,jz0);
565
566             /* Calculate squared distance and things based on it */
567             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
568             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
569             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
570
571             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
572             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
573             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
574
575             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
576             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
577             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
578
579             /* Load parameters for j particles */
580             jq0              = gmx_fjsp_load_2real_swizzle_v2r8(charge+jnrA+0,charge+jnrB+0);
581
582             fjx0             = _fjsp_setzero_v2r8();
583             fjy0             = _fjsp_setzero_v2r8();
584             fjz0             = _fjsp_setzero_v2r8();
585
586             /**************************
587              * CALCULATE INTERACTIONS *
588              **************************/
589
590             /* Compute parameters for interactions between i and j atoms */
591             qq00             = _fjsp_mul_v2r8(iq0,jq0);
592
593             /* COULOMB ELECTROSTATICS */
594             velec            = _fjsp_mul_v2r8(qq00,rinv00);
595             felec            = _fjsp_mul_v2r8(velec,rinvsq00);
596
597             fscal            = felec;
598
599             /* Update vectorial force */
600             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
601             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
602             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
603             
604             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
605             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
606             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
607
608             /**************************
609              * CALCULATE INTERACTIONS *
610              **************************/
611
612             /* Compute parameters for interactions between i and j atoms */
613             qq10             = _fjsp_mul_v2r8(iq1,jq0);
614
615             /* COULOMB ELECTROSTATICS */
616             velec            = _fjsp_mul_v2r8(qq10,rinv10);
617             felec            = _fjsp_mul_v2r8(velec,rinvsq10);
618
619             fscal            = felec;
620
621             /* Update vectorial force */
622             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
623             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
624             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
625             
626             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
627             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
628             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
629
630             /**************************
631              * CALCULATE INTERACTIONS *
632              **************************/
633
634             /* Compute parameters for interactions between i and j atoms */
635             qq20             = _fjsp_mul_v2r8(iq2,jq0);
636
637             /* COULOMB ELECTROSTATICS */
638             velec            = _fjsp_mul_v2r8(qq20,rinv20);
639             felec            = _fjsp_mul_v2r8(velec,rinvsq20);
640
641             fscal            = felec;
642
643             /* Update vectorial force */
644             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
645             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
646             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
647             
648             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
649             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
650             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
651
652             gmx_fjsp_decrement_1rvec_2ptr_swizzle_v2r8(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
653
654             /* Inner loop uses 93 flops */
655         }
656
657         if(jidx<j_index_end)
658         {
659
660             jnrA             = jjnr[jidx];
661             j_coord_offsetA  = DIM*jnrA;
662
663             /* load j atom coordinates */
664             gmx_fjsp_load_1rvec_1ptr_swizzle_v2r8(x+j_coord_offsetA,
665                                               &jx0,&jy0,&jz0);
666
667             /* Calculate displacement vector */
668             dx00             = _fjsp_sub_v2r8(ix0,jx0);
669             dy00             = _fjsp_sub_v2r8(iy0,jy0);
670             dz00             = _fjsp_sub_v2r8(iz0,jz0);
671             dx10             = _fjsp_sub_v2r8(ix1,jx0);
672             dy10             = _fjsp_sub_v2r8(iy1,jy0);
673             dz10             = _fjsp_sub_v2r8(iz1,jz0);
674             dx20             = _fjsp_sub_v2r8(ix2,jx0);
675             dy20             = _fjsp_sub_v2r8(iy2,jy0);
676             dz20             = _fjsp_sub_v2r8(iz2,jz0);
677
678             /* Calculate squared distance and things based on it */
679             rsq00            = gmx_fjsp_calc_rsq_v2r8(dx00,dy00,dz00);
680             rsq10            = gmx_fjsp_calc_rsq_v2r8(dx10,dy10,dz10);
681             rsq20            = gmx_fjsp_calc_rsq_v2r8(dx20,dy20,dz20);
682
683             rinv00           = gmx_fjsp_invsqrt_v2r8(rsq00);
684             rinv10           = gmx_fjsp_invsqrt_v2r8(rsq10);
685             rinv20           = gmx_fjsp_invsqrt_v2r8(rsq20);
686
687             rinvsq00         = _fjsp_mul_v2r8(rinv00,rinv00);
688             rinvsq10         = _fjsp_mul_v2r8(rinv10,rinv10);
689             rinvsq20         = _fjsp_mul_v2r8(rinv20,rinv20);
690
691             /* Load parameters for j particles */
692             jq0              = _fjsp_loadl_v2r8(_fjsp_setzero_v2r8(),charge+jnrA+0);
693
694             fjx0             = _fjsp_setzero_v2r8();
695             fjy0             = _fjsp_setzero_v2r8();
696             fjz0             = _fjsp_setzero_v2r8();
697
698             /**************************
699              * CALCULATE INTERACTIONS *
700              **************************/
701
702             /* Compute parameters for interactions between i and j atoms */
703             qq00             = _fjsp_mul_v2r8(iq0,jq0);
704
705             /* COULOMB ELECTROSTATICS */
706             velec            = _fjsp_mul_v2r8(qq00,rinv00);
707             felec            = _fjsp_mul_v2r8(velec,rinvsq00);
708
709             fscal            = felec;
710
711             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
712
713             /* Update vectorial force */
714             fix0             = _fjsp_madd_v2r8(dx00,fscal,fix0);
715             fiy0             = _fjsp_madd_v2r8(dy00,fscal,fiy0);
716             fiz0             = _fjsp_madd_v2r8(dz00,fscal,fiz0);
717             
718             fjx0             = _fjsp_madd_v2r8(dx00,fscal,fjx0);
719             fjy0             = _fjsp_madd_v2r8(dy00,fscal,fjy0);
720             fjz0             = _fjsp_madd_v2r8(dz00,fscal,fjz0);
721
722             /**************************
723              * CALCULATE INTERACTIONS *
724              **************************/
725
726             /* Compute parameters for interactions between i and j atoms */
727             qq10             = _fjsp_mul_v2r8(iq1,jq0);
728
729             /* COULOMB ELECTROSTATICS */
730             velec            = _fjsp_mul_v2r8(qq10,rinv10);
731             felec            = _fjsp_mul_v2r8(velec,rinvsq10);
732
733             fscal            = felec;
734
735             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
736
737             /* Update vectorial force */
738             fix1             = _fjsp_madd_v2r8(dx10,fscal,fix1);
739             fiy1             = _fjsp_madd_v2r8(dy10,fscal,fiy1);
740             fiz1             = _fjsp_madd_v2r8(dz10,fscal,fiz1);
741             
742             fjx0             = _fjsp_madd_v2r8(dx10,fscal,fjx0);
743             fjy0             = _fjsp_madd_v2r8(dy10,fscal,fjy0);
744             fjz0             = _fjsp_madd_v2r8(dz10,fscal,fjz0);
745
746             /**************************
747              * CALCULATE INTERACTIONS *
748              **************************/
749
750             /* Compute parameters for interactions between i and j atoms */
751             qq20             = _fjsp_mul_v2r8(iq2,jq0);
752
753             /* COULOMB ELECTROSTATICS */
754             velec            = _fjsp_mul_v2r8(qq20,rinv20);
755             felec            = _fjsp_mul_v2r8(velec,rinvsq20);
756
757             fscal            = felec;
758
759             fscal            = _fjsp_unpacklo_v2r8(fscal,_fjsp_setzero_v2r8());
760
761             /* Update vectorial force */
762             fix2             = _fjsp_madd_v2r8(dx20,fscal,fix2);
763             fiy2             = _fjsp_madd_v2r8(dy20,fscal,fiy2);
764             fiz2             = _fjsp_madd_v2r8(dz20,fscal,fiz2);
765             
766             fjx0             = _fjsp_madd_v2r8(dx20,fscal,fjx0);
767             fjy0             = _fjsp_madd_v2r8(dy20,fscal,fjy0);
768             fjz0             = _fjsp_madd_v2r8(dz20,fscal,fjz0);
769
770             gmx_fjsp_decrement_1rvec_1ptr_swizzle_v2r8(f+j_coord_offsetA,fjx0,fjy0,fjz0);
771
772             /* Inner loop uses 93 flops */
773         }
774
775         /* End of innermost loop */
776
777         gmx_fjsp_update_iforce_3atom_swizzle_v2r8(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
778                                               f+i_coord_offset,fshift+i_shift_offset);
779
780         /* Increment number of inner iterations */
781         inneriter                  += j_index_end - j_index_start;
782
783         /* Outer loop uses 18 flops */
784     }
785
786     /* Increment number of outer iterations */
787     outeriter        += nri;
788
789     /* Update outer/inner flops */
790
791     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*93);
792 }