aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/prefetch.zig
blob: 2d3a04e66ea00c3ad69d86336ef2b10840e2cefe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const builtin = @import("builtin");
const std = @import("std");

test "@prefetch()" {
    if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
    if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isLoongArch()) return error.SkipZigTest; // https://github.com/llvm/llvm-project/issues/134624

    var a: [2]u32 = .{ 42, 42 };
    var a_len = a.len;
    _ = &a_len;

    @prefetch(&a, .{});

    @prefetch(&a[0], .{ .rw = .read, .locality = 3, .cache = .data });
    @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .data });
    @prefetch(a[0..].ptr, .{ .rw = .read, .locality = 1, .cache = .data });
    @prefetch(a[0..a_len], .{ .rw = .read, .locality = 0, .cache = .data });

    @prefetch(&a[0], .{ .rw = .write, .locality = 3, .cache = .data });
    @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .data });
    @prefetch(a[0..].ptr, .{ .rw = .write, .locality = 1, .cache = .data });
    @prefetch(a[0..a_len], .{ .rw = .write, .locality = 0, .cache = .data });

    @prefetch(&a[0], .{ .rw = .read, .locality = 3, .cache = .instruction });
    @prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .instruction });
    @prefetch(a[0..].ptr, .{ .rw = .read, .locality = 1, .cache = .instruction });
    @prefetch(a[0..a_len], .{ .rw = .read, .locality = 0, .cache = .instruction });

    @prefetch(&a[0], .{ .rw = .write, .locality = 3, .cache = .instruction });
    @prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .instruction });
    @prefetch(a[0..].ptr, .{ .rw = .write, .locality = 1, .cache = .instruction });
    @prefetch(a[0..a_len], .{ .rw = .write, .locality = 0, .cache = .instruction });
}