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