tiny.simd.AlignedAllocation
Defined in aligned.
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
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |