authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-29 01:31:49+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-01-22 03:01:05+01:00
log280ced66eb712f5c74835b10fa6ba0bd915ee96b
tree0ba02dbed0c698345a2cd2341cdbb812886c1e61
parent206373ca61ec6803e979aad9491e1da16cbf94b6
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Target: Define and use lime1 as the baseline CPU model for WebAssembly.

See: https://github.com/WebAssembly/tool-conventions/pull/235 This is not *quite* using the same features as the spec'd lime1 model because LLVM 19 doesn't have the level of feature granularity that we need for that. This will be fixed once we upgrade to LLVM 20. Part of #21818.

5 files changed, 34 insertions(+), 13 deletions(-)

build.zig+7-7
......@@ -594,15 +594,14 @@ pub fn build(b: *std.Build) !void {
594594fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
595595 const semver = try std.SemanticVersion.parse(version);
596596
597 var target_query: std.Target.Query = .{
598 .cpu_arch = .wasm32,
599 .os_tag = .wasi,
600 };
601 target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory));
602
603597 const exe = addCompilerStep(b, .{
604598 .optimize = .ReleaseSmall,
605 .target = b.resolveTargetQuery(target_query),
599 .target = b.resolveTargetQuery(std.Target.Query.parse(.{
600 .arch_os_abi = "wasm32-wasi",
601 // `extended_const` is not supported by the `wasm-opt` version in CI.
602 // `nontrapping_fptoint` is not supported by `wasm2c`.
603 .cpu_features = "baseline-extended_const-nontrapping_fptoint",
604 }) catch unreachable),
606605 });
607606
608607 const exe_options = b.addOptions();
......@@ -644,6 +643,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
644643 "wasm-opt",
645644 "-Oz",
646645 "--enable-bulk-memory",
646 "--enable-mutable-globals",
647647 "--enable-sign-ext",
648648 });
649649 run_opt.addArtifactArg(exe);
lib/std/Target.zig+1-1
......@@ -2012,7 +2012,7 @@ pub const Cpu = struct {
20122012 else => generic(arch),
20132013 },
20142014 .xcore => &xcore.cpu.xs1b_generic,
2015 .wasm32, .wasm64 => &wasm.cpu.generic,
2015 .wasm32, .wasm64 => &wasm.cpu.lime1,
20162016
20172017 else => generic(arch),
20182018 };
lib/std/Target/wasm.zig+12
......@@ -139,6 +139,18 @@ pub const cpu = struct {
139139 .sign_ext,
140140 }),
141141 };
142 pub const lime1: CpuModel = .{
143 .name = "lime1",
144 .llvm_name = null,
145 .features = featureSet(&[_]Feature{
146 .bulk_memory,
147 .extended_const,
148 .multivalue,
149 .mutable_globals,
150 .nontrapping_fptoint,
151 .sign_ext,
152 }),
153 };
142154 pub const mvp: CpuModel = .{
143155 .name = "mvp",
144156 .llvm_name = "mvp",
src/Compilation.zig-5
......@@ -4150,14 +4150,9 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
41504150 .os_tag = .freestanding,
41514151 .cpu_features_add = std.Target.wasm.featureSet(&.{
41524152 .atomics,
4153 .bulk_memory,
41544153 // .extended_const, not supported by Safari
4155 .multivalue,
4156 .mutable_globals,
4157 .nontrapping_fptoint,
41584154 .reference_types,
41594155 //.relaxed_simd, not supported by Firefox or Safari
4160 .sign_ext,
41614156 // observed to cause Error occured during wast conversion :
41624157 // Unknown operator: 0xfd058 in Firefox 117
41634158 //.simd128,
tools/update_cpu_features.zig+14
......@@ -1033,6 +1033,20 @@ const llvm_targets = [_]LlvmTarget{
10331033 .zig_name = "wasm",
10341034 .llvm_name = "WebAssembly",
10351035 .td_name = "WebAssembly.td",
1036 .extra_cpus = &.{
1037 .{
1038 .llvm_name = null,
1039 .zig_name = "lime1",
1040 .features = &.{
1041 "bulk_memory",
1042 "extended_const",
1043 "multivalue",
1044 "mutable_globals",
1045 "nontrapping_fptoint",
1046 "sign_ext",
1047 },
1048 },
1049 },
10361050 },
10371051 .{
10381052 .zig_name = "x86",