blob: 1fe51d75fc8a2c1c8a122af3bf6ebfe75e53bbe5 [file] [log] [blame]
Michalis Spyrou5f390912020-05-13 00:12:08 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2020 Arm Limited.
Michalis Spyrou5f390912020-05-13 00:12:08 +01003 *
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
29namespace arm_compute
30{
31namespace wrapper
32{
33inline uint8_t sub_sat(const uint8_t &a, const uint8_t &b)
34{
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 };
37 return vget_lane_u8(vqsub_u8(va, vb), 0);
38}
39
40inline int16_t sub_sat(const int16_t &a, const int16_t &b)
41{
42 const int16x4_t va = { a, 0, 0, 0 };
43 const int16x4_t vb = { b, 0, 0, 0 };
44 return vget_lane_s16(vqsub_s16(va, vb), 0);
45}
46
SiCong Li903f8cc2020-08-27 10:17:10 +010047inline int32_t sub_sat(const int32_t &a, const int32_t &b)
48{
49 const int32x2_t va = { a, 0 };
50 const int32x2_t vb = { b, 0 };
51 return vget_lane_s32(vqsub_s32(va, vb), 0);
52}
53
Michalis Spyrou5f390912020-05-13 00:12:08 +010054inline 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
61inline 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 */