Use Highway SIMD (#19134)

Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2025-04-21 23:28:03 -07:00
committed by GitHub
parent b117d14650
commit 0471254e4e
19 changed files with 1841 additions and 872 deletions

View File

@@ -95,60 +95,6 @@ fn StackStack(comptime T: type, comptime SizeType: type, comptime N: SizeType) t
};
}
/// This may have false positives but it is fast
fn fastDetect(src: []const u8) bool {
var has_open = false;
var has_close = false;
if (src.len < 16) {
for (src) |char| {
switch (char) {
'{' => {
has_open = true;
},
'}' => {
has_close = true;
},
}
if (has_close and has_close) return true;
}
return false;
}
const needles = comptime [2]@Vector(16, u8){
@splat('{'),
@splat('}'),
@splat('"'),
};
const i: usize = 0;
while (i + 16 <= src.len) {
const haystack = src[i .. i + 16].*;
if (std.simd.firstTrue(needles[0] == haystack)) {
has_open = true;
}
if (std.simd.firstTrue(needles[1] == haystack)) {
has_close = true;
}
if (has_open and has_close) return true;
}
if (i < src.len) {
for (src) |char| {
switch (char) {
'{' => {
has_open = true;
},
'}' => {
has_close = true;
},
}
if (has_close and has_open) return true;
}
return false;
}
return false;
}
const ExpandError = StackError || ParserError;
/// `out` is preallocated by using the result from `calculateExpandedAmount`

View File

@@ -3563,26 +3563,10 @@ var stderr_mutex = bun.Mutex{};
pub fn hasEqSign(str: []const u8) ?u32 {
if (isAllAscii(str)) {
if (str.len < 16)
return hasEqSignAsciiSlow(str);
const needles: @Vector(16, u8) = @splat('=');
var i: u32 = 0;
while (i + 16 <= str.len) : (i += 16) {
const haystack = str[i..][0..16].*;
const result = haystack == needles;
if (std.simd.firstTrue(result)) |idx| {
return @intCast(i + idx);
}
}
return i + (hasEqSignAsciiSlow(str[i..]) orelse return null);
return bun.strings.indexOfChar(str, '=');
}
// TODO actually i think that this can also use the simd stuff
var iter = CodepointIterator.init(str);
var cursor = CodepointIterator.Cursor{};
while (iter.next(&cursor)) {
@@ -3594,11 +3578,6 @@ pub fn hasEqSign(str: []const u8) ?u32 {
return null;
}
pub fn hasEqSignAsciiSlow(str: []const u8) ?u32 {
for (str, 0..) |c, i| if (c == '=') return @intCast(i);
return null;
}
pub const CmdEnvIter = struct {
env: *const bun.StringArrayHashMap([:0]const u8),
iter: bun.StringArrayHashMap([:0]const u8).Iterator,