gcc/libgo/go/runtime/internal/sys/intrinsics.go
Ian Lance Taylor a846424359 runtime/internal/sys: new package, API copied from Go 1.7
Copy over the Go 1.7 runtime/internal/sys package, but instead of having
    separate files for each GOARCH and GOOS value, set the values in
    configure.ac and write them out in Makefile.am.  Setting the values in
    configure.ac should make it easier to add new processors.
    
    Remove the automake GOARCH conditionals, which are no longer used.
    Leave the GOOS conditionals for now, as they are used for the C runtime
    package.
    
    Reviewed-on: https://go-review.googlesource.com/29018

From-SVN: r240083
2016-09-11 13:23:27 +00:00

78 lines
1.4 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) uint64 {
if x == 0 {
return 64
}
return uint64(builtinCtz64(x))
}
//go:nosplit
// Ctz32 counts trailing (low-order) zeroes,
// and if all are zero, then 32.
func Ctz32(x uint32) uint32 {
if x == 0 {
return 32
}
return uint32(builtinCtz32(x))
}
//go:nosplit
// Ctz16 counts trailing (low-order) zeroes,
// and if all are zero, then 16.
func Ctz16(x uint16) uint16 {
if x == 0 {
return 16
}
return uint16(builtinCtz32(uint32(x)))
}
//go:nosplit
// Ctz8 counts trailing (low-order) zeroes,
// and if all are zero, then 8.
func Ctz8(x uint8) uint8 {
if x == 0 {
return 8
}
return uint8(builtinCtz32(uint32(x)))
}
//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)
}