Skip to content

Commit 8575ff9

Browse files
authored
Update to latest nightly, nightly-2023-05-10 (#249)
There are some newly stabilized things that we want to use to replace C versions. `ilog2` from #184 and other cleanups was one of them, and there were some other ones I came across as well. Also, `#![feature(let_chains)]` became unstable again as it was implemented incorrectly, so I've removed their few uses and manually desugared them or used `Option::filter` instead. Also, upgrading the toolchain seems to cause test failures now because of stricter checks. Raw pointer dereferences are now checked for alignment (in debug builds it seems), and that's now uncovering further errors. Unaligned references are UB in Rust, so we need to fix these. Tracked in #250. This is another great reason to upgrade the toolchain, as this is a really useful check. Update: #251 has been merged into this PR, fixing the crashes explained above.
2 parents 495dabb + 9142244 commit 8575ff9

File tree

11 files changed

+79
-133
lines changed

11 files changed

+79
-133
lines changed

rust-toolchain.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[toolchain]
2-
channel = "nightly-2022-08-08"
2+
channel = "nightly-2023-05-10"
3+
targets = [
4+
"x86_64-unknown-linux-gnu",
5+
"i686-unknown-linux-gnu",
6+
"aarch64-unknown-linux-gnu",
7+
"armv7-unknown-linux-gnueabihf",
8+
]
39
components = ["rustfmt"]

src/cdef_apply_tmpl_16.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ pub unsafe extern "C" fn dav1d_cdef_brow_16bpc(
929929
layout,
930930
);
931931
}
932-
let mut lr_bak: [[[[pixel; 2]; 8]; 3]; 2] = [[[[0; 2]; 8]; 3]; 2];
932+
let mut lr_bak: Align16<[[[[pixel; 2]; 8]; 3]; 2]> = Align16([[[[0; 2]; 8]; 3]; 2]);
933933
let mut iptrs: [*mut pixel; 3] = [ptrs[0], ptrs[1], ptrs[2]];
934934
edges = ::core::mem::transmute::<libc::c_uint, CdefEdgeFlags>(
935935
edges as libc::c_uint & !(CDEF_HAVE_LEFT as libc::c_int) as libc::c_uint,

src/cdef_apply_tmpl_8.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ pub unsafe extern "C" fn dav1d_cdef_brow_8bpc(
902902
layout,
903903
);
904904
}
905-
let mut lr_bak: [[[[pixel; 2]; 8]; 3]; 2] = [[[[0; 2]; 8]; 3]; 2];
905+
let mut lr_bak: Align16<[[[[pixel; 2]; 8]; 3]; 2]> = Align16([[[[0; 2]; 8]; 3]; 2]);
906906
let mut iptrs: [*mut pixel; 3] = [ptrs[0], ptrs[1], ptrs[2]];
907907
edges = ::core::mem::transmute::<libc::c_uint, CdefEdgeFlags>(
908908
edges as libc::c_uint & !(CDEF_HAVE_LEFT as libc::c_int) as libc::c_uint,

src/cdef_tmpl_8.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ unsafe extern "C" fn cdef_filter_4x4_neon(
845845
damping: libc::c_int,
846846
edges: CdefEdgeFlags,
847847
) {
848-
let mut tmp_buf = [0; 104];
849-
let mut tmp = tmp_buf.as_mut_ptr().offset(2 * 8).offset(8);
848+
let mut tmp_buf = Align16([0; 104]);
849+
let mut tmp = tmp_buf.0.as_mut_ptr().offset(2 * 8).offset(8);
850850
dav1d_cdef_padding4_8bpc_neon(tmp, dst, stride, left, top, bottom, 4, edges);
851851
dav1d_cdef_filter4_8bpc_neon(
852852
dst,
@@ -875,8 +875,8 @@ unsafe extern "C" fn cdef_filter_4x8_neon(
875875
damping: libc::c_int,
876876
edges: CdefEdgeFlags,
877877
) {
878-
let mut tmp_buf = [0; 104];
879-
let mut tmp = tmp_buf.as_mut_ptr().offset(2 * 8).offset(8);
878+
let mut tmp_buf = Align16([0; 104]);
879+
let mut tmp = tmp_buf.0.as_mut_ptr().offset(2 * 8).offset(8);
880880
dav1d_cdef_padding4_8bpc_neon(tmp, dst, stride, left, top, bottom, 8, edges);
881881
dav1d_cdef_filter4_8bpc_neon(
882882
dst,

src/decode.rs

Lines changed: 36 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,14 +3335,13 @@ unsafe fn decode_b(
33353335
if b.skip_mode != 0 {
33363336
b.intra = 0;
33373337
} else if is_inter_or_switch(frame_hdr) {
3338-
if let Some(seg) = seg && (seg.r#ref >= 0 || seg.globalmv != 0) {
3338+
if let Some(seg) = seg.filter(|seg| seg.r#ref >= 0 || seg.globalmv != 0) {
33393339
b.intra = (seg.r#ref == 0) as uint8_t;
33403340
} else {
33413341
let ictx = get_intra_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left);
3342-
b.intra = (!dav1d_msac_decode_bool_adapt(
3343-
&mut ts.msac,
3344-
&mut ts.cdf.m.intra[ictx.into()],
3345-
)) as uint8_t;
3342+
b.intra =
3343+
(!dav1d_msac_decode_bool_adapt(&mut ts.msac, &mut ts.cdf.m.intra[ictx.into()]))
3344+
as uint8_t;
33463345

33473346
if DEBUG_BLOCK_INFO(f, t) {
33483347
println!("Post-intra[{}]: r={}", b.intra, ts.msac.rng);
@@ -4266,139 +4265,64 @@ unsafe fn decode_b(
42664265
}
42674266
} else {
42684267
b.c2rust_unnamed.c2rust_unnamed_0.comp_type = COMP_INTER_NONE as libc::c_int as uint8_t;
4269-
if let Some(seg) = seg && seg.r#ref > 0 {
4270-
b
4271-
.c2rust_unnamed
4272-
.c2rust_unnamed_0
4273-
.r#ref[0 as libc::c_int
4274-
as usize] = seg.r#ref as i8 - 1;
4275-
} else if let Some(seg) = seg && (seg.globalmv != 0 || seg.skip != 0) {
4276-
b
4277-
.c2rust_unnamed
4278-
.c2rust_unnamed_0
4279-
.r#ref[0] = 0 as libc::c_int as int8_t;
4268+
if let Some(seg) = seg.filter(|seg| seg.r#ref > 0) {
4269+
b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0 as libc::c_int as usize] =
4270+
seg.r#ref as i8 - 1;
4271+
} else if let Some(_) = seg.filter(|seg| seg.globalmv != 0 || seg.skip != 0) {
4272+
b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] = 0 as libc::c_int as int8_t;
42804273
} else {
4281-
let ctx1_0 = av1_get_ref_ctx(
4282-
&*t.a,
4283-
&t.l,
4284-
by4,
4285-
bx4,
4286-
have_top,
4287-
have_left,
4288-
);
4274+
let ctx1_0 = av1_get_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left);
42894275
if dav1d_msac_decode_bool_adapt(
42904276
&mut ts.msac,
42914277
&mut ts.cdf.m.r#ref[0][ctx1_0 as usize],
4292-
)
4293-
{
4294-
let ctx2_1 = av1_get_bwd_ref_ctx(
4295-
&*t.a,
4296-
&t.l,
4297-
by4,
4298-
bx4,
4299-
have_top,
4300-
have_left,
4301-
);
4278+
) {
4279+
let ctx2_1 = av1_get_bwd_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left);
43024280
if dav1d_msac_decode_bool_adapt(
43034281
&mut ts.msac,
43044282
&mut ts.cdf.m.r#ref[1][ctx2_1 as usize],
4305-
)
4306-
{
4307-
b
4308-
.c2rust_unnamed
4309-
.c2rust_unnamed_0
4310-
.r#ref[0 as libc::c_int
4311-
as usize] = 6 as libc::c_int as int8_t;
4283+
) {
4284+
b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0 as libc::c_int as usize] =
4285+
6 as libc::c_int as int8_t;
43124286
} else {
4313-
let ctx3_0 = av1_get_bwd_ref_1_ctx(
4314-
&*t.a,
4315-
&t.l,
4316-
by4,
4317-
bx4,
4318-
have_top,
4319-
have_left,
4320-
);
4321-
b
4322-
.c2rust_unnamed
4323-
.c2rust_unnamed_0
4324-
.r#ref[0 as libc::c_int
4325-
as usize] = (4 as libc::c_int as libc::c_uint)
4326-
.wrapping_add(
4287+
let ctx3_0 =
4288+
av1_get_bwd_ref_1_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left);
4289+
b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0 as libc::c_int as usize] =
4290+
(4 as libc::c_int as libc::c_uint).wrapping_add(
43274291
dav1d_msac_decode_bool_adapt(
43284292
&mut ts.msac,
4329-
&mut ts
4330-
.cdf
4331-
.m
4332-
.r#ref[5][ctx3_0 as usize],
4293+
&mut ts.cdf.m.r#ref[5][ctx3_0 as usize],
43334294
) as libc::c_uint,
43344295
) as int8_t;
43354296
}
43364297
} else {
4337-
let ctx2_2 = av1_get_fwd_ref_ctx(
4338-
&*t.a,
4339-
&t.l,
4340-
by4,
4341-
bx4,
4342-
have_top,
4343-
have_left,
4344-
);
4298+
let ctx2_2 = av1_get_fwd_ref_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left);
43454299
if dav1d_msac_decode_bool_adapt(
43464300
&mut ts.msac,
43474301
&mut ts.cdf.m.r#ref[2][ctx2_2 as usize],
4348-
)
4349-
{
4350-
let ctx3_1 = av1_get_fwd_ref_2_ctx(
4351-
&*t.a,
4352-
&t.l,
4353-
by4,
4354-
bx4,
4355-
have_top,
4356-
have_left,
4357-
);
4358-
b
4359-
.c2rust_unnamed
4360-
.c2rust_unnamed_0
4361-
.r#ref[0 as libc::c_int
4362-
as usize] = (2 as libc::c_int as libc::c_uint)
4363-
.wrapping_add(
4302+
) {
4303+
let ctx3_1 =
4304+
av1_get_fwd_ref_2_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left);
4305+
b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0 as libc::c_int as usize] =
4306+
(2 as libc::c_int as libc::c_uint).wrapping_add(
43644307
dav1d_msac_decode_bool_adapt(
43654308
&mut ts.msac,
4366-
&mut ts
4367-
.cdf
4368-
.m
4369-
.r#ref[4][ctx3_1 as usize],
4309+
&mut ts.cdf.m.r#ref[4][ctx3_1 as usize],
43704310
) as libc::c_uint,
43714311
) as int8_t;
43724312
} else {
4373-
let ctx3_2 = av1_get_fwd_ref_1_ctx(
4374-
&*t.a,
4375-
&t.l,
4376-
by4,
4377-
bx4,
4378-
have_top,
4379-
have_left,
4380-
);
4381-
b
4382-
.c2rust_unnamed
4383-
.c2rust_unnamed_0
4384-
.r#ref[0 as libc::c_int
4385-
as usize] = dav1d_msac_decode_bool_adapt(
4386-
&mut ts.msac,
4387-
&mut ts
4388-
.cdf
4389-
.m
4390-
.r#ref[3][ctx3_2 as usize],
4391-
) as int8_t;
4313+
let ctx3_2 =
4314+
av1_get_fwd_ref_1_ctx(&*t.a, &t.l, by4, bx4, have_top, have_left);
4315+
b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0 as libc::c_int as usize] =
4316+
dav1d_msac_decode_bool_adapt(
4317+
&mut ts.msac,
4318+
&mut ts.cdf.m.r#ref[3][ctx3_2 as usize],
4319+
) as int8_t;
43924320
}
43934321
}
4394-
if DEBUG_BLOCK_INFO(f, t)
4395-
{
4322+
if DEBUG_BLOCK_INFO(f, t) {
43964323
printf(
43974324
b"Post-ref[%d]: r=%d\n\0" as *const u8 as *const libc::c_char,
4398-
b
4399-
.c2rust_unnamed
4400-
.c2rust_unnamed_0
4401-
.r#ref[0] as libc::c_int,
4325+
b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] as libc::c_int,
44024326
ts.msac.rng,
44034327
);
44044328
}

src/env.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,19 +578,21 @@ pub fn av1_get_uni_p1_ctx(
578578
if let Some(cnt) = cnt.get_mut((a.r#ref[0][xb4 as usize] - 1) as usize) {
579579
*cnt += 1;
580580
}
581-
if a.comp_type[xb4 as usize] != 0
582-
&& let Some(cnt) = cnt.get_mut((a.r#ref[1][xb4 as usize] - 1) as usize) {
583-
*cnt += 1;
581+
if a.comp_type[xb4 as usize] != 0 {
582+
if let Some(cnt) = cnt.get_mut((a.r#ref[1][xb4 as usize] - 1) as usize) {
583+
*cnt += 1;
584+
}
584585
}
585586
}
586587

587588
if have_left && l.intra[yb4 as usize] == 0 {
588589
if let Some(cnt) = cnt.get_mut((l.r#ref[0][yb4 as usize] - 1) as usize) {
589590
*cnt += 1;
590591
}
591-
if l.comp_type[yb4 as usize] != 0
592-
&& let Some(cnt) = cnt.get_mut((l.r#ref[1][yb4 as usize] - 1) as usize) {
593-
*cnt += 1;
592+
if l.comp_type[yb4 as usize] != 0 {
593+
if let Some(cnt) = cnt.get_mut((l.r#ref[1][yb4 as usize] - 1) as usize) {
594+
*cnt += 1;
595+
}
594596
}
595597
}
596598

src/fg_apply_tmpl_16.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::include::stddef::*;
22
use crate::include::stdint::*;
3-
use crate::src::align::{Align16, Align64};
3+
use crate::src::align::{Align1, Align16};
44
use ::libc;
55
extern "C" {
66
pub type Dav1dRef;
@@ -392,7 +392,7 @@ pub unsafe extern "C" fn dav1d_apply_grain_16bpc(
392392
in_0: *const Dav1dPicture,
393393
) {
394394
let mut grain_lut = Align16([[[0; 82]; 74]; 3]);
395-
let mut scaling = Align64([[0; 4096]; 3]);
395+
let mut scaling = Align1([[0; 4096]; 3]);
396396
let rows = (*out).p.h + 31 >> 5;
397397
dav1d_prep_grain_16bpc(
398398
dsp,

src/fg_apply_tmpl_8.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::include::stddef::*;
22
use crate::include::stdint::*;
3-
use crate::src::align::{Align16, Align64};
3+
use crate::src::align::Align16;
44
use ::libc;
5+
use cfg_if::cfg_if;
56
extern "C" {
67
pub type Dav1dRef;
78
fn memcpy(_: *mut libc::c_void, _: *const libc::c_void, _: libc::c_ulong) -> *mut libc::c_void;
@@ -348,7 +349,17 @@ pub unsafe extern "C" fn dav1d_apply_grain_8bpc(
348349
in_0: *const Dav1dPicture,
349350
) {
350351
let mut grain_lut = Align16([[[0; 82]; 74]; 3]);
351-
let mut scaling = Align64([[0; 256]; 3]);
352+
cfg_if! {
353+
if #[cfg(target_arch = "x86_64")] {
354+
use crate::src::align::Align64;
355+
356+
let mut scaling = Align64([[0; 256]; 3]);
357+
} else {
358+
use crate::src::align::Align1;
359+
360+
let mut scaling = Align1([[0; 256]; 3]);
361+
}
362+
}
352363
let rows = (*out).p.h + 31 >> 5;
353364
dav1d_prep_grain_8bpc(
354365
dsp,

src/lf_mask.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ use crate::include::common::intops::iclip;
6060
use crate::include::common::intops::imax;
6161
use crate::include::common::intops::imin;
6262
use crate::src::tables::TxfmInfo;
63+
64+
use crate::src::align::Align16;
65+
6366
unsafe extern "C" fn decomp_tx(
6467
txa: *mut [[[uint8_t; 32]; 32]; 2],
6568
from: RectTxfmSize,
@@ -324,15 +327,15 @@ unsafe extern "C" fn mask_edges_inter(
324327
&*dav1d_txfm_dimensions.as_ptr().offset(max_tx as isize) as *const TxfmInfo;
325328
let mut y = 0;
326329
let mut x = 0;
327-
let mut txa: [[[[uint8_t; 32]; 32]; 2]; 2] = [[[[0; 32]; 32]; 2]; 2];
330+
let mut txa: Align16<[[[[uint8_t; 32]; 32]; 2]; 2]> = Align16([[[[0; 32]; 32]; 2]; 2]);
328331
let mut y_off = 0;
329332
let mut y_0 = 0;
330333
while y_0 < h4 {
331334
let mut x_off = 0;
332335
let mut x_0 = 0;
333336
while x_0 < w4 {
334337
decomp_tx(
335-
&mut *(*(*(*txa.as_mut_ptr().offset(0)).as_mut_ptr().offset(0))
338+
&mut *(*(*(*txa.0.as_mut_ptr().offset(0)).as_mut_ptr().offset(0))
336339
.as_mut_ptr()
337340
.offset(y_0 as isize))
338341
.as_mut_ptr()

src/lr_apply_tmpl_16.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ unsafe extern "C" fn lr_sbrow(
869869
let max_unit_size = unit_size + half_unit_size;
870870
let row_y = y + (8 >> ss_ver) * (y != 0) as libc::c_int;
871871
let shift_hor = 7 - ss_hor;
872-
let mut pre_lr_border: [[[pixel; 4]; 136]; 2] = [[[0; 4]; 136]; 2];
872+
let mut pre_lr_border: Align16<[[[pixel; 4]; 136]; 2]> = Align16([[[0; 4]; 136]; 2]);
873873
let mut lr: [*const Av1RestorationUnit; 2] = [0 as *const Av1RestorationUnit; 2];
874874
let mut edges: LrEdgeFlags = ((if y > 0 {
875875
LR_HAVE_TOP as libc::c_int

0 commit comments

Comments
 (0)