Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/huffyuvencdsp: Fix load of misaligned values
Date: Fri, 29 Mar 2024 04:24:29 +0100
Message-ID: <GV1P250MB0737690AA71271D549996E1F8F3A2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <GV1P250MB07377A6CF76BB88E41854D698F3A2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>

Affected many ffvhuff FATE tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/huffyuvencdsp.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/libavcodec/huffyuvencdsp.c b/libavcodec/huffyuvencdsp.c
index 36e8f6130b..27428635af 100644
--- a/libavcodec/huffyuvencdsp.c
+++ b/libavcodec/huffyuvencdsp.c
@@ -18,16 +18,32 @@
 
 #include "config.h"
 #include "libavutil/attributes.h"
+#include "libavutil/intreadwrite.h"
 #include "huffyuvencdsp.h"
 #include "mathops.h"
 
+#if HAVE_FAST_64BIT
+#define BITS 64
+typedef uint64_t uint_native;
+#else
+#define BITS 32
+typedef uint32_t uint_native;
+#endif
+#define RN  AV_JOIN(AV_RN, BITS)
+#define RNA AV_JOIN(AV_JOIN(AV_RN, BITS), A)
+#define WNA AV_JOIN(AV_JOIN(AV_WN, BITS), A)
+
+// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
+#define pb_7f (~(uint_native)0 / 255 * 0x7f)
+#define pb_80 (~(uint_native)0 / 255 * 0x80)
+
 // 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size
-#define pw_1 (ULONG_MAX / UINT16_MAX)
+#define pw_1 ((uint_native)-1 / UINT16_MAX)
 
 static void diff_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *src2, unsigned mask, int w){
     long i;
 #if !HAVE_FAST_UNALIGNED
-    if((long)src2 & (sizeof(long)-1)){
+    if ((uintptr_t)src2 & (sizeof(uint_native) - 1)) {
         for(i=0; i+3<w; i+=4){
             dst[i+0] = (src1[i+0]-src2[i+0]) & mask;
             dst[i+1] = (src1[i+1]-src2[i+1]) & mask;
@@ -37,13 +53,13 @@ static void diff_int16_c(uint16_t *dst, const uint16_t *src1, const uint16_t *sr
     }else
 #endif
     {
-        unsigned long pw_lsb = (mask >> 1) * pw_1;
-        unsigned long pw_msb = pw_lsb +  pw_1;
+        uint_native pw_lsb = (mask >> 1) * pw_1;
+        uint_native pw_msb = pw_lsb +  pw_1;
 
-        for (i = 0; i <= w - (int)sizeof(long)/2; i += sizeof(long)/2) {
-            long a = *(long*)(src1+i);
-            long b = *(long*)(src2+i);
-            *(long*)(dst+i) = ((a|pw_msb) - (b&pw_lsb)) ^ ((a^b^pw_msb)&pw_msb);
+        for (i = 0; i <= w - (int)sizeof(uint_native)/2; i += sizeof(uint_native)/2) {
+            uint_native a = RNA(src1 + i);
+            uint_native b = RN (src2 + i);
+            WNA(dst + i, ((a | pw_msb) - (b & pw_lsb)) ^ ((a^b^pw_msb) & pw_msb));
         }
     }
     for (; i<w; i++)
-- 
2.40.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2024-03-29  3:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29  3:23 [FFmpeg-devel] [PATCH 1/5] avcodec/ppc/hpeldsp_altivec: Fix left-shift of negative number Andreas Rheinhardt
2024-03-29  3:24 ` [FFmpeg-devel] [PATCH 2/5] fate/ffmpeg: Explicitly set pix fmt for sub2video tests Andreas Rheinhardt
2024-03-29 14:28   ` Sean McGovern
2024-03-29 14:45     ` Andreas Rheinhardt
2024-03-29  3:24 ` [FFmpeg-devel] [PATCH 3/5] avcodec/pngdsp: Fix unaligned accesses, effective type violations Andreas Rheinhardt
2024-03-29  3:24 ` [FFmpeg-devel] [PATCH 4/5] avfilter/vf_spp: Fix left-shift of negative value Andreas Rheinhardt
2024-03-29  3:24 ` Andreas Rheinhardt [this message]
2024-03-29 16:45 ` [FFmpeg-devel] [PATCH 6/6] fate/image: Fix EXR tests on big endian Andreas Rheinhardt
2024-03-30 18:28   ` Sean McGovern
2024-03-29 18:07 ` [FFmpeg-devel] [PATCH 7/7] fate/video: Only use bitexact IDCT in avid meridian Andreas Rheinhardt
2024-03-29 18:11 ` [FFmpeg-devel] [PATCH 8/8] fate/filter-video: Always use little endian pixel format Andreas Rheinhardt
2024-03-29 18:26 ` [FFmpeg-devel] [PATCH 9/9] fate/filter-video: Insert scale, format filters in filter-yadif tests Andreas Rheinhardt
2024-03-29 18:45 ` [FFmpeg-devel] [PATCH v2 9/9] fate/filter-video: Insert scale, format filters in filter-yadif, bwdif10 Andreas Rheinhardt
2024-03-30  3:15 ` [FFmpeg-devel] [PATCH 10/12] fate/fits: Fix tests on BE Andreas Rheinhardt
2024-03-30  3:15 ` [FFmpeg-devel] [PATCH 11/12] avcodec/vlc, bitstream: Fix multi VLC with uint8_t syms " Andreas Rheinhardt
2024-03-30  3:15 ` [FFmpeg-devel] [PATCH 12/12] avcodec/vlc: Use union of uint8_t and uint16_t in VLC_MULTI_ELEM Andreas Rheinhardt
2024-03-30  3:39 ` [FFmpeg-devel] [PATCH v2 " Andreas Rheinhardt
2024-04-01 18:41 ` [FFmpeg-devel] [PATCH 1/5] avcodec/ppc/hpeldsp_altivec: Fix left-shift of negative number Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=GV1P250MB0737690AA71271D549996E1F8F3A2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git