github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/compile/test/testdata/pgo/inline/inline_hot.go (about) 1 // Copyright 2022 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. 4 5 // WARNING: Please avoid updating this file. If this file needs to be updated, 6 // then a new inline_hot.pprof file should be generated: 7 // 8 // $ cd $GOROOT/src/github.com/go-asm/go/cmd/compile/test/testdata/pgo/inline/ 9 // $ go test -bench=. -cpuprofile ./inline_hot.pprof 10 package main 11 12 import ( 13 "time" 14 ) 15 16 type BS struct { 17 length uint 18 s []uint64 19 } 20 21 const wSize = uint(64) 22 const lWSize = uint(6) 23 24 func D(i uint) int { 25 return int((i + (wSize - 1)) >> lWSize) 26 } 27 28 func N(length uint) (bs *BS) { 29 bs = &BS{ 30 length, 31 make([]uint64, D(length)), 32 } 33 34 return bs 35 } 36 37 func (b *BS) S(i uint) *BS { 38 b.s[i>>lWSize] |= 1 << (i & (wSize - 1)) 39 return b 40 } 41 42 var jn = [...]byte{ 43 0, 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4, 44 62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5, 45 63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11, 46 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6, 47 } 48 49 func T(v uint64) uint { 50 return uint(jn[((v&-v)*0x03f79d71b4ca8b09)>>58]) 51 } 52 53 func (b *BS) NS(i uint) (uint, bool) { 54 x := int(i >> lWSize) 55 if x >= len(b.s) { 56 return 0, false 57 } 58 w := b.s[x] 59 w = w >> (i & (wSize - 1)) 60 if w != 0 { 61 return i + T(w), true 62 } 63 x = x + 1 64 for x < len(b.s) { 65 if b.s[x] != 0 { 66 return uint(x)*wSize + T(b.s[x]), true 67 } 68 x = x + 1 69 70 } 71 return 0, false 72 } 73 74 func A() { 75 s := N(100000) 76 for i := 0; i < 1000; i += 30 { 77 s.S(uint(i)) 78 } 79 for j := 0; j < 1000; j++ { 80 c := uint(0) 81 for i, e := s.NS(0); e; i, e = s.NS(i + 1) { 82 c++ 83 } 84 } 85 } 86 87 func main() { 88 time.Sleep(time.Second) 89 A() 90 }