enum Alignment [src]

Stored as a power-of-two.

Fields

@"1" = 0
@"2" = 1
@"4" = 2
@"8" = 3
@"16" = 4
@"32" = 5
@"64" = 6
_

Members

Source

pub const Alignment = enum(math.Log2Int(usize)) { @"1" = 0, @"2" = 1, @"4" = 2, @"8" = 3, @"16" = 4, @"32" = 5, @"64" = 6, _, pub fn toByteUnits(a: Alignment) usize { return @as(usize, 1) << @intFromEnum(a); } pub fn fromByteUnits(n: usize) Alignment { assert(std.math.isPowerOfTwo(n)); return @enumFromInt(@ctz(n)); } pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order { return std.math.order(@intFromEnum(lhs), @intFromEnum(rhs)); } pub fn compare(lhs: Alignment, op: std.math.CompareOperator, rhs: Alignment) bool { return std.math.compare(@intFromEnum(lhs), op, @intFromEnum(rhs)); } pub fn max(lhs: Alignment, rhs: Alignment) Alignment { return @enumFromInt(@max(@intFromEnum(lhs), @intFromEnum(rhs))); } pub fn min(lhs: Alignment, rhs: Alignment) Alignment { return @enumFromInt(@min(@intFromEnum(lhs), @intFromEnum(rhs))); } /// Return next address with this alignment. pub fn forward(a: Alignment, address: usize) usize { const x = (@as(usize, 1) << @intFromEnum(a)) - 1; return (address + x) & ~x; } /// Return previous address with this alignment. pub fn backward(a: Alignment, address: usize) usize { const x = (@as(usize, 1) << @intFromEnum(a)) - 1; return address & ~x; } /// Return whether address is aligned to this amount. pub fn check(a: Alignment, address: usize) bool { return @ctz(address) >= @intFromEnum(a); } }