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