diff mbox series

[FFmpeg-devel] lavu/common: Fix AV_CEIL_RSHIFT for unsigned LHS

Message ID 20241005223922.53888-1-post@frankplowman.com
State New
Headers show
Series [FFmpeg-devel] lavu/common: Fix AV_CEIL_RSHIFT for unsigned LHS | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Frank Plowman Oct. 5, 2024, 10:38 p.m. UTC
The first branch of this ternary expression was intended to avoid
having two shift operations in the case the RHS is not known at
compile time.  It only works if the LHS has a signed type however,
otherwise the result is invalid.

We could alternatively have different versions of AV_CEIL_RSHIFT for
different sizes of operand, then cast the LHS to the relevant signed
type.

Signed-off-by: Frank Plowman <post@frankplowman.com>
---
 libavutil/common.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/common.h b/libavutil/common.h
index 3b830daf30..ec38752b64 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -57,8 +57,7 @@ 
 /* assume b>0 */
 #define ROUNDED_DIV(a,b) (((a)>=0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
 /* Fast a/(1<<b) rounded toward +inf. Assume a>=0 and b>=0 */
-#define AV_CEIL_RSHIFT(a,b) (!av_builtin_constant_p(b) ? -((-(a)) >> (b)) \
-                                                       : ((a) + (1<<(b)) - 1) >> (b))
+#define AV_CEIL_RSHIFT(a,b) (((a) + (1<<(b)) - 1) >> (b))
 /* Backwards compat. */
 #define FF_CEIL_RSHIFT AV_CEIL_RSHIFT