[Git][NTPsec/ntpsec][master] 2 commits: Simplify uint64 to lfp conversion.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Dec 26 23:57:25 UTC 2016


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


Commits:
6bbbe7ce by Eric S. Raymond at 2016-12-26T16:07:00-05:00
Simplify uint64 to lfp conversion.

- - - - -
b9db17ee by Eric S. Raymond at 2016-12-26T18:56:52-05:00
More elimination of grotty macros.

- - - - -


2 changed files:

- include/ntp_fp.h
- ntpd/ntp_proto.c


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -51,9 +51,11 @@ static inline uint64_t lfp_to_uint64(const l_fp lfp) {
     return (uint64_t)lfpuint(lfp) << 32 | (uint64_t)lfpfrac(lfp);
 }
 
-static inline void uint64_to_lfp(l_fp *lfp, uint64_t x) {
-  setlfpuint(*lfp, x >> 32);
-  setlfpfrac(*lfp, x & 0xFFFFFFFFUL);
+static inline l_fp uint64_to_lfp(uint64_t x) {
+    l_fp fp;
+    setlfpuint(fp, x >> 32);
+    setlfpfrac(fp, x & 0xFFFFFFFFUL);
+    return fp;
 }
 
 /*
@@ -157,13 +159,6 @@ typedef uint32_t u_fp;
 		(r_i) += (a_i) + ((uint32_t)(r_f) < add_t); \
 	} while (false)
 
-#define M_SUB(r_i, r_f, a_i, a_f)	/* r -= a */ \
-	do { \
-		uint32_t sub_t = (r_f); \
-		(r_f) -= (a_f); \
-		(r_i) -= (a_i) + ((uint32_t)(r_f) > sub_t); \
-	} while (false)
-
 #define	M_LSHIFT(v_i, v_f)		/* v <<= 1 */ \
 	do { \
 		(v_i) = ((uint32_t)(v_i) << 1) | ((uint32_t)(v_f) >> 31);	\
@@ -192,8 +187,8 @@ typedef uint32_t u_fp;
  * Operations on the long fp format
  * FIXME: Using lfpuint(x) as rvalue, this will fail when representation changes.
  */
-#define	L_ADD(r, a)	M_ADD(lfpuint(*r), lfpfrac(*r), lfpuint(*a), lfpfrac(*a))
-#define	L_SUB(r, a)	M_SUB(lfpuint(*r), lfpfrac(*r), lfpuint(*a), lfpfrac(*a))
+#define	L_ADD(r, a)	(*r) = uint64_to_lfp(lfp_to_uint64(*r)+lfp_to_uint64(*a))
+#define	L_SUB(r, a)	(*r) = uint64_to_lfp(lfp_to_uint64(*r)-lfp_to_uint64(*a))
 #define	L_NEG(v)	M_NEG(lfpuint(*v), lfpfrac(*v))
 #define L_ADDUF(r, uf)	M_ADDUF(lfpuint(*r), lfpfrac(*r), (uf))
 #define L_SUBUF(r, uf)	M_SUBUF(lfpuint(*r), lfpfrac(*r), (uf))


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -618,9 +618,9 @@ handle_procpkt(
 	peer->rootdelay = scalbn((double)pkt->rootdelay, -16);
 	peer->rootdisp = scalbn((double)pkt->rootdisp, -16);
 	memcpy(&peer->refid, pkt->refid, REFIDLEN);
-	uint64_to_lfp(&peer->reftime, pkt->reftime);
-	uint64_to_lfp(&peer->rec, pkt->rec);
-	uint64_to_lfp(&peer->xmt, pkt->xmt);
+	peer->reftime = uint64_to_lfp(pkt->reftime);
+	peer->rec = uint64_to_lfp(pkt->rec);
+	peer->xmt = uint64_to_lfp(pkt->xmt);
 	peer->dst = rbufp->recv_time;
 
 	record_raw_stats(&peer->srcadr,



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/7becd9ba3986486f92a50722a2c9d4bd5ab77fe8...b9db17ee186cee18485e4194fa8cb5c7c299ddfb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161226/2767c1bd/attachment.html>


More information about the vc mailing list