![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/include/boost/atomic/detail/ |
Upload File : |
/* * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * Copyright (c) 2018 Andrey Semashev */ /*! * \file atomic/detail/integral_extend.hpp * * This header defines sign/zero extension utilities for Boost.Atomic. The tools assume two's complement signed integer representation. */ #ifndef BOOST_ATOMIC_DETAIL_INTEGRAL_EXTEND_HPP_INCLUDED_ #define BOOST_ATOMIC_DETAIL_INTEGRAL_EXTEND_HPP_INCLUDED_ #include <boost/atomic/detail/config.hpp> #include <boost/atomic/detail/bitwise_cast.hpp> #include <boost/atomic/detail/type_traits/integral_constant.hpp> #include <boost/atomic/detail/type_traits/is_signed.hpp> #include <boost/atomic/detail/type_traits/make_signed.hpp> #include <boost/atomic/detail/type_traits/make_unsigned.hpp> #ifdef BOOST_HAS_PRAGMA_ONCE #pragma once #endif namespace boost { namespace atomics { namespace detail { template< typename Output, typename Input > BOOST_FORCEINLINE Output zero_extend_impl(Input input, atomics::detail::true_type) BOOST_NOEXCEPT { // Note: If we are casting with truncation or to the same-sized output, don't cause signed integer overflow by this chain of conversions return atomics::detail::bitwise_cast< Output >(static_cast< typename atomics::detail::make_unsigned< Output >::type >( static_cast< typename atomics::detail::make_unsigned< Input >::type >(input))); } template< typename Output, typename Input > BOOST_FORCEINLINE Output zero_extend_impl(Input input, atomics::detail::false_type) BOOST_NOEXCEPT { return static_cast< Output >(static_cast< typename atomics::detail::make_unsigned< Input >::type >(input)); } //! Zero-extends or truncates (wraps) input operand to fit in the output type template< typename Output, typename Input > BOOST_FORCEINLINE Output zero_extend(Input input) BOOST_NOEXCEPT { return atomics::detail::zero_extend_impl< Output >(input, atomics::detail::integral_constant< bool, atomics::detail::is_signed< Output >::value >()); } //! Truncates (wraps) input operand to fit in the output type template< typename Output, typename Input > BOOST_FORCEINLINE Output integral_truncate(Input input) BOOST_NOEXCEPT { // zero_extend does the truncation return atomics::detail::zero_extend< Output >(input); } template< typename Output, typename Input > BOOST_FORCEINLINE Output sign_extend_impl(Input input, atomics::detail::true_type) BOOST_NOEXCEPT { return atomics::detail::integral_truncate< Output >(input); } template< typename Output, typename Input > BOOST_FORCEINLINE Output sign_extend_impl(Input input, atomics::detail::false_type) BOOST_NOEXCEPT { return static_cast< Output >(atomics::detail::bitwise_cast< typename atomics::detail::make_signed< Input >::type >(input)); } //! Sign-extends or truncates (wraps) input operand to fit in the output type template< typename Output, typename Input > BOOST_FORCEINLINE Output sign_extend(Input input) BOOST_NOEXCEPT { return atomics::detail::sign_extend_impl< Output >(input, atomics::detail::integral_constant< bool, sizeof(Output) <= sizeof(Input) >()); } //! Sign-extends or truncates (wraps) input operand to fit in the output type template< typename Output, typename Input > BOOST_FORCEINLINE Output integral_extend(Input input, atomics::detail::true_type) BOOST_NOEXCEPT { return atomics::detail::sign_extend< Output >(input); } //! Zero-extends or truncates (wraps) input operand to fit in the output type template< typename Output, typename Input > BOOST_FORCEINLINE Output integral_extend(Input input, atomics::detail::false_type) BOOST_NOEXCEPT { return atomics::detail::zero_extend< Output >(input); } //! Sign- or zero-extends or truncates (wraps) input operand to fit in the output type template< bool Signed, typename Output, typename Input > BOOST_FORCEINLINE Output integral_extend(Input input) BOOST_NOEXCEPT { return atomics::detail::integral_extend< Output >(input, atomics::detail::integral_constant< bool, Signed >()); } } // namespace detail } // namespace atomics } // namespace boost #endif // BOOST_ATOMIC_DETAIL_INTEGRAL_EXTEND_HPP_INCLUDED_