From mboxrd@z Thu Jan 1 00:00:00 1970 From: dhylands@gmail.com (Dave Hylands) Date: Thu, 19 May 2011 21:15:07 -0700 Subject: about 64-bits division in kernel In-Reply-To: References: Message-ID: To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org Hi lody, On Thu, May 19, 2011 at 8:34 PM, loody wrote: > hi all: > My platform is 32-bits cpu and I need following calculation in my driver. > #define longdiv(sr1, sr2, div) ? ? ?(unsigned long )((((unsigned long > long)(sr1) << 32) ^ (sr2)) / (div)) > > my question are: > 1. why "__udivdi3" has any relationship with above calculation? Because you're doing 64 bit arithmetic (unsigned long long) and 64 bit division is not supported in all kernels. > 2. I know the above calculation is implemented in clibc, but why > kernel still implement itself? > ? ? why kernel try to make another wheel instead of including what > clib provided ? The kernel doesn't use anything from the C runtime library at all. 64-bit division and floating point are 2 things not supported in the kernel, although they do happen to word on some platforms, they aren't portable operations. -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com