authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2025-03-11 00:49:16+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2025-03-17 21:56:17+03:30
log50539a2447c0720f91789063d7349bd0103de4bd
tree4e199fd54e58623f363b84c0899f149c8c718d97
parente2e75774748591fb44bfc905080e7a14008d4ec3

spirv/target: arbitrary_precision_integers feature support


4 files changed, 12 insertions(+), 4 deletions(-)

lib/std/Target/spirv.zig+6
...@@ -17,6 +17,7 @@ pub const Feature = enum {...@@ -17,6 +17,7 @@ pub const Feature = enum {
17 float64,17 float64,
18 matrix,18 matrix,
19 storage_push_constant16,19 storage_push_constant16,
20 arbitrary_precision_integers,
20 kernel,21 kernel,
21 addresses,22 addresses,
22 generic_pointer,23 generic_pointer,
...@@ -105,6 +106,11 @@ pub const all_features = blk: {...@@ -105,6 +106,11 @@ pub const all_features = blk: {
105 .description = "Enable SPV_KHR_16bit_storage extension and the StoragePushConstant16 capability",106 .description = "Enable SPV_KHR_16bit_storage extension and the StoragePushConstant16 capability",
106 .dependencies = featureSet(&[_]Feature{.v1_3}),107 .dependencies = featureSet(&[_]Feature{.v1_3}),
107 };108 };
109 result[@intFromEnum(Feature.arbitrary_precision_integers)] = .{
110 .llvm_name = null,
111 .description = "Enable SPV_INTEL_arbitrary_precision_integers extension and the ArbitraryPrecisionIntegersINTEL capability",
112 .dependencies = featureSet(&[_]Feature{ .v1_5, .int8, .int16 }),
113 };
108 result[@intFromEnum(Feature.kernel)] = .{114 result[@intFromEnum(Feature.kernel)] = .{
109 .llvm_name = null,115 .llvm_name = null,
110 .description = "Enable Kernel capability",116 .description = "Enable Kernel capability",
src/codegen/spirv.zig+2-2
...@@ -581,13 +581,13 @@ const NavGen = struct {...@@ -581,13 +581,13 @@ const NavGen = struct {
581 /// that size. In this case, multiple elements of the largest type should be used.581 /// that size. In this case, multiple elements of the largest type should be used.
582 /// The backing type will be chosen as the smallest supported integer larger or equal to it in number of bits.582 /// The backing type will be chosen as the smallest supported integer larger or equal to it in number of bits.
583 /// The result is valid to be used with OpTypeInt.583 /// The result is valid to be used with OpTypeInt.
584 /// TODO: The extension SPV_INTEL_arbitrary_precision_integers allows any integer size (at least up to 32 bits).
585 /// TODO: This probably needs an ABI-version as well (especially in combination with SPV_INTEL_arbitrary_precision_integers).
586 /// TODO: Should the result of this function be cached?584 /// TODO: Should the result of this function be cached?
587 fn backingIntBits(self: *NavGen, bits: u16) ?u16 {585 fn backingIntBits(self: *NavGen, bits: u16) ?u16 {
588 // The backend will never be asked to compiler a 0-bit integer, so we won't have to handle those in this function.586 // The backend will never be asked to compiler a 0-bit integer, so we won't have to handle those in this function.
589 assert(bits != 0);587 assert(bits != 0);
590588
589 if (self.spv.hasFeature(.arbitrary_precision_integers) and bits <= 32) return bits;
590
591 // 8, 16 and 64-bit integers require the Int8, Int16 and Inr64 capabilities respectively.591 // 8, 16 and 64-bit integers require the Int8, Int16 and Inr64 capabilities respectively.
592 // 32-bit integers are always supported (see spec, 2.16.1, Data rules).592 // 32-bit integers are always supported (see spec, 2.16.1, Data rules).
593 const ints = [_]struct { bits: u16, feature: ?Target.spirv.Feature }{593 const ints = [_]struct { bits: u16, feature: ?Target.spirv.Feature }{
src/codegen/spirv/Module.zig+4
...@@ -343,6 +343,10 @@ pub fn finalize(self: *Module, a: Allocator) ![]Word {...@@ -343,6 +343,10 @@ pub fn finalize(self: *Module, a: Allocator) ![]Word {
343 try self.addExtension("SPV_KHR_16bit_storage");343 try self.addExtension("SPV_KHR_16bit_storage");
344 try self.addCapability(.StoragePushConstant16);344 try self.addCapability(.StoragePushConstant16);
345 },345 },
346 .arbitrary_precision_integers => {
347 try self.addExtension("SPV_INTEL_arbitrary_precision_integers");
348 try self.addCapability(.ArbitraryPrecisionIntegersINTEL);
349 },
346 .addresses => try self.addCapability(.Addresses),350 .addresses => try self.addCapability(.Addresses),
347 // Kernel351 // Kernel
348 .kernel => try self.addCapability(.Kernel),352 .kernel => try self.addCapability(.Kernel),
test/behavior/vector.zig-2
...@@ -11,7 +11,6 @@ test "implicit cast vector to array - bool" {...@@ -11,7 +11,6 @@ test "implicit cast vector to array - bool" {
11 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO11 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
12 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO12 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
13 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO13 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1514
16 const S = struct {15 const S = struct {
17 fn doTheTest() !void {16 fn doTheTest() !void {
...@@ -30,7 +29,6 @@ test "vector wrap operators" {...@@ -30,7 +29,6 @@ test "vector wrap operators" {
30 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO29 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
31 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO30 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
32 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;31 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
33 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
34 if (builtin.zig_backend == .stage2_x86_64 and32 if (builtin.zig_backend == .stage2_x86_64 and
35 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest;33 !comptime std.Target.x86.featureSetHas(builtin.cpu.features, .sse4_1)) return error.SkipZigTest;
3634