// Copyright 2025 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build (!amd64 && !arm64) || purego package bitutil import "unsafe" func testBytes(p []byte) bool { if supportsUnaligned { return fastTestBytes(p) } return safeTestBytes(p) } // fastTestBytes tests for set bits in bulk. It only works on architectures that // support unaligned read/writes. func fastTestBytes(p []byte) bool { n := len(p) w := n / wordSize if w > 0 { pw := *(*[]uintptr)(unsafe.Pointer(&p)) for i := 0; i < w; i++ { if pw[i] != 0 { return true } } } for i := n - n%wordSize; i < n; i++ { if p[i] != 0 { return true } } return false }