[FFmpeg-cvslog] avcodec/asvenc,dvenc: Optimize unaligned checks away if possible
Andreas Rheinhardt
git at videolan.org
Sat May 31 02:53:00 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue May 27 21:46:06 2025 +0200| [23761c7acd5352e4452b24cb5fd97d6b12b9ae91] | committer: Andreas Rheinhardt
avcodec/asvenc,dvenc: Optimize unaligned checks away if possible
For certain arches (AARCH64, x86, generic) get_pixels and
get_pixels_unaligned always coincide for 8 bit input.
In these cases it is possible to avoid checks for unaligned
input in asvenc, dvenc.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=23761c7acd5352e4452b24cb5fd97d6b12b9ae91
---
libavcodec/asvenc.c | 7 ++++---
libavcodec/dvenc.c | 7 ++++---
libavcodec/pixblockdsp.h | 7 ++++++-
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index 159b070821..883edd0468 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -301,9 +301,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
if (ret < 0)
return ret;
- if ((uintptr_t)pict->data[0] & 7 || pict->linesize[0] & 7 ||
- (uintptr_t)pict->data[1] & 7 || pict->linesize[1] & 7 ||
- (uintptr_t)pict->data[2] & 7 || pict->linesize[2] & 7)
+ if (!PIXBLOCKDSP_8BPP_GET_PIXELS_SUPPORTS_UNALIGNED &&
+ ((uintptr_t)pict->data[0] & 7 || pict->linesize[0] & 7 ||
+ (uintptr_t)pict->data[1] & 7 || pict->linesize[1] & 7 ||
+ (uintptr_t)pict->data[2] & 7 || pict->linesize[2] & 7))
a->get_pixels = a->pdsp.get_pixels_unaligned;
else
a->get_pixels = a->pdsp.get_pixels;
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index b6764e9c2c..a477b84261 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -1200,9 +1200,10 @@ static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt,
DVEncContext *s = c->priv_data;
int ret;
- if ((uintptr_t)frame->data[0] & 7 || frame->linesize[0] & 7 ||
- (uintptr_t)frame->data[1] & 7 || frame->linesize[1] & 7 ||
- (uintptr_t)frame->data[2] & 7 || frame->linesize[2] & 7)
+ if (!PIXBLOCKDSP_8BPP_GET_PIXELS_SUPPORTS_UNALIGNED &&
+ ((uintptr_t)frame->data[0] & 7 || frame->linesize[0] & 7 ||
+ (uintptr_t)frame->data[1] & 7 || frame->linesize[1] & 7 ||
+ (uintptr_t)frame->data[2] & 7 || frame->linesize[2] & 7))
s->get_pixels = s->pdsp.get_pixels_unaligned;
else
s->get_pixels = s->pdsp.get_pixels;
diff --git a/libavcodec/pixblockdsp.h b/libavcodec/pixblockdsp.h
index 8d767b2fd3..d493d0e22b 100644
--- a/libavcodec/pixblockdsp.h
+++ b/libavcodec/pixblockdsp.h
@@ -22,9 +22,14 @@
#include <stddef.h>
#include <stdint.h>
+#define PIXBLOCKDSP_8BPP_GET_PIXELS_SUPPORTS_UNALIGNED \
+ !(ARCH_ARM || ARCH_MIPS || ARCH_PPC || ARCH_RISCV)
+
typedef struct PixblockDSPContext {
void (*get_pixels)(int16_t *restrict block /* align 16 */,
- const uint8_t *pixels /* align 8 for <= 8 bit, 16 otherwise */,
+ /* align 16 for > 8 bits; align 8 for <= 8 bits
+ * (or 1 if PIXBLOCKDSP_8BPP_GET_PIXELS_SUPPORTS_UNALIGNED is set) */
+ const uint8_t *pixels,
ptrdiff_t stride);
void (*get_pixels_unaligned)(int16_t *restrict block /* align 16 */,
const uint8_t *pixels,
More information about the ffmpeg-cvslog
mailing list