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