On Sat, Sep 21, 2013 at 5:19 PM, Michael Jones <
m...@google.com> wrote:
> Personally I wish for integer powers in the language. Much as I wish for
> min() and max() in the language: calling the function can be as expensive as
> doing the operation.
Theres fortunately no call, it's inlined (release 1.1.2/Linux/x86_64):
jnml@r630 ~/src/tmp $ ls
main.go
jnml@r630 ~/src/tmp $ cat main.go
package main
import (
"fmt"
)
func max(a, b int) int {
if a > b {
return a
}
return b
}
func main() {
fmt.Println(max(0xaaaa, 0xbbbb))
}
jnml@r630 ~/src/tmp $ go build && ls
main.go tmp
jnml@r630 ~/src/tmp $ gdb tmp
GNU gdb (GDB) 7.5.91.20130417-cvs-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<
http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jnml/src/tmp/tmp...done.
warning: File "/home/jnml/go/src/pkg/runtime/runtime-gdb.py"
auto-loading has been declined by your `auto-load safe-path' set to
"$debugdir:$datadir/auto-load".
To enable execution of this file add
add-auto-load-safe-path /home/jnml/go/src/pkg/runtime/runtime-gdb.py
line to your configuration file "/home/jnml/.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "/home/jnml/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
(gdb) b main.main
Breakpoint 1 at 0x400c00: file /home/jnml/src/tmp/main.go, line 15.
(gdb) r
Starting program: /home/jnml/src/tmp/tmp
warning: no loadable sections found in added symbol-file
system-supplied DSO at 0x7ffff7ffd000
Breakpoint 1, main.main () at /home/jnml/src/tmp/main.go:15
15 func main() {
(gdb) disassemble /m
Dump of assembler code for function main.main:
15 func main() {
=> 0x0000000000400c00 <+0>: mov %fs:0xfffffffffffffff0,%rcx
0x0000000000400c09 <+9>: cmp (%rcx),%rsp
0x0000000000400c0c <+12>: ja 0x400c13 <main.main+19>
0x0000000000400c0e <+14>: callq 0x41e3c0 <runtime.morestack00>
0x0000000000400c13 <+19>: sub $0x60,%rsp
16 fmt.Println(max(0xaaaa, 0xbbbb))
0x0000000000400c17 <+23>: mov $0xaaaa,%rcx
0x0000000000400c1e <+30>: mov $0xbbbb,%rax
0x0000000000400c25 <+37>: cmp %rax,%rcx
0x0000000000400c28 <+40>: jle 0x400c86 <main.main+134>
0x0000000000400c2a <+42>: lea 0x50(%rsp),%rdi
0x0000000000400c2f <+47>: xor %rax,%rax
0x0000000000400c32 <+50>: stos %rax,%es:(%rdi)
0x0000000000400c34 <+52>: stos %rax,%es:(%rdi)
0x0000000000400c36 <+54>: lea 0x50(%rsp),%rbx
0x0000000000400c3b <+59>: mov %rbx,0x30(%rsp)
0x0000000000400c40 <+64>: mov 0x30(%rsp),%rbx
0x0000000000400c45 <+69>: mov $0x1,%rsi
0x0000000000400c4c <+76>: mov $0x1,%rdx
0x0000000000400c53 <+83>: mov %rbx,0x38(%rsp)
0x0000000000400c58 <+88>: mov 0x38(%rsp),%rbx
0x0000000000400c5d <+93>: mov $0x4815c0,%eax
0x0000000000400c62 <+98>: mov %rax,(%rbx)
0x0000000000400c65 <+101>: mov %rcx,0x8(%rbx)
0x0000000000400c69 <+105>: mov 0x38(%rsp),%rbx
0x0000000000400c6e <+110>: mov %rbx,(%rsp)
0x0000000000400c72 <+114>: mov %rsi,0x8(%rsp)
0x0000000000400c77 <+119>: mov %rdx,0x10(%rsp)
0x0000000000400c7c <+124>: callq 0x421e30 <fmt.Println>
0x0000000000400c86 <+134>: mov %rax,%rcx
0x0000000000400c89 <+137>: jmp 0x400c2a <main.main+42>
0x0000000000400c8b <+139>: add %al,(%rax)
0x0000000000400c8d <+141>: add %al,(%rax)
0x0000000000400c8f <+143>: add %ah,-0x75(%rax,%rcx,2)
17 }
0x0000000000400c81 <+129>: add $0x60,%rsp
0x0000000000400c85 <+133>: retq
End of assembler dump.
(gdb)
-j