[Git][NTPsec/ntpsec][master] Simplify l_fp access macros since the code is assuming POSIX/C99

Eric S. Raymond gitlab at mg.gitlab.com
Wed Mar 1 18:41:55 UTC 2017


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
7e30e0e2 by Achim Gratz at 2017-03-01T13:41:15-05:00
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.

- - - - -


1 changed file:

- include/ntp_fp.h


Changes:

=====================================
include/ntp_fp.h
=====================================
--- 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)((uint64_t)(n) << 32))
+#define lfptouint(n)	        ((uint64_t)((uint64_t)(n) << 32))
+#define lfpsint(n)		(( int32_t)((n) >> 32))
+#define lfpuint(n)		((uint32_t)((n) >> 32))
+#define bumplfpsint(n, i)       ((n) += lfptosint(i))
+#define bumplfpuint(n, i)       ((n) += lfptouint(i))
+#define setlfpfrac(n, v)        ((n)  = (lfptouint(lfpuint(n)) | lfpfrac(v)))
+#define setlfpsint(n, v)        ((n)  = (lfptosint(v) | lfpfrac(n)))
+#define setlfpuint(n, v)        ((n)  = (lfptouint(v) | lfpfrac(n)))
 
 static inline l_fp lfpinit(int32_t hi, uint32_t lo)
 {



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/7e30e0e21ea904c80a59abf34d6266e83504a042
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170301/c5c42600/attachment.html>


More information about the vc mailing list