runtime: add special handling for signal 34
[official-gcc.git] / libgo / go / math / bits / make_tables.go
blob867025ea61dfe59303c32bea50e3abb64f1c1928
1 // Copyright 2017 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 //go:build ignore
6 // +build ignore
8 // This program generates bits_tables.go.
10 package main
12 import (
13 "bytes"
14 "fmt"
15 "go/format"
16 "io"
17 "log"
18 "os"
21 var header = []byte(`// Copyright 2017 The Go Authors. All rights reserved.
22 // Use of this source code is governed by a BSD-style
23 // license that can be found in the LICENSE file.
25 // Code generated by go run make_tables.go. DO NOT EDIT.
27 package bits
31 func main() {
32 buf := bytes.NewBuffer(header)
34 gen(buf, "ntz8tab", ntz8)
35 gen(buf, "pop8tab", pop8)
36 gen(buf, "rev8tab", rev8)
37 gen(buf, "len8tab", len8)
39 out, err := format.Source(buf.Bytes())
40 if err != nil {
41 log.Fatal(err)
44 err = os.WriteFile("bits_tables.go", out, 0666)
45 if err != nil {
46 log.Fatal(err)
50 func gen(w io.Writer, name string, f func(uint8) uint8) {
51 // Use a const string to allow the compiler to constant-evaluate lookups at constant index.
52 fmt.Fprintf(w, "const %s = \"\"+\n\"", name)
53 for i := 0; i < 256; i++ {
54 fmt.Fprintf(w, "\\x%02x", f(uint8(i)))
55 if i%16 == 15 && i != 255 {
56 fmt.Fprint(w, "\"+\n\"")
59 fmt.Fprint(w, "\"\n\n")
62 func ntz8(x uint8) (n uint8) {
63 for x&1 == 0 && n < 8 {
64 x >>= 1
65 n++
67 return
70 func pop8(x uint8) (n uint8) {
71 for x != 0 {
72 x &= x - 1
73 n++
75 return
78 func rev8(x uint8) (r uint8) {
79 for i := 8; i > 0; i-- {
80 r = r<<1 | x&1
81 x >>= 1
83 return
86 func len8(x uint8) (n uint8) {
87 for x != 0 {
88 x >>= 1
89 n++
91 return