libgo: update to Go 1.11
[official-gcc.git] / libgo / go / runtime / internal / sys / intrinsics.go
blob6906938e574f9898312df51ac490fba27ac8c681
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package sys
7 //extern __builtin_ctz
8 func builtinCtz32(uint32) int32
10 //extern __builtin_ctzll
11 func builtinCtz64(uint64) int32
13 //go:nosplit
15 // Ctz64 counts trailing (low-order) zeroes,
16 // and if all are zero, then 64.
17 func Ctz64(x uint64) int {
18 if x == 0 {
19 return 64
21 return int(builtinCtz64(x))
24 //go:nosplit
26 // Ctz32 counts trailing (low-order) zeroes,
27 // and if all are zero, then 32.
28 func Ctz32(x uint32) int {
29 if x == 0 {
30 return 32
32 return int(builtinCtz32(x))
35 // Ctz8 returns the number of trailing zero bits in x; the result is 8 for x == 0.
36 func Ctz8(x uint8) int {
37 return int(ntz8tab[x])
40 var ntz8tab = [256]uint8{
41 0x08, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
42 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
43 0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
44 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
45 0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
46 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
47 0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
48 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
49 0x07, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
50 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
51 0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
52 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
53 0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
54 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
55 0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
56 0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
59 //extern __builtin_bswap64
60 func bswap64(uint64) uint64
62 //go:nosplit
64 // Bswap64 returns its input with byte order reversed
65 // 0x0102030405060708 -> 0x0807060504030201
66 func Bswap64(x uint64) uint64 {
67 return bswap64(x)
70 //extern __builtin_bswap32
71 func bswap32(uint32) uint32
73 //go:nosplit
75 // Bswap32 returns its input with byte order reversed
76 // 0x01020304 -> 0x04030201
77 func Bswap32(x uint32) uint32 {
78 return bswap32(x)