From 82d259c28dd5be149c34e76d71e4368cc26c42fb Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 20 Nov 2012 22:25:05 -0800 Subject: [PATCH] count-leading-zeros: better 'inline' * lib/count-leading-zeros.c: New file. * lib/count-leading-zeros.h (COUNT_LEADING_ZEROS_INLINE): New macro. Replace all uses of 'static inline' with it. Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. * m4/count-leading-zeros.m4 (gl_COUNT_LEADING_ZEROS): Do not require AC_C_INLINE. * modules/count-leading-zeros (Files, lib_SOURCES): Add lib/count-leading-zeros.c. (Depends-on): Add extern-inline. --- ChangeLog | 11 +++++++++++ lib/count-leading-zeros.c | 3 +++ lib/count-leading-zeros.h | 15 +++++++++++---- m4/count-leading-zeros.m4 | 5 +---- modules/count-leading-zeros | 3 +++ 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 lib/count-leading-zeros.c diff --git a/ChangeLog b/ChangeLog index c23c0fda7..124ead01a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2012-11-29 Paul Eggert + count-leading-zeros: better 'inline' + * lib/count-leading-zeros.c: New file. + * lib/count-leading-zeros.h (COUNT_LEADING_ZEROS_INLINE): + New macro. Replace all uses of 'static inline' with it. + Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END. + * m4/count-leading-zeros.m4 (gl_COUNT_LEADING_ZEROS): + Do not require AC_C_INLINE. + * modules/count-leading-zeros (Files, lib_SOURCES): + Add lib/count-leading-zeros.c. + (Depends-on): Add extern-inline. + bitrotate: better 'inline' * lib/bitrotate.c: New file. * lib/bitrotate.h (BITROTATE_INLINE): diff --git a/lib/count-leading-zeros.c b/lib/count-leading-zeros.c new file mode 100644 index 000000000..d0c0704f5 --- /dev/null +++ b/lib/count-leading-zeros.c @@ -0,0 +1,3 @@ +#include +#define COUNT_LEADING_ZEROS_INLINE _GL_EXTERN_INLINE +#include "count-leading-zeros.h" diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index cbb3264e3..7eb0cf2b0 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -23,6 +23,11 @@ #include #include "verify.h" +_GL_INLINE_HEADER_BEGIN +#ifndef COUNT_LEADING_ZEROS_INLINE +# define COUNT_LEADING_ZEROS_INLINE _GL_INLINE +#endif + /* Expand the code which computes the number of leading zeros of the local variable 'x' of type TYPE (an unsigned integer type) and returns it from the current function. */ @@ -44,7 +49,7 @@ /* Compute and return the number of leading zeros in the least significant 32 bits of X. */ -static inline int +COUNT_LEADING_ZEROS_INLINE int count_leading_zeros_32 (unsigned int x) { /* http://graphics.stanford.edu/~seander/bithacks.html */ @@ -66,14 +71,14 @@ count_leading_zeros_32 (unsigned int x) #endif /* Compute and return the number of leading zeros in X. */ -static inline int +COUNT_LEADING_ZEROS_INLINE int count_leading_zeros (unsigned int x) { COUNT_LEADING_ZEROS (__builtin_clz, unsigned int); } /* Compute and return the number of leading zeros in X. */ -static inline int +COUNT_LEADING_ZEROS_INLINE int count_leading_zeros_l (unsigned long int x) { COUNT_LEADING_ZEROS (__builtin_clzl, unsigned long int); @@ -81,11 +86,13 @@ count_leading_zeros_l (unsigned long int x) #if HAVE_UNSIGNED_LONG_LONG_INT /* Compute and return the number of leading zeros in X. */ -static inline int +COUNT_LEADING_ZEROS_INLINE int count_leading_zeros_ll (unsigned long long int x) { COUNT_LEADING_ZEROS (__builtin_clzll, unsigned long long int); } #endif +_GL_INLINE_HEADER_END + #endif /* COUNT_LEADING_ZEROS_H */ diff --git a/m4/count-leading-zeros.m4 b/m4/count-leading-zeros.m4 index 1efb9414e..5fef2da87 100644 --- a/m4/count-leading-zeros.m4 +++ b/m4/count-leading-zeros.m4 @@ -1,4 +1,4 @@ -# count-leading-zeros.m4 serial 1 +# count-leading-zeros.m4 serial 2 dnl Copyright (C) 2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,7 +9,4 @@ AC_DEFUN([gl_COUNT_LEADING_ZEROS], dnl We don't need (and can't compile) count_leading_zeros_ll dnl unless the type 'unsigned long long int' exists. AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) - - dnl Prerequisites of lib/count-leading-zeros.h. - AC_REQUIRE([AC_C_INLINE]) ]) diff --git a/modules/count-leading-zeros b/modules/count-leading-zeros index 60ec930a3..f6ec283cd 100644 --- a/modules/count-leading-zeros +++ b/modules/count-leading-zeros @@ -2,16 +2,19 @@ Description: Counts the number of leading 0-bits in a word. Files: +lib/count-leading-zeros.c lib/count-leading-zeros.h m4/count-leading-zeros.m4 Depends-on: +extern-inline verify configure.ac: gl_COUNT_LEADING_ZEROS Makefile.am: +lib_SOURCES += count-leading-zeros.c Include: "count-leading-zeros.h" -- 2.11.0