* [FFmpeg-devel] [PATCH 2/4] avcodec/vvc/vvc_ps: Use union for luts to avoid unaligned accesses
2024-02-18 19:29 [FFmpeg-devel] [PATCH 1/4] avcodec/vvc/vvc_ps: Check before access Andreas Rheinhardt
@ 2024-02-18 19:31 ` Andreas Rheinhardt
2024-02-18 19:31 ` [FFmpeg-devel] [PATCH 3/4] avcodec/vvc/vvcdsp: Remove pointless wrappers Andreas Rheinhardt
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Andreas Rheinhardt @ 2024-02-18 19:31 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
These arrays are currently accessed via uint16_t* pointers
although nothing guarantees their alignment. Furthermore,
this is problematic wrt the effective-type rules.
Fix this by using a union of arrays of uint8_t and uint16_t.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vvc/vvc_filter.c | 2 +-
libavcodec/vvc/vvc_filter_template.c | 4 ++--
libavcodec/vvc/vvc_inter.c | 4 ++--
libavcodec/vvc/vvc_ps.c | 8 ++++----
libavcodec/vvc/vvc_ps.h | 7 ++++---
libavcodec/vvc/vvcdsp.h | 2 +-
6 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/libavcodec/vvc/vvc_filter.c b/libavcodec/vvc/vvc_filter.c
index df77e443f6..5fa711c9e0 100644
--- a/libavcodec/vvc/vvc_filter.c
+++ b/libavcodec/vvc/vvc_filter.c
@@ -1328,5 +1328,5 @@ void ff_vvc_lmcs_filter(const VVCLocalContext *lc, const int x, const int y)
const int height = FFMIN(fc->ps.pps->height - y, ctb_size);
uint8_t *data = fc->frame->data[LUMA] + y * fc->frame->linesize[LUMA] + (x << fc->ps.sps->pixel_shift);
if (sc->sh.r->sh_lmcs_used_flag)
- fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, fc->ps.lmcs.inv_lut);
+ fc->vvcdsp.lmcs.filter(data, fc->frame->linesize[LUMA], width, height, &fc->ps.lmcs.inv_lut);
}
diff --git a/libavcodec/vvc/vvc_filter_template.c b/libavcodec/vvc/vvc_filter_template.c
index b7eaef5125..9b3a0e46f7 100644
--- a/libavcodec/vvc/vvc_filter_template.c
+++ b/libavcodec/vvc/vvc_filter_template.c
@@ -22,9 +22,9 @@
#include "libavcodec/h26x/h2656_sao_template.c"
-static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const uint8_t *_lut)
+static void FUNC(lmcs_filter_luma)(uint8_t *_dst, ptrdiff_t dst_stride, const int width, const int height, const void *_lut)
{
- const pixel *lut = (const pixel *)_lut;
+ const pixel *lut = _lut;
pixel *dst = (pixel*)_dst;
dst_stride /= sizeof(pixel);
diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c
index e05f3db93e..6c9c8a7165 100644
--- a/libavcodec/vvc/vvc_inter.c
+++ b/libavcodec/vvc/vvc_inter.c
@@ -571,7 +571,7 @@ static void pred_regular_luma(VVCLocalContext *lc, const int hf_idx, const int v
const int intra_weight = ciip_derive_intra_weight(lc, x0, y0, sbw, sbh);
fc->vvcdsp.intra.intra_pred(lc, x0, y0, sbw, sbh, 0);
if (sc->sh.r->sh_lmcs_used_flag)
- fc->vvcdsp.lmcs.filter(inter, inter_stride, sbw, sbh, fc->ps.lmcs.fwd_lut);
+ fc->vvcdsp.lmcs.filter(inter, inter_stride, sbw, sbh, &fc->ps.lmcs.fwd_lut);
fc->vvcdsp.inter.put_ciip(dst, dst_stride, sbw, sbh, inter, inter_stride, intra_weight);
}
@@ -887,7 +887,7 @@ static void predict_inter(VVCLocalContext *lc)
if (lc->sc->sh.r->sh_lmcs_used_flag && !cu->ciip_flag) {
uint8_t* dst0 = POS(0, cu->x0, cu->y0);
- fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, fc->ps.lmcs.fwd_lut);
+ fc->vvcdsp.lmcs.filter(dst0, fc->frame->linesize[LUMA], cu->cb_width, cu->cb_height, &fc->ps.lmcs.fwd_lut);
}
}
diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c
index 376027ed81..e6e46d2039 100644
--- a/libavcodec/vvc/vvc_ps.c
+++ b/libavcodec/vvc/vvc_ps.c
@@ -642,9 +642,9 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw
const uint16_t fwd_sample = lmcs_derive_lut_sample(sample, lmcs->pivot,
input_pivot, scale_coeff, idx_y, max);
if (bit_depth > 8)
- ((uint16_t *)lmcs->fwd_lut)[sample] = fwd_sample;
+ lmcs->fwd_lut.u16[sample] = fwd_sample;
else
- lmcs->fwd_lut[sample] = fwd_sample;
+ lmcs->fwd_lut.u8 [sample] = fwd_sample;
}
@@ -659,9 +659,9 @@ static int lmcs_derive_lut(VVCLMCS *lmcs, const H266RawAPS *rlmcs, const H266Raw
inv_scale_coeff, i, max);
if (bit_depth > 8)
- ((uint16_t *)lmcs->inv_lut)[sample] = inv_sample;
+ lmcs->inv_lut.u16[sample] = inv_sample;
else
- lmcs->inv_lut[sample] = inv_sample;
+ lmcs->inv_lut.u8 [sample] = inv_sample;
}
return 0;
diff --git a/libavcodec/vvc/vvc_ps.h b/libavcodec/vvc/vvc_ps.h
index 3d3aa061f5..5adf3f3453 100644
--- a/libavcodec/vvc/vvc_ps.h
+++ b/libavcodec/vvc/vvc_ps.h
@@ -191,9 +191,10 @@ typedef struct VVCLMCS {
uint8_t min_bin_idx;
uint8_t max_bin_idx;
- //*2 for high depth
- uint8_t fwd_lut[LMCS_MAX_LUT_SIZE * 2];
- uint8_t inv_lut[LMCS_MAX_LUT_SIZE * 2];
+ union {
+ uint8_t u8[LMCS_MAX_LUT_SIZE];
+ uint16_t u16[LMCS_MAX_LUT_SIZE]; ///< for high bit-depth
+ } fwd_lut, inv_lut;
uint16_t pivot[LMCS_MAX_BIN_SIZE + 1];
uint16_t chroma_scale_coeff[LMCS_MAX_BIN_SIZE];
diff --git a/libavcodec/vvc/vvcdsp.h b/libavcodec/vvc/vvcdsp.h
index 6f59e73654..f4fb3cb7d7 100644
--- a/libavcodec/vvc/vvcdsp.h
+++ b/libavcodec/vvc/vvcdsp.h
@@ -119,7 +119,7 @@ typedef struct VVCItxDSPContext {
} VVCItxDSPContext;
typedef struct VVCLMCSDSPContext {
- void (*filter)(uint8_t *dst, ptrdiff_t dst_stride, int width, int height, const uint8_t *lut);
+ void (*filter)(uint8_t *dst, ptrdiff_t dst_stride, int width, int height, const void *lut);
} VVCLMCSDSPContext;
typedef struct VVCLFDSPContext {
--
2.34.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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH 4/4] avcodec: Remove superfluous '; ' outside of functions
2024-02-18 19:29 [FFmpeg-devel] [PATCH 1/4] avcodec/vvc/vvc_ps: Check before access Andreas Rheinhardt
2024-02-18 19:31 ` [FFmpeg-devel] [PATCH 2/4] avcodec/vvc/vvc_ps: Use union for luts to avoid unaligned accesses Andreas Rheinhardt
2024-02-18 19:31 ` [FFmpeg-devel] [PATCH 3/4] avcodec/vvc/vvcdsp: Remove pointless wrappers Andreas Rheinhardt
@ 2024-02-18 19:31 ` Andreas Rheinhardt
2024-02-19 23:26 ` [FFmpeg-devel] [PATCH 1/4] avcodec/vvc/vvc_ps: Check before access Andreas Rheinhardt
3 siblings, 0 replies; 6+ messages in thread
From: Andreas Rheinhardt @ 2024-02-18 19:31 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Inside a function an extra ';' is a null statement;
but outside of it it simply must not happen.
So remove them.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vvc/vvc_itx_1d.c | 2 +-
libavcodec/x86/h26x/h2656dsp.h | 2 +-
libavcodec/x86/hevcdsp_init.c | 78 ++++++++++++++++----------------
libavcodec/x86/vvc/vvcdsp_init.c | 24 +++++-----
4 files changed, 53 insertions(+), 53 deletions(-)
diff --git a/libavcodec/vvc/vvc_itx_1d.c b/libavcodec/vvc/vvc_itx_1d.c
index 01a50aad25..cb076f680f 100644
--- a/libavcodec/vvc/vvc_itx_1d.c
+++ b/libavcodec/vvc/vvc_itx_1d.c
@@ -639,7 +639,7 @@ void ff_vvc_inv_dct2_64(int *coeffs, const ptrdiff_t stride, const size_t nz)
coeffs[61 * stride] = E[2] - O[2];
coeffs[62 * stride] = E[1] - O[1];
coeffs[63 * stride] = E[0] - O[0];
-};
+}
static void matrix_mul(int *coeffs, const ptrdiff_t stride, const int8_t* matrix, const int size, const size_t nz)
{
diff --git a/libavcodec/x86/h26x/h2656dsp.h b/libavcodec/x86/h26x/h2656dsp.h
index e31aae6b0d..0ea08b6a20 100644
--- a/libavcodec/x86/h26x/h2656dsp.h
+++ b/libavcodec/x86/h26x/h2656dsp.h
@@ -31,7 +31,7 @@
#define H2656_PEL_PROTOTYPE(name, D, opt) \
void ff_h2656_put_ ## name ## _ ## D ## _##opt(int16_t *dst, ptrdiff_t dststride, const uint8_t *_src, ptrdiff_t _srcstride, int height, const int8_t *hf, const int8_t *vf, int width); \
-void ff_h2656_put_uni_ ## name ## _ ## D ## _##opt(uint8_t *_dst, ptrdiff_t _dststride, const uint8_t *_src, ptrdiff_t _srcstride, int height, const int8_t *hf, const int8_t *vf, int width); \
+void ff_h2656_put_uni_ ## name ## _ ## D ## _##opt(uint8_t *_dst, ptrdiff_t _dststride, const uint8_t *_src, ptrdiff_t _srcstride, int height, const int8_t *hf, const int8_t *vf, int width) \
#define H2656_MC_8TAP_PROTOTYPES(fname, bitd, opt) \
H2656_PEL_PROTOTYPE(fname##4, bitd, opt); \
diff --git a/libavcodec/x86/hevcdsp_init.c b/libavcodec/x86/hevcdsp_init.c
index 3d4e41754d..f5bc342cd5 100644
--- a/libavcodec/x86/hevcdsp_init.c
+++ b/libavcodec/x86/hevcdsp_init.c
@@ -123,17 +123,17 @@ void ff_hevc_put_hevc_uni_ ## a ## _ ## depth ## _##opt(uint8_t *dst, ptrdiff_t
#define FW_DIR_HV(npel, n, w, depth, opt) \
FW_PUT_FUNCS(npel, npel ## _hv##w, n ## tap_hv##w, depth, opt)
-FW_PEL(4, 8, sse4);
-FW_PEL(6, 8, sse4);
-FW_PEL(8, 8, sse4);
-FW_PEL(12, 8, sse4);
-FW_PEL(16, 8, sse4);
-FW_PEL(4, 10, sse4);
-FW_PEL(6, 10, sse4);
-FW_PEL(8, 10, sse4);
-FW_PEL(4, 12, sse4);
-FW_PEL(6, 12, sse4);
-FW_PEL(8, 12, sse4);
+FW_PEL(4, 8, sse4)
+FW_PEL(6, 8, sse4)
+FW_PEL(8, 8, sse4)
+FW_PEL(12, 8, sse4)
+FW_PEL(16, 8, sse4)
+FW_PEL(4, 10, sse4)
+FW_PEL(6, 10, sse4)
+FW_PEL(8, 10, sse4)
+FW_PEL(4, 12, sse4)
+FW_PEL(6, 12, sse4)
+FW_PEL(8, 12, sse4)
#define FW_EPEL(w, depth, opt) FW_DIR(epel, 4, w, depth, opt)
#define FW_EPEL_HV(w, depth, opt) FW_DIR_HV(epel, 4, w, depth, opt)
@@ -141,18 +141,18 @@ FW_PEL(8, 12, sse4);
FW_EPEL(w, depth, opt) \
FW_EPEL_HV(w, depth, opt)
-FW_EPEL(12, 8, sse4);
+FW_EPEL(12, 8, sse4)
-FW_EPEL_FUNCS(4, 8, sse4);
-FW_EPEL_FUNCS(6, 8, sse4);
-FW_EPEL_FUNCS(8, 8, sse4);
-FW_EPEL_FUNCS(16, 8, sse4);
-FW_EPEL_FUNCS(4, 10, sse4);
-FW_EPEL_FUNCS(6, 10, sse4);
-FW_EPEL_FUNCS(8, 10, sse4);
-FW_EPEL_FUNCS(4, 12, sse4);
-FW_EPEL_FUNCS(6, 12, sse4);
-FW_EPEL_FUNCS(8, 12, sse4);
+FW_EPEL_FUNCS(4, 8, sse4)
+FW_EPEL_FUNCS(6, 8, sse4)
+FW_EPEL_FUNCS(8, 8, sse4)
+FW_EPEL_FUNCS(16, 8, sse4)
+FW_EPEL_FUNCS(4, 10, sse4)
+FW_EPEL_FUNCS(6, 10, sse4)
+FW_EPEL_FUNCS(8, 10, sse4)
+FW_EPEL_FUNCS(4, 12, sse4)
+FW_EPEL_FUNCS(6, 12, sse4)
+FW_EPEL_FUNCS(8, 12, sse4)
#define FW_QPEL(w, depth, opt) FW_DIR(qpel, 8, w, depth, opt)
#define FW_QPEL_HV(w, depth, opt) FW_DIR_HV(qpel, 8, w, depth, opt)
@@ -160,31 +160,31 @@ FW_EPEL_FUNCS(8, 12, sse4);
FW_QPEL(w, depth, opt) \
FW_QPEL_HV(w, depth, opt)
-FW_QPEL(12, 8, sse4);
-FW_QPEL(16, 8, sse4);
+FW_QPEL(12, 8, sse4)
+FW_QPEL(16, 8, sse4)
-FW_QPEL_FUNCS(4, 8, sse4);
-FW_QPEL_FUNCS(8, 8, sse4);
-FW_QPEL_FUNCS(4, 10, sse4);
-FW_QPEL_FUNCS(8, 10, sse4);
-FW_QPEL_FUNCS(4, 12, sse4);
-FW_QPEL_FUNCS(8, 12, sse4);
+FW_QPEL_FUNCS(4, 8, sse4)
+FW_QPEL_FUNCS(8, 8, sse4)
+FW_QPEL_FUNCS(4, 10, sse4)
+FW_QPEL_FUNCS(8, 10, sse4)
+FW_QPEL_FUNCS(4, 12, sse4)
+FW_QPEL_FUNCS(8, 12, sse4)
#if HAVE_AVX2_EXTERNAL
-FW_PEL(32, 8, avx2);
-FW_PUT(pel, pel_pixels16, pixels16, 10, avx2);
+FW_PEL(32, 8, avx2)
+FW_PUT(pel, pel_pixels16, pixels16, 10, avx2)
-FW_EPEL(32, 8, avx2);
-FW_EPEL(16, 10, avx2);
+FW_EPEL(32, 8, avx2)
+FW_EPEL(16, 10, avx2)
-FW_EPEL_HV(32, 8, avx2);
-FW_EPEL_HV(16, 10, avx2);
+FW_EPEL_HV(32, 8, avx2)
+FW_EPEL_HV(16, 10, avx2)
-FW_QPEL(32, 8, avx2);
-FW_QPEL(16, 10, avx2);
+FW_QPEL(32, 8, avx2)
+FW_QPEL(16, 10, avx2)
-FW_QPEL_HV(16, 10, avx2);
+FW_QPEL_HV(16, 10, avx2)
#endif
#endif
diff --git a/libavcodec/x86/vvc/vvcdsp_init.c b/libavcodec/x86/vvc/vvcdsp_init.c
index 8ee4074350..0d2c683f0f 100644
--- a/libavcodec/x86/vvc/vvcdsp_init.c
+++ b/libavcodec/x86/vvc/vvcdsp_init.c
@@ -40,12 +40,12 @@ static void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const uint
}
#define FW_PUT_TAP(fname, bitd, opt ) \
- FW_PUT(fname##4, bitd, opt ); \
- FW_PUT(fname##8, bitd, opt ); \
- FW_PUT(fname##16, bitd, opt ); \
- FW_PUT(fname##32, bitd, opt ); \
- FW_PUT(fname##64, bitd, opt ); \
- FW_PUT(fname##128, bitd, opt ); \
+ FW_PUT(fname##4, bitd, opt ) \
+ FW_PUT(fname##8, bitd, opt ) \
+ FW_PUT(fname##16, bitd, opt ) \
+ FW_PUT(fname##32, bitd, opt ) \
+ FW_PUT(fname##64, bitd, opt ) \
+ FW_PUT(fname##128, bitd, opt ) \
#define FW_PUT_4TAP(fname, bitd, opt) \
FW_PUT(fname ## 2, bitd, opt) \
@@ -66,9 +66,9 @@ static void ff_vvc_put_ ## name ## _ ## depth ## _##opt(int16_t *dst, const uint
FW_PUT_4TAP_SSE4(bitd) \
FW_PUT_8TAP_SSE4(bitd)
-FW_PUT_SSE4( 8);
-FW_PUT_SSE4(10);
-FW_PUT_SSE4(12);
+FW_PUT_SSE4( 8)
+FW_PUT_SSE4(10)
+FW_PUT_SSE4(12)
#define FW_PUT_TAP_AVX2(n, bitd) \
FW_PUT(n ## tap_h32, bitd, avx2) \
@@ -100,10 +100,10 @@ FW_PUT_AVX2(12)
#define FW_PUT_16BPC_AVX2(bitd) \
FW_PUT(pixels16, bitd, avx2) \
FW_PUT_TAP_16BPC_AVX2(4, bitd) \
- FW_PUT_TAP_16BPC_AVX2(8, bitd);
+ FW_PUT_TAP_16BPC_AVX2(8, bitd)
-FW_PUT_16BPC_AVX2(10);
-FW_PUT_16BPC_AVX2(12);
+FW_PUT_16BPC_AVX2(10)
+FW_PUT_16BPC_AVX2(12)
#define PEL_LINK(dst, C, W, idx1, idx2, name, D, opt) \
dst[C][W][idx1][idx2] = ff_vvc_put_## name ## _ ## D ## _##opt; \
--
2.34.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".
^ permalink raw reply [flat|nested] 6+ messages in thread