Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:37:18

0001 /***************************************************************************
0002  * Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and         *
0003  * Martin Renou                                                             *
0004  * Copyright (c) QuantStack                                                 *
0005  * Copyright (c) Serge Guelton                                              *
0006  *                                                                          *
0007  * Distributed under the terms of the BSD 3-Clause License.                 *
0008  *                                                                          *
0009  * The full license is in the file LICENSE, distributed with this software. *
0010  ****************************************************************************/
0011 
0012 #ifndef XSIMD_TYPE_TRAITS_HPP
0013 #define XSIMD_TYPE_TRAITS_HPP
0014 
0015 #include <cstddef>
0016 #include <cstdint>
0017 #include <type_traits>
0018 
0019 namespace xsimd
0020 {
0021     namespace detail
0022     {
0023         template <std::size_t S>
0024         struct sized_num_types;
0025 
0026         template <>
0027         struct sized_num_types<1>
0028         {
0029             using signed_type = std::int8_t;
0030             using unsigned_type = std::uint8_t;
0031             using floating_point_type = void;
0032         };
0033 
0034         template <>
0035         struct sized_num_types<2>
0036         {
0037             using signed_type = std::int16_t;
0038             using unsigned_type = std::uint16_t;
0039             using floating_point_type = void;
0040         };
0041 
0042         template <>
0043         struct sized_num_types<4>
0044         {
0045             using signed_type = std::int32_t;
0046             using unsigned_type = std::uint32_t;
0047             using floating_point_type = float;
0048         };
0049 
0050         template <>
0051         struct sized_num_types<8>
0052         {
0053             using signed_type = std::int64_t;
0054             using unsigned_type = std::uint64_t;
0055             using floating_point_type = double;
0056         };
0057     }
0058 
0059     /**
0060      * @ingroup type_traits
0061      *
0062      * Signed integer type with exactly @c S bytes (1, 2, 4, or 8).
0063      *
0064      * @tparam S size in bytes.
0065      */
0066     template <std::size_t S>
0067     using sized_int_t = typename detail::sized_num_types<S>::signed_type;
0068 
0069     /**
0070      * @ingroup type_traits
0071      *
0072      * Unsigned integer type with exactly @c S bytes (1, 2, 4, or 8).
0073      *
0074      * @tparam S size in bytes.
0075      */
0076     template <std::size_t S>
0077     using sized_uint_t = typename detail::sized_num_types<S>::unsigned_type;
0078 
0079     /**
0080      * @ingroup type_traits
0081      *
0082      * Floating-point type with exactly @c S bytes (4 for @c float, 8 for @c double).
0083      * Yields @c void for sizes without a standard floating-point type (1, 2).
0084      *
0085      * @tparam S size in bytes.
0086      */
0087     template <std::size_t S>
0088     using sized_fp_t = typename detail::sized_num_types<S>::floating_point_type;
0089 
0090     namespace detail
0091     {
0092         template <typename T, std::size_t factor, typename = void>
0093         struct remap_num
0094         {
0095             using type = T;
0096         };
0097 
0098         template <typename T, std::size_t factor>
0099         struct remap_num<T, factor, std::enable_if_t<std::is_floating_point<T>::value>>
0100         {
0101             using type = xsimd::sized_fp_t<sizeof(T) * factor>;
0102         };
0103 
0104         template <typename T, std::size_t factor>
0105         struct remap_num<T, factor, std::enable_if_t<!std::is_floating_point<T>::value && std::is_signed<T>::value>>
0106         {
0107             using type = xsimd::sized_int_t<sizeof(T) * factor>;
0108         };
0109 
0110         template <typename T, std::size_t factor>
0111         struct remap_num<T, factor, std::enable_if_t<!std::is_floating_point<T>::value && std::is_unsigned<T>::value>>
0112         {
0113             using type = xsimd::sized_uint_t<sizeof(T) * factor>;
0114         };
0115     }
0116 
0117     /**
0118      * @ingroup type_traits
0119      *
0120      * Remap numeral types to their fixed sized variant (``[u]int{8,16,32}_t``
0121      * and pass through other types).
0122      * Certain platforms have different types (*i.e.* not aliases) between
0123      * ``char`` and ``int8_t``, or ``long long`` and ``int{32,64}_t``, with SIMD
0124      * intrinsicts only defined for some of them.
0125      * Handling them requires to cast to a known predictable type.
0126      *
0127      * @tparam T arithmetic type to project from.
0128      */
0129     template <typename T>
0130     using map_to_sized_type_t = typename detail::remap_num<T, /* factor= */ 1>::type;
0131 
0132     /**
0133      * @ingroup type_traits
0134      *
0135      * The next-wider arithmetic type for @c T: doubles the size while preserving
0136      * signedness for integers and yielding @c double for @c float.
0137      * Supported input types: @c [u]int{8,16,32}_t and @c float.
0138      *
0139      * @tparam T arithmetic type to widen.
0140      */
0141     template <typename T>
0142     using widen_t = typename detail::remap_num<T, /* factor= */ 2>::type;
0143 }
0144 
0145 #endif