Files
unkernel/js/core/zero-scan.zig
Kotaro Chikuba ba600f0d36 js: use a Zig SIMD scan for zero-filled blocks (#187)
* js: scan zero-filled blocks with Zig WebAssembly SIMD

Use an explicit vector scan for sparse disk blocks and snapshots without a chunk map. Preserve the JavaScript path for short scans and hosts without SIMD.

* js: refuse a zero-scan span outside the view

* js: keep the zero scan's scratch off address 0 and test the embedded module against zero-scan.zig

---------

Co-authored-by: Pooya Parsa <pooya@pi0.io>
2026-12-05 00:48:10 +01:00

23 lines
740 B
Zig

// SPDX-License-Identifier: MIT
// Copyright (C) 2026 mizchi
const Vec = @Vector(16, u8);
const group_bytes = 4 * @sizeOf(Vec);
var scratch: [65536]u8 align(@sizeOf(Vec)) = undefined;
export fn scratchOffset() usize {
return @intFromPtr(&scratch);
}
// The host fills scratch with one block, in whole 64-byte groups.
export fn isZero(length: usize) u32 {
if (length > scratch.len or length % group_bytes != 0) return 0;
var offset: usize = 0;
while (offset < length) : (offset += group_bytes) {
const lanes: *const [4]Vec = @ptrCast(@alignCast(&scratch[offset]));
const any = lanes[0] | lanes[1] | lanes[2] | lanes[3];
if (@reduce(.Or, any != @as(Vec, @splat(0)))) return 0;
}
return 1;
}