blob: 2ec88869e38cb46bffa5085a8d70a80f463af1a5 [file] [log] [blame]
Georgios Pinitas5a594532018-12-03 14:30:05 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitas5a594532018-12-03 14:30:05 +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_SCALAR_ADD_H
25#define ARM_COMPUTE_WRAPPER_SCALAR_ADD_H
Georgios Pinitas5a594532018-12-03 14:30:05 +000026
27#include <arm_neon.h>
28
29namespace arm_compute
30{
31namespace wrapper
32{
33inline uint8_t add_sat(const uint8_t &a, const uint8_t &b)
34{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010035 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};
Georgios Pinitas5a594532018-12-03 14:30:05 +000037 return vget_lane_u8(vqadd_u8(va, vb), 0);
38}
39
40inline int16_t add_sat(const int16_t &a, const int16_t &b)
41{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010042 const int16x4_t va = {a, 0, 0, 0};
43 const int16x4_t vb = {b, 0, 0, 0};
Georgios Pinitas5a594532018-12-03 14:30:05 +000044 return vget_lane_s16(vqadd_s16(va, vb), 0);
45}
46
Michele Di Giorgio11c562c2020-06-10 16:34:50 +010047inline int32_t add_sat(const int32_t &a, const int32_t &b)
48{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010049 const int32x2_t va = {a, 0};
50 const int32x2_t vb = {b, 0};
Michele Di Giorgio11c562c2020-06-10 16:34:50 +010051 return vget_lane_s32(vqadd_s32(va, vb), 0);
52}
53
Georgios Pinitas5a594532018-12-03 14:30:05 +000054inline 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
61inline 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
Michalis Spyrouf4643372019-11-29 16:17:13 +000069#endif /* ARM_COMPUTE_WRAPPER_SCALAR_ADD_H */