diff options
author | Martin Jambor <mjambor@suse.cz> | 2016-10-19 12:48:56 +0000 |
---|---|---|
committer | Martin Jambor <mjambor@suse.cz> | 2016-10-19 12:48:56 +0000 |
commit | 52841aef869b297cfe6e544948376597f0e14027 (patch) | |
tree | c209e0790d5046aecd4e7fdcd29e0eed83dace9d /libstdc++-v3/include/ext | |
parent | 52f96141605ebcd9d8498fa33e53d70bc7257c4b (diff) |
Merged trunk revision 241230 into the hsa branch
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/hsa@241341 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/ext')
-rw-r--r-- | libstdc++-v3/include/ext/bitmap_allocator.h | 18 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/malloc_allocator.h | 25 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/mt_allocator.h | 18 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/new_allocator.h | 18 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/pool_allocator.h | 18 |
5 files changed, 94 insertions, 3 deletions
diff --git a/libstdc++-v3/include/ext/bitmap_allocator.h b/libstdc++-v3/include/ext/bitmap_allocator.h index c7fbd3e20c7..836abc8c530 100644 --- a/libstdc++-v3/include/ext/bitmap_allocator.h +++ b/libstdc++-v3/include/ext/bitmap_allocator.h @@ -1018,6 +1018,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__n > this->max_size()) std::__throw_bad_alloc(); +#if __cpp_aligned_new + if (alignof(value_type) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + const size_type __b = __n * sizeof(value_type); + std::align_val_t __al = std::align_val_t(alignof(value_type)); + return static_cast<pointer>(::operator new(__b, __al)); + } +#endif + if (__builtin_expect(__n == 1, true)) return this->_M_allocate_single_object(); else @@ -1036,6 +1045,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (__builtin_expect(__p != 0, true)) { +#if __cpp_aligned_new + // Types with extended alignment are handled by operator delete. + if (alignof(value_type) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + ::operator delete(__p, std::align_val_t(alignof(value_type))); + return; + } +#endif + if (__builtin_expect(__n == 1, true)) this->_M_deallocate_single_object(__p); else diff --git a/libstdc++-v3/include/ext/malloc_allocator.h b/libstdc++-v3/include/ext/malloc_allocator.h index 5c32eab70c3..113c1dcfe6c 100644 --- a/libstdc++-v3/include/ext/malloc_allocator.h +++ b/libstdc++-v3/include/ext/malloc_allocator.h @@ -30,6 +30,7 @@ #define _MALLOC_ALLOCATOR_H 1 #include <cstdlib> +#include <cstddef> #include <new> #include <bits/functexcept.h> #include <bits/move.h> @@ -100,9 +101,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__n > this->max_size()) std::__throw_bad_alloc(); - pointer __ret = static_cast<_Tp*>(std::malloc(__n * sizeof(_Tp))); + pointer __ret = 0; +#if __cpp_aligned_new +#if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC + if (alignof(_Tp) > alignof(std::max_align_t)) + { + __ret = static_cast<_Tp*>(::aligned_alloc(alignof(_Tp), + __n * sizeof(_Tp))); + } +#else +# define _GLIBCXX_CHECK_MALLOC_RESULT +#endif +#endif + if (!__ret) + __ret = static_cast<_Tp*>(std::malloc(__n * sizeof(_Tp))); if (!__ret) std::__throw_bad_alloc(); +#ifdef _GLIBCXX_CHECK_MALLOC_RESULT +#undef _GLIBCXX_CHECK_MALLOC_RESULT + if (reinterpret_cast<std::size_t>(__ret) % alignof(_Tp)) + { + // Memory returned by malloc is not suitably aligned for _Tp. + deallocate(__ret, __n); + std::__throw_bad_alloc(); + } +#endif return __ret; } diff --git a/libstdc++-v3/include/ext/mt_allocator.h b/libstdc++-v3/include/ext/mt_allocator.h index 7016e489d41..d7ea7c1a8c3 100644 --- a/libstdc++-v3/include/ext/mt_allocator.h +++ b/libstdc++-v3/include/ext/mt_allocator.h @@ -691,6 +691,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__n > this->max_size()) std::__throw_bad_alloc(); +#if __cpp_aligned_new + // Types with extended alignment are handled by operator new/delete. + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + std::align_val_t __al = std::align_val_t(alignof(_Tp)); + return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al)); + } +#endif + __policy_type::_S_initialize_once(); // Requests larger than _M_max_bytes are handled by operator @@ -737,6 +746,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (__builtin_expect(__p != 0, true)) { +#if __cpp_aligned_new + // Types with extended alignment are handled by operator new/delete. + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + ::operator delete(__p, std::align_val_t(alignof(_Tp))); + return; + } +#endif + // Requests larger than _M_max_bytes are handled by // operators new/delete directly. __pool_type& __pool = __policy_type::_S_get_pool(); diff --git a/libstdc++-v3/include/ext/new_allocator.h b/libstdc++-v3/include/ext/new_allocator.h index dd00b7384aa..2ff4780f0e0 100644 --- a/libstdc++-v3/include/ext/new_allocator.h +++ b/libstdc++-v3/include/ext/new_allocator.h @@ -101,13 +101,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__n > this->max_size()) std::__throw_bad_alloc(); +#if __cpp_aligned_new + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + std::align_val_t __al = std::align_val_t(alignof(_Tp)); + return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al)); + } +#endif return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); } // __p is not permitted to be a null pointer. void deallocate(pointer __p, size_type) - { ::operator delete(__p); } + { +#if __cpp_aligned_new + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + ::operator delete(__p, std::align_val_t(alignof(_Tp))); + return; + } +#endif + ::operator delete(__p); + } size_type max_size() const _GLIBCXX_USE_NOEXCEPT diff --git a/libstdc++-v3/include/ext/pool_allocator.h b/libstdc++-v3/include/ext/pool_allocator.h index ee60e90166e..9e0511de19a 100644 --- a/libstdc++-v3/include/ext/pool_allocator.h +++ b/libstdc++-v3/include/ext/pool_allocator.h @@ -219,6 +219,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__n > this->max_size()) std::__throw_bad_alloc(); + const size_t __bytes = __n * sizeof(_Tp); + +#if __cpp_aligned_new + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + std::align_val_t __al = std::align_val_t(alignof(_Tp)); + return static_cast<_Tp*>(::operator new(__bytes, __al)); + } +#endif + // If there is a race through here, assume answer from getenv // will resolve in same direction. Inspired by techniques // to efficiently support threading found in basic_string.h. @@ -230,7 +240,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __atomic_add_dispatch(&_S_force_new, -1); } - const size_t __bytes = __n * sizeof(_Tp); if (__bytes > size_t(_S_max_bytes) || _S_force_new > 0) __ret = static_cast<_Tp*>(::operator new(__bytes)); else @@ -259,6 +268,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (__builtin_expect(__n != 0 && __p != 0, true)) { +#if __cpp_aligned_new + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + ::operator delete(__p, std::align_val_t(alignof(_Tp))); + return; + } +#endif const size_t __bytes = __n * sizeof(_Tp); if (__bytes > static_cast<size_t>(_S_max_bytes) || _S_force_new > 0) ::operator delete(__p); |