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