This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
soft-fp patch: Use __builtin_clz*
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: libc-alpha at sourceware dot org
- Date: Sun, 4 Dec 2005 14:22:54 +0000 (UTC)
- Subject: soft-fp patch: Use __builtin_clz*
The soft-fp code has an inefficient generic default implementation of
__FP_CLZ. GCC 3.4 and greater provide __builtin_clz which can be used for
a better and simpler implementation. This patch makes soft-fp use these
built-in functions.
In fact the only non-default definitions of __FP_CLZ are those in
sysdeps/i386/soft-fp/sfp-machine.h and
sysdeps/x86_64/soft-fp/sfp-machine.h. GCC knows how to expand
__builtin_clz/__builtin_clzl properly for both platforms, though on x86_64
it seems this support isn't there until GCC 4.0.
2005-12-04 Joseph S. Myers <joseph@codesourcery.com>
* soft-fp/op-common.h (__FP_CLZ): Define using __builtin_clz,
__builtin_clzl and __builtin_clzll.
diff -rupN libc.orig/soft-fp/op-common.h libc.clz/soft-fp/op-common.h
--- libc.orig/soft-fp/op-common.h 2002-12-31 18:29:02.000000000 +0000
+++ libc.clz/soft-fp/op-common.h 2005-12-04 14:10:42.000000000 +0000
@@ -725,40 +725,17 @@ do { \
/* Count leading zeros in a word. */
#ifndef __FP_CLZ
-#if _FP_W_TYPE_SIZE < 64
-/* this is just to shut the compiler up about shifts > word length -- PMM 02/1998 */
-#define __FP_CLZ(r, x) \
- do { \
- _FP_W_TYPE _t = (x); \
- r = _FP_W_TYPE_SIZE - 1; \
- if (_t > 0xffff) r -= 16; \
- if (_t > 0xffff) _t >>= 16; \
- if (_t > 0xff) r -= 8; \
- if (_t > 0xff) _t >>= 8; \
- if (_t & 0xf0) r -= 4; \
- if (_t & 0xf0) _t >>= 4; \
- if (_t & 0xc) r -= 2; \
- if (_t & 0xc) _t >>= 2; \
- if (_t & 0x2) r -= 1; \
- } while (0)
-#else /* not _FP_W_TYPE_SIZE < 64 */
-#define __FP_CLZ(r, x) \
- do { \
- _FP_W_TYPE _t = (x); \
- r = _FP_W_TYPE_SIZE - 1; \
- if (_t > 0xffffffff) r -= 32; \
- if (_t > 0xffffffff) _t >>= 32; \
- if (_t > 0xffff) r -= 16; \
- if (_t > 0xffff) _t >>= 16; \
- if (_t > 0xff) r -= 8; \
- if (_t > 0xff) _t >>= 8; \
- if (_t & 0xf0) r -= 4; \
- if (_t & 0xf0) _t >>= 4; \
- if (_t & 0xc) r -= 2; \
- if (_t & 0xc) _t >>= 2; \
- if (_t & 0x2) r -= 1; \
+#define __FP_CLZ(r, x) \
+ do { \
+ if (sizeof(_FP_W_TYPE) == sizeof(unsigned int)) \
+ r = __builtin_clz(x); \
+ else if (sizeof(_FP_W_TYPE) == sizeof(unsigned long)) \
+ r = __builtin_clzl(x); \
+ else if (sizeof(_FP_W_TYPE) == sizeof(unsigned long long)) \
+ r = __builtin_clzll(x); \
+ else \
+ abort(); \
} while (0)
-#endif /* not _FP_W_TYPE_SIZE < 64 */
#endif /* ndef __FP_CLZ */
#define _FP_DIV_HELP_imm(q, r, n, d) \
--
Joseph S. Myers
joseph@codesourcery.com