Skip to content

Commit

Permalink
Self-hosted compiler support (#85)
Browse files Browse the repository at this point in the history
Bypass simd vector logic when backend does not support vectors.

Detection logic taken from here:
https://github.com/ziglang/zig/blob/497592c9b45a94fb7b6028bf45b80f183e395a9b/lib/std/mem.zig#L1066
  • Loading branch information
bobf authored Dec 25, 2024
1 parent 32c98e0 commit bdba46d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/url.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const std = @import("std");
const builtin = @import("builtin");
const metrics = @import("metrics.zig");

const Allocator = std.mem.Allocator;

const backend_supports_vectors = switch (builtin.zig_backend) {
.stage2_llvm, .stage2_c => true,
else => false,
};

pub const Url = struct {
raw: []const u8 = "",
path: []const u8 = "",
Expand Down Expand Up @@ -125,13 +131,16 @@ pub const Url = struct {

pub fn isValid(url: []const u8) bool {
var rest = url;
if (comptime std.simd.suggestVectorLength(u8)) |vector_len| {
while (rest.len >= vector_len) {
const block: @Vector(vector_len, u8) = rest[0..vector_len].*;
if (@reduce(.Min, block) < 32 or @reduce(.Max, block) > 126) {
return false;

if (comptime backend_supports_vectors) {
if (comptime std.simd.suggestVectorLength(u8)) |vector_len| {
while (rest.len >= vector_len) {
const block: @Vector(vector_len, u8) = rest[0..vector_len].*;
if (@reduce(.Min, block) < 32 or @reduce(.Max, block) > 126) {
return false;
}
rest = rest[vector_len..];
}
rest = rest[vector_len..];
}
}

Expand Down

0 comments on commit bdba46d

Please sign in to comment.