simd: remove ziglyph fallback

This commit is contained in:
Mitchell Hashimoto
2024-02-07 09:21:33 -08:00
parent 697fbe21ec
commit 46a887578a
2 changed files with 25 additions and 33 deletions

View File

@ -15,8 +15,6 @@ namespace hn = hwy::HWY_NAMESPACE;
using T = uint32_t;
extern "C" int8_t ghostty_ziglyph_codepoint_width(uint32_t);
// East Asian Width
HWY_ALIGN constexpr T eaw_gte[] = {
0x3000, 0xff01, 0xffe0, 0x1100, 0x231a, 0x2329, 0x232a, 0x23e9,
@ -74,7 +72,7 @@ HWY_ALIGN constexpr T zero_gte[] = {
0xfeff, 0xfff9, 0x110bd, 0x110cd, 0x13430, 0x1bca0, 0x1d173, 0xe0001,
0xe0020, 0x488, 0x1abe, 0x20dd, 0x20e2, 0xa670, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
HWY_ALIGN constexpr T zero_lte[] = {
@ -82,7 +80,7 @@ HWY_ALIGN constexpr T zero_lte[] = {
0xfeff, 0xfffb, 0x110bd, 0x110cd, 0x1343f, 0x1bca3, 0x1d17a, 0xe0001,
0xe007f, 0x489, 0x1abe, 0x20e0, 0x20e4, 0xa672, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
/// Non-spacing marks
@ -132,7 +130,7 @@ HWY_ALIGN constexpr T nsm_gte[] = {
0x1e023, 0x1e026, 0x1e08f, 0x1e130, 0x1e2ae, 0x1e2ec, 0x1e4ec, 0x1e8d0,
0x1e944, 0xe0100, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
HWY_ALIGN constexpr T nsm_lte[] = {
@ -181,7 +179,7 @@ HWY_ALIGN constexpr T nsm_lte[] = {
0x1e024, 0x1e02a, 0x1e08f, 0x1e136, 0x1e2ae, 0x1e2ef, 0x1e4ef, 0x1e8d6,
0x1e94a, 0xe01ef, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
// All our tables must be identically sized
@ -312,7 +310,6 @@ int8_t CodepointWidthImpl(D d, T input) {
}
return 1;
// return ghostty_ziglyph_codepoint_width(input);
}
int8_t CodepointWidth(T input) {

View File

@ -22,29 +22,24 @@ test "codepointWidth basic" {
// try testing.expectEqual(@as(i8, 1), @import("ziglyph").display_width.codePointWidth(0x100, .half));
}
pub export fn ghostty_ziglyph_codepoint_width(cp: u32) callconv(.C) i8 {
return @import("ziglyph").display_width.codePointWidth(@intCast(cp), .half);
}
test "codepointWidth matches ziglyph" {
const testing = std.testing;
const ziglyph = @import("ziglyph");
// try testing.expect(ziglyph.general_category.isNonspacingMark(0x16fe4));
// if (true) return;
const min = 0xFF + 1; // start outside ascii
for (min..std.math.maxInt(u21)) |cp| {
const simd = codepointWidth(@intCast(cp));
const zg = ziglyph.display_width.codePointWidth(@intCast(cp), .half);
if (simd != zg) mismatch: {
if (cp == 0x2E3B) {
try testing.expectEqual(@as(i8, 2), simd);
break :mismatch;
}
std.log.warn("mismatch cp=U+{x} simd={} zg={}", .{ cp, simd, zg });
try testing.expect(false);
}
}
}
// This is not very fast in debug modes, so its commented by default.
// IMPORTANT: UNCOMMENT THIS WHENEVER MAKING CODEPOINTWIDTH CHANGES.
// test "codepointWidth matches ziglyph" {
// const testing = std.testing;
// const ziglyph = @import("ziglyph");
//
// const min = 0xFF + 1; // start outside ascii
// for (min..std.math.maxInt(u21)) |cp| {
// const simd = codepointWidth(@intCast(cp));
// const zg = ziglyph.display_width.codePointWidth(@intCast(cp), .half);
// if (simd != zg) mismatch: {
// if (cp == 0x2E3B) {
// try testing.expectEqual(@as(i8, 2), simd);
// break :mismatch;
// }
//
// std.log.warn("mismatch cp=U+{x} simd={} zg={}", .{ cp, simd, zg });
// try testing.expect(false);
// }
// }
// }