made errors during GPU detection non-fatal
[alexxy/gromacs.git] / src / gmxlib / nonbonded / nb_kernel_avx_128_fma_single / nb_kernel_ElecRFCut_VdwNone_GeomW3P1_avx_128_fma_single.c
1 /*
2  * Note: this file was generated by the Gromacs avx_128_fma_single 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_single.h"
34 #include "kernelutil_x86_avx_128_fma_single.h"
35
36 /*
37  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_single
38  * Electrostatics interaction: ReactionField
39  * VdW interaction:            None
40  * Geometry:                   Water3-Particle
41  * Calculate force/pot:        PotentialAndForce
42  */
43 void
44 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_VF_avx_128_fma_single
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,C,D refer to j loop unrolling done with AVX_128, e.g. for the four 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,jnrC,jnrD;
61     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
62     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
63     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
64     real             rcutoff_scalar;
65     real             *shiftvec,*fshift,*x,*f;
66     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
67     real             scratch[4*DIM];
68     __m128           fscal,rcutoff,rcutoff2,jidxall;
69     int              vdwioffset0;
70     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
71     int              vdwioffset1;
72     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
73     int              vdwioffset2;
74     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
75     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
76     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
77     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
78     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
79     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
80     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
81     real             *charge;
82     __m128           dummy_mask,cutoff_mask;
83     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
84     __m128           one     = _mm_set1_ps(1.0);
85     __m128           two     = _mm_set1_ps(2.0);
86     x                = xx[0];
87     f                = ff[0];
88
89     nri              = nlist->nri;
90     iinr             = nlist->iinr;
91     jindex           = nlist->jindex;
92     jjnr             = nlist->jjnr;
93     shiftidx         = nlist->shift;
94     gid              = nlist->gid;
95     shiftvec         = fr->shift_vec[0];
96     fshift           = fr->fshift[0];
97     facel            = _mm_set1_ps(fr->epsfac);
98     charge           = mdatoms->chargeA;
99     krf              = _mm_set1_ps(fr->ic->k_rf);
100     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
101     crf              = _mm_set1_ps(fr->ic->c_rf);
102
103     /* Setup water-specific parameters */
104     inr              = nlist->iinr[0];
105     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
106     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
107     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
108
109     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
110     rcutoff_scalar   = fr->rcoulomb;
111     rcutoff          = _mm_set1_ps(rcutoff_scalar);
112     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
113
114     /* Avoid stupid compiler warnings */
115     jnrA = jnrB = jnrC = jnrD = 0;
116     j_coord_offsetA = 0;
117     j_coord_offsetB = 0;
118     j_coord_offsetC = 0;
119     j_coord_offsetD = 0;
120
121     outeriter        = 0;
122     inneriter        = 0;
123
124     for(iidx=0;iidx<4*DIM;iidx++)
125     {
126         scratch[iidx] = 0.0;
127     }
128
129     /* Start outer loop over neighborlists */
130     for(iidx=0; iidx<nri; iidx++)
131     {
132         /* Load shift vector for this list */
133         i_shift_offset   = DIM*shiftidx[iidx];
134
135         /* Load limits for loop over neighbors */
136         j_index_start    = jindex[iidx];
137         j_index_end      = jindex[iidx+1];
138
139         /* Get outer coordinate index */
140         inr              = iinr[iidx];
141         i_coord_offset   = DIM*inr;
142
143         /* Load i particle coords and add shift vector */
144         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
145                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
146
147         fix0             = _mm_setzero_ps();
148         fiy0             = _mm_setzero_ps();
149         fiz0             = _mm_setzero_ps();
150         fix1             = _mm_setzero_ps();
151         fiy1             = _mm_setzero_ps();
152         fiz1             = _mm_setzero_ps();
153         fix2             = _mm_setzero_ps();
154         fiy2             = _mm_setzero_ps();
155         fiz2             = _mm_setzero_ps();
156
157         /* Reset potential sums */
158         velecsum         = _mm_setzero_ps();
159
160         /* Start inner kernel loop */
161         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
162         {
163
164             /* Get j neighbor index, and coordinate index */
165             jnrA             = jjnr[jidx];
166             jnrB             = jjnr[jidx+1];
167             jnrC             = jjnr[jidx+2];
168             jnrD             = jjnr[jidx+3];
169             j_coord_offsetA  = DIM*jnrA;
170             j_coord_offsetB  = DIM*jnrB;
171             j_coord_offsetC  = DIM*jnrC;
172             j_coord_offsetD  = DIM*jnrD;
173
174             /* load j atom coordinates */
175             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
176                                               x+j_coord_offsetC,x+j_coord_offsetD,
177                                               &jx0,&jy0,&jz0);
178
179             /* Calculate displacement vector */
180             dx00             = _mm_sub_ps(ix0,jx0);
181             dy00             = _mm_sub_ps(iy0,jy0);
182             dz00             = _mm_sub_ps(iz0,jz0);
183             dx10             = _mm_sub_ps(ix1,jx0);
184             dy10             = _mm_sub_ps(iy1,jy0);
185             dz10             = _mm_sub_ps(iz1,jz0);
186             dx20             = _mm_sub_ps(ix2,jx0);
187             dy20             = _mm_sub_ps(iy2,jy0);
188             dz20             = _mm_sub_ps(iz2,jz0);
189
190             /* Calculate squared distance and things based on it */
191             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
192             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
193             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
194
195             rinv00           = gmx_mm_invsqrt_ps(rsq00);
196             rinv10           = gmx_mm_invsqrt_ps(rsq10);
197             rinv20           = gmx_mm_invsqrt_ps(rsq20);
198
199             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
200             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
201             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
202
203             /* Load parameters for j particles */
204             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
205                                                               charge+jnrC+0,charge+jnrD+0);
206
207             fjx0             = _mm_setzero_ps();
208             fjy0             = _mm_setzero_ps();
209             fjz0             = _mm_setzero_ps();
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_ps(iq0,jq0);
220
221             /* REACTION-FIELD ELECTROSTATICS */
222             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
223             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
224
225             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
226
227             /* Update potential sum for this i atom from the interaction with this j atom. */
228             velec            = _mm_and_ps(velec,cutoff_mask);
229             velecsum         = _mm_add_ps(velecsum,velec);
230
231             fscal            = felec;
232
233             fscal            = _mm_and_ps(fscal,cutoff_mask);
234
235              /* Update vectorial force */
236             fix0             = _mm_macc_ps(dx00,fscal,fix0);
237             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
238             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
239
240             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
241             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
242             fjz0             = _mm_macc_ps(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_ps(iq1,jq0);
255
256             /* REACTION-FIELD ELECTROSTATICS */
257             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
258             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
259
260             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
261
262             /* Update potential sum for this i atom from the interaction with this j atom. */
263             velec            = _mm_and_ps(velec,cutoff_mask);
264             velecsum         = _mm_add_ps(velecsum,velec);
265
266             fscal            = felec;
267
268             fscal            = _mm_and_ps(fscal,cutoff_mask);
269
270              /* Update vectorial force */
271             fix1             = _mm_macc_ps(dx10,fscal,fix1);
272             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
273             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
274
275             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
276             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
277             fjz0             = _mm_macc_ps(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_ps(iq2,jq0);
290
291             /* REACTION-FIELD ELECTROSTATICS */
292             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
293             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
294
295             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
296
297             /* Update potential sum for this i atom from the interaction with this j atom. */
298             velec            = _mm_and_ps(velec,cutoff_mask);
299             velecsum         = _mm_add_ps(velecsum,velec);
300
301             fscal            = felec;
302
303             fscal            = _mm_and_ps(fscal,cutoff_mask);
304
305              /* Update vectorial force */
306             fix2             = _mm_macc_ps(dx20,fscal,fix2);
307             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
308             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
309
310             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
311             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
312             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
313
314             }
315
316             fjptrA             = f+j_coord_offsetA;
317             fjptrB             = f+j_coord_offsetB;
318             fjptrC             = f+j_coord_offsetC;
319             fjptrD             = f+j_coord_offsetD;
320
321             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
322
323             /* Inner loop uses 117 flops */
324         }
325
326         if(jidx<j_index_end)
327         {
328
329             /* Get j neighbor index, and coordinate index */
330             jnrlistA         = jjnr[jidx];
331             jnrlistB         = jjnr[jidx+1];
332             jnrlistC         = jjnr[jidx+2];
333             jnrlistD         = jjnr[jidx+3];
334             /* Sign of each element will be negative for non-real atoms.
335              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
336              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
337              */
338             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
339             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
340             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
341             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
342             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
343             j_coord_offsetA  = DIM*jnrA;
344             j_coord_offsetB  = DIM*jnrB;
345             j_coord_offsetC  = DIM*jnrC;
346             j_coord_offsetD  = DIM*jnrD;
347
348             /* load j atom coordinates */
349             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
350                                               x+j_coord_offsetC,x+j_coord_offsetD,
351                                               &jx0,&jy0,&jz0);
352
353             /* Calculate displacement vector */
354             dx00             = _mm_sub_ps(ix0,jx0);
355             dy00             = _mm_sub_ps(iy0,jy0);
356             dz00             = _mm_sub_ps(iz0,jz0);
357             dx10             = _mm_sub_ps(ix1,jx0);
358             dy10             = _mm_sub_ps(iy1,jy0);
359             dz10             = _mm_sub_ps(iz1,jz0);
360             dx20             = _mm_sub_ps(ix2,jx0);
361             dy20             = _mm_sub_ps(iy2,jy0);
362             dz20             = _mm_sub_ps(iz2,jz0);
363
364             /* Calculate squared distance and things based on it */
365             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
366             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
367             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
368
369             rinv00           = gmx_mm_invsqrt_ps(rsq00);
370             rinv10           = gmx_mm_invsqrt_ps(rsq10);
371             rinv20           = gmx_mm_invsqrt_ps(rsq20);
372
373             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
374             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
375             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
376
377             /* Load parameters for j particles */
378             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
379                                                               charge+jnrC+0,charge+jnrD+0);
380
381             fjx0             = _mm_setzero_ps();
382             fjy0             = _mm_setzero_ps();
383             fjz0             = _mm_setzero_ps();
384
385             /**************************
386              * CALCULATE INTERACTIONS *
387              **************************/
388
389             if (gmx_mm_any_lt(rsq00,rcutoff2))
390             {
391
392             /* Compute parameters for interactions between i and j atoms */
393             qq00             = _mm_mul_ps(iq0,jq0);
394
395             /* REACTION-FIELD ELECTROSTATICS */
396             velec            = _mm_mul_ps(qq00,_mm_sub_ps(_mm_macc_ps(krf,rsq00,rinv00),crf));
397             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
398
399             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
400
401             /* Update potential sum for this i atom from the interaction with this j atom. */
402             velec            = _mm_and_ps(velec,cutoff_mask);
403             velec            = _mm_andnot_ps(dummy_mask,velec);
404             velecsum         = _mm_add_ps(velecsum,velec);
405
406             fscal            = felec;
407
408             fscal            = _mm_and_ps(fscal,cutoff_mask);
409
410             fscal            = _mm_andnot_ps(dummy_mask,fscal);
411
412              /* Update vectorial force */
413             fix0             = _mm_macc_ps(dx00,fscal,fix0);
414             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
415             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
416
417             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
418             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
419             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
420
421             }
422
423             /**************************
424              * CALCULATE INTERACTIONS *
425              **************************/
426
427             if (gmx_mm_any_lt(rsq10,rcutoff2))
428             {
429
430             /* Compute parameters for interactions between i and j atoms */
431             qq10             = _mm_mul_ps(iq1,jq0);
432
433             /* REACTION-FIELD ELECTROSTATICS */
434             velec            = _mm_mul_ps(qq10,_mm_sub_ps(_mm_macc_ps(krf,rsq10,rinv10),crf));
435             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
436
437             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
438
439             /* Update potential sum for this i atom from the interaction with this j atom. */
440             velec            = _mm_and_ps(velec,cutoff_mask);
441             velec            = _mm_andnot_ps(dummy_mask,velec);
442             velecsum         = _mm_add_ps(velecsum,velec);
443
444             fscal            = felec;
445
446             fscal            = _mm_and_ps(fscal,cutoff_mask);
447
448             fscal            = _mm_andnot_ps(dummy_mask,fscal);
449
450              /* Update vectorial force */
451             fix1             = _mm_macc_ps(dx10,fscal,fix1);
452             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
453             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
454
455             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
456             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
457             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
458
459             }
460
461             /**************************
462              * CALCULATE INTERACTIONS *
463              **************************/
464
465             if (gmx_mm_any_lt(rsq20,rcutoff2))
466             {
467
468             /* Compute parameters for interactions between i and j atoms */
469             qq20             = _mm_mul_ps(iq2,jq0);
470
471             /* REACTION-FIELD ELECTROSTATICS */
472             velec            = _mm_mul_ps(qq20,_mm_sub_ps(_mm_macc_ps(krf,rsq20,rinv20),crf));
473             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
474
475             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
476
477             /* Update potential sum for this i atom from the interaction with this j atom. */
478             velec            = _mm_and_ps(velec,cutoff_mask);
479             velec            = _mm_andnot_ps(dummy_mask,velec);
480             velecsum         = _mm_add_ps(velecsum,velec);
481
482             fscal            = felec;
483
484             fscal            = _mm_and_ps(fscal,cutoff_mask);
485
486             fscal            = _mm_andnot_ps(dummy_mask,fscal);
487
488              /* Update vectorial force */
489             fix2             = _mm_macc_ps(dx20,fscal,fix2);
490             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
491             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
492
493             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
494             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
495             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
496
497             }
498
499             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
500             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
501             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
502             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
503
504             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
505
506             /* Inner loop uses 117 flops */
507         }
508
509         /* End of innermost loop */
510
511         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
512                                               f+i_coord_offset,fshift+i_shift_offset);
513
514         ggid                        = gid[iidx];
515         /* Update potential energies */
516         gmx_mm_update_1pot_ps(velecsum,kernel_data->energygrp_elec+ggid);
517
518         /* Increment number of inner iterations */
519         inneriter                  += j_index_end - j_index_start;
520
521         /* Outer loop uses 19 flops */
522     }
523
524     /* Increment number of outer iterations */
525     outeriter        += nri;
526
527     /* Update outer/inner flops */
528
529     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_VF,outeriter*19 + inneriter*117);
530 }
531 /*
532  * Gromacs nonbonded kernel:   nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
533  * Electrostatics interaction: ReactionField
534  * VdW interaction:            None
535  * Geometry:                   Water3-Particle
536  * Calculate force/pot:        Force
537  */
538 void
539 nb_kernel_ElecRFCut_VdwNone_GeomW3P1_F_avx_128_fma_single
540                     (t_nblist * gmx_restrict                nlist,
541                      rvec * gmx_restrict                    xx,
542                      rvec * gmx_restrict                    ff,
543                      t_forcerec * gmx_restrict              fr,
544                      t_mdatoms * gmx_restrict               mdatoms,
545                      nb_kernel_data_t * gmx_restrict        kernel_data,
546                      t_nrnb * gmx_restrict                  nrnb)
547 {
548     /* Suffixes 0,1,2,3 refer to particle indices for waters in the inner or outer loop, or
549      * just 0 for non-waters.
550      * Suffixes A,B,C,D refer to j loop unrolling done with AVX_128, e.g. for the four different
551      * jnr indices corresponding to data put in the four positions in the SIMD register.
552      */
553     int              i_shift_offset,i_coord_offset,outeriter,inneriter;
554     int              j_index_start,j_index_end,jidx,nri,inr,ggid,iidx;
555     int              jnrA,jnrB,jnrC,jnrD;
556     int              jnrlistA,jnrlistB,jnrlistC,jnrlistD;
557     int              j_coord_offsetA,j_coord_offsetB,j_coord_offsetC,j_coord_offsetD;
558     int              *iinr,*jindex,*jjnr,*shiftidx,*gid;
559     real             rcutoff_scalar;
560     real             *shiftvec,*fshift,*x,*f;
561     real             *fjptrA,*fjptrB,*fjptrC,*fjptrD;
562     real             scratch[4*DIM];
563     __m128           fscal,rcutoff,rcutoff2,jidxall;
564     int              vdwioffset0;
565     __m128           ix0,iy0,iz0,fix0,fiy0,fiz0,iq0,isai0;
566     int              vdwioffset1;
567     __m128           ix1,iy1,iz1,fix1,fiy1,fiz1,iq1,isai1;
568     int              vdwioffset2;
569     __m128           ix2,iy2,iz2,fix2,fiy2,fiz2,iq2,isai2;
570     int              vdwjidx0A,vdwjidx0B,vdwjidx0C,vdwjidx0D;
571     __m128           jx0,jy0,jz0,fjx0,fjy0,fjz0,jq0,isaj0;
572     __m128           dx00,dy00,dz00,rsq00,rinv00,rinvsq00,r00,qq00,c6_00,c12_00;
573     __m128           dx10,dy10,dz10,rsq10,rinv10,rinvsq10,r10,qq10,c6_10,c12_10;
574     __m128           dx20,dy20,dz20,rsq20,rinv20,rinvsq20,r20,qq20,c6_20,c12_20;
575     __m128           velec,felec,velecsum,facel,crf,krf,krf2;
576     real             *charge;
577     __m128           dummy_mask,cutoff_mask;
578     __m128           signbit = _mm_castsi128_ps( _mm_set1_epi32(0x80000000) );
579     __m128           one     = _mm_set1_ps(1.0);
580     __m128           two     = _mm_set1_ps(2.0);
581     x                = xx[0];
582     f                = ff[0];
583
584     nri              = nlist->nri;
585     iinr             = nlist->iinr;
586     jindex           = nlist->jindex;
587     jjnr             = nlist->jjnr;
588     shiftidx         = nlist->shift;
589     gid              = nlist->gid;
590     shiftvec         = fr->shift_vec[0];
591     fshift           = fr->fshift[0];
592     facel            = _mm_set1_ps(fr->epsfac);
593     charge           = mdatoms->chargeA;
594     krf              = _mm_set1_ps(fr->ic->k_rf);
595     krf2             = _mm_set1_ps(fr->ic->k_rf*2.0);
596     crf              = _mm_set1_ps(fr->ic->c_rf);
597
598     /* Setup water-specific parameters */
599     inr              = nlist->iinr[0];
600     iq0              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+0]));
601     iq1              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+1]));
602     iq2              = _mm_mul_ps(facel,_mm_set1_ps(charge[inr+2]));
603
604     /* When we use explicit cutoffs the value must be identical for elec and VdW, so use elec as an arbitrary choice */
605     rcutoff_scalar   = fr->rcoulomb;
606     rcutoff          = _mm_set1_ps(rcutoff_scalar);
607     rcutoff2         = _mm_mul_ps(rcutoff,rcutoff);
608
609     /* Avoid stupid compiler warnings */
610     jnrA = jnrB = jnrC = jnrD = 0;
611     j_coord_offsetA = 0;
612     j_coord_offsetB = 0;
613     j_coord_offsetC = 0;
614     j_coord_offsetD = 0;
615
616     outeriter        = 0;
617     inneriter        = 0;
618
619     for(iidx=0;iidx<4*DIM;iidx++)
620     {
621         scratch[iidx] = 0.0;
622     }
623
624     /* Start outer loop over neighborlists */
625     for(iidx=0; iidx<nri; iidx++)
626     {
627         /* Load shift vector for this list */
628         i_shift_offset   = DIM*shiftidx[iidx];
629
630         /* Load limits for loop over neighbors */
631         j_index_start    = jindex[iidx];
632         j_index_end      = jindex[iidx+1];
633
634         /* Get outer coordinate index */
635         inr              = iinr[iidx];
636         i_coord_offset   = DIM*inr;
637
638         /* Load i particle coords and add shift vector */
639         gmx_mm_load_shift_and_3rvec_broadcast_ps(shiftvec+i_shift_offset,x+i_coord_offset,
640                                                  &ix0,&iy0,&iz0,&ix1,&iy1,&iz1,&ix2,&iy2,&iz2);
641
642         fix0             = _mm_setzero_ps();
643         fiy0             = _mm_setzero_ps();
644         fiz0             = _mm_setzero_ps();
645         fix1             = _mm_setzero_ps();
646         fiy1             = _mm_setzero_ps();
647         fiz1             = _mm_setzero_ps();
648         fix2             = _mm_setzero_ps();
649         fiy2             = _mm_setzero_ps();
650         fiz2             = _mm_setzero_ps();
651
652         /* Start inner kernel loop */
653         for(jidx=j_index_start; jidx<j_index_end && jjnr[jidx+3]>=0; jidx+=4)
654         {
655
656             /* Get j neighbor index, and coordinate index */
657             jnrA             = jjnr[jidx];
658             jnrB             = jjnr[jidx+1];
659             jnrC             = jjnr[jidx+2];
660             jnrD             = jjnr[jidx+3];
661             j_coord_offsetA  = DIM*jnrA;
662             j_coord_offsetB  = DIM*jnrB;
663             j_coord_offsetC  = DIM*jnrC;
664             j_coord_offsetD  = DIM*jnrD;
665
666             /* load j atom coordinates */
667             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
668                                               x+j_coord_offsetC,x+j_coord_offsetD,
669                                               &jx0,&jy0,&jz0);
670
671             /* Calculate displacement vector */
672             dx00             = _mm_sub_ps(ix0,jx0);
673             dy00             = _mm_sub_ps(iy0,jy0);
674             dz00             = _mm_sub_ps(iz0,jz0);
675             dx10             = _mm_sub_ps(ix1,jx0);
676             dy10             = _mm_sub_ps(iy1,jy0);
677             dz10             = _mm_sub_ps(iz1,jz0);
678             dx20             = _mm_sub_ps(ix2,jx0);
679             dy20             = _mm_sub_ps(iy2,jy0);
680             dz20             = _mm_sub_ps(iz2,jz0);
681
682             /* Calculate squared distance and things based on it */
683             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
684             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
685             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
686
687             rinv00           = gmx_mm_invsqrt_ps(rsq00);
688             rinv10           = gmx_mm_invsqrt_ps(rsq10);
689             rinv20           = gmx_mm_invsqrt_ps(rsq20);
690
691             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
692             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
693             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
694
695             /* Load parameters for j particles */
696             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
697                                                               charge+jnrC+0,charge+jnrD+0);
698
699             fjx0             = _mm_setzero_ps();
700             fjy0             = _mm_setzero_ps();
701             fjz0             = _mm_setzero_ps();
702
703             /**************************
704              * CALCULATE INTERACTIONS *
705              **************************/
706
707             if (gmx_mm_any_lt(rsq00,rcutoff2))
708             {
709
710             /* Compute parameters for interactions between i and j atoms */
711             qq00             = _mm_mul_ps(iq0,jq0);
712
713             /* REACTION-FIELD ELECTROSTATICS */
714             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
715
716             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
717
718             fscal            = felec;
719
720             fscal            = _mm_and_ps(fscal,cutoff_mask);
721
722              /* Update vectorial force */
723             fix0             = _mm_macc_ps(dx00,fscal,fix0);
724             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
725             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
726
727             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
728             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
729             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
730
731             }
732
733             /**************************
734              * CALCULATE INTERACTIONS *
735              **************************/
736
737             if (gmx_mm_any_lt(rsq10,rcutoff2))
738             {
739
740             /* Compute parameters for interactions between i and j atoms */
741             qq10             = _mm_mul_ps(iq1,jq0);
742
743             /* REACTION-FIELD ELECTROSTATICS */
744             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
745
746             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
747
748             fscal            = felec;
749
750             fscal            = _mm_and_ps(fscal,cutoff_mask);
751
752              /* Update vectorial force */
753             fix1             = _mm_macc_ps(dx10,fscal,fix1);
754             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
755             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
756
757             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
758             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
759             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
760
761             }
762
763             /**************************
764              * CALCULATE INTERACTIONS *
765              **************************/
766
767             if (gmx_mm_any_lt(rsq20,rcutoff2))
768             {
769
770             /* Compute parameters for interactions between i and j atoms */
771             qq20             = _mm_mul_ps(iq2,jq0);
772
773             /* REACTION-FIELD ELECTROSTATICS */
774             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
775
776             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
777
778             fscal            = felec;
779
780             fscal            = _mm_and_ps(fscal,cutoff_mask);
781
782              /* Update vectorial force */
783             fix2             = _mm_macc_ps(dx20,fscal,fix2);
784             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
785             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
786
787             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
788             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
789             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
790
791             }
792
793             fjptrA             = f+j_coord_offsetA;
794             fjptrB             = f+j_coord_offsetB;
795             fjptrC             = f+j_coord_offsetC;
796             fjptrD             = f+j_coord_offsetD;
797
798             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
799
800             /* Inner loop uses 99 flops */
801         }
802
803         if(jidx<j_index_end)
804         {
805
806             /* Get j neighbor index, and coordinate index */
807             jnrlistA         = jjnr[jidx];
808             jnrlistB         = jjnr[jidx+1];
809             jnrlistC         = jjnr[jidx+2];
810             jnrlistD         = jjnr[jidx+3];
811             /* Sign of each element will be negative for non-real atoms.
812              * This mask will be 0xFFFFFFFF for dummy entries and 0x0 for real ones,
813              * so use it as val = _mm_andnot_ps(mask,val) to clear dummy entries.
814              */
815             dummy_mask = gmx_mm_castsi128_ps(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)(jjnr+jidx)),_mm_setzero_si128()));
816             jnrA       = (jnrlistA>=0) ? jnrlistA : 0;
817             jnrB       = (jnrlistB>=0) ? jnrlistB : 0;
818             jnrC       = (jnrlistC>=0) ? jnrlistC : 0;
819             jnrD       = (jnrlistD>=0) ? jnrlistD : 0;
820             j_coord_offsetA  = DIM*jnrA;
821             j_coord_offsetB  = DIM*jnrB;
822             j_coord_offsetC  = DIM*jnrC;
823             j_coord_offsetD  = DIM*jnrD;
824
825             /* load j atom coordinates */
826             gmx_mm_load_1rvec_4ptr_swizzle_ps(x+j_coord_offsetA,x+j_coord_offsetB,
827                                               x+j_coord_offsetC,x+j_coord_offsetD,
828                                               &jx0,&jy0,&jz0);
829
830             /* Calculate displacement vector */
831             dx00             = _mm_sub_ps(ix0,jx0);
832             dy00             = _mm_sub_ps(iy0,jy0);
833             dz00             = _mm_sub_ps(iz0,jz0);
834             dx10             = _mm_sub_ps(ix1,jx0);
835             dy10             = _mm_sub_ps(iy1,jy0);
836             dz10             = _mm_sub_ps(iz1,jz0);
837             dx20             = _mm_sub_ps(ix2,jx0);
838             dy20             = _mm_sub_ps(iy2,jy0);
839             dz20             = _mm_sub_ps(iz2,jz0);
840
841             /* Calculate squared distance and things based on it */
842             rsq00            = gmx_mm_calc_rsq_ps(dx00,dy00,dz00);
843             rsq10            = gmx_mm_calc_rsq_ps(dx10,dy10,dz10);
844             rsq20            = gmx_mm_calc_rsq_ps(dx20,dy20,dz20);
845
846             rinv00           = gmx_mm_invsqrt_ps(rsq00);
847             rinv10           = gmx_mm_invsqrt_ps(rsq10);
848             rinv20           = gmx_mm_invsqrt_ps(rsq20);
849
850             rinvsq00         = _mm_mul_ps(rinv00,rinv00);
851             rinvsq10         = _mm_mul_ps(rinv10,rinv10);
852             rinvsq20         = _mm_mul_ps(rinv20,rinv20);
853
854             /* Load parameters for j particles */
855             jq0              = gmx_mm_load_4real_swizzle_ps(charge+jnrA+0,charge+jnrB+0,
856                                                               charge+jnrC+0,charge+jnrD+0);
857
858             fjx0             = _mm_setzero_ps();
859             fjy0             = _mm_setzero_ps();
860             fjz0             = _mm_setzero_ps();
861
862             /**************************
863              * CALCULATE INTERACTIONS *
864              **************************/
865
866             if (gmx_mm_any_lt(rsq00,rcutoff2))
867             {
868
869             /* Compute parameters for interactions between i and j atoms */
870             qq00             = _mm_mul_ps(iq0,jq0);
871
872             /* REACTION-FIELD ELECTROSTATICS */
873             felec            = _mm_mul_ps(qq00,_mm_msub_ps(rinv00,rinvsq00,krf2));
874
875             cutoff_mask      = _mm_cmplt_ps(rsq00,rcutoff2);
876
877             fscal            = felec;
878
879             fscal            = _mm_and_ps(fscal,cutoff_mask);
880
881             fscal            = _mm_andnot_ps(dummy_mask,fscal);
882
883              /* Update vectorial force */
884             fix0             = _mm_macc_ps(dx00,fscal,fix0);
885             fiy0             = _mm_macc_ps(dy00,fscal,fiy0);
886             fiz0             = _mm_macc_ps(dz00,fscal,fiz0);
887
888             fjx0             = _mm_macc_ps(dx00,fscal,fjx0);
889             fjy0             = _mm_macc_ps(dy00,fscal,fjy0);
890             fjz0             = _mm_macc_ps(dz00,fscal,fjz0);
891
892             }
893
894             /**************************
895              * CALCULATE INTERACTIONS *
896              **************************/
897
898             if (gmx_mm_any_lt(rsq10,rcutoff2))
899             {
900
901             /* Compute parameters for interactions between i and j atoms */
902             qq10             = _mm_mul_ps(iq1,jq0);
903
904             /* REACTION-FIELD ELECTROSTATICS */
905             felec            = _mm_mul_ps(qq10,_mm_msub_ps(rinv10,rinvsq10,krf2));
906
907             cutoff_mask      = _mm_cmplt_ps(rsq10,rcutoff2);
908
909             fscal            = felec;
910
911             fscal            = _mm_and_ps(fscal,cutoff_mask);
912
913             fscal            = _mm_andnot_ps(dummy_mask,fscal);
914
915              /* Update vectorial force */
916             fix1             = _mm_macc_ps(dx10,fscal,fix1);
917             fiy1             = _mm_macc_ps(dy10,fscal,fiy1);
918             fiz1             = _mm_macc_ps(dz10,fscal,fiz1);
919
920             fjx0             = _mm_macc_ps(dx10,fscal,fjx0);
921             fjy0             = _mm_macc_ps(dy10,fscal,fjy0);
922             fjz0             = _mm_macc_ps(dz10,fscal,fjz0);
923
924             }
925
926             /**************************
927              * CALCULATE INTERACTIONS *
928              **************************/
929
930             if (gmx_mm_any_lt(rsq20,rcutoff2))
931             {
932
933             /* Compute parameters for interactions between i and j atoms */
934             qq20             = _mm_mul_ps(iq2,jq0);
935
936             /* REACTION-FIELD ELECTROSTATICS */
937             felec            = _mm_mul_ps(qq20,_mm_msub_ps(rinv20,rinvsq20,krf2));
938
939             cutoff_mask      = _mm_cmplt_ps(rsq20,rcutoff2);
940
941             fscal            = felec;
942
943             fscal            = _mm_and_ps(fscal,cutoff_mask);
944
945             fscal            = _mm_andnot_ps(dummy_mask,fscal);
946
947              /* Update vectorial force */
948             fix2             = _mm_macc_ps(dx20,fscal,fix2);
949             fiy2             = _mm_macc_ps(dy20,fscal,fiy2);
950             fiz2             = _mm_macc_ps(dz20,fscal,fiz2);
951
952             fjx0             = _mm_macc_ps(dx20,fscal,fjx0);
953             fjy0             = _mm_macc_ps(dy20,fscal,fjy0);
954             fjz0             = _mm_macc_ps(dz20,fscal,fjz0);
955
956             }
957
958             fjptrA             = (jnrlistA>=0) ? f+j_coord_offsetA : scratch;
959             fjptrB             = (jnrlistB>=0) ? f+j_coord_offsetB : scratch;
960             fjptrC             = (jnrlistC>=0) ? f+j_coord_offsetC : scratch;
961             fjptrD             = (jnrlistD>=0) ? f+j_coord_offsetD : scratch;
962
963             gmx_mm_decrement_1rvec_4ptr_swizzle_ps(fjptrA,fjptrB,fjptrC,fjptrD,fjx0,fjy0,fjz0);
964
965             /* Inner loop uses 99 flops */
966         }
967
968         /* End of innermost loop */
969
970         gmx_mm_update_iforce_3atom_swizzle_ps(fix0,fiy0,fiz0,fix1,fiy1,fiz1,fix2,fiy2,fiz2,
971                                               f+i_coord_offset,fshift+i_shift_offset);
972
973         /* Increment number of inner iterations */
974         inneriter                  += j_index_end - j_index_start;
975
976         /* Outer loop uses 18 flops */
977     }
978
979     /* Increment number of outer iterations */
980     outeriter        += nri;
981
982     /* Update outer/inner flops */
983
984     inc_nrnb(nrnb,eNR_NBKERNEL_ELEC_W3_F,outeriter*18 + inneriter*99);
985 }