Skip to content

Commit

Permalink
Migrate inline assembly incremental tests to asm!
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Jan 12, 2022
1 parent cc20dd4 commit 02e6c64
Showing 1 changed file with 53 additions and 77 deletions.
130 changes: 53 additions & 77 deletions src/test/incremental/hashes/inline_asm.rs
Expand Up @@ -18,23 +18,19 @@

#![allow(warnings)]
#![feature(rustc_attrs)]
#![feature(llvm_asm)]
#![crate_type="rlib"]


use std::arch::asm;

// Change template
#[cfg(any(cfail1,cfail4))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn change_template(a: i32) -> i32 {
pub fn change_template(_a: i32) -> i32 {
let c: i32;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(c)
: "0"(a)
:
:
);
asm!("mov {0}, 1",
out(reg) c
);
}
c
}
Expand All @@ -45,15 +41,12 @@ pub fn change_template(a: i32) -> i32 {
#[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
#[rustc_clean(cfg="cfail6")]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn change_template(a: i32) -> i32 {
pub fn change_template(_a: i32) -> i32 {
let c: i32;
unsafe {
llvm_asm!("add 2, $0"
: "=r"(c)
: "0"(a)
:
:
);
asm!("mov {0}, 2",
out(reg) c
);
}
c
}
Expand All @@ -67,12 +60,10 @@ pub fn change_output(a: i32) -> i32 {
let mut _out1: i32 = 0;
let mut _out2: i32 = 0;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out1)
: "0"(a)
:
:
);
asm!("mov {0}, {1}",
out(reg) _out1,
in(reg) a
);
}
_out1
}
Expand All @@ -87,12 +78,10 @@ pub fn change_output(a: i32) -> i32 {
let mut _out1: i32 = 0;
let mut _out2: i32 = 0;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out2)
: "0"(a)
:
:
);
asm!("mov {0}, {1}",
out(reg) _out2,
in(reg) a
);
}
_out1
}
Expand All @@ -105,12 +94,10 @@ pub fn change_output(a: i32) -> i32 {
pub fn change_input(_a: i32, _b: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "0"(_a)
:
:
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _a
);
}
_out
}
Expand All @@ -124,12 +111,10 @@ pub fn change_input(_a: i32, _b: i32) -> i32 {
pub fn change_input(_a: i32, _b: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "0"(_b)
:
:
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _b
);
}
_out
}
Expand All @@ -142,12 +127,10 @@ pub fn change_input(_a: i32, _b: i32) -> i32 {
pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "0"(_a), "r"(_b)
:
:
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _a,
in("eax") _b);
}
_out
}
Expand All @@ -161,30 +144,26 @@ pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "r"(_a), "0"(_b)
:
:
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _a,
in("ecx") _b);
}
_out
}



// Change clobber
#[cfg(any(cfail1,cfail4))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn change_clobber(_a: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "0"(_a)
:/*--*/
:
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _a,
lateout("ecx") _
);
}
_out
}
Expand All @@ -198,12 +177,11 @@ pub fn change_clobber(_a: i32) -> i32 {
pub fn change_clobber(_a: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "0"(_a)
: "eax"
:
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _a,
lateout("edx") _
);
}
_out
}
Expand All @@ -216,12 +194,11 @@ pub fn change_clobber(_a: i32) -> i32 {
pub fn change_options(_a: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "0"(_a)
:
:/*-------*/
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _a,
options(readonly),
);
}
_out
}
Expand All @@ -235,12 +212,11 @@ pub fn change_options(_a: i32) -> i32 {
pub fn change_options(_a: i32) -> i32 {
let _out;
unsafe {
llvm_asm!("add 1, $0"
: "=r"(_out)
: "0"(_a)
:
: "volatile"
);
asm!("mov {0}, {1}",
out(reg) _out,
in(reg) _a,
options(nomem ),
);
}
_out
}

0 comments on commit 02e6c64

Please sign in to comment.