From 6fcec439545c817fbc8e2f51c667a70037a34a76 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Fri, 15 Nov 2013 03:28:34 +0100 Subject: [PATCH] Replace libgcc version of ctz with our own. On upcoming arm64 port libgcc ctz* are not usable in standalone environment. Since we need ctz* for this case and implementation is in C we may as well use it on all concerned platforms. --- ChangeLog | 8 +++++ configure.ac | 2 +- grub-core/kern/misc.c | 79 +++++++++++++++++++++++++++++++++++++++++++ include/grub/misc.h | 12 +++++++ 4 files changed, 100 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4281e5b20..6d502f8fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2013-11-15 Vladimir Serbinenko + + Replace libgcc version of ctz with our own. + + On upcoming arm64 port libgcc ctz* are not usable in standalone + environment. Since we need ctz* for this case and implementation is + in C we may as well use it on all concerned platforms. + 2013-11-14 Vladimir Serbinenko * configure.ac: Probe for linking format rather than guessing it based diff --git a/configure.ac b/configure.ac index 19b22344f..2c4f019f6 100644 --- a/configure.ac +++ b/configure.ac @@ -822,7 +822,7 @@ fi fi # Check for libgcc symbols -AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x __ctzdi2 __ctzsi2) +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x) if test "x$TARGET_APPLE_LINKER" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib" diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 194e7703a..f61ff00c1 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -614,6 +614,85 @@ __umodsi3 (grub_uint32_t a, grub_uint32_t b) return ret; } +#endif + +#ifdef NEED_CTZDI2 + +unsigned +__ctzdi2 (grub_uint64_t x) +{ + unsigned ret = 0; + if (!x) + return 64; + if (!(x & 0xffffffff)) + { + x >>= 32; + ret |= 32; + } + if (!(x & 0xffff)) + { + x >>= 16; + ret |= 16; + } + if (!(x & 0xff)) + { + x >>= 8; + ret |= 8; + } + if (!(x & 0xf)) + { + x >>= 4; + ret |= 4; + } + if (!(x & 0x3)) + { + x >>= 2; + ret |= 2; + } + if (!(x & 0x1)) + { + x >>= 1; + ret |= 1; + } + return ret; +} +#endif + +#ifdef NEED_CTZSI2 +unsigned +__ctzsi2 (grub_uint32_t x) +{ + unsigned ret = 0; + if (!x) + return 32; + + if (!(x & 0xffff)) + { + x >>= 16; + ret |= 16; + } + if (!(x & 0xff)) + { + x >>= 8; + ret |= 8; + } + if (!(x & 0xf)) + { + x >>= 4; + ret |= 4; + } + if (!(x & 0x3)) + { + x >>= 2; + ret |= 2; + } + if (!(x & 0x1)) + { + x >>= 1; + ret |= 1; + } + return ret; +} #endif diff --git a/include/grub/misc.h b/include/grub/misc.h index a46e08684..9c8faf274 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -465,6 +465,18 @@ EXPORT_FUNC (__umodsi3) (grub_uint32_t a, grub_uint32_t b); #endif +#if defined (__sparc64__) || defined (__powerpc__) +unsigned +EXPORT_FUNC (__ctzdi2) (grub_uint64_t x); +#define NEED_CTZDI2 1 +#endif + +#if defined (__mips__) || defined (__arm__) +unsigned +EXPORT_FUNC (__ctzsi2) (grub_uint32_t x); +#define NEED_CTZSI2 1 +#endif + #ifdef __arm__ grub_uint32_t EXPORT_FUNC (__aeabi_uidiv) (grub_uint32_t a, grub_uint32_t b);