mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
parent
26b03ca823
commit
c429bb5d2f
3 changed files with 21 additions and 15 deletions
|
|
@ -6951,8 +6951,10 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
|
|||
}
|
||||
|
||||
fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
const mod = f.object.dg.module;
|
||||
const prefetch = f.air.instructions.items(.data)[inst].prefetch;
|
||||
|
||||
const ptr_ty = f.typeOf(prefetch.ptr);
|
||||
const ptr = try f.resolveInst(prefetch.ptr);
|
||||
try reap(f, inst, &.{prefetch.ptr});
|
||||
|
||||
|
|
@ -6960,6 +6962,9 @@ fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue {
|
|||
switch (prefetch.cache) {
|
||||
.data => {
|
||||
try writer.writeAll("zig_prefetch(");
|
||||
if (ptr_ty.isSlice(mod))
|
||||
try f.writeCValueMember(writer, ptr, .{ .identifier = "ptr" })
|
||||
else
|
||||
try f.writeCValue(writer, ptr, .FunctionArgument);
|
||||
try writer.print(", {d}, {d});\n", .{ @intFromEnum(prefetch.rw), prefetch.locality });
|
||||
},
|
||||
|
|
|
|||
|
|
@ -9837,7 +9837,7 @@ pub const FuncGen = struct {
|
|||
}
|
||||
|
||||
_ = try self.wip.callIntrinsic(.normal, .none, .prefetch, &.{.ptr}, &.{
|
||||
try self.resolveInst(prefetch.ptr),
|
||||
try self.sliceOrArrayPtr(try self.resolveInst(prefetch.ptr), self.typeOf(prefetch.ptr)),
|
||||
try o.builder.intValue(.i32, prefetch.rw),
|
||||
try o.builder.intValue(.i32, prefetch.locality),
|
||||
try o.builder.intValue(.i32, prefetch.cache),
|
||||
|
|
|
|||
|
|
@ -4,27 +4,28 @@ const std = @import("std");
|
|||
test "@prefetch()" {
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
|
||||
var a: u32 = 42;
|
||||
var a: [2]u32 = .{ 42, 42 };
|
||||
var a_len = a.len;
|
||||
|
||||
@prefetch(&a, .{});
|
||||
|
||||
@prefetch(&a, .{ .rw = .read, .locality = 3, .cache = .data });
|
||||
@prefetch(&a[0], .{ .rw = .read, .locality = 3, .cache = .data });
|
||||
@prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .data });
|
||||
@prefetch(&a, .{ .rw = .read, .locality = 1, .cache = .data });
|
||||
@prefetch(&a, .{ .rw = .read, .locality = 0, .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, .{ .rw = .write, .locality = 3, .cache = .data });
|
||||
@prefetch(&a[0], .{ .rw = .write, .locality = 3, .cache = .data });
|
||||
@prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .data });
|
||||
@prefetch(&a, .{ .rw = .write, .locality = 1, .cache = .data });
|
||||
@prefetch(&a, .{ .rw = .write, .locality = 0, .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, .{ .rw = .read, .locality = 3, .cache = .instruction });
|
||||
@prefetch(&a[0], .{ .rw = .read, .locality = 3, .cache = .instruction });
|
||||
@prefetch(&a, .{ .rw = .read, .locality = 2, .cache = .instruction });
|
||||
@prefetch(&a, .{ .rw = .read, .locality = 1, .cache = .instruction });
|
||||
@prefetch(&a, .{ .rw = .read, .locality = 0, .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, .{ .rw = .write, .locality = 3, .cache = .instruction });
|
||||
@prefetch(&a[0], .{ .rw = .write, .locality = 3, .cache = .instruction });
|
||||
@prefetch(&a, .{ .rw = .write, .locality = 2, .cache = .instruction });
|
||||
@prefetch(&a, .{ .rw = .write, .locality = 1, .cache = .instruction });
|
||||
@prefetch(&a, .{ .rw = .write, .locality = 0, .cache = .instruction });
|
||||
@prefetch(a[0..].ptr, .{ .rw = .write, .locality = 1, .cache = .instruction });
|
||||
@prefetch(a[0..a_len], .{ .rw = .write, .locality = 0, .cache = .instruction });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue