lib: div64: syncronize to current kernel version
PATCH 1/1 lib: div64: syncronize to current kernel version
Synchronize with the implementation from v3.18 tag. This allows us to use a standardized 64 bit ops on architectures that do not natively support 64 bit (example: 32bit ARM)
--- include/linux/math64.h | 81 ++++++++++++++++++++++++++++++ lib/div64.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 209 insertions(+), 4 deletions(-)
include/linux/math64.h +81 -0
@@ -2,9 +2,13 @@#define _LINUX_MATH64_H#include <linux/types.h> +#include <div64.h> #if BITS_PER_LONG ==64 +#define div64_long (x, y) div64_s64((x), (y)) +#define div64_ul (x, y) div64_u64((x), (y)) +/** * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder *
@@ -27,6 +31,15 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder) }/** +* div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder +*/ +static inline u64 div64_u64_rem (u64 dividend,u64 divisor,u64 *remainder) +{ + *remainder = dividend % divisor; +return dividend / divisor; +} + +/** * div64_u64 - unsigned 64bit divide with 64bit divisor */ static inline u64 div64_u64 (u64 dividend,u64 divisor)
@@ -34,8 +47,19 @@ static inline u64 div64_u64(u64 dividend, u64 divisor) return dividend / divisor; } +/** +* div64_s64 - signed 64bit divide with 64bit divisor +*/ +static inline s64 div64_s64 (s64 dividend,s64 divisor) +{ +return dividend / divisor; +} +#elif BITS_PER_LONG == 32 +#define div64_long (x, y) div_s64((x), (y)) +#define div64_ul (x, y) div_u64((x), (y)) +#ifndef div_u64_remstatic inline u64 div_u64_rem (u64 dividend,u32 divisor,u32 *remainder) {
@@ -48,10 +72,18 @@ static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)extern s64 div_s64_rem (s64 dividend,s32 divisor,s32 *remainder);#endif +#ifndef div64_u64_rem +extern u64 div64_u64_rem (u64 dividend,u64 divisor,u64 *remainder); +#endif +#ifndef div64_u64extern u64 div64_u64 (u64 dividend,u64 divisor);#endif +#ifndef div64_s64 +extern s64 div64_s64 (s64 dividend,s64 divisor); +#endif +#endif /* BITS_PER_LONG */ /**
@@ -82,4 +114,53 @@ static inline s64 div_s64(s64 dividend, s32 divisor)u32 iter_div_u64_rem (u64 dividend,u32 divisor,u64 *remainder); +static __always_inline u32 +__iter_div_u64_rem (u64 dividend,u32 divisor,u64 *remainder) +{ +u32 ret =0 ; + +while (dividend >= divisor) { +/* The following asm() prevents the compiler from +optimising this loop into a modulo operation. */ + asm("" :"+rm" (dividend)); + + dividend -= divisor; + ret++; + } + + *remainder = dividend; + +return ret; +} + +#if defined(CONFIG_ARCH_SUPPORTS_INT128 ) && defined(__SIZEOF_INT128__) + +#ifndef mul_u64_u32_shr +static inline u64 mul_u64_u32_shr (u64 a,u32 mul,unsigned int shift) +{ +return (u64)(((unsigned __int128 )a * mul) >> shift); +} +#endif /* mul_u64_u32_shr */ + +#else + +#ifndef mul_u64_u32_shr +static inline u64 mul_u64_u32_shr (u64 a,u32 mul,unsigned int shift) +{ +u32 ah, al; +u64 ret; + + al = a; + ah = a >>32 ; + + ret = ((u64 )al * mul) >> shift; +if (ah) + ret += ((u64 )ah * mul) << (32 - shift); + +return ret; +} +#endif /* mul_u64_u32_shr */ + +#endif +#endif /* _LINUX_MATH64_H */
lib/div64.c +128 -4
148 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 5 lines · Nishanth Menon
Synchronize with the implementation from v3.18 tag. This allows us to use a standardized 64 bit ops on architectures that do not natively support 64 bit (example: 32bit ARM)
Signed-off-by Nishanth Menon <[email protected]>
This breaks building on 64bit platforms (mips64, aarch64). Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150306/0912f8fc/attachment.sig>
Quoted 10 lines · Tom Rini
Quoted 5 lines · Nishanth Menon
Synchronize with the implementation from v3.18 tag. This allows us to use a standardized 64 bit ops on architectures that do not natively support 64 bit (example: 32bit ARM)
Signed-off-by Nishanth Menon <[email protected]>This breaks building on 64bit platforms (mips64, aarch64). Thanks!
Uggh.. dropping this. Sorry for the noise.
Signature · 2 lines
Regards, Nishanth Menon