Eric S. Raymond writes: > Fortunately, we have good regression tests for those macros. So if you want > to submit a simplification MR, feel free.
Here's that patch. Tests are still clean of course. I have not removed the distinction between signed and unsigned where it makes no difference to the result.
>From ed6acb5df18b7917ee390ad74548153b049fb801 Mon Sep 17 00:00:00 2001 From: Achim Gratz <strom...@stromeko.de> Date: Sat, 25 Feb 2017 12:48:48 +0100 Subject: [PATCH 2/2] Simplify l_fp access macros since the code is assuming POSIX/C99 * include/ntp_fp.h: Remove magic constants and rely on C99 cast semantics instead. --- include/ntp_fp.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/include/ntp_fp.h b/include/ntp_fp.h index 2f15124..741bb46 100644 --- a/include/ntp_fp.h +++ b/include/ntp_fp.h @@ -30,17 +30,16 @@ * */ typedef uint64_t l_fp; -#define LOW32 0x00000000ffffffffUL -#define HIGH32 0xffffffff00000000UL -#define BUMP 0x0000000100000000UL -#define lfpfrac(n) ((uint32_t)((n) & LOW32)) -#define setlfpfrac(n, v) (n) = (((n) & HIGH32) | ((v) & LOW32)) -#define lfpsint(n) (int32_t)(((n) & HIGH32) >> 32) -#define setlfpsint(n, v) (n) = (int64_t)((((int64_t)(v)) << 32) | ((n) & LOW32)) -#define bumplfpsint(n, i) (n) += (i)*BUMP -#define lfpuint(n) (uint32_t)(((n) & HIGH32) >> 32) -#define setlfpuint(n, v) (n) = (uint64_t)((((uint64_t)(v)) << 32) | ((n) & LOW32)) -#define bumplfpuint(n, i) (n) += (i)*BUMP +#define lfpfrac(n) ((uint32_t)(n)) +#define lfptosint(n) (( int64_t)((n) << 32)) +#define lfptouint(n) ((uint64_t)((n) << 32)) +#define lfpsint(n) (( int32_t)((n) >> 32)) +#define lfpuint(n) ((uint32_t)((n) >> 32)) +#define bumplfpsint(n, i) ((l_fp)(n) += lfptosint(i)) +#define bumplfpuint(n, i) ((l_fp)(n) += lfptouint(i)) +#define setlfpfrac(n, v) ((l_fp)(n) = lfptouint(lfpuint(n)) | lfpfrac(v)) +#define setlfpsint(n, v) ((l_fp)(n) = lfptosint(v) | lfpfrac(n)) +#define setlfpuint(n, v) ((l_fp)(n) = lfptouint(v) | lfpfrac(n)) static inline l_fp lfpinit(int32_t hi, uint32_t lo) { -- 2.1.4
Regards, Achim. -- +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+ SD adaptation for Waldorf microQ V2.22R2: http://Synth.Stromeko.net/Downloads.html#WaldorfSDada
_______________________________________________ devel mailing list devel@ntpsec.org http://lists.ntpsec.org/mailman/listinfo/devel