[Git][NTPsec/ntpsec][master] More l_fp encapsulation via bump* macros.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Dec 26 01:46:00 UTC 2016


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


Commits:
fd3834e6 by Eric S. Raymond at 2016-12-25T20:45:02-05:00
More l_fp encapsulation via bump* macros.

- - - - -


6 changed files:

- include/ntp_fp.h
- libparse/clk_rawdcf.c
- ntpd/refclock_generic.c
- ntpd/refclock_jupiter.c
- ntpd/refclock_oncore.c
- ntpfrob/jitter.c


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -42,8 +42,10 @@ typedef struct {
 #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 (uint64_t)lfpuint(*lfp) << 32 | (uint64_t)lfpfrac(*lfp);


=====================================
libparse/clk_rawdcf.c
=====================================
--- a/libparse/clk_rawdcf.c
+++ b/libparse/clk_rawdcf.c
@@ -546,7 +546,7 @@ snt_rawdcf(
 	{
 		parseio->parse_dtime.parse_stime = *ptime;
 
-		parseio->parse_dtime.parse_time.fp.l_ui++;
+		bumplfpuint(parseio->parse_dtime.parse_time.fp, 1);
 
 		parseprintf(DD_RAWDCF,("parse: snt_rawdcf: time stamp synthesized offset %d seconds\n", parseio->parse_index - 1));
 


=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -1850,16 +1850,16 @@ local_input(
 							else
 							  pts = pps_info.assert_timestamp;
 
-							parse->parseio.parse_dtime.parse_ptime.fp.l_ui = (uint32_t) (pts.tv_sec + JAN_1970);
+							setlfpuint(parse->parseio.parse_dtime.parse_ptime.fp, (uint32_t) (pts.tv_sec + JAN_1970));
 
 							dtemp = (double) pts.tv_nsec / 1e9;
 							if (dtemp < 0.) {
 								dtemp += 1;
-								parse->parseio.parse_dtime.parse_ptime.fp.l_ui--;
+								bumplfpuint(parse->parseio.parse_dtime.parse_ptime.fp, -1);
 							}
 							if (dtemp > 1.) {
 								dtemp -= 1;
-								parse->parseio.parse_dtime.parse_ptime.fp.l_ui++;
+								bumplfpuint(parse->parseio.parse_dtime.parse_ptime.fp, 1);
 							}
 							setlfpfrac(parse->parseio.parse_dtime.parse_ptime.fp, (uint32_t)(dtemp * FRAC));
 
@@ -3522,15 +3522,15 @@ parse_process(
 				{
 					reftime = off = offset;
 					if (lfpfrac(reftime) & 0x80000000)
-						reftime.l_ui++;
+						bumplfpuint(reftime, 1);
 					setlfpfrac(reftime, 0);
 
 
 					/*
 					 * implied on second offset
 					 */
-					off.l_uf = ~off.l_uf; /* map [0.5..1[ -> [-0.5..0[ */
-					off.l_i = (off.l_uf & 0x80000000) ? -1 : 0; /* sign extend */
+					setlfpfrac(off, ~lfpfrac(off)); /* map [0.5..1[ -> [-0.5..0[ */
+					setlfpsint(off, (lfpfrac(off) & 0x80000000) ? -1 : 0); /* sign extend */
 				}
 				else
 				{
@@ -3555,14 +3555,14 @@ parse_process(
 			 */
 			off = offset;
 			reftime = offset;
-			if (reftime.l_uf & 0x80000000)
-				reftime.l_ui++;
-			reftime.l_uf = 0;
+			if (lfpfrac(reftime) & 0x80000000)
+				bumplfpuint(reftime, 1);
+			setlfpfrac(reftime, 0);
 			/*
 			 * implied on second offset
 			 */
-			off.l_uf = ~off.l_uf; /* map [0.5..1[ -> [-0.5..0[ */
-			off.l_i = (off.l_uf & 0x80000000) ? -1 : 0; /* sign extend */
+			setlfpfrac(off, ~lfpfrac(off)); /* map [0.5..1[ -> [-0.5..0[ */
+			setlfpsint(off, (lfpfrac(off) & 0x80000000) ? -1 : 0); /* sign extend */
 		}
 	}
 	else


=====================================
ntpd/refclock_jupiter.c
=====================================
--- a/ntpd/refclock_jupiter.c
+++ b/ntpd/refclock_jupiter.c
@@ -821,7 +821,7 @@ jupiter_receive(struct recvbuf *rbufp)
 			 */
 			L_SUB(&tstamp, &pp->lastrec);
 			if (!L_ISGEQ(&tstamp, &instance->limit))
-				++pp->lastrec.l_ui;
+				bumplfpuint(pp->lastrec, 1);
 
 			/* Parse timecode (even when there's no pps) */
 			last_timecode = instance->timecode;


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -1758,7 +1758,7 @@ oncore_get_timestamp(
 
 	/* have time from UNIX origin, convert to NTP origin. */
 
-	ts.l_ui += JAN_1970;
+	bumplfpuint(ts, JAN_1970);
 	instance->pp->lastrec = ts;
 
 	/* print out information about this timestamp (long line) */


=====================================
ntpfrob/jitter.c
=====================================
--- a/ntpfrob/jitter.c
+++ b/ntpfrob/jitter.c
@@ -53,10 +53,10 @@ get_clocktime(
 	dtemp += sys_residual;
 	if (dtemp >= 1) {
 		dtemp -= 1;
-		setlfpsint(*now, lfpsint(*now) + 1);
+		bumplfpsint(*now, 1);
 	} else if (dtemp < -1) {
 		dtemp += 1;
-		setlfpsint(*now, lfpsint(*now) - 1);
+		bumplfpsint(*now, -1);
 	}
 	dtemp *= FRAC;
 	setlfpfrac(*now, (uint32_t)dtemp);



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/fd3834e6989f1c68704f0bee8f307e7453e5b15b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161226/0a36215c/attachment.html>


More information about the vc mailing list