On 2020/3/14 13:58, Richard Henderson wrote:
On 3/12/20 7:58 AM, LIU Zhiwei wrote:
+#define DO_MADC(N, M, C) ((__typeof(N))(N + M + C) < N ? 1 : 0)
Incorrect.  E.g N = 1, M = UINT_MAX, C = 1, adds to 1, which is not less than
N, despite the carry-out.
Yes, it really the corner case. I should test C first.

Thanks for pointing that.

Zhiwei

You want

     C ? N + M <= N : N + M < N

+#define DO_MSBC(N, M, C) ((__typeof(N))(N - M - C) > N ? 1 : 0)
Similarly

     C ? N <= M : N < M


r~


Reply via email to