Skip to content

Instantly share code, notes, and snippets.

@dns2utf8
Created May 28, 2020 11:17
Show Gist options
  • Save dns2utf8/421a51d04551cb21728a329c091f110e to your computer and use it in GitHub Desktop.
Save dns2utf8/421a51d04551cb21728a329c091f110e to your computer and use it in GitHub Desktop.
#![feature(test)]
use std::hint::black_box;
#[inline(never)]
fn calc1(n: u32) -> u32 {
n * n
}
#[inline(never)]
fn calc2(n: u32) -> u32 {
n.pow(2)
}
fn main() {
let input = black_box(7);
let _a = calc1(input);
let _b = calc2(input);
println!("{} {}", _a, _b);
}
@dns2utf8
Copy link
Author

Run on play.rust-lang.org

...

playground::calc1: # @playground::calc1
# %bb.0:
	movl	%edi, %eax
	imull	%edi, %eax
	retq
                                        # -- End function

playground::main: # @playground::main
# %bb.0:
	pushq	%rbx
	subq	$96, %rsp
	movl	$7, 16(%rsp)
	leaq	16(%rsp), %rax
	#APP
	#NO_APP
	movl	16(%rsp), %ebx
	movl	%ebx, %edi
	callq	playground::calc1
	movl	%eax, 8(%rsp)
	movl	%ebx, %edi
	callq	playground::calc1
	movl	%eax, 12(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 64(%rsp)

...

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