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