diff options
author | Alon Zakai <azakai@mozilla.com> | 2011-01-17 15:36:26 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2011-01-17 15:36:26 -0800 |
commit | 1f3de5c76e4947afccca350da24859e52f6aa83f (patch) | |
tree | 1539bbf09d9a3b71e06db5444d4ea5ceb43f8013 /tests/libcxx/include | |
parent | 13a520ed493d40e405045df1829863edfdb2308e (diff) |
libcxx test; support for linking in test runner; failure in clang_0_1.test_libcxx
Diffstat (limited to 'tests/libcxx/include')
99 files changed, 97565 insertions, 0 deletions
diff --git a/tests/libcxx/include/__bit_reference b/tests/libcxx/include/__bit_reference new file mode 100644 index 00000000..bef27625 --- /dev/null +++ b/tests/libcxx/include/__bit_reference @@ -0,0 +1,1225 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___BIT_REFERENCE +#define _LIBCPP___BIT_REFERENCE + +#include <__config> +#include <algorithm> + +#pragma GCC system_header + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _C, bool _IsConst> class __bit_iterator; +template <class _C> class __bit_const_reference; + +template <class _C> +class __bit_reference +{ + typedef typename _C::__storage_type __storage_type; + typedef typename _C::__storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + +#if defined(__clang__) + friend typename _C::__self; +#else + friend class _C::__self; +#endif + friend class __bit_const_reference<_C>; + friend class __bit_iterator<_C, false>; +public: + _LIBCPP_INLINE_VISIBILITY operator bool() const {return static_cast<bool>(*__seg_ & __mask_);} + _LIBCPP_INLINE_VISIBILITY bool operator ~() const {return !static_cast<bool>(*this);} + + _LIBCPP_INLINE_VISIBILITY + __bit_reference& operator=(bool __x) + { + if (__x) + *__seg_ |= __mask_; + else + *__seg_ &= ~__mask_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __bit_reference& operator=(const __bit_reference& __x) {return operator=(static_cast<bool>(__x));} + + _LIBCPP_INLINE_VISIBILITY void flip() {*__seg_ ^= __mask_;} + _LIBCPP_INLINE_VISIBILITY __bit_iterator<_C, false> operator&() const + {return __bit_iterator<_C, false>(__seg_, static_cast<unsigned>(__ctz(__mask_)));} +private: + _LIBCPP_INLINE_VISIBILITY + __bit_reference(__storage_pointer __s, __storage_type __m) : __seg_(__s), __mask_(__m) {} +}; + +template <class _C, class _D> +_LIBCPP_INLINE_VISIBILITY inline +void +swap(__bit_reference<_C> __x, __bit_reference<_D> __y) +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template <class _C> +_LIBCPP_INLINE_VISIBILITY inline +void +swap(__bit_reference<_C> __x, bool& __y) +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template <class _C> +_LIBCPP_INLINE_VISIBILITY inline +void +swap(bool& __x, __bit_reference<_C> __y) +{ + bool __t = __x; + __x = __y; + __y = __t; +} + +template <class _C> +class __bit_const_reference +{ + typedef typename _C::__storage_type __storage_type; + typedef typename _C::__const_storage_pointer __storage_pointer; + + __storage_pointer __seg_; + __storage_type __mask_; + +#if defined(__clang__) + friend typename _C::__self; +#else + friend class _C::__self; +#endif + friend class __bit_iterator<_C, true>; +public: + _LIBCPP_INLINE_VISIBILITY + __bit_const_reference(const __bit_reference<_C>& __x) + : __seg_(__x.__seg_), __mask_(__x.__mask_) {} + + _LIBCPP_INLINE_VISIBILITY operator bool() const {return static_cast<bool>(*__seg_ & __mask_);} + + _LIBCPP_INLINE_VISIBILITY __bit_iterator<_C, true> operator&() const + {return __bit_iterator<_C, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));} +private: + _LIBCPP_INLINE_VISIBILITY + __bit_const_reference(__storage_pointer __s, __storage_type __m) : __seg_(__s), __mask_(__m) {} + + __bit_const_reference& operator=(const __bit_const_reference& __x); +}; + +// find + +template <class _C> +__bit_iterator<_C, false> +__find_bool_true(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _STD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_STD::__ctz(__b))); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + if (*__first.__seg_) + return _It(__first.__seg_, static_cast<unsigned>(_STD::__ctz(*__first.__seg_))); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = *__first.__seg_ & __m; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_STD::__ctz(__b))); + } + return _It(__first.__seg_, static_cast<unsigned>(__n)); +} + +template <class _C> +__bit_iterator<_C, false> +__find_bool_false(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _STD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __storage_type __b = ~(*__first.__seg_ & __m); + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_STD::__ctz(__b))); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + { + __storage_type __b = ~*__first.__seg_; + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_STD::__ctz(__b))); + } + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __storage_type __b = ~(*__first.__seg_ & __m); + if (__b) + return _It(__first.__seg_, static_cast<unsigned>(_STD::__ctz(__b))); + } + return _It(__first.__seg_, static_cast<unsigned>(__n)); +} + +template <class _C, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__bit_iterator<_C, false> +find(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value) +{ + if (static_cast<bool>(__value)) + return __find_bool_true(__first, static_cast<typename _C::size_type>(__last - __first)); + return __find_bool_false(__first, static_cast<typename _C::size_type>(__last - __first)); +} + +// count + +template <class _C> +typename __bit_iterator<_C, false>::difference_type +__count_bool_true(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _STD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _STD::__pop_count(*__first.__seg_ & __m); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _STD::__pop_count(*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _STD::__pop_count(*__first.__seg_ & __m); + } + return __r; +} + +template <class _C> +typename __bit_iterator<_C, false>::difference_type +__count_bool_false(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage_type; + typedef typename _It::difference_type difference_type; + static const unsigned __bits_per_word = _It::__bits_per_word; + difference_type __r = 0; + // do first partial word + if (__first.__ctz_ != 0) + { + __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); + __storage_type __dn = _STD::min(__clz_f, __n); + __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); + __r = _STD::__pop_count(~(*__first.__seg_ & __m)); + __n -= __dn; + ++__first.__seg_; + } + // do middle whole words + for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) + __r += _STD::__pop_count(~*__first.__seg_); + // do last partial word + if (__n > 0) + { + __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); + __r += _STD::__pop_count(~(*__first.__seg_ & __m)); + } + return __r; +} + +template <class _C, class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +typename __bit_iterator<_C, false>::difference_type +count(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value) +{ + if (static_cast<bool>(__value)) + return __count_bool_true(__first, static_cast<typename _C::size_type>(__last - __first)); + return __count_bool_false(__first, static_cast<typename _C::size_type>(__last - __first)); +} + +// fill_n + +template <class _C> +void +__fill_n_false(__bit_iterator<_C, false> __first, typename _C::size_type __n) +{ + typedef __bit_iterator<_C, false> _It; + typedef typename _It::__storage_type __storage |