Michalis Spyrou | 5f39091 | 2020-05-13 00:12:08 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020 Arm Limited. |
Michalis Spyrou | 5f39091 | 2020-05-13 00:12:08 +0100 | [diff] [blame] | 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_SCALAR_SUB_H |
| 25 | #define ARM_COMPUTE_WRAPPER_SCALAR_SUB_H |
| 26 | |
| 27 | #include <arm_neon.h> |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace wrapper |
| 32 | { |
| 33 | inline uint8_t sub_sat(const uint8_t &a, const uint8_t &b) |
| 34 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 35 | const uint8x8_t va = {a, 0, 0, 0, 0, 0, 0, 0}; |
| 36 | const uint8x8_t vb = {b, 0, 0, 0, 0, 0, 0, 0}; |
Michalis Spyrou | 5f39091 | 2020-05-13 00:12:08 +0100 | [diff] [blame] | 37 | return vget_lane_u8(vqsub_u8(va, vb), 0); |
| 38 | } |
| 39 | |
| 40 | inline int16_t sub_sat(const int16_t &a, const int16_t &b) |
| 41 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 42 | const int16x4_t va = {a, 0, 0, 0}; |
| 43 | const int16x4_t vb = {b, 0, 0, 0}; |
Michalis Spyrou | 5f39091 | 2020-05-13 00:12:08 +0100 | [diff] [blame] | 44 | return vget_lane_s16(vqsub_s16(va, vb), 0); |
| 45 | } |
| 46 | |
SiCong Li | 903f8cc | 2020-08-27 10:17:10 +0100 | [diff] [blame] | 47 | inline int32_t sub_sat(const int32_t &a, const int32_t &b) |
| 48 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 49 | const int32x2_t va = {a, 0}; |
| 50 | const int32x2_t vb = {b, 0}; |
SiCong Li | 903f8cc | 2020-08-27 10:17:10 +0100 | [diff] [blame] | 51 | return vget_lane_s32(vqsub_s32(va, vb), 0); |
| 52 | } |
| 53 | |
Michalis Spyrou | 5f39091 | 2020-05-13 00:12:08 +0100 | [diff] [blame] | 54 | inline float sub_sat(const float &a, const float &b) |
| 55 | { |
| 56 | // No notion of saturation exists in floating point |
| 57 | return a - b; |
| 58 | } |
| 59 | |
| 60 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 61 | inline float16_t sub_sat(const float16_t &a, const float16_t &b) |
| 62 | { |
| 63 | // No notion of saturation exists in floating point |
| 64 | return a - b; |
| 65 | } |
| 66 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 67 | } // namespace wrapper |
| 68 | } // namespace arm_compute |
| 69 | #endif /* ARM_COMPUTE_WRAPPER_SCALAR_SUB_H */ |