From 8ff32af323eb3c6554a3495c01cc43ba089d36d5 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 28 Oct 2018 22:51:57 +0000 Subject: [PATCH] symm/blkc.h: Define a new `BLKC_ADD' macro. And rewrite `BLKC_STEP' in terms of it. --- symm/blkc.h | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/symm/blkc.h b/symm/blkc.h index 608dfcd0..5e996e8b 100644 --- a/symm/blkc.h +++ b/symm/blkc.h @@ -95,9 +95,11 @@ BLKC_GLUE(BLKC_XMOVE_, BLKC_TYPE(PRE)) \ (PRE, w, wx, BLKC_BITS(PRE)) -#define BLKC_STEP(PRE, w) \ - BLKC_GLUE(BLKC_STEP_X_, BLKC_ENDIAN(PRE)) \ - (PRE, w) +#define BLKC_STEP(PRE, w) BLKC_ADD(PRE, w, 1) + +#define BLKC_ADD(PRE, w, n) \ + BLKC_GLUE(BLKC_ADD_X_, BLKC_ENDIAN(PRE)) \ + (PRE, w, n) #define BLKC_ZERO(PRE, w) \ BLKC_GLUE(BLKC_ZERO_, BLKC_TYPE(PRE)) \ @@ -113,6 +115,24 @@ fputc('\n', stdout); \ } while (0) +/* --- Utilities --- * + * + * These seem too hard to properly generalize, or I'd have put them in + * . + */ + +#ifdef HAVE_UINT64 +# define BLKC_ADDC32(z_out, c_out, x, y) do { \ + uint64 _t = (uint64)(x) + (y); \ + (z_out) = U32(_t); (c_out) = _t >> 32; \ + } while (0) +#else +# define BLKC_ADDC32(z_out, c_out, x, y) do { \ + uint32 _x = (x), _c = 0, _t; \ + _t = U32(_x + (y)); (z_out) = _t; (c_out) = (_t < _x); \ + } while (0) +#endif + /* --- General implementation skeleton --- */ #define BLKC_SKEL(PRE, decl, guts) do { \ @@ -159,15 +179,15 @@ #define BLKC_ZERO_X(PRE, w, n) \ BLKC_SKEL_X(PRE, BLKC_W(w);, *_w++ = 0;) -#define BLKC_STEP_X_B(PRE, w) do { \ - unsigned _i = PRE##_BLKSZ/4; BLKC_W(w); uint32 _x = 0; \ - while (_i && !_x) { _i--; _w[_i] = _x = U32(_w[_i] + 1); } \ +#define BLKC_ADD_X_B(PRE, w, n) do { \ + unsigned _i = PRE##_BLKSZ/4; BLKC_W(w); uint32 _n = (n); \ + while (_i-- && _n) BLKC_ADDC32(_w[_i], _n, _w[_i], _n); \ } while (0) -#define BLKC_STEP_X_L(PRE, w) do { \ - unsigned _i = 0; BLKC_W(w); uint32 _x = 0; \ - while (_i < PRE##_BLKSZ/4 && !_x) \ - { _w[_i] = _x = U32(_w[_i] + 1); _i++; } \ +#define BLKC_ADD_X_L(PRE, w, n) do { \ + unsigned _i = 0; BLKC_W(w); uint32 _n = (n); \ + while (_i < PRE##_BLKSZ/4 && _n) \ + { BLKC_ADDC32(_w[_i], _n, _w[_i], _n); _i++; } \ } while (0) #define BLKC_SET_X_B(PRE, w, x) do { \ -- 2.11.0