• Rick Hudson's avatar
    [dev.garbage] runtime: add bit and cache ctz64 (count trailing zero) · 40934815
    Rick Hudson authored
    Add to each span a 64 bit cache (allocCache) of the allocBits
    at freeindex. allocCache is shifted such that the lowest bit
    corresponds to the bit freeindex. allocBits uses a 0 to
    indicate an object is free, on the other hand allocCache
    uses a 1 to indicate an object is free. This facilitates
    ctz64 (count trailing zero) which counts the number of 0s
    trailing the least significant 1. This is also the index of
    the least significant 1.
    
    Each span maintains a freeindex indicating the boundary
    between allocated objects and unallocated objects. allocCache
    is shifted as freeindex is incremented such that the low bit
    in allocCache corresponds to the bit a freeindex in the
    allocBits array.
    
    Currently ctz64 is written in Go using a for loop so it is
    not very efficient. Use of the hardware instruction will
    follow. With this in mind comparisons of the garbage
    benchmark are as follows.
    
    1.6 release        2.8 seconds
    dev:garbage branch 3.1 seconds.
    
    Profiling shows the go implementation of ctz64 takes up
    1% of the total time.
    
    Change-Id: If084ed9c3b1eda9f3c6ab2e794625cb870b8167f
    Reviewed-on: https://go-review.googlesource.com/20200Reviewed-by: default avatarAustin Clements <austin@google.com>
    40934815
malloc.go 30.9 KB