aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/xntpd/lib/tsftomsu.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/xntpd/lib/tsftomsu.c')
-rw-r--r--usr.sbin/xntpd/lib/tsftomsu.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/usr.sbin/xntpd/lib/tsftomsu.c b/usr.sbin/xntpd/lib/tsftomsu.c
new file mode 100644
index 000000000000..b9161141d359
--- /dev/null
+++ b/usr.sbin/xntpd/lib/tsftomsu.c
@@ -0,0 +1,37 @@
+/* tsftomsu.c,v 3.1 1993/07/06 01:08:47 jbj Exp
+ * tsftomsu - convert from a time stamp fraction to milliseconds
+ */
+#include "ntp_fp.h"
+#include "ntp_stdlib.h"
+
+int
+tsftomsu(tsf, round)
+ U_LONG tsf;
+ int round;
+{
+ register U_LONG val_ui, val_uf;
+ register U_LONG tmp_ui, tmp_uf;
+ register int i;
+
+ /*
+ * Essentially, multiply by 10 three times in l_fp form.
+ * The integral part is the milliseconds.
+ */
+ val_ui = 0;
+ val_uf = tsf;
+ for (i = 3; i > 0; i--) {
+ M_LSHIFT(val_ui, val_uf);
+ tmp_ui = val_ui;
+ tmp_uf = val_uf;
+ M_LSHIFT(val_ui, val_uf);
+ M_LSHIFT(val_ui, val_uf);
+ M_ADD(val_ui, val_uf, tmp_ui, tmp_uf);
+ }
+
+ /*
+ * Round the value if need be, then return it.
+ */
+ if (round && (val_uf & 0x80000000))
+ val_ui++;
+ return (int)val_ui;
+}