Skip to content

Commit

Permalink
Rav1dTaskContext::a: Make into offset and give BlockContext inter…
Browse files Browse the repository at this point in the history
…ior mutability (#958)
  • Loading branch information
randomPoison authored Apr 23, 2024
1 parent 7b800d8 commit c9e134f
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 355 deletions.
12 changes: 12 additions & 0 deletions src/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ macro_rules! def_align {
}

impl AlignedByteChunk for $name<[u8; $align]> {}

unsafe impl<V, const N: usize> AsMutPtr for $name<[V; N]> {
type Target = V;

unsafe fn as_mut_ptr(ptr: *mut Self) -> *mut V {
(*ptr).0.as_mut_ptr()
}

fn len(&self) -> usize {
N
}
}
};
}

Expand Down
16 changes: 16 additions & 0 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
//! * is far simpler than the `case_set*` implementation, consisting of a `match` and array writes
//!
//! [`BlockContext`]: crate::src::env::BlockContext
use crate::src::disjoint_mut::AsMutPtr;
use crate::src::disjoint_mut::DisjointMut;
use std::iter::zip;

/// Perform a `memset` optimized for lengths that are small powers of 2.
Expand Down Expand Up @@ -83,6 +85,20 @@ impl<const UP_TO: usize, const WITH_DEFAULT: bool> CaseSetter<UP_TO, WITH_DEFAUL
pub fn set<T: Clone + Copy>(&self, buf: &mut [T], val: T) {
small_memset::<T, UP_TO, WITH_DEFAULT>(&mut buf[self.offset..][..self.len], val);
}

/// # Safety
///
/// Caller must ensure that no elements of the written range are concurrently
/// borrowed (immutably or mutably) at all during the call to `set_disjoint`.
#[inline]
pub unsafe fn set_disjoint<T, V>(&self, buf: &DisjointMut<T>, val: V)
where
T: AsMutPtr<Target = V>,
V: Clone + Copy,
{
let mut buf = unsafe { buf.index_mut(self.offset..self.offset + self.len) };
small_memset::<V, UP_TO, WITH_DEFAULT>(&mut *buf, val);
}
}

/// The entrypoint to the [`CaseSet`] API.
Expand Down
317 changes: 171 additions & 146 deletions src/decode.rs

Large diffs are not rendered by default.

Loading

0 comments on commit c9e134f

Please sign in to comment.