runtime: scan register backing store on ia64
[official-gcc.git] / libgo / go / runtime / mkfastlog2table.go
blob587ebf476d388690b8062046a3c14c607aef0e66
1 // Copyright 2015 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 // +build ignore
7 // fastlog2Table contains log2 approximations for 5 binary digits.
8 // This is used to implement fastlog2, which is used for heap sampling.
10 package main
12 import (
13 "bytes"
14 "fmt"
15 "io/ioutil"
16 "log"
17 "math"
20 func main() {
21 var buf bytes.Buffer
23 fmt.Fprintln(&buf, "// AUTO-GENERATED by mkfastlog2table.go")
24 fmt.Fprintln(&buf, "// Run go generate from src/runtime to update.")
25 fmt.Fprintln(&buf, "// See mkfastlog2table.go for comments.")
26 fmt.Fprintln(&buf)
27 fmt.Fprintln(&buf, "package runtime")
28 fmt.Fprintln(&buf)
29 fmt.Fprintln(&buf, "const fastlogNumBits =", fastlogNumBits)
30 fmt.Fprintln(&buf)
32 fmt.Fprintln(&buf, "var fastlog2Table = [1<<fastlogNumBits + 1]float64{")
33 table := computeTable()
34 for _, t := range table {
35 fmt.Fprintf(&buf, "\t%v,\n", t)
37 fmt.Fprintln(&buf, "}")
39 if err := ioutil.WriteFile("fastlog2table.go", buf.Bytes(), 0644); err != nil {
40 log.Fatalln(err)
44 const fastlogNumBits = 5
46 func computeTable() []float64 {
47 fastlog2Table := make([]float64, 1<<fastlogNumBits+1)
48 for i := 0; i <= (1 << fastlogNumBits); i++ {
49 fastlog2Table[i] = math.Log2(1.0 + float64(i)/(1<<fastlogNumBits))
51 return fastlog2Table