Skip to content
/ zig Public
forked from ziglang/zig

Commit

Permalink
std.Target: Define and use lime1 as the baseline CPU model for WebAss…
Browse files Browse the repository at this point in the history
…embly.

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.
  • Loading branch information
alexrp committed Nov 29, 2024
1 parent 1eaf9c8 commit 2233837
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
4 changes: 3 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
.cpu_arch = .wasm32,
.os_tag = .wasi,
};
target_query.cpu_features_add.addFeature(@intFromEnum(std.Target.wasm.Feature.bulk_memory));
target_query.cpu_features_add.removeFeature(@intFromEnum(std.Target.wasm.Feature.nontrapping_fptoint));

const exe = addCompilerStep(b, .{
.optimize = .ReleaseSmall,
Expand Down Expand Up @@ -620,6 +620,8 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
"wasm-opt",
"-Oz",
"--enable-bulk-memory",
"--enable-extended-const",
"--enable-mutable-globals",
"--enable-sign-ext",
});
run_opt.addArtifactArg(exe);
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ pub const Cpu = struct {
else => generic(arch),
},
.xcore => &xcore.cpu.xs1b_generic,
.wasm32, .wasm64 => &wasm.cpu.generic,
.wasm32, .wasm64 => &wasm.cpu.lime1,

else => generic(arch),
};
Expand Down
12 changes: 12 additions & 0 deletions lib/std/Target/wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ pub const cpu = struct {
.sign_ext,
}),
};
pub const lime1: CpuModel = .{
.name = "lime1",
.llvm_name = null,
.features = featureSet(&[_]Feature{
.bulk_memory,
.extended_const,
.multivalue,
.mutable_globals,
.nontrapping_fptoint,
.sign_ext,
}),
};
pub const mvp: CpuModel = .{
.name = "mvp",
.llvm_name = "mvp",
Expand Down
5 changes: 0 additions & 5 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4004,14 +4004,9 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
.os_tag = .freestanding,
.cpu_features_add = std.Target.wasm.featureSet(&.{
.atomics,
.bulk_memory,
// .extended_const, not supported by Safari
.multivalue,
.mutable_globals,
.nontrapping_fptoint,
.reference_types,
//.relaxed_simd, not supported by Firefox or Safari
.sign_ext,
// observed to cause Error occured during wast conversion :
// Unknown operator: 0xfd058 in Firefox 117
//.simd128,
Expand Down
14 changes: 14 additions & 0 deletions tools/update_cpu_features.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,20 @@ const llvm_targets = [_]LlvmTarget{
.zig_name = "wasm",
.llvm_name = "WebAssembly",
.td_name = "WebAssembly.td",
.extra_cpus = &.{
.{
.llvm_name = null,
.zig_name = "lime1",
.features = &.{
"bulk_memory",
"extended_const",
"multivalue",
"mutable_globals",
"nontrapping_fptoint",
"sign_ext"
},
},
},
},
.{
.zig_name = "x86",
Expand Down

0 comments on commit 2233837

Please sign in to comment.