Commit 7e5fe21c authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Aurelio Colosimo

arith.c: use __div64_32 from the library

This change is needed to avoid requiring libgcc in freestanding

The div64 function I copied from the kernel only works with unsigned
numbers, but arth.h had them signed. I'm not sure at this point
whether PTP uses negative nanoseconds in this conversion, so I added a
diagnostic message. If it triggers, I can look for a solution, but I
suspect it doesn't happen.

Please note that a 64-bit arch may define the function as an inline
that does the calculation with C operators, but currently
arch-gnu-linux is used for both 32-bit and 64-bit hosts.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <>
parent 205d324e
......@@ -3,19 +3,24 @@
#include <pptp/pptp.h>
#include <pptp/diag.h>
/* FIXME: This is a temp workaround. How to define it? */
#define PP_INT_MAX 2147483647
void int64_to_TimeInternal(Integer64 bigint, TimeInternal *internal)
int64_t bigint_val;
uint64_t bigint_val;
if (bigint.msb < 0)
pp_printf("BUG: %s doesn't support negatives\n", __func__);
bigint_val = bigint.lsb;
bigint_val += ((int64_t)bigint.msb) << 32;
internal->nanoseconds = bigint_val % PP_NSEC_PER_SEC;
internal->seconds = bigint_val / PP_NSEC_PER_SEC;
/* Use __div64_32 from library, to avoid libgcc on small targets */
internal->nanoseconds = __div64_32(&bigint_val, PP_NSEC_PER_SEC);
internal->seconds = bigint_val;
void from_TimeInternal(TimeInternal *internal, Timestamp *external)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment