PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/contrib/ntp/libntp/tsftomsu.c

https://bitbucket.org/freebsd/freebsd-head/
C | 38 lines | 25 code | 3 blank | 10 comment | 3 complexity | b658b96793121a569b07e8e771312518 MD5 | raw file
 1/*
 2 * tsftomsu - convert from a time stamp fraction to milliseconds
 3 */
 4#include "ntp_fp.h"
 5#include "ntp_stdlib.h"
 6
 7int
 8tsftomsu(
 9	u_long tsf,
10	int round
11	)
12{
13	register long val_ui, val_uf;
14	register long tmp_ui, tmp_uf;
15	register int i;
16
17	/*
18	 * Essentially, multiply by 10 three times in l_fp form.
19	 * The integral part is the milliseconds.
20	 */
21	val_ui = 0;
22	val_uf = tsf;
23	for (i = 3; i > 0; i--) {
24		M_LSHIFT(val_ui, val_uf);
25		tmp_ui = val_ui;
26		tmp_uf = val_uf;
27		M_LSHIFT(val_ui, val_uf);
28		M_LSHIFT(val_ui, val_uf);
29		M_ADD(val_ui, val_uf, tmp_ui, tmp_uf);
30	}
31
32	/*
33	 * Round the value if need be, then return it.
34	 */
35	if (round && (val_uf & 0x80000000))
36	    val_ui++;
37	return (int)val_ui;
38}