| @@ -290,13 +290,29 @@ static inline uint64_t BS_FUNC(read_64)(BSCTX *bc, unsigned int n) · 289 unmodified lines |
| 290 | 290 | return BS_FUNC(read_63)(bc, n); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | +/** |
| 294 | + * Return n bits from the buffer as a signed integer, n has to be in the 1-32 |
| 295 | + * range. May be faster than bits_read_signed() when n is not a compile-time |
| 296 | + * constant and is known to be non-zero; |
| 297 | + */ |
| 298 | +static inline int32_t BS_FUNC(read_signed_nz)(BSCTX *bc, unsigned int n) |
| 299 | +{ |
| 300 | + av_assert2(n > 0 && n <= 32); |
| 301 | + return sign_extend(BS_FUNC(read_nz)(bc, n), n); |
| 302 | +} |
| 303 | + |
| 293 | 304 | /** |
| 294 | 305 | * Return n bits from the buffer as a signed integer. |
| 295 | 306 | * n has to be in the 0-32 range. |
| 296 | 307 | */ |
| 297 | 308 | static inline int32_t BS_FUNC(read_signed)(BSCTX *bc, unsigned int n) |
| 298 | 309 | { |
| 299 | | − return sign_extend(BS_FUNC(read)(bc, n), n); |
| 310 | + av_assert2(n <= 32); |
| 311 | + |
| 312 | + if (!n) |
| 313 | + return 0; |
| 314 | + |
| 315 | + return BS_FUNC(read_signed_nz)(bc, n); |
| 300 | 316 | } |
| 301 | 317 | |
| 302 | 318 | /** |
| @@ -327,6 +343,17 @@ static inline uint32_t BS_FUNC(peek)(BSCTX *bc, unsigned int n) · 24 unmodified lines |
| 327 | 343 | return BS_FUNC(peek_nz)(bc, n); |
| 328 | 344 | } |
| 329 | 345 | |
| 346 | +/** |
| 347 | + * Return n bits from the buffer as a signed integer, do not change the buffer |
| 348 | + * state. n has to be in the 1-32 range. May be faster than bits_peek_signed() |
| 349 | + * when n is not a compile-time constant and is known to be non-zero; |
| 350 | + */ |
| 351 | +static inline int BS_FUNC(peek_signed_nz)(BSCTX *bc, unsigned int n) |
| 352 | +{ |
| 353 | + av_assert2(n > 0 && n <= 32); |
| 354 | + return sign_extend(BS_FUNC(peek_nz)(bc, n), n); |
| 355 | +} |
| 356 | + |
| 330 | 357 | /** |
| 331 | 358 | * Return n bits from the buffer as a signed integer, |
| 332 | 359 | * do not change the buffer state. |
| @@ -334,7 +361,12 @@ static inline uint32_t BS_FUNC(peek)(BSCTX *bc, unsigned int n) · 1 unmodified line |
| 334 | 361 | */ |
| 335 | 362 | static inline int BS_FUNC(peek_signed)(BSCTX *bc, unsigned int n) |
| 336 | 363 | { |
| 337 | | − return sign_extend(BS_FUNC(peek)(bc, n), n); |
| 364 | + av_assert2(n <= 32); |
| 365 | + |
| 366 | + if (!n) |
| 367 | + return 0; |
| 368 | + |
| 369 | + return BS_FUNC(peek_signed_nz)(bc, n); |
| 338 | 370 | } |
| 339 | 371 | |
| 340 | 372 | /** |