Georgios Pinitas | 82833b8 | 2018-01-30 12:14:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_WRAPPER_TRAITS_H__ |
| 25 | #define __ARM_COMPUTE_WRAPPER_TRAITS_H__ |
| 26 | |
| 27 | #include <arm_neon.h> |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace wrapper |
| 32 | { |
| 33 | namespace traits |
| 34 | { |
| 35 | // *INDENT-OFF* |
| 36 | // clang-format off |
| 37 | |
Georgios Pinitas | 57c033b | 2018-02-15 12:29:44 +0000 | [diff] [blame] | 38 | /** 64-bit vector tag */ |
| 39 | struct vector_64_tag {}; |
| 40 | /** 128-bit vector tag */ |
| 41 | struct vector_128_tag {}; |
| 42 | |
Georgios Pinitas | 52ebf42 | 2018-12-17 18:21:02 +0000 | [diff] [blame] | 43 | /** Create the appropriate NEON vector given its type and size in terms of elements */ |
Georgios Pinitas | 82833b8 | 2018-01-30 12:14:24 +0000 | [diff] [blame] | 44 | template <typename T, int S> struct neon_vector; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 45 | // Specializations |
| 46 | #ifndef DOXYGEN_SKIP_THIS |
Georgios Pinitas | 57c033b | 2018-02-15 12:29:44 +0000 | [diff] [blame] | 47 | template <> struct neon_vector<uint8_t, 8>{ using type = uint8x8_t; using tag_type = vector_64_tag; }; |
| 48 | template <> struct neon_vector<int8_t, 8>{ using type = int8x8_t; using tag_type = vector_64_tag; }; |
| 49 | template <> struct neon_vector<uint8_t, 16>{ using type = uint8x16_t; using tag_type = vector_128_tag; }; |
| 50 | template <> struct neon_vector<int8_t, 16>{ using type = int8x16_t; using tag_type = vector_128_tag; }; |
| 51 | template <> struct neon_vector<uint16_t, 4>{ using type = uint16x4_t; using tag_type = vector_64_tag; }; |
| 52 | template <> struct neon_vector<int16_t, 4>{ using type = int16x4_t; using tag_type = vector_64_tag; }; |
| 53 | template <> struct neon_vector<uint16_t, 8>{ using type = uint16x8_t; using tag_type = vector_128_tag; }; |
| 54 | template <> struct neon_vector<int16_t, 8>{ using type = int16x8_t; using tag_type = vector_128_tag; }; |
| 55 | template <> struct neon_vector<uint32_t, 2>{ using type = uint32x2_t; using tag_type = vector_64_tag; }; |
| 56 | template <> struct neon_vector<int32_t, 2>{ using type = int32x2_t; using tag_type = vector_64_tag; }; |
| 57 | template <> struct neon_vector<uint32_t, 4>{ using type = uint32x4_t; using tag_type = vector_128_tag; }; |
| 58 | template <> struct neon_vector<int32_t, 4>{ using type = int32x4_t; using tag_type = vector_128_tag; }; |
| 59 | template <> struct neon_vector<uint64_t, 1>{ using type = uint64x1_t; using tag_type = vector_64_tag; }; |
| 60 | template <> struct neon_vector<int64_t, 1>{ using type = int64x1_t; using tag_type = vector_64_tag; }; |
| 61 | template <> struct neon_vector<uint64_t, 2>{ using type = uint64x2_t; using tag_type = vector_128_tag; }; |
| 62 | template <> struct neon_vector<int64_t, 2>{ using type = int64x2_t; using tag_type = vector_128_tag; }; |
| 63 | template <> struct neon_vector<float_t, 2>{ using type = float32x2_t; using tag_type = vector_64_tag; }; |
| 64 | template <> struct neon_vector<float_t, 4>{ using type = float32x4_t; using tag_type = vector_128_tag; }; |
Georgios Pinitas | aaba4c6 | 2018-08-22 16:20:21 +0100 | [diff] [blame] | 65 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 66 | template <> struct neon_vector<float16_t, 4>{ using type = float16x4_t; using tag_type = vector_64_tag; }; |
| 67 | template <> struct neon_vector<float16_t, 8>{ using type = float16x8_t; using tag_type = vector_128_tag; }; |
| 68 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 69 | #endif /* DOXYGEN_SKIP_THIS */ |
Georgios Pinitas | 57c033b | 2018-02-15 12:29:44 +0000 | [diff] [blame] | 70 | |
| 71 | /** Helper type template to get the type of a neon vector */ |
Georgios Pinitas | 82833b8 | 2018-01-30 12:14:24 +0000 | [diff] [blame] | 72 | template <typename T, int S> using neon_vector_t = typename neon_vector<T, S>::type; |
Georgios Pinitas | 57c033b | 2018-02-15 12:29:44 +0000 | [diff] [blame] | 73 | /** Helper type template to get the tag type of a neon vector */ |
| 74 | template <typename T, int S> using neon_vector_tag_t = typename neon_vector<T, S>::tag_type; |
Georgios Pinitas | 52ebf42 | 2018-12-17 18:21:02 +0000 | [diff] [blame] | 75 | |
| 76 | /** Vector bit-width enum class */ |
| 77 | enum class BitWidth |
| 78 | { |
| 79 | W64, /**< 64-bit width */ |
| 80 | W128, /**< 128-bit width */ |
| 81 | }; |
| 82 | |
| 83 | /** Create the appropriate NEON vector given its type and size in terms of bits */ |
| 84 | template <typename T, BitWidth BW> struct neon_bitvector; |
| 85 | // Specializations |
| 86 | #ifndef DOXYGEN_SKIP_THIS |
| 87 | template <> struct neon_bitvector<uint8_t, BitWidth::W64>{ using type = uint8x8_t; using tag_type = vector_64_tag; }; |
| 88 | template <> struct neon_bitvector<int8_t, BitWidth::W64>{ using type = int8x8_t; using tag_type = vector_64_tag; }; |
| 89 | template <> struct neon_bitvector<uint8_t, BitWidth::W128>{ using type = uint8x16_t; using tag_type = vector_128_tag; }; |
| 90 | template <> struct neon_bitvector<int8_t, BitWidth::W128>{ using type = int8x16_t; using tag_type = vector_128_tag; }; |
| 91 | template <> struct neon_bitvector<uint16_t, BitWidth::W64>{ using type = uint16x4_t; using tag_type = vector_64_tag; }; |
| 92 | template <> struct neon_bitvector<int16_t, BitWidth::W64>{ using type = int16x4_t; using tag_type = vector_64_tag; }; |
| 93 | template <> struct neon_bitvector<uint16_t, BitWidth::W128>{ using type = uint16x8_t; using tag_type = vector_128_tag; }; |
| 94 | template <> struct neon_bitvector<int16_t, BitWidth::W128>{ using type = int16x8_t; using tag_type = vector_128_tag; }; |
| 95 | template <> struct neon_bitvector<uint32_t, BitWidth::W64>{ using type = uint32x2_t; using tag_type = vector_64_tag; }; |
| 96 | template <> struct neon_bitvector<int32_t, BitWidth::W64>{ using type = int32x2_t; using tag_type = vector_64_tag; }; |
| 97 | template <> struct neon_bitvector<uint32_t, BitWidth::W128>{ using type = uint32x4_t; using tag_type = vector_128_tag; }; |
| 98 | template <> struct neon_bitvector<int32_t, BitWidth::W128>{ using type = int32x4_t; using tag_type = vector_128_tag; }; |
| 99 | template <> struct neon_bitvector<uint64_t, BitWidth::W64>{ using type = uint64x1_t; using tag_type = vector_64_tag; }; |
| 100 | template <> struct neon_bitvector<int64_t, BitWidth::W64>{ using type = int64x1_t; using tag_type = vector_64_tag; }; |
| 101 | template <> struct neon_bitvector<uint64_t, BitWidth::W128>{ using type = uint64x2_t; using tag_type = vector_128_tag; }; |
| 102 | template <> struct neon_bitvector<int64_t, BitWidth::W128>{ using type = int64x2_t; using tag_type = vector_128_tag; }; |
| 103 | template <> struct neon_bitvector<float_t, BitWidth::W64>{ using type = float32x2_t; using tag_type = vector_64_tag; }; |
| 104 | template <> struct neon_bitvector<float_t, BitWidth::W128>{ using type = float32x4_t; using tag_type = vector_128_tag; }; |
| 105 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 106 | template <> struct neon_bitvector<float16_t, BitWidth::W64>{ using type = float16x4_t; using tag_type = vector_64_tag; }; |
| 107 | template <> struct neon_bitvector<float16_t, BitWidth::W128>{ using type = float16x8_t; using tag_type = vector_128_tag; }; |
| 108 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 109 | #endif /* DOXYGEN_SKIP_THIS */ |
| 110 | |
| 111 | /** Helper type template to get the type of a neon vector */ |
| 112 | template <typename T, BitWidth BW> using neon_bitvector_t = typename neon_bitvector<T, BW>::type; |
| 113 | /** Helper type template to get the tag type of a neon vector */ |
| 114 | template <typename T, BitWidth BW> using neon_bitvector_tag_t = typename neon_bitvector<T, BW>::tag_type; |
Georgios Pinitas | 82833b8 | 2018-01-30 12:14:24 +0000 | [diff] [blame] | 115 | // clang-format on |
| 116 | // *INDENT-ON* |
Georgios Pinitas | 57c033b | 2018-02-15 12:29:44 +0000 | [diff] [blame] | 117 | } // namespace traits |
| 118 | } // namespace wrapper |
| 119 | } // namespace arm_compute |
Georgios Pinitas | 82833b8 | 2018-01-30 12:14:24 +0000 | [diff] [blame] | 120 | #endif /* __ARM_COMPUTE_WRAPPER_TRAITS_H__ */ |