Merge release-4-6 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_avx_128_fma_single.c
1 /*
2  * Note: this file was generated by the Gromacs avx_128_fma_single kernel generator.
3  *
4  *                This source code is part of
5  *
6  *                 G   R   O   M   A   C   S
7  *
8  * Copyright (c) 2001-2012, The GROMACS Development Team
9  *
10  * Gromacs is a library for molecular simulation and trajectory analysis,
11  * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
12  * a full list of developers and information, check out http://www.gromacs.org
13  *
14  * This program is free software; you can redistribute it and/or modify it under
15  * the terms of the GNU Lesser General Public License as published by the Free
16  * Software Foundation; either version 2 of the License, or (at your option) any
17  * later version.
18  *
19  * To help fund GROMACS development, we humbly ask that you cite
20  * the papers people have written on it - you can find them on the website.
21  */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <math.h>
27
28 #include "../nb_kernel.h"
29 #include "types/simple.h"
30 #include "vec.h"
31 #include "nrnb.h"
32
33 #include "gmx_math_x86_avx_128_fma_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
35
36 /*
37  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_VF_avx_128_fma_single
38  * Electrostatics interaction: ReactionField
39  * VdW interaction:            LennardJones
40  * Geometry:                   Water4-Particle
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_VF_avx_128_fma_single
45                     (t_nblist * gmx_restrict                nlist,
46                      rvec * gmx_restrict                    xx,
47                      rvec * gmx_restrict                    ff,
48                      t_forcerec * gmx_restrict              fr,
49                      t_mdatoms * gmx_restrict               mdatoms,
50                      nb_kernel_data_t * gmx_restrict        kernel_data,
51                      t_nrnb * gmx_restrict                  nrnb)
52 {
53     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
54      * just 0 for non-waters.
55      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
56      * jnr indices corresponding to data put in the four positions in the SIMD register.
57      */
58     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
59     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
60     int              jnrA,jnrB,jnrC,jnrD;
61     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
64     real             rcutoff_scalar;
65     real             *shiftvec,*fshift,*x,*f;
66     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
67     real             scratch[4*DIM];
68     __m128           fscal,rcutoff,rcutoff2,jidxall;
69     int              vdwioffset0;
70     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
71     int              vdwioffset1;
72     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
73     int              vdwioffset2;
74     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75     int              vdwioffset3;
76     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
77     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
78     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
79     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
80     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
81     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
82     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
83     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
84     real             *charge;
85     int              nvdwtype;
86     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
87     int              *vdwtype;
88     real             *vdwparam;
89     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
90     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
91     __m128           dummy_mask,cutoff_mask;
92     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
93     __m128           one     = _mm_set1_ps(1.0);
94     __m128           two     = _mm_set1_ps(2.0);
95     x                = xx[0];
96     f                = ff[0];
97
98     nri              = nlist->nri;
99     iinr             = nlist->iinr;
100     jindex           = nlist->jindex;
101     jjnr             = nlist->jjnr;
102     shiftidx         = nlist->shift;
103     gid              = nlist->gid;
104     shiftvec         = fr->shift_vec[0];
105     fshift           = fr->fshift[0];
106     facel            = _mm_set1_ps(fr->epsfac);
107     charge           = mdatoms->chargeA;
108     krf              = _mm_set1_ps(fr->ic->k_rf);
109     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
110     crf              = _mm_set1_ps(fr->ic->c_rf);
111     nvdwtype         = fr->ntype;
112     vdwparam         = fr->nbfp;
113     vdwtype          = mdatoms->typeA;
114
115     /* Setup water-specific parameters */
116     inr              = nlist->iinr[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     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
120     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
121
122     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
123     rcutoff_scalar   = fr->rcoulomb;
124     rcutoff          = _mm_set1_ps(rcutoff_scalar);
125     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
126
127     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
128     rvdw             = _mm_set1_ps(fr->rvdw);
129
130     /* Avoid stupid compiler warnings */
131     jnrA = jnrB = jnrC = jnrD = 0;
132     j_coord_offsetA = 0;
133     j_coord_offsetB = 0;
134     j_coord_offsetC = 0;
135     j_coord_offsetD = 0;
136
137     outeriter        = 0;
138     inneriter        = 0;
139
140     for(iidx=0;iidx<4*DIM;iidx++)
141     {
142         scratch[iidx] = 0.0;
143     }
144
145     /* Start outer loop over neighborlists */
146     for(iidx=0; iidx<nri; iidx++)
147     {
148         /* Load shift vector for this list */
149         i_shift_offset   = DIM*shiftidx[iidx];
150
151         /* Load limits for loop over neighbors */
152         j_index_start    = jindex[iidx];
153         j_index_end      = jindex[iidx+1];
154
155         /* Get outer coordinate index */
156         inr              = iinr[iidx];
157         i_coord_offset   = DIM*inr;
158
159         /* Load i particle coords and add shift vector */
160         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
161                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
162
163         fix0             = _mm_setzero_ps();
164         fiy0             = _mm_setzero_ps();
165         fiz0             = _mm_setzero_ps();
166         fix1             = _mm_setzero_ps();
167         fiy1             = _mm_setzero_ps();
168         fiz1             = _mm_setzero_ps();
169         fix2             = _mm_setzero_ps();
170         fiy2             = _mm_setzero_ps();
171         fiz2             = _mm_setzero_ps();
172         fix3             = _mm_setzero_ps();
173         fiy3             = _mm_setzero_ps();
174         fiz3             = _mm_setzero_ps();
175
176         /* Reset potential sums */
177         velecsum         = _mm_setzero_ps();
178         vvdwsum          = _mm_setzero_ps();
179
180         /* Start inner kernel loop */
181         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
182         {
183
184             /* Get j neighbor index, and coordinate index */
185             jnrA             = jjnr[jidx];
186             jnrB             = jjnr[jidx+1];
187             jnrC             = jjnr[jidx+2];
188             jnrD             = jjnr[jidx+3];
189             j_coord_offsetA  = DIM*jnrA;
190             j_coord_offsetB  = DIM*jnrB;
191             j_coord_offsetC  = DIM*jnrC;
192             j_coord_offsetD  = DIM*jnrD;
193
194             /* load j atom coordinates */
195             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
196                                               x+j_coord_offsetC,x+j_coord_offsetD,
197                                               &jx0,&jy0,&jz0);
198
199             /* Calculate displacement vector */
200             dx00             = _mm_sub_ps(ix0,jx0);
201             dy00             = _mm_sub_ps(iy0,jy0);
202             dz00             = _mm_sub_ps(iz0,jz0);
203             dx10             = _mm_sub_ps(ix1,jx0);
204             dy10             = _mm_sub_ps(iy1,jy0);
205             dz10             = _mm_sub_ps(iz1,jz0);
206             dx20             = _mm_sub_ps(ix2,jx0);
207             dy20             = _mm_sub_ps(iy2,jy0);
208             dz20             = _mm_sub_ps(iz2,jz0);
209             dx30             = _mm_sub_ps(ix3,jx0);
210             dy30             = _mm_sub_ps(iy3,jy0);
211             dz30             = _mm_sub_ps(iz3,jz0);
212
213             /* Calculate squared distance and things based on it */
214             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
215             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
216             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
217             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
218
219             rinv10           = gmx_mm_invsqrt_ps(rsq10);
220             rinv20           = gmx_mm_invsqrt_ps(rsq20);
221             rinv30           = gmx_mm_invsqrt_ps(rsq30);
222
223             rinvsq00         = gmx_mm_inv_ps(rsq00);
224             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
225             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
226             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
227
228             /* Load parameters for j particles */
229             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
230                                                               charge+jnrC+0,charge+jnrD+0);
231             vdwjidx0A        = 2*vdwtype[jnrA+0];
232             vdwjidx0B        = 2*vdwtype[jnrB+0];
233             vdwjidx0C        = 2*vdwtype[jnrC+0];
234             vdwjidx0D        = 2*vdwtype[jnrD+0];
235
236             fjx0             = _mm_setzero_ps();
237             fjy0             = _mm_setzero_ps();
238             fjz0             = _mm_setzero_ps();
239
240             /**************************
241              * CALCULATE INTERACTIONS *
242              **************************/
243
244             if (gmx_mm_any_lt(rsq00,rcutoff2))
245             {
246
247             /* Compute parameters for interactions between i and j atoms */
248             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
249                                          vdwparam+vdwioffset0+vdwjidx0B,
250                                          vdwparam+vdwioffset0+vdwjidx0C,
251                                          vdwparam+vdwioffset0+vdwjidx0D,
252                                          &c6_00,&c12_00);
253
254             /* LENNARD-JONES DISPERSION/REPULSION */
255
256             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
257             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
258             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
259             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
260                                           _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
261             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
262
263             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
264
265             /* Update potential sum for this i atom from the interaction with this j atom. */
266             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
267             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
268
269             fscal            = fvdw;
270
271             fscal            = _mm_and_ps(fscal,cutoff_mask);
272
273              /* Update vectorial force */
274             fix0             = _mm_macc_ps(dx00,fscal,fix0);
275             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
276             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
277
278             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
279             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
280             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
281
282             }
283
284             /**************************
285              * CALCULATE INTERACTIONS *
286              **************************/
287
288             if (gmx_mm_any_lt(rsq10,rcutoff2))
289             {
290
291             /* Compute parameters for interactions between i and j atoms */
292             qq10             = _mm_mul_ps(iq1,jq0);
293
294             /* REACTION-FIELD ELECTROSTATICS */
295             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
296             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
297
298             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
299
300             /* Update potential sum for this i atom from the interaction with this j atom. */
301             velec            = _mm_and_ps(velec,cutoff_mask);
302             velecsum         = _mm_add_ps(velecsum,velec);
303
304             fscal            = felec;
305
306             fscal            = _mm_and_ps(fscal,cutoff_mask);
307
308              /* Update vectorial force */
309             fix1             = _mm_macc_ps(dx10,fscal,fix1);
310             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
311             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
312
313             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
314             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
315             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
316
317             }
318
319             /**************************
320              * CALCULATE INTERACTIONS *
321              **************************/
322
323             if (gmx_mm_any_lt(rsq20,rcutoff2))
324             {
325
326             /* Compute parameters for interactions between i and j atoms */
327             qq20             = _mm_mul_ps(iq2,jq0);
328
329             /* REACTION-FIELD ELECTROSTATICS */
330             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
331             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
332
333             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
334
335             /* Update potential sum for this i atom from the interaction with this j atom. */
336             velec            = _mm_and_ps(velec,cutoff_mask);
337             velecsum         = _mm_add_ps(velecsum,velec);
338
339             fscal            = felec;
340
341             fscal            = _mm_and_ps(fscal,cutoff_mask);
342
343              /* Update vectorial force */
344             fix2             = _mm_macc_ps(dx20,fscal,fix2);
345             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
346             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
347
348             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
349             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
350             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
351
352             }
353
354             /**************************
355              * CALCULATE INTERACTIONS *
356              **************************/
357
358             if (gmx_mm_any_lt(rsq30,rcutoff2))
359             {
360
361             /* Compute parameters for interactions between i and j atoms */
362             qq30             = _mm_mul_ps(iq3,jq0);
363
364             /* REACTION-FIELD ELECTROSTATICS */
365             velec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
366             felec            = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
367
368             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
369
370             /* Update potential sum for this i atom from the interaction with this j atom. */
371             velec            = _mm_and_ps(velec,cutoff_mask);
372             velecsum         = _mm_add_ps(velecsum,velec);
373
374             fscal            = felec;
375
376             fscal            = _mm_and_ps(fscal,cutoff_mask);
377
378              /* Update vectorial force */
379             fix3             = _mm_macc_ps(dx30,fscal,fix3);
380             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
381             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
382
383             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
384             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
385             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
386
387             }
388
389             fjptrA             = f+j_coord_offsetA;
390             fjptrB             = f+j_coord_offsetB;
391             fjptrC             = f+j_coord_offsetC;
392             fjptrD             = f+j_coord_offsetD;
393
394             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
395
396             /* Inner loop uses 161 flops */
397         }
398
399         if(jidx<j_index_end)
400         {
401
402             /* Get j neighbor index, and coordinate index */
403             jnrlistA         = jjnr[jidx];
404             jnrlistB         = jjnr[jidx+1];
405             jnrlistC         = jjnr[jidx+2];
406             jnrlistD         = jjnr[jidx+3];
407             /* Sign of each element will be negative for non-real atoms.
408              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
409              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
410              */
411             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
412             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
413             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
414             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
415             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
416             j_coord_offsetA  = DIM*jnrA;
417             j_coord_offsetB  = DIM*jnrB;
418             j_coord_offsetC  = DIM*jnrC;
419             j_coord_offsetD  = DIM*jnrD;
420
421             /* load j atom coordinates */
422             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
423                                               x+j_coord_offsetC,x+j_coord_offsetD,
424                                               &jx0,&jy0,&jz0);
425
426             /* Calculate displacement vector */
427             dx00             = _mm_sub_ps(ix0,jx0);
428             dy00             = _mm_sub_ps(iy0,jy0);
429             dz00             = _mm_sub_ps(iz0,jz0);
430             dx10             = _mm_sub_ps(ix1,jx0);
431             dy10             = _mm_sub_ps(iy1,jy0);
432             dz10             = _mm_sub_ps(iz1,jz0);
433             dx20             = _mm_sub_ps(ix2,jx0);
434             dy20             = _mm_sub_ps(iy2,jy0);
435             dz20             = _mm_sub_ps(iz2,jz0);
436             dx30             = _mm_sub_ps(ix3,jx0);
437             dy30             = _mm_sub_ps(iy3,jy0);
438             dz30             = _mm_sub_ps(iz3,jz0);
439
440             /* Calculate squared distance and things based on it */
441             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
442             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
443             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
444             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
445
446             rinv10           = gmx_mm_invsqrt_ps(rsq10);
447             rinv20           = gmx_mm_invsqrt_ps(rsq20);
448             rinv30           = gmx_mm_invsqrt_ps(rsq30);
449
450             rinvsq00         = gmx_mm_inv_ps(rsq00);
451             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
452             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
453             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
454
455             /* Load parameters for j particles */
456             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
457                                                               charge+jnrC+0,charge+jnrD+0);
458             vdwjidx0A        = 2*vdwtype[jnrA+0];
459             vdwjidx0B        = 2*vdwtype[jnrB+0];
460             vdwjidx0C        = 2*vdwtype[jnrC+0];
461             vdwjidx0D        = 2*vdwtype[jnrD+0];
462
463             fjx0             = _mm_setzero_ps();
464             fjy0             = _mm_setzero_ps();
465             fjz0             = _mm_setzero_ps();
466
467             /**************************
468              * CALCULATE INTERACTIONS *
469              **************************/
470
471             if (gmx_mm_any_lt(rsq00,rcutoff2))
472             {
473
474             /* Compute parameters for interactions between i and j atoms */
475             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
476                                          vdwparam+vdwioffset0+vdwjidx0B,
477                                          vdwparam+vdwioffset0+vdwjidx0C,
478                                          vdwparam+vdwioffset0+vdwjidx0D,
479                                          &c6_00,&c12_00);
480
481             /* LENNARD-JONES DISPERSION/REPULSION */
482
483             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
484             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
485             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
486             vvdw             = _mm_msub_ps(_mm_nmacc_ps(c12_00,_mm_mul_ps(sh_vdw_invrcut6,sh_vdw_invrcut6),vvdw12),one_twelfth,
487                                           _mm_mul_ps( _mm_nmacc_ps(c6_00,sh_vdw_invrcut6,vvdw6),one_sixth));
488             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
489
490             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
491
492             /* Update potential sum for this i atom from the interaction with this j atom. */
493             vvdw             = _mm_and_ps(vvdw,cutoff_mask);
494             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
495             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
496
497             fscal            = fvdw;
498
499             fscal            = _mm_and_ps(fscal,cutoff_mask);
500
501             fscal            = _mm_andnot_ps(dummy_mask,fscal);
502
503              /* Update vectorial force */
504             fix0             = _mm_macc_ps(dx00,fscal,fix0);
505             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
506             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
507
508             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
509             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
510             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
511
512             }
513
514             /**************************
515              * CALCULATE INTERACTIONS *
516              **************************/
517
518             if (gmx_mm_any_lt(rsq10,rcutoff2))
519             {
520
521             /* Compute parameters for interactions between i and j atoms */
522             qq10             = _mm_mul_ps(iq1,jq0);
523
524             /* REACTION-FIELD ELECTROSTATICS */
525             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
526             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
527
528             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
529
530             /* Update potential sum for this i atom from the interaction with this j atom. */
531             velec            = _mm_and_ps(velec,cutoff_mask);
532             velec            = _mm_andnot_ps(dummy_mask,velec);
533             velecsum         = _mm_add_ps(velecsum,velec);
534
535             fscal            = felec;
536
537             fscal            = _mm_and_ps(fscal,cutoff_mask);
538
539             fscal            = _mm_andnot_ps(dummy_mask,fscal);
540
541              /* Update vectorial force */
542             fix1             = _mm_macc_ps(dx10,fscal,fix1);
543             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
544             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
545
546             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
547             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
548             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
549
550             }
551
552             /**************************
553              * CALCULATE INTERACTIONS *
554              **************************/
555
556             if (gmx_mm_any_lt(rsq20,rcutoff2))
557             {
558
559             /* Compute parameters for interactions between i and j atoms */
560             qq20             = _mm_mul_ps(iq2,jq0);
561
562             /* REACTION-FIELD ELECTROSTATICS */
563             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
564             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
565
566             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
567
568             /* Update potential sum for this i atom from the interaction with this j atom. */
569             velec            = _mm_and_ps(velec,cutoff_mask);
570             velec            = _mm_andnot_ps(dummy_mask,velec);
571             velecsum         = _mm_add_ps(velecsum,velec);
572
573             fscal            = felec;
574
575             fscal            = _mm_and_ps(fscal,cutoff_mask);
576
577             fscal            = _mm_andnot_ps(dummy_mask,fscal);
578
579              /* Update vectorial force */
580             fix2             = _mm_macc_ps(dx20,fscal,fix2);
581             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
582             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
583
584             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
585             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
586             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
587
588             }
589
590             /**************************
591              * CALCULATE INTERACTIONS *
592              **************************/
593
594             if (gmx_mm_any_lt(rsq30,rcutoff2))
595             {
596
597             /* Compute parameters for interactions between i and j atoms */
598             qq30             = _mm_mul_ps(iq3,jq0);
599
600             /* REACTION-FIELD ELECTROSTATICS */
601             velec            = _mm_mul_ps(qq30,_mm_sub_ps(_mm_macc_ps(krf,rsq30,rinv30),crf));
602             felec            = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
603
604             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
605
606             /* Update potential sum for this i atom from the interaction with this j atom. */
607             velec            = _mm_and_ps(velec,cutoff_mask);
608             velec            = _mm_andnot_ps(dummy_mask,velec);
609             velecsum         = _mm_add_ps(velecsum,velec);
610
611             fscal            = felec;
612
613             fscal            = _mm_and_ps(fscal,cutoff_mask);
614
615             fscal            = _mm_andnot_ps(dummy_mask,fscal);
616
617              /* Update vectorial force */
618             fix3             = _mm_macc_ps(dx30,fscal,fix3);
619             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
620             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
621
622             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
623             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
624             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
625
626             }
627
628             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
629             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
630             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
631             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
632
633             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
634
635             /* Inner loop uses 161 flops */
636         }
637
638         /* End of innermost loop */
639
640         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
641                                               f+i_coord_offset,fshift+i_shift_offset);
642
643         ggid                        = gid[iidx];
644         /* Update potential energies */
645         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
646         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
647
648         /* Increment number of inner iterations */
649         inneriter                  += j_index_end - j_index_start;
650
651         /* Outer loop uses 26 flops */
652     }
653
654     /* Increment number of outer iterations */
655     outeriter        += nri;
656
657     /* Update outer/inner flops */
658
659     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_VF,outeriter*26 + inneriter*161);
660 }
661 /*
662  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_avx_128_fma_single
663  * Electrostatics interaction: ReactionField
664  * VdW interaction:            LennardJones
665  * Geometry:                   Water4-Particle
666  * Calculate force/pot:        Force
667  */
668 void
669 nb_kernel_ElecRFCut_VdwLJSh_GeomW4P1_F_avx_128_fma_single
670                     (t_nblist * gmx_restrict                nlist,
671                      rvec * gmx_restrict                    xx,
672                      rvec * gmx_restrict                    ff,
673                      t_forcerec * gmx_restrict              fr,
674                      t_mdatoms * gmx_restrict               mdatoms,
675                      nb_kernel_data_t * gmx_restrict        kernel_data,
676                      t_nrnb * gmx_restrict                  nrnb)
677 {
678     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
679      * just 0 for non-waters.
680      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
681      * jnr indices corresponding to data put in the four positions in the SIMD register.
682      */
683     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
684     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
685     int              jnrA,jnrB,jnrC,jnrD;
686     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
687     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
688     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
689     real             rcutoff_scalar;
690     real             *shiftvec,*fshift,*x,*f;
691     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
692     real             scratch[4*DIM];
693     __m128           fscal,rcutoff,rcutoff2,jidxall;
694     int              vdwioffset0;
695     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
696     int              vdwioffset1;
697     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
698     int              vdwioffset2;
699     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
700     int              vdwioffset3;
701     __m128           ix3,iy3,iz3,fix3,fiy3,fiz3,iq3,isai3;
702     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
703     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
704     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
705     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
706     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
707     __m128           dx30,dy30,dz30,rsq30,rinv30,rinvsq30,r30,qq30,c6_30,c12_30;
708     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
709     real             *charge;
710     int              nvdwtype;
711     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
712     int              *vdwtype;
713     real             *vdwparam;
714     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
715     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
716     __m128           dummy_mask,cutoff_mask;
717     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
718     __m128           one     = _mm_set1_ps(1.0);
719     __m128           two     = _mm_set1_ps(2.0);
720     x                = xx[0];
721     f                = ff[0];
722
723     nri              = nlist->nri;
724     iinr             = nlist->iinr;
725     jindex           = nlist->jindex;
726     jjnr             = nlist->jjnr;
727     shiftidx         = nlist->shift;
728     gid              = nlist->gid;
729     shiftvec         = fr->shift_vec[0];
730     fshift           = fr->fshift[0];
731     facel            = _mm_set1_ps(fr->epsfac);
732     charge           = mdatoms->chargeA;
733     krf              = _mm_set1_ps(fr->ic->k_rf);
734     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
735     crf              = _mm_set1_ps(fr->ic->c_rf);
736     nvdwtype         = fr->ntype;
737     vdwparam         = fr->nbfp;
738     vdwtype          = mdatoms->typeA;
739
740     /* Setup water-specific parameters */
741     inr              = nlist->iinr[0];
742     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
743     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
744     iq3              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+3]));
745     vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
746
747     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
748     rcutoff_scalar   = fr->rcoulomb;
749     rcutoff          = _mm_set1_ps(rcutoff_scalar);
750     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
751
752     sh_vdw_invrcut6  = _mm_set1_ps(fr->ic->sh_invrc6);
753     rvdw             = _mm_set1_ps(fr->rvdw);
754
755     /* Avoid stupid compiler warnings */
756     jnrA = jnrB = jnrC = jnrD = 0;
757     j_coord_offsetA = 0;
758     j_coord_offsetB = 0;
759     j_coord_offsetC = 0;
760     j_coord_offsetD = 0;
761
762     outeriter        = 0;
763     inneriter        = 0;
764
765     for(iidx=0;iidx<4*DIM;iidx++)
766     {
767         scratch[iidx] = 0.0;
768     }
769
770     /* Start outer loop over neighborlists */
771     for(iidx=0; iidx<nri; iidx++)
772     {
773         /* Load shift vector for this list */
774         i_shift_offset   = DIM*shiftidx[iidx];
775
776         /* Load limits for loop over neighbors */
777         j_index_start    = jindex[iidx];
778         j_index_end      = jindex[iidx+1];
779
780         /* Get outer coordinate index */
781         inr              = iinr[iidx];
782         i_coord_offset   = DIM*inr;
783
784         /* Load i particle coords and add shift vector */
785         gmx_mm_load_shift_and_4rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
786                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2,&ix3,&iy3,&iz3);
787
788         fix0             = _mm_setzero_ps();
789         fiy0             = _mm_setzero_ps();
790         fiz0             = _mm_setzero_ps();
791         fix1             = _mm_setzero_ps();
792         fiy1             = _mm_setzero_ps();
793         fiz1             = _mm_setzero_ps();
794         fix2             = _mm_setzero_ps();
795         fiy2             = _mm_setzero_ps();
796         fiz2             = _mm_setzero_ps();
797         fix3             = _mm_setzero_ps();
798         fiy3             = _mm_setzero_ps();
799         fiz3             = _mm_setzero_ps();
800
801         /* Start inner kernel loop */
802         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
803         {
804
805             /* Get j neighbor index, and coordinate index */
806             jnrA             = jjnr[jidx];
807             jnrB             = jjnr[jidx+1];
808             jnrC             = jjnr[jidx+2];
809             jnrD             = jjnr[jidx+3];
810             j_coord_offsetA  = DIM*jnrA;
811             j_coord_offsetB  = DIM*jnrB;
812             j_coord_offsetC  = DIM*jnrC;
813             j_coord_offsetD  = DIM*jnrD;
814
815             /* load j atom coordinates */
816             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
817                                               x+j_coord_offsetC,x+j_coord_offsetD,
818                                               &jx0,&jy0,&jz0);
819
820             /* Calculate displacement vector */
821             dx00             = _mm_sub_ps(ix0,jx0);
822             dy00             = _mm_sub_ps(iy0,jy0);
823             dz00             = _mm_sub_ps(iz0,jz0);
824             dx10             = _mm_sub_ps(ix1,jx0);
825             dy10             = _mm_sub_ps(iy1,jy0);
826             dz10             = _mm_sub_ps(iz1,jz0);
827             dx20             = _mm_sub_ps(ix2,jx0);
828             dy20             = _mm_sub_ps(iy2,jy0);
829             dz20             = _mm_sub_ps(iz2,jz0);
830             dx30             = _mm_sub_ps(ix3,jx0);
831             dy30             = _mm_sub_ps(iy3,jy0);
832             dz30             = _mm_sub_ps(iz3,jz0);
833
834             /* Calculate squared distance and things based on it */
835             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
836             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
837             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
838             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
839
840             rinv10           = gmx_mm_invsqrt_ps(rsq10);
841             rinv20           = gmx_mm_invsqrt_ps(rsq20);
842             rinv30           = gmx_mm_invsqrt_ps(rsq30);
843
844             rinvsq00         = gmx_mm_inv_ps(rsq00);
845             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
846             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
847             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
848
849             /* Load parameters for j particles */
850             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
851                                                               charge+jnrC+0,charge+jnrD+0);
852             vdwjidx0A        = 2*vdwtype[jnrA+0];
853             vdwjidx0B        = 2*vdwtype[jnrB+0];
854             vdwjidx0C        = 2*vdwtype[jnrC+0];
855             vdwjidx0D        = 2*vdwtype[jnrD+0];
856
857             fjx0             = _mm_setzero_ps();
858             fjy0             = _mm_setzero_ps();
859             fjz0             = _mm_setzero_ps();
860
861             /**************************
862              * CALCULATE INTERACTIONS *
863              **************************/
864
865             if (gmx_mm_any_lt(rsq00,rcutoff2))
866             {
867
868             /* Compute parameters for interactions between i and j atoms */
869             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
870                                          vdwparam+vdwioffset0+vdwjidx0B,
871                                          vdwparam+vdwioffset0+vdwjidx0C,
872                                          vdwparam+vdwioffset0+vdwjidx0D,
873                                          &c6_00,&c12_00);
874
875             /* LENNARD-JONES DISPERSION/REPULSION */
876
877             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
878             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
879
880             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
881
882             fscal            = fvdw;
883
884             fscal            = _mm_and_ps(fscal,cutoff_mask);
885
886              /* Update vectorial force */
887             fix0             = _mm_macc_ps(dx00,fscal,fix0);
888             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
889             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
890
891             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
892             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
893             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
894
895             }
896
897             /**************************
898              * CALCULATE INTERACTIONS *
899              **************************/
900
901             if (gmx_mm_any_lt(rsq10,rcutoff2))
902             {
903
904             /* Compute parameters for interactions between i and j atoms */
905             qq10             = _mm_mul_ps(iq1,jq0);
906
907             /* REACTION-FIELD ELECTROSTATICS */
908             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
909
910             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
911
912             fscal            = felec;
913
914             fscal            = _mm_and_ps(fscal,cutoff_mask);
915
916              /* Update vectorial force */
917             fix1             = _mm_macc_ps(dx10,fscal,fix1);
918             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
919             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
920
921             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
922             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
923             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
924
925             }
926
927             /**************************
928              * CALCULATE INTERACTIONS *
929              **************************/
930
931             if (gmx_mm_any_lt(rsq20,rcutoff2))
932             {
933
934             /* Compute parameters for interactions between i and j atoms */
935             qq20             = _mm_mul_ps(iq2,jq0);
936
937             /* REACTION-FIELD ELECTROSTATICS */
938             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
939
940             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
941
942             fscal            = felec;
943
944             fscal            = _mm_and_ps(fscal,cutoff_mask);
945
946              /* Update vectorial force */
947             fix2             = _mm_macc_ps(dx20,fscal,fix2);
948             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
949             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
950
951             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
952             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
953             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
954
955             }
956
957             /**************************
958              * CALCULATE INTERACTIONS *
959              **************************/
960
961             if (gmx_mm_any_lt(rsq30,rcutoff2))
962             {
963
964             /* Compute parameters for interactions between i and j atoms */
965             qq30             = _mm_mul_ps(iq3,jq0);
966
967             /* REACTION-FIELD ELECTROSTATICS */
968             felec            = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
969
970             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
971
972             fscal            = felec;
973
974             fscal            = _mm_and_ps(fscal,cutoff_mask);
975
976              /* Update vectorial force */
977             fix3             = _mm_macc_ps(dx30,fscal,fix3);
978             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
979             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
980
981             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
982             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
983             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
984
985             }
986
987             fjptrA             = f+j_coord_offsetA;
988             fjptrB             = f+j_coord_offsetB;
989             fjptrC             = f+j_coord_offsetC;
990             fjptrD             = f+j_coord_offsetD;
991
992             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
993
994             /* Inner loop uses 132 flops */
995         }
996
997         if(jidx<j_index_end)
998         {
999
1000             /* Get j neighbor index, and coordinate index */
1001             jnrlistA         = jjnr[jidx];
1002             jnrlistB         = jjnr[jidx+1];
1003             jnrlistC         = jjnr[jidx+2];
1004             jnrlistD         = jjnr[jidx+3];
1005             /* Sign of each element will be negative for non-real atoms.
1006              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
1007              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
1008              */
1009             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
1010             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
1011             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
1012             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
1013             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
1014             j_coord_offsetA  = DIM*jnrA;
1015             j_coord_offsetB  = DIM*jnrB;
1016             j_coord_offsetC  = DIM*jnrC;
1017             j_coord_offsetD  = DIM*jnrD;
1018
1019             /* load j atom coordinates */
1020             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
1021                                               x+j_coord_offsetC,x+j_coord_offsetD,
1022                                               &jx0,&jy0,&jz0);
1023
1024             /* Calculate displacement vector */
1025             dx00             = _mm_sub_ps(ix0,jx0);
1026             dy00             = _mm_sub_ps(iy0,jy0);
1027             dz00             = _mm_sub_ps(iz0,jz0);
1028             dx10             = _mm_sub_ps(ix1,jx0);
1029             dy10             = _mm_sub_ps(iy1,jy0);
1030             dz10             = _mm_sub_ps(iz1,jz0);
1031             dx20             = _mm_sub_ps(ix2,jx0);
1032             dy20             = _mm_sub_ps(iy2,jy0);
1033             dz20             = _mm_sub_ps(iz2,jz0);
1034             dx30             = _mm_sub_ps(ix3,jx0);
1035             dy30             = _mm_sub_ps(iy3,jy0);
1036             dz30             = _mm_sub_ps(iz3,jz0);
1037
1038             /* Calculate squared distance and things based on it */
1039             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
1040             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
1041             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
1042             rsq30            = gmx_mm_calc_rsq_ps(dx30,dy30,dz30);
1043
1044             rinv10           = gmx_mm_invsqrt_ps(rsq10);
1045             rinv20           = gmx_mm_invsqrt_ps(rsq20);
1046             rinv30           = gmx_mm_invsqrt_ps(rsq30);
1047
1048             rinvsq00         = gmx_mm_inv_ps(rsq00);
1049             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
1050             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
1051             rinvsq30         = _mm_mul_ps(rinv30,rinv30);
1052
1053             /* Load parameters for j particles */
1054             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
1055                                                               charge+jnrC+0,charge+jnrD+0);
1056             vdwjidx0A        = 2*vdwtype[jnrA+0];
1057             vdwjidx0B        = 2*vdwtype[jnrB+0];
1058             vdwjidx0C        = 2*vdwtype[jnrC+0];
1059             vdwjidx0D        = 2*vdwtype[jnrD+0];
1060
1061             fjx0             = _mm_setzero_ps();
1062             fjy0             = _mm_setzero_ps();
1063             fjz0             = _mm_setzero_ps();
1064
1065             /**************************
1066              * CALCULATE INTERACTIONS *
1067              **************************/
1068
1069             if (gmx_mm_any_lt(rsq00,rcutoff2))
1070             {
1071
1072             /* Compute parameters for interactions between i and j atoms */
1073             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
1074                                          vdwparam+vdwioffset0+vdwjidx0B,
1075                                          vdwparam+vdwioffset0+vdwjidx0C,
1076                                          vdwparam+vdwioffset0+vdwjidx0D,
1077                                          &c6_00,&c12_00);
1078
1079             /* LENNARD-JONES DISPERSION/REPULSION */
1080
1081             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
1082             fvdw             = _mm_mul_ps(_mm_msub_ps(c12_00,rinvsix,c6_00),_mm_mul_ps(rinvsix,rinvsq00));
1083
1084             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
1085
1086             fscal            = fvdw;
1087
1088             fscal            = _mm_and_ps(fscal,cutoff_mask);
1089
1090             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1091
1092              /* Update vectorial force */
1093             fix0             = _mm_macc_ps(dx00,fscal,fix0);
1094             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
1095             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
1096
1097             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
1098             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
1099             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
1100
1101             }
1102
1103             /**************************
1104              * CALCULATE INTERACTIONS *
1105              **************************/
1106
1107             if (gmx_mm_any_lt(rsq10,rcutoff2))
1108             {
1109
1110             /* Compute parameters for interactions between i and j atoms */
1111             qq10             = _mm_mul_ps(iq1,jq0);
1112
1113             /* REACTION-FIELD ELECTROSTATICS */
1114             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
1115
1116             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
1117
1118             fscal            = felec;
1119
1120             fscal            = _mm_and_ps(fscal,cutoff_mask);
1121
1122             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1123
1124              /* Update vectorial force */
1125             fix1             = _mm_macc_ps(dx10,fscal,fix1);
1126             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
1127             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
1128
1129             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
1130             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
1131             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
1132
1133             }
1134
1135             /**************************
1136              * CALCULATE INTERACTIONS *
1137              **************************/
1138
1139             if (gmx_mm_any_lt(rsq20,rcutoff2))
1140             {
1141
1142             /* Compute parameters for interactions between i and j atoms */
1143             qq20             = _mm_mul_ps(iq2,jq0);
1144
1145             /* REACTION-FIELD ELECTROSTATICS */
1146             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
1147
1148             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
1149
1150             fscal            = felec;
1151
1152             fscal            = _mm_and_ps(fscal,cutoff_mask);
1153
1154             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1155
1156              /* Update vectorial force */
1157             fix2             = _mm_macc_ps(dx20,fscal,fix2);
1158             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
1159             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
1160
1161             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
1162             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
1163             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
1164
1165             }
1166
1167             /**************************
1168              * CALCULATE INTERACTIONS *
1169              **************************/
1170
1171             if (gmx_mm_any_lt(rsq30,rcutoff2))
1172             {
1173
1174             /* Compute parameters for interactions between i and j atoms */
1175             qq30             = _mm_mul_ps(iq3,jq0);
1176
1177             /* REACTION-FIELD ELECTROSTATICS */
1178             felec            = _mm_mul_ps(qq30,_mm_msub_ps(rinv30,rinvsq30,krf2));
1179
1180             cutoff_mask      = _mm_cmplt_ps(rsq30,rcutoff2);
1181
1182             fscal            = felec;
1183
1184             fscal            = _mm_and_ps(fscal,cutoff_mask);
1185
1186             fscal            = _mm_andnot_ps(dummy_mask,fscal);
1187
1188              /* Update vectorial force */
1189             fix3             = _mm_macc_ps(dx30,fscal,fix3);
1190             fiy3             = _mm_macc_ps(dy30,fscal,fiy3);
1191             fiz3             = _mm_macc_ps(dz30,fscal,fiz3);
1192
1193             fjx0             = _mm_macc_ps(dx30,fscal,fjx0);
1194             fjy0             = _mm_macc_ps(dy30,fscal,fjy0);
1195             fjz0             = _mm_macc_ps(dz30,fscal,fjz0);
1196
1197             }
1198
1199             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
1200             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
1201             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
1202             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
1203
1204             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
1205
1206             /* Inner loop uses 132 flops */
1207         }
1208
1209         /* End of innermost loop */
1210
1211         gmx_mm_update_iforce_4atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,fix3,fiy3,fiz3,
1212                                               f+i_coord_offset,fshift+i_shift_offset);
1213
1214         /* Increment number of inner iterations */
1215         inneriter                  += j_index_end - j_index_start;
1216
1217         /* Outer loop uses 24 flops */
1218     }
1219
1220     /* Increment number of outer iterations */
1221     outeriter        += nri;
1222
1223     /* Update outer/inner flops */
1224
1225     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_W4_F,outeriter*24 + inneriter*132);
1226 }