Skip to content

Commit

Permalink
fn decode_sb: Make Block* enums u8s to avoid back-and-forth c…
Browse files Browse the repository at this point in the history
…onversion (#385)
  • Loading branch information
kkysen authored Aug 24, 2023
2 parents 7591504 + c5d8df4 commit 1a6c503
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 128 deletions.
160 changes: 36 additions & 124 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4247,39 +4247,35 @@ 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 {
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];

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], bp, 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], bp, 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], bp, 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], bp, 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], bp, node.v[1]) != 0 {
return -1;
}
t.bx -= hsz;
Expand All @@ -4288,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;
Expand Down Expand Up @@ -4340,189 +4336,105 @@ 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], bp, 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], bp, 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], 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] as BlockSize,
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] as BlockSize,
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] as BlockSize,
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;
t.by -= hsz;
}
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], bp, 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], bp, 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], 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] as BlockSize,
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] as BlockSize,
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] as BlockSize,
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;
t.bx -= hsz;
}
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], bp, 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], bp, 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], bp, 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], bp, branch.h4[3]) != 0 {
return -1;
}
}
t.by -= hsz * 3 >> 1;
}
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], bp, 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], bp, 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], bp, 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], bp, branch.v4[3]) != 0 {
return -1;
}
}
Expand Down Expand Up @@ -4552,7 +4464,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);
Expand All @@ -4572,8 +4484,8 @@ unsafe fn decode_sb(
if decode_b(
t,
bl,
dav1d_block_sizes[bl as usize][PARTITION_H as usize][0] as BlockSize,
PARTITION_H,
dav1d_block_sizes[bl as usize][bp as usize][0],
bp,
(*node).h[0],
) != 0
{
Expand Down Expand Up @@ -4606,7 +4518,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);
Expand All @@ -4626,8 +4538,8 @@ unsafe fn decode_sb(
if decode_b(
t,
bl,
dav1d_block_sizes[bl as usize][PARTITION_V as usize][0] as BlockSize,
PARTITION_V,
dav1d_block_sizes[bl as usize][bp as usize][0],
bp,
(*node).v[0],
) != 0
{
Expand Down
6 changes: 3 additions & 3 deletions src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 1a6c503

Please sign in to comment.