Add 'compiler/rustc_codegen_gcc/' from commit 'afae271d5d
'
git-subtree-dir: compiler/rustc_codegen_gcc git-subtree-mainline:ae90dcf020
git-subtree-split:afae271d5d
This commit is contained in:
commit
f7237f16ae
80 changed files with 15608 additions and 0 deletions
66
compiler/rustc_codegen_gcc/tests/run/asm.rs
Normal file
66
compiler/rustc_codegen_gcc/tests/run/asm.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
// Compiler:
|
||||
//
|
||||
// Run-time:
|
||||
// status: 0
|
||||
|
||||
#![feature(asm, global_asm)]
|
||||
|
||||
global_asm!("
|
||||
.global add_asm
|
||||
add_asm:
|
||||
mov rax, rdi
|
||||
add rax, rsi
|
||||
ret"
|
||||
);
|
||||
|
||||
extern "C" {
|
||||
fn add_asm(a: i64, b: i64) -> i64;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
asm!("nop");
|
||||
}
|
||||
|
||||
let x: u64;
|
||||
unsafe {
|
||||
asm!("mov $5, {}",
|
||||
out(reg) x,
|
||||
options(att_syntax)
|
||||
);
|
||||
}
|
||||
assert_eq!(x, 5);
|
||||
|
||||
let x: u64;
|
||||
let input: u64 = 42;
|
||||
unsafe {
|
||||
asm!("mov {input}, {output}",
|
||||
"add $1, {output}",
|
||||
input = in(reg) input,
|
||||
output = out(reg) x,
|
||||
options(att_syntax)
|
||||
);
|
||||
}
|
||||
assert_eq!(x, 43);
|
||||
|
||||
let x: u64;
|
||||
unsafe {
|
||||
asm!("mov {}, 6",
|
||||
out(reg) x,
|
||||
);
|
||||
}
|
||||
assert_eq!(x, 6);
|
||||
|
||||
let x: u64;
|
||||
let input: u64 = 42;
|
||||
unsafe {
|
||||
asm!("mov {output}, {input}",
|
||||
"add {output}, 1",
|
||||
input = in(reg) input,
|
||||
output = out(reg) x,
|
||||
);
|
||||
}
|
||||
assert_eq!(x, 43);
|
||||
|
||||
assert_eq!(unsafe { add_asm(40, 2) }, 42);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue