1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef SBC_MATH_H
17 #define SBC_MATH_H
18
19 #include <cstddef>
20 #include <cstdint>
21
FABS(int32_t x)22 static inline int32_t FABS(int32_t x)
23 {
24 return ((x) < 0 ? -(x) : (x));
25 }
ASR(int32_t val,int bits)26 static inline int32_t ASR(int32_t val, int bits)
27 {
28 return ((-2 >> 1 == -1) ?
29 (static_cast<int32_t>(val)) >> (bits) : (static_cast<int32_t>(val)) / (1 << (bits)));
30 }
31
32 #define SCALE_SPROTO4_TBL 12
33 #define SCALE_SPROTO8_TBL 14
34 #define SCALE_NPROTO4_TBL 11
35 #define SCALE_NPROTO8_TBL 11
36 #define SCALE4_STAGED1_BITS 15
37 #define SCALE4_STAGED2_BITS 16
38 #define SCALE8_STAGED1_BITS 15
39 #define SCALE8_STAGED2_BITS 16
40
Scale4Staged1(int32_t src)41 static inline int32_t Scale4Staged1(int32_t src)
42 {
43 return ((-2 >> 1 == -1) ?
44 (static_cast<int32_t>(src)) >> (SCALE4_STAGED1_BITS) :
45 (static_cast<int32_t>(src)) / (1 << (SCALE4_STAGED1_BITS)));
46 }
Scale8Staged1(int32_t src)47 static inline int32_t Scale8Staged1(int32_t src)
48 {
49 return ((-2 >> 1 == -1) ?
50 (static_cast<int32_t>(src)) >> (SCALE8_STAGED1_BITS) :
51 (static_cast<int32_t>(src)) / (1 << (SCALE8_STAGED1_BITS)));
52 }
53
MUL(int32_t a,int32_t b)54 static inline int32_t MUL(int32_t a, int32_t b)
55 {
56 return a * b;
57 }
58
MULA(int32_t a,int32_t b,int32_t res)59 static inline int32_t MULA(int32_t a, int32_t b, int32_t res)
60 {
61 return (a * b + res);
62 }
63 #endif // SBC_MATH_H