d4f752829d6f7d6db1b66736b25e7a5ecfa1c897
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_sse2_double / nb_kernel_ElecEw_VdwLJ_GeomP1P1_sse2_double.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 sse2_double kernel generator.
37  */
38 #include "config.h"
39
40 #include <math.h>
41
42 #include "../nb_kernel.h"
43 #include "types/simple.h"
44 #include "gromacs/math/vec.h"
45 #include "nrnb.h"
46
47 #include "gromacs/simd/math_x86_sse2_double.h"
48 #include "kernelutil_x86_sse2_double.h"
49
50 /*
51  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomP1P1_VF_sse2_double
52  * Electrostatics interaction: Ewald
53  * VdW interaction:            LennardJones
54  * Geometry:                   Particle-Particle
55  * Calculate force/pot:        PotentialAndForce
56  */
57 void
58 nb_kernel_ElecEw_VdwLJ_GeomP1P1_VF_sse2_double
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 refer to j loop unrolling done with SSE double precision, e.g. for the two 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;
75     int              j_coord_offsetA,j_coord_offsetB;
76     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
77     real             rcutoff_scalar;
78     real             *shiftvec,*fshift,*x,*f;
79     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
80     int              vdwioffset0;
81     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
82     int              vdwjidx0A,vdwjidx0B;
83     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
84     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
85     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
86     real             *charge;
87     int              nvdwtype;
88     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
89     int              *vdwtype;
90     real             *vdwparam;
91     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
92     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
93     __m128i          ewitab;
94     __m128d          ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
95     real             *ewtab;
96     __m128d          dummy_mask,cutoff_mask;
97     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
98     __m128d          one     = _mm_set1_pd(1.0);
99     __m128d          two     = _mm_set1_pd(2.0);
100     x                = xx[0];
101     f                = ff[0];
102
103     nri              = nlist->nri;
104     iinr             = nlist->iinr;
105     jindex           = nlist->jindex;
106     jjnr             = nlist->jjnr;
107     shiftidx         = nlist->shift;
108     gid              = nlist->gid;
109     shiftvec         = fr->shift_vec[0];
110     fshift           = fr->fshift[0];
111     facel            = _mm_set1_pd(fr->epsfac);
112     charge           = mdatoms->chargeA;
113     nvdwtype         = fr->ntype;
114     vdwparam         = fr->nbfp;
115     vdwtype          = mdatoms->typeA;
116
117     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
118     ewtab            = fr->ic->tabq_coul_FDV0;
119     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
120     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
121
122     /* Avoid stupid compiler warnings */
123     jnrA = jnrB = 0;
124     j_coord_offsetA = 0;
125     j_coord_offsetB = 0;
126
127     outeriter        = 0;
128     inneriter        = 0;
129
130     /* Start outer loop over neighborlists */
131     for(iidx=0; iidx<nri; iidx++)
132     {
133         /* Load shift vector for this list */
134         i_shift_offset   = DIM*shiftidx[iidx];
135
136         /* Load limits for loop over neighbors */
137         j_index_start    = jindex[iidx];
138         j_index_end      = jindex[iidx+1];
139
140         /* Get outer coordinate index */
141         inr              = iinr[iidx];
142         i_coord_offset   = DIM*inr;
143
144         /* Load i particle coords and add shift vector */
145         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
146
147         fix0             = _mm_setzero_pd();
148         fiy0             = _mm_setzero_pd();
149         fiz0             = _mm_setzero_pd();
150
151         /* Load parameters for i particles */
152         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
153         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
154
155         /* Reset potential sums */
156         velecsum         = _mm_setzero_pd();
157         vvdwsum          = _mm_setzero_pd();
158
159         /* Start inner kernel loop */
160         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
161         {
162
163             /* Get j neighbor index, and coordinate index */
164             jnrA             = jjnr[jidx];
165             jnrB             = jjnr[jidx+1];
166             j_coord_offsetA  = DIM*jnrA;
167             j_coord_offsetB  = DIM*jnrB;
168
169             /* load j atom coordinates */
170             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
171                                               &jx0,&jy0,&jz0);
172
173             /* Calculate displacement vector */
174             dx00             = _mm_sub_pd(ix0,jx0);
175             dy00             = _mm_sub_pd(iy0,jy0);
176             dz00             = _mm_sub_pd(iz0,jz0);
177
178             /* Calculate squared distance and things based on it */
179             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
180
181             rinv00           = gmx_mm_invsqrt_pd(rsq00);
182
183             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
184
185             /* Load parameters for j particles */
186             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
187             vdwjidx0A        = 2*vdwtype[jnrA+0];
188             vdwjidx0B        = 2*vdwtype[jnrB+0];
189
190             /**************************
191              * CALCULATE INTERACTIONS *
192              **************************/
193
194             r00              = _mm_mul_pd(rsq00,rinv00);
195
196             /* Compute parameters for interactions between i and j atoms */
197             qq00             = _mm_mul_pd(iq0,jq0);
198             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
199                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
200
201             /* EWALD ELECTROSTATICS */
202
203             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
204             ewrt             = _mm_mul_pd(r00,ewtabscale);
205             ewitab           = _mm_cvttpd_epi32(ewrt);
206             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
207             ewitab           = _mm_slli_epi32(ewitab,2);
208             ewtabF           = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
209             ewtabD           = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,1) );
210             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
211             ewtabV           = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
212             ewtabFn          = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,1) +2);
213             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
214             felec            = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
215             velec            = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
216             velec            = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
217             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
218
219             /* LENNARD-JONES DISPERSION/REPULSION */
220
221             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
222             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
223             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
224             vvdw             = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
225             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
226
227             /* Update potential sum for this i atom from the interaction with this j atom. */
228             velecsum         = _mm_add_pd(velecsum,velec);
229             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
230
231             fscal            = _mm_add_pd(felec,fvdw);
232
233             /* Calculate temporary vectorial force */
234             tx               = _mm_mul_pd(fscal,dx00);
235             ty               = _mm_mul_pd(fscal,dy00);
236             tz               = _mm_mul_pd(fscal,dz00);
237
238             /* Update vectorial force */
239             fix0             = _mm_add_pd(fix0,tx);
240             fiy0             = _mm_add_pd(fiy0,ty);
241             fiz0             = _mm_add_pd(fiz0,tz);
242
243             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
244
245             /* Inner loop uses 53 flops */
246         }
247
248         if(jidx<j_index_end)
249         {
250
251             jnrA             = jjnr[jidx];
252             j_coord_offsetA  = DIM*jnrA;
253
254             /* load j atom coordinates */
255             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
256                                               &jx0,&jy0,&jz0);
257
258             /* Calculate displacement vector */
259             dx00             = _mm_sub_pd(ix0,jx0);
260             dy00             = _mm_sub_pd(iy0,jy0);
261             dz00             = _mm_sub_pd(iz0,jz0);
262
263             /* Calculate squared distance and things based on it */
264             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
265
266             rinv00           = gmx_mm_invsqrt_pd(rsq00);
267
268             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
269
270             /* Load parameters for j particles */
271             jq0              = _mm_load_sd(charge+jnrA+0);
272             vdwjidx0A        = 2*vdwtype[jnrA+0];
273
274             /**************************
275              * CALCULATE INTERACTIONS *
276              **************************/
277
278             r00              = _mm_mul_pd(rsq00,rinv00);
279
280             /* Compute parameters for interactions between i and j atoms */
281             qq00             = _mm_mul_pd(iq0,jq0);
282             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
283
284             /* EWALD ELECTROSTATICS */
285
286             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
287             ewrt             = _mm_mul_pd(r00,ewtabscale);
288             ewitab           = _mm_cvttpd_epi32(ewrt);
289             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
290             ewitab           = _mm_slli_epi32(ewitab,2);
291             ewtabF           = _mm_load_pd( ewtab + gmx_mm_extract_epi32(ewitab,0) );
292             ewtabD           = _mm_setzero_pd();
293             GMX_MM_TRANSPOSE2_PD(ewtabF,ewtabD);
294             ewtabV           = _mm_load_sd( ewtab + gmx_mm_extract_epi32(ewitab,0) +2);
295             ewtabFn          = _mm_setzero_pd();
296             GMX_MM_TRANSPOSE2_PD(ewtabV,ewtabFn);
297             felec            = _mm_add_pd(ewtabF,_mm_mul_pd(eweps,ewtabD));
298             velec            = _mm_sub_pd(ewtabV,_mm_mul_pd(_mm_mul_pd(ewtabhalfspace,eweps),_mm_add_pd(ewtabF,felec)));
299             velec            = _mm_mul_pd(qq00,_mm_sub_pd(rinv00,velec));
300             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
301
302             /* LENNARD-JONES DISPERSION/REPULSION */
303
304             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
305             vvdw6            = _mm_mul_pd(c6_00,rinvsix);
306             vvdw12           = _mm_mul_pd(c12_00,_mm_mul_pd(rinvsix,rinvsix));
307             vvdw             = _mm_sub_pd( _mm_mul_pd(vvdw12,one_twelfth) , _mm_mul_pd(vvdw6,one_sixth) );
308             fvdw             = _mm_mul_pd(_mm_sub_pd(vvdw12,vvdw6),rinvsq00);
309
310             /* Update potential sum for this i atom from the interaction with this j atom. */
311             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
312             velecsum         = _mm_add_pd(velecsum,velec);
313             vvdw             = _mm_unpacklo_pd(vvdw,_mm_setzero_pd());
314             vvdwsum          = _mm_add_pd(vvdwsum,vvdw);
315
316             fscal            = _mm_add_pd(felec,fvdw);
317
318             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
319
320             /* Calculate temporary vectorial force */
321             tx               = _mm_mul_pd(fscal,dx00);
322             ty               = _mm_mul_pd(fscal,dy00);
323             tz               = _mm_mul_pd(fscal,dz00);
324
325             /* Update vectorial force */
326             fix0             = _mm_add_pd(fix0,tx);
327             fiy0             = _mm_add_pd(fiy0,ty);
328             fiz0             = _mm_add_pd(fiz0,tz);
329
330             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
331
332             /* Inner loop uses 53 flops */
333         }
334
335         /* End of innermost loop */
336
337         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
338                                               f+i_coord_offset,fshift+i_shift_offset);
339
340         ggid                        = gid[iidx];
341         /* Update potential energies */
342         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
343         gmx_mm_update_1pot_pd(vvdwsum,kernel_data->energygrp_vdw+ggid);
344
345         /* Increment number of inner iterations */
346         inneriter                  += j_index_end - j_index_start;
347
348         /* Outer loop uses 9 flops */
349     }
350
351     /* Increment number of outer iterations */
352     outeriter        += nri;
353
354     /* Update outer/inner flops */
355
356     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_VF,outeriter*9 + inneriter*53);
357 }
358 /*
359  * Gromacs nonbonded kernel:   nb_kernel_ElecEw_VdwLJ_GeomP1P1_F_sse2_double
360  * Electrostatics interaction: Ewald
361  * VdW interaction:            LennardJones
362  * Geometry:                   Particle-Particle
363  * Calculate force/pot:        Force
364  */
365 void
366 nb_kernel_ElecEw_VdwLJ_GeomP1P1_F_sse2_double
367                     (t_nblist                    * gmx_restrict       nlist,
368                      rvec                        * gmx_restrict          xx,
369                      rvec                        * gmx_restrict          ff,
370                      t_forcerec                  * gmx_restrict          fr,
371                      t_mdatoms                   * gmx_restrict     mdatoms,
372                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
373                      t_nrnb                      * gmx_restrict        nrnb)
374 {
375     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
376      * just 0 for non-waters.
377      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
378      * jnr indices corresponding to data put in the four positions in the SIMD register.
379      */
380     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
381     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
382     int              jnrA,jnrB;
383     int              j_coord_offsetA,j_coord_offsetB;
384     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
385     real             rcutoff_scalar;
386     real             *shiftvec,*fshift,*x,*f;
387     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
388     int              vdwioffset0;
389     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
390     int              vdwjidx0A,vdwjidx0B;
391     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
392     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
393     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
394     real             *charge;
395     int              nvdwtype;
396     __m128d          rinvsix,rvdw,vvdw,vvdw6,vvdw12,fvdw,fvdw6,fvdw12,vvdwsum,sh_vdw_invrcut6;
397     int              *vdwtype;
398     real             *vdwparam;
399     __m128d          one_sixth   = _mm_set1_pd(1.0/6.0);
400     __m128d          one_twelfth = _mm_set1_pd(1.0/12.0);
401     __m128i          ewitab;
402     __m128d          ewtabscale,eweps,sh_ewald,ewrt,ewtabhalfspace,ewtabF,ewtabFn,ewtabD,ewtabV;
403     real             *ewtab;
404     __m128d          dummy_mask,cutoff_mask;
405     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
406     __m128d          one     = _mm_set1_pd(1.0);
407     __m128d          two     = _mm_set1_pd(2.0);
408     x                = xx[0];
409     f                = ff[0];
410
411     nri              = nlist->nri;
412     iinr             = nlist->iinr;
413     jindex           = nlist->jindex;
414     jjnr             = nlist->jjnr;
415     shiftidx         = nlist->shift;
416     gid              = nlist->gid;
417     shiftvec         = fr->shift_vec[0];
418     fshift           = fr->fshift[0];
419     facel            = _mm_set1_pd(fr->epsfac);
420     charge           = mdatoms->chargeA;
421     nvdwtype         = fr->ntype;
422     vdwparam         = fr->nbfp;
423     vdwtype          = mdatoms->typeA;
424
425     sh_ewald         = _mm_set1_pd(fr->ic->sh_ewald);
426     ewtab            = fr->ic->tabq_coul_F;
427     ewtabscale       = _mm_set1_pd(fr->ic->tabq_scale);
428     ewtabhalfspace   = _mm_set1_pd(0.5/fr->ic->tabq_scale);
429
430     /* Avoid stupid compiler warnings */
431     jnrA = jnrB = 0;
432     j_coord_offsetA = 0;
433     j_coord_offsetB = 0;
434
435     outeriter        = 0;
436     inneriter        = 0;
437
438     /* Start outer loop over neighborlists */
439     for(iidx=0; iidx<nri; iidx++)
440     {
441         /* Load shift vector for this list */
442         i_shift_offset   = DIM*shiftidx[iidx];
443
444         /* Load limits for loop over neighbors */
445         j_index_start    = jindex[iidx];
446         j_index_end      = jindex[iidx+1];
447
448         /* Get outer coordinate index */
449         inr              = iinr[iidx];
450         i_coord_offset   = DIM*inr;
451
452         /* Load i particle coords and add shift vector */
453         gmx_mm_load_shift_and_1rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,&ix0,&iy0,&iz0);
454
455         fix0             = _mm_setzero_pd();
456         fiy0             = _mm_setzero_pd();
457         fiz0             = _mm_setzero_pd();
458
459         /* Load parameters for i particles */
460         iq0              = _mm_mul_pd(facel,_mm_load1_pd(charge+inr+0));
461         vdwioffset0      = 2*nvdwtype*vdwtype[inr+0];
462
463         /* Start inner kernel loop */
464         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
465         {
466
467             /* Get j neighbor index, and coordinate index */
468             jnrA             = jjnr[jidx];
469             jnrB             = jjnr[jidx+1];
470             j_coord_offsetA  = DIM*jnrA;
471             j_coord_offsetB  = DIM*jnrB;
472
473             /* load j atom coordinates */
474             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
475                                               &jx0,&jy0,&jz0);
476
477             /* Calculate displacement vector */
478             dx00             = _mm_sub_pd(ix0,jx0);
479             dy00             = _mm_sub_pd(iy0,jy0);
480             dz00             = _mm_sub_pd(iz0,jz0);
481
482             /* Calculate squared distance and things based on it */
483             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
484
485             rinv00           = gmx_mm_invsqrt_pd(rsq00);
486
487             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
488
489             /* Load parameters for j particles */
490             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
491             vdwjidx0A        = 2*vdwtype[jnrA+0];
492             vdwjidx0B        = 2*vdwtype[jnrB+0];
493
494             /**************************
495              * CALCULATE INTERACTIONS *
496              **************************/
497
498             r00              = _mm_mul_pd(rsq00,rinv00);
499
500             /* Compute parameters for interactions between i and j atoms */
501             qq00             = _mm_mul_pd(iq0,jq0);
502             gmx_mm_load_2pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,
503                                          vdwparam+vdwioffset0+vdwjidx0B,&c6_00,&c12_00);
504
505             /* EWALD ELECTROSTATICS */
506
507             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
508             ewrt             = _mm_mul_pd(r00,ewtabscale);
509             ewitab           = _mm_cvttpd_epi32(ewrt);
510             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
511             gmx_mm_load_2pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),ewtab+gmx_mm_extract_epi32(ewitab,1),
512                                          &ewtabF,&ewtabFn);
513             felec            = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
514             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
515
516             /* LENNARD-JONES DISPERSION/REPULSION */
517
518             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
519             fvdw             = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
520
521             fscal            = _mm_add_pd(felec,fvdw);
522
523             /* Calculate temporary vectorial force */
524             tx               = _mm_mul_pd(fscal,dx00);
525             ty               = _mm_mul_pd(fscal,dy00);
526             tz               = _mm_mul_pd(fscal,dz00);
527
528             /* Update vectorial force */
529             fix0             = _mm_add_pd(fix0,tx);
530             fiy0             = _mm_add_pd(fiy0,ty);
531             fiz0             = _mm_add_pd(fiz0,tz);
532
533             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,tx,ty,tz);
534
535             /* Inner loop uses 43 flops */
536         }
537
538         if(jidx<j_index_end)
539         {
540
541             jnrA             = jjnr[jidx];
542             j_coord_offsetA  = DIM*jnrA;
543
544             /* load j atom coordinates */
545             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
546                                               &jx0,&jy0,&jz0);
547
548             /* Calculate displacement vector */
549             dx00             = _mm_sub_pd(ix0,jx0);
550             dy00             = _mm_sub_pd(iy0,jy0);
551             dz00             = _mm_sub_pd(iz0,jz0);
552
553             /* Calculate squared distance and things based on it */
554             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
555
556             rinv00           = gmx_mm_invsqrt_pd(rsq00);
557
558             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
559
560             /* Load parameters for j particles */
561             jq0              = _mm_load_sd(charge+jnrA+0);
562             vdwjidx0A        = 2*vdwtype[jnrA+0];
563
564             /**************************
565              * CALCULATE INTERACTIONS *
566              **************************/
567
568             r00              = _mm_mul_pd(rsq00,rinv00);
569
570             /* Compute parameters for interactions between i and j atoms */
571             qq00             = _mm_mul_pd(iq0,jq0);
572             gmx_mm_load_1pair_swizzle_pd(vdwparam+vdwioffset0+vdwjidx0A,&c6_00,&c12_00);
573
574             /* EWALD ELECTROSTATICS */
575
576             /* Calculate Ewald table index by multiplying r with scale and truncate to integer */
577             ewrt             = _mm_mul_pd(r00,ewtabscale);
578             ewitab           = _mm_cvttpd_epi32(ewrt);
579             eweps            = _mm_sub_pd(ewrt,_mm_cvtepi32_pd(ewitab));
580             gmx_mm_load_1pair_swizzle_pd(ewtab+gmx_mm_extract_epi32(ewitab,0),&ewtabF,&ewtabFn);
581             felec            = _mm_add_pd(_mm_mul_pd( _mm_sub_pd(one,eweps),ewtabF),_mm_mul_pd(eweps,ewtabFn));
582             felec            = _mm_mul_pd(_mm_mul_pd(qq00,rinv00),_mm_sub_pd(rinvsq00,felec));
583
584             /* LENNARD-JONES DISPERSION/REPULSION */
585
586             rinvsix          = _mm_mul_pd(_mm_mul_pd(rinvsq00,rinvsq00),rinvsq00);
587             fvdw             = _mm_mul_pd(_mm_sub_pd(_mm_mul_pd(c12_00,rinvsix),c6_00),_mm_mul_pd(rinvsix,rinvsq00));
588
589             fscal            = _mm_add_pd(felec,fvdw);
590
591             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
592
593             /* Calculate temporary vectorial force */
594             tx               = _mm_mul_pd(fscal,dx00);
595             ty               = _mm_mul_pd(fscal,dy00);
596             tz               = _mm_mul_pd(fscal,dz00);
597
598             /* Update vectorial force */
599             fix0             = _mm_add_pd(fix0,tx);
600             fiy0             = _mm_add_pd(fiy0,ty);
601             fiz0             = _mm_add_pd(fiz0,tz);
602
603             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,tx,ty,tz);
604
605             /* Inner loop uses 43 flops */
606         }
607
608         /* End of innermost loop */
609
610         gmx_mm_update_iforce_1atom_swizzle_pd(fix0,fiy0,fiz0,
611                                               f+i_coord_offset,fshift+i_shift_offset);
612
613         /* Increment number of inner iterations */
614         inneriter                  += j_index_end - j_index_start;
615
616         /* Outer loop uses 7 flops */
617     }
618
619     /* Increment number of outer iterations */
620     outeriter        += nri;
621
622     /* Update outer/inner flops */
623
624     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_VDW_F,outeriter*7 + inneriter*43);
625 }