From 6887f43300d09e5573da90cfd43082b3d0c696e3 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Tue, 1 Jan 2013 18:16:39 -0800 Subject: [PATCH] sna: Rewrite __fls without x86 assembly Prevented SNA from compiling on ia64. Fixes https://bugs.gentoo.org/show_bug.cgi?id=448570 --- src/sna/kgem.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/sna/kgem.c b/src/sna/kgem.c index f4c2b1c..09b887d 100644 --- a/src/sna/kgem.c +++ b/src/sna/kgem.c @@ -516,10 +516,19 @@ static void gem_close(int fd, uint32_t handle) constant inline static unsigned long __fls(unsigned long word) { - asm("bsr %1,%0" - : "=r" (word) - : "rm" (word)); - return word; +#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304) + return word == 0 ? 0 : 32 - __builtin_clz(word); +#else + unsigned int v = 1; + + if (word == 0) + return 0; + + while (word >>= 1) + v++; + + return v; +#endif } constant inline static int cache_bucket(int num_pages) -- 1.7.8.6