runtime: add special handling for signal 34
[official-gcc.git] / libgo / go / math / bits / make_examples.go
blob92e9aabfb52738ebc1af7f5526c893b873b14e65
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 example_test.go.
10 package main
12 import (
13 "bytes"
14 "fmt"
15 "log"
16 "math/bits"
17 "os"
20 const header = `// Copyright 2017 The Go Authors. All rights reserved.
21 // Use of this source code is governed by a BSD-style
22 // license that can be found in the LICENSE file.
24 // Code generated by go run make_examples.go. DO NOT EDIT.
26 package bits_test
28 import (
29 "fmt"
30 "math/bits"
34 func main() {
35 w := bytes.NewBuffer([]byte(header))
37 for _, e := range []struct {
38 name string
39 in int
40 out [4]any
41 out2 [4]any
44 name: "LeadingZeros",
45 in: 1,
46 out: [4]any{bits.LeadingZeros8(1), bits.LeadingZeros16(1), bits.LeadingZeros32(1), bits.LeadingZeros64(1)},
49 name: "TrailingZeros",
50 in: 14,
51 out: [4]any{bits.TrailingZeros8(14), bits.TrailingZeros16(14), bits.TrailingZeros32(14), bits.TrailingZeros64(14)},
54 name: "OnesCount",
55 in: 14,
56 out: [4]any{bits.OnesCount8(14), bits.OnesCount16(14), bits.OnesCount32(14), bits.OnesCount64(14)},
59 name: "RotateLeft",
60 in: 15,
61 out: [4]any{bits.RotateLeft8(15, 2), bits.RotateLeft16(15, 2), bits.RotateLeft32(15, 2), bits.RotateLeft64(15, 2)},
62 out2: [4]any{bits.RotateLeft8(15, -2), bits.RotateLeft16(15, -2), bits.RotateLeft32(15, -2), bits.RotateLeft64(15, -2)},
65 name: "Reverse",
66 in: 19,
67 out: [4]any{bits.Reverse8(19), bits.Reverse16(19), bits.Reverse32(19), bits.Reverse64(19)},
70 name: "ReverseBytes",
71 in: 15,
72 out: [4]any{nil, bits.ReverseBytes16(15), bits.ReverseBytes32(15), bits.ReverseBytes64(15)},
75 name: "Len",
76 in: 8,
77 out: [4]any{bits.Len8(8), bits.Len16(8), bits.Len32(8), bits.Len64(8)},
79 } {
80 for i, size := range []int{8, 16, 32, 64} {
81 if e.out[i] == nil {
82 continue // function doesn't exist
84 f := fmt.Sprintf("%s%d", e.name, size)
85 fmt.Fprintf(w, "\nfunc Example%s() {\n", f)
86 switch e.name {
87 case "RotateLeft", "Reverse", "ReverseBytes":
88 fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", %d)\n", size, e.in)
89 if e.name == "RotateLeft" {
90 fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d, 2))\n", size, f, e.in)
91 fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d, -2))\n", size, f, e.in)
92 } else {
93 fmt.Fprintf(w, "\tfmt.Printf(\"%%0%db\\n\", bits.%s(%d))\n", size, f, e.in)
95 fmt.Fprintf(w, "\t// Output:\n")
96 fmt.Fprintf(w, "\t// %0*b\n", size, e.in)
97 fmt.Fprintf(w, "\t// %0*b\n", size, e.out[i])
98 if e.name == "RotateLeft" && e.out2[i] != nil {
99 fmt.Fprintf(w, "\t// %0*b\n", size, e.out2[i])
101 default:
102 fmt.Fprintf(w, "\tfmt.Printf(\"%s(%%0%db) = %%d\\n\", %d, bits.%s(%d))\n", f, size, e.in, f, e.in)
103 fmt.Fprintf(w, "\t// Output:\n")
104 fmt.Fprintf(w, "\t// %s(%0*b) = %d\n", f, size, e.in, e.out[i])
106 fmt.Fprintf(w, "}\n")
110 if err := os.WriteFile("example_test.go", w.Bytes(), 0666); err != nil {
111 log.Fatal(err)