Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Enum

Alignment

Public Enum
std.mem.Alignment
pub const Alignment = enum(math.Log2Int(usize))

Stored as a power-of-two.

Functions

pub fn toByteUnits(a: Alignment) usize
pub fn fromByteUnits(n: usize) Alignment
pub fn fromByteUnitsOptional(maybe_n: ?usize) ?Alignment
pub inline fn of(comptime T: type) Alignment
pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order
pub fn compare(lhs: Alignment, op: std.math.CompareOperator, rhs: Alignment) bool
pub fn max(lhs: Alignment, rhs: Alignment) Alignment
pub fn min(lhs: Alignment, rhs: Alignment) Alignment
pub fn forward(a: Alignment, address: usize) usize

Return next address with this alignment.

pub fn backward(a: Alignment, address: usize) usize

Return previous address with this alignment.

pub fn check(a: Alignment, address: usize) bool

Return whether address is aligned to this amount.

File

mem.zig:25
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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) << @backingInt(a);
    }

    pub fn fromByteUnits(n: usize) Alignment {
        assert(std.math.isPowerOfTwo(n));
        return @fromBackingInt(@intCast(@ctz(n)));
    }

    pub fn fromByteUnitsOptional(maybe_n: ?usize) ?Alignment {
        return if (maybe_n) |n| .fromByteUnits(n) else null;
    }

    pub inline fn of(comptime T: type) Alignment {
        return comptime fromByteUnits(@alignOf(T));
    }

    pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order {
        return std.math.order(@backingInt(lhs), @backingInt(rhs));
    }

    pub fn compare(lhs: Alignment, op: std.math.CompareOperator, rhs: Alignment) bool {
        return std.math.compare(@backingInt(lhs), op, @backingInt(rhs));
    }

    pub fn max(lhs: Alignment, rhs: Alignment) Alignment {
        return @fromBackingInt(@intCast(@max(@backingInt(lhs), @backingInt(rhs))));
    }

    pub fn min(lhs: Alignment, rhs: Alignment) Alignment {
        return @fromBackingInt(@intCast(@min(@backingInt(lhs), @backingInt(rhs))));
    }

    /// Return next address with this alignment.
    pub fn forward(a: Alignment, address: usize) usize {
        const x = (@as(usize, 1) << @backingInt(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) << @backingInt(a)) - 1;
        return address & ~x;
    }

    /// Return whether address is aligned to this amount.
    pub fn check(a: Alignment, address: usize) bool {
        return @ctz(address) >= @backingInt(a);
    }
}