diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-09-25 18:43:36 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-09-25 18:43:36 +0200 |
commit | 5fc99de1f5542554ed02edb0b5f6f43ceea3c09d (patch) | |
tree | be81f90f96db4c5a70022f3c6b6ca4460665f6f4 | |
parent | 67b80a01a681870031a81960a2ae310c367827a8 (diff) |
Improve code readability.
-rw-r--r-- | src/new.c | 10 | ||||
-rw-r--r-- | src/new32.c | 10 | ||||
-rw-r--r-- | src/new32v2.c | 2 |
3 files changed, 11 insertions, 11 deletions
@@ -9,16 +9,16 @@ static const uint64_t divtab[244] = { [243] = 0x010db20a + 1l }; -#define FASTDIV(n, C) (((n) * (C)) >> 32) -#define FASTMOD(n, d, C) ((n) - (d) * FASTDIV((n), (C))) +#define FASTDIV(n, d) (((n) * divtab[d]) >> 32) +#define FASTMOD(n, d) ((n) - (d) * FASTDIV((n), (d))) int new(int i, int x, int y) { uint64_t A, B, C; - A = FASTDIV(i, divtab[y]); - B = FASTMOD(A, 3, divtab[3]); - C = FASTMOD(A + (uint64_t)x, 3, divtab[3]); + A = FASTDIV(i, y); + B = FASTMOD(A, 3); + C = FASTMOD(A + (uint64_t)x, 3); return i + (C - B) * y; } diff --git a/src/new32.c b/src/new32.c index 9136115..654b793 100644 --- a/src/new32.c +++ b/src/new32.c @@ -9,16 +9,16 @@ static const unsigned int divtab[244] = { [243] = 0x010d + 1l }; -#define FASTDIV(n, C) (((n) * (C)) >> 16) -#define FASTMOD(n, d, C) ((n) - (d) * FASTDIV((n), (C))) +#define FASTDIV(n, d) (((n) * divtab[d]) >> 16) +#define FASTMOD(n, d) ((n) - (d) * FASTDIV((n), (d))) int new32(int i, int x, int y) { int A, B, C; - A = FASTDIV(i, divtab[y]); - B = FASTMOD(A, 3, divtab[3]); - C = FASTMOD(A + x, 3, divtab[3]); + A = FASTDIV(i, y); + B = FASTMOD(A, 3); + C = FASTMOD(A + x, 3); return i + (C - B) * y; } diff --git a/src/new32v2.c b/src/new32v2.c index a755d6d..1fd4c6f 100644 --- a/src/new32v2.c +++ b/src/new32v2.c @@ -9,7 +9,7 @@ static const unsigned int divtab[244] = { [243] = 0x010d + 1l }; -#define FASTDIV(n, d) (((n) * (divtab[d])) >> 16) +#define FASTDIV(n, d) (((n) * divtab[d]) >> 16) int new32v2(int i, int x, int y) { |