blob: eafbeef3727ad03c48bc4e5654d3398b08feae58 [file] [log] [blame]
Georgios Pinitas82833b82018-01-30 12:14:24 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitas82833b82018-01-30 12:14:24 +00003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_WRAPPER_TRAITS_H
25#define ARM_COMPUTE_WRAPPER_TRAITS_H
Georgios Pinitas82833b82018-01-30 12:14:24 +000026
27#include <arm_neon.h>
28
29namespace arm_compute
30{
31namespace wrapper
32{
33namespace traits
34{
35// *INDENT-OFF*
36// clang-format off
37
Georgios Pinitas57c033b2018-02-15 12:29:44 +000038/** 64-bit vector tag */
39struct vector_64_tag {};
40/** 128-bit vector tag */
41struct vector_128_tag {};
42
Georgios Pinitas52ebf422018-12-17 18:21:02 +000043/** Create the appropriate NEON vector given its type and size in terms of elements */
Georgios Pinitas82833b82018-01-30 12:14:24 +000044template <typename T, int S> struct neon_vector;
Manuel Bottinib4bb8272019-12-18 18:01:27 +000045
Alex Gildayc357c472018-03-21 13:54:09 +000046// Specializations
47#ifndef DOXYGEN_SKIP_THIS
giuros01d5134362019-05-14 16:12:53 +010048template <> struct neon_vector<uint8_t, 8>{ using scalar_type = uint8_t; using type = uint8x8_t; using tag_type = vector_64_tag; };
49template <> struct neon_vector<int8_t, 8>{ using scalar_type = int8_t; using type = int8x8_t; using tag_type = vector_64_tag; };
50template <> struct neon_vector<uint8_t, 16>{ using scalar_type = uint8_t; using type = uint8x16_t; using tag_type = vector_128_tag; };
51template <> struct neon_vector<int8_t, 16>{ using scalar_type = int8_t; using type = int8x16_t; using tag_type = vector_128_tag; };
52template <> struct neon_vector<uint16_t, 4>{ using scalar_type = uint16_t; using type = uint16x4_t; using tag_type = vector_64_tag; };
53template <> struct neon_vector<int16_t, 4>{ using scalar_type = int16_t; using type = int16x4_t; using tag_type = vector_64_tag; };
54template <> struct neon_vector<uint16_t, 8>{ using scalar_type = uint16_t; using type = uint16x8_t; using tag_type = vector_128_tag; };
Manuel Bottinib4bb8272019-12-18 18:01:27 +000055template <> struct neon_vector<uint16_t, 16>{ using scalar_type = uint16_t; using type = uint16x8x2_t; };
giuros01d5134362019-05-14 16:12:53 +010056template <> struct neon_vector<int16_t, 8>{ using scalar_type = int16_t; using type = int16x8_t; using tag_type = vector_128_tag; };
Manuel Bottinib4bb8272019-12-18 18:01:27 +000057template <> struct neon_vector<int16_t, 16>{ using scalar_type = int16_t; using type = int16x8x2_t; };
giuros01d5134362019-05-14 16:12:53 +010058template <> struct neon_vector<uint32_t, 2>{ using scalar_type = uint32_t; using type = uint32x2_t; using tag_type = vector_64_tag; };
59template <> struct neon_vector<int32_t, 2>{ using scalar_type = int32_t; using type = int32x2_t; using tag_type = vector_64_tag; };
60template <> struct neon_vector<uint32_t, 4>{ using scalar_type = uint32_t; using type = uint32x4_t; using tag_type = vector_128_tag; };
61template <> struct neon_vector<int32_t, 4>{ using scalar_type = int32_t; using type = int32x4_t; using tag_type = vector_128_tag; };
62template <> struct neon_vector<uint64_t, 1>{ using scalar_type = uint64_t;using type = uint64x1_t; using tag_type = vector_64_tag; };
63template <> struct neon_vector<int64_t, 1>{ using scalar_type = int64_t; using type = int64x1_t; using tag_type = vector_64_tag; };
64template <> struct neon_vector<uint64_t, 2>{ using scalar_type = uint64_t; using type = uint64x2_t; using tag_type = vector_128_tag; };
65template <> struct neon_vector<int64_t, 2>{ using scalar_type = int64_t; using type = int64x2_t; using tag_type = vector_128_tag; };
66template <> struct neon_vector<float_t, 2>{ using scalar_type = float_t; using type = float32x2_t; using tag_type = vector_64_tag; };
67template <> struct neon_vector<float_t, 4>{ using scalar_type = float_t; using type = float32x4_t; using tag_type = vector_128_tag; };
Manuel Bottinib4bb8272019-12-18 18:01:27 +000068
Georgios Pinitasaaba4c62018-08-22 16:20:21 +010069#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
giuros01d5134362019-05-14 16:12:53 +010070template <> struct neon_vector<float16_t, 4>{ using scalar_type = float16_t; using type = float16x4_t; using tag_type = vector_64_tag; };
71template <> struct neon_vector<float16_t, 8>{ using scalar_type = float16_t; using type = float16x8_t; using tag_type = vector_128_tag; };
Georgios Pinitasaaba4c62018-08-22 16:20:21 +010072#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Alex Gildayc357c472018-03-21 13:54:09 +000073#endif /* DOXYGEN_SKIP_THIS */
Georgios Pinitas57c033b2018-02-15 12:29:44 +000074
75/** Helper type template to get the type of a neon vector */
Georgios Pinitas82833b82018-01-30 12:14:24 +000076template <typename T, int S> using neon_vector_t = typename neon_vector<T, S>::type;
Georgios Pinitas57c033b2018-02-15 12:29:44 +000077/** Helper type template to get the tag type of a neon vector */
78template <typename T, int S> using neon_vector_tag_t = typename neon_vector<T, S>::tag_type;
Georgios Pinitas52ebf422018-12-17 18:21:02 +000079
80/** Vector bit-width enum class */
81enum class BitWidth
82{
83 W64, /**< 64-bit width */
84 W128, /**< 128-bit width */
85};
86
87/** Create the appropriate NEON vector given its type and size in terms of bits */
88template <typename T, BitWidth BW> struct neon_bitvector;
89// Specializations
90#ifndef DOXYGEN_SKIP_THIS
91template <> struct neon_bitvector<uint8_t, BitWidth::W64>{ using type = uint8x8_t; using tag_type = vector_64_tag; };
92template <> struct neon_bitvector<int8_t, BitWidth::W64>{ using type = int8x8_t; using tag_type = vector_64_tag; };
93template <> struct neon_bitvector<uint8_t, BitWidth::W128>{ using type = uint8x16_t; using tag_type = vector_128_tag; };
94template <> struct neon_bitvector<int8_t, BitWidth::W128>{ using type = int8x16_t; using tag_type = vector_128_tag; };
95template <> struct neon_bitvector<uint16_t, BitWidth::W64>{ using type = uint16x4_t; using tag_type = vector_64_tag; };
96template <> struct neon_bitvector<int16_t, BitWidth::W64>{ using type = int16x4_t; using tag_type = vector_64_tag; };
97template <> struct neon_bitvector<uint16_t, BitWidth::W128>{ using type = uint16x8_t; using tag_type = vector_128_tag; };
98template <> struct neon_bitvector<int16_t, BitWidth::W128>{ using type = int16x8_t; using tag_type = vector_128_tag; };
99template <> struct neon_bitvector<uint32_t, BitWidth::W64>{ using type = uint32x2_t; using tag_type = vector_64_tag; };
100template <> struct neon_bitvector<int32_t, BitWidth::W64>{ using type = int32x2_t; using tag_type = vector_64_tag; };
101template <> struct neon_bitvector<uint32_t, BitWidth::W128>{ using type = uint32x4_t; using tag_type = vector_128_tag; };
102template <> struct neon_bitvector<int32_t, BitWidth::W128>{ using type = int32x4_t; using tag_type = vector_128_tag; };
103template <> struct neon_bitvector<uint64_t, BitWidth::W64>{ using type = uint64x1_t; using tag_type = vector_64_tag; };
104template <> struct neon_bitvector<int64_t, BitWidth::W64>{ using type = int64x1_t; using tag_type = vector_64_tag; };
105template <> struct neon_bitvector<uint64_t, BitWidth::W128>{ using type = uint64x2_t; using tag_type = vector_128_tag; };
106template <> struct neon_bitvector<int64_t, BitWidth::W128>{ using type = int64x2_t; using tag_type = vector_128_tag; };
107template <> struct neon_bitvector<float_t, BitWidth::W64>{ using type = float32x2_t; using tag_type = vector_64_tag; };
108template <> struct neon_bitvector<float_t, BitWidth::W128>{ using type = float32x4_t; using tag_type = vector_128_tag; };
109#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
110template <> struct neon_bitvector<float16_t, BitWidth::W64>{ using type = float16x4_t; using tag_type = vector_64_tag; };
111template <> struct neon_bitvector<float16_t, BitWidth::W128>{ using type = float16x8_t; using tag_type = vector_128_tag; };
112#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
113#endif /* DOXYGEN_SKIP_THIS */
114
115/** Helper type template to get the type of a neon vector */
116template <typename T, BitWidth BW> using neon_bitvector_t = typename neon_bitvector<T, BW>::type;
117/** Helper type template to get the tag type of a neon vector */
118template <typename T, BitWidth BW> using neon_bitvector_tag_t = typename neon_bitvector<T, BW>::tag_type;
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +0100119
120/** Promote a type */
121template <typename T> struct promote { };
122template <> struct promote<uint8_t> { using type = uint16_t; };
123template <> struct promote<int8_t> { using type = int16_t; };
124template <> struct promote<uint16_t> { using type = uint32_t; };
125template <> struct promote<int16_t> { using type = int32_t; };
126template <> struct promote<uint32_t> { using type = uint64_t; };
127template <> struct promote<int32_t> { using type = int64_t; };
128template <> struct promote<float> { using type = float; };
129template <> struct promote<half> { using type = half; };
130
131/** Get promoted type */
132template <typename T>
133using promote_t = typename promote<T>::type;
134
Georgios Pinitas82833b82018-01-30 12:14:24 +0000135// clang-format on
136// *INDENT-ON*
Georgios Pinitas57c033b2018-02-15 12:29:44 +0000137} // namespace traits
138} // namespace wrapper
139} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000140#endif /* ARM_COMPUTE_WRAPPER_TRAITS_H */