qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 03/21] Int128.h: addition of a few 128-bit operations


From: Richard Henderson
Subject: Re: [PATCH v3 03/21] Int128.h: addition of a few 128-bit operations
Date: Tue, 19 Oct 2021 11:15:20 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

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~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]