- if (a.tv_sec < b.tv_sec)
- return true;
- else if (a.tv_sec > b.tv_sec)
- return false;
-
- return a.tv_usec < b.tv_usec;
-}
-
-bool time_eq(struct timeval a, struct timeval b)
-{
- return a.tv_sec == b.tv_sec && a.tv_usec == b.tv_usec;
-}
-
-struct timeval time_sub(struct timeval recent, struct timeval old)
-{
- struct timeval diff;
-
- diff.tv_sec = recent.tv_sec - old.tv_sec;
- if (old.tv_usec > recent.tv_usec) {
- diff.tv_sec--;
- diff.tv_usec = 1000000 + recent.tv_usec - old.tv_usec;
- } else
- diff.tv_usec = recent.tv_usec - old.tv_usec;
-
- assert(diff.tv_sec >= 0);
- return diff;
-}
-
-struct timeval time_add(struct timeval a, struct timeval b)
-{
- struct timeval sum;
-
- sum.tv_sec = a.tv_sec + b.tv_sec;
- sum.tv_usec = a.tv_usec + b.tv_usec;
- if (sum.tv_usec > 1000000) {
- sum.tv_sec++;
- sum.tv_usec -= 1000000;
+ struct timespec res;
+ uint64_t rem, ns;
+
+ /* Dividing seconds is simple. */
+ res.tv_sec = TIME_CHECK(t).tv_sec / div;
+ rem = t.tv_sec % div;
+
+ /* If we can't fit remainder * 1,000,000,000 in 64 bits? */
+#if 0 /* ilog is great, but we use fp for multiply anyway. */
+ bits = ilog64(rem);
+ if (bits + 30 >= 64) {
+ /* Reduce accuracy slightly */
+ rem >>= (bits - (64 - 30));
+ div >>= (bits - (64 - 30));