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