| 709 | } |
| 710 | |
| 711 | static inline uint32_t |
| 712 | read_unaligned_bits(uint8_t *ptr, int len, int offset) |
| 713 | { |
| 714 | uint32_t ret = 0; |
| 715 | int shift; |
| 716 | |
| 717 | len = RTE_MAX(len, 0); |
| 718 | len = RTE_MIN(len, (int)(sizeof(uint32_t) * CHAR_BIT)); |
| 719 | |
| 720 | while (len > 0) { |
| 721 | ret <<= CHAR_BIT; |
| 722 | |
| 723 | ret |= read_unaligned_byte(ptr, offset); |
| 724 | offset += CHAR_BIT; |
| 725 | len -= CHAR_BIT; |
| 726 | } |
| 727 | |
| 728 | shift = (len == 0) ? 0 : |
| 729 | (CHAR_BIT - ((len + CHAR_BIT) % CHAR_BIT)); |
| 730 | return ret >> shift; |
| 731 | } |
| 732 | |
| 733 | /* returns mask for len bits with given offset inside byte */ |
| 734 | static inline uint8_t |
no test coverage detected