[FFmpeg-devel] [PATCH 10/12] avcodec/put_bits: Allow to mark places where PutBitContext is flushed

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat May 25 01:04:53 EEST 2024


This will allow the compiler to optimize the "is the cache full?"
branches away from some put_bits().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/put_bits.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
index 4561dc131a..79bad1c214 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.40.1



More information about the ffmpeg-devel mailing list