From: Paolo Carlini Date: Fri, 18 Nov 2011 12:37:06 +0000 (+0000) Subject: hash-long-double-aux.cc: Rename to... X-Git-Tag: releases/gcc-4.7.0~2121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=72f1c34bd49cceca3dc1f8529161353b1aa89c41;p=thirdparty%2Fgcc.git hash-long-double-aux.cc: Rename to... 2011-11-18 Paolo Carlini * src/hash-long-double-aux.cc: Rename to... * src/hash-long-double-tr1-aux.cc: ... this. * src/compatibility-ldbl.cc: Adjust. * src/hash_tr1.cc: Likewise. * src/hash_c++0x.cc: Don't use src/hash-long-double-aux.cc. * include/bits/functional_hash.h (hash<_Tp*>::operator(), specs for integer types, hash::operator(), hash::operator(), hash::operator()): Declare noexcept. * include/debug/bitset (hash<__debug::bitset>::operator()): Likewise. * include/debug/vector (hash<__debug::vector>::operator()): Likewise. * include/std/system_error (hash::operator()): Likewise. * include/std/thread (hash::operator()): Likewise. * include/std/bitset (hash::operator()): Likewise. * include/std/typeindex (hash::operator()): Likewise. * include/profile/bitset (hash<__profile::vector>::operator()): Likewise. * include/profile/vector (hash<__profile::vector>::operator()): Likewise. * include/ext/vstring.h (hash<__vstring>::operator(), hash<__wvstring>::operator(), hash<__u16vstring>::operator(), hash<__u32vstring>::operator()): Likewise. * include/bits/shared_ptr.h (hash::operator()): Likewise. * include/bits/shared_ptr_base.h (hash<__shared_ptr>::operator()): Likewise. * include/bits/unique_ptr.h (hash::operator()): Likewise. * include/bits/basic_string.h (hash::operator(), hash::operator(), hash::operator(), hash::operator()): Likewise. * include/bits/vector.tcc (hash::operator()): Likewise. * include/bits/stl_bvector.h (hash::operator()): Likewise. * libsupc++/typeinfo (type_info::hash_code): Use noexcept instead of throw(). From-SVN: r181473 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c52db3895837..0d68464933c9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,38 @@ +2011-11-18 Paolo Carlini + + * src/hash-long-double-aux.cc: Rename to... + * src/hash-long-double-tr1-aux.cc: ... this. + * src/compatibility-ldbl.cc: Adjust. + * src/hash_tr1.cc: Likewise. + * src/hash_c++0x.cc: Don't use src/hash-long-double-aux.cc. + * include/bits/functional_hash.h (hash<_Tp*>::operator(), specs + for integer types, hash::operator(), hash::operator(), + hash::operator()): Declare noexcept. + * include/debug/bitset (hash<__debug::bitset>::operator()): Likewise. + * include/debug/vector (hash<__debug::vector>::operator()): Likewise. + * include/std/system_error (hash::operator()): Likewise. + * include/std/thread (hash::operator()): Likewise. + * include/std/bitset (hash::operator()): Likewise. + * include/std/typeindex (hash::operator()): Likewise. + * include/profile/bitset (hash<__profile::vector>::operator()): + Likewise. + * include/profile/vector (hash<__profile::vector>::operator()): + Likewise. + * include/ext/vstring.h (hash<__vstring>::operator(), + hash<__wvstring>::operator(), hash<__u16vstring>::operator(), + hash<__u32vstring>::operator()): Likewise. + * include/bits/shared_ptr.h (hash::operator()): Likewise. + * include/bits/shared_ptr_base.h (hash<__shared_ptr>::operator()): + Likewise. + * include/bits/unique_ptr.h (hash::operator()): Likewise. + * include/bits/basic_string.h (hash::operator(), + hash::operator(), hash::operator(), + hash::operator()): Likewise. + * include/bits/vector.tcc (hash::operator()): Likewise. + * include/bits/stl_bvector.h (hash::operator()): Likewise. + * libsupc++/typeinfo (type_info::hash_code): Use noexcept instead of + throw(). + 2011-11-17 Richard Henderson PR libstdc++/51181 diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 00f9bccd419e..169daf586138 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -3044,7 +3044,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const string& __s) const + operator()(const string& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length()); } }; @@ -3055,7 +3055,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const wstring& __s) const + operator()(const wstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); } }; @@ -3069,7 +3069,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const u16string& __s) const + operator()(const u16string& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char16_t)); } }; @@ -3080,7 +3080,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const u32string& __s) const + operator()(const u32string& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char32_t)); } }; diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h index e77cb4e17bfb..2b82b21f7160 100644 --- a/libstdc++-v3/include/bits/functional_hash.h +++ b/libstdc++-v3/include/bits/functional_hash.h @@ -66,61 +66,64 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash<_Tp*> : public __hash_base { size_t - operator()(_Tp* __p) const + operator()(_Tp* __p) const noexcept { return reinterpret_cast(__p); } }; // Explicit specializations for integer types. #define _Cxx_hashtable_define_trivial_hash(_Tp) \ template<> \ - inline size_t \ - hash<_Tp>::operator()(_Tp __val) const \ - { return static_cast(__val); } + struct hash<_Tp> : public __hash_base \ + { \ + size_t \ + operator()(_Tp __val) const noexcept \ + { return static_cast(__val); } \ + }; /// Explicit specialization for bool. - _Cxx_hashtable_define_trivial_hash(bool); + _Cxx_hashtable_define_trivial_hash(bool) /// Explicit specialization for char. - _Cxx_hashtable_define_trivial_hash(char); + _Cxx_hashtable_define_trivial_hash(char) /// Explicit specialization for signed char. - _Cxx_hashtable_define_trivial_hash(signed char); + _Cxx_hashtable_define_trivial_hash(signed char) /// Explicit specialization for unsigned char. - _Cxx_hashtable_define_trivial_hash(unsigned char); + _Cxx_hashtable_define_trivial_hash(unsigned char) /// Explicit specialization for wchar_t. - _Cxx_hashtable_define_trivial_hash(wchar_t); + _Cxx_hashtable_define_trivial_hash(wchar_t) /// Explicit specialization for char16_t. - _Cxx_hashtable_define_trivial_hash(char16_t); + _Cxx_hashtable_define_trivial_hash(char16_t) /// Explicit specialization for char32_t. - _Cxx_hashtable_define_trivial_hash(char32_t); + _Cxx_hashtable_define_trivial_hash(char32_t) /// Explicit specialization for short. - _Cxx_hashtable_define_trivial_hash(short); + _Cxx_hashtable_define_trivial_hash(short) /// Explicit specialization for int. - _Cxx_hashtable_define_trivial_hash(int); + _Cxx_hashtable_define_trivial_hash(int) /// Explicit specialization for long. - _Cxx_hashtable_define_trivial_hash(long); + _Cxx_hashtable_define_trivial_hash(long) /// Explicit specialization for long long. - _Cxx_hashtable_define_trivial_hash(long long); + _Cxx_hashtable_define_trivial_hash(long long) /// Explicit specialization for unsigned short. - _Cxx_hashtable_define_trivial_hash(unsigned short); + _Cxx_hashtable_define_trivial_hash(unsigned short) /// Explicit specialization for unsigned int. - _Cxx_hashtable_define_trivial_hash(unsigned int); + _Cxx_hashtable_define_trivial_hash(unsigned int) /// Explicit specialization for unsigned long. - _Cxx_hashtable_define_trivial_hash(unsigned long); + _Cxx_hashtable_define_trivial_hash(unsigned long) /// Explicit specialization for unsigned long long. - _Cxx_hashtable_define_trivial_hash(unsigned long long); + _Cxx_hashtable_define_trivial_hash(unsigned long long) #undef _Cxx_hashtable_define_trivial_hash @@ -162,26 +165,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Specialization for float. template<> - inline size_t - hash::operator()(float __val) const + struct hash : public __hash_base { - // 0 and -0 both hash to zero. - return __val != 0.0f ? std::_Hash_impl::hash(__val) : 0; - } + size_t + operator()(float __val) const noexcept + { + // 0 and -0 both hash to zero. + return __val != 0.0f ? std::_Hash_impl::hash(__val) : 0; + } + }; /// Specialization for double. template<> - inline size_t - hash::operator()(double __val) const + struct hash : public __hash_base { - // 0 and -0 both hash to zero. - return __val != 0.0 ? std::_Hash_impl::hash(__val) : 0; - } + size_t + operator()(double __val) const noexcept + { + // 0 and -0 both hash to zero. + return __val != 0.0 ? std::_Hash_impl::hash(__val) : 0; + } + }; /// Specialization for long double. template<> - _GLIBCXX_PURE size_t - hash::operator()(long double __val) const; + struct hash + : public __hash_base + { + _GLIBCXX_PURE size_t + operator()(long double __val) const noexcept; + }; // @} group hashes diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 32addf95105e..33128dd4ed63 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -619,7 +619,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base> { size_t - operator()(const shared_ptr<_Tp>& __s) const + operator()(const shared_ptr<_Tp>& __s) const noexcept { return std::hash<_Tp*>()(__s.get()); } }; diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index fbbadd1aaaac..c06775475532 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -1450,7 +1450,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base> { size_t - operator()(const __shared_ptr<_Tp, _Lp>& __s) const + operator()(const __shared_ptr<_Tp, _Lp>& __s) const noexcept { return std::hash<_Tp*>()(__s.get()); } }; diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 8f286400aec7..bec63ff03f97 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -1075,7 +1075,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base> { size_t - operator()(const _GLIBCXX_STD_C::vector& __b) const; + operator()(const _GLIBCXX_STD_C::vector&) const noexcept; }; _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 869d931330c1..0a127996e52e 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -545,7 +545,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base> { size_t - operator()(const unique_ptr<_Tp, _Dp>& __u) const + operator()(const unique_ptr<_Tp, _Dp>& __u) const noexcept { typedef unique_ptr<_Tp, _Dp> _UP; return std::hash()(__u.get()); diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index b74684228c1a..d9c3b659e6b5 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -818,7 +818,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template size_t hash<_GLIBCXX_STD_C::vector>:: - operator()(const _GLIBCXX_STD_C::vector& __b) const + operator()(const _GLIBCXX_STD_C::vector& __b) const noexcept { size_t __hash = 0; using _GLIBCXX_STD_C::_S_word_bit; diff --git a/libstdc++-v3/include/debug/bitset b/libstdc++-v3/include/debug/bitset index 21d281787ad7..f44bbcddefd1 100644 --- a/libstdc++-v3/include/debug/bitset +++ b/libstdc++-v3/include/debug/bitset @@ -414,7 +414,7 @@ namespace __debug : public __hash_base> { size_t - operator()(const __debug::bitset<_Nb>& __b) const + operator()(const __debug::bitset<_Nb>& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); } }; #endif diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 82662b446054..5ee0fabc32a1 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -625,7 +625,7 @@ namespace __debug : public __hash_base> { size_t - operator()(const __debug::vector& __b) const + operator()(const __debug::vector& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::vector>() (__b._M_base()); } }; diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index a613e364d3a4..8c4120a3be2c 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -2769,7 +2769,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const __gnu_cxx::__vstring& __s) const + operator()(const __gnu_cxx::__vstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length()); } }; @@ -2780,7 +2780,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const __gnu_cxx::__wvstring& __s) const + operator()(const __gnu_cxx::__wvstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(wchar_t)); } }; @@ -2793,7 +2793,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const __gnu_cxx::__u16vstring& __s) const + operator()(const __gnu_cxx::__u16vstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char16_t)); } }; @@ -2804,7 +2804,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const __gnu_cxx::__u32vstring& __s) const + operator()(const __gnu_cxx::__u32vstring& __s) const noexcept { return std::_Hash_impl::hash(__s.data(), __s.length() * sizeof(char32_t)); } }; diff --git a/libstdc++-v3/include/profile/bitset b/libstdc++-v3/include/profile/bitset index bd4aa3e152f9..a2cba5efe801 100644 --- a/libstdc++-v3/include/profile/bitset +++ b/libstdc++-v3/include/profile/bitset @@ -372,7 +372,7 @@ namespace __profile : public __hash_base> { size_t - operator()(const __profile::bitset<_Nb>& __b) const + operator()(const __profile::bitset<_Nb>& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::bitset<_Nb>>()(__b._M_base()); } }; #endif diff --git a/libstdc++-v3/include/profile/vector b/libstdc++-v3/include/profile/vector index 86aefd649e32..0526c5aabb7d 100644 --- a/libstdc++-v3/include/profile/vector +++ b/libstdc++-v3/include/profile/vector @@ -529,7 +529,7 @@ namespace __profile : public __hash_base> { size_t - operator()(const __profile::vector& __b) const + operator()(const __profile::vector& __b) const noexcept { return std::hash<_GLIBCXX_STD_C::vector>() (__b._M_base()); } }; diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset index 813ed4b2599b..e07c5e089706 100644 --- a/libstdc++-v3/include/std/bitset +++ b/libstdc++-v3/include/std/bitset @@ -1555,7 +1555,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base> { size_t - operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const + operator()(const _GLIBCXX_STD_C::bitset<_Nb>& __b) const noexcept { const size_t __clength = (_Nb + __CHAR_BIT__ - 1) / __CHAR_BIT__; return std::_Hash_impl::hash(__b._M_getdata(), __clength); @@ -1567,7 +1567,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base> { size_t - operator()(const _GLIBCXX_STD_C::bitset<0>&) const + operator()(const _GLIBCXX_STD_C::bitset<0>&) const noexcept { return 0; } }; diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 565261e709bd..19482bc21811 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -361,7 +361,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const error_code& __e) const + operator()(const error_code& __e) const noexcept { const size_t __tmp = std::_Hash_impl::hash(__e._M_value); return std::_Hash_impl::__hash_combine(__e._M_cat, __tmp); diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread index 8cc06903ebf9..1d1733731bf4 100644 --- a/libstdc++-v3/include/std/thread +++ b/libstdc++-v3/include/std/thread @@ -221,7 +221,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __hash_base { size_t - operator()(const thread::id& __id) const + operator()(const thread::id& __id) const noexcept { return std::_Hash_impl::hash(__id._M_thread); } }; diff --git a/libstdc++-v3/include/std/typeindex b/libstdc++-v3/include/std/typeindex index a92c2969b972..fa07ac620e6e 100644 --- a/libstdc++-v3/include/std/typeindex +++ b/libstdc++-v3/include/std/typeindex @@ -76,7 +76,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return !_M_target->before(*__rhs._M_target); } size_t - hash_code() const + hash_code() const noexcept { return _M_target->hash_code(); } const char* @@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef type_index argument_type; size_t - operator()(const type_index& __ti) const + operator()(const type_index& __ti) const noexcept { return __ti.hash_code(); } }; diff --git a/libstdc++-v3/libsupc++/typeinfo b/libstdc++-v3/libsupc++/typeinfo index 69311d69e9a8..22ef49fa7b21 100644 --- a/libstdc++-v3/libsupc++/typeinfo +++ b/libstdc++-v3/libsupc++/typeinfo @@ -140,7 +140,7 @@ namespace std { return !operator==(__arg); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ - size_t hash_code() const throw() + size_t hash_code() const noexcept { # if !__GXX_MERGED_TYPEINFO_NAMES return _Hash_bytes(name(), __builtin_strlen(name()), diff --git a/libstdc++-v3/src/compatibility-ldbl.cc b/libstdc++-v3/src/compatibility-ldbl.cc index a9bdb8b09864..a103856adfa0 100644 --- a/libstdc++-v3/src/compatibility-ldbl.cc +++ b/libstdc++-v3/src/compatibility-ldbl.cc @@ -1,6 +1,6 @@ // Compatibility symbols for -mlong-double-64 compatibility -*- C++ -*- -// Copyright (C) 2006, 2008, 2009, 2010 +// Copyright (C) 2006, 2008, 2009, 2010, 2011 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -69,14 +69,7 @@ namespace std _GLIBCXX_VISIBILITY(default) // For std::tr1::hash::operator() #define _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL - -namespace std _GLIBCXX_VISIBILITY(default) -{ - namespace tr1 - { -#include "hash-long-double-aux.cc" - } -} +#include "hash-long-double-tr1-aux.cc" // std::tr1::hash::operator() // and std::hash::operator() diff --git a/libstdc++-v3/src/hash-long-double-aux.cc b/libstdc++-v3/src/hash-long-double-aux.cc deleted file mode 100644 index d54d635f83e6..000000000000 --- a/libstdc++-v3/src/hash-long-double-aux.cc +++ /dev/null @@ -1,50 +0,0 @@ -// std::hash and std::tr1::hash definitions, long double bits -*- C++ -*- - -// Copyright (C) 2010 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 -// terms of the GNU General Public License as published by the -// Free Software Foundation; either version 3, or (at your option) -// any later version. - -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// Under Section 7 of GPL version 3, you are granted additional -// permissions described in the GCC Runtime Library Exception, version -// 3.1, as published by the Free Software Foundation. - -// You should have received a copy of the GNU General Public License and -// a copy of the GCC Runtime Library Exception along with this program; -// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -// . - - // For long double, careful with random padding bits (e.g., on x86, - // 10 bytes -> 12 bytes) and resort to frexp. - template<> - size_t - hash::operator()(long double __val) const - { - // 0 and -0 both hash to zero. - if (__val == 0.0L) - return 0; - - int __exponent; - __val = __builtin_frexpl(__val, &__exponent); - __val = __val < 0.0l ? -(__val + 0.5l) : __val; - - const long double __mult = __SIZE_MAX__ + 1.0l; - __val *= __mult; - - // Try to use all the bits of the mantissa (really necessary only - // on 32-bit targets, at least for 80-bit floating point formats). - const size_t __hibits = (size_t)__val; - __val = (__val - (long double)__hibits) * __mult; - - const size_t __coeff = __SIZE_MAX__ / __LDBL_MAX_EXP__; - - return __hibits + (size_t)__val + __coeff * __exponent; - } diff --git a/libstdc++-v3/src/hash-long-double-tr1-aux.cc b/libstdc++-v3/src/hash-long-double-tr1-aux.cc new file mode 100644 index 000000000000..70ed45bbfbe8 --- /dev/null +++ b/libstdc++-v3/src/hash-long-double-tr1-aux.cc @@ -0,0 +1,56 @@ +// std::tr1::hash definitions, long double bits -*- C++ -*- + +// Copyright (C) 2010, 2011 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 +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +namespace std _GLIBCXX_VISIBILITY(default) +{ + namespace tr1 + { + // For long double, careful with random padding bits (e.g., on x86, + // 10 bytes -> 12 bytes) and resort to frexp. + template<> + size_t + hash::operator()(long double __val) const + { + // 0 and -0 both hash to zero. + if (__val == 0.0L) + return 0; + + int __exponent; + __val = __builtin_frexpl(__val, &__exponent); + __val = __val < 0.0l ? -(__val + 0.5l) : __val; + + const long double __mult = __SIZE_MAX__ + 1.0l; + __val *= __mult; + + // Try to use all the bits of the mantissa (really necessary only + // on 32-bit targets, at least for 80-bit floating point formats). + const size_t __hibits = (size_t)__val; + __val = (__val - (long double)__hibits) * __mult; + + const size_t __coeff = __SIZE_MAX__ / __LDBL_MAX_EXP__; + + return __hibits + (size_t)__val + __coeff * __exponent; + } + } +} diff --git a/libstdc++-v3/src/hash_c++0x.cc b/libstdc++-v3/src/hash_c++0x.cc index 852498df602b..d685074540b0 100644 --- a/libstdc++-v3/src/hash_c++0x.cc +++ b/libstdc++-v3/src/hash_c++0x.cc @@ -1,6 +1,6 @@ // std::hash definitions -*- C++ -*- -// Copyright (C) 2010 Free Software Foundation, Inc. +// Copyright (C) 2010, 2011 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 @@ -30,5 +30,27 @@ namespace std _GLIBCXX_VISIBILITY(default) { -#include "hash-long-double-aux.cc" + _GLIBCXX_PURE size_t + hash::operator()(long double __val) const noexcept + { + // 0 and -0 both hash to zero. + if (__val == 0.0L) + return 0; + + int __exponent; + __val = __builtin_frexpl(__val, &__exponent); + __val = __val < 0.0l ? -(__val + 0.5l) : __val; + + const long double __mult = __SIZE_MAX__ + 1.0l; + __val *= __mult; + + // Try to use all the bits of the mantissa (really necessary only + // on 32-bit targets, at least for 80-bit floating point formats). + const size_t __hibits = (size_t)__val; + __val = (__val - (long double)__hibits) * __mult; + + const size_t __coeff = __SIZE_MAX__ / __LDBL_MAX_EXP__; + + return __hibits + (size_t)__val + __coeff * __exponent; + } } diff --git a/libstdc++-v3/src/hash_tr1.cc b/libstdc++-v3/src/hash_tr1.cc index e707e827a116..a5ac87e585b9 100644 --- a/libstdc++-v3/src/hash_tr1.cc +++ b/libstdc++-v3/src/hash_tr1.cc @@ -1,6 +1,6 @@ // std::tr1::hash definitions -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008, 2009, 2010, 2011 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 @@ -25,12 +25,12 @@ #include #include +#include "hash-long-double-tr1-aux.cc" + namespace std _GLIBCXX_VISIBILITY(default) { namespace tr1 { -#include "hash-long-double-aux.cc" - #ifndef _GLIBCXX_LONG_DOUBLE_COMPAT_IMPL template<> size_t