[Git][NTPsec/ntpsec][master] Refactor for simplicity.
Eric S. Raymond
gitlab at mg.gitlab.com
Tue Jan 3 13:12:37 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
31539be4 by Eric S. Raymond at 2017-01-03T08:12:01-05:00
Refactor for simplicity.
- - - - -
9 changed files:
- include/ntp_fp.h
- include/timespecops.h
- libntp/atolfp.c
- libntp/hextolfp.c
- libparse/mfp_mul.c
- ntpd/ntp_control.c
- ntpd/refclock_jupiter.c
- ntpd/refclock_truetime.c
- ntptime/ntptime.c
Changes:
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -105,23 +105,15 @@ typedef uint32_t u_fp;
#define NTOHS_FP(x) (ntohl(x))
static inline l_fp htonl_fp(l_fp lfp) {
- setlfpuint(lfp, htonl(lfpuint(lfp)));
- setlfpfrac(lfp, htonl(lfpfrac(lfp)));
- return lfp;
+ return lfpinit(htonl(lfpuint(lfp)), htonl(lfpfrac(lfp)));
}
static inline l_fp ntohl_fp(l_fp lfp) {
- setlfpuint(lfp, ntohl(lfpuint(lfp)));
- setlfpfrac(lfp, ntohl(lfpfrac(lfp)));
- return lfp;
+ return lfpinit(ntohl(lfpuint(lfp)), ntohl(lfpfrac(lfp)));
}
/* Convert unsigned ts fraction to net order ts */
-#define HTONL_UF(uf, nts) \
- do { \
- setlfpuint(*nts, 0); \
- setlfpfrac(*nts, htonl(uf)); \
- } while (false)
+#define HTONL_UF(uf, nts) *nts = lfpint(0, htonl(uf))
/*
* Conversions between the two fixed point types
@@ -131,11 +123,11 @@ static inline l_fp ntohl_fp(l_fp lfp) {
(((x_i)<<16) | (((x_f)>>16)&0xffff))))
#define LFPTOFP(v) MFPTOFP(lfpsint(*v), lfprac(*v))
-#define UFPTOLFP(x, v) (setlfpuint(*v, (u_fp)(x)>>16), setlfpfrac(*v, (x)<<16))
+#define UFPTOLFP(x, v) (*v = lfpinit((u_fp)(x)>>16, (x)<<16))
#define FPTOLFP(x, v) (UFPTOLFP((x), (v)), (x) < 0 ? setlfpuint(*v, getlfpuint(*v) - 0x10000) : 0)
-#define MAXLFP(v) (setlfpuint(*v, 0x7fffffffu), setlfpfrac(*v, 0xffffffffu))
-#define MINLFP(v) (selfpuint(*v, 0x80000000u), setlfpfrac(*v, 0u))
+#define MAXLFP(v) *v = lfpinit(0x7fffffffu, 0xffffffffu)
+#define MINLFP(v) *v = lfpinit(0x80000000u, 0u)
/*
* Primitive operations on long fixed point values. If these are
@@ -161,7 +153,7 @@ static inline l_fp ntohl_fp(l_fp lfp) {
#define L_ADDUF(r, uf) (*r) = uint64_to_lfp(lfp_to_uint64(*r) + (uf))
#define L_SUBUF(r, uf) (*r) = uint64_to_lfp(lfp_to_uint64(*r) - (uf))
#define L_ADDF(r, f) (*r) = uint64_to_lfp((int64_t)lfp_to_uint64(*r) + (int64_t)(uf))
-#define L_CLR(v) (setlfpuint(*v, 0), setlfpfrac(*v, 0))
+#define L_CLR(v) *v = lfpinit(0, 0)
#define L_ISNEG(v) M_ISNEG(lfpuint(*v))
#define L_ISZERO(v) ((lfpuint(*v) | lfpfrac(*v)) == 0)
#define L_ISGT(a, b) ((int64_t)lfp_to_uint64(*a) > (int64_t)lfp_to_uint64(*b))
@@ -197,7 +189,6 @@ static inline l_fp dtolfp(double d)
double d_tmp;
uint64_t q_tmp;
int M_isneg;
- l_fp r;
d_tmp = (d);
M_isneg = (d_tmp < 0.);
@@ -208,9 +199,7 @@ static inline l_fp dtolfp(double d)
if (M_isneg) {
q_tmp = ~q_tmp + 1;
}
- setlfpfrac(r, (uint32_t)q_tmp);
- setlfpuint(r, (uint32_t)(q_tmp >> 32));
- return r;
+ return lfpinit((uint32_t)(q_tmp >> 32) , (uint32_t)q_tmp);
}
static inline double lfptod(l_fp r)
=====================================
include/timespecops.h
=====================================
--- a/include/timespecops.h
+++ b/include/timespecops.h
@@ -297,14 +297,8 @@ tspec_intv_to_lfp(
struct timespec x
)
{
- struct timespec v;
- l_fp y;
-
- v = normalize_tspec(x);
- setlfpfrac(y, TVNTOF(v.tv_nsec));
- setlfpsint(y, (int32_t)v.tv_sec);
-
- return y;
+ struct timespec v = normalize_tspec(x);
+ return lfpinit((int32_t)v.tv_sec, TVNTOF(v.tv_nsec));
}
/* x must be UN*X epoch, output will be in NTP epoch */
=====================================
libntp/atolfp.c
=====================================
--- a/libntp/atolfp.c
+++ b/libntp/atolfp.c
@@ -116,7 +116,6 @@ atolfp(
if (isneg)
M_NEG(dec_i, dec_f);
- setlfpuint(*lfp, dec_i);
- setlfpfrac(*lfp, dec_f);
+ *lfp = lfpinit(dec_i, dec_f);
return true;
}
=====================================
libntp/hextolfp.c
=====================================
--- a/libntp/hextolfp.c
+++ b/libntp/hextolfp.c
@@ -62,7 +62,6 @@ hextolfp(
if (*cp != '\0' && !isspace((unsigned char)*cp))
return false;
- setlfpuint(*lfp, dec_i);
- setlfpfrac(*lfp, dec_f);
+ *lfp = lfpinit(dec_i, dec_f);
return true;
}
=====================================
libparse/mfp_mul.c
=====================================
--- a/libparse/mfp_mul.c
+++ b/libparse/mfp_mul.c
@@ -131,14 +131,11 @@ mfp_mul(
M_NEG(i, f);
}
- setlfpsint(out, i);
- setlfpfrac(out, f);
+ out = lfpinit(i, f);
#ifdef DEBUG
if (debug > 6) {
- l_fp b;
- setlfpsint(b, b_i);
- setlfpfrac(b, b_f);
+ l_fp b = lfpinit(b_i, b_f);
printf("mfp_mul: %s * %s => %s\n",
mfptoa(a_op, 6), mfptoa(b, 6), mfptoa(out, 6));
}
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -3088,8 +3088,7 @@ static int validate_nonce(
if (3 != sscanf(pnonce, "%08x%08x%08x", &ts_i, &ts_f, &supposed))
return false;
- setlfpuint(ts, (uint32_t)ts_i);
- setlfpfrac(ts, (uint32_t)ts_f);
+ ts = lfpinit((uint32_t)ts_i, (uint32_t)ts_f);
derived = derive_nonce(&rbufp->recv_srcadr, lfpuint(ts), lfpfrac(ts));
get_systime(&now_delta);
L_SUB(&now_delta, &ts);
@@ -3456,8 +3455,7 @@ static void read_mru_list(
(size_t)si < COUNTOF(last)) {
if (2 != sscanf(val, "0x%08x.%08x", &ui, &uf))
goto blooper;
- setlfpuint(last[si], ui);
- setlfpfrac(last[si], uf);
+ last[si] = lfpinit(ui, uf);
if (!SOCK_UNSPEC(&addr[si]) && si == priors)
priors++;
} else if (1 == sscanf(v->text, addr_fmt, &si) &&
=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -840,8 +840,7 @@ jupiter_receive(struct recvbuf *rbufp)
break;
/* Add the new sample to a median filter */
- setlfpuint(tstamp, JAN_1970 + (uint32_t)last_timecode);
- setlfpfrac(tstamp, 0);
+ tstamp = lfpinit(JAN_1970 + (uint32_t)last_timecode, 0);
refclock_process_offset(pp, tstamp, pp->lastrec, pp->fudgetime1);
=====================================
ntpd/refclock_truetime.c
=====================================
--- a/ntpd/refclock_truetime.c
+++ b/ntpd/refclock_truetime.c
@@ -498,8 +498,7 @@ true_receive(
refclock_report(peer, CEVNT_BADTIME);
return;
}
- setlfpuint(off, sec);
- setlfpfrac(off, 0);
+ off = lfpinut(sec, 0);
#endif
pp->usec = true_sample720();
=====================================
ntptime/ntptime.c
=====================================
--- a/ntptime/ntptime.c
+++ b/ntptime/ntptime.c
@@ -35,15 +35,6 @@
# define TVUTOTSF(tvu) \
(uint32_t)((((uint64_t)(tvu) << 32) + MICROSECONDS / 2) / MICROSECONDS)
-/*
- * Convert a struct timeval to a time stamp.
- */
-#define TVTOTS(tv, ts) \
- do { \
- setlfpuint(*ts, (u_long)(tv)->tv_sec); \
- setlfpfrac(*ts, TVUTOTSF((tv)->tv_usec)); \
- } while (false)
-
#define NS_PER_MS_FLOAT 1000.0
/* MUSL port shim */
@@ -338,7 +329,8 @@ main(
#endif
tv.tv_sec = ntv.time.tv_sec;
tv.tv_usec = ntv.time.tv_frac_sec;
- TVTOTS(&tv, &ts);
+ setlfpuint(ts, (u_long)tv.tv_sec); \
+ setlfpfrac(ts, TVUTOTSF(tv.tv_usec)); \
setlfpuint(ts, lfpuint(ts) + JAN_1970);
setlfpfrac(ts, lfpfrac(ts) + ts_roundbit);
setlfpfrac(ts, lfpfrac(ts) & ts_mask);
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/31539be47c80fc847dc95f4f8c0424567c42056e
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170103/609fdccb/attachment.html>
More information about the vc
mailing list