64 bit signed division

From: Steve French
Date: Thu Sep 11 2014 - 04:05:54 EST


Does 64 bit signed division work on all archs?

Since do_div (currently used by cifs and ntfs to convert time formats
from DCE time to Linux time) does not handle negative numbers, and
there does not appear to be a kernel equivalent of Ildiv, I was
wondering if there really is a problem with simply doing s64 division
on other architectures (it obviously works on my systems but they are
Intel and AMD).

ie I have to change from
- u64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
-
- ts.tv_nsec = do_div(t, 10000000) * 100;
- ts.tv_sec = t;

to something like

+ s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
+
+ ts.tv_sec = t / 10000000;
+ ts.tv_nsec = (t % 10000000) * 100;

If 64 bit division does not work on all archs then I will need to fall
back to something uglier,

+ s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
+
+ if (t < 0) {
+ t = -t;
+ ts.tv_nsec = -(do_div(t, 10000000) * 100);
+ ts.tv_sec = -t;
+ } else {
+ ts.tv_nsec = do_div(t, 10000000) * 100;
+ ts.tv_sec = t;
+ }

Are there better alternatives?

--
Thanks,

Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/