On 10/19/21 2:47 AM, Frédéric Pétrot wrote:
+static inline void divrem128(uint64_t ul, uint64_t uh,
+ uint64_t vl, uint64_t vh,
+ uint64_t *ql, uint64_t *qh,
+ uint64_t *rl, uint64_t *rh)
I think we should move all of the division implementation out of the header; this is
really much too large to inline.
I think util/int128.c would be a reasonable place.
That said, why are you splitting the Int128 apart to pass as pieces here? Seems like
passing the Int128 and doing the split inside would make more sense.
+ /* never happens, but makes gcc shy */
+ n = 0;
Then g_assert_not_reached(), or change the previous if to an assert.
Hmm, it's not "never happens" so much as "divide by zero".
Please update the comment accordingly.
+ if (r != NULL) {
+ r[0] = k;
+ }
r is a local array; useless check for null.
+ s = clz32(v[n - 1]); /* 0 <= s <= 32 */
+ if (s != 0) {
+ for (i = n - 1; i > 0; i--) {
+ vn[i] = ((v[i] << s) | (v[i - 1] >> (32 - s)));
+ }
+ vn[0] = v[0] << s;
+
+ un[m] = u[m - 1] >> (32 - s);
+ for (i = m - 1; i > 0; i--) {
+ un[i] = (u[i] << s) | (u[i - 1] >> (32 - s));
+ }
+ un[0] = u[0] << s;
Why are you shifting the 128-bit value in 4 parts, rather than letting int128_lshift do
the job?
r~