Skip to content

Commit ad5ce71

Browse files
committed
std.Target: Define and use lime1 as the baseline CPU model for WebAssembly.
See: WebAssembly/tool-conventions#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 ziglang#21818.
1 parent 866d7c0 commit ad5ce71

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

build.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
592592
.cpu_arch = .wasm32,
593593
.os_tag = .wasi,
594594
};
595-
target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory));
595+
target_query.cpu_features_add.removeFeature(@intFromEnum(std.Target.wasm.Feature.nontrapping_fptoint));
596596

597597
const exe = addCompilerStep(b, .{
598598
.optimize = .ReleaseSmall,
@@ -620,6 +620,8 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
620620
"wasm-opt",
621621
"-Oz",
622622
"--enable-bulk-memory",
623+
"--enable-extended-const",
624+
"--enable-mutable-globals",
623625
"--enable-sign-ext",
624626
});
625627
run_opt.addArtifactArg(exe);

lib/std/Target.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ pub const Cpu = struct {
20062006
else => generic(arch),
20072007
},
20082008
.xcore => &xcore.cpu.xs1b_generic,
2009-
.wasm32, .wasm64 => &wasm.cpu.generic,
2009+
.wasm32, .wasm64 => &wasm.cpu.lime1,
20102010

20112011
else => generic(arch),
20122012
};

lib/std/Target/wasm.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,14 +4004,9 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
40044004
.os_tag = .freestanding,
40054005
.cpu_features_add = std.Target.wasm.featureSet(&.{
40064006
.atomics,
4007-
.bulk_memory,
40084007
// .extended_const, not supported by Safari
4009-
.multivalue,
4010-
.mutable_globals,
4011-
.nontrapping_fptoint,
40124008
.reference_types,
40134009
//.relaxed_simd, not supported by Firefox or Safari
4014-
.sign_ext,
40154010
// observed to cause Error occured during wast conversion :
40164011
// Unknown operator: 0xfd058 in Firefox 117
40174012
//.simd128,

tools/update_cpu_features.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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",

0 commit comments

Comments
 (0)