Merge 'release-4-6' into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_single / nb_kernel_ElecEw_VdwLJ_GeomP1P1_sse2_single.c
1 /*
2  * Note: this file was generated by the Gromacs sse2_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_sse2_single.h"
34 #include "kernelutil_x86_sse2_single.h"
35
36 /*
37  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomP1P1_VF_sse2_single
38  * Electrostatics interaction: Ewald
39  * VdW interaction:            LennardJones
40  * Geometry:                   Particle-Particle
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecEw_VdwLJ_GeomP1P1_VF_sse2_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 SSE, 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              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
62     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
63     real             shX,shY,shZ,rcutoff_scalar;
64     real             *shiftvec,*fshift,*x,*f;
65     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
66     int              vdwioffset0;
67     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
68     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
69     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
70     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
71     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
72     real             *charge;
73     int              nvdwtype;
74     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
75     int              *vdwtype;
76     real             *vdwparam;
77     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
78     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
79     __m128i          ewitab;
80     __m128           ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
81     real             *ewtab;
82     __m128           dummy_mask,cutoff_mask;
83     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
84     __m128           one     = _mm_set1_ps(1.0);
85     __m128           two     = _mm_set1_ps(2.0);
86     x                = xx[0];
87     f                = ff[0];
88
89     nri              = nlist->nri;
90     iinr             = nlist->iinr;
91     jindex           = nlist->jindex;
92     jjnr             = nlist->jjnr;
93     shiftidx         = nlist->shift;
94     gid              = nlist->gid;
95     shiftvec         = fr->shift_vec[0];
96     fshift           = fr->fshift[0];
97     facel            = _mm_set1_ps(fr->epsfac);
98     charge           = mdatoms->chargeA;
99     nvdwtype         = fr->ntype;
100     vdwparam         = fr->nbfp;
101     vdwtype          = mdatoms->typeA;
102
103     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
104     ewtab            = fr->ic->tabq_coul_FDV0;
105     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
106     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
107
108     /* Avoid stupid compiler warnings */
109     jnrA = jnrB = jnrC = jnrD = 0;
110     j_coord_offsetA = 0;
111     j_coord_offsetB = 0;
112     j_coord_offsetC = 0;
113     j_coord_offsetD = 0;
114
115     outeriter        = 0;
116     inneriter        = 0;
117
118     /* Start outer loop over neighborlists */
119     for(iidx=0; iidx<nri; iidx++)
120     {
121         /* Load shift vector for this list */
122         i_shift_offset   = DIM*shiftidx[iidx];
123         shX              = shiftvec[i_shift_offset+XX];
124         shY              = shiftvec[i_shift_offset+YY];
125         shZ              = shiftvec[i_shift_offset+ZZ];
126
127         /* Load limits for loop over neighbors */
128         j_index_start    = jindex[iidx];
129         j_index_end      = jindex[iidx+1];
130
131         /* Get outer coordinate index */
132         inr              = iinr[iidx];
133         i_coord_offset   = DIM*inr;
134
135         /* Load i particle coords and add shift vector */
136         ix0              = _mm_set1_ps(shX + x[i_coord_offset+DIM*0+XX]);
137         iy0              = _mm_set1_ps(shY + x[i_coord_offset+DIM*0+YY]);
138         iz0              = _mm_set1_ps(shZ + x[i_coord_offset+DIM*0+ZZ]);
139
140         fix0             = _mm_setzero_ps();
141         fiy0             = _mm_setzero_ps();
142         fiz0             = _mm_setzero_ps();
143
144         /* Load parameters for i particles */
145         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
146         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
147
148         /* Reset potential sums */
149         velecsum         = _mm_setzero_ps();
150         vvdwsum          = _mm_setzero_ps();
151
152         /* Start inner kernel loop */
153         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
154         {
155
156             /* Get j neighbor index, and coordinate index */
157             jnrA             = jjnr[jidx];
158             jnrB             = jjnr[jidx+1];
159             jnrC             = jjnr[jidx+2];
160             jnrD             = jjnr[jidx+3];
161
162             j_coord_offsetA  = DIM*jnrA;
163             j_coord_offsetB  = DIM*jnrB;
164             j_coord_offsetC  = DIM*jnrC;
165             j_coord_offsetD  = DIM*jnrD;
166
167             /* load j atom coordinates */
168             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
169                                               x+j_coord_offsetC,x+j_coord_offsetD,
170                                               &jx0,&jy0,&jz0);
171
172             /* Calculate displacement vector */
173             dx00             = _mm_sub_ps(ix0,jx0);
174             dy00             = _mm_sub_ps(iy0,jy0);
175             dz00             = _mm_sub_ps(iz0,jz0);
176
177             /* Calculate squared distance and things based on it */
178             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
179
180             rinv00           = gmx_mm_invsqrt_ps(rsq00);
181
182             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
183
184             /* Load parameters for j particles */
185             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
186                                                               charge+jnrC+0,charge+jnrD+0);
187             vdwjidx0A        = 2*vdwtype[jnrA+0];
188             vdwjidx0B        = 2*vdwtype[jnrB+0];
189             vdwjidx0C        = 2*vdwtype[jnrC+0];
190             vdwjidx0D        = 2*vdwtype[jnrD+0];
191
192             /**************************
193              * CALCULATE INTERACTIONS *
194              **************************/
195
196             r00              = _mm_mul_ps(rsq00,rinv00);
197
198             /* Compute parameters for interactions between i and j atoms */
199             qq00             = _mm_mul_ps(iq0,jq0);
200             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
201                                          vdwparam+vdwioffset0+vdwjidx0B,
202                                          vdwparam+vdwioffset0+vdwjidx0C,
203                                          vdwparam+vdwioffset0+vdwjidx0D,
204                                          &c6_00,&c12_00);
205
206             /* EWALD ELECTROSTATICS */
207
208             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
209             ewrt             = _mm_mul_ps(r00,ewtabscale);
210             ewitab           = _mm_cvttps_epi32(ewrt);
211             eweps            = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
212             ewitab           = _mm_slli_epi32(ewitab,2);
213             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
214             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
215             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
216             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
217             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
218             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
219             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
220             velec            = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
221             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
222
223             /* LENNARD-JONES DISPERSION/REPULSION */
224
225             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
226             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
227             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
228             vvdw             = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
229             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
230
231             /* Update potential sum for this i atom from the interaction with this j atom. */
232             velecsum         = _mm_add_ps(velecsum,velec);
233             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
234
235             fscal            = _mm_add_ps(felec,fvdw);
236
237             /* Calculate temporary vectorial force */
238             tx               = _mm_mul_ps(fscal,dx00);
239             ty               = _mm_mul_ps(fscal,dy00);
240             tz               = _mm_mul_ps(fscal,dz00);
241
242             /* Update vectorial force */
243             fix0             = _mm_add_ps(fix0,tx);
244             fiy0             = _mm_add_ps(fiy0,ty);
245             fiz0             = _mm_add_ps(fiz0,tz);
246
247             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
248                                                    f+j_coord_offsetC,f+j_coord_offsetD,
249                                                    tx,ty,tz);
250
251             /* Inner loop uses 53 flops */
252         }
253
254         if(jidx<j_index_end)
255         {
256
257             /* Get j neighbor index, and coordinate index */
258             jnrA             = jjnr[jidx];
259             jnrB             = jjnr[jidx+1];
260             jnrC             = jjnr[jidx+2];
261             jnrD             = jjnr[jidx+3];
262
263             /* Sign of each element will be negative for non-real atoms.
264              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
265              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
266              */
267             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
268             jnrA       = (jnrA>=0) ? jnrA : 0;
269             jnrB       = (jnrB>=0) ? jnrB : 0;
270             jnrC       = (jnrC>=0) ? jnrC : 0;
271             jnrD       = (jnrD>=0) ? jnrD : 0;
272
273             j_coord_offsetA  = DIM*jnrA;
274             j_coord_offsetB  = DIM*jnrB;
275             j_coord_offsetC  = DIM*jnrC;
276             j_coord_offsetD  = DIM*jnrD;
277
278             /* load j atom coordinates */
279             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
280                                               x+j_coord_offsetC,x+j_coord_offsetD,
281                                               &jx0,&jy0,&jz0);
282
283             /* Calculate displacement vector */
284             dx00             = _mm_sub_ps(ix0,jx0);
285             dy00             = _mm_sub_ps(iy0,jy0);
286             dz00             = _mm_sub_ps(iz0,jz0);
287
288             /* Calculate squared distance and things based on it */
289             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
290
291             rinv00           = gmx_mm_invsqrt_ps(rsq00);
292
293             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
294
295             /* Load parameters for j particles */
296             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
297                                                               charge+jnrC+0,charge+jnrD+0);
298             vdwjidx0A        = 2*vdwtype[jnrA+0];
299             vdwjidx0B        = 2*vdwtype[jnrB+0];
300             vdwjidx0C        = 2*vdwtype[jnrC+0];
301             vdwjidx0D        = 2*vdwtype[jnrD+0];
302
303             /**************************
304              * CALCULATE INTERACTIONS *
305              **************************/
306
307             r00              = _mm_mul_ps(rsq00,rinv00);
308             r00              = _mm_andnot_ps(dummy_mask,r00);
309
310             /* Compute parameters for interactions between i and j atoms */
311             qq00             = _mm_mul_ps(iq0,jq0);
312             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
313                                          vdwparam+vdwioffset0+vdwjidx0B,
314                                          vdwparam+vdwioffset0+vdwjidx0C,
315                                          vdwparam+vdwioffset0+vdwjidx0D,
316                                          &c6_00,&c12_00);
317
318             /* EWALD ELECTROSTATICS */
319
320             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
321             ewrt             = _mm_mul_ps(r00,ewtabscale);
322             ewitab           = _mm_cvttps_epi32(ewrt);
323             eweps            = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
324             ewitab           = _mm_slli_epi32(ewitab,2);
325             ewtabF           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,0) );
326             ewtabD           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,1) );
327             ewtabV           = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,2) );
328             ewtabFn          = _mm_load_ps( ewtab + gmx_mm_extract_epi32(ewitab,3) );
329             _MM_TRANSPOSE4_PS(ewtabF,ewtabD,ewtabV,ewtabFn);
330             felec            = _mm_add_ps(ewtabF,_mm_mul_ps(eweps,ewtabD));
331             velec            = _mm_sub_ps(ewtabV,_mm_mul_ps(_mm_mul_ps(ewtabhalfspace,eweps),_mm_add_ps(ewtabF,felec)));
332             velec            = _mm_mul_ps(qq00,_mm_sub_ps(rinv00,velec));
333             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
334
335             /* LENNARD-JONES DISPERSION/REPULSION */
336
337             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
338             vvdw6            = _mm_mul_ps(c6_00,rinvsix);
339             vvdw12           = _mm_mul_ps(c12_00,_mm_mul_ps(rinvsix,rinvsix));
340             vvdw             = _mm_sub_ps( _mm_mul_ps(vvdw12,one_twelfth) , _mm_mul_ps(vvdw6,one_sixth) );
341             fvdw             = _mm_mul_ps(_mm_sub_ps(vvdw12,vvdw6),rinvsq00);
342
343             /* Update potential sum for this i atom from the interaction with this j atom. */
344             velec            = _mm_andnot_ps(dummy_mask,velec);
345             velecsum         = _mm_add_ps(velecsum,velec);
346             vvdw             = _mm_andnot_ps(dummy_mask,vvdw);
347             vvdwsum          = _mm_add_ps(vvdwsum,vvdw);
348
349             fscal            = _mm_add_ps(felec,fvdw);
350
351             fscal            = _mm_andnot_ps(dummy_mask,fscal);
352
353             /* Calculate temporary vectorial force */
354             tx               = _mm_mul_ps(fscal,dx00);
355             ty               = _mm_mul_ps(fscal,dy00);
356             tz               = _mm_mul_ps(fscal,dz00);
357
358             /* Update vectorial force */
359             fix0             = _mm_add_ps(fix0,tx);
360             fiy0             = _mm_add_ps(fiy0,ty);
361             fiz0             = _mm_add_ps(fiz0,tz);
362
363             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
364                                                    f+j_coord_offsetC,f+j_coord_offsetD,
365                                                    tx,ty,tz);
366
367             /* Inner loop uses 54 flops */
368         }
369
370         /* End of innermost loop */
371
372         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
373                                               f+i_coord_offset,fshift+i_shift_offset);
374
375         ggid                        = gid[iidx];
376         /* Update potential energies */
377         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
378         gmx_mm_update_1pot_ps(vvdwsum,kernel_data->energygrp_vdw+ggid);
379
380         /* Increment number of inner iterations */
381         inneriter                  += j_index_end - j_index_start;
382
383         /* Outer loop uses 12 flops */
384     }
385
386     /* Increment number of outer iterations */
387     outeriter        += nri;
388
389     /* Update outer/inner flops */
390
391     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*12 + inneriter*54);
392 }
393 /*
394  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomP1P1_F_sse2_single
395  * Electrostatics interaction: Ewald
396  * VdW interaction:            LennardJones
397  * Geometry:                   Particle-Particle
398  * Calculate force/pot:        Force
399  */
400 void
401 nb_kernel_ElecEw_VdwLJ_GeomP1P1_F_sse2_single
402                     (t_nblist * gmx_restrict                nlist,
403                      rvec * gmx_restrict                    xx,
404                      rvec * gmx_restrict                    ff,
405                      t_forcerec * gmx_restrict              fr,
406                      t_mdatoms * gmx_restrict               mdatoms,
407                      nb_kernel_data_t * gmx_restrict        kernel_data,
408                      t_nrnb * gmx_restrict                  nrnb)
409 {
410     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or 
411      * just 0 for non-waters.
412      * Suffixes A,B,C,D refer to j loop unrolling done with SSE, e.g. for the four different
413      * jnr indices corresponding to data put in the four positions in the SIMD register.
414      */
415     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
416     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
417     int              jnrA,jnrB,jnrC,jnrD;
418     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
419     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
420     real             shX,shY,shZ,rcutoff_scalar;
421     real             *shiftvec,*fshift,*x,*f;
422     __m128           tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
423     int              vdwioffset0;
424     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
425     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
426     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
427     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
428     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
429     real             *charge;
430     int              nvdwtype;
431     __m128           rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
432     int              *vdwtype;
433     real             *vdwparam;
434     __m128           one_sixth   = _mm_set1_ps(1.0/6.0);
435     __m128           one_twelfth = _mm_set1_ps(1.0/12.0);
436     __m128i          ewitab;
437     __m128           ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
438     real             *ewtab;
439     __m128           dummy_mask,cutoff_mask;
440     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
441     __m128           one     = _mm_set1_ps(1.0);
442     __m128           two     = _mm_set1_ps(2.0);
443     x                = xx[0];
444     f                = ff[0];
445
446     nri              = nlist->nri;
447     iinr             = nlist->iinr;
448     jindex           = nlist->jindex;
449     jjnr             = nlist->jjnr;
450     shiftidx         = nlist->shift;
451     gid              = nlist->gid;
452     shiftvec         = fr->shift_vec[0];
453     fshift           = fr->fshift[0];
454     facel            = _mm_set1_ps(fr->epsfac);
455     charge           = mdatoms->chargeA;
456     nvdwtype         = fr->ntype;
457     vdwparam         = fr->nbfp;
458     vdwtype          = mdatoms->typeA;
459
460     sh_ewald         = _mm_set1_ps(fr->ic->sh_ewald);
461     ewtab            = fr->ic->tabq_coul_F;
462     ewtabscale       = _mm_set1_ps(fr->ic->tabq_scale);
463     ewtabhalfspace   = _mm_set1_ps(0.5/fr->ic->tabq_scale);
464
465     /* Avoid stupid compiler warnings */
466     jnrA = jnrB = jnrC = jnrD = 0;
467     j_coord_offsetA = 0;
468     j_coord_offsetB = 0;
469     j_coord_offsetC = 0;
470     j_coord_offsetD = 0;
471
472     outeriter        = 0;
473     inneriter        = 0;
474
475     /* Start outer loop over neighborlists */
476     for(iidx=0; iidx<nri; iidx++)
477     {
478         /* Load shift vector for this list */
479         i_shift_offset   = DIM*shiftidx[iidx];
480         shX              = shiftvec[i_shift_offset+XX];
481         shY              = shiftvec[i_shift_offset+YY];
482         shZ              = shiftvec[i_shift_offset+ZZ];
483
484         /* Load limits for loop over neighbors */
485         j_index_start    = jindex[iidx];
486         j_index_end      = jindex[iidx+1];
487
488         /* Get outer coordinate index */
489         inr              = iinr[iidx];
490         i_coord_offset   = DIM*inr;
491
492         /* Load i particle coords and add shift vector */
493         ix0              = _mm_set1_ps(shX + x[i_coord_offset+DIM*0+XX]);
494         iy0              = _mm_set1_ps(shY + x[i_coord_offset+DIM*0+YY]);
495         iz0              = _mm_set1_ps(shZ + x[i_coord_offset+DIM*0+ZZ]);
496
497         fix0             = _mm_setzero_ps();
498         fiy0             = _mm_setzero_ps();
499         fiz0             = _mm_setzero_ps();
500
501         /* Load parameters for i particles */
502         iq0              = _mm_mul_ps(facel,_mm_load1_ps(charge+inr+0));
503         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
504
505         /* Start inner kernel loop */
506         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
507         {
508
509             /* Get j neighbor index, and coordinate index */
510             jnrA             = jjnr[jidx];
511             jnrB             = jjnr[jidx+1];
512             jnrC             = jjnr[jidx+2];
513             jnrD             = jjnr[jidx+3];
514
515             j_coord_offsetA  = DIM*jnrA;
516             j_coord_offsetB  = DIM*jnrB;
517             j_coord_offsetC  = DIM*jnrC;
518             j_coord_offsetD  = DIM*jnrD;
519
520             /* load j atom coordinates */
521             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
522                                               x+j_coord_offsetC,x+j_coord_offsetD,
523                                               &jx0,&jy0,&jz0);
524
525             /* Calculate displacement vector */
526             dx00             = _mm_sub_ps(ix0,jx0);
527             dy00             = _mm_sub_ps(iy0,jy0);
528             dz00             = _mm_sub_ps(iz0,jz0);
529
530             /* Calculate squared distance and things based on it */
531             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
532
533             rinv00           = gmx_mm_invsqrt_ps(rsq00);
534
535             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
536
537             /* Load parameters for j particles */
538             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
539                                                               charge+jnrC+0,charge+jnrD+0);
540             vdwjidx0A        = 2*vdwtype[jnrA+0];
541             vdwjidx0B        = 2*vdwtype[jnrB+0];
542             vdwjidx0C        = 2*vdwtype[jnrC+0];
543             vdwjidx0D        = 2*vdwtype[jnrD+0];
544
545             /**************************
546              * CALCULATE INTERACTIONS *
547              **************************/
548
549             r00              = _mm_mul_ps(rsq00,rinv00);
550
551             /* Compute parameters for interactions between i and j atoms */
552             qq00             = _mm_mul_ps(iq0,jq0);
553             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
554                                          vdwparam+vdwioffset0+vdwjidx0B,
555                                          vdwparam+vdwioffset0+vdwjidx0C,
556                                          vdwparam+vdwioffset0+vdwjidx0D,
557                                          &c6_00,&c12_00);
558
559             /* EWALD ELECTROSTATICS */
560
561             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
562             ewrt             = _mm_mul_ps(r00,ewtabscale);
563             ewitab           = _mm_cvttps_epi32(ewrt);
564             eweps            = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
565             gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
566                                          ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
567                                          &ewtabF,&ewtabFn);
568             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
569             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
570
571             /* LENNARD-JONES DISPERSION/REPULSION */
572
573             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
574             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
575
576             fscal            = _mm_add_ps(felec,fvdw);
577
578             /* Calculate temporary vectorial force */
579             tx               = _mm_mul_ps(fscal,dx00);
580             ty               = _mm_mul_ps(fscal,dy00);
581             tz               = _mm_mul_ps(fscal,dz00);
582
583             /* Update vectorial force */
584             fix0             = _mm_add_ps(fix0,tx);
585             fiy0             = _mm_add_ps(fiy0,ty);
586             fiz0             = _mm_add_ps(fiz0,tz);
587
588             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
589                                                    f+j_coord_offsetC,f+j_coord_offsetD,
590                                                    tx,ty,tz);
591
592             /* Inner loop uses 43 flops */
593         }
594
595         if(jidx<j_index_end)
596         {
597
598             /* Get j neighbor index, and coordinate index */
599             jnrA             = jjnr[jidx];
600             jnrB             = jjnr[jidx+1];
601             jnrC             = jjnr[jidx+2];
602             jnrD             = jjnr[jidx+3];
603
604             /* Sign of each element will be negative for non-real atoms.
605              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
606              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
607              */
608             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
609             jnrA       = (jnrA>=0) ? jnrA : 0;
610             jnrB       = (jnrB>=0) ? jnrB : 0;
611             jnrC       = (jnrC>=0) ? jnrC : 0;
612             jnrD       = (jnrD>=0) ? jnrD : 0;
613
614             j_coord_offsetA  = DIM*jnrA;
615             j_coord_offsetB  = DIM*jnrB;
616             j_coord_offsetC  = DIM*jnrC;
617             j_coord_offsetD  = DIM*jnrD;
618
619             /* load j atom coordinates */
620             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
621                                               x+j_coord_offsetC,x+j_coord_offsetD,
622                                               &jx0,&jy0,&jz0);
623
624             /* Calculate displacement vector */
625             dx00             = _mm_sub_ps(ix0,jx0);
626             dy00             = _mm_sub_ps(iy0,jy0);
627             dz00             = _mm_sub_ps(iz0,jz0);
628
629             /* Calculate squared distance and things based on it */
630             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
631
632             rinv00           = gmx_mm_invsqrt_ps(rsq00);
633
634             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
635
636             /* Load parameters for j particles */
637             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
638                                                               charge+jnrC+0,charge+jnrD+0);
639             vdwjidx0A        = 2*vdwtype[jnrA+0];
640             vdwjidx0B        = 2*vdwtype[jnrB+0];
641             vdwjidx0C        = 2*vdwtype[jnrC+0];
642             vdwjidx0D        = 2*vdwtype[jnrD+0];
643
644             /**************************
645              * CALCULATE INTERACTIONS *
646              **************************/
647
648             r00              = _mm_mul_ps(rsq00,rinv00);
649             r00              = _mm_andnot_ps(dummy_mask,r00);
650
651             /* Compute parameters for interactions between i and j atoms */
652             qq00             = _mm_mul_ps(iq0,jq0);
653             gmx_mm_load_4pair_swizzle_ps(vdwparam+vdwioffset0+vdwjidx0A,
654                                          vdwparam+vdwioffset0+vdwjidx0B,
655                                          vdwparam+vdwioffset0+vdwjidx0C,
656                                          vdwparam+vdwioffset0+vdwjidx0D,
657                                          &c6_00,&c12_00);
658
659             /* EWALD ELECTROSTATICS */
660
661             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
662             ewrt             = _mm_mul_ps(r00,ewtabscale);
663             ewitab           = _mm_cvttps_epi32(ewrt);
664             eweps            = _mm_sub_ps(ewrt,_mm_cvtepi32_ps(ewitab));
665             gmx_mm_load_4pair_swizzle_ps(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
666                                          ewtab+gmx_mm_extract_epi32(ewitab,2),ewtab+gmx_mm_extract_epi32(ewitab,3),
667                                          &ewtabF,&ewtabFn);
668             felec            = _mm_add_ps(_mm_mul_ps( _mm_sub_ps(one,eweps),ewtabF),_mm_mul_ps(eweps,ewtabFn));
669             felec            = _mm_mul_ps(_mm_mul_ps(qq00,rinv00),_mm_sub_ps(rinvsq00,felec));
670
671             /* LENNARD-JONES DISPERSION/REPULSION */
672
673             rinvsix          = _mm_mul_ps(_mm_mul_ps(rinvsq00,rinvsq00),rinvsq00);
674             fvdw             = _mm_mul_ps(_mm_sub_ps(_mm_mul_ps(c12_00,rinvsix),c6_00),_mm_mul_ps(rinvsix,rinvsq00));
675
676             fscal            = _mm_add_ps(felec,fvdw);
677
678             fscal            = _mm_andnot_ps(dummy_mask,fscal);
679
680             /* Calculate temporary vectorial force */
681             tx               = _mm_mul_ps(fscal,dx00);
682             ty               = _mm_mul_ps(fscal,dy00);
683             tz               = _mm_mul_ps(fscal,dz00);
684
685             /* Update vectorial force */
686             fix0             = _mm_add_ps(fix0,tx);
687             fiy0             = _mm_add_ps(fiy0,ty);
688             fiz0             = _mm_add_ps(fiz0,tz);
689
690             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(f+j_coord_offsetA,f+j_coord_offsetB,
691                                                    f+j_coord_offsetC,f+j_coord_offsetD,
692                                                    tx,ty,tz);
693
694             /* Inner loop uses 44 flops */
695         }
696
697         /* End of innermost loop */
698
699         gmx_mm_update_iforce_1atom_swizzle_ps(fix0,fiy0,fiz0,
700                                               f+i_coord_offset,fshift+i_shift_offset);
701
702         /* Increment number of inner iterations */
703         inneriter                  += j_index_end - j_index_start;
704
705         /* Outer loop uses 10 flops */
706     }
707
708     /* Increment number of outer iterations */
709     outeriter        += nri;
710
711     /* Update outer/inner flops */
712
713     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*10 + inneriter*44);
714 }