1 /*
2 * Copyright (c) 2018-2020 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_SCALAR_ADD_H
25 #define ARM_COMPUTE_WRAPPER_SCALAR_ADD_H
26
27 #include <arm_neon.h>
28
29 namespace arm_compute
30 {
31 namespace wrapper
32 {
add_sat(const uint8_t & a,const uint8_t & b)33 inline uint8_t add_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(vqadd_u8(va, vb), 0);
38 }
39
add_sat(const int16_t & a,const int16_t & b)40 inline int16_t add_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(vqadd_s16(va, vb), 0);
45 }
46
add_sat(const int32_t & a,const int32_t & b)47 inline int32_t add_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(vqadd_s32(va, vb), 0);
52 }
53
add_sat(const float & a,const float & b)54 inline float add_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
add_sat(const float16_t & a,const float16_t & b)61 inline float16_t add_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_ADD_H */
70