@@ -120,6 +120,22 @@ TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, c
120120 return 0 ;
121121}
122122
123+ TU_ATTR_ALWAYS_INLINE static inline bool tu_mem_is_zero (const void * buffer , size_t size ) {
124+ const uint8_t * buf8 = (const uint8_t * ) buffer ;
125+ for (size_t i = 0 ; i < size ; i ++ ) {
126+ if (buf8 [i ] != 0 ) { return false; }
127+ }
128+ return true;
129+ }
130+
131+ TU_ATTR_ALWAYS_INLINE static inline bool tu_mem_is_ff (const void * buffer , size_t size ) {
132+ const uint8_t * buf8 = (const uint8_t * ) buffer ;
133+ for (size_t i = 0 ; i < size ; i ++ ) {
134+ if (buf8 [i ] != 0xff ) { return false; }
135+ }
136+ return true;
137+ }
138+
123139
124140//------------- Bytes -------------//
125141TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_u32 (uint8_t b3 , uint8_t b2 , uint8_t b1 , uint8_t b0 ) {
@@ -181,8 +197,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_round_up(uint32_t v, uint32_t f)
181197
182198// log2 of a value is its MSB's position
183199// TODO use clz TODO remove
184- static inline uint8_t tu_log2 (uint32_t value )
185- {
200+ TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_log2 (uint32_t value ) {
186201 uint8_t result = 0 ;
187202 while (value >>= 1 ) { result ++ ; }
188203 return result ;
@@ -193,8 +208,7 @@ static inline uint8_t tu_log2(uint32_t value)
193208// return sizeof(uint32_t) * CHAR_BIT - __builtin_clz(x) - 1;
194209//}
195210
196- static inline bool tu_is_power_of_two (uint32_t value )
197- {
211+ TU_ATTR_ALWAYS_INLINE static inline bool tu_is_power_of_two (uint32_t value ) {
198212 return (value != 0 ) && ((value & (value - 1 )) == 0 );
199213}
200214
@@ -205,27 +219,23 @@ static inline bool tu_is_power_of_two(uint32_t value)
205219typedef struct { uint16_t val ; } TU_ATTR_PACKED tu_unaligned_uint16_t ;
206220typedef struct { uint32_t val ; } TU_ATTR_PACKED tu_unaligned_uint32_t ;
207221
208- TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_unaligned_read32 (const void * mem )
209- {
210- tu_unaligned_uint32_t const * ua32 = (tu_unaligned_uint32_t const * ) mem ;
222+ TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_unaligned_read32 (const void * mem ) {
223+ tu_unaligned_uint32_t const * ua32 = (tu_unaligned_uint32_t const * ) mem ;
211224 return ua32 -> val ;
212225}
213226
214- TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write32 (void * mem , uint32_t value )
215- {
216- tu_unaligned_uint32_t * ua32 = (tu_unaligned_uint32_t * ) mem ;
227+ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write32 (void * mem , uint32_t value ) {
228+ tu_unaligned_uint32_t * ua32 = (tu_unaligned_uint32_t * ) mem ;
217229 ua32 -> val = value ;
218230}
219231
220- TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16 (const void * mem )
221- {
222- tu_unaligned_uint16_t const * ua16 = (tu_unaligned_uint16_t const * ) mem ;
232+ TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_unaligned_read16 (const void * mem ) {
233+ tu_unaligned_uint16_t const * ua16 = (tu_unaligned_uint16_t const * ) mem ;
223234 return ua16 -> val ;
224235}
225236
226- TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void * mem , uint16_t value )
227- {
228- tu_unaligned_uint16_t * ua16 = (tu_unaligned_uint16_t * ) mem ;
237+ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void * mem , uint16_t value ) {
238+ tu_unaligned_uint16_t * ua16 = (tu_unaligned_uint16_t * ) mem ;
229239 ua16 -> val = value ;
230240}
231241
0 commit comments