authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-02-15 17:28:15+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2024-02-15 17:28:15+03:30
log23b707565676fd650299e9808c1acf2bbb4d46f2
treeec2a00f8381784c7a8ad69f0f9c80d86669c5a7a
parent44c31194e3d192d0991866c91c5b44a54ebf8fb1

spirv: add capability to compile with x86_64 backend


1 files changed, 20 insertions(+), 12 deletions(-)

src/codegen/spirv/Module.zig+20-12
......@@ -8,6 +8,7 @@
88const Module = @This();
99
1010const std = @import("std");
11const builtin = @import("builtin");
1112const Allocator = std.mem.Allocator;
1213const assert = std.debug.assert;
1314
......@@ -471,19 +472,26 @@ pub fn flush(self: *Module, file: std.fs.File, target: std.Target) !void {
471472 self.sections.functions.toWords(),
472473 };
473474
474 var iovc_buffers: [buffers.len]std.os.iovec_const = undefined;
475 var file_size: u64 = 0;
476 for (&iovc_buffers, 0..) |*iovc, i| {
477 // Note, since spir-v supports both little and big endian we can ignore byte order here and
478 // just treat the words as a sequence of bytes.
479 const bytes = std.mem.sliceAsBytes(buffers[i]);
480 iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len };
481 file_size += bytes.len;
482 }
475 if (builtin.zig_backend == .stage2_x86_64) {
476 for (buffers) |buf| {
477 try file.writeAll(std.mem.sliceAsBytes(buf));
478 }
479 } else {
480 // miscompiles with x86_64 backend
481 var iovc_buffers: [buffers.len]std.os.iovec_const = undefined;
482 var file_size: u64 = 0;
483 for (&iovc_buffers, 0..) |*iovc, i| {
484 // Note, since spir-v supports both little and big endian we can ignore byte order here and
485 // just treat the words as a sequence of bytes.
486 const bytes = std.mem.sliceAsBytes(buffers[i]);
487 iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len };
488 file_size += bytes.len;
489 }
483490
484 try file.seekTo(0);
485 try file.setEndPos(file_size);
486 try file.pwritevAll(&iovc_buffers, 0);
491 try file.seekTo(0);
492 try file.setEndPos(file_size);
493 try file.pwritevAll(&iovc_buffers, 0);
494 }
487495}
488496
489497/// Merge the sections making up a function declaration into this module.