[Git][NTPsec/ntpsec][master] Revert "Change the representation of l_fp from a struct to a 64-bit scalar."

Eric S. Raymond gitlab at mg.gitlab.com
Tue Jan 3 04:49:15 UTC 2017


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


Commits:
71faaad4 by Eric S. Raymond at 2017-01-02T23:49:05-05:00
Revert "Change the representation of l_fp from a struct to a 64-bit scalar."

Somehow this broke the protocol init sequence.  Backing out just the one commit
fixes it..

- - - - -


5 changed files:

- include/ntp_fp.h
- include/timespecops.h
- libntp/refidsmear.c
- libparse/mfp_mul.c
- ntpd/refclock_jupiter.c


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -29,33 +29,35 @@
  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  *
  */
-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
-
-static inline l_fp lfpinit(int32_t hi, uint32_t lo)
-{
-    l_fp tmp = 0;
-    setlfpsint(tmp, hi);
-    setlfpfrac(tmp, lo);
-    return tmp;
-}
+typedef struct {
+	union {
+		uint32_t Xl_ui;
+		int32_t Xl_i;
+	} Ul_i;
+	uint32_t	l_uf;
+} l_fp;
+
+#define l_ui	Ul_i.Xl_ui		/* unsigned integral part */
+#define	l_i	Ul_i.Xl_i		/* signed integral part */
+
+#define lfpfrac(n)		((n).l_uf)
+#define setlfpfrac(n, v)	(n).l_uf = (v)
+#define lfpsint(n)		(n).l_i
+#define setlfpsint(n, v)	(n).l_i = (v)
+#define bumplfpsint(n, i)	(n).l_i += (i)
+#define lfpuint(n)		(n).l_ui
+#define setlfpuint(n, v)	(n).l_ui = (v)
+#define bumplfpuint(n, i)	(n).l_ui += (i)
 
 static inline uint64_t lfp_to_uint64(const l_fp lfp) {
-    return lfp;
+    return (uint64_t)lfpuint(lfp) << 32 | (uint64_t)lfpfrac(lfp);
 }
 
 static inline l_fp uint64_to_lfp(uint64_t x) {
-    return x;
+    l_fp fp;
+    setlfpuint(fp, x >> 32);
+    setlfpfrac(fp, x & 0xFFFFFFFFUL);
+    return fp;
 }
 
 /*
@@ -64,6 +66,14 @@ static inline l_fp uint64_to_lfp(uint64_t x) {
  */
 #define	FRACTION_PREC	(32)
 
+static inline l_fp lfpinit(int32_t hi, uint32_t lo)
+{
+    l_fp tmp;
+    setlfpsint(tmp, hi);
+    setlfpfrac(tmp, lo);
+    return tmp;
+}
+
 /*
  * The second fixed point format is 32 bits, with the decimal between
  * bits 15 and 16.  There is a signed version (s_fp) and an unsigned
@@ -187,7 +197,7 @@ static inline l_fp dtolfp(double d)
 	double	d_tmp;
 	uint64_t	q_tmp;
 	int	M_isneg;
-	l_fp	r = 0;
+	l_fp	r;
 
 	d_tmp = (d);
 	M_isneg = (d_tmp < 0.);


=====================================
include/timespecops.h
=====================================
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -298,7 +298,7 @@ tspec_intv_to_lfp(
 	)
 {
 	struct timespec	v;
-	l_fp		y = 0;
+	l_fp		y;
 	
 	v = normalize_tspec(x);
 	setlfpfrac(y, TVNTOF(v.tv_nsec));


=====================================
libntp/refidsmear.c
=====================================
--- a/libntp/refidsmear.c
+++ b/libntp/refidsmear.c
@@ -17,7 +17,7 @@
 l_fp
 convertRefIDToLFP(uint32_t r)
 {
-	l_fp temp = 0;
+	l_fp temp;
 
 	r = ntohl(r);
 


=====================================
libparse/mfp_mul.c
=====================================
--- a/libparse/mfp_mul.c
+++ b/libparse/mfp_mul.c
@@ -41,7 +41,7 @@ mfp_mul(
   unsigned long carry;
   int32_t   a_i = lfpsint(a_op);
   uint32_t  a_f = lfpfrac(a_op);
-  l_fp out = 0;
+  l_fp out;
   
   int neg = 0;
 
@@ -136,7 +136,7 @@ mfp_mul(
 
 #ifdef DEBUG
   if (debug > 6) {
-    l_fp b = 0;
+    l_fp b;
     setlfpsint(b, b_i);
     setlfpfrac(b, b_f);
     printf("mfp_mul: %s * %s => %s\n",


=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -613,7 +613,7 @@ jupiter_pps(struct instance *instance)
 	pps_info_t pps_info;
 	struct timespec timeout, ts;
 	double dtemp;
-	l_fp tstmp = 0;
+	l_fp tstmp;
 
 	/*
 	 * Convert the timespec nanoseconds field to ntp l_fp units.



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/71faaad4002f2219212e0da6c4022d7cd08135c4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170103/9bb507c0/attachment.html>


More information about the vc mailing list