[Git][NTPsec/ntpsec][master] Scalarize the l_fp type. Byte order magic is due to Hal Murray.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Jan 5 04:06:12 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
d4c2a76b by Eric S. Raymond at 2017-01-04T23:05:47-05:00
Scalarize the l_fp type. Byte order magic is due to Hal Murray.
- - - - -
4 changed files:
- include/ntp.h
- include/ntp_fp.h
- libntp/refidsmear.c
- ntpd/refclock_jupiter.c
Changes:
=====================================
include/ntp.h
=====================================
--- a/include/ntp.h
+++ b/include/ntp.h
@@ -494,10 +494,10 @@ struct pkt {
u_fp rootdelay; /* roundtrip delay to primary source */
u_fp rootdisp; /* dispersion to primary source*/
uint32_t refid; /* reference id */
- l_fp reftime; /* last update time */
- l_fp org; /* originate time stamp */
- l_fp rec; /* receive time stamp */
- l_fp xmt; /* transmit time stamp */
+ l_fp_w reftime; /* last update time */
+ l_fp_w org; /* originate time stamp */
+ l_fp_w rec; /* receive time stamp */
+ l_fp_w xmt; /* transmit time stamp */
#define MIN_MAC_LEN (1 * sizeof(uint32_t)) /* crypto_NAK */
#define MAX_MD5_LEN (5 * sizeof(uint32_t)) /* MD5 */
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -29,39 +29,30 @@
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
-typedef struct {
- union {
- uint32_t Xl_ui; /* unsigned integral part */
- int32_t Xl_i; /* signed integral part */
- } Ul_i;
- uint32_t l_uf;
-} l_fp;
-
-#define lfpfrac(n) ((n).l_uf)
-#define setlfpfrac(n, v) (n).l_uf = (v)
-#define lfpsint(n) (n).Ul_i.Xl_i
-#define setlfpsint(n, v) (n).Ul_i.Xl_i = (v)
-#define bumplfpsint(n, i) (n).Ul_i.Xl_i += (i)
-#define lfpuint(n) (n).Ul_i.Xl_ui
-#define setlfpuint(n, v) (n).Ul_i.Xl_ui = (v)
-#define bumplfpuint(n, i) (n).Ul_i.Xl_ui += (i)
-
-static inline uint64_t lfp_to_uint64(const l_fp lfp)
-{
- return (uint64_t)lfpuint(lfp) << 32 | (uint64_t)lfpfrac(lfp);
+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 uint64_t lfp_to_uint64(const l_fp lfp) {
+ return lfp;
}
-static inline l_fp uint64_to_lfp(uint64_t x)
-{
- l_fp fp;
- setlfpuint(fp, x >> 32);
- setlfpfrac(fp, x & 0xFFFFFFFFUL);
- return fp;
+static inline l_fp uint64_to_lfp(uint64_t x) {
+ return x;
}
static inline l_fp lfpinit(int32_t hi, uint32_t lo)
{
- l_fp tmp;
+ l_fp tmp = 0;
setlfpsint(tmp, hi);
setlfpfrac(tmp, lo);
return tmp;
@@ -103,12 +94,22 @@ typedef uint32_t u_fp;
#define HTONS_FP(x) (htonl(x))
#define NTOHS_FP(x) (ntohl(x))
-static inline l_fp htonl_fp(l_fp lfp) {
- return lfpinit(htonl(lfpuint(lfp)), htonl(lfpfrac(lfp)));
+
+typedef struct {
+ uint32_t l_ui;
+ uint32_t l_uf;
+} l_fp_w;
+
+static inline l_fp_w htonl_fp(l_fp lfp) {
+ l_fp_w lfpw;
+ lfpw.l_ui = htonl(lfpuint(lfp));
+ lfpw.l_uf = htonl(lfpfrac(lfp));
+ return lfpw;
+// return lfpinit(htonl(lfpuint(lfp)), htonl(lfpfrac(lfp)));
}
-static inline l_fp ntohl_fp(l_fp lfp) {
- return lfpinit(ntohl(lfpuint(lfp)), ntohl(lfpfrac(lfp)));
+static inline l_fp ntohl_fp(l_fp_w lfpw) {
+ return lfpinit(ntohl(lfpw.l_ui), ntohl(lfpw.l_uf));
}
/* Convert unsigned ts fraction to net order ts */
=====================================
libntp/refidsmear.c
=====================================
--- a/libntp/refidsmear.c
+++ b/libntp/refidsmear.c
@@ -17,7 +17,7 @@
l_fp
convertRefIDToLFP(uint32_t r)
{
- l_fp temp;
+ l_fp temp = 0;
r = ntohl(r);
=====================================
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;
+ l_fp tstmp = 0;
/*
* Convert the timespec nanoseconds field to ntp l_fp units.
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/d4c2a76b06248734103f886916bf4cf7a1f5724d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170105/518608b8/attachment.html>
More information about the vc
mailing list