Yahui Han | ad79ebb | 2023-07-19 17:02:21 +0800 | [diff] [blame] | 1 | typedef unsigned int UWORD32; |
| 2 | |
| 3 | /*****************************************************************************/ |
| 4 | /* Define a macro for inlining of NEXTBITS_32 */ |
| 5 | /*****************************************************************************/ |
| 6 | #define NEXTBITS_32(u4_word, u4_offset, pu4_bitstream) \ |
| 7 | { \ |
| 8 | UWORD32 *pu4_buf = (pu4_bitstream); \ |
| 9 | UWORD32 u4_word_off = ((u4_offset) >> 5); \ |
| 10 | UWORD32 u4_bit_off = (u4_offset) & 0x1F; \ |
| 11 | \ |
| 12 | u4_word = pu4_buf[u4_word_off++] << u4_bit_off; \ |
| 13 | if(u4_bit_off) \ |
| 14 | u4_word |= (pu4_buf[u4_word_off] >> (INT_IN_BITS - u4_bit_off)); \ |
| 15 | } \ |
| 16 | |
| 17 | #define INT_IN_BITS 32 |
| 18 | /*****************************************************************************/ |
| 19 | /* Define a macro for inlining of GETBITS: u4_no_bits shall not exceed 32 */ |
| 20 | /*****************************************************************************/ |
| 21 | #define GETBITS(u4_code, u4_offset, pu4_bitstream, u4_no_bits) \ |
| 22 | { \ |
| 23 | UWORD32 *pu4_buf = (pu4_bitstream); \ |
| 24 | UWORD32 u4_word_off = ((u4_offset) >> 5); \ |
| 25 | UWORD32 u4_bit_off = (u4_offset) & 0x1F; \ |
| 26 | u4_code = pu4_buf[u4_word_off++] << u4_bit_off; \ |
| 27 | \ |
| 28 | if(u4_bit_off) \ |
| 29 | u4_code |= (pu4_buf[u4_word_off] >> (INT_IN_BITS - u4_bit_off)); \ |
| 30 | u4_code = u4_code >> (INT_IN_BITS - u4_no_bits); \ |
| 31 | (u4_offset) += u4_no_bits; \ |
| 32 | } \ |
| 33 | |
| 34 | static inline uint32_t CLZ(uint32_t u4_word) |
| 35 | { |
| 36 | if (u4_word) |
| 37 | return (__builtin_clz(u4_word)); |
| 38 | else |
| 39 | return 31; |
| 40 | } |