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