Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: @prefetch builtin #3600

Closed
data-man opened this issue Nov 5, 2019 · 4 comments
Closed

Proposal: @prefetch builtin #3600

data-man opened this issue Nov 5, 2019 · 4 comments
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@data-man
Copy link
Contributor

data-man commented Nov 5, 2019

Accepted Proposal


LLVM docs

@llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>, i32 <cache type>)

Possible syntax:

pub const FetchType = enum {
    Read,
    Write
}

pub const CacheType = enum {
    Instruction,
    Data
}

pub const Locality = enum {
    No,
    ...,
    ...,
    Extremely
}

@prefetch(comptime fetchType: FetchType,
          comptime cacheType: CacheType,
          comptime locality: Locality,
          ptr: var) noreturn

Related: #767

@shawnl
Copy link
Contributor

shawnl commented Nov 5, 2019

yeah I like it, except that isData should be a enum with .Data and .Instruction, and isWrite should also be an enum---these just mean that its easier to read the code.

@data-man
Copy link
Contributor Author

data-man commented Nov 5, 2019

Updated.

@andrewrk andrewrk added this to the 0.7.0 milestone Nov 14, 2019
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Nov 14, 2019
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
ifreund added a commit to tigerbeetle/tigerbeetle that referenced this issue Nov 26, 2021
Currently the stage1 zig compiler allows access to all LLVM instrinsics
if you know what you are doing: ziglang/zig#2291

This is however a bug, and we should use the @prefetch() builtin when
availible ziglang/zig#3600.
@andrewrk
Copy link
Member

To go into std.builtin:

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Prefetch = struct {
    rw: Rw = .read,
    /// 0 means no locality.
    /// 3 means extremely local, keep in cache.
    locality: u2 = 3,
    type: Type = .data,

    pub const Rw = enum { read, write };
    pub const Type = enum { instruction, data };
};

@prefetch(ptr: anytype, options: Prefetch) void

Any objections?

@andrewrk andrewrk added the accepted This proposal is planned. label Nov 27, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.9.0 Dec 11, 2021
@andrewrk
Copy link
Member

Landed in 97c0373 just in time for 0.9.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants