From 9b87978fb97f8bed9d53c41830c1bf457dd63703 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 24 May 2024 16:33:47 +0200 Subject: [PATCH 09/21] avcodec/put_bits: Allow to mark places where PutBitContext is flushed This will allow the compiler to optimize the "is the cache full?" branches away from some put_bits(). Signed-off-by: Andreas Rheinhardt --- libavcodec/put_bits.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h index 56c3f4cc6d..c3eee622d4 100644 --- a/libavcodec/put_bits.h +++ b/libavcodec/put_bits.h @@ -74,6 +74,16 @@ static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, s->bit_buf = 0; } +/** + * Inform the compiler that a PutBitContext is flushed (i.e. if it has just + * been initialized or flushed). Undefined behaviour occurs if this is used + * with a PutBitContext for which this is not true. + */ +static inline void put_bits_assume_flushed(const PutBitContext *s) +{ + av_assume(s->bit_left == BUF_BITS); +} + /** * @return the total number of bits written to the bitstream. */ -- 2.45.2