diff mbox series

[FFmpeg-devel,1/5] avcodec/ppc/hpeldsp_altivec: Fix left-shift of negative number

Message ID GV1P250MB07377A6CF76BB88E41854D698F3A2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 356610a2ac1db9c1908903ee48721b3ce391ba01
Headers show
Series [FFmpeg-devel,1/5] avcodec/ppc/hpeldsp_altivec: Fix left-shift of negative number | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt March 29, 2024, 3:23 a.m. UTC
It is UB and affected e.g. the vp5 and vp61 FATE tests:
https://fate.ffmpeg.org/report.cgi?time=20240327083327&slot=ppc-linux-gcc-13.2-ubsan-altivec-qemu

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ppc/hpeldsp_altivec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andreas Rheinhardt April 1, 2024, 6:41 p.m. UTC | #1
Andreas Rheinhardt:
> It is UB and affected e.g. the vp5 and vp61 FATE tests:
> https://fate.ffmpeg.org/report.cgi?time=20240327083327&slot=ppc-linux-gcc-13.2-ubsan-altivec-qemu
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/ppc/hpeldsp_altivec.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/ppc/hpeldsp_altivec.c b/libavcodec/ppc/hpeldsp_altivec.c
> index a531b6b6ec..4bf6b28ed6 100644
> --- a/libavcodec/ppc/hpeldsp_altivec.c
> +++ b/libavcodec/ppc/hpeldsp_altivec.c
> @@ -41,9 +41,9 @@ void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t li
>      register vector unsigned char pixelsv1D;
>  
>      int i;
> -    register ptrdiff_t line_size_2 = line_size << 1;
> +    register ptrdiff_t line_size_2 = line_size * (1 << 1);
>      register ptrdiff_t line_size_3 = line_size + line_size_2;
> -    register ptrdiff_t line_size_4 = line_size << 2;
> +    register ptrdiff_t line_size_4 = line_size * (1 << 2);
>  
>  // hand-unrolling the loop by 4 gains about 15%
>  // mininum execution time goes from 74 to 60 cycles

Will apply the remainder of this patchset tomorrow unless there are
objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/ppc/hpeldsp_altivec.c b/libavcodec/ppc/hpeldsp_altivec.c
index a531b6b6ec..4bf6b28ed6 100644
--- a/libavcodec/ppc/hpeldsp_altivec.c
+++ b/libavcodec/ppc/hpeldsp_altivec.c
@@ -41,9 +41,9 @@  void ff_put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, ptrdiff_t li
     register vector unsigned char pixelsv1D;
 
     int i;
-    register ptrdiff_t line_size_2 = line_size << 1;
+    register ptrdiff_t line_size_2 = line_size * (1 << 1);
     register ptrdiff_t line_size_3 = line_size + line_size_2;
-    register ptrdiff_t line_size_4 = line_size << 2;
+    register ptrdiff_t line_size_4 = line_size * (1 << 2);
 
 // hand-unrolling the loop by 4 gains about 15%
 // mininum execution time goes from 74 to 60 cycles