Skip to content

Commit

Permalink
binary size optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
HattoriHanzo031 committed Sep 8, 2023
1 parent 565a24d commit 9a315e8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/runtime/gc_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ package runtime

import (
"internal/task"
"math/bits"
"runtime/interrupt"
"unsafe"
)
Expand Down Expand Up @@ -80,6 +79,20 @@ const (
// turned into variable and assigned using inline function.
const blockStateByteAllTails = uint8(blockStateTail<<(stateBits*3) | blockStateTail<<(stateBits*2) | blockStateTail<<(stateBits*1) | blockStateTail<<(stateBits*0))

const len6tab = "" +
"\x00\x01\x02\x02\x03\x03\x03\x03\x04\x04\x04\x04\x04\x04\x04\x04" +
"\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" +
"\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06" +
"\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06"

// leadingZeros6 returns the number of leading zero bits in x; the result is 6 for x == 0.
func leadingZeros6(x uint8) int { return 6 - len6(x) }

// len6 returns the minimum number of bits required to represent x; the result is 0 for x == 0.
func len6(x uint8) int {
return int(len6tab[x])
}

// String returns a human-readable version of the block state, for debugging.
func (s blockState) String() string {
switch s {
Expand Down Expand Up @@ -151,7 +164,7 @@ func (b gcBlock) findHead() gcBlock {
// at this point stateByte is set to the first state byte of the object that we encountered which is not all tails
// and all tail bits in it are turned to zero. We count number of bytes that are 0 (tail) using LeadingZeros8
// and divide it by stateBits to get the number of tail blocks in state bits.
b -= gcBlock(bits.LeadingZeros8(stateByte) / stateBits)
b -= gcBlock(leadingZeros6(stateByte>>2) / stateBits)

if gcAsserts {
if b.state() != blockStateHead && b.state() != blockStateMark {
Expand Down

0 comments on commit 9a315e8

Please sign in to comment.