Source File
mpallocbits.go
Belonging Package
runtime
package runtime
import (
)
type pageBits [pallocChunkPages / 64]uint64
.set()
return
:= + - 1
if /64 == /64 {
[/64] |= ((uint64(1) << ) - 1) << ( % 64)
return
}
[/64] |= (uint64(1) << (%64 + 1)) - 1
}
.clear()
return
:= + - 1
if /64 == /64 {
[/64] &^= ((uint64(1) << ) - 1) << ( % 64)
return
}
[/64] &^= ^uint64(0) << ( % 64)
for := /64 + 1; < /64; ++ {
[] = 0
[/64] &^= (uint64(1) << (%64 + 1)) - 1
}
func ( *pageBits) () {
for := range {
[] = 0
}
}
func ( *pageBits) (, uint) ( uint) {
if == 1 {
return uint(([/64] >> ( % 64)) & 1)
}
_ = [/64]
:= + - 1
if /64 == /64 {
return uint(sys.OnesCount64(([/64] >> ( % 64)) & ((1 << ) - 1)))
}
_ = [/64]
+= uint(sys.OnesCount64([/64] >> ( % 64)))
for := /64 + 1; < /64; ++ {
+= uint(sys.OnesCount64([]))
}
+= uint(sys.OnesCount64([/64] & ((1 << (%64 + 1)) - 1)))
return
}
type pallocBits pageBits
func ( *pallocBits) () pallocSum {
var , , uint
const = ^uint(0) // sentinel for start value
=
for := 0; < len(); ++ {
:= []
if == 0 {
+= 64
continue
}
:= uint(sys.TrailingZeros64())
:= uint(sys.LeadingZeros64())
+=
if == {
=
}
if > {
=
=
}
const = uint(64 * len())
return packPallocSum(, , )
}
if > {
=
}
return packPallocSum(, , )
:
for := 0; < len(); ++ {
:= []
>>= sys.TrailingZeros64() & 63
if &(+1) == 0 { // no more zeros (except at the top).
continue
}
:= // number of zeros we still need to shrink by.
:= uint(1) // current minimum length of runs of ones in x.
for > 0 {
|= >> ( & 63)
if &(+1) == 0 { // no more zeros (except at the top).
continue
}
break
|= >> ( & 63)
if &(+1) == 0 { // no more zeros (except at the top).
continue
}
*= 2
}
:= uint(sys.TrailingZeros64(^)) // count contiguous trailing ones
>>= & 63 // remove trailing ones
= uint(sys.TrailingZeros64()) // count contiguous trailing zeros
>>= & 63 // remove zeros
+= // we have a new maximum!
if &(+1) == 0 { // no more zeros (except at the top).
continue
}
= // remove j more zeros from each zero run.
}
}
return packPallocSum(, , )
}
func ( *pallocBits) ( uintptr, uint) (uint, uint) {
if == 1 {
:= .find1()
return ,
} else if <= 64 {
return .findSmallN(, )
}
return .findLargeN(, )
}
func ( *pallocBits) ( uint) uint {
_ = [0] // lift nil check out of loop
for := / 64; < uint(len()); ++ {
:= []
if ^ == 0 {
continue
}
return *64 + uint(sys.TrailingZeros64(^))
}
return ^uint(0)
}
= *64 + uint(sys.TrailingZeros64(^))
}
:= uint(sys.TrailingZeros64())
if + >= uint() {
return *64 - ,
:= findBitRange64(^, uint())
if < 64 {
return *64 + ,
}
= uint(sys.LeadingZeros64())
}
return ^uint(0),
}
= *64 + uint(sys.TrailingZeros64(^))
}
if == 0 {
= uint(sys.LeadingZeros64())
= *64 + 64 -
continue
}
:= uint(sys.TrailingZeros64())
if + >= uint() {
+=
return ,
}
if < 64 {
= uint(sys.LeadingZeros64())
= *64 + 64 -
continue
}
+= 64
}
if < uint() {
return ^uint(0),
}
return ,
}
func ( *pallocBits) (, uint) {
(*pageBits)().setRange(, )
}
func ( *pallocBits) () {
(*pageBits)().setAll()
}
func ( *pallocBits) ( uint) {
(*pageBits)().clear()
}
func ( *pallocBits) (, uint) {
(*pageBits)().clearRange(, )
}
func ( *pallocBits) () {
(*pageBits)().clearAll()
}
func ( *pallocBits) ( uint) uint64 {
return (*pageBits)().block64()
}
:= - 1 // number of 1s we want to remove.
:= uint(1) // current minimum width of runs of 0 in c.
for > 0 {
&= >> ( & 63)
break
&= >> ( & 63)
if == 0 {
return 64
}
*= 2
return uint(sys.TrailingZeros64())
}
type pallocData struct {
pallocBits
scavenged pageBits
}
.pallocBits.allocRange(, )
.scavenged.clearRange(, )
}
.pallocBits.allocAll()
.scavenged.clearAll()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |