Use AT&T syntax to support LLVM 10

This commit is contained in:
Amanieu d'Antras 2021-05-07 22:58:08 +01:00
parent 8a2936b9a2
commit 994a4250a9
4 changed files with 30 additions and 30 deletions

View file

@ -8,12 +8,12 @@ use stdarch_test::assert_instr;
pub unsafe fn _bittest(p: *const i32, b: i32) -> u8 {
let r: u8;
asm!(
"bt [{p}], {b:e}",
"btl {b:e}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(readonly, nostack, pure)
options(readonly, nostack, pure, att_syntax)
);
r
}
@ -25,12 +25,12 @@ pub unsafe fn _bittest(p: *const i32, b: i32) -> u8 {
pub unsafe fn _bittestandset(p: *mut i32, b: i32) -> u8 {
let r: u8;
asm!(
"bts [{p}], {b:e}",
"btsl {b:e}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(nostack)
options(nostack, att_syntax)
);
r
}
@ -42,12 +42,12 @@ pub unsafe fn _bittestandset(p: *mut i32, b: i32) -> u8 {
pub unsafe fn _bittestandreset(p: *mut i32, b: i32) -> u8 {
let r: u8;
asm!(
"btr [{p}], {b:e}",
"btrl {b:e}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(nostack)
options(nostack, att_syntax)
);
r
}
@ -59,12 +59,12 @@ pub unsafe fn _bittestandreset(p: *mut i32, b: i32) -> u8 {
pub unsafe fn _bittestandcomplement(p: *mut i32, b: i32) -> u8 {
let r: u8;
asm!(
"btc [{p}], {b:e}",
"btcl {b:e}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(nostack)
options(nostack, att_syntax)
);
r
}

View file

@ -61,27 +61,27 @@ pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
#[cfg(target_arch = "x86")]
{
asm!(
"mov {0}, ebx",
"movl %ebx, {0}",
"cpuid",
"xchg {0}, ebx",
"xchgl %ebx, {0}",
lateout(reg) ebx,
inlateout("eax") leaf => eax,
inlateout("ecx") sub_leaf => ecx,
lateout("edx") edx,
options(nostack, preserves_flags),
options(nostack, preserves_flags, att_syntax),
);
}
#[cfg(target_arch = "x86_64")]
{
asm!(
"mov {0:r}, rbx",
"movq %rbx, {0:r}",
"cpuid",
"xchg {0:r}, rbx",
"xchgq %rbx, {0:r}",
lateout(reg) ebx,
inlateout("eax") leaf => eax,
inlateout("ecx") sub_leaf => ecx,
lateout("edx") edx,
options(nostack, preserves_flags),
options(nostack, preserves_flags, att_syntax),
);
}
CpuidResult { eax, ebx, ecx, edx }
@ -130,9 +130,9 @@ pub fn has_cpuid() -> bool {
// Read eflags and save a copy of it
"pushfd",
"pop {result}",
"mov {saved_flags}, {result}",
"mov {result}, {saved_flags}",
// Flip 21st bit of the flags
"xor {result}, 0x200000",
"xor $0x200000, {result}",
// Load the modified flags and read them back.
// Bit 21 can only be modified if cpuid is available.
"push {result}",
@ -140,10 +140,10 @@ pub fn has_cpuid() -> bool {
"pushfd",
"pop {result}",
// Use xor to find out whether bit 21 has changed
"xor {result}, {saved_flags}",
"xor {saved_flags}, {result}",
result = out(reg) result,
saved_flags = out(reg) _,
options(nomem),
options(nomem, att_syntax),
);
// There is a race between popfd (A) and pushfd (B)
// where other bits beyond 21st may have been modified due to

View file

@ -13,7 +13,7 @@
#[doc(hidden)]
pub unsafe fn __readeflags() -> u32 {
let eflags: u32;
asm!("pushfd", "pop {}", out(reg) eflags, options(nomem));
asm!("pushfd", "pop {}", out(reg) eflags, options(nomem, att_syntax));
eflags
}
@ -30,7 +30,7 @@ pub unsafe fn __readeflags() -> u32 {
#[doc(hidden)]
pub unsafe fn __readeflags() -> u64 {
let eflags: u64;
asm!("pushfq", "pop {}", out(reg) eflags, options(nomem));
asm!("pushfq", "pop {}", out(reg) eflags, options(nomem, att_syntax));
eflags
}
@ -46,7 +46,7 @@ pub unsafe fn __readeflags() -> u64 {
)]
#[doc(hidden)]
pub unsafe fn __writeeflags(eflags: u32) {
asm!("push {}", "popfd", in(reg) eflags, options(nomem));
asm!("push {}", "popfd", in(reg) eflags, options(nomem, att_syntax));
}
/// Write EFLAGS.
@ -61,7 +61,7 @@ pub unsafe fn __writeeflags(eflags: u32) {
)]
#[doc(hidden)]
pub unsafe fn __writeeflags(eflags: u64) {
asm!("push {}", "popfq", in(reg) eflags, options(nomem));
asm!("push {}", "popfq", in(reg) eflags, options(nomem, att_syntax));
}
#[cfg(test)]

View file

@ -8,12 +8,12 @@ use stdarch_test::assert_instr;
pub unsafe fn _bittest64(p: *const i64, b: i64) -> u8 {
let r: u8;
asm!(
"bt [{p}], {b}",
"btq {b}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(readonly, nostack, pure)
options(readonly, nostack, pure, att_syntax)
);
r
}
@ -25,12 +25,12 @@ pub unsafe fn _bittest64(p: *const i64, b: i64) -> u8 {
pub unsafe fn _bittestandset64(p: *mut i64, b: i64) -> u8 {
let r: u8;
asm!(
"bts [{p}], {b}",
"btsq {b}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(nostack)
options(nostack, att_syntax)
);
r
}
@ -42,12 +42,12 @@ pub unsafe fn _bittestandset64(p: *mut i64, b: i64) -> u8 {
pub unsafe fn _bittestandreset64(p: *mut i64, b: i64) -> u8 {
let r: u8;
asm!(
"btr [{p}], {b}",
"btrq {b}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(nostack)
options(nostack, att_syntax)
);
r
}
@ -59,12 +59,12 @@ pub unsafe fn _bittestandreset64(p: *mut i64, b: i64) -> u8 {
pub unsafe fn _bittestandcomplement64(p: *mut i64, b: i64) -> u8 {
let r: u8;
asm!(
"btc [{p}], {b}",
"btcq {b}, ({p})",
"setc {r}",
p = in(reg) p,
b = in(reg) b,
r = out(reg_byte) r,
options(nostack)
options(nostack, att_syntax)
);
r
}