main() { union { long long q; unsigned long v[2]; } a, b, q, r; char buf[300]; extern long long __qdivrem(unsigned long long, unsigned long long, unsigned long long *); for (;;) { printf("> "); if (fgets(buf, sizeof buf, stdin) == NULL) break; if (sscanf(buf, "%lu:%lu %lu:%lu", &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4 && sscanf(buf, "0x%lx:%lx 0x%lx:%lx", &a.v[0], &a.v[1], &b.v[0], &b.v[1]) != 4) { printf("eh?\n"); continue; } q.q = __qdivrem(a.q, b.q, &r.q); printf("%lx:%lx /%% %lx:%lx => q=%lx:%lx r=%lx:%lx\n", a.v[0], a.v[1], b.v[0], b.v[1], q.v[0], q.v[1], r.v[0], r.v[1]); printf(" = %lX%08lX / %lX%08lX => %lX%08lX\n\ = %lX%08lX %% %lX%08lX => %lX%08lX\n", a.v[0], a.v[1], b.v[0], b.v[1], q.v[0], q.v[1], a.v[0], a.v[1], b.v[0], b.v[1], r.v[0], r.v[1]); } exit(0); }
/* * Divide two signed quads. * ??? if -1/2 should produce -1 on this machine, this code is wrong */ quad_t __divdi3(quad_t a, quad_t b) { u_quad_t ua, ub, uq; int neg = 0; ua = a; ub = b; if (a < 0) { ua = -ua; neg = !neg; } if (b < 0) { ub = -ub; neg = !neg; } uq = __qdivrem(ua, ub, NULL); if (neg) { uq = -uq; } return uq; }
static int eclock_gettime(struct todr_chip_handle *todr, struct timeval *tv) { struct eclock_softc *sc = todr->cookie; struct _Tc *tc = sc->sc_dp; uint64_t free; int s; /* * 32bit processor, guard against interrupts in the middle of * reading this 64bit entity */ /* BUGBUG Should read it "twice" to guard against rollover too. */ s = splhigh(); free = tc->FreeRunning; splx(s); /* * Big fight with the compiler here, it gets very confused by 64bits. */ #if 1 /* * This is in C: */ { uint64_t freeS, freeU; freeS = free / 10000000UL; freeU = free % 10000000UL; tv->tv_sec = freeS; tv->tv_usec = freeU / 10; #if 0 printf("egt: s x%" PRIx64 " u x%lx (fs %" PRId64 " fu %" PRId64 " f %" PRId64 ")\n", tv->tv_sec, tv->tv_usec, freeS, freeU, free); #endif } #else /* * And this is in assembly :-) */ { u_quad_t r; u_quad_t d = __qdivrem(free,(u_quad_t)10000000,&r); uint32_t su, uu; su = (uint32_t)d; uu = (uint32_t)r; uu = uu / 10; /* in usecs */ tv->tv_sec = su; tv->tv_usec = uu; #if 0 printf("egt: s x%" PRIx64 " u x%lx (fs %" PRId64 " fu %" PRId64 " f %" PRId64 ")\n", tv->tv_sec, tv->tv_usec, d, r, free); #endif } #endif return 0; }
/* * Return remainder after dividing two unsigned quads. */ uint64 __umoddi3(uint64 a, uint64 b) { MONA_ASSERT(sizeof(uint64) == 8); uint64 r; (void)__qdivrem(a, b, &r); return (r); }
/* * Return remainder after dividing two unsigned quads. */ u_quad_t __umoddi3(u_quad_t a, u_quad_t b) { u_quad_t r; (void)__qdivrem(a, b, &r); return (r); }
/* * Divide two signed quads. * ??? if -1/2 should produce -1 on this machine, this code is wrong */ quad_t __divdi3(quad_t a, quad_t b) { u_quad_t ua, ub, uq; int neg; if (a < 0) ua = -(u_quad_t)a, neg = 1; else ua = a, neg = 0; if (b < 0) ub = -(u_quad_t)b, neg ^= 1; else ub = b; uq = __qdivrem(ua, ub, (u_quad_t *)0); return (neg ? -uq : uq); }
/* * Return remainder after dividing two signed quads. * * XXX * If -1/2 should produce -1 on this machine, this code is wrong. */ quad_t __moddi3(quad_t a, quad_t b) { u_quad_t ua, ub, ur; int neg; if (a < 0) ua = -(u_quad_t)a, neg = 1; else ua = a, neg = 0; if (b < 0) ub = -(u_quad_t)b; else ub = b; (void)__qdivrem(ua, ub, &ur); return (neg ? -ur : ur); }
/* * Return remainder after dividing two signed quads. * * XXX we assume a % b < 0 iff a < 0, but this is actually machine-dependent. */ quad_t __moddi3(quad_t a, quad_t b) { u_quad_t ua, ub, ur; int neg = 0; ua = a; ub = b; if (a < 0) ua = -ua, neg ^= 1; if (b < 0) ub = -ub; (void)__qdivrem(ua, ub, &ur); if (neg) ur = -ur; return (ur); }
/* * Return remainder after dividing two signed long longs. * * XXX we assume a % b < 0 iff a < 0, but this is actually machine-dependent. */ long long __moddi3(long long a, long long b) { unsigned long long ua, ub, ur; int neg = 0; ua = a; ub = b; if (a < 0) ua = -ua, neg ^= 1; if (b < 0) ub = -ub; (void)__qdivrem(ua, ub, &ur); if (neg) ur = -ur; return (ur); }
/* * Divide two signed quads. * ??? if -1/2 should produce -1 on this machine, this code is wrong */ quad_t __divdi3(quad_t a, quad_t b) { u_quad_t ua, ub, uq; int neg = 0; ua = a; ub = b; if (a < 0) ua = -ua, neg ^= 1; if (b < 0) ub = -ub, neg ^= 1; uq = __qdivrem(ua, ub, (u_quad_t *)0); if (neg) uq = - uq; return uq; }
/* * Divide two unsigned quads. */ u_quad_t __udivdi3(u_quad_t a, u_quad_t b) { return (__qdivrem(a, b, (u_quad_t *)0)); }