Skip to documentation
SLOP

tiny.simd.AlignedAllocation

Reference tiny.simd AlignedAllocation

Defined in aligned.

Called byCallsalignedArrayalignedVectortest sourcelib.simd.src.alignedtest: Highway aligned allocation cycl...test sourcelib.simd.src.alignedtest: Highway aligned allocation pres...test sourcelib.simd.src.alignedtest: Highway typed allocation reject...test sourcelib.simd.src.alignedtest: aligned owners reject invalid g...private sourcelib.simd.src.alignednextAlignedOffsetalignedAllocation
Static calls · unresolved targets: 1 · external targets: 2.

Source

Source: lib/simd/src/aligned.zig:51

zig
pub fn Allocation(comptime T: type) type {    if (@sizeOf(T) == 0) @compileError("aligned allocations require nonzero-sized values");    if (@alignOf(T) > allocation_alignment) {        @compileError("value alignment exceeds the Highway allocation alignment");    }    return struct {        allocation: []u8,        values: []align(allocation_alignment) T,        const Self = @This();        pub fn init(allocator: std.mem.Allocator, count: usize) Error!Self {            if (count == 0) return error.EmptyAllocation;            const payload_bytes = std.math.mul(usize, count, @sizeOf(T)) catch                return error.AllocationSizeOverflow;            if (payload_bytes >= std.math.maxInt(usize) / 2) {                return error.AllocationSizeOverflow;            }            const offset = nextAlignedOffset();            const prefix_bytes = std.math.add(usize, alias_bytes, offset) catch                return error.AllocationSizeOverflow;            const allocated_bytes = std.math.add(usize, prefix_bytes, payload_bytes) catch                return error.AllocationSizeOverflow;            const allocation = try allocator.alloc(u8, allocated_bytes);            errdefer allocator.free(allocation);            const aligned_base = std.mem.alignBackward(                usize,                @intFromPtr(allocation.ptr) + alias_bytes,                alias_bytes,            );            const payload_address = aligned_base + offset;            std.debug.assert(payload_address >= @intFromPtr(allocation.ptr));            std.debug.assert(payload_address + payload_bytes <=                @intFromPtr(allocation.ptr) + allocation.len);            std.debug.assert(payload_address % allocation_alignment == 0);            const payload_offset = payload_address - @intFromPtr(allocation.ptr);            const byte_pointer: [*]align(allocation_alignment) u8 =                @alignCast(allocation.ptr + payload_offset);            const pointer: [*]align(allocation_alignment) T = @ptrCast(byte_pointer);            return .{                .allocation = allocation,                .values = pointer[0..count],            };        }        pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {            allocator.free(self.allocation);            self.* = undefined;        }        pub fn slice(self: *Self) []T {            return self.values;        }        pub fn constSlice(self: *const Self) []const T {            return self.values;        }    };}

Source: lib/simd/src/root.zig:249

zig
pub const AlignedAllocation = aligned.Allocation;

Audit

Definitions1
Public names2
Members0
Version26.7.0
Revisiondaab053ee433