From 09080eb0f6d9bb23b927801ea653ab9e5207f191 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 24 Jun 2024 15:06:16 -0700 Subject: [PATCH] disable AVX512 until Zig issue is resolved https://github.com/ziglang/zig/issues/20414 --- build.zig | 30 +++++++++++++++++++++++++----- pkg/simdutf/build.zig | 4 +++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index 6db0ccbe04..a30ddb4bfb 100644 --- a/build.zig +++ b/build.zig @@ -1028,11 +1028,31 @@ fn addDeps( // C++ files step.linkLibCpp(); step.addIncludePath(b.path("src")); - step.addCSourceFiles(.{ .files = &.{ - "src/simd/codepoint_width.cpp", - "src/simd/index_of.cpp", - "src/simd/vt.cpp", - } }); + { + // From hwy/detect_targets.h + const HWY_AVX3_SPR: c_int = 1 << 4; + const HWY_AVX3_ZEN4: c_int = 1 << 6; + const HWY_AVX3_DL: c_int = 1 << 7; + const HWY_AVX3: c_int = 1 << 8; + + // Zig 0.13 bug: https://github.com/ziglang/zig/issues/20414 + // To workaround this we just disable AVX512 support completely. + // The performance difference between AVX2 and AVX512 is not + // significant for our use case and AVX512 is very rare on consumer + // hardware anyways. + const HWY_DISABLED_TARGETS: c_int = HWY_AVX3_SPR | HWY_AVX3_ZEN4 | HWY_AVX3_DL | HWY_AVX3; + + step.addCSourceFiles(.{ + .files = &.{ + "src/simd/codepoint_width.cpp", + "src/simd/index_of.cpp", + "src/simd/vt.cpp", + }, + .flags = if (step.rootModuleTarget().cpu.arch == .x86_64) &.{ + b.fmt("-DHWY_DISABLED_TARGETS={}", .{HWY_DISABLED_TARGETS}), + } else &.{}, + }); + } // If we're building a lib we have some different deps const lib = step.kind == .lib; diff --git a/pkg/simdutf/build.zig b/pkg/simdutf/build.zig index 784d7cce13..1532e4a336 100644 --- a/pkg/simdutf/build.zig +++ b/pkg/simdutf/build.zig @@ -19,7 +19,9 @@ pub fn build(b: *std.Build) !void { var flags = std.ArrayList([]const u8).init(b.allocator); defer flags.deinit(); - try flags.appendSlice(&.{}); + // Zig 0.13 bug: https://github.com/ziglang/zig/issues/20414 + // (See root Ghostty build.zig on why we do this) + try flags.appendSlice(&.{"-DSIMDUTF_IMPLEMENTATION_ICELAKE=0"}); lib.addCSourceFiles(.{ .flags = flags.items,