Skip to content

Instantly share code, notes, and snippets.

@Zheaoli
Created September 21, 2022 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zheaoli/ae1a914d4b6923dc4112e1f5a4c07b1f to your computer and use it in GitHub Desktop.
Save Zheaoli/ae1a914d4b6923dc4112e1f5a4c07b1f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func Absdiff1(x, y int) int {
if x > y {
return x - y
}
return y - x
}
func Absdiff2(x, y int) int {
rval := y - x
eval := x - y
etest := x > y
if etest {
rval = eval
}
return rval
}
func main() {
fmt.Print(Absdiff1(1, 2))
fmt.Print(Absdiff2(1, 2))
}
@Zheaoli
Copy link
Author

Zheaoli commented Sep 21, 2022

_main.Absdiff1:
00000000010936a0	cmpq	%rax, %rbx
00000000010936a3	jge	0x10936a9
00000000010936a5	subq	%rbx, %rax
00000000010936a8	retq
00000000010936a9	subq	%rax, %rbx
00000000010936ac	movq	%rbx, %rax
00000000010936af	retq
_main.Absdiff2:
00000000010936c0	movq	%rbx, %rcx
00000000010936c3	subq	%rax, %rbx
00000000010936c6	movq	%rax, %rdx
00000000010936c9	subq	%rcx, %rax
00000000010936cc	cmpq	%rdx, %rcx
00000000010936cf	cmovlq	%rax, %rbx
00000000010936d3	movq	%rbx, %rax
00000000010936d6	retq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment