Commit 348b0c31 by Falk Hueffner Committed by Phil Edwards

std_bitset.h: Replace CHAR_BIT with __CHAR_BIT__, use numeric_limits for bits-per-word values.

2003-02-03  Falk Hueffner  <falk.hueffner@student.uni-tuebingen.de>
            Phil Edwards  <pme@gcc.gnu.org>

	* include/std/std_bitset.h:  Replace CHAR_BIT with __CHAR_BIT__, use
	numeric_limits for bits-per-word values.
	(_Base_bitset::_M_do_count, _Base_bitset<1>::_M_do_count):
	Use __builtin_popcountl instead.
	(_Base_bitset::_M_do_find_first, _Base_bitset::_M_do_find_next,
	_Base_bitset<1>::_M_do_find_first, _Base_bitset<1>::_M_do_find_next):
	Use __builtin_ctzl instead.
	(_S_bit_count, _S_first_one):  Remove.
	* config/linker-map.gnu (GLIBCPP_3.4):  Remove std::_S_bit_count.
	* src/Makefile.am (sources):  Remove bitset.cc.
	* src/bitset.cc:  Delete file.
	* src/Makefile.in:  Regenerate.

Co-Authored-By: Phil Edwards <pme@gcc.gnu.org>

From-SVN: r62335
parent 2d7b3505
2003-02-03 Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
Phil Edwards <pme@gcc.gnu.org>
* include/std/std_bitset.h: Replace CHAR_BIT with __CHAR_BIT__, use
numeric_limits for bits-per-word values.
(_Base_bitset::_M_do_count, _Base_bitset<1>::_M_do_count):
Use __builtin_popcountl instead.
(_Base_bitset::_M_do_find_first, _Base_bitset::_M_do_find_next,
_Base_bitset<1>::_M_do_find_first, _Base_bitset<1>::_M_do_find_next):
Use __builtin_ctzl instead.
(_S_bit_count, _S_first_one): Remove.
* config/linker-map.gnu (GLIBCPP_3.4): Remove std::_S_bit_count.
* src/Makefile.am (sources): Remove bitset.cc.
* src/bitset.cc: Delete file.
* src/Makefile.in: Regenerate.
2003-02-03 Phil Edwards <pme@gcc.gnu.org>
PR libstdc++/9527, PR libstdc++/8713
......
......@@ -62,8 +62,7 @@ GLIBCPP_3.4 {
std::__basic_file*;
std::__num_base*;
std::__timepunct*;
std::__numeric_limits_base*;
std::_S_bit_count
std::__numeric_limits_base*
};
# Names not in an 'extern' block are mangled names.
......
// <bitset> -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc.
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
......@@ -52,6 +52,7 @@
#include <cstddef> // for size_t
#include <cstring> // for memset
#include <limits> // for numeric_limits
#include <string>
#include <bits/functexcept.h> // for invalid_argument, out_of_range,
// overflow_error
......@@ -59,15 +60,12 @@
#include <istream> // for istream (operator>>)
#define _GLIBCPP_BITSET_BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
#define _GLIBCPP_BITSET_BITS_PER_WORD numeric_limits<unsigned long>::digits
#define _GLIBCPP_BITSET_WORDS(__n) \
((__n) < 1 ? 0 : ((__n) + _GLIBCPP_BITSET_BITS_PER_WORD - 1)/_GLIBCPP_BITSET_BITS_PER_WORD)
namespace std
{
extern unsigned char _S_bit_count[256];
extern unsigned char _S_first_one[256];
/**
* @if maint
* Base class, general case. It is a class inveriant that _Nw will be
......@@ -97,7 +95,7 @@ namespace std
static size_t
_S_whichbyte(size_t __pos )
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / CHAR_BIT; }
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
static size_t
_S_whichbit(size_t __pos )
......@@ -191,14 +189,8 @@ namespace std
_M_do_count() const
{
size_t __result = 0;
const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
const unsigned char* __end_ptr = (const unsigned char*)(_M_w + _Nw);
while ( __byte_ptr < __end_ptr )
{
__result += _S_bit_count[*__byte_ptr];
__byte_ptr++;
}
for (size_t __i = 0; __i < _Nw; __i++)
__result += __builtin_popcountl(_M_w[__i]);
return __result;
}
......@@ -280,23 +272,12 @@ namespace std
size_t
_Base_bitset<_Nw>::_M_do_find_first(size_t __not_found) const
{
for (size_t __i = 0; __i < _Nw; __i++ )
for (size_t __i = 0; __i < _Nw; __i++)
{
_WordT __thisword = _M_w[__i];
if ( __thisword != static_cast<_WordT>(0) )
{
// find byte within word
for (size_t __j = 0; __j < sizeof(_WordT); __j++ )
{
unsigned char __this_byte
= static_cast<unsigned char>(__thisword & (~(unsigned char)0));
if (__this_byte)
return __i*_GLIBCPP_BITSET_BITS_PER_WORD + __j*CHAR_BIT +
_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
if (__thisword != static_cast<_WordT>(0))
return __i * _GLIBCPP_BITSET_BITS_PER_WORD
+ __builtin_ctzl(__thisword);
}
// not found, so return an indication of failure.
return __not_found;
......@@ -318,44 +299,20 @@ namespace std
_WordT __thisword = _M_w[__i];
// mask off bits below bound
__thisword &= (~static_cast<_WordT>(0)) << _S_whichbit(__prev);
__thisword >>= __prev + 1;
if ( __thisword != static_cast<_WordT>(0) )
{
// find byte within word
// get first byte into place
__thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
for (size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++)
{
unsigned char __this_byte
= static_cast<unsigned char>(__thisword & (~(unsigned char)0));
if ( __this_byte )
return __i*_GLIBCPP_BITSET_BITS_PER_WORD + __j*CHAR_BIT +
_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
if (__thisword != static_cast<_WordT>(0))
return __i * _GLIBCPP_BITSET_BITS_PER_WORD
+ __builtin_ctzl(__thisword);
// check subsequent words
__i++;
for ( ; __i < _Nw; __i++ )
{
__thisword = _M_w[__i];
if ( __thisword != static_cast<_WordT>(0) )
{
// find byte within word
for (size_t __j = 0; __j < sizeof(_WordT); __j++ )
{
unsigned char __this_byte
= static_cast<unsigned char>(__thisword & (~(unsigned char)0));
if ( __this_byte )
return __i*_GLIBCPP_BITSET_BITS_PER_WORD + __j*CHAR_BIT +
_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
if (__thisword != static_cast<_WordT>(0))
return __i * _GLIBCPP_BITSET_BITS_PER_WORD
+ __builtin_ctzl(__thisword);
}
// not found, so return an indication of failure.
return __not_found;
......@@ -384,7 +341,7 @@ namespace std
static size_t
_S_whichbyte(size_t __pos )
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / CHAR_BIT; }
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
static size_t
_S_whichbit(size_t __pos )
......@@ -438,29 +395,34 @@ namespace std
_M_is_any() const { return _M_w != 0; }
size_t
_M_do_count() const
{
size_t __result = 0;
const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
const unsigned char* __end_ptr
= ((const unsigned char*)&_M_w)+sizeof(_M_w);
while ( __byte_ptr < __end_ptr )
{
__result += _S_bit_count[*__byte_ptr];
__byte_ptr++;
}
return __result;
}
_M_do_count() const { return __builtin_popcountl(_M_w); }
unsigned long
_M_do_to_ulong() const { return _M_w; }
size_t
_M_do_find_first(size_t __not_found) const;
_M_do_find_first(size_t __not_found) const
{
if (_M_w != 0)
return __builtin_ctzl(_M_w);
else
return __not_found;
}
// find the next "on" bit that follows "prev"
size_t
_M_do_find_next(size_t __prev, size_t __not_found) const;
_M_do_find_next(size_t __prev, size_t __not_found) const
{
++__prev;
if (__prev >= _GLIBCPP_BITSET_BITS_PER_WORD)
return __not_found;
_WordT __x = _M_w >> __prev;
if (__x != 0)
return __builtin_ctzl(__x) + __prev;
else
return __not_found;
}
};
......@@ -485,7 +447,7 @@ namespace std
static size_t
_S_whichbyte(size_t __pos )
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / CHAR_BIT; }
{ return (__pos % _GLIBCPP_BITSET_BITS_PER_WORD) / __CHAR_BIT__; }
static size_t
_S_whichbit(size_t __pos )
......@@ -1248,5 +1210,6 @@ namespace std
} // namespace std
#undef _GLIBCPP_BITSET_WORDS
#undef _GLIBCPP_BITSET_BITS_PER_WORD
#endif /* _GLIBCPP_BITSET_H */
......@@ -117,7 +117,6 @@ basic_file.cc: ${glibcpp_srcdir}/@BASIC_FILE_CC@
# Sources present in the src directory.
sources = \
bitset.cc \
codecvt.cc \
complex_io.cc \
concept-inst.cc \
......
# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
......@@ -146,7 +146,7 @@ glibcpp_builddir = @glibcpp_builddir@
toolexecdir = @glibcpp_toolexecdir@
toolexeclibdir = @glibcpp_toolexeclibdir@
toolexeclib_LTLIBRARIES = libstdc++.la
@GLIBCPP_BUILD_VERSIONED_SHLIB_TRUE@version_arg = @GLIBCPP_BUILD_VERSIONED_SHLIB_TRUE@-Wl,--version-script=libstdc++-symbol.ver
@GLIBCPP_BUILD_VERSIONED_SHLIB_TRUE@version_arg = -Wl,--version-script=libstdc++-symbol.ver
@GLIBCPP_BUILD_VERSIONED_SHLIB_FALSE@version_arg =
# Compile flags that should be constant throughout the build, both for
......@@ -155,13 +155,11 @@ OPTIMIZE_CXXFLAGS = @OPTIMIZE_CXXFLAGS@
# These bits are all figured out from configure. Look in acinclude.m4
# or configure.in to see how they are set. See GLIBCPP_EXPORT_FLAGS
CONFIG_CXXFLAGS = \
@SECTION_FLAGS@ @EXTRA_CXX_FLAGS@
CONFIG_CXXFLAGS = @SECTION_FLAGS@ @EXTRA_CXX_FLAGS@
# Warning flags to use.
WARN_CXXFLAGS = \
@WARN_FLAGS@ $(WERROR) -fdiagnostics-show-location=once
WARN_CXXFLAGS = @WARN_FLAGS@ $(WERROR) -fdiagnostics-show-location=once
# Use common includes from acinclude.m4/GLIBCPP_EXPORT_INCLUDES
......@@ -171,79 +169,33 @@ LIBSUPCXX_INCLUDES = @LIBSUPCXX_INCLUDES@
LIBIO_INCLUDES = @LIBIO_INCLUDES@
TOPLEVEL_INCLUDES = @TOPLEVEL_INCLUDES@
INCLUDES = \
-nostdinc++ \
$(GLIBCPP_INCLUDES) \
$(LIBSUPCXX_INCLUDES) $(LIBIO_INCLUDES) $(LIBMATH_INCLUDES) \
$(TOPLEVEL_INCLUDES)
INCLUDES = -nostdinc++ $(GLIBCPP_INCLUDES) $(LIBSUPCXX_INCLUDES) $(LIBIO_INCLUDES) $(LIBMATH_INCLUDES) $(TOPLEVEL_INCLUDES)
# Source files linked in via configuration/make substitution for a
# particular target.
target_sources = \
codecvt_members.cc \
collate_members.cc \
ctype_members.cc \
messages_members.cc \
monetary_members.cc \
numeric_members.cc \
time_members.cc
target_sources = codecvt_members.cc collate_members.cc ctype_members.cc messages_members.cc monetary_members.cc numeric_members.cc time_members.cc
# Source files linked in via configuration/make substitution for a
# particular target, but with ad hoc naming rules.
target_sources_extra = \
basic_file.cc \
c++locale.cc
target_sources_extra = basic_file.cc c++locale.cc
# Sources present in the src directory.
sources = \
bitset.cc \
codecvt.cc \
complex_io.cc \
concept-inst.cc \
ctype.cc \
ext-inst.cc \
fstream.cc \
fstream-inst.cc \
functexcept.cc \
globals.cc \
io-inst.cc \
ios.cc \
istream-inst.cc \
limits.cc \
locale.cc \
locale-inst.cc \
localename.cc \
misc-inst.cc \
ostream-inst.cc \
sstream-inst.cc \
stdexcept.cc \
stl-inst.cc \
streambuf-inst.cc \
string-inst.cc \
strstream.cc \
valarray-inst.cc \
wstring-inst.cc \
${target_sources} \
${target_sources_extra}
sources = codecvt.cc complex_io.cc concept-inst.cc ctype.cc ext-inst.cc fstream.cc fstream-inst.cc functexcept.cc globals.cc io-inst.cc ios.cc istream-inst.cc limits.cc locale.cc locale-inst.cc localename.cc misc-inst.cc ostream-inst.cc sstream-inst.cc stdexcept.cc stl-inst.cc streambuf-inst.cc string-inst.cc strstream.cc valarray-inst.cc wstring-inst.cc ${target_sources} ${target_sources_extra}
VPATH = $(top_srcdir)/src:$(top_srcdir)
libstdc___la_SOURCES = $(sources)
libstdc___la_LIBADD = \
$(top_builddir)/libmath/libmath.la @libio_la@ \
$(top_builddir)/libsupc++/libsupc++convenience.la
libstdc___la_LIBADD = $(top_builddir)/libmath/libmath.la @libio_la@ $(top_builddir)/libsupc++/libsupc++convenience.la
libstdc___la_DEPENDENCIES = libstdc++-symbol.ver $(libstdc___la_LIBADD)
libstdc___la_LDFLAGS = \
-version-info @libtool_VERSION@ ${version_arg} \
-lm @LIBUNWIND_FLAG@
libstdc___la_LDFLAGS = -version-info @libtool_VERSION@ ${version_arg} -lm @LIBUNWIND_FLAG@
# Use special rules for the deprecated source files so that they find
......@@ -255,12 +207,7 @@ GLIBCPP_INCLUDE_DIR = @glibcpp_builddir@/include
# set this option because CONFIG_CXXFLAGS has to be after
# OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
# as the occasion call for it.
AM_CXXFLAGS = \
-fno-implicit-templates \
$(LIBSUPCXX_CXXFLAGS) \
$(WARN_CXXFLAGS) \
$(OPTIMIZE_CXXFLAGS) \
$(CONFIG_CXXFLAGS)
AM_CXXFLAGS = -fno-implicit-templates $(LIBSUPCXX_CXXFLAGS) $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
# libstdc++ libtool notes
......@@ -281,8 +228,7 @@ AM_CXXFLAGS = \
# correct solution is to add `--tag CXX' to LTCXXCOMPILE and maybe
# CXXLINK, just after $(LIBTOOL), so that libtool doesn't have to
# attempt to infer which configuration to use
LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
# 3) We'd have a problem when building the shared libstdc++ object if
......@@ -291,8 +237,7 @@ LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) \
# course is problematic at this point. So, we get the top-level
# directory to configure libstdc++-v3 to use gcc as the C++
# compilation driver.
CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
@OPT_LDFLAGS@ @SECTION_LDFLAGS@ $(AM_CXXFLAGS) $(LDFLAGS) -o $@
CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) @OPT_LDFLAGS@ @SECTION_LDFLAGS@ $(AM_CXXFLAGS) $(LDFLAGS) -o $@
debugdir = debug
......@@ -305,10 +250,10 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I..
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
libstdc___la_OBJECTS = bitset.lo codecvt.lo complex_io.lo \
concept-inst.lo ctype.lo ext-inst.lo fstream.lo fstream-inst.lo \
functexcept.lo globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo \
locale.lo locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
libstdc___la_OBJECTS = codecvt.lo complex_io.lo concept-inst.lo \
ctype.lo ext-inst.lo fstream.lo fstream-inst.lo functexcept.lo \
globals.lo io-inst.lo ios.lo istream-inst.lo limits.lo locale.lo \
locale-inst.lo localename.lo misc-inst.lo ostream-inst.lo \
sstream-inst.lo stdexcept.lo stl-inst.lo streambuf-inst.lo \
string-inst.lo strstream.lo valarray-inst.lo wstring-inst.lo \
codecvt_members.lo collate_members.lo ctype_members.lo \
......@@ -322,7 +267,7 @@ DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
TAR = tar
GZIP_ENV = --best
SOURCES = $(libstdc___la_SOURCES)
OBJECTS = $(libstdc___la_OBJECTS)
......@@ -434,7 +379,7 @@ TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|| (cd $(srcdir) && etags -o $$here/TAGS $(ETAGS_ARGS) $$tags $$unique $(LISP))
mostlyclean-tags:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment