why does Linux kernel use do_div instead of /?

Viewed 6901

For 64-bit division, what is the difference between using / and do_div? only to improve performance? and is it architecture dependent?

The source code is here.

2 Answers

The macro is needed because on 32-bit target platforms, writing a "/" will fail to link.

The C library in the kernel is not the one you're using in user space. In user space C programs, the C library will implement the 64-bit division for you, if your CPU does not have a 64-bit divide instruction.

64-bit multiplication is okay, even on 32-bit platforms, but 64-bit divide is a no-no and will get your driver rejected because it won't pass compilation.

Related