Remove all unnecessary HAVE_CONFIG_H
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecCoul_VdwNone_GeomW3P1_avx_128_fma_single.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 avx_128_fma_single kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 #include "gromacs/simd/math_x86_avx_128_fma_single.h"
48 #include "kernelutil_x86_avx_128_fma_single.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwNone_GeomW3P1_VF_avx_128_fma_single
52  * Electrostatics interaction: Coulomb
53  * VdW interaction:            None
54  * Geometry:                   Water3-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecCoul_VdwNone_GeomW3P1_VF_avx_128_fma_single
59                     (t_nblist                    * gmx_restrict       nlist,
60                      rvec                        * gmx_restrict          xx,
61                      rvec                        * gmx_restrict          ff,
62                      t_forcerec                  * gmx_restrict          fr,
63                      t_mdatoms                   * gmx_restrict     mdatoms,
64                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
65                      t_nrnb                      * gmx_restrict        nrnb)
66 {
67     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
68      * just 0 for non-waters.
69      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
70      * jnr indices corresponding to data put in the four positions in the SIMD register.
71      */
72     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
73     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
74     int              jnrA,jnrB,jnrC,jnrD;
75     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
76     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
77     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
78     real             rcutoff_scalar;
79     real             *shiftvec,*fshift,*x,*f;
80     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
81     real             scratch[4*DIM];
82     __m128           fscal,rcutoff,rcutoff2,jidxall;
83     int              vdwioffset0;
84     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
85     int              vdwioffset1;
86     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
87     int              vdwioffset2;
88     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
89     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
90     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
91     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
92     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
93     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
94     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
95     real             *charge;
96     __m128           dummy_mask,cutoff_mask;
97     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
98     __m128           one     = _mm_set1_ps(1.0);
99     __m128           two     = _mm_set1_ps(2.0);
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            = _mm_set1_ps(fr->epsfac);
112     charge           = mdatoms->chargeA;
113
114     /* Setup water-specific parameters */
115     inr              = nlist->iinr[0];
116     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
117     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
118     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
119
120     /* Avoid stupid compiler warnings */
121     jnrA = jnrB = jnrC = jnrD = 0;
122     j_coord_offsetA = 0;
123     j_coord_offsetB = 0;
124     j_coord_offsetC = 0;
125     j_coord_offsetD = 0;
126
127     outeriter        = 0;
128     inneriter        = 0;
129
130     for(iidx=0;iidx<4*DIM;iidx++)
131     {
132         scratch[iidx] = 0.0;
133     }
134
135     /* Start outer loop over neighborlists */
136     for(iidx=0; iidx<nri; iidx++)
137     {
138         /* Load shift vector for this list */
139         i_shift_offset   = DIM*shiftidx[iidx];
140
141         /* Load limits for loop over neighbors */
142         j_index_start    = jindex[iidx];
143         j_index_end      = jindex[iidx+1];
144
145         /* Get outer coordinate index */
146         inr              = iinr[iidx];
147         i_coord_offset   = DIM*inr;
148
149         /* Load i particle coords and add shift vector */
150         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
151                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
152
153         fix0             = _mm_setzero_ps();
154         fiy0             = _mm_setzero_ps();
155         fiz0             = _mm_setzero_ps();
156         fix1             = _mm_setzero_ps();
157         fiy1             = _mm_setzero_ps();
158         fiz1             = _mm_setzero_ps();
159         fix2             = _mm_setzero_ps();
160         fiy2             = _mm_setzero_ps();
161         fiz2             = _mm_setzero_ps();
162
163         /* Reset potential sums */
164         velecsum         = _mm_setzero_ps();
165
166         /* Start inner kernel loop */
167         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
168         {
169
170             /* Get j neighbor index, and coordinate index */
171             jnrA             = jjnr[jidx];
172             jnrB             = jjnr[jidx+1];
173             jnrC             = jjnr[jidx+2];
174             jnrD             = jjnr[jidx+3];
175             j_coord_offsetA  = DIM*jnrA;
176             j_coord_offsetB  = DIM*jnrB;
177             j_coord_offsetC  = DIM*jnrC;
178             j_coord_offsetD  = DIM*jnrD;
179
180             /* load j atom coordinates */
181             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
182                                               x+j_coord_offsetC,x+j_coord_offsetD,
183                                               &jx0,&jy0,&jz0);
184
185             /* Calculate displacement vector */
186             dx00             = _mm_sub_ps(ix0,jx0);
187             dy00             = _mm_sub_ps(iy0,jy0);
188             dz00             = _mm_sub_ps(iz0,jz0);
189             dx10             = _mm_sub_ps(ix1,jx0);
190             dy10             = _mm_sub_ps(iy1,jy0);
191             dz10             = _mm_sub_ps(iz1,jz0);
192             dx20             = _mm_sub_ps(ix2,jx0);
193             dy20             = _mm_sub_ps(iy2,jy0);
194             dz20             = _mm_sub_ps(iz2,jz0);
195
196             /* Calculate squared distance and things based on it */
197             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
198             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
199             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
200
201             rinv00           = gmx_mm_invsqrt_ps(rsq00);
202             rinv10           = gmx_mm_invsqrt_ps(rsq10);
203             rinv20           = gmx_mm_invsqrt_ps(rsq20);
204
205             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
206             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
207             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
208
209             /* Load parameters for j particles */
210             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
211                                                               charge+jnrC+0,charge+jnrD+0);
212
213             fjx0             = _mm_setzero_ps();
214             fjy0             = _mm_setzero_ps();
215             fjz0             = _mm_setzero_ps();
216
217             /**************************
218              * CALCULATE INTERACTIONS *
219              **************************/
220
221             /* Compute parameters for interactions between i and j atoms */
222             qq00             = _mm_mul_ps(iq0,jq0);
223
224             /* COULOMB ELECTROSTATICS */
225             velec            = _mm_mul_ps(qq00,rinv00);
226             felec            = _mm_mul_ps(velec,rinvsq00);
227
228             /* Update potential sum for this i atom from the interaction with this j atom. */
229             velecsum         = _mm_add_ps(velecsum,velec);
230
231             fscal            = felec;
232
233              /* Update vectorial force */
234             fix0             = _mm_macc_ps(dx00,fscal,fix0);
235             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
236             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
237
238             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
239             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
240             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
241
242             /**************************
243              * CALCULATE INTERACTIONS *
244              **************************/
245
246             /* Compute parameters for interactions between i and j atoms */
247             qq10             = _mm_mul_ps(iq1,jq0);
248
249             /* COULOMB ELECTROSTATICS */
250             velec            = _mm_mul_ps(qq10,rinv10);
251             felec            = _mm_mul_ps(velec,rinvsq10);
252
253             /* Update potential sum for this i atom from the interaction with this j atom. */
254             velecsum         = _mm_add_ps(velecsum,velec);
255
256             fscal            = felec;
257
258              /* Update vectorial force */
259             fix1             = _mm_macc_ps(dx10,fscal,fix1);
260             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
261             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
262
263             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
264             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
265             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
266
267             /**************************
268              * CALCULATE INTERACTIONS *
269              **************************/
270
271             /* Compute parameters for interactions between i and j atoms */
272             qq20             = _mm_mul_ps(iq2,jq0);
273
274             /* COULOMB ELECTROSTATICS */
275             velec            = _mm_mul_ps(qq20,rinv20);
276             felec            = _mm_mul_ps(velec,rinvsq20);
277
278             /* Update potential sum for this i atom from the interaction with this j atom. */
279             velecsum         = _mm_add_ps(velecsum,velec);
280
281             fscal            = felec;
282
283              /* Update vectorial force */
284             fix2             = _mm_macc_ps(dx20,fscal,fix2);
285             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
286             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
287
288             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
289             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
290             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
291
292             fjptrA             = f+j_coord_offsetA;
293             fjptrB             = f+j_coord_offsetB;
294             fjptrC             = f+j_coord_offsetC;
295             fjptrD             = f+j_coord_offsetD;
296
297             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
298
299             /* Inner loop uses 93 flops */
300         }
301
302         if(jidx<j_index_end)
303         {
304
305             /* Get j neighbor index, and coordinate index */
306             jnrlistA         = jjnr[jidx];
307             jnrlistB         = jjnr[jidx+1];
308             jnrlistC         = jjnr[jidx+2];
309             jnrlistD         = jjnr[jidx+3];
310             /* Sign of each element will be negative for non-real atoms.
311              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
312              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
313              */
314             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
315             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
316             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
317             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
318             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
319             j_coord_offsetA  = DIM*jnrA;
320             j_coord_offsetB  = DIM*jnrB;
321             j_coord_offsetC  = DIM*jnrC;
322             j_coord_offsetD  = DIM*jnrD;
323
324             /* load j atom coordinates */
325             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
326                                               x+j_coord_offsetC,x+j_coord_offsetD,
327                                               &jx0,&jy0,&jz0);
328
329             /* Calculate displacement vector */
330             dx00             = _mm_sub_ps(ix0,jx0);
331             dy00             = _mm_sub_ps(iy0,jy0);
332             dz00             = _mm_sub_ps(iz0,jz0);
333             dx10             = _mm_sub_ps(ix1,jx0);
334             dy10             = _mm_sub_ps(iy1,jy0);
335             dz10             = _mm_sub_ps(iz1,jz0);
336             dx20             = _mm_sub_ps(ix2,jx0);
337             dy20             = _mm_sub_ps(iy2,jy0);
338             dz20             = _mm_sub_ps(iz2,jz0);
339
340             /* Calculate squared distance and things based on it */
341             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
342             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
343             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
344
345             rinv00           = gmx_mm_invsqrt_ps(rsq00);
346             rinv10           = gmx_mm_invsqrt_ps(rsq10);
347             rinv20           = gmx_mm_invsqrt_ps(rsq20);
348
349             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
350             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
351             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
352
353             /* Load parameters for j particles */
354             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
355                                                               charge+jnrC+0,charge+jnrD+0);
356
357             fjx0             = _mm_setzero_ps();
358             fjy0             = _mm_setzero_ps();
359             fjz0             = _mm_setzero_ps();
360
361             /**************************
362              * CALCULATE INTERACTIONS *
363              **************************/
364
365             /* Compute parameters for interactions between i and j atoms */
366             qq00             = _mm_mul_ps(iq0,jq0);
367
368             /* COULOMB ELECTROSTATICS */
369             velec            = _mm_mul_ps(qq00,rinv00);
370             felec            = _mm_mul_ps(velec,rinvsq00);
371
372             /* Update potential sum for this i atom from the interaction with this j atom. */
373             velec            = _mm_andnot_ps(dummy_mask,velec);
374             velecsum         = _mm_add_ps(velecsum,velec);
375
376             fscal            = felec;
377
378             fscal            = _mm_andnot_ps(dummy_mask,fscal);
379
380              /* Update vectorial force */
381             fix0             = _mm_macc_ps(dx00,fscal,fix0);
382             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
383             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
384
385             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
386             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
387             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
388
389             /**************************
390              * CALCULATE INTERACTIONS *
391              **************************/
392
393             /* Compute parameters for interactions between i and j atoms */
394             qq10             = _mm_mul_ps(iq1,jq0);
395
396             /* COULOMB ELECTROSTATICS */
397             velec            = _mm_mul_ps(qq10,rinv10);
398             felec            = _mm_mul_ps(velec,rinvsq10);
399
400             /* Update potential sum for this i atom from the interaction with this j atom. */
401             velec            = _mm_andnot_ps(dummy_mask,velec);
402             velecsum         = _mm_add_ps(velecsum,velec);
403
404             fscal            = felec;
405
406             fscal            = _mm_andnot_ps(dummy_mask,fscal);
407
408              /* Update vectorial force */
409             fix1             = _mm_macc_ps(dx10,fscal,fix1);
410             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
411             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
412
413             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
414             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
415             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
416
417             /**************************
418              * CALCULATE INTERACTIONS *
419              **************************/
420
421             /* Compute parameters for interactions between i and j atoms */
422             qq20             = _mm_mul_ps(iq2,jq0);
423
424             /* COULOMB ELECTROSTATICS */
425             velec            = _mm_mul_ps(qq20,rinv20);
426             felec            = _mm_mul_ps(velec,rinvsq20);
427
428             /* Update potential sum for this i atom from the interaction with this j atom. */
429             velec            = _mm_andnot_ps(dummy_mask,velec);
430             velecsum         = _mm_add_ps(velecsum,velec);
431
432             fscal            = felec;
433
434             fscal            = _mm_andnot_ps(dummy_mask,fscal);
435
436              /* Update vectorial force */
437             fix2             = _mm_macc_ps(dx20,fscal,fix2);
438             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
439             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
440
441             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
442             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
443             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
444
445             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
446             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
447             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
448             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
449
450             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
451
452             /* Inner loop uses 93 flops */
453         }
454
455         /* End of innermost loop */
456
457         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
458                                               f+i_coord_offset,fshift+i_shift_offset);
459
460         ggid                        = gid[iidx];
461         /* Update potential energies */
462         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
463
464         /* Increment number of inner iterations */
465         inneriter                  += j_index_end - j_index_start;
466
467         /* Outer loop uses 19 flops */
468     }
469
470     /* Increment number of outer iterations */
471     outeriter        += nri;
472
473     /* Update outer/inner flops */
474
475     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*93);
476 }
477 /*
478  * Gromacs nonbonded kernel:   nb_kernel_ElecCoul_VdwNone_GeomW3P1_F_avx_128_fma_single
479  * Electrostatics interaction: Coulomb
480  * VdW interaction:            None
481  * Geometry:                   Water3-Particle
482  * Calculate force/pot:        Force
483  */
484 void
485 nb_kernel_ElecCoul_VdwNone_GeomW3P1_F_avx_128_fma_single
486                     (t_nblist                    * gmx_restrict       nlist,
487                      rvec                        * gmx_restrict          xx,
488                      rvec                        * gmx_restrict          ff,
489                      t_forcerec                  * gmx_restrict          fr,
490                      t_mdatoms                   * gmx_restrict     mdatoms,
491                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
492                      t_nrnb                      * gmx_restrict        nrnb)
493 {
494     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
495      * just 0 for non-waters.
496      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
497      * jnr indices corresponding to data put in the four positions in the SIMD register.
498      */
499     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
500     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
501     int              jnrA,jnrB,jnrC,jnrD;
502     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
503     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
504     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
505     real             rcutoff_scalar;
506     real             *shiftvec,*fshift,*x,*f;
507     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
508     real             scratch[4*DIM];
509     __m128           fscal,rcutoff,rcutoff2,jidxall;
510     int              vdwioffset0;
511     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
512     int              vdwioffset1;
513     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
514     int              vdwioffset2;
515     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
516     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
517     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
518     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
519     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
520     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
521     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
522     real             *charge;
523     __m128           dummy_mask,cutoff_mask;
524     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
525     __m128           one     = _mm_set1_ps(1.0);
526     __m128           two     = _mm_set1_ps(2.0);
527     x                = xx[0];
528     f                = ff[0];
529
530     nri              = nlist->nri;
531     iinr             = nlist->iinr;
532     jindex           = nlist->jindex;
533     jjnr             = nlist->jjnr;
534     shiftidx         = nlist->shift;
535     gid              = nlist->gid;
536     shiftvec         = fr->shift_vec[0];
537     fshift           = fr->fshift[0];
538     facel            = _mm_set1_ps(fr->epsfac);
539     charge           = mdatoms->chargeA;
540
541     /* Setup water-specific parameters */
542     inr              = nlist->iinr[0];
543     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
544     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
545     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
546
547     /* Avoid stupid compiler warnings */
548     jnrA = jnrB = jnrC = jnrD = 0;
549     j_coord_offsetA = 0;
550     j_coord_offsetB = 0;
551     j_coord_offsetC = 0;
552     j_coord_offsetD = 0;
553
554     outeriter        = 0;
555     inneriter        = 0;
556
557     for(iidx=0;iidx<4*DIM;iidx++)
558     {
559         scratch[iidx] = 0.0;
560     }
561
562     /* Start outer loop over neighborlists */
563     for(iidx=0; iidx<nri; iidx++)
564     {
565         /* Load shift vector for this list */
566         i_shift_offset   = DIM*shiftidx[iidx];
567
568         /* Load limits for loop over neighbors */
569         j_index_start    = jindex[iidx];
570         j_index_end      = jindex[iidx+1];
571
572         /* Get outer coordinate index */
573         inr              = iinr[iidx];
574         i_coord_offset   = DIM*inr;
575
576         /* Load i particle coords and add shift vector */
577         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
578                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
579
580         fix0             = _mm_setzero_ps();
581         fiy0             = _mm_setzero_ps();
582         fiz0             = _mm_setzero_ps();
583         fix1             = _mm_setzero_ps();
584         fiy1             = _mm_setzero_ps();
585         fiz1             = _mm_setzero_ps();
586         fix2             = _mm_setzero_ps();
587         fiy2             = _mm_setzero_ps();
588         fiz2             = _mm_setzero_ps();
589
590         /* Start inner kernel loop */
591         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
592         {
593
594             /* Get j neighbor index, and coordinate index */
595             jnrA             = jjnr[jidx];
596             jnrB             = jjnr[jidx+1];
597             jnrC             = jjnr[jidx+2];
598             jnrD             = jjnr[jidx+3];
599             j_coord_offsetA  = DIM*jnrA;
600             j_coord_offsetB  = DIM*jnrB;
601             j_coord_offsetC  = DIM*jnrC;
602             j_coord_offsetD  = DIM*jnrD;
603
604             /* load j atom coordinates */
605             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
606                                               x+j_coord_offsetC,x+j_coord_offsetD,
607                                               &jx0,&jy0,&jz0);
608
609             /* Calculate displacement vector */
610             dx00             = _mm_sub_ps(ix0,jx0);
611             dy00             = _mm_sub_ps(iy0,jy0);
612             dz00             = _mm_sub_ps(iz0,jz0);
613             dx10             = _mm_sub_ps(ix1,jx0);
614             dy10             = _mm_sub_ps(iy1,jy0);
615             dz10             = _mm_sub_ps(iz1,jz0);
616             dx20             = _mm_sub_ps(ix2,jx0);
617             dy20             = _mm_sub_ps(iy2,jy0);
618             dz20             = _mm_sub_ps(iz2,jz0);
619
620             /* Calculate squared distance and things based on it */
621             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
622             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
623             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
624
625             rinv00           = gmx_mm_invsqrt_ps(rsq00);
626             rinv10           = gmx_mm_invsqrt_ps(rsq10);
627             rinv20           = gmx_mm_invsqrt_ps(rsq20);
628
629             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
630             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
631             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
632
633             /* Load parameters for j particles */
634             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
635                                                               charge+jnrC+0,charge+jnrD+0);
636
637             fjx0             = _mm_setzero_ps();
638             fjy0             = _mm_setzero_ps();
639             fjz0             = _mm_setzero_ps();
640
641             /**************************
642              * CALCULATE INTERACTIONS *
643              **************************/
644
645             /* Compute parameters for interactions between i and j atoms */
646             qq00             = _mm_mul_ps(iq0,jq0);
647
648             /* COULOMB ELECTROSTATICS */
649             velec            = _mm_mul_ps(qq00,rinv00);
650             felec            = _mm_mul_ps(velec,rinvsq00);
651
652             fscal            = felec;
653
654              /* Update vectorial force */
655             fix0             = _mm_macc_ps(dx00,fscal,fix0);
656             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
657             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
658
659             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
660             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
661             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
662
663             /**************************
664              * CALCULATE INTERACTIONS *
665              **************************/
666
667             /* Compute parameters for interactions between i and j atoms */
668             qq10             = _mm_mul_ps(iq1,jq0);
669
670             /* COULOMB ELECTROSTATICS */
671             velec            = _mm_mul_ps(qq10,rinv10);
672             felec            = _mm_mul_ps(velec,rinvsq10);
673
674             fscal            = felec;
675
676              /* Update vectorial force */
677             fix1             = _mm_macc_ps(dx10,fscal,fix1);
678             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
679             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
680
681             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
682             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
683             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
684
685             /**************************
686              * CALCULATE INTERACTIONS *
687              **************************/
688
689             /* Compute parameters for interactions between i and j atoms */
690             qq20             = _mm_mul_ps(iq2,jq0);
691
692             /* COULOMB ELECTROSTATICS */
693             velec            = _mm_mul_ps(qq20,rinv20);
694             felec            = _mm_mul_ps(velec,rinvsq20);
695
696             fscal            = felec;
697
698              /* Update vectorial force */
699             fix2             = _mm_macc_ps(dx20,fscal,fix2);
700             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
701             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
702
703             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
704             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
705             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
706
707             fjptrA             = f+j_coord_offsetA;
708             fjptrB             = f+j_coord_offsetB;
709             fjptrC             = f+j_coord_offsetC;
710             fjptrD             = f+j_coord_offsetD;
711
712             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
713
714             /* Inner loop uses 90 flops */
715         }
716
717         if(jidx<j_index_end)
718         {
719
720             /* Get j neighbor index, and coordinate index */
721             jnrlistA         = jjnr[jidx];
722             jnrlistB         = jjnr[jidx+1];
723             jnrlistC         = jjnr[jidx+2];
724             jnrlistD         = jjnr[jidx+3];
725             /* Sign of each element will be negative for non-real atoms.
726              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
727              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
728              */
729             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
730             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
731             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
732             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
733             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
734             j_coord_offsetA  = DIM*jnrA;
735             j_coord_offsetB  = DIM*jnrB;
736             j_coord_offsetC  = DIM*jnrC;
737             j_coord_offsetD  = DIM*jnrD;
738
739             /* load j atom coordinates */
740             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
741                                               x+j_coord_offsetC,x+j_coord_offsetD,
742                                               &jx0,&jy0,&jz0);
743
744             /* Calculate displacement vector */
745             dx00             = _mm_sub_ps(ix0,jx0);
746             dy00             = _mm_sub_ps(iy0,jy0);
747             dz00             = _mm_sub_ps(iz0,jz0);
748             dx10             = _mm_sub_ps(ix1,jx0);
749             dy10             = _mm_sub_ps(iy1,jy0);
750             dz10             = _mm_sub_ps(iz1,jz0);
751             dx20             = _mm_sub_ps(ix2,jx0);
752             dy20             = _mm_sub_ps(iy2,jy0);
753             dz20             = _mm_sub_ps(iz2,jz0);
754
755             /* Calculate squared distance and things based on it */
756             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
757             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
758             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
759
760             rinv00           = gmx_mm_invsqrt_ps(rsq00);
761             rinv10           = gmx_mm_invsqrt_ps(rsq10);
762             rinv20           = gmx_mm_invsqrt_ps(rsq20);
763
764             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
765             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
766             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
767
768             /* Load parameters for j particles */
769             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
770                                                               charge+jnrC+0,charge+jnrD+0);
771
772             fjx0             = _mm_setzero_ps();
773             fjy0             = _mm_setzero_ps();
774             fjz0             = _mm_setzero_ps();
775
776             /**************************
777              * CALCULATE INTERACTIONS *
778              **************************/
779
780             /* Compute parameters for interactions between i and j atoms */
781             qq00             = _mm_mul_ps(iq0,jq0);
782
783             /* COULOMB ELECTROSTATICS */
784             velec            = _mm_mul_ps(qq00,rinv00);
785             felec            = _mm_mul_ps(velec,rinvsq00);
786
787             fscal            = felec;
788
789             fscal            = _mm_andnot_ps(dummy_mask,fscal);
790
791              /* Update vectorial force */
792             fix0             = _mm_macc_ps(dx00,fscal,fix0);
793             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
794             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
795
796             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
797             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
798             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
799
800             /**************************
801              * CALCULATE INTERACTIONS *
802              **************************/
803
804             /* Compute parameters for interactions between i and j atoms */
805             qq10             = _mm_mul_ps(iq1,jq0);
806
807             /* COULOMB ELECTROSTATICS */
808             velec            = _mm_mul_ps(qq10,rinv10);
809             felec            = _mm_mul_ps(velec,rinvsq10);
810
811             fscal            = felec;
812
813             fscal            = _mm_andnot_ps(dummy_mask,fscal);
814
815              /* Update vectorial force */
816             fix1             = _mm_macc_ps(dx10,fscal,fix1);
817             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
818             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
819
820             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
821             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
822             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
823
824             /**************************
825              * CALCULATE INTERACTIONS *
826              **************************/
827
828             /* Compute parameters for interactions between i and j atoms */
829             qq20             = _mm_mul_ps(iq2,jq0);
830
831             /* COULOMB ELECTROSTATICS */
832             velec            = _mm_mul_ps(qq20,rinv20);
833             felec            = _mm_mul_ps(velec,rinvsq20);
834
835             fscal            = felec;
836
837             fscal            = _mm_andnot_ps(dummy_mask,fscal);
838
839              /* Update vectorial force */
840             fix2             = _mm_macc_ps(dx20,fscal,fix2);
841             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
842             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
843
844             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
845             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
846             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
847
848             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
849             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
850             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
851             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
852
853             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
854
855             /* Inner loop uses 90 flops */
856         }
857
858         /* End of innermost loop */
859
860         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
861                                               f+i_coord_offset,fshift+i_shift_offset);
862
863         /* Increment number of inner iterations */
864         inneriter                  += j_index_end - j_index_start;
865
866         /* Outer loop uses 18 flops */
867     }
868
869     /* Increment number of outer iterations */
870     outeriter        += nri;
871
872     /* Update outer/inner flops */
873
874     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*90);
875 }