1 /*
2     Copyright (C) 2021 Fredrik Johansson
3 
4     This file is part of Arb.
5 
6     Arb is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include "acb.h"
13 
14 static void
arf_shallow_set_uiui(arf_t res,ulong vhi,ulong vlo)15 arf_shallow_set_uiui(arf_t res, ulong vhi, ulong vlo)
16 {
17     unsigned int bc;
18 
19     if (vhi == 0)
20     {
21         if (vlo == 0)
22         {
23             ARF_XSIZE(res) = 0;
24             ARF_EXP(res) = ARF_EXP_ZERO;
25         }
26         else
27         {
28             count_leading_zeros(bc, vlo);
29             ARF_EXP(res) = FLINT_BITS - bc;
30             ARF_NOPTR_D(res)[0] = vlo << bc;
31             ARF_XSIZE(res) = ARF_MAKE_XSIZE(1, 0);
32         }
33     }
34     else if (vlo == 0)
35     {
36         count_leading_zeros(bc, vhi);
37         ARF_EXP(res) = 2 * FLINT_BITS - bc;
38         ARF_NOPTR_D(res)[0] = vhi << bc;
39         ARF_XSIZE(res) = ARF_MAKE_XSIZE(1, 0);
40     }
41     else
42     {
43         count_leading_zeros(bc, vhi);
44         ARF_EXP(res) = 2 * FLINT_BITS - bc;
45         ARF_NOPTR_D(res)[0] = vlo << bc;
46         if (bc == 0)
47             ARF_NOPTR_D(res)[1] = vhi;
48         else
49             ARF_NOPTR_D(res)[1] = (vhi << bc) | (vlo >> (FLINT_BITS - bc));
50         ARF_XSIZE(res) = ARF_MAKE_XSIZE(2, 0);
51     }
52 }
53 
54 void
acb_dot_uiui(acb_t res,const acb_t initial,int subtract,acb_srcptr x,slong xstep,const ulong * y,slong ystep,slong len,slong prec)55 acb_dot_uiui(acb_t res, const acb_t initial, int subtract, acb_srcptr x, slong xstep, const ulong * y, slong ystep, slong len, slong prec)
56 {
57     arb_ptr t;
58     slong i;
59     ulong vhi, vlo;
60     TMP_INIT;
61 
62     /* todo: fast fma and fmma (len=2) code */
63     if (len <= 1)
64     {
65         if (initial == NULL)
66         {
67             if (len <= 0)
68                 acb_zero(res);
69             else
70             {
71                 arf_t t;
72                 arf_shallow_set_uiui(t, y[1], y[0]);
73                 arb_mul_arf(acb_realref(res), acb_realref(x), t, prec);
74                 arb_mul_arf(acb_imagref(res), acb_imagref(x), t, prec);
75                 if (subtract)
76                     acb_neg(res, res);
77             }
78             return;
79         }
80         else if (len <= 0)
81         {
82             acb_set_round(res, initial, prec);
83             return;
84         }
85     }
86 
87     TMP_START;
88     t = TMP_ALLOC(sizeof(arb_struct) * len);
89 
90     for (i = 0; i < len; i++)
91     {
92         vlo = y[2 * i * ystep];
93         vhi = y[2 * i * ystep + 1];
94 
95         arf_shallow_set_uiui(arb_midref(t + i), vhi, vlo);
96 
97         MAG_EXP(arb_radref(t + i)) = 0;
98         MAG_MAN(arb_radref(t + i)) = 0;
99     }
100 
101     arb_dot(((arb_ptr) res) + 0, (initial == NULL) ? NULL : ((arb_srcptr) initial) + 0, subtract, ((arb_srcptr) x) + 0, 2 * xstep, t, 1, len, prec);
102     arb_dot(((arb_ptr) res) + 1, (initial == NULL) ? NULL : ((arb_srcptr) initial) + 1, subtract, ((arb_srcptr) x) + 1, 2 * xstep, t, 1, len, prec);
103 
104     TMP_END;
105 }
106 
107