• Josh Bleecher Snyder's avatar
    cmd/compile: use intrinsic for LeadingZeros8 on amd64 · c5f0104d
    Josh Bleecher Snyder authored
    The previous change sped up the pure computation form of LeadingZeros8.
    This places it somewhat close to the table lookup form.
    Depending on something that varies from toolchain to toolchain
    (alignment, perhaps?), the slowdown from ditching the table lookup
    is either 20% or 5%.
    
    This benchmark is the best case scenario for the table lookup:
    It is in the L1 cache already.
    
    I think we're close enough that we can switch to the computational version,
    and trust that the memory effects and binary size savings will be worth it.
    
    Code:
    
    func f8(x uint8)   { z = bits.LeadingZeros8(x) }
    
    Before:
    
    "".f8 STEXT nosplit size=34 args=0x8 locals=0x0
    	0x0000 00000 (x.go:7)	TEXT	"".f8(SB), NOSPLIT, $0-8
    	0x0000 00000 (x.go:7)	FUNCDATA	$0, gclocals·2a5305abe05176240e61b8620e19a815(SB)
    	0x0000 00000 (x.go:7)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
    	0x0000 00000 (x.go:7)	MOVBLZX	"".x+8(SP), AX
    	0x0005 00005 (x.go:7)	MOVBLZX	AL, AX
    	0x0008 00008 (x.go:7)	LEAQ	math/bits.len8tab(SB), CX
    	0x000f 00015 (x.go:7)	MOVBLZX	(CX)(AX*1), AX
    	0x0013 00019 (x.go:7)	ADDQ	$-8, AX
    	0x0017 00023 (x.go:7)	NEGQ	AX
    	0x001a 00026 (x.go:7)	MOVQ	AX, "".z(SB)
    	0x0021 00033 (x.go:7)	RET
    
    After:
    
    "".f8 STEXT nosplit size=30 args=0x8 locals=0x0
    	0x0000 00000 (x.go:7)	TEXT	"".f8(SB), NOSPLIT, $0-8
    	0x0000 00000 (x.go:7)	FUNCDATA	$0, gclocals·2a5305abe05176240e61b8620e19a815(SB)
    	0x0000 00000 (x.go:7)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
    	0x0000 00000 (x.go:7)	MOVBLZX	"".x+8(SP), AX
    	0x0005 00005 (x.go:7)	MOVBLZX	AL, AX
    	0x0008 00008 (x.go:7)	LEAL	1(AX)(AX*1), AX
    	0x000c 00012 (x.go:7)	BSRL	AX, AX
    	0x000f 00015 (x.go:7)	ADDQ	$-8, AX
    	0x0013 00019 (x.go:7)	NEGQ	AX
    	0x0016 00022 (x.go:7)	MOVQ	AX, "".z(SB)
    	0x001d 00029 (x.go:7)	RET
    
    Change-Id: Icc7db50a7820fb9a3da8a816d6b6940d7f8e193e
    Reviewed-on: https://go-review.googlesource.com/108942
    Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarKeith Randall <khr@golang.org>
    c5f0104d
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
context Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
plugin Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang_org/x Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
cmp.bash Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
naclmake.bash Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...