Auto merge of #77292 - lzutao:std_asm, r=Amanieu

Prefer asm! in std - all in sgx module

Similar to the change in #76669 but all `llvm_asm!` is gate in x86/x86_64 target.
Godbolt:
- https://rust.godbolt.org/z/h7nG1h
- https://rust.godbolt.org/z/xx39hW
This commit is contained in:
bors 2020-09-30 05:27:16 +00:00
commit c0127e4dbf
2 changed files with 24 additions and 16 deletions

View File

@ -21,8 +21,15 @@ extern "C" {
#[inline(always)] #[inline(always)]
#[unstable(feature = "sgx_platform", issue = "56975")] #[unstable(feature = "sgx_platform", issue = "56975")]
pub fn image_base() -> u64 { pub fn image_base() -> u64 {
let base; let base: u64;
unsafe { llvm_asm!("lea IMAGE_BASE(%rip),$0":"=r"(base)) }; unsafe {
asm!(
"lea IMAGE_BASE(%rip), {}",
lateout(reg) base,
// NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
options(att_syntax, nostack, preserves_flags, nomem, pure),
)
};
base base
} }

View File

@ -31,13 +31,13 @@ pub fn egetkey(request: &Align512<[u8; 512]>) -> Result<Align16<[u8; 16]>, u32>
let mut out = MaybeUninit::uninit(); let mut out = MaybeUninit::uninit();
let error; let error;
llvm_asm!( asm!(
"enclu" "enclu",
: "={eax}"(error) inlateout("eax") ENCLU_EGETKEY => error,
: "{eax}"(ENCLU_EGETKEY), in("rbx") request,
"{rbx}"(request), in("rcx") out.as_mut_ptr(),
"{rcx}"(out.as_mut_ptr()) // NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
: "flags" options(att_syntax, nostack),
); );
match error { match error {
@ -60,13 +60,14 @@ pub fn ereport(
unsafe { unsafe {
let mut report = MaybeUninit::uninit(); let mut report = MaybeUninit::uninit();
llvm_asm!( asm!(
"enclu" "enclu",
: /* no output registers */ in("eax") ENCLU_EREPORT,
: "{eax}"(ENCLU_EREPORT), in("rbx") targetinfo,
"{rbx}"(targetinfo), in("rcx") reportdata,
"{rcx}"(reportdata), in("rdx") report.as_mut_ptr(),
"{rdx}"(report.as_mut_ptr()) // NOTE(#76738): ATT syntax is used to support LLVM 8 and 9.
options(att_syntax, preserves_flags, nostack),
); );
report.assume_init() report.assume_init()