simd: only ref buildable decls

This commit is contained in:
Mitchell Hashimoto
2024-01-29 21:01:40 -08:00
parent e682cea911
commit 5b295cf6e2
2 changed files with 15 additions and 11 deletions

View File

@ -2,16 +2,16 @@ const std = @import("std");
pub const isa = @import("isa.zig"); pub const isa = @import("isa.zig");
pub const utf8 = @import("utf8.zig"); pub const utf8 = @import("utf8.zig");
const index_of = @import("index_of.zig"); pub const index_of = @import("index_of.zig");
pub usingnamespace index_of;
pub fn main() !void { // TODO: temporary, only for zig build simd to inspect disasm easily
//std.log.warn("ISA={}", .{isa.ISA.detect()}); // pub fn main() !void {
const input = "1234567\x1b1234567\x1b"; // //std.log.warn("ISA={}", .{isa.ISA.detect()});
//const input = "1234567812345678"; // const input = "1234567\x1b1234567\x1b";
std.log.warn("result={any}", .{index_of.indexOf(input, 0x1B)}); // //const input = "1234567812345678";
std.log.warn("result={any}", .{utf8.utf8Validate(input)}); // std.log.warn("result={any}", .{index_of.indexOf(input, 0x1B)});
} // std.log.warn("result={any}", .{utf8.utf8Validate(input)});
// }
test { test {
@import("std").testing.refAllDecls(@This()); @import("std").testing.refAllDecls(@This());

View File

@ -21,6 +21,10 @@ pub fn utf8ValidateNeon(input: []const u8) bool {
return !neon.hasErrors(); return !neon.hasErrors();
} }
pub fn utf8ValidateScalar(input: []const u8) bool {
return std.unicode.utf8ValidateSlice(input);
}
pub const Neon = struct { pub const Neon = struct {
/// The previous input in a vector. This is required because to check /// The previous input in a vector. This is required because to check
/// the validity of a UTF-8 byte, we need to sometimes know previous /// the validity of a UTF-8 byte, we need to sometimes know previous
@ -52,7 +56,7 @@ pub const Neon = struct {
var i: usize = 0; var i: usize = 0;
while (i + 16 <= input.len) : (i += 16) { while (i + 16 <= input.len) : (i += 16) {
const input_vec = aarch64.vld1q_u8(input[i..]); const input_vec = aarch64.vld1q_u8(input[i..]);
self.next(input_vec); self.process(input_vec);
} }
// If we have any data remaining, we pad it with zeroes since that // If we have any data remaining, we pad it with zeroes since that
@ -66,7 +70,7 @@ pub const Neon = struct {
@memset(buf[remaining..], 0); @memset(buf[remaining..], 0);
const input_vec = aarch64.vld1q_u8(&buf); const input_vec = aarch64.vld1q_u8(&buf);
self.next(input_vec); self.process(input_vec);
} }
} }