+static inline void refill_64(GetBitContext *s)
+{
+#if !UNCHECKED_BITSTREAM_READER
+ if (s->index >> 3 >= s->buffer_end - s->buffer)
+ return;
+#endif
+
+#ifdef BITSTREAM_READER_LE
+ s->cache = AV_RL64(s->buffer + (s->index >> 3));
+#else
+ s->cache = AV_RB64(s->buffer + (s->index >> 3));
+#endif
+ s->index += 64;
+ s->bits_left = 64;
+}
+
+static inline uint64_t get_val(GetBitContext *s, unsigned n, int is_le)
+{
+ uint64_t ret;
+ av_assert2(n>0 && n<=63);
+ if (is_le) {
+ ret = s->cache & ((UINT64_C(1) << n) - 1);
+ s->cache >>= n;
+ } else {
+ ret = s->cache >> (64 - n);
+ s->cache <<= n;
+ }
+ s->bits_left -= n;
+ return ret;
+}
+
+static inline unsigned show_val(const GetBitContext *s, unsigned n)
+{
+#ifdef BITSTREAM_READER_LE
+ return s->cache & ((UINT64_C(1) << n) - 1);
+#else
+ return s->cache >> (64 - n);
+#endif
+}
+#endif
+