• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: LIB模块内部头文件
14  */
15 #ifndef PRT_LIB_EXTERNAL_H
16 #define PRT_LIB_EXTERNAL_H
17 
18 #include "securec.h"
19 #include "prt_sys.h"
20 
21 /* 对齐操作API */
22 #define OS_ADDR_OVERTURN_CHK(addr, size) (((size) != 0) && (((addr) + (size) - 1) < (addr)))
23 #define OS_ALIGN_CHK(addr, align)       (((uintptr_t)(addr) & ((align) - 1)) == 0)
24 #define OS_NOT_ALIGN_CHK(addr, align)   (!OS_ALIGN_CHK(addr, align))
25 #define OS_ALIGN(addr, align)           ((uintptr_t)(addr) & ((align) - 1))
26 
27 #define OS_32BIT_MOD(num)               ((num) % 32)
28 
29 #define OS_GET_64BIT_HIGH_32BIT(num)    ((U32)((num) >> 32))
30 #define OS_GET_64BIT_LOW_32BIT(num)     ((U32)((num) & 0xFFFFFFFFU))
31 
32 #define OS_GET_32BIT_HIGH_8BIT(num)     (((num) >> 24) & 0xffU)
33 #define OS_GET_32BIT_LOW_8BIT(num)      ((num) & 0xffU)
34 
35 #define OS_GET_32BIT_HIGH_16BIT(num)    ((num) >> 16)
36 #define OS_GET_32BIT_LOW_16BIT(num)     ((num) & 0xFFFFU)
37 
38 #define OS_GET_16BIT_HIGH_8BIT(num)     ((num) >> 8)
39 
40 #define OS_GET_8BIT_HIGH_4BIT(num)      ((num) >> 4)
41 #define OS_GET_8BIT_LOW_4BIT(num)       ((num) & 0xFU)
42 
43 #define OS_GET_32BIT_ARRAY_INDEX(num)   ((num) >> 5)
44 #define OS_GET_32BIT_ARRAY_BASE(num)    ((num) << 5)
45 
46 #define OS_32BIT_MASK(bit)              (1U << OS_32BIT_MOD(bit))
47 #define OS_32BIT_VERSE_MASK(bit)        (~(1U << OS_32BIT_MOD(bit)))
48 
49 #define OS_GET_BIT_IN_WORD(num)         ((num) & 0x1FUL)
50 
51 #define OS_64BIT_SET(high, low)         (((U64)(high) << 32) + (U64)(low))
52 #define OS_LMB32                        31
53 
54 #define OS_MAX_U32 0xFFFFFFFFU
55 #define OS_MAX_U16 0xFFFFU
56 #define OS_MAX_U12 0xFFFU
57 #define OS_MAX_U8 0xFFU
58 #define OS_MAX_U4 0xFU
59 
60 #define OS_MAX_S8 0xFF
61 
62 #define OS_BYTES_PER_DWORD              (sizeof(U64))
63 #define OS_BYTES_PER_WORD               (sizeof(U32))
64 #define OS_BITS_PER_BYTE                8
65 
66 #define OS_BITNUM_2_MASK(bitNum) ((1U << (bitNum)) - 1)
67 #define OS_WORD_ALLBIT_MASK 0xFFFFFFFFU
68 
69 #define OS_IS_VISIBLE_CHAR(word) ((((word) >= 'a') && ((word) <= 'z')) || (((word) >= 'A') && ((word) <= 'Z')) || \
70                                   ((word) == '_') || (((word) <= '9') && ((word) >= '0')))
71 
72 #define MIN(a, b) ((a) < (b) ? (a) : (b))
73 #define MAX(a, b) ((a) > (b) ? (a) : (b))
74 
75 #define OS_DECIMAL    10
76 #define OS_OCTAL      8
77 #define OS_HEX        16
78 
79 #define OS_BIT0_MASK  (0x1U << 0)
80 #define OS_BIT1_MASK  (0x1U << 1)
81 #define OS_BIT2_MASK  (0x1U << 2)
82 #define OS_BIT3_MASK  (0x1U << 3)
83 #define OS_BIT4_MASK  (0x1U << 4)
84 #define OS_BIT5_MASK  (0x1U << 5)
85 #define OS_BIT6_MASK  (0x1U << 6)
86 #define OS_BIT7_MASK  (0x1U << 7)
87 #define OS_BIT8_MASK  (0x1U << 8)
88 #define OS_BIT9_MASK  (0x1U << 9)
89 #define OS_BIT10_MASK (0x1U << 10)
90 #define OS_BIT11_MASK (0x1U << 11)
91 #define OS_BIT12_MASK (0x1U << 12)
92 #define OS_BIT13_MASK (0x1U << 13)
93 #define OS_BIT14_MASK (0x1U << 14)
94 #define OS_BIT15_MASK (0x1U << 15)
95 #define OS_BIT16_MASK (0x1U << 16)
96 #define OS_BIT17_MASK (0x1U << 17)
97 #define OS_BIT18_MASK (0x1U << 18)
98 #define OS_BIT19_MASK (0x1U << 19)
99 #define OS_BIT20_MASK (0x1U << 20)
100 #define OS_BIT21_MASK (0x1U << 21)
101 #define OS_BIT22_MASK (0x1U << 22)
102 #define OS_BIT23_MASK (0x1U << 23)
103 #define OS_BIT24_MASK (0x1U << 24)
104 #define OS_BIT25_MASK (0x1U << 25)
105 #define OS_BIT26_MASK (0x1U << 26)
106 #define OS_BIT27_MASK (0x1U << 27)
107 #define OS_BIT28_MASK (0x1U << 28)
108 #define OS_BIT29_MASK (0x1U << 29)
109 #define OS_BIT30_MASK (0x1U << 30)
110 #define OS_BIT31_MASK (0x1U << 31)
111 
112 #define OS_BIT_SET_VALUE(bit) (0x1UL << (bit))
113 
114 #define BNUM_TO_WNUM(bnum)   (((bnum) + 31) >> 5)
115 #define OS_WORD_BIT_NUM      32
116 #define OS_WORD_BIT_POW      5
117 #define OS_DWORD_BIT_NUM     64
118 #define OS_DWORD_BIT_POW     6
119 #define OS_HALF_WORD_BIT_NUM 16
120 #define OS_GET_WORD_NUM_BY_PRIONUM(prio) (((prio) + 0x1f) >> 5)  // 通过支持的优先级个数计算需要多少个word表示
121 
122 #ifndef OS_STATIC_NO_INLINE
123 #define OS_STATIC_NO_INLINE static __noinline __attribute__((noinline))
124 #endif
125 
126 #ifndef ATTR_ALIGN_128
127 #define ATTR_ALIGN_128 __attribute__((aligned(128))) /* 表示128 字节对齐 */
128 #endif
129 
130 #ifndef ATTR_ALIGN_64
131 #define ATTR_ALIGN_64 __attribute__((aligned(64)))   /* 表示64 字节对齐 */
132 #endif
133 
134 #ifndef ATTR_ALIGN_32
135 #define ATTR_ALIGN_32 __attribute__((aligned(32)))   /* 表示32 字节对齐 */
136 #endif
137 
138 #ifndef ATTR_ALIGN_16
139 #define ATTR_ALIGN_16 __attribute__((aligned(16)))   /* 表示16 字节对齐 */
140 #endif
141 
142 #ifndef ATTR_ALIGN_8
143 #define ATTR_ALIGN_8 __attribute__((aligned(8)))     /* 表示8字节对齐 */
144 #endif
145 
146 #ifndef ATTR_ALIGN_4
147 #define ATTR_ALIGN_4 __attribute__((aligned(4)))     /* 表示4字节对齐 */
148 #endif
149 
150 #define OS_SYS_UINT_IDX(coreId) ((U32)(coreId) >> 5)  // 一个U32表示32个核
151 #define OS_SYS_UINT_LCOREID_OFFSET(coreId) (((coreId) & 0x1fUL))  // 核号在一个U32里的偏移
152 
153 /*
154  * 模块间宏定义
155  */
156 extern void OsAdd64(U32 *low, U32 *high, U32 oldLow, U32 oldHigh);
157 extern void OsSub64(U32 *low, U32 *high, U32 oldLow, U32 oldHigh);
158 extern U32 OsGetLmb1(U32 value);
159 
160 #endif /* PRT_LIB_EXTERNAL_H */
161