Line | Branch | Exec | Source |
---|---|---|---|
1 | /* -*- c++ -*- */ | ||
2 | /* | ||
3 | * Copyright 2016 Free Software Foundation, Inc. | ||
4 | * | ||
5 | * This file is part of VOLK | ||
6 | * | ||
7 | * SPDX-License-Identifier: LGPL-3.0-or-later | ||
8 | */ | ||
9 | |||
10 | |||
11 | #ifndef INCLUDED_volk_saturation_arithmetic_H_ | ||
12 | #define INCLUDED_volk_saturation_arithmetic_H_ | ||
13 | |||
14 | #include <limits.h> | ||
15 | |||
16 | 524460 | static inline int16_t sat_adds16i(int16_t x, int16_t y) | |
17 | { | ||
18 | 524460 | int32_t res = (int32_t)x + (int32_t)y; | |
19 | |||
20 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 524460 times.
|
524460 | if (res < SHRT_MIN) |
21 | ✗ | res = SHRT_MIN; | |
22 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 524460 times.
|
524460 | if (res > SHRT_MAX) |
23 | ✗ | res = SHRT_MAX; | |
24 | |||
25 | 524460 | return res; | |
26 | } | ||
27 | |||
28 | static inline int16_t sat_muls16i(int16_t x, int16_t y) | ||
29 | { | ||
30 | int32_t res = (int32_t)x * (int32_t)y; | ||
31 | |||
32 | if (res < SHRT_MIN) | ||
33 | res = SHRT_MIN; | ||
34 | if (res > SHRT_MAX) | ||
35 | res = SHRT_MAX; | ||
36 | |||
37 | return res; | ||
38 | } | ||
39 | |||
40 | #endif /* INCLUDED_volk_saturation_arithmetic_H_ */ | ||
41 |