Skip to main content

AlignedVec

Struct AlignedVec 

Source
pub struct AlignedVec<T>
where T: Copy + Default,
{ /* private fields */ }
Expand description

64-byte aligned vector for SIMD operations (spec §5.2)

Provides memory-aligned storage for efficient SIMD access. Alignment is guaranteed at 64 bytes for AVX-512 compatibility.

§Memory Layout

  • Data is stored in a Vec with additional alignment tracking
  • Capacity is rounded up to 64-byte boundaries
  • Provides raw pointers for FFI/SIMD operations

§Example

use aprender::native::AlignedVec;

let vec = AlignedVec::from_slice(&[1.0_f32, 2.0, 3.0, 4.0]);
assert!(vec.is_aligned());
assert_eq!(vec.len(), 4);

// Access as slice
assert_eq!(vec.as_slice(), &[1.0, 2.0, 3.0, 4.0]);

Implementations§

Source§

impl<T> AlignedVec<T>
where T: Copy + Default,

Source

pub fn with_capacity(capacity: usize) -> AlignedVec<T>

Create with capacity rounded up to 64-byte boundary

Source

pub fn from_slice(slice: &[T]) -> AlignedVec<T>

Create from a slice, copying data into aligned storage

Source

pub fn zeros(len: usize) -> AlignedVec<T>

Create filled with zeros

Source

pub const fn len(&self) -> usize

Logical length

Source

pub const fn is_empty(&self) -> bool

Check if empty

Source

pub const fn capacity(&self) -> usize

Aligned capacity

Source

pub fn as_ptr(&self) -> *const T

Get raw pointer (guaranteed 64-byte aligned for f32/f64)

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Get mutable raw pointer

Source

pub fn as_slice(&self) -> &[T]

Get as slice

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Get as mutable slice

Source

pub fn is_aligned(&self) -> bool

Check alignment (for debugging)

Note: Standard Rust Vec does not guarantee 64-byte alignment. This function checks if the data pointer happens to be aligned. For true SIMD-aligned allocations, use a specialized allocator.

Source

pub fn size_bytes(&self) -> usize

Size in bytes (actual data, not capacity)

Source

pub fn push(&mut self, value: T)

Push a value (may reallocate if at capacity)

Source

pub fn clear(&mut self)

Clear the vector (keeps capacity)

Source

pub fn get(&self, index: usize) -> Option<&T>

Get element by index

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Get mutable element by index

Source

pub fn set(&mut self, index: usize, value: T) -> bool

Set element by index

Trait Implementations§

Source§

impl<T> Clone for AlignedVec<T>
where T: Clone + Copy + Default,

Source§

fn clone(&self) -> AlignedVec<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for AlignedVec<T>
where T: Debug + Copy + Default,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for AlignedVec<T>
where T: Copy + Default,

Source§

fn default() -> AlignedVec<T>

Returns the “default value” for a type. Read more
Source§

impl<T> FromIterator<T> for AlignedVec<T>
where T: Copy + Default,

Source§

fn from_iter<I>(iter: I) -> AlignedVec<T>
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
Source§

impl<T> Index<usize> for AlignedVec<T>
where T: Copy + Default,

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &<AlignedVec<T> as Index<usize>>::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for AlignedVec<T>
where T: Copy + Default,

Source§

fn index_mut( &mut self, index: usize, ) -> &mut <AlignedVec<T> as Index<usize>>::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> PartialEq for AlignedVec<T>
where T: Copy + Default + PartialEq,

Source§

fn eq(&self, other: &AlignedVec<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AlignedVec<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for AlignedVec<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for AlignedVec<T>
where Vec<T>: Send,

§

impl<T> Sync for AlignedVec<T>
where Vec<T>: Sync,

§

impl<T> Unpin for AlignedVec<T>
where Vec<T>: Unpin,

§

impl<T> UnsafeUnpin for AlignedVec<T>
where Vec<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for AlignedVec<T>
where Vec<T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,