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_s_p_s_p(struct simint_multi_shellpair const P,struct simint_multi_shellpair const Q,double screen_tol,double * const restrict work,double * const restrict INT__s_p_s_p)8 int ostei_s_p_s_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__s_p_s_p)
13 {
14 
15     SIMINT_ASSUME_ALIGN_DBL(work);
16     SIMINT_ASSUME_ALIGN_DBL(INT__s_p_s_p);
17     memset(INT__s_p_s_p, 0, P.nshell12_clip * Q.nshell12_clip * 9 * sizeof(double));
18 
19     int ab, cd, abcd;
20     int istart, jstart;
21     int iprimcd, nprim_icd, icd;
22     const int check_screen = (screen_tol > 0.0);
23     int i, j;
24     int n;
25     int not_screened;
26 
27     // partition workspace
28     SIMINT_DBLTYPE * const primwork = (SIMINT_DBLTYPE *)(work + SIMINT_NSHELL_SIMD*0);
29     SIMINT_DBLTYPE * const restrict PRIM_INT__s_s_s_s = primwork + 0;
30     SIMINT_DBLTYPE * const restrict PRIM_INT__s_p_s_s = primwork + 3;
31     SIMINT_DBLTYPE * const restrict PRIM_INT__s_p_s_p = primwork + 9;
32     double * const hrrwork = (double *)(primwork + 18);
33 
34 
35     // Create constants
36     const SIMINT_DBLTYPE const_1 = SIMINT_DBLSET1(1);
37     const SIMINT_DBLTYPE one_half = SIMINT_DBLSET1(0.5);
38 
39 
40     ////////////////////////////////////////
41     // Loop over shells and primitives
42     ////////////////////////////////////////
43 
44     abcd = 0;
45     istart = 0;
46     for(ab = 0; ab < P.nshell12_clip; ++ab)
47     {
48         const int iend = istart + P.nprim12[ab];
49 
50         cd = 0;
51         jstart = 0;
52 
53         for(cd = 0; cd < Q.nshell12_clip; cd += SIMINT_NSHELL_SIMD)
54         {
55             const int nshellbatch = ((cd + SIMINT_NSHELL_SIMD) > Q.nshell12_clip) ? Q.nshell12_clip - cd : SIMINT_NSHELL_SIMD;
56             int jend = jstart;
57             for(i = 0; i < nshellbatch; i++)
58                 jend += Q.nprim12[cd+i];
59 
60 
61             for(i = istart; i < iend; ++i)
62             {
63                 SIMINT_DBLTYPE bra_screen_max;  // only used if check_screen
64 
65                 if(check_screen)
66                 {
67                     // Skip this whole thing if always insignificant
68                     if((P.screen[i] * Q.screen_max) < screen_tol)
69                         continue;
70                     bra_screen_max = SIMINT_DBLSET1(P.screen[i]);
71                 }
72 
73                 icd = 0;
74                 iprimcd = 0;
75                 nprim_icd = Q.nprim12[cd];
76                 double * restrict PRIM_PTR_INT__s_p_s_p = INT__s_p_s_p + abcd * 9;
77 
78 
79 
80                 // Load these one per loop over i
81                 const SIMINT_DBLTYPE P_alpha = SIMINT_DBLSET1(P.alpha[i]);
82                 const SIMINT_DBLTYPE P_prefac = SIMINT_DBLSET1(P.prefac[i]);
83                 const SIMINT_DBLTYPE Pxyz[3] = { SIMINT_DBLSET1(P.x[i]), SIMINT_DBLSET1(P.y[i]), SIMINT_DBLSET1(P.z[i]) };
84 
85                 const SIMINT_DBLTYPE P_PB[3] = { SIMINT_DBLSET1(P.PB_x[i]), SIMINT_DBLSET1(P.PB_y[i]), SIMINT_DBLSET1(P.PB_z[i]) };
86 
87                 for(j = jstart; j < jend; j += SIMINT_SIMD_LEN)
88                 {
89                     // calculate the shell offsets
90                     // these are the offset from the shell pointed to by cd
91                     // for each element
92                     int shelloffsets[SIMINT_SIMD_LEN] = {0};
93                     int lastoffset = 0;
94                     const int nlane = ( ((j + SIMINT_SIMD_LEN) < jend) ? SIMINT_SIMD_LEN : (jend - j));
95 
96                     if((iprimcd + SIMINT_SIMD_LEN) >= nprim_icd)
97                     {
98                         // Handle if the first element of the vector is a new shell
99                         if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
100                         {
101                             nprim_icd += Q.nprim12[cd + (++icd)];
102                             PRIM_PTR_INT__s_p_s_p += 9;
103                         }
104                         iprimcd++;
105                         for(n = 1; n < SIMINT_SIMD_LEN; ++n)
106                         {
107                             if(iprimcd >= nprim_icd && ((icd+1) < nshellbatch))
108                             {
109                                 shelloffsets[n] = shelloffsets[n-1] + 1;
110                                 lastoffset++;
111                                 nprim_icd += Q.nprim12[cd + (++icd)];
112                             }
113                             else
114                                 shelloffsets[n] = shelloffsets[n-1];
115                             iprimcd++;
116                         }
117                     }
118                     else
119                         iprimcd += SIMINT_SIMD_LEN;
120 
121                     // Do we have to compute this vector (or has it been screened out)?
122                     // (not_screened != 0 means we have to do this vector)
123                     if(check_screen)
124                     {
125                         const double vmax = vector_max(SIMINT_MUL(bra_screen_max, SIMINT_DBLLOAD(Q.screen, j)));
126                         if(vmax < screen_tol)
127                         {
128                             PRIM_PTR_INT__s_p_s_p += lastoffset*9;
129                             continue;
130                         }
131                     }
132 
133                     const SIMINT_DBLTYPE Q_alpha = SIMINT_DBLLOAD(Q.alpha, j);
134                     const SIMINT_DBLTYPE PQalpha_mul = SIMINT_MUL(P_alpha, Q_alpha);
135                     const SIMINT_DBLTYPE PQalpha_sum = SIMINT_ADD(P_alpha, Q_alpha);
136                     const SIMINT_DBLTYPE one_over_PQalpha_sum = SIMINT_DIV(const_1, PQalpha_sum);
137 
138 
139                     /* construct R2 = (Px - Qx)**2 + (Py - Qy)**2 + (Pz -Qz)**2 */
140                     SIMINT_DBLTYPE PQ[3];
141                     PQ[0] = SIMINT_SUB(Pxyz[0], SIMINT_DBLLOAD(Q.x, j));
142                     PQ[1] = SIMINT_SUB(Pxyz[1], SIMINT_DBLLOAD(Q.y, j));
143                     PQ[2] = SIMINT_SUB(Pxyz[2], SIMINT_DBLLOAD(Q.z, j));
144                     SIMINT_DBLTYPE R2 = SIMINT_MUL(PQ[0], PQ[0]);
145                     R2 = SIMINT_FMADD(PQ[1], PQ[1], R2);
146                     R2 = SIMINT_FMADD(PQ[2], PQ[2], R2);
147 
148                     const SIMINT_DBLTYPE alpha = SIMINT_MUL(PQalpha_mul, one_over_PQalpha_sum); // alpha from MEST
149                     const SIMINT_DBLTYPE one_over_p = SIMINT_DIV(const_1, P_alpha);
150                     const SIMINT_DBLTYPE one_over_q = SIMINT_DIV(const_1, Q_alpha);
151                     const SIMINT_DBLTYPE one_over_2p = SIMINT_MUL(one_half, one_over_p);
152                     const SIMINT_DBLTYPE one_over_2q = SIMINT_MUL(one_half, one_over_q);
153                     const SIMINT_DBLTYPE one_over_2pq = SIMINT_MUL(one_half, one_over_PQalpha_sum);
154                     const SIMINT_DBLTYPE Q_PB[3] = { SIMINT_DBLLOAD(Q.PB_x, j), SIMINT_DBLLOAD(Q.PB_y, j), SIMINT_DBLLOAD(Q.PB_z, j) };
155 
156                     // NOTE: Minus sign!
157                     const SIMINT_DBLTYPE a_over_p = SIMINT_MUL(SIMINT_NEG(alpha), one_over_p);
158                     SIMINT_DBLTYPE aop_PQ[3];
159                     aop_PQ[0] = SIMINT_MUL(a_over_p, PQ[0]);
160                     aop_PQ[1] = SIMINT_MUL(a_over_p, PQ[1]);
161                     aop_PQ[2] = SIMINT_MUL(a_over_p, PQ[2]);
162 
163                     SIMINT_DBLTYPE a_over_q = SIMINT_MUL(alpha, one_over_q);
164                     SIMINT_DBLTYPE aoq_PQ[3];
165                     aoq_PQ[0] = SIMINT_MUL(a_over_q, PQ[0]);
166                     aoq_PQ[1] = SIMINT_MUL(a_over_q, PQ[1]);
167                     aoq_PQ[2] = SIMINT_MUL(a_over_q, PQ[2]);
168                     // Put a minus sign here so we don't have to in RR routines
169                     a_over_q = SIMINT_NEG(a_over_q);
170 
171 
172                     //////////////////////////////////////////////
173                     // Fjt function section
174                     // Maximum v value: 2
175                     //////////////////////////////////////////////
176                     // The parameter to the Fjt function
177                     const SIMINT_DBLTYPE F_x = SIMINT_MUL(R2, alpha);
178 
179 
180                     const SIMINT_DBLTYPE Q_prefac = mask_load(nlane, Q.prefac + j);
181 
182 
183                     boys_F_split(PRIM_INT__s_s_s_s, F_x, 2);
184                     SIMINT_DBLTYPE prefac = SIMINT_SQRT(one_over_PQalpha_sum);
185                     prefac = SIMINT_MUL(SIMINT_MUL(P_prefac, Q_prefac), prefac);
186                     for(n = 0; n <= 2; n++)
187                         PRIM_INT__s_s_s_s[n] = SIMINT_MUL(PRIM_INT__s_s_s_s[n], prefac);
188 
189                     //////////////////////////////////////////////
190                     // Primitive integrals: Vertical recurrance
191                     //////////////////////////////////////////////
192 
193                     const SIMINT_DBLTYPE vrr_const_1_over_2pq = one_over_2pq;
194 
195 
196 
197                     // Forming PRIM_INT__s_p_s_s[2 * 3];
198                     for(n = 0; n < 2; ++n)  // loop over orders of auxiliary function
199                     {
200 
201                         PRIM_INT__s_p_s_s[n * 3 + 0] = SIMINT_MUL(P_PB[0], PRIM_INT__s_s_s_s[n * 1 + 0]);
202                         PRIM_INT__s_p_s_s[n * 3 + 0] = SIMINT_FMADD( aop_PQ[0], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_p_s_s[n * 3 + 0]);
203 
204                         PRIM_INT__s_p_s_s[n * 3 + 1] = SIMINT_MUL(P_PB[1], PRIM_INT__s_s_s_s[n * 1 + 0]);
205                         PRIM_INT__s_p_s_s[n * 3 + 1] = SIMINT_FMADD( aop_PQ[1], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_p_s_s[n * 3 + 1]);
206 
207                         PRIM_INT__s_p_s_s[n * 3 + 2] = SIMINT_MUL(P_PB[2], PRIM_INT__s_s_s_s[n * 1 + 0]);
208                         PRIM_INT__s_p_s_s[n * 3 + 2] = SIMINT_FMADD( aop_PQ[2], PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_p_s_s[n * 3 + 2]);
209 
210                     }
211 
212 
213 
214                     // Forming PRIM_INT__s_p_s_p[1 * 9];
215                     for(n = 0; n < 1; ++n)  // loop over orders of auxiliary function
216                     {
217 
218                         PRIM_INT__s_p_s_p[n * 9 + 0] = SIMINT_MUL(Q_PB[0], PRIM_INT__s_p_s_s[n * 3 + 0]);
219                         PRIM_INT__s_p_s_p[n * 9 + 0] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_p_s_s[(n+1) * 3 + 0], PRIM_INT__s_p_s_p[n * 9 + 0]);
220                         PRIM_INT__s_p_s_p[n * 9 + 0] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_p_s_p[n * 9 + 0]);
221 
222                         PRIM_INT__s_p_s_p[n * 9 + 1] = SIMINT_MUL(Q_PB[1], PRIM_INT__s_p_s_s[n * 3 + 0]);
223                         PRIM_INT__s_p_s_p[n * 9 + 1] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_p_s_s[(n+1) * 3 + 0], PRIM_INT__s_p_s_p[n * 9 + 1]);
224 
225                         PRIM_INT__s_p_s_p[n * 9 + 2] = SIMINT_MUL(Q_PB[2], PRIM_INT__s_p_s_s[n * 3 + 0]);
226                         PRIM_INT__s_p_s_p[n * 9 + 2] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_p_s_s[(n+1) * 3 + 0], PRIM_INT__s_p_s_p[n * 9 + 2]);
227 
228                         PRIM_INT__s_p_s_p[n * 9 + 3] = SIMINT_MUL(Q_PB[0], PRIM_INT__s_p_s_s[n * 3 + 1]);
229                         PRIM_INT__s_p_s_p[n * 9 + 3] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_p_s_s[(n+1) * 3 + 1], PRIM_INT__s_p_s_p[n * 9 + 3]);
230 
231                         PRIM_INT__s_p_s_p[n * 9 + 4] = SIMINT_MUL(Q_PB[1], PRIM_INT__s_p_s_s[n * 3 + 1]);
232                         PRIM_INT__s_p_s_p[n * 9 + 4] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_p_s_s[(n+1) * 3 + 1], PRIM_INT__s_p_s_p[n * 9 + 4]);
233                         PRIM_INT__s_p_s_p[n * 9 + 4] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_p_s_p[n * 9 + 4]);
234 
235                         PRIM_INT__s_p_s_p[n * 9 + 5] = SIMINT_MUL(Q_PB[2], PRIM_INT__s_p_s_s[n * 3 + 1]);
236                         PRIM_INT__s_p_s_p[n * 9 + 5] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_p_s_s[(n+1) * 3 + 1], PRIM_INT__s_p_s_p[n * 9 + 5]);
237 
238                         PRIM_INT__s_p_s_p[n * 9 + 6] = SIMINT_MUL(Q_PB[0], PRIM_INT__s_p_s_s[n * 3 + 2]);
239                         PRIM_INT__s_p_s_p[n * 9 + 6] = SIMINT_FMADD( aoq_PQ[0], PRIM_INT__s_p_s_s[(n+1) * 3 + 2], PRIM_INT__s_p_s_p[n * 9 + 6]);
240 
241                         PRIM_INT__s_p_s_p[n * 9 + 7] = SIMINT_MUL(Q_PB[1], PRIM_INT__s_p_s_s[n * 3 + 2]);
242                         PRIM_INT__s_p_s_p[n * 9 + 7] = SIMINT_FMADD( aoq_PQ[1], PRIM_INT__s_p_s_s[(n+1) * 3 + 2], PRIM_INT__s_p_s_p[n * 9 + 7]);
243 
244                         PRIM_INT__s_p_s_p[n * 9 + 8] = SIMINT_MUL(Q_PB[2], PRIM_INT__s_p_s_s[n * 3 + 2]);
245                         PRIM_INT__s_p_s_p[n * 9 + 8] = SIMINT_FMADD( aoq_PQ[2], PRIM_INT__s_p_s_s[(n+1) * 3 + 2], PRIM_INT__s_p_s_p[n * 9 + 8]);
246                         PRIM_INT__s_p_s_p[n * 9 + 8] = SIMINT_FMADD( vrr_const_1_over_2pq, PRIM_INT__s_s_s_s[(n+1) * 1 + 0], PRIM_INT__s_p_s_p[n * 9 + 8]);
247 
248                     }
249 
250 
251 
252 
253                     ////////////////////////////////////
254                     // Accumulate contracted integrals
255                     ////////////////////////////////////
256                     if(lastoffset == 0)
257                     {
258                         contract_all(9, PRIM_INT__s_p_s_p, PRIM_PTR_INT__s_p_s_p);
259                     }
260                     else
261                     {
262                         contract(9, shelloffsets, PRIM_INT__s_p_s_p, PRIM_PTR_INT__s_p_s_p);
263                         PRIM_PTR_INT__s_p_s_p += lastoffset*9;
264                     }
265 
266                 }  // close loop over j
267             }  // close loop over i
268 
269             //Advance to the next batch
270             jstart = SIMINT_SIMD_ROUND(jend);
271             abcd += nshellbatch;
272 
273         }   // close loop cdbatch
274 
275         istart = iend;
276     }  // close loop over ab
277 
278     return P.nshell12_clip * Q.nshell12_clip;
279 }
280 
281