All of lore.kernel.org
 help / color / mirror / Atom feed
* 64 bit signed division
@ 2014-09-11  8:03 Steve French
  0 siblings, 0 replies; only message in thread
From: Steve French @ 2014-09-11  8:03 UTC (permalink / raw)
  To: LKML

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-09-11  8:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-11  8:03 64 bit signed division Steve French

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.