Viet-Hoa Do | 40b4419 | 2022-09-22 10:24:23 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2022 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 | |
| 25 | #ifndef ARM_COMPUTE_WRAPPER_SHR_H |
| 26 | #define ARM_COMPUTE_WRAPPER_SHR_H |
| 27 | |
| 28 | #include <type_traits> |
| 29 | #include <arm_neon.h> |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace wrapper |
| 34 | { |
| 35 | |
| 36 | #define VQRSHRN_IMPL(half_vtype, vtype, prefix, postfix) \ |
| 37 | template <int b> \ |
| 38 | inline half_vtype vqrshrn(const vtype &a) \ |
| 39 | { \ |
| 40 | return prefix##_##postfix(a, b); \ |
| 41 | } |
| 42 | |
| 43 | VQRSHRN_IMPL(int8x8_t, int16x8_t, vqrshrn_n, s16) |
| 44 | VQRSHRN_IMPL(uint8x8_t, uint16x8_t, vqrshrn_n, u16) |
| 45 | VQRSHRN_IMPL(int16x4_t, int32x4_t, vqrshrn_n, s32) |
| 46 | VQRSHRN_IMPL(uint16x4_t, uint32x4_t, vqrshrn_n, u32) |
| 47 | VQRSHRN_IMPL(int32x2_t, int64x2_t, vqrshrn_n, s64) |
| 48 | VQRSHRN_IMPL(uint32x2_t, uint64x2_t, vqrshrn_n, u64) |
| 49 | |
| 50 | #undef VQRSHRN_IMPL |
| 51 | |
| 52 | // This function is the mixed version of VQRSHRN and VQRSHRUN. |
| 53 | // The input vector is always signed integer, while the returned vector |
| 54 | // can be either signed or unsigned depending on the signedness of scalar type T. |
| 55 | #define VQRSHRN_EX_IMPL(half_vtype, vtype, prefix_signed, prefix_unsigned, postfix) \ |
| 56 | template <int b, typename T> \ |
| 57 | inline typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value, half_vtype>::type \ |
| 58 | vqrshrn_ex(const vtype &a) \ |
| 59 | { \ |
| 60 | return prefix_signed##_##postfix(a, b); \ |
| 61 | } \ |
| 62 | \ |
| 63 | template <int b, typename T> \ |
| 64 | inline typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value, u##half_vtype>::type \ |
| 65 | vqrshrn_ex(const vtype &a) \ |
| 66 | { \ |
| 67 | return prefix_unsigned##_##postfix(a, b); \ |
| 68 | } |
| 69 | |
| 70 | VQRSHRN_EX_IMPL(int8x8_t, int16x8_t, vqrshrn_n, vqrshrun_n, s16) |
| 71 | VQRSHRN_EX_IMPL(int16x4_t, int32x4_t, vqrshrn_n, vqrshrun_n, s32) |
| 72 | VQRSHRN_EX_IMPL(int32x2_t, int64x2_t, vqrshrn_n, vqrshrun_n, s64) |
| 73 | |
| 74 | #undef VQRSHRN_EX_IMPL |
| 75 | |
| 76 | } // namespace wrapper |
| 77 | } // namespace arm_compute |
| 78 | #endif /* ARM_COMPUTE_WRAPPER_SHR_H */ |