Vector Optimized Library of Kernels  3.0.0
Architecture-tuned implementations of math kernels
saturation_arithmetic.h
Go to the documentation of this file.
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 static inline int16_t sat_adds16i(int16_t x, int16_t y)
17 {
18  int32_t res = (int32_t)x + (int32_t)y;
19 
20  if (res < SHRT_MIN)
21  res = SHRT_MIN;
22  if (res > SHRT_MAX)
23  res = SHRT_MAX;
24 
25  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_ */
static int16_t sat_muls16i(int16_t x, int16_t y)
Definition: saturation_arithmetic.h:28
static int16_t sat_adds16i(int16_t x, int16_t y)
Definition: saturation_arithmetic.h:16