From af69ee396347c4612c180771b4e5a911e1859a87 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 23 Aug 2023 22:23:53 -0700 Subject: [PATCH 1/5] `enum BlockLevel`: Make a `u8`. --- src/decode.rs | 6 +++--- src/levels.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index aaa15dfec..dcb994b50 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -4247,7 +4247,7 @@ unsafe fn decode_sb( } } else { let b = &mut *(f.frame_thread.b).offset(t.by as isize * f.b4_stride + t.bx as isize); - bp = if b.bl as BlockLevel == bl { + bp = if b.bl == bl { b.bp as BlockPartition } else { PARTITION_SPLIT @@ -4552,7 +4552,7 @@ unsafe fn decode_sb( } } else { let b = &mut *(f.frame_thread.b).offset(t.by as isize * f.b4_stride + t.bx as isize); - is_split = b.bl as BlockLevel != bl; + is_split = b.bl != bl; } assert!(bl < BL_8X8); @@ -4606,7 +4606,7 @@ unsafe fn decode_sb( } } else { let b = &mut *(f.frame_thread.b).offset(t.by as isize * f.b4_stride + t.bx as isize); - is_split = b.bl as BlockLevel != bl; + is_split = b.bl != bl; } assert!(bl < BL_8X8); diff --git a/src/levels.rs b/src/levels.rs index 5e8d48293..85ef0563c 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -18,7 +18,7 @@ pub const TX_32X32: TxfmSize = 3; pub const TX_16X16: TxfmSize = 2; pub const TX_8X8: TxfmSize = 1; pub const TX_4X4: TxfmSize = 0; -pub type BlockLevel = libc::c_uint; +pub type BlockLevel = u8; pub const N_BL_LEVELS: BlockLevel = 5; pub const BL_8X8: BlockLevel = 4; pub const BL_16X16: BlockLevel = 3; From 311b52cf02db48d67b71532d0890e67e7c7c41ef Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 23 Aug 2023 22:25:06 -0700 Subject: [PATCH 2/5] `enum BlockPartition`: Make a `u8`. --- src/decode.rs | 6 +----- src/levels.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index dcb994b50..34f4fedff 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -4247,11 +4247,7 @@ unsafe fn decode_sb( } } else { let b = &mut *(f.frame_thread.b).offset(t.by as isize * f.b4_stride + t.bx as isize); - bp = if b.bl == bl { - b.bp as BlockPartition - } else { - PARTITION_SPLIT - }; + bp = if b.bl == bl { b.bp } else { PARTITION_SPLIT }; } let b = &dav1d_block_sizes[bl as usize][bp as usize]; diff --git a/src/levels.rs b/src/levels.rs index 85ef0563c..e6fcfb2d8 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -96,7 +96,7 @@ pub const II_SMOOTH_PRED: InterIntraPredMode = 3; pub const II_HOR_PRED: InterIntraPredMode = 2; pub const II_VERT_PRED: InterIntraPredMode = 1; pub const II_DC_PRED: InterIntraPredMode = 0; -pub type BlockPartition = libc::c_uint; +pub type BlockPartition = u8; pub const N_SUB8X8_PARTITIONS: BlockPartition = 4; pub const N_PARTITIONS: BlockPartition = 10; pub const PARTITION_V4: BlockPartition = 9; From 074ecc2c6278e362c677e79fd7d7ad538892ac81 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 23 Aug 2023 22:28:11 -0700 Subject: [PATCH 3/5] `enum BlockSize`: Make a `u8`. --- src/decode.rs | 138 ++++++++++---------------------------------------- src/levels.rs | 2 +- 2 files changed, 28 insertions(+), 112 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index 34f4fedff..20b8e2f07 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -4254,28 +4254,28 @@ unsafe fn decode_sb( match bp { PARTITION_NONE => { let node = &*node; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_NONE, node.o) != 0 { + if decode_b(t, bl, b[0], PARTITION_NONE, node.o) != 0 { return -1; } } PARTITION_H => { let node = &*node; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_H, node.h[0]) != 0 { + if decode_b(t, bl, b[0], PARTITION_H, node.h[0]) != 0 { return -1; } t.by += hsz; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_H, node.h[1]) != 0 { + if decode_b(t, bl, b[0], PARTITION_H, node.h[1]) != 0 { return -1; } t.by -= hsz; } PARTITION_V => { let node = &*node; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_V, node.v[0]) != 0 { + if decode_b(t, bl, b[0], PARTITION_V, node.v[0]) != 0 { return -1; } t.bx += hsz; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_V, node.v[1]) != 0 { + if decode_b(t, bl, b[0], PARTITION_V, node.v[1]) != 0 { return -1; } t.bx -= hsz; @@ -4336,73 +4336,31 @@ unsafe fn decode_sb( } PARTITION_T_TOP_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b( - t, - bl, - b[0] as BlockSize, - PARTITION_T_TOP_SPLIT, - branch.tts[0], - ) != 0 - { + if decode_b(t, bl, b[0], PARTITION_T_TOP_SPLIT, branch.tts[0]) != 0 { return -1; } t.bx += hsz; - if decode_b( - t, - bl, - b[0] as BlockSize, - PARTITION_T_TOP_SPLIT, - branch.tts[1], - ) != 0 - { + if decode_b(t, bl, b[0], PARTITION_T_TOP_SPLIT, branch.tts[1]) != 0 { return -1; } t.bx -= hsz; t.by += hsz; - if decode_b( - t, - bl, - b[1] as BlockSize, - PARTITION_T_TOP_SPLIT, - branch.tts[2], - ) != 0 - { + if decode_b(t, bl, b[1], PARTITION_T_TOP_SPLIT, branch.tts[2]) != 0 { return -1; } t.by -= hsz; } PARTITION_T_BOTTOM_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b( - t, - bl, - b[0] as BlockSize, - PARTITION_T_BOTTOM_SPLIT, - branch.tbs[0], - ) != 0 - { + if decode_b(t, bl, b[0], PARTITION_T_BOTTOM_SPLIT, branch.tbs[0]) != 0 { return -1; } t.by += hsz; - if decode_b( - t, - bl, - b[1] as BlockSize, - PARTITION_T_BOTTOM_SPLIT, - branch.tbs[1], - ) != 0 - { + if decode_b(t, bl, b[1], PARTITION_T_BOTTOM_SPLIT, branch.tbs[1]) != 0 { return -1; } t.bx += hsz; - if decode_b( - t, - bl, - b[1] as BlockSize, - PARTITION_T_BOTTOM_SPLIT, - branch.tbs[2], - ) != 0 - { + if decode_b(t, bl, b[1], PARTITION_T_BOTTOM_SPLIT, branch.tbs[2]) != 0 { return -1; } t.bx -= hsz; @@ -4410,73 +4368,31 @@ unsafe fn decode_sb( } PARTITION_T_LEFT_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b( - t, - bl, - b[0] as BlockSize, - PARTITION_T_LEFT_SPLIT, - branch.tls[0], - ) != 0 - { + if decode_b(t, bl, b[0], PARTITION_T_LEFT_SPLIT, branch.tls[0]) != 0 { return -1; } t.by += hsz; - if decode_b( - t, - bl, - b[0] as BlockSize, - PARTITION_T_LEFT_SPLIT, - branch.tls[1], - ) != 0 - { + if decode_b(t, bl, b[0], PARTITION_T_LEFT_SPLIT, branch.tls[1]) != 0 { return -1; } t.by -= hsz; t.bx += hsz; - if decode_b( - t, - bl, - b[1] as BlockSize, - PARTITION_T_LEFT_SPLIT, - branch.tls[2], - ) != 0 - { + if decode_b(t, bl, b[1], PARTITION_T_LEFT_SPLIT, branch.tls[2]) != 0 { return -1; } t.bx -= hsz; } PARTITION_T_RIGHT_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b( - t, - bl, - b[0] as BlockSize, - PARTITION_T_RIGHT_SPLIT, - branch.trs[0], - ) != 0 - { + if decode_b(t, bl, b[0], PARTITION_T_RIGHT_SPLIT, branch.trs[0]) != 0 { return -1; } t.bx += hsz; - if decode_b( - t, - bl, - b[1] as BlockSize, - PARTITION_T_RIGHT_SPLIT, - branch.trs[1], - ) != 0 - { + if decode_b(t, bl, b[1], PARTITION_T_RIGHT_SPLIT, branch.trs[1]) != 0 { return -1; } t.by += hsz; - if decode_b( - t, - bl, - b[1] as BlockSize, - PARTITION_T_RIGHT_SPLIT, - (*branch).trs[2], - ) != 0 - { + if decode_b(t, bl, b[1], PARTITION_T_RIGHT_SPLIT, (*branch).trs[2]) != 0 { return -1; } t.by -= hsz; @@ -4484,20 +4400,20 @@ unsafe fn decode_sb( } PARTITION_H4 => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0] as BlockSize, PARTITION_H4, branch.h4[0]) != 0 { + if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[0]) != 0 { return -1; } t.by += hsz >> 1; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_H4, branch.h4[1]) != 0 { + if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[1]) != 0 { return -1; } t.by += hsz >> 1; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_H4, branch.h4[2]) != 0 { + if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[2]) != 0 { return -1; } t.by += hsz >> 1; if t.by < f.bh { - if decode_b(t, bl, b[0] as BlockSize, PARTITION_H4, branch.h4[3]) != 0 { + if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[3]) != 0 { return -1; } } @@ -4505,20 +4421,20 @@ unsafe fn decode_sb( } PARTITION_V4 => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0] as BlockSize, PARTITION_V4, branch.v4[0]) != 0 { + if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[0]) != 0 { return -1; } t.bx += hsz >> 1; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_V4, branch.v4[1]) != 0 { + if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[1]) != 0 { return -1; } t.bx += hsz >> 1; - if decode_b(t, bl, b[0] as BlockSize, PARTITION_V4, branch.v4[2]) != 0 { + if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[2]) != 0 { return -1; } t.bx += hsz >> 1; if t.bx < f.bw { - if decode_b(t, bl, b[0] as BlockSize, PARTITION_V4, branch.v4[3]) != 0 { + if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[3]) != 0 { return -1; } } @@ -4568,7 +4484,7 @@ unsafe fn decode_sb( if decode_b( t, bl, - dav1d_block_sizes[bl as usize][PARTITION_H as usize][0] as BlockSize, + dav1d_block_sizes[bl as usize][PARTITION_H as usize][0], PARTITION_H, (*node).h[0], ) != 0 @@ -4622,7 +4538,7 @@ unsafe fn decode_sb( if decode_b( t, bl, - dav1d_block_sizes[bl as usize][PARTITION_V as usize][0] as BlockSize, + dav1d_block_sizes[bl as usize][PARTITION_V as usize][0], PARTITION_V, (*node).v[0], ) != 0 diff --git a/src/levels.rs b/src/levels.rs index e6fcfb2d8..437ed794f 100644 --- a/src/levels.rs +++ b/src/levels.rs @@ -109,7 +109,7 @@ pub const PARTITION_SPLIT: BlockPartition = 3; pub const PARTITION_V: BlockPartition = 2; pub const PARTITION_H: BlockPartition = 1; pub const PARTITION_NONE: BlockPartition = 0; -pub type BlockSize = libc::c_uint; +pub type BlockSize = u8; pub const N_BS_SIZES: BlockSize = 22; pub const BS_4x4: BlockSize = 21; pub const BS_4x8: BlockSize = 20; From 57b2dbdc175e54dab61968a6711391948e8f2b35 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 23 Aug 2023 22:29:18 -0700 Subject: [PATCH 4/5] `static dav1d_block_sizes`: Make the array of `BlockSize` instead of `u8` now that `BlockSize` is `u8`. --- src/tables.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tables.rs b/src/tables.rs index 3ff848505..256e892f5 100644 --- a/src/tables.rs +++ b/src/tables.rs @@ -30,6 +30,7 @@ use crate::src::levels::BS_8x16; use crate::src::levels::BS_8x32; use crate::src::levels::BS_8x4; use crate::src::levels::BS_8x8; +use crate::src::levels::BlockSize; use crate::src::levels::ADST_ADST; use crate::src::levels::ADST_DCT; use crate::src::levels::ADST_FLIPADST; @@ -119,7 +120,7 @@ pub static dav1d_al_part_ctx: [[[u8; 10]; 5]; 2] = [ ], ]; -pub static dav1d_block_sizes: [[[u8; 2]; 10]; 5] = [ +pub static dav1d_block_sizes: [[[BlockSize; 2]; 10]; 5] = [ [ [BS_128x128 as u8, 0], [BS_128x64 as u8, 0], From c5d8df4e5919c4620296b59f53923d559649afbe Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 23 Aug 2023 22:38:21 -0700 Subject: [PATCH 5/5] `fn decode_sb`: Prefer `bp` over the explicit `BlockPartition` variant when they're the same. --- src/decode.rs | 66 +++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/decode.rs b/src/decode.rs index 20b8e2f07..cce28f018 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -4254,28 +4254,28 @@ unsafe fn decode_sb( match bp { PARTITION_NONE => { let node = &*node; - if decode_b(t, bl, b[0], PARTITION_NONE, node.o) != 0 { + if decode_b(t, bl, b[0], bp, node.o) != 0 { return -1; } } PARTITION_H => { let node = &*node; - if decode_b(t, bl, b[0], PARTITION_H, node.h[0]) != 0 { + if decode_b(t, bl, b[0], bp, node.h[0]) != 0 { return -1; } t.by += hsz; - if decode_b(t, bl, b[0], PARTITION_H, node.h[1]) != 0 { + if decode_b(t, bl, b[0], bp, node.h[1]) != 0 { return -1; } t.by -= hsz; } PARTITION_V => { let node = &*node; - if decode_b(t, bl, b[0], PARTITION_V, node.v[0]) != 0 { + if decode_b(t, bl, b[0], bp, node.v[0]) != 0 { return -1; } t.bx += hsz; - if decode_b(t, bl, b[0], PARTITION_V, node.v[1]) != 0 { + if decode_b(t, bl, b[0], bp, node.v[1]) != 0 { return -1; } t.bx -= hsz; @@ -4284,22 +4284,22 @@ unsafe fn decode_sb( if bl == BL_8X8 { let tip = &*(node as *const EdgeTip); assert!(hsz == 1); - if decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip.split[0]) != 0 { + if decode_b(t, bl, BS_4x4, bp, tip.split[0]) != 0 { return -1; } let tl_filter = t.tl_4x4_filter; t.bx += 1; - if decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip.split[1]) != 0 { + if decode_b(t, bl, BS_4x4, bp, tip.split[1]) != 0 { return -1; } t.bx -= 1; t.by += 1; - if decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip.split[2]) != 0 { + if decode_b(t, bl, BS_4x4, bp, tip.split[2]) != 0 { return -1; } t.bx += 1; t.tl_4x4_filter = tl_filter; - if decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip.split[3]) != 0 { + if decode_b(t, bl, BS_4x4, bp, tip.split[3]) != 0 { return -1; } t.bx -= 1; @@ -4336,31 +4336,31 @@ unsafe fn decode_sb( } PARTITION_T_TOP_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0], PARTITION_T_TOP_SPLIT, branch.tts[0]) != 0 { + if decode_b(t, bl, b[0], bp, branch.tts[0]) != 0 { return -1; } t.bx += hsz; - if decode_b(t, bl, b[0], PARTITION_T_TOP_SPLIT, branch.tts[1]) != 0 { + if decode_b(t, bl, b[0], bp, branch.tts[1]) != 0 { return -1; } t.bx -= hsz; t.by += hsz; - if decode_b(t, bl, b[1], PARTITION_T_TOP_SPLIT, branch.tts[2]) != 0 { + if decode_b(t, bl, b[1], bp, branch.tts[2]) != 0 { return -1; } t.by -= hsz; } PARTITION_T_BOTTOM_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0], PARTITION_T_BOTTOM_SPLIT, branch.tbs[0]) != 0 { + if decode_b(t, bl, b[0], bp, branch.tbs[0]) != 0 { return -1; } t.by += hsz; - if decode_b(t, bl, b[1], PARTITION_T_BOTTOM_SPLIT, branch.tbs[1]) != 0 { + if decode_b(t, bl, b[1], bp, branch.tbs[1]) != 0 { return -1; } t.bx += hsz; - if decode_b(t, bl, b[1], PARTITION_T_BOTTOM_SPLIT, branch.tbs[2]) != 0 { + if decode_b(t, bl, b[1], bp, branch.tbs[2]) != 0 { return -1; } t.bx -= hsz; @@ -4368,31 +4368,31 @@ unsafe fn decode_sb( } PARTITION_T_LEFT_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0], PARTITION_T_LEFT_SPLIT, branch.tls[0]) != 0 { + if decode_b(t, bl, b[0], bp, branch.tls[0]) != 0 { return -1; } t.by += hsz; - if decode_b(t, bl, b[0], PARTITION_T_LEFT_SPLIT, branch.tls[1]) != 0 { + if decode_b(t, bl, b[0], bp, branch.tls[1]) != 0 { return -1; } t.by -= hsz; t.bx += hsz; - if decode_b(t, bl, b[1], PARTITION_T_LEFT_SPLIT, branch.tls[2]) != 0 { + if decode_b(t, bl, b[1], bp, branch.tls[2]) != 0 { return -1; } t.bx -= hsz; } PARTITION_T_RIGHT_SPLIT => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0], PARTITION_T_RIGHT_SPLIT, branch.trs[0]) != 0 { + if decode_b(t, bl, b[0], bp, branch.trs[0]) != 0 { return -1; } t.bx += hsz; - if decode_b(t, bl, b[1], PARTITION_T_RIGHT_SPLIT, branch.trs[1]) != 0 { + if decode_b(t, bl, b[1], bp, branch.trs[1]) != 0 { return -1; } t.by += hsz; - if decode_b(t, bl, b[1], PARTITION_T_RIGHT_SPLIT, (*branch).trs[2]) != 0 { + if decode_b(t, bl, b[1], bp, (*branch).trs[2]) != 0 { return -1; } t.by -= hsz; @@ -4400,20 +4400,20 @@ unsafe fn decode_sb( } PARTITION_H4 => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[0]) != 0 { + if decode_b(t, bl, b[0], bp, branch.h4[0]) != 0 { return -1; } t.by += hsz >> 1; - if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[1]) != 0 { + if decode_b(t, bl, b[0], bp, branch.h4[1]) != 0 { return -1; } t.by += hsz >> 1; - if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[2]) != 0 { + if decode_b(t, bl, b[0], bp, branch.h4[2]) != 0 { return -1; } t.by += hsz >> 1; if t.by < f.bh { - if decode_b(t, bl, b[0], PARTITION_H4, branch.h4[3]) != 0 { + if decode_b(t, bl, b[0], bp, branch.h4[3]) != 0 { return -1; } } @@ -4421,20 +4421,20 @@ unsafe fn decode_sb( } PARTITION_V4 => { let branch = &*(node as *const EdgeBranch); - if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[0]) != 0 { + if decode_b(t, bl, b[0], bp, branch.v4[0]) != 0 { return -1; } t.bx += hsz >> 1; - if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[1]) != 0 { + if decode_b(t, bl, b[0], bp, branch.v4[1]) != 0 { return -1; } t.bx += hsz >> 1; - if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[2]) != 0 { + if decode_b(t, bl, b[0], bp, branch.v4[2]) != 0 { return -1; } t.bx += hsz >> 1; if t.bx < f.bw { - if decode_b(t, bl, b[0], PARTITION_V4, branch.v4[3]) != 0 { + if decode_b(t, bl, b[0], bp, branch.v4[3]) != 0 { return -1; } } @@ -4484,8 +4484,8 @@ unsafe fn decode_sb( if decode_b( t, bl, - dav1d_block_sizes[bl as usize][PARTITION_H as usize][0], - PARTITION_H, + dav1d_block_sizes[bl as usize][bp as usize][0], + bp, (*node).h[0], ) != 0 { @@ -4538,8 +4538,8 @@ unsafe fn decode_sb( if decode_b( t, bl, - dav1d_block_sizes[bl as usize][PARTITION_V as usize][0], - PARTITION_V, + dav1d_block_sizes[bl as usize][bp as usize][0], + bp, (*node).v[0], ) != 0 {