1 #include "simint/boys/boys.h"
2 #include "simint/ostei/gen/ostei_generated.h"
3 #include "simint/vectorization/vectorization.h"
4 #include <math.h>
5 #include <string.h>
6 
7 
ostei_p_s_d_d(struct simint_multi_shellpair const P,struct simint_multi_shellpair const Q,double screen_tol,double * const restrict work,double * const restrict INT__p_s_d_d)8 int ostei_p_s_d_d(struct simint_multi_shellpair const P,
9                   struct simint_multi_shellpair const Q,
10                   double screen_tol,
11                   double * const restrict work,
12                   double * const restrict INT__p_s_d_d)
13 {
14 
15     SIMINT_ASSUME_ALIGN_DBL(work);
16     SIMINT_ASSUME_ALIGN_DBL(INT__p_s_d_d);
17     int ab, cd, abcd;
18     int istart, jstart;
19     int iprimcd, nprim_icd, icd;
20     const int check_screen = (screen_tol > 0.0);
21     int i, j;
22     int n;
23     int not_screened;
24     int real_abcd;
25     int ibra;
26 
27     // partition workspace
28     double * const INT__p_s_d_s = work + (SIMINT_NSHELL_SIMD * 0);
29     double * const INT__p_s_f_s = work + (SIMINT_NSHELL_SIMD * 18);
30     double * const INT__p_s_g_s = work + (SIMINT_NSHELL_SIMD * 48);
31     SIMINT_DBLTYPE * const primwork = (SIMINT_DBLTYPE *)(work + SIMINT_NSHELL_SIMD*93);
32     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_s_s = primwork + 0;
33     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_p_s = primwork + 6;
34     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_d_s = primwork + 21;
35     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_f_s = primwork + 45;
36     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_g_s = primwork + 75;
37     SIMINT_DBLTYPE * const restrict PRIM_INT__p_s_d_s = primwork + 105;
38     SIMINT_DBLTYPE * const restrict PRIM_INT__p_s_f_s = primwork + 123;
39     SIMINT_DBLTYPE * const restrict PRIM_INT__p_s_g_s = primwork + 153;
40     double * const hrrwork = (double *)(primwork + 198);
41     double * const HRR_INT__p_s_d_p = hrrwork + 0;
42     double * const HRR_INT__p_s_f_p = hrrwork + 54;
43 
44 
45     // Create constants
46     const SIMINT_DBLTYPE const_1 = SIMINT_DBLSET1(1);
47     const SIMINT_DBLTYPE const_2 = SIMINT_DBLSET1(2);
48     const SIMINT_DBLTYPE const_3 = SIMINT_DBLSET1(3);
49     const SIMINT_DBLTYPE const_4 = SIMINT_DBLSET1(4);
50     const SIMINT_DBLTYPE one_half = SIMINT_DBLSET1(0.5);
51 
52 
53     ////////////////////////////////////////
54     // Loop over shells and primitives
55     ////////////////////////////////////////
56 
57     real_abcd = 0;
58     istart = 0;
59     for(ab = 0; ab < P.nshell12_clip; ++ab)
60     {
61         const int iend = istart + P.nprim12[ab];
62 
63         cd = 0;
64         jstart = 0;
65 
66         for(cd = 0; cd < Q.nshell12_clip; cd += SIMINT_NSHELL_SIMD)
67         {
68             const int nshellbatch = ((cd + SIMINT_NSHELL_SIMD) > Q.nshell12_clip) ? Q.nshell12_clip - cd : SIMINT_NSHELL_SIMD;
69             int jend = jstart;
70             for(i = 0; i < nshellbatch; i++)
71                 jend += Q.nprim12[cd+i];
72 
73             // Clear the beginning of the workspace (where we are accumulating integrals)
74             memset(work, 0, SIMINT_NSHELL_SIMD * 93 * sizeof(double));
75             abcd = 0;
76 
77 
78             for(i = istart; i < iend; ++i)
79             {
80                 SIMINT_DBLTYPE bra_screen_max;  // only used if check_screen
81 
82                 if(check_screen)
83                 {
84                     // Skip this whole thing if always insignificant
85                     if((P.screen[i] * Q.screen_max) < screen_tol)
86                         continue;
87                     bra_screen_max = SIMINT_DBLSET1(P.screen[i]);
88                 }
89 
90                 icd = 0;
91                 iprimcd = 0;
92                 nprim_icd = Q.nprim12[cd];
93                 double * restrict PRIM_PTR_INT__p_s_d_s = INT__p_s_d_s + abcd * 18;
94                 double * restrict PRIM_PTR_INT__p_s_f_s = INT__p_s_f_s + abcd * 30;
95                 double * restrict PRIM_PTR_INT__p_s_g_s = INT__p_s_g_s + abcd * 45;
96 
97 
98 
99                 // Load these one per loop over i
100                 const SIMINT_DBLTYPE P_alpha = SIMINT_DBLSET1(P.alpha[i]);
101                 const SIMINT_DBLTYPE P_prefac = SIMINT_DBLSET1(P.prefac[i]);
102                 const SIMINT_DBLTYPE Pxyz[3] = { SIMINT_DBLSET1(P.x[i]), SIMINT_DBLSET1(P.y[i]), SIMINT_DBLSET1(P.z[i]) };
103 
104                 const SIMINT_DBLTYPE P_PA[3] = { SIMINT_DBLSET1(P.PA_x[i]), SIMINT_DBLSET1(P.PA_y[i]), SIMINT_DBLSET1(P.PA_z[i]) };
105 
106                 for(j = jstart; j < jend; j += SIMINT_SIMD_LEN)
107                 {
108                     // calculate the shell offsets
109                     // these are the offset from the shell pointed to by cd
110                     // for each element
111                     int shelloffsets[SIMINT_SIMD_LEN] = {0};
112                     int lastoffset = 0;
113                     const int nlane = ( ((j + SIMINT_SIMD_LEN) < jend) ? SIMINT_SIMD_LEN : (jend - j));
114 
115                     if((iprimcd + SIMINT_SIMD_LEN) >= nprim_icd)
116                     {
117                         // Handle if the first element of the vector is a new shell
118                         if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
119                         {
120                             nprim_icd += Q.nprim12[cd + (++icd)];
121                             PRIM_PTR_INT__p_s_d_s += 18;
122                             PRIM_PTR_INT__p_s_f_s += 30;
123                             PRIM_PTR_INT__p_s_g_s += 45;
124                         }
125                         iprimcd++;
126                         for(n = 1; n < SIMINT_SIMD_LEN; ++n)
127                         {
128                             if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
129                             {
130                                 shelloffsets[n] = shelloffsets[n-1] + 1;
131                                 lastoffset++;
132                                 nprim_icd += Q.nprim12[cd + (++icd)];
133                             }
134                             else
135                                 shelloffsets[n] = shelloffsets[n-1];
136                             iprimcd++;
137                         }
138                     }
139                     else
140                         iprimcd += SIMINT_SIMD_LEN;
141 
142                     // Do we have to compute this vector (or has it been screened out)?
143                     // (not_screened != 0 means we have to do this vector)
144                     if(check_screen)
145                     {
146                         const double vmax = vector_max(SIMINT_MUL(bra_screen_max, SIMINT_DBLLOAD(Q.screen, j)));
147                         if(vmax < screen_tol)
148                         {
149                             PRIM_PTR_INT__p_s_d_s += lastoffset*18;
150                             PRIM_PTR_INT__p_s_f_s += lastoffset*30;
151                             PRIM_PTR_INT__p_s_g_s += lastoffset*45;
152                             continue;
153                         }
154                     }
155 
156                     const SIMINT_DBLTYPE Q_alpha = SIMINT_DBLLOAD(Q.alpha, j);
157                     const SIMINT_DBLTYPE PQalpha_mul = SIMINT_MUL(P_alpha, Q_alpha);
158                     const SIMINT_DBLTYPE PQalpha_sum = SIMINT_ADD(P_alpha, Q_alpha);
159                     const SIMINT_DBLTYPE one_over_PQalpha_sum = SIMINT_DIV(const_1, PQalpha_sum);
160 
161 
162                     /* construct R2 = (Px - Qx)**2 + (Py - Qy)**2 + (Pz -Qz)**2 */
163                     SIMINT_DBLTYPE PQ[3];
164                     PQ[0] = SIMINT_SUB(Pxyz[0], SIMINT_DBLLOAD(Q.x, j));
165                     PQ[1] = SIMINT_SUB(Pxyz[1], SIMINT_DBLLOAD(Q.y, j));
166                     PQ[2] = SIMINT_SUB(Pxyz[2], SIMINT_DBLLOAD(Q.z, j));
167                     SIMINT_DBLTYPE R2 = SIMINT_MUL(PQ[0], PQ[0]);
168                     R2 = SIMINT_FMADD(PQ[1], PQ[1], R2);
169                     R2 = SIMINT_FMADD(PQ[2], PQ[2], R2);
170 
171                     const SIMINT_DBLTYPE alpha = SIMINT_MUL(PQalpha_mul, one_over_PQalpha_sum); // alpha from MEST
172                     const SIMINT_DBLTYPE one_over_p = SIMINT_DIV(const_1, P_alpha);
173                     const SIMINT_DBLTYPE one_over_q = SIMINT_DIV(const_1, Q_alpha);
174                     const SIMINT_DBLTYPE one_over_2p = SIMINT_MUL(one_half, one_over_p);
175                     const SIMINT_DBLTYPE one_over_2q = SIMINT_MUL(one_half, one_over_q);
176                     const SIMINT_DBLTYPE one_over_2pq = SIMINT_MUL(one_half, one_over_PQalpha_sum);
177                     const SIMINT_DBLTYPE Q_PA[3] = { SIMINT_DBLLOAD(Q.PA_x, j), SIMINT_DBLLOAD(Q.PA_y, j), SIMINT_DBLLOAD(Q.PA_z, j) };
178 
179                     // NOTE: Minus sign!
180                     const SIMINT_DBLTYPE a_over_p = SIMINT_MUL(SIMINT_NEG(alpha), one_over_p);
181                     SIMINT_DBLTYPE aop_PQ[3];
182                     aop_PQ[0] = SIMINT_MUL(a_over_p, PQ[0]);
183                     aop_PQ[1] = SIMINT_MUL(a_over_p, PQ[1]);
184                     aop_PQ[2] = SIMINT_MUL(a_over_p, PQ[2]);
185 
186                     SIMINT_DBLTYPE a_over_q = SIMINT_MUL(alpha, one_over_q);
187                     SIMINT_DBLTYPE aoq_PQ[3];
188                     aoq_PQ[0] = SIMINT_MUL(a_over_q, PQ[0]);
189                     aoq_PQ[1] = SIMINT_MUL(a_over_q, PQ[1]);
190                     aoq_PQ[2] = SIMINT_MUL(a_over_q, PQ[2]);
191                     // Put a minus sign here so we don't have to in RR routines
192                     a_over_q = SIMINT_NEG(a_over_q);
193 
194 
195                     //////////////////////////////////////////////
196                     // Fjt function section
197                     // Maximum v value: 5
198                     //////////////////////////////////////////////
199                     // The parameter to the Fjt function
200                     const SIMINT_DBLTYPE F_x = SIMINT_MUL(R2, alpha);
201 
202 
203                     const SIMINT_DBLTYPE Q_prefac = mask_load(nlane, Q.prefac + j);
204 
205 
206                     boys_F_split(PRIM_INT__s_s_s_s, F_x, 5);
207                     SIMINT_DBLTYPE prefac = SIMINT_SQRT(one_over_PQalpha_sum);
208                     prefac = SIMINT_MUL(SIMINT_MUL(P_prefac, Q_prefac), prefac);
209                     for(n = 0; n <= 5; n++)
210                         PRIM_INT__s_s_s_s[n] = SIMINT_MUL(PRIM_INT__s_s_s_s[n], prefac);
211 
212                     //////////////////////////////////////////////
213                     // Primitive integrals: Vertical recurrance
214                     //////////////////////////////////////////////
215 
216                     const SIMINT_DBLTYPE vrr_const_1_over_2q = one_over_2q;
217                     const SIMINT_DBLTYPE vrr_const_2_over_2q = SIMINT_MUL(const_2, one_over_2q);
218                     const SIMINT_DBLTYPE vrr_const_3_over_2q = SIMINT_MUL(const_3, one_over_2q);
219                     const SIMINT_DBLTYPE vrr_const_1_over_2pq = one_over_2pq;
220                     const SIMINT_DBLTYPE vrr_const_2_over_2pq = SIMINT_MUL(const_2, one_over_2pq);
221                     const SIMINT_DBLTYPE vrr_const_3_over_2pq = SIMINT_MUL(const_3, one_over_2pq);
222                     const SIMINT_DBLTYPE vrr_const_4_over_2pq = SIMINT_MUL(const_4, one_over_2pq);
223 
224 
225 
226                     // Forming PRIM_INT__s_s_p_s[5 * 3];
227                     for(n = 0; n < 5; ++n)  // loop over orders of auxiliary function
228                     {
229 
230                         PRIM_INT__s_s_p_s[n * 3 + 0] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_s_s[n * 1 + 0]);
231                         PRIM_INT__s_s_p_s[n * 3 + 0] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_p_s[n * 3 + 0]);
232 
233                         PRIM_INT__s_s_p_s[n * 3 + 1] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_s_s[n * 1 + 0]);
234                         PRIM_INT__s_s_p_s[n * 3 + 1] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_p_s[n * 3 + 1]);
235 
236                         PRIM_INT__s_s_p_s[n * 3 + 2] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_s_s[n * 1 + 0]);
237                         PRIM_INT__s_s_p_s[n * 3 + 2] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_p_s[n * 3 + 2]);
238 
239                     }
240 
241 
242 
243                     // Forming PRIM_INT__s_s_d_s[4 * 6];
244                     for(n = 0; n < 4; ++n)  // loop over orders of auxiliary function
245                     {
246 
247                         PRIM_INT__s_s_d_s[n * 6 + 0] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_p_s[n * 3 + 0]);
248                         PRIM_INT__s_s_d_s[n * 6 + 0] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__s_s_d_s[n * 6 + 0]);
249                         PRIM_INT__s_s_d_s[n * 6 + 0] = SIMINT_FMADD( vrr_const_1_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__s_s_d_s[n * 6 + 0]);
250 
251                         PRIM_INT__s_s_d_s[n * 6 + 1] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_p_s[n * 3 + 0]);
252                         PRIM_INT__s_s_d_s[n * 6 + 1] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__s_s_d_s[n * 6 + 1]);
253 
254                         PRIM_INT__s_s_d_s[n * 6 + 2] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_p_s[n * 3 + 0]);
255                         PRIM_INT__s_s_d_s[n * 6 + 2] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__s_s_d_s[n * 6 + 2]);
256 
257                         PRIM_INT__s_s_d_s[n * 6 + 3] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_p_s[n * 3 + 1]);
258                         PRIM_INT__s_s_d_s[n * 6 + 3] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__s_s_d_s[n * 6 + 3]);
259                         PRIM_INT__s_s_d_s[n * 6 + 3] = SIMINT_FMADD( vrr_const_1_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__s_s_d_s[n * 6 + 3]);
260 
261                         PRIM_INT__s_s_d_s[n * 6 + 4] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_p_s[n * 3 + 1]);
262                         PRIM_INT__s_s_d_s[n * 6 + 4] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__s_s_d_s[n * 6 + 4]);
263 
264                         PRIM_INT__s_s_d_s[n * 6 + 5] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_p_s[n * 3 + 2]);
265                         PRIM_INT__s_s_d_s[n * 6 + 5] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_p_s[(n+1) * 3 + 2], PRIM_INT__s_s_d_s[n * 6 + 5]);
266                         PRIM_INT__s_s_d_s[n * 6 + 5] = SIMINT_FMADD( vrr_const_1_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_s_s_s[n * 1 + 0]), PRIM_INT__s_s_d_s[n * 6 + 5]);
267 
268                     }
269 
270 
271 
272                     // Forming PRIM_INT__p_s_d_s[1 * 18];
273                     for(n = 0; n < 1; ++n)  // loop over orders of auxiliary function
274                     {
275 
276                         PRIM_INT__p_s_d_s[n * 18 + 0] = SIMINT_MUL(P_PA[0], PRIM_INT__s_s_d_s[n * 6 + 0]);
277                         PRIM_INT__p_s_d_s[n * 18 + 0] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__p_s_d_s[n * 18 + 0]);
278                         PRIM_INT__p_s_d_s[n * 18 + 0] = SIMINT_FMADD( vrr_const_2_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__p_s_d_s[n * 18 + 0]);
279 
280                         PRIM_INT__p_s_d_s[n * 18 + 1] = SIMINT_MUL(P_PA[0], PRIM_INT__s_s_d_s[n * 6 + 1]);
281                         PRIM_INT__p_s_d_s[n * 18 + 1] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 1], PRIM_INT__p_s_d_s[n * 18 + 1]);
282                         PRIM_INT__p_s_d_s[n * 18 + 1] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__p_s_d_s[n * 18 + 1]);
283 
284                         PRIM_INT__p_s_d_s[n * 18 + 2] = SIMINT_MUL(P_PA[0], PRIM_INT__s_s_d_s[n * 6 + 2]);
285                         PRIM_INT__p_s_d_s[n * 18 + 2] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 2], PRIM_INT__p_s_d_s[n * 18 + 2]);
286                         PRIM_INT__p_s_d_s[n * 18 + 2] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 2], PRIM_INT__p_s_d_s[n * 18 + 2]);
287 
288                         PRIM_INT__p_s_d_s[n * 18 + 3] = SIMINT_MUL(P_PA[0], PRIM_INT__s_s_d_s[n * 6 + 3]);
289                         PRIM_INT__p_s_d_s[n * 18 + 3] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__p_s_d_s[n * 18 + 3]);
290 
291                         PRIM_INT__p_s_d_s[n * 18 + 4] = SIMINT_MUL(P_PA[0], PRIM_INT__s_s_d_s[n * 6 + 4]);
292                         PRIM_INT__p_s_d_s[n * 18 + 4] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 4], PRIM_INT__p_s_d_s[n * 18 + 4]);
293 
294                         PRIM_INT__p_s_d_s[n * 18 + 5] = SIMINT_MUL(P_PA[0], PRIM_INT__s_s_d_s[n * 6 + 5]);
295                         PRIM_INT__p_s_d_s[n * 18 + 5] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 5], PRIM_INT__p_s_d_s[n * 18 + 5]);
296 
297                         PRIM_INT__p_s_d_s[n * 18 + 6] = SIMINT_MUL(P_PA[1], PRIM_INT__s_s_d_s[n * 6 + 0]);
298                         PRIM_INT__p_s_d_s[n * 18 + 6] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__p_s_d_s[n * 18 + 6]);
299 
300                         PRIM_INT__p_s_d_s[n * 18 + 7] = SIMINT_MUL(P_PA[1], PRIM_INT__s_s_d_s[n * 6 + 1]);
301                         PRIM_INT__p_s_d_s[n * 18 + 7] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 1], PRIM_INT__p_s_d_s[n * 18 + 7]);
302                         PRIM_INT__p_s_d_s[n * 18 + 7] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__p_s_d_s[n * 18 + 7]);
303 
304                         PRIM_INT__p_s_d_s[n * 18 + 8] = SIMINT_MUL(P_PA[1], PRIM_INT__s_s_d_s[n * 6 + 2]);
305                         PRIM_INT__p_s_d_s[n * 18 + 8] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 2], PRIM_INT__p_s_d_s[n * 18 + 8]);
306 
307                         PRIM_INT__p_s_d_s[n * 18 + 9] = SIMINT_MUL(P_PA[1], PRIM_INT__s_s_d_s[n * 6 + 3]);
308                         PRIM_INT__p_s_d_s[n * 18 + 9] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__p_s_d_s[n * 18 + 9]);
309                         PRIM_INT__p_s_d_s[n * 18 + 9] = SIMINT_FMADD( vrr_const_2_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__p_s_d_s[n * 18 + 9]);
310 
311                         PRIM_INT__p_s_d_s[n * 18 + 10] = SIMINT_MUL(P_PA[1], PRIM_INT__s_s_d_s[n * 6 + 4]);
312                         PRIM_INT__p_s_d_s[n * 18 + 10] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 4], PRIM_INT__p_s_d_s[n * 18 + 10]);
313                         PRIM_INT__p_s_d_s[n * 18 + 10] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 2], PRIM_INT__p_s_d_s[n * 18 + 10]);
314 
315                         PRIM_INT__p_s_d_s[n * 18 + 11] = SIMINT_MUL(P_PA[1], PRIM_INT__s_s_d_s[n * 6 + 5]);
316                         PRIM_INT__p_s_d_s[n * 18 + 11] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 5], PRIM_INT__p_s_d_s[n * 18 + 11]);
317 
318                         PRIM_INT__p_s_d_s[n * 18 + 12] = SIMINT_MUL(P_PA[2], PRIM_INT__s_s_d_s[n * 6 + 0]);
319                         PRIM_INT__p_s_d_s[n * 18 + 12] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__p_s_d_s[n * 18 + 12]);
320 
321                         PRIM_INT__p_s_d_s[n * 18 + 13] = SIMINT_MUL(P_PA[2], PRIM_INT__s_s_d_s[n * 6 + 1]);
322                         PRIM_INT__p_s_d_s[n * 18 + 13] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 1], PRIM_INT__p_s_d_s[n * 18 + 13]);
323 
324                         PRIM_INT__p_s_d_s[n * 18 + 14] = SIMINT_MUL(P_PA[2], PRIM_INT__s_s_d_s[n * 6 + 2]);
325                         PRIM_INT__p_s_d_s[n * 18 + 14] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 2], PRIM_INT__p_s_d_s[n * 18 + 14]);
326                         PRIM_INT__p_s_d_s[n * 18 + 14] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__p_s_d_s[n * 18 + 14]);
327 
328                         PRIM_INT__p_s_d_s[n * 18 + 15] = SIMINT_MUL(P_PA[2], PRIM_INT__s_s_d_s[n * 6 + 3]);
329                         PRIM_INT__p_s_d_s[n * 18 + 15] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__p_s_d_s[n * 18 + 15]);
330 
331                         PRIM_INT__p_s_d_s[n * 18 + 16] = SIMINT_MUL(P_PA[2], PRIM_INT__s_s_d_s[n * 6 + 4]);
332                         PRIM_INT__p_s_d_s[n * 18 + 16] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 4], PRIM_INT__p_s_d_s[n * 18 + 16]);
333                         PRIM_INT__p_s_d_s[n * 18 + 16] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__p_s_d_s[n * 18 + 16]);
334 
335                         PRIM_INT__p_s_d_s[n * 18 + 17] = SIMINT_MUL(P_PA[2], PRIM_INT__s_s_d_s[n * 6 + 5]);
336                         PRIM_INT__p_s_d_s[n * 18 + 17] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 5], PRIM_INT__p_s_d_s[n * 18 + 17]);
337                         PRIM_INT__p_s_d_s[n * 18 + 17] = SIMINT_FMADD( vrr_const_2_over_2pq, PRIM_INT__s_s_p_s[(n+1) * 3 + 2], PRIM_INT__p_s_d_s[n * 18 + 17]);
338 
339                     }
340 
341 
342 
343                     // Forming PRIM_INT__s_s_f_s[3 * 10];
344                     for(n = 0; n < 3; ++n)  // loop over orders of auxiliary function
345                     {
346 
347                         PRIM_INT__s_s_f_s[n * 10 + 0] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_d_s[n * 6 + 0]);
348                         PRIM_INT__s_s_f_s[n * 10 + 0] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__s_s_f_s[n * 10 + 0]);
349                         PRIM_INT__s_s_f_s[n * 10 + 0] = SIMINT_FMADD( vrr_const_2_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_p_s[(n+1) * 3 + 0], PRIM_INT__s_s_p_s[n * 3 + 0]), PRIM_INT__s_s_f_s[n * 10 + 0]);
350 
351                         PRIM_INT__s_s_f_s[n * 10 + 1] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_d_s[n * 6 + 0]);
352                         PRIM_INT__s_s_f_s[n * 10 + 1] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__s_s_f_s[n * 10 + 1]);
353 
354                         PRIM_INT__s_s_f_s[n * 10 + 2] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_d_s[n * 6 + 0]);
355                         PRIM_INT__s_s_f_s[n * 10 + 2] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 0], PRIM_INT__s_s_f_s[n * 10 + 2]);
356 
357                         PRIM_INT__s_s_f_s[n * 10 + 3] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_d_s[n * 6 + 3]);
358                         PRIM_INT__s_s_f_s[n * 10 + 3] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__s_s_f_s[n * 10 + 3]);
359 
360                         PRIM_INT__s_s_f_s[n * 10 + 4] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_d_s[n * 6 + 1]);
361                         PRIM_INT__s_s_f_s[n * 10 + 4] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 1], PRIM_INT__s_s_f_s[n * 10 + 4]);
362 
363                         PRIM_INT__s_s_f_s[n * 10 + 5] = SIMINT_MUL(Q_PA[0], PRIM_INT__s_s_d_s[n * 6 + 5]);
364                         PRIM_INT__s_s_f_s[n * 10 + 5] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_s_d_s[(n+1) * 6 + 5], PRIM_INT__s_s_f_s[n * 10 + 5]);
365 
366                         PRIM_INT__s_s_f_s[n * 10 + 6] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_d_s[n * 6 + 3]);
367                         PRIM_INT__s_s_f_s[n * 10 + 6] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__s_s_f_s[n * 10 + 6]);
368                         PRIM_INT__s_s_f_s[n * 10 + 6] = SIMINT_FMADD( vrr_const_2_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_p_s[(n+1) * 3 + 1], PRIM_INT__s_s_p_s[n * 3 + 1]), PRIM_INT__s_s_f_s[n * 10 + 6]);
369 
370                         PRIM_INT__s_s_f_s[n * 10 + 7] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_d_s[n * 6 + 3]);
371                         PRIM_INT__s_s_f_s[n * 10 + 7] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 3], PRIM_INT__s_s_f_s[n * 10 + 7]);
372 
373                         PRIM_INT__s_s_f_s[n * 10 + 8] = SIMINT_MUL(Q_PA[1], PRIM_INT__s_s_d_s[n * 6 + 5]);
374                         PRIM_INT__s_s_f_s[n * 10 + 8] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_s_d_s[(n+1) * 6 + 5], PRIM_INT__s_s_f_s[n * 10 + 8]);
375 
376                         PRIM_INT__s_s_f_s[n * 10 + 9] = SIMINT_MUL(Q_PA[2], PRIM_INT__s_s_d_s[n * 6 + 5]);
377                         PRIM_INT__s_s_f_s[n * 10 + 9] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_s_d_s[(n+1) * 6 + 5], PRIM_INT__s_s_f_s[n * 10 + 9]);
378                         PRIM_INT__s_s_f_s[n * 10 + 9] = SIMINT_FMADD( vrr_const_2_over_2q, SIMINT_FMADD(a_over_q, PRIM_INT__s_s_p_s[(n+1) * 3 + 2], PRIM_INT__s_s_p_s[n * 3 + 2]), PRIM_INT__s_s_f_s[n * 10 + 9]);
379 
380                     }
381 
382 
383                     VRR_I_p_s_f_s(
384                             PRIM_INT__p_s_f_s,
385                             PRIM_INT__s_s_f_s,
386                             PRIM_INT__s_s_d_s,
387                             P_PA,
388                             aop_PQ,
389                             one_over_2pq,
390                             1);
391 
392 
393                     VRR_K_s_s_g_s(
394                             PRIM_INT__s_s_g_s,
395                             PRIM_INT__s_s_f_s,
396                             PRIM_INT__s_s_d_s,
397                             Q_PA,
398                             a_over_q,
399                             aoq_PQ,
400                             one_over_2q,
401                             2);
402 
403 
404                     VRR_I_p_s_g_s(
405                             PRIM_INT__p_s_g_s,
406                             PRIM_INT__s_s_g_s,
407                             PRIM_INT__s_s_f_s,
408                             P_PA,
409                             aop_PQ,
410                             one_over_2pq,
411                             1);
412 
413 
414 
415 
416                     ////////////////////////////////////
417                     // Accumulate contracted integrals
418                     ////////////////////////////////////
419                     if(lastoffset == 0)
420                     {
421                         contract_all(18, PRIM_INT__p_s_d_s, PRIM_PTR_INT__p_s_d_s);
422                         contract_all(30, PRIM_INT__p_s_f_s, PRIM_PTR_INT__p_s_f_s);
423                         contract_all(45, PRIM_INT__p_s_g_s, PRIM_PTR_INT__p_s_g_s);
424                     }
425                     else
426                     {
427                         contract(18, shelloffsets, PRIM_INT__p_s_d_s, PRIM_PTR_INT__p_s_d_s);
428                         contract(30, shelloffsets, PRIM_INT__p_s_f_s, PRIM_PTR_INT__p_s_f_s);
429                         contract(45, shelloffsets, PRIM_INT__p_s_g_s, PRIM_PTR_INT__p_s_g_s);
430                         PRIM_PTR_INT__p_s_d_s += lastoffset*18;
431                         PRIM_PTR_INT__p_s_f_s += lastoffset*30;
432                         PRIM_PTR_INT__p_s_g_s += lastoffset*45;
433                     }
434 
435                 }  // close loop over j
436             }  // close loop over i
437 
438             //Advance to the next batch
439             jstart = SIMINT_SIMD_ROUND(jend);
440 
441             //////////////////////////////////////////////
442             // Contracted integrals: Horizontal recurrance
443             //////////////////////////////////////////////
444 
445 
446 
447 
448             for(abcd = 0; abcd < nshellbatch; ++abcd, ++real_abcd)
449             {
450                 const double hCD[3] = { Q.AB_x[cd+abcd], Q.AB_y[cd+abcd], Q.AB_z[cd+abcd] };
451 
452                 // set up HRR pointers
453                 double const * restrict HRR_INT__p_s_d_s = INT__p_s_d_s + abcd * 18;
454                 double const * restrict HRR_INT__p_s_f_s = INT__p_s_f_s + abcd * 30;
455                 double const * restrict HRR_INT__p_s_g_s = INT__p_s_g_s + abcd * 45;
456                 double * restrict HRR_INT__p_s_d_d = INT__p_s_d_d + real_abcd * 108;
457 
458                 // form INT__p_s_d_p
459                 for(ibra = 0; ibra < 3; ++ibra)
460                 {
461                     HRR_INT__p_s_d_p[ibra * 18 + 0] = HRR_INT__p_s_f_s[ibra * 10 + 0] + ( hCD[0] * HRR_INT__p_s_d_s[ibra * 6 + 0] );
462 
463                     HRR_INT__p_s_d_p[ibra * 18 + 1] = HRR_INT__p_s_f_s[ibra * 10 + 1] + ( hCD[1] * HRR_INT__p_s_d_s[ibra * 6 + 0] );
464 
465                     HRR_INT__p_s_d_p[ibra * 18 + 2] = HRR_INT__p_s_f_s[ibra * 10 + 2] + ( hCD[2] * HRR_INT__p_s_d_s[ibra * 6 + 0] );
466 
467                     HRR_INT__p_s_d_p[ibra * 18 + 3] = HRR_INT__p_s_f_s[ibra * 10 + 1] + ( hCD[0] * HRR_INT__p_s_d_s[ibra * 6 + 1] );
468 
469                     HRR_INT__p_s_d_p[ibra * 18 + 4] = HRR_INT__p_s_f_s[ibra * 10 + 3] + ( hCD[1] * HRR_INT__p_s_d_s[ibra * 6 + 1] );
470 
471                     HRR_INT__p_s_d_p[ibra * 18 + 5] = HRR_INT__p_s_f_s[ibra * 10 + 4] + ( hCD[2] * HRR_INT__p_s_d_s[ibra * 6 + 1] );
472 
473                     HRR_INT__p_s_d_p[ibra * 18 + 6] = HRR_INT__p_s_f_s[ibra * 10 + 2] + ( hCD[0] * HRR_INT__p_s_d_s[ibra * 6 + 2] );
474 
475                     HRR_INT__p_s_d_p[ibra * 18 + 7] = HRR_INT__p_s_f_s[ibra * 10 + 4] + ( hCD[1] * HRR_INT__p_s_d_s[ibra * 6 + 2] );
476 
477                     HRR_INT__p_s_d_p[ibra * 18 + 8] = HRR_INT__p_s_f_s[ibra * 10 + 5] + ( hCD[2] * HRR_INT__p_s_d_s[ibra * 6 + 2] );
478 
479                     HRR_INT__p_s_d_p[ibra * 18 + 9] = HRR_INT__p_s_f_s[ibra * 10 + 3] + ( hCD[0] * HRR_INT__p_s_d_s[ibra * 6 + 3] );
480 
481                     HRR_INT__p_s_d_p[ibra * 18 + 10] = HRR_INT__p_s_f_s[ibra * 10 + 6] + ( hCD[1] * HRR_INT__p_s_d_s[ibra * 6 + 3] );
482 
483                     HRR_INT__p_s_d_p[ibra * 18 + 11] = HRR_INT__p_s_f_s[ibra * 10 + 7] + ( hCD[2] * HRR_INT__p_s_d_s[ibra * 6 + 3] );
484 
485                     HRR_INT__p_s_d_p[ibra * 18 + 12] = HRR_INT__p_s_f_s[ibra * 10 + 4] + ( hCD[0] * HRR_INT__p_s_d_s[ibra * 6 + 4] );
486 
487                     HRR_INT__p_s_d_p[ibra * 18 + 13] = HRR_INT__p_s_f_s[ibra * 10 + 7] + ( hCD[1] * HRR_INT__p_s_d_s[ibra * 6 + 4] );
488 
489                     HRR_INT__p_s_d_p[ibra * 18 + 14] = HRR_INT__p_s_f_s[ibra * 10 + 8] + ( hCD[2] * HRR_INT__p_s_d_s[ibra * 6 + 4] );
490 
491                     HRR_INT__p_s_d_p[ibra * 18 + 15] = HRR_INT__p_s_f_s[ibra * 10 + 5] + ( hCD[0] * HRR_INT__p_s_d_s[ibra * 6 + 5] );
492 
493                     HRR_INT__p_s_d_p[ibra * 18 + 16] = HRR_INT__p_s_f_s[ibra * 10 + 8] + ( hCD[1] * HRR_INT__p_s_d_s[ibra * 6 + 5] );
494 
495                     HRR_INT__p_s_d_p[ibra * 18 + 17] = HRR_INT__p_s_f_s[ibra * 10 + 9] + ( hCD[2] * HRR_INT__p_s_d_s[ibra * 6 + 5] );
496 
497                 }
498 
499                 // form INT__p_s_f_p
500                 HRR_L_f_p(
501                     HRR_INT__p_s_f_p,
502                     HRR_INT__p_s_f_s,
503                     HRR_INT__p_s_g_s,
504                     hCD, 3);
505 
506                 // form INT__p_s_d_d
507                 HRR_L_d_d(
508                     HRR_INT__p_s_d_d,
509                     HRR_INT__p_s_d_p,
510                     HRR_INT__p_s_f_p,
511                     hCD, 3);
512 
513 
514             }  // close HRR loop
515 
516 
517         }   // close loop cdbatch
518 
519         istart = iend;
520     }  // close loop over ab
521 
522     return P.nshell12_clip * Q.nshell12_clip;
523 }
524 
525