diff options
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 3f3147ca80..42778bccf8 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1278,6 +1278,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .error_name => try airErrorName(f, inst), .splat => try airSplat(f, inst), .vector_init => try airVectorInit(f, inst), + .prefetch => try airPrefetch(f, inst), .int_to_float, .float_to_int, @@ -3089,6 +3090,25 @@ fn airVectorInit(f: *Function, inst: Air.Inst.Index) !CValue { return f.fail("TODO: C backend: implement airVectorInit", .{}); } +fn airPrefetch(f: *Function, inst: Air.Inst.Index) !CValue { + const prefetch = f.air.instructions.items(.data)[inst].prefetch; + switch (prefetch.cache) { + .data => {}, + // The available prefetch intrinsics do not accept a cache argument; only + // address, rw, and locality. So unless the cache is data, we do not lower + // this instruction. + .instruction => return CValue.none, + } + const ptr = try f.resolveInst(prefetch.ptr); + const writer = f.object.writer(); + try writer.writeAll("zig_prefetch("); + try f.writeCValue(writer, ptr); + try writer.print(", {d}, {d});\n", .{ + @enumToInt(prefetch.rw), prefetch.locality, + }); + return CValue.none; +} + fn toMemoryOrder(order: std.builtin.AtomicOrder) [:0]const u8 { return switch (order) { .Unordered => "memory_order_relaxed", |
