Debian Codegraph @

src/multiply.h

raw symbols SCIP
1 #ifndef _MULTIPLY_H
2 #define _MULTIPLY_H
3
4 #include "common.h"
5
6 /**
7 * Double-precision multiplication
8 */
9 #if defined(HAVE_UINT128)
10
11 #define DP_MULT(a,b,ol,oh) do { \
12 __uint128_t pr; \
13 pr = (__uint128_t)(a)*(b); \
14 ol = (uint64_t)pr; \
15 oh = (uint64_t)(pr >> 64); \
16 } while (0)
17
18 #elif defined(_MSC_VER) && (defined(_M_X64) || defined(__x86_64__))
19
20 #include <intrin.h>
21 #define DP_MULT(a,b,ol,oh) do { ol = _umul128(a,b,&oh); } while (0)
22
23 #elif defined(_MSC_VER) && defined(_M_ARM64)
24
25 #include <intrin.h>
26 #define DP_MULT(a,b,ol,oh) do { \
27 ol = ((uint64_t)(a))*(b); \
28 oh = __umulh(a, b); \
29 } while (0)
30
31 #else
32
33 static inline uint64_t dp_mult_128_32(uint64_t a, uint64_t b, uint64_t *oh);
34
35 static inline uint64_t dp_mult_128_32(uint64_t a, uint64_t b, uint64_t *oh)
36 {
37 uint32_t al = (uint32_t) a;
38 uint32_t ah = (uint32_t)(a >> 32);
39 uint32_t bl = (uint32_t) b;
40 uint32_t bh = (uint32_t)(b >> 32);
41
42 uint64_t sum0, sum1a, sum1b, sum2, sum3;
43
44 sum0 = (uint64_t)al*bl;
45 sum1a = (uint64_t)al*bh;
46 sum1b = (uint64_t)ah*bl;
47 sum2 = (uint64_t)ah*bh;
48
49 sum1a += sum0 >> 32;
50 sum1b += sum1a;
51 sum3 = sum1b < sum1a;
52 sum2 += sum1b >> 32;
53 sum3 += sum2 >> 32;
54
55 *oh = (sum3 << 32) + (uint32_t)sum2;
56 return (sum1b << 32) + (uint32_t)sum0;
57 }
58
59 #define DP_MULT(a,b,ol,oh) do { ol = dp_mult_128_32(a,b,&oh); } while (0)
60
61 #endif
62
63 /*
64 * Square an integer a[].
65 *
66 * @param t Location where the result is stored, 2*nw words.
67 * @param scratchpad Temporary space, 3*nw words.
68 * @param a Integer to square, nw words.
69 * @param nw Size of the integer a[], in 64-bit words.
70 */
71 void square(uint64_t *t, uint64_t *scratchpad, const uint64_t *a, size_t nw);
72
73 /*
74 * Multiply an integer a[] by a 128-bit scalar, and add the result to integer t[].
75 *
76 * @param t Integer where the result of the multiplication is added
77 * to, t_nw words.
78 * @param scratchpad Temporary space, with t_nw+a_nw words.
79 * @param a Integer to multiply by the scalar, a_nw words.
80 * @param b0 Lower 64 bits of the scalar
81 * @param b1 Higher 64 bits of the scalar
82 * @param t_nw Size of integer t[], in 64-bit words. It must be at least a_nw+2.
83 * @param a_nw Size of integer a[], in 64-bit words.
84 */
85 void addmul128(uint64_t *t, uint64_t *scratchpad, const uint64_t * a, uint64_t b0, uint64_t b1, size_t t_nw, size_t a_nw);
86 #endif