dd931d9b48
Reviewed-on: https://go-review.googlesource.com/136435 gotools/: * Makefile.am (mostlyclean-local): Run chmod on check-go-dir to make sure it is writable. (check-go-tools): Likewise. (check-vet): Copy internal/objabi to check-vet-dir. * Makefile.in: Rebuild. From-SVN: r264546
80 lines
2.7 KiB
Go
80 lines
2.7 KiB
Go
// Copyright 2016 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.
|
|
|
|
package sys
|
|
|
|
//extern __builtin_ctz
|
|
func builtinCtz32(uint32) int32
|
|
|
|
//extern __builtin_ctzll
|
|
func builtinCtz64(uint64) int32
|
|
|
|
//go:nosplit
|
|
|
|
// Ctz64 counts trailing (low-order) zeroes,
|
|
// and if all are zero, then 64.
|
|
func Ctz64(x uint64) int {
|
|
if x == 0 {
|
|
return 64
|
|
}
|
|
return int(builtinCtz64(x))
|
|
}
|
|
|
|
//go:nosplit
|
|
|
|
// Ctz32 counts trailing (low-order) zeroes,
|
|
// and if all are zero, then 32.
|
|
func Ctz32(x uint32) int {
|
|
if x == 0 {
|
|
return 32
|
|
}
|
|
return int(builtinCtz32(x))
|
|
}
|
|
|
|
// Ctz8 returns the number of trailing zero bits in x; the result is 8 for x == 0.
|
|
func Ctz8(x uint8) int {
|
|
return int(ntz8tab[x])
|
|
}
|
|
|
|
var ntz8tab = [256]uint8{
|
|
0x08, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x07, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
|
|
}
|
|
|
|
//extern __builtin_bswap64
|
|
func bswap64(uint64) uint64
|
|
|
|
//go:nosplit
|
|
|
|
// Bswap64 returns its input with byte order reversed
|
|
// 0x0102030405060708 -> 0x0807060504030201
|
|
func Bswap64(x uint64) uint64 {
|
|
return bswap64(x)
|
|
}
|
|
|
|
//extern __builtin_bswap32
|
|
func bswap32(uint32) uint32
|
|
|
|
//go:nosplit
|
|
|
|
// Bswap32 returns its input with byte order reversed
|
|
// 0x01020304 -> 0x04030201
|
|
func Bswap32(x uint32) uint32 {
|
|
return bswap32(x)
|
|
}
|