1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2025-08-08 17:22:05 +03:00

count-one-bits: better 'inline'

* lib/count-one-bits.c: New file.
* lib/count-one-bits.h (COUNT_ONE_BITS_INLINE):
New macro.  Replace all uses of 'static inline' with it.
Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
* m4/count-one-bits.m4 (gl_COUNT_ONE_BITS):
Do not require AC_C_INLINE.
* modules/count-one-bits (Files, lib_SOURCES):
Add lib/count-one-bits.c.
(Depends-on): Add extern-inline.
This commit is contained in:
Paul Eggert
2012-11-20 22:25:05 -08:00
parent 82d259c28d
commit aa7a0991de
5 changed files with 29 additions and 8 deletions

View File

@@ -1,5 +1,16 @@
2012-11-29 Paul Eggert <eggert@cs.ucla.edu> 2012-11-29 Paul Eggert <eggert@cs.ucla.edu>
count-one-bits: better 'inline'
* lib/count-one-bits.c: New file.
* lib/count-one-bits.h (COUNT_ONE_BITS_INLINE):
New macro. Replace all uses of 'static inline' with it.
Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
* m4/count-one-bits.m4 (gl_COUNT_ONE_BITS):
Do not require AC_C_INLINE.
* modules/count-one-bits (Files, lib_SOURCES):
Add lib/count-one-bits.c.
(Depends-on): Add extern-inline.
count-leading-zeros: better 'inline' count-leading-zeros: better 'inline'
* lib/count-leading-zeros.c: New file. * lib/count-leading-zeros.c: New file.
* lib/count-leading-zeros.h (COUNT_LEADING_ZEROS_INLINE): * lib/count-leading-zeros.h (COUNT_LEADING_ZEROS_INLINE):

3
lib/count-one-bits.c Normal file
View File

@@ -0,0 +1,3 @@
#include <config.h>
#define COUNT_ONE_BITS_INLINE _GL_EXTERN_INLINE
#include "count-one-bits.h"

View File

@@ -22,6 +22,11 @@
#include <stdlib.h> #include <stdlib.h>
#include "verify.h" #include "verify.h"
_GL_INLINE_HEADER_BEGIN
#ifndef COUNT_ONE_BITS_INLINE
# define COUNT_ONE_BITS_INLINE _GL_INLINE
#endif
/* Expand the code which computes the number of 1-bits of the local /* Expand the code which computes the number of 1-bits of the local
variable 'x' of type TYPE (an unsigned integer type) and returns it variable 'x' of type TYPE (an unsigned integer type) and returns it
from the current function. */ from the current function. */
@@ -40,7 +45,7 @@
/* Compute and return the number of 1-bits set in the least /* Compute and return the number of 1-bits set in the least
significant 32 bits of X. */ significant 32 bits of X. */
static inline int COUNT_ONE_BITS_INLINE int
count_one_bits_32 (unsigned int x) count_one_bits_32 (unsigned int x)
{ {
x = ((x & 0xaaaaaaaaU) >> 1) + (x & 0x55555555U); x = ((x & 0xaaaaaaaaU) >> 1) + (x & 0x55555555U);
@@ -52,14 +57,14 @@ count_one_bits_32 (unsigned int x)
#endif #endif
/* Compute and return the number of 1-bits set in X. */ /* Compute and return the number of 1-bits set in X. */
static inline int COUNT_ONE_BITS_INLINE int
count_one_bits (unsigned int x) count_one_bits (unsigned int x)
{ {
COUNT_ONE_BITS (__builtin_popcount, unsigned int); COUNT_ONE_BITS (__builtin_popcount, unsigned int);
} }
/* Compute and return the number of 1-bits set in X. */ /* Compute and return the number of 1-bits set in X. */
static inline int COUNT_ONE_BITS_INLINE int
count_one_bits_l (unsigned long int x) count_one_bits_l (unsigned long int x)
{ {
COUNT_ONE_BITS (__builtin_popcountl, unsigned long int); COUNT_ONE_BITS (__builtin_popcountl, unsigned long int);
@@ -67,11 +72,13 @@ count_one_bits_l (unsigned long int x)
#if HAVE_UNSIGNED_LONG_LONG_INT #if HAVE_UNSIGNED_LONG_LONG_INT
/* Compute and return the number of 1-bits set in X. */ /* Compute and return the number of 1-bits set in X. */
static inline int COUNT_ONE_BITS_INLINE int
count_one_bits_ll (unsigned long long int x) count_one_bits_ll (unsigned long long int x)
{ {
COUNT_ONE_BITS (__builtin_popcountll, unsigned long long int); COUNT_ONE_BITS (__builtin_popcountll, unsigned long long int);
} }
#endif #endif
_GL_INLINE_HEADER_END
#endif /* COUNT_ONE_BITS_H */ #endif /* COUNT_ONE_BITS_H */

View File

@@ -1,4 +1,4 @@
# count-one-bits.m4 serial 2 # count-one-bits.m4 serial 3
dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc. dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
@@ -9,7 +9,4 @@ AC_DEFUN([gl_COUNT_ONE_BITS],
dnl We don't need (and can't compile) count_one_bits_ll dnl We don't need (and can't compile) count_one_bits_ll
dnl unless the type 'unsigned long long int' exists. dnl unless the type 'unsigned long long int' exists.
AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT])
dnl Prerequisites of lib/count-one-bits.h.
AC_REQUIRE([AC_C_INLINE])
]) ])

View File

@@ -2,16 +2,19 @@ Description:
Counts the number of 1-bits in a word. Counts the number of 1-bits in a word.
Files: Files:
lib/count-one-bits.c
lib/count-one-bits.h lib/count-one-bits.h
m4/count-one-bits.m4 m4/count-one-bits.m4
Depends-on: Depends-on:
extern-inline
verify verify
configure.ac: configure.ac:
gl_COUNT_ONE_BITS gl_COUNT_ONE_BITS
Makefile.am: Makefile.am:
lib_SOURCES += count-one-bits.c
Include: Include:
"count-one-bits.h" "count-one-bits.h"