/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. int
  7. tsftomsu(
  8. u_long tsf,
  9. int round
  10. )
  11. {
  12. register long val_ui, val_uf;
  13. register long tmp_ui, tmp_uf;
  14. register int i;
  15. /*
  16. * Essentially, multiply by 10 three times in l_fp form.
  17. * The integral part is the milliseconds.
  18. */
  19. val_ui = 0;
  20. val_uf = tsf;
  21. for (i = 3; i > 0; i--) {
  22. M_LSHIFT(val_ui, val_uf);
  23. tmp_ui = val_ui;
  24. tmp_uf = val_uf;
  25. M_LSHIFT(val_ui, val_uf);
  26. M_LSHIFT(val_ui, val_uf);
  27. M_ADD(val_ui, val_uf, tmp_ui, tmp_uf);
  28. }
  29. /*
  30. * Round the value if need be, then return it.
  31. */
  32. if (round && (val_uf & 0x80000000))
  33. val_ui++;
  34. return (int)val_ui;
  35. }