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