Valgrind suppression for OS X 10.9
[alexxy/gromacs.git] / src / gromacs / gmxlib / nonbonded / nb_kernel_avx_128_fma_double / nb_kernel_ElecRFCut_VdwNone_GeomW3P1_avx_128_fma_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 avx_128_fma_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_avx_128_fma_double.h"
50 #include "kernelutil_x86_avx_128_fma_double.h"
51
52 /*
53  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_double
54  * Electrostatics interaction: ReactionField
55  * VdW interaction:            None
56  * Geometry:                   Water3-Particle
57  * Calculate force/pot:        PotentialAndForce
58  */
59 void
60 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_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              vdwioffset1;
85     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
86     int              vdwioffset2;
87     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
88     int              vdwjidx0A,vdwjidx0B;
89     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
90     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
91     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
92     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
93     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
94     real             *charge;
95     __m128d          dummy_mask,cutoff_mask;
96     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
97     __m128d          one     = _mm_set1_pd(1.0);
98     __m128d          two     = _mm_set1_pd(2.0);
99     x                = xx[0];
100     f                = ff[0];
101
102     nri              = nlist->nri;
103     iinr             = nlist->iinr;
104     jindex           = nlist->jindex;
105     jjnr             = nlist->jjnr;
106     shiftidx         = nlist->shift;
107     gid              = nlist->gid;
108     shiftvec         = fr->shift_vec[0];
109     fshift           = fr->fshift[0];
110     facel            = _mm_set1_pd(fr->epsfac);
111     charge           = mdatoms->chargeA;
112     krf              = _mm_set1_pd(fr->ic->k_rf);
113     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
114     crf              = _mm_set1_pd(fr->ic->c_rf);
115
116     /* Setup water-specific parameters */
117     inr              = nlist->iinr[0];
118     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
119     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
120     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
121
122     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
123     rcutoff_scalar   = fr->rcoulomb;
124     rcutoff          = _mm_set1_pd(rcutoff_scalar);
125     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
126
127     /* Avoid stupid compiler warnings */
128     jnrA = jnrB = 0;
129     j_coord_offsetA = 0;
130     j_coord_offsetB = 0;
131
132     outeriter        = 0;
133     inneriter        = 0;
134
135     /* Start outer loop over neighborlists */
136     for(iidx=0; iidx<nri; iidx++)
137     {
138         /* Load shift vector for this list */
139         i_shift_offset   = DIM*shiftidx[iidx];
140
141         /* Load limits for loop over neighbors */
142         j_index_start    = jindex[iidx];
143         j_index_end      = jindex[iidx+1];
144
145         /* Get outer coordinate index */
146         inr              = iinr[iidx];
147         i_coord_offset   = DIM*inr;
148
149         /* Load i particle coords and add shift vector */
150         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
151                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
152
153         fix0             = _mm_setzero_pd();
154         fiy0             = _mm_setzero_pd();
155         fiz0             = _mm_setzero_pd();
156         fix1             = _mm_setzero_pd();
157         fiy1             = _mm_setzero_pd();
158         fiz1             = _mm_setzero_pd();
159         fix2             = _mm_setzero_pd();
160         fiy2             = _mm_setzero_pd();
161         fiz2             = _mm_setzero_pd();
162
163         /* Reset potential sums */
164         velecsum         = _mm_setzero_pd();
165
166         /* Start inner kernel loop */
167         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
168         {
169
170             /* Get j neighbor index, and coordinate index */
171             jnrA             = jjnr[jidx];
172             jnrB             = jjnr[jidx+1];
173             j_coord_offsetA  = DIM*jnrA;
174             j_coord_offsetB  = DIM*jnrB;
175
176             /* load j atom coordinates */
177             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
178                                               &jx0,&jy0,&jz0);
179
180             /* Calculate displacement vector */
181             dx00             = _mm_sub_pd(ix0,jx0);
182             dy00             = _mm_sub_pd(iy0,jy0);
183             dz00             = _mm_sub_pd(iz0,jz0);
184             dx10             = _mm_sub_pd(ix1,jx0);
185             dy10             = _mm_sub_pd(iy1,jy0);
186             dz10             = _mm_sub_pd(iz1,jz0);
187             dx20             = _mm_sub_pd(ix2,jx0);
188             dy20             = _mm_sub_pd(iy2,jy0);
189             dz20             = _mm_sub_pd(iz2,jz0);
190
191             /* Calculate squared distance and things based on it */
192             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
193             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
194             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
195
196             rinv00           = gmx_mm_invsqrt_pd(rsq00);
197             rinv10           = gmx_mm_invsqrt_pd(rsq10);
198             rinv20           = gmx_mm_invsqrt_pd(rsq20);
199
200             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
201             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
202             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
203
204             /* Load parameters for j particles */
205             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
206
207             fjx0             = _mm_setzero_pd();
208             fjy0             = _mm_setzero_pd();
209             fjz0             = _mm_setzero_pd();
210
211             /**************************
212              * CALCULATE INTERACTIONS *
213              **************************/
214
215             if (gmx_mm_any_lt(rsq00,rcutoff2))
216             {
217
218             /* Compute parameters for interactions between i and j atoms */
219             qq00             = _mm_mul_pd(iq0,jq0);
220
221             /* REACTION-FIELD ELECTROSTATICS */
222             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
223             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
224
225             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
226
227             /* Update potential sum for this i atom from the interaction with this j atom. */
228             velec            = _mm_and_pd(velec,cutoff_mask);
229             velecsum         = _mm_add_pd(velecsum,velec);
230
231             fscal            = felec;
232
233             fscal            = _mm_and_pd(fscal,cutoff_mask);
234
235             /* Update vectorial force */
236             fix0             = _mm_macc_pd(dx00,fscal,fix0);
237             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
238             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
239             
240             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
241             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
242             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
243
244             }
245
246             /**************************
247              * CALCULATE INTERACTIONS *
248              **************************/
249
250             if (gmx_mm_any_lt(rsq10,rcutoff2))
251             {
252
253             /* Compute parameters for interactions between i and j atoms */
254             qq10             = _mm_mul_pd(iq1,jq0);
255
256             /* REACTION-FIELD ELECTROSTATICS */
257             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
258             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
259
260             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
261
262             /* Update potential sum for this i atom from the interaction with this j atom. */
263             velec            = _mm_and_pd(velec,cutoff_mask);
264             velecsum         = _mm_add_pd(velecsum,velec);
265
266             fscal            = felec;
267
268             fscal            = _mm_and_pd(fscal,cutoff_mask);
269
270             /* Update vectorial force */
271             fix1             = _mm_macc_pd(dx10,fscal,fix1);
272             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
273             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
274             
275             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
276             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
277             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
278
279             }
280
281             /**************************
282              * CALCULATE INTERACTIONS *
283              **************************/
284
285             if (gmx_mm_any_lt(rsq20,rcutoff2))
286             {
287
288             /* Compute parameters for interactions between i and j atoms */
289             qq20             = _mm_mul_pd(iq2,jq0);
290
291             /* REACTION-FIELD ELECTROSTATICS */
292             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
293             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
294
295             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
296
297             /* Update potential sum for this i atom from the interaction with this j atom. */
298             velec            = _mm_and_pd(velec,cutoff_mask);
299             velecsum         = _mm_add_pd(velecsum,velec);
300
301             fscal            = felec;
302
303             fscal            = _mm_and_pd(fscal,cutoff_mask);
304
305             /* Update vectorial force */
306             fix2             = _mm_macc_pd(dx20,fscal,fix2);
307             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
308             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
309             
310             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
311             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
312             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
313
314             }
315
316             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
317
318             /* Inner loop uses 120 flops */
319         }
320
321         if(jidx<j_index_end)
322         {
323
324             jnrA             = jjnr[jidx];
325             j_coord_offsetA  = DIM*jnrA;
326
327             /* load j atom coordinates */
328             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
329                                               &jx0,&jy0,&jz0);
330
331             /* Calculate displacement vector */
332             dx00             = _mm_sub_pd(ix0,jx0);
333             dy00             = _mm_sub_pd(iy0,jy0);
334             dz00             = _mm_sub_pd(iz0,jz0);
335             dx10             = _mm_sub_pd(ix1,jx0);
336             dy10             = _mm_sub_pd(iy1,jy0);
337             dz10             = _mm_sub_pd(iz1,jz0);
338             dx20             = _mm_sub_pd(ix2,jx0);
339             dy20             = _mm_sub_pd(iy2,jy0);
340             dz20             = _mm_sub_pd(iz2,jz0);
341
342             /* Calculate squared distance and things based on it */
343             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
344             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
345             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
346
347             rinv00           = gmx_mm_invsqrt_pd(rsq00);
348             rinv10           = gmx_mm_invsqrt_pd(rsq10);
349             rinv20           = gmx_mm_invsqrt_pd(rsq20);
350
351             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
352             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
353             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
354
355             /* Load parameters for j particles */
356             jq0              = _mm_load_sd(charge+jnrA+0);
357
358             fjx0             = _mm_setzero_pd();
359             fjy0             = _mm_setzero_pd();
360             fjz0             = _mm_setzero_pd();
361
362             /**************************
363              * CALCULATE INTERACTIONS *
364              **************************/
365
366             if (gmx_mm_any_lt(rsq00,rcutoff2))
367             {
368
369             /* Compute parameters for interactions between i and j atoms */
370             qq00             = _mm_mul_pd(iq0,jq0);
371
372             /* REACTION-FIELD ELECTROSTATICS */
373             velec            = _mm_mul_pd(qq00,_mm_sub_pd(_mm_macc_pd(krf,rsq00,rinv00),crf));
374             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
375
376             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
377
378             /* Update potential sum for this i atom from the interaction with this j atom. */
379             velec            = _mm_and_pd(velec,cutoff_mask);
380             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
381             velecsum         = _mm_add_pd(velecsum,velec);
382
383             fscal            = felec;
384
385             fscal            = _mm_and_pd(fscal,cutoff_mask);
386
387             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
388
389             /* Update vectorial force */
390             fix0             = _mm_macc_pd(dx00,fscal,fix0);
391             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
392             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
393             
394             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
395             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
396             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
397
398             }
399
400             /**************************
401              * CALCULATE INTERACTIONS *
402              **************************/
403
404             if (gmx_mm_any_lt(rsq10,rcutoff2))
405             {
406
407             /* Compute parameters for interactions between i and j atoms */
408             qq10             = _mm_mul_pd(iq1,jq0);
409
410             /* REACTION-FIELD ELECTROSTATICS */
411             velec            = _mm_mul_pd(qq10,_mm_sub_pd(_mm_macc_pd(krf,rsq10,rinv10),crf));
412             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
413
414             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
415
416             /* Update potential sum for this i atom from the interaction with this j atom. */
417             velec            = _mm_and_pd(velec,cutoff_mask);
418             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
419             velecsum         = _mm_add_pd(velecsum,velec);
420
421             fscal            = felec;
422
423             fscal            = _mm_and_pd(fscal,cutoff_mask);
424
425             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
426
427             /* Update vectorial force */
428             fix1             = _mm_macc_pd(dx10,fscal,fix1);
429             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
430             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
431             
432             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
433             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
434             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
435
436             }
437
438             /**************************
439              * CALCULATE INTERACTIONS *
440              **************************/
441
442             if (gmx_mm_any_lt(rsq20,rcutoff2))
443             {
444
445             /* Compute parameters for interactions between i and j atoms */
446             qq20             = _mm_mul_pd(iq2,jq0);
447
448             /* REACTION-FIELD ELECTROSTATICS */
449             velec            = _mm_mul_pd(qq20,_mm_sub_pd(_mm_macc_pd(krf,rsq20,rinv20),crf));
450             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
451
452             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
453
454             /* Update potential sum for this i atom from the interaction with this j atom. */
455             velec            = _mm_and_pd(velec,cutoff_mask);
456             velec            = _mm_unpacklo_pd(velec,_mm_setzero_pd());
457             velecsum         = _mm_add_pd(velecsum,velec);
458
459             fscal            = felec;
460
461             fscal            = _mm_and_pd(fscal,cutoff_mask);
462
463             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
464
465             /* Update vectorial force */
466             fix2             = _mm_macc_pd(dx20,fscal,fix2);
467             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
468             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
469             
470             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
471             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
472             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
473
474             }
475
476             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
477
478             /* Inner loop uses 120 flops */
479         }
480
481         /* End of innermost loop */
482
483         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
484                                               f+i_coord_offset,fshift+i_shift_offset);
485
486         ggid                        = gid[iidx];
487         /* Update potential energies */
488         gmx_mm_update_1pot_pd(velecsum,kernel_data->energygrp_elec+ggid);
489
490         /* Increment number of inner iterations */
491         inneriter                  += j_index_end - j_index_start;
492
493         /* Outer loop uses 19 flops */
494     }
495
496     /* Increment number of outer iterations */
497     outeriter        += nri;
498
499     /* Update outer/inner flops */
500
501     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*120);
502 }
503 /*
504  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_double
505  * Electrostatics interaction: ReactionField
506  * VdW interaction:            None
507  * Geometry:                   Water3-Particle
508  * Calculate force/pot:        Force
509  */
510 void
511 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_double
512                     (t_nblist                    * gmx_restrict       nlist,
513                      rvec                        * gmx_restrict          xx,
514                      rvec                        * gmx_restrict          ff,
515                      t_forcerec                  * gmx_restrict          fr,
516                      t_mdatoms                   * gmx_restrict     mdatoms,
517                      nb_kernel_data_t gmx_unused * gmx_restrict kernel_data,
518                      t_nrnb                      * gmx_restrict        nrnb)
519 {
520     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
521      * just 0 for non-waters.
522      * Suffixes A,B refer to j loop unrolling done with SSE double precision, e.g. for the two different
523      * jnr indices corresponding to data put in the four positions in the SIMD register.
524      */
525     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
526     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
527     int              jnrA,jnrB;
528     int              j_coord_offsetA,j_coord_offsetB;
529     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
530     real             rcutoff_scalar;
531     real             *shiftvec,*fshift,*x,*f;
532     __m128d          tx,ty,tz,fscal,rcutoff,rcutoff2,jidxall;
533     int              vdwioffset0;
534     __m128d          ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
535     int              vdwioffset1;
536     __m128d          ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
537     int              vdwioffset2;
538     __m128d          ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
539     int              vdwjidx0A,vdwjidx0B;
540     __m128d          jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
541     __m128d          dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
542     __m128d          dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
543     __m128d          dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
544     __m128d          velec,felec,velecsum,facel,crf,krf,krf2;
545     real             *charge;
546     __m128d          dummy_mask,cutoff_mask;
547     __m128d          signbit   = gmx_mm_castsi128_pd( _mm_set_epi32(0x80000000,0x00000000,0x80000000,0x00000000) );
548     __m128d          one     = _mm_set1_pd(1.0);
549     __m128d          two     = _mm_set1_pd(2.0);
550     x                = xx[0];
551     f                = ff[0];
552
553     nri              = nlist->nri;
554     iinr             = nlist->iinr;
555     jindex           = nlist->jindex;
556     jjnr             = nlist->jjnr;
557     shiftidx         = nlist->shift;
558     gid              = nlist->gid;
559     shiftvec         = fr->shift_vec[0];
560     fshift           = fr->fshift[0];
561     facel            = _mm_set1_pd(fr->epsfac);
562     charge           = mdatoms->chargeA;
563     krf              = _mm_set1_pd(fr->ic->k_rf);
564     krf2             = _mm_set1_pd(fr->ic->k_rf*2.0);
565     crf              = _mm_set1_pd(fr->ic->c_rf);
566
567     /* Setup water-specific parameters */
568     inr              = nlist->iinr[0];
569     iq0              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+0]));
570     iq1              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+1]));
571     iq2              = _mm_mul_pd(facel,_mm_set1_pd(charge[inr+2]));
572
573     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
574     rcutoff_scalar   = fr->rcoulomb;
575     rcutoff          = _mm_set1_pd(rcutoff_scalar);
576     rcutoff2         = _mm_mul_pd(rcutoff,rcutoff);
577
578     /* Avoid stupid compiler warnings */
579     jnrA = jnrB = 0;
580     j_coord_offsetA = 0;
581     j_coord_offsetB = 0;
582
583     outeriter        = 0;
584     inneriter        = 0;
585
586     /* Start outer loop over neighborlists */
587     for(iidx=0; iidx<nri; iidx++)
588     {
589         /* Load shift vector for this list */
590         i_shift_offset   = DIM*shiftidx[iidx];
591
592         /* Load limits for loop over neighbors */
593         j_index_start    = jindex[iidx];
594         j_index_end      = jindex[iidx+1];
595
596         /* Get outer coordinate index */
597         inr              = iinr[iidx];
598         i_coord_offset   = DIM*inr;
599
600         /* Load i particle coords and add shift vector */
601         gmx_mm_load_shift_and_3rvec_broadcast_pd(shiftvec+i_shift_offset,x+i_coord_offset,
602                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
603
604         fix0             = _mm_setzero_pd();
605         fiy0             = _mm_setzero_pd();
606         fiz0             = _mm_setzero_pd();
607         fix1             = _mm_setzero_pd();
608         fiy1             = _mm_setzero_pd();
609         fiz1             = _mm_setzero_pd();
610         fix2             = _mm_setzero_pd();
611         fiy2             = _mm_setzero_pd();
612         fiz2             = _mm_setzero_pd();
613
614         /* Start inner kernel loop */
615         for(jidx=j_index_start; jidx<j_index_end-1; jidx+=2)
616         {
617
618             /* Get j neighbor index, and coordinate index */
619             jnrA             = jjnr[jidx];
620             jnrB             = jjnr[jidx+1];
621             j_coord_offsetA  = DIM*jnrA;
622             j_coord_offsetB  = DIM*jnrB;
623
624             /* load j atom coordinates */
625             gmx_mm_load_1rvec_2ptr_swizzle_pd(x+j_coord_offsetA,x+j_coord_offsetB,
626                                               &jx0,&jy0,&jz0);
627
628             /* Calculate displacement vector */
629             dx00             = _mm_sub_pd(ix0,jx0);
630             dy00             = _mm_sub_pd(iy0,jy0);
631             dz00             = _mm_sub_pd(iz0,jz0);
632             dx10             = _mm_sub_pd(ix1,jx0);
633             dy10             = _mm_sub_pd(iy1,jy0);
634             dz10             = _mm_sub_pd(iz1,jz0);
635             dx20             = _mm_sub_pd(ix2,jx0);
636             dy20             = _mm_sub_pd(iy2,jy0);
637             dz20             = _mm_sub_pd(iz2,jz0);
638
639             /* Calculate squared distance and things based on it */
640             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
641             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
642             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
643
644             rinv00           = gmx_mm_invsqrt_pd(rsq00);
645             rinv10           = gmx_mm_invsqrt_pd(rsq10);
646             rinv20           = gmx_mm_invsqrt_pd(rsq20);
647
648             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
649             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
650             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
651
652             /* Load parameters for j particles */
653             jq0              = gmx_mm_load_2real_swizzle_pd(charge+jnrA+0,charge+jnrB+0);
654
655             fjx0             = _mm_setzero_pd();
656             fjy0             = _mm_setzero_pd();
657             fjz0             = _mm_setzero_pd();
658
659             /**************************
660              * CALCULATE INTERACTIONS *
661              **************************/
662
663             if (gmx_mm_any_lt(rsq00,rcutoff2))
664             {
665
666             /* Compute parameters for interactions between i and j atoms */
667             qq00             = _mm_mul_pd(iq0,jq0);
668
669             /* REACTION-FIELD ELECTROSTATICS */
670             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
671
672             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
673
674             fscal            = felec;
675
676             fscal            = _mm_and_pd(fscal,cutoff_mask);
677
678             /* Update vectorial force */
679             fix0             = _mm_macc_pd(dx00,fscal,fix0);
680             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
681             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
682             
683             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
684             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
685             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
686
687             }
688
689             /**************************
690              * CALCULATE INTERACTIONS *
691              **************************/
692
693             if (gmx_mm_any_lt(rsq10,rcutoff2))
694             {
695
696             /* Compute parameters for interactions between i and j atoms */
697             qq10             = _mm_mul_pd(iq1,jq0);
698
699             /* REACTION-FIELD ELECTROSTATICS */
700             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
701
702             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
703
704             fscal            = felec;
705
706             fscal            = _mm_and_pd(fscal,cutoff_mask);
707
708             /* Update vectorial force */
709             fix1             = _mm_macc_pd(dx10,fscal,fix1);
710             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
711             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
712             
713             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
714             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
715             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
716
717             }
718
719             /**************************
720              * CALCULATE INTERACTIONS *
721              **************************/
722
723             if (gmx_mm_any_lt(rsq20,rcutoff2))
724             {
725
726             /* Compute parameters for interactions between i and j atoms */
727             qq20             = _mm_mul_pd(iq2,jq0);
728
729             /* REACTION-FIELD ELECTROSTATICS */
730             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
731
732             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
733
734             fscal            = felec;
735
736             fscal            = _mm_and_pd(fscal,cutoff_mask);
737
738             /* Update vectorial force */
739             fix2             = _mm_macc_pd(dx20,fscal,fix2);
740             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
741             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
742             
743             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
744             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
745             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
746
747             }
748
749             gmx_mm_decrement_1rvec_2ptr_swizzle_pd(f+j_coord_offsetA,f+j_coord_offsetB,fjx0,fjy0,fjz0);
750
751             /* Inner loop uses 102 flops */
752         }
753
754         if(jidx<j_index_end)
755         {
756
757             jnrA             = jjnr[jidx];
758             j_coord_offsetA  = DIM*jnrA;
759
760             /* load j atom coordinates */
761             gmx_mm_load_1rvec_1ptr_swizzle_pd(x+j_coord_offsetA,
762                                               &jx0,&jy0,&jz0);
763
764             /* Calculate displacement vector */
765             dx00             = _mm_sub_pd(ix0,jx0);
766             dy00             = _mm_sub_pd(iy0,jy0);
767             dz00             = _mm_sub_pd(iz0,jz0);
768             dx10             = _mm_sub_pd(ix1,jx0);
769             dy10             = _mm_sub_pd(iy1,jy0);
770             dz10             = _mm_sub_pd(iz1,jz0);
771             dx20             = _mm_sub_pd(ix2,jx0);
772             dy20             = _mm_sub_pd(iy2,jy0);
773             dz20             = _mm_sub_pd(iz2,jz0);
774
775             /* Calculate squared distance and things based on it */
776             rsq00            = gmx_mm_calc_rsq_pd(dx00,dy00,dz00);
777             rsq10            = gmx_mm_calc_rsq_pd(dx10,dy10,dz10);
778             rsq20            = gmx_mm_calc_rsq_pd(dx20,dy20,dz20);
779
780             rinv00           = gmx_mm_invsqrt_pd(rsq00);
781             rinv10           = gmx_mm_invsqrt_pd(rsq10);
782             rinv20           = gmx_mm_invsqrt_pd(rsq20);
783
784             rinvsq00         = _mm_mul_pd(rinv00,rinv00);
785             rinvsq10         = _mm_mul_pd(rinv10,rinv10);
786             rinvsq20         = _mm_mul_pd(rinv20,rinv20);
787
788             /* Load parameters for j particles */
789             jq0              = _mm_load_sd(charge+jnrA+0);
790
791             fjx0             = _mm_setzero_pd();
792             fjy0             = _mm_setzero_pd();
793             fjz0             = _mm_setzero_pd();
794
795             /**************************
796              * CALCULATE INTERACTIONS *
797              **************************/
798
799             if (gmx_mm_any_lt(rsq00,rcutoff2))
800             {
801
802             /* Compute parameters for interactions between i and j atoms */
803             qq00             = _mm_mul_pd(iq0,jq0);
804
805             /* REACTION-FIELD ELECTROSTATICS */
806             felec            = _mm_mul_pd(qq00,_mm_msub_pd(rinv00,rinvsq00,krf2));
807
808             cutoff_mask      = _mm_cmplt_pd(rsq00,rcutoff2);
809
810             fscal            = felec;
811
812             fscal            = _mm_and_pd(fscal,cutoff_mask);
813
814             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
815
816             /* Update vectorial force */
817             fix0             = _mm_macc_pd(dx00,fscal,fix0);
818             fiy0             = _mm_macc_pd(dy00,fscal,fiy0);
819             fiz0             = _mm_macc_pd(dz00,fscal,fiz0);
820             
821             fjx0             = _mm_macc_pd(dx00,fscal,fjx0);
822             fjy0             = _mm_macc_pd(dy00,fscal,fjy0);
823             fjz0             = _mm_macc_pd(dz00,fscal,fjz0);
824
825             }
826
827             /**************************
828              * CALCULATE INTERACTIONS *
829              **************************/
830
831             if (gmx_mm_any_lt(rsq10,rcutoff2))
832             {
833
834             /* Compute parameters for interactions between i and j atoms */
835             qq10             = _mm_mul_pd(iq1,jq0);
836
837             /* REACTION-FIELD ELECTROSTATICS */
838             felec            = _mm_mul_pd(qq10,_mm_msub_pd(rinv10,rinvsq10,krf2));
839
840             cutoff_mask      = _mm_cmplt_pd(rsq10,rcutoff2);
841
842             fscal            = felec;
843
844             fscal            = _mm_and_pd(fscal,cutoff_mask);
845
846             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
847
848             /* Update vectorial force */
849             fix1             = _mm_macc_pd(dx10,fscal,fix1);
850             fiy1             = _mm_macc_pd(dy10,fscal,fiy1);
851             fiz1             = _mm_macc_pd(dz10,fscal,fiz1);
852             
853             fjx0             = _mm_macc_pd(dx10,fscal,fjx0);
854             fjy0             = _mm_macc_pd(dy10,fscal,fjy0);
855             fjz0             = _mm_macc_pd(dz10,fscal,fjz0);
856
857             }
858
859             /**************************
860              * CALCULATE INTERACTIONS *
861              **************************/
862
863             if (gmx_mm_any_lt(rsq20,rcutoff2))
864             {
865
866             /* Compute parameters for interactions between i and j atoms */
867             qq20             = _mm_mul_pd(iq2,jq0);
868
869             /* REACTION-FIELD ELECTROSTATICS */
870             felec            = _mm_mul_pd(qq20,_mm_msub_pd(rinv20,rinvsq20,krf2));
871
872             cutoff_mask      = _mm_cmplt_pd(rsq20,rcutoff2);
873
874             fscal            = felec;
875
876             fscal            = _mm_and_pd(fscal,cutoff_mask);
877
878             fscal            = _mm_unpacklo_pd(fscal,_mm_setzero_pd());
879
880             /* Update vectorial force */
881             fix2             = _mm_macc_pd(dx20,fscal,fix2);
882             fiy2             = _mm_macc_pd(dy20,fscal,fiy2);
883             fiz2             = _mm_macc_pd(dz20,fscal,fiz2);
884             
885             fjx0             = _mm_macc_pd(dx20,fscal,fjx0);
886             fjy0             = _mm_macc_pd(dy20,fscal,fjy0);
887             fjz0             = _mm_macc_pd(dz20,fscal,fjz0);
888
889             }
890
891             gmx_mm_decrement_1rvec_1ptr_swizzle_pd(f+j_coord_offsetA,fjx0,fjy0,fjz0);
892
893             /* Inner loop uses 102 flops */
894         }
895
896         /* End of innermost loop */
897
898         gmx_mm_update_iforce_3atom_swizzle_pd(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
899                                               f+i_coord_offset,fshift+i_shift_offset);
900
901         /* Increment number of inner iterations */
902         inneriter                  += j_index_end - j_index_start;
903
904         /* Outer loop uses 18 flops */
905     }
906
907     /* Increment number of outer iterations */
908     outeriter        += nri;
909
910     /* Update outer/inner flops */
911
912     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*102);
913 }