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