FAQ
Same issue as https://github.com/golang/go/issues/14504. Can you include
update the bug with this test case?

imulq needs the multiplicand (second argument) to be %rax. In order to do
this the compiler copies %rdx in %rax. The problem here is that the load is
done in %rdx instead of %rax.

joi, 3 martie 2016, 15:25:03 UTC+1, Adam Strzelecki a scris:
Just playing around with ssa.dev branch. Looks like the code is about ~10%
faster than 1.6 in some artificial benchmarks, binaries are ~%5 smaller.
Great job! FYI compilation is unfortunately about ~10% slower compiling
some larger project like Gogs.

Anyways, just reading generated x86-64 assembly for simple recursive
factorial I spotted some weird unnecessary register copy.

func Fac(n int64) int64 {
if n < 2 {
return 1
}
return n * Fac(n-1)
}

In its assembly starting 404e070 n is loaded into RDX then immediately
gets copied to RAX, but RDX is later not used at all. Can we just load
directly into RAX? Or it is done for some purpose? (prefetch friendly, etc.
etc.)

In 1.6 assembly there's no such thing. Obviously it is not big deal, but
maybe it is a hint for some problem in SSA register allocation?

github.com/nanoant/gotests/fib.Fac:
000000000404e040 movq %gs:0x8a0, %rcx
000000000404e049 cmpq 0x10(%rcx), %rsp
000000000404e04d jbe 0x404e094
000000000404e04f subq $0x10, %rsp
000000000404e053 movq 0x18(%rsp), %rcx
000000000404e058 cmpq $0x2, %rcx
000000000404e05c jl 0x404e086
000000000404e05e leaq -0x1(%rcx), %rax
000000000404e062 movq %rax, (%rsp)
000000000404e066 callq "github.com/nanoant/gotests/fib.Fac"
000000000404e06b movq 0x8(%rsp), %rcx // Fac(n-1) result


*000000000404e070 movq 0x18(%rsp), %rdx // n loaded again into
RDX000000000404e075 movq %rdx, %rax // immidiately copied
to RAX <-- do we need that?000000000404e078 imulq %rcx, %**rax
// RAX used for multiplication, RDX not used anymore*
000000000404e07c movq %rax, 0x20(%rsp)
000000000404e081 addq $0x10, %rsp
000000000404e085 retq
000000000404e086 movq $0x1, 0x20(%rsp)
000000000404e08f addq $0x10, %rsp
000000000404e093 retq
000000000404e094 callq runtime.morestack_noctxt
000000000404e099 jmp "github.com/nanoant/gotests/fib.Fac"

Cheers,
-- Adam
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
groupgolang-dev @
categoriesgo
postedMar 3, '16 at 2:25p
activeMar 3, '16 at 7:38p
posts3
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase