Lines Matching +full:a +full:- +full:h

1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/types.h>
6 #include <linux/limits.h>
7 #include <linux/math.h>
8 #include <linux/math64.h>
13 * u128_u: u128 user mode, because not all architectures support a real int128
26 static inline u128_u u64_to_u128(u64 a) in u64_to_u128() argument
28 return (u128_u) { .v = a }; in u64_to_u128()
31 static inline u64 u128_lo(u128_u a) in u128_lo() argument
33 return a.v; in u128_lo()
36 static inline u64 u128_hi(u128_u a) in u128_hi() argument
38 return a.v >> 64; in u128_hi()
41 static inline u128_u u128_add(u128_u a, u128_u b) in u128_add() argument
43 a.v += b.v; in u128_add()
44 return a; in u128_add()
47 static inline u128_u u128_sub(u128_u a, u128_u b) in u128_sub() argument
49 a.v -= b.v; in u128_sub()
50 return a; in u128_sub()
53 static inline u128_u u128_shl(u128_u a, s8 shift) in u128_shl() argument
55 a.v <<= shift; in u128_shl()
56 return a; in u128_shl()
59 static inline u128_u u128_square(u64 a) in u128_square() argument
61 u128_u b = u64_to_u128(a); in u128_square()
75 static inline u128_u u64_to_u128(u64 a) in u64_to_u128() argument
77 return (u128_u) { .lo = a }; in u64_to_u128()
80 static inline u64 u128_lo(u128_u a) in u128_lo() argument
82 return a.lo; in u128_lo()
85 static inline u64 u128_hi(u128_u a) in u128_hi() argument
87 return a.hi; in u128_hi()
92 static inline u128_u u128_add(u128_u a, u128_u b) in u128_add() argument
96 c.lo = a.lo + b.lo; in u128_add()
97 c.hi = a.hi + b.hi + (c.lo < a.lo); in u128_add()
101 static inline u128_u u128_sub(u128_u a, u128_u b) in u128_sub() argument
105 c.lo = a.lo - b.lo; in u128_sub()
106 c.hi = a.hi - b.hi - (c.lo > a.lo); in u128_sub()
116 r.hi = (i.hi << (shift & 63)) | (i.lo >> (-shift & 63)); in u128_shl()
118 r.hi = i.lo << (-shift & 63); in u128_shl()
127 u64 h = i >> 32, l = i & U32_MAX; in u128_square() local
129 r = u128_shl(u64_to_u128(h*h), 64); in u128_square()
130 r = u128_add(r, u128_shl(u64_to_u128(h*l), 32)); in u128_square()
131 r = u128_add(r, u128_shl(u64_to_u128(l*h), 32)); in u128_square()
162 * fast_divpow2() - fast approximation for n / (1 << d)
170 return (n + ((n < 0) ? ((1 << d) - 1) : 0)) >> d; in fast_divpow2()
174 * mean_and_variance_update() - update a mean_and_variance struct @s1 with a new sample @v1
184 s->n++; in mean_and_variance_update()
185 s->sum += v; in mean_and_variance_update()
186 s->sum_squares = u128_add(s->sum_squares, u128_square(abs(v))); in mean_and_variance_update()