Files
ghostty/pkg/highway/src/detect/loongarch.zig
Mitchell Hashimoto 00dfd67bee pkg/highway: replace resolveTargetQuery with direct CPU detection
The previous runtime_detect.zig called std.zig.system.resolveTargetQuery
which pulled in the entire Zig target/CPU model table infrastructure for
every architecture (~4,000 symbols, ~175 KB of data tables, ~130 KB of
code). This bloated the binary by ~500 KB and shifted code layout enough
to cause a measurable icache/branch-predictor regression in unrelated
hot paths like the terminal parser (~20% more cycles for identical
instruction counts).

Replace with minimal, direct CPU feature detection per architecture:
CPUID + XGETBV inline assembly on x86, sysctlbyname on Darwin AArch64,
and getauxval/prctl via std.os.linux (direct syscalls, no libc) on
Linux for AArch64, PPC, S390x, RISC-V, and LoongArch.

Split into per-architecture files under src/detect/ for
maintainability.
2026-04-23 21:23:12 -07:00

27 lines
621 B
Zig

const builtin = @import("builtin");
const HwyTargets = @import("../targets.zig").Targets;
const linux = @import("linux.zig");
pub fn detect() i64 {
var t: HwyTargets = .{};
if (comptime builtin.os.tag != .linux) return @bitCast(t);
const AT_HWCAP: usize = 16;
const hwcap = linux.getauxval(AT_HWCAP);
// From Linux arch/loongarch/include/uapi/asm/hwcap.h
const HWCAP_LSX: usize = 1 << 4;
const HWCAP_LASX: usize = 1 << 5;
if (hwcap & HWCAP_LSX != 0) {
t.lsx = true;
if (hwcap & HWCAP_LASX != 0) {
t.lasx = true;
}
}
return @bitCast(t);
}