Switch to using `llvm_asm!` instead of `asm!` (#351)
* Switch to using `llvm_asm!` instead of `asm!` * Run rustfmt * Fix how LTO is specified on nightly
This commit is contained in:
parent
25ea08da28
commit
cde22bc180
|
@ -85,9 +85,11 @@ RUSTFLAGS="-C debug-assertions=no" $build_intrinsics --features c --release
|
||||||
if [ -z "$DEBUG_LTO_BUILD_DOESNT_WORK" ]; then
|
if [ -z "$DEBUG_LTO_BUILD_DOESNT_WORK" ]; then
|
||||||
RUSTFLAGS="-C debug-assertions=no" \
|
RUSTFLAGS="-C debug-assertions=no" \
|
||||||
CARGO_INCREMENTAL=0 \
|
CARGO_INCREMENTAL=0 \
|
||||||
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics -- -C lto
|
CARGO_PROFILE_DEV_LTO=true \
|
||||||
|
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics
|
||||||
fi
|
fi
|
||||||
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics --release -- -C lto
|
CARGO_PROFILE_RELEASE_LTO=true \
|
||||||
|
$cargo rustc --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics --release
|
||||||
|
|
||||||
# Ensure no references to a panicking function
|
# Ensure no references to a panicking function
|
||||||
for rlib in $(echo $path); do
|
for rlib in $(echo $path); do
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#![allow(unused_features)]
|
#![allow(unused_features)]
|
||||||
#![cfg_attr(thumb, no_main)]
|
#![cfg_attr(thumb, no_main)]
|
||||||
#![deny(dead_code)]
|
#![deny(dead_code)]
|
||||||
#![feature(asm)]
|
#![feature(llvm_asm)]
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
#![feature(start)]
|
#![feature(start)]
|
||||||
#![feature(allocator_api)]
|
#![feature(allocator_api)]
|
||||||
|
@ -280,7 +280,7 @@ fn run() {
|
||||||
|
|
||||||
// A copy of "test::black_box". Used to prevent LLVM from optimizing away the intrinsics during LTO
|
// A copy of "test::black_box". Used to prevent LLVM from optimizing away the intrinsics during LTO
|
||||||
fn bb<T>(dummy: T) -> T {
|
fn bb<T>(dummy: T) -> T {
|
||||||
unsafe { asm!("" : : "r"(&dummy)) }
|
unsafe { llvm_asm!("" : : "r"(&dummy)) }
|
||||||
dummy
|
dummy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
140
src/arm.rs
140
src/arm.rs
|
@ -8,13 +8,15 @@ use core::intrinsics;
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_uidivmod() {
|
pub unsafe fn __aeabi_uidivmod() {
|
||||||
asm!("push {lr}
|
llvm_asm!("
|
||||||
sub sp, sp, #4
|
push {lr}
|
||||||
mov r2, sp
|
sub sp, sp, #4
|
||||||
bl __udivmodsi4
|
mov r2, sp
|
||||||
ldr r1, [sp]
|
bl __udivmodsi4
|
||||||
add sp, sp, #4
|
ldr r1, [sp]
|
||||||
pop {pc}" ::: "memory" : "volatile");
|
add sp, sp, #4
|
||||||
|
pop {pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,13 +24,15 @@ pub unsafe fn __aeabi_uidivmod() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_uidivmod() {
|
pub unsafe fn __aeabi_uidivmod() {
|
||||||
asm!("push {lr}
|
llvm_asm!("
|
||||||
sub sp, sp, #4
|
push {lr}
|
||||||
mov r2, sp
|
sub sp, sp, #4
|
||||||
bl ___udivmodsi4
|
mov r2, sp
|
||||||
ldr r1, [sp]
|
bl ___udivmodsi4
|
||||||
add sp, sp, #4
|
ldr r1, [sp]
|
||||||
pop {pc}" ::: "memory" : "volatile");
|
add sp, sp, #4
|
||||||
|
pop {pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,15 +40,17 @@ pub unsafe fn __aeabi_uidivmod() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_uldivmod() {
|
pub unsafe fn __aeabi_uldivmod() {
|
||||||
asm!("push {r4, lr}
|
llvm_asm!("
|
||||||
sub sp, sp, #16
|
push {r4, lr}
|
||||||
add r4, sp, #8
|
sub sp, sp, #16
|
||||||
str r4, [sp]
|
add r4, sp, #8
|
||||||
bl __udivmoddi4
|
str r4, [sp]
|
||||||
ldr r2, [sp, #8]
|
bl __udivmoddi4
|
||||||
ldr r3, [sp, #12]
|
ldr r2, [sp, #8]
|
||||||
add sp, sp, #16
|
ldr r3, [sp, #12]
|
||||||
pop {r4, pc}" ::: "memory" : "volatile");
|
add sp, sp, #16
|
||||||
|
pop {r4, pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,15 +58,17 @@ pub unsafe fn __aeabi_uldivmod() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_uldivmod() {
|
pub unsafe fn __aeabi_uldivmod() {
|
||||||
asm!("push {r4, lr}
|
llvm_asm!("
|
||||||
sub sp, sp, #16
|
push {r4, lr}
|
||||||
add r4, sp, #8
|
sub sp, sp, #16
|
||||||
str r4, [sp]
|
add r4, sp, #8
|
||||||
bl ___udivmoddi4
|
str r4, [sp]
|
||||||
ldr r2, [sp, #8]
|
bl ___udivmoddi4
|
||||||
ldr r3, [sp, #12]
|
ldr r2, [sp, #8]
|
||||||
add sp, sp, #16
|
ldr r3, [sp, #12]
|
||||||
pop {r4, pc}" ::: "memory" : "volatile");
|
add sp, sp, #16
|
||||||
|
pop {r4, pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,12 +76,14 @@ pub unsafe fn __aeabi_uldivmod() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_idivmod() {
|
pub unsafe fn __aeabi_idivmod() {
|
||||||
asm!("push {r0, r1, r4, lr}
|
llvm_asm!("
|
||||||
bl __aeabi_idiv
|
push {r0, r1, r4, lr}
|
||||||
pop {r1, r2}
|
bl __aeabi_idiv
|
||||||
muls r2, r2, r0
|
pop {r1, r2}
|
||||||
subs r1, r1, r2
|
muls r2, r2, r0
|
||||||
pop {r4, pc}" ::: "memory" : "volatile");
|
subs r1, r1, r2
|
||||||
|
pop {r4, pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,12 +91,14 @@ pub unsafe fn __aeabi_idivmod() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_idivmod() {
|
pub unsafe fn __aeabi_idivmod() {
|
||||||
asm!("push {r0, r1, r4, lr}
|
llvm_asm!("
|
||||||
bl ___aeabi_idiv
|
push {r0, r1, r4, lr}
|
||||||
pop {r1, r2}
|
bl ___aeabi_idiv
|
||||||
muls r2, r2, r0
|
pop {r1, r2}
|
||||||
subs r1, r1, r2
|
muls r2, r2, r0
|
||||||
pop {r4, pc}" ::: "memory" : "volatile");
|
subs r1, r1, r2
|
||||||
|
pop {r4, pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,15 +106,17 @@ pub unsafe fn __aeabi_idivmod() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_ldivmod() {
|
pub unsafe fn __aeabi_ldivmod() {
|
||||||
asm!("push {r4, lr}
|
llvm_asm!("
|
||||||
sub sp, sp, #16
|
push {r4, lr}
|
||||||
add r4, sp, #8
|
sub sp, sp, #16
|
||||||
str r4, [sp]
|
add r4, sp, #8
|
||||||
bl __divmoddi4
|
str r4, [sp]
|
||||||
ldr r2, [sp, #8]
|
bl __divmoddi4
|
||||||
ldr r3, [sp, #12]
|
ldr r2, [sp, #8]
|
||||||
add sp, sp, #16
|
ldr r3, [sp, #12]
|
||||||
pop {r4, pc}" ::: "memory" : "volatile");
|
add sp, sp, #16
|
||||||
|
pop {r4, pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,15 +124,17 @@ pub unsafe fn __aeabi_ldivmod() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
|
||||||
pub unsafe fn __aeabi_ldivmod() {
|
pub unsafe fn __aeabi_ldivmod() {
|
||||||
asm!("push {r4, lr}
|
llvm_asm!("
|
||||||
sub sp, sp, #16
|
push {r4, lr}
|
||||||
add r4, sp, #8
|
sub sp, sp, #16
|
||||||
str r4, [sp]
|
add r4, sp, #8
|
||||||
bl ___divmoddi4
|
str r4, [sp]
|
||||||
ldr r2, [sp, #8]
|
bl ___divmoddi4
|
||||||
ldr r3, [sp, #12]
|
ldr r2, [sp, #8]
|
||||||
add sp, sp, #16
|
ldr r3, [sp, #12]
|
||||||
pop {r4, pc}" ::: "memory" : "volatile");
|
add sp, sp, #16
|
||||||
|
pop {r4, pc}
|
||||||
|
" ::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,55 +88,55 @@ fn unwrap<T>(t: Option<T>) -> T {
|
||||||
|
|
||||||
macro_rules! int_impl_common {
|
macro_rules! int_impl_common {
|
||||||
($ty:ty, $bits:expr) => {
|
($ty:ty, $bits:expr) => {
|
||||||
const BITS: u32 = $bits;
|
const BITS: u32 = $bits;
|
||||||
|
|
||||||
const ZERO: Self = 0;
|
const ZERO: Self = 0;
|
||||||
const ONE: Self = 1;
|
const ONE: Self = 1;
|
||||||
|
|
||||||
fn from_bool(b: bool) -> Self {
|
fn from_bool(b: bool) -> Self {
|
||||||
b as $ty
|
b as $ty
|
||||||
}
|
}
|
||||||
|
|
||||||
fn max_value() -> Self {
|
fn max_value() -> Self {
|
||||||
<Self>::max_value()
|
<Self>::max_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn min_value() -> Self {
|
fn min_value() -> Self {
|
||||||
<Self>::min_value()
|
<Self>::min_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrapping_add(self, other: Self) -> Self {
|
fn wrapping_add(self, other: Self) -> Self {
|
||||||
<Self>::wrapping_add(self, other)
|
<Self>::wrapping_add(self, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrapping_mul(self, other: Self) -> Self {
|
fn wrapping_mul(self, other: Self) -> Self {
|
||||||
<Self>::wrapping_mul(self, other)
|
<Self>::wrapping_mul(self, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrapping_sub(self, other: Self) -> Self {
|
fn wrapping_sub(self, other: Self) -> Self {
|
||||||
<Self>::wrapping_sub(self, other)
|
<Self>::wrapping_sub(self, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrapping_shl(self, other: u32) -> Self {
|
fn wrapping_shl(self, other: u32) -> Self {
|
||||||
<Self>::wrapping_shl(self, other)
|
<Self>::wrapping_shl(self, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn overflowing_add(self, other: Self) -> (Self, bool) {
|
fn overflowing_add(self, other: Self) -> (Self, bool) {
|
||||||
<Self>::overflowing_add(self, other)
|
<Self>::overflowing_add(self, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aborting_div(self, other: Self) -> Self {
|
fn aborting_div(self, other: Self) -> Self {
|
||||||
unwrap(<Self>::checked_div(self, other))
|
unwrap(<Self>::checked_div(self, other))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aborting_rem(self, other: Self) -> Self {
|
fn aborting_rem(self, other: Self) -> Self {
|
||||||
unwrap(<Self>::checked_rem(self, other))
|
unwrap(<Self>::checked_rem(self, other))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leading_zeros(self) -> u32 {
|
fn leading_zeros(self) -> u32 {
|
||||||
<Self>::leading_zeros(self)
|
<Self>::leading_zeros(self)
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! int_impl {
|
macro_rules! int_impl {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#![cfg_attr(feature = "compiler-builtins", compiler_builtins)]
|
#![cfg_attr(feature = "compiler-builtins", compiler_builtins)]
|
||||||
#![feature(abi_unadjusted)]
|
#![feature(abi_unadjusted)]
|
||||||
#![feature(asm)]
|
#![feature(llvm_asm)]
|
||||||
#![feature(global_asm)]
|
#![feature(global_asm)]
|
||||||
#![feature(cfg_target_has_atomic)]
|
#![feature(cfg_target_has_atomic)]
|
||||||
#![feature(compiler_builtins)]
|
#![feature(compiler_builtins)]
|
||||||
|
|
|
@ -12,7 +12,7 @@ use core::intrinsics;
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn ___chkstk_ms() {
|
pub unsafe fn ___chkstk_ms() {
|
||||||
asm!("
|
llvm_asm!("
|
||||||
push %ecx
|
push %ecx
|
||||||
push %eax
|
push %eax
|
||||||
cmp $$0x1000,%eax
|
cmp $$0x1000,%eax
|
||||||
|
@ -38,7 +38,7 @@ pub unsafe fn ___chkstk_ms() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn __alloca() {
|
pub unsafe fn __alloca() {
|
||||||
asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
|
llvm_asm!("jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
|
||||||
::: "memory" : "volatile");
|
::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ pub unsafe fn __alloca() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn ___chkstk() {
|
pub unsafe fn ___chkstk() {
|
||||||
asm!("
|
llvm_asm!("
|
||||||
push %ecx
|
push %ecx
|
||||||
cmp $$0x1000,%eax
|
cmp $$0x1000,%eax
|
||||||
lea 8(%esp),%ecx // esp before calling this routine -> ecx
|
lea 8(%esp),%ecx // esp before calling this routine -> ecx
|
||||||
|
|
|
@ -12,7 +12,7 @@ use core::intrinsics;
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn ___chkstk_ms() {
|
pub unsafe fn ___chkstk_ms() {
|
||||||
asm!("
|
llvm_asm!("
|
||||||
push %rcx
|
push %rcx
|
||||||
push %rax
|
push %rax
|
||||||
cmp $$0x1000,%rax
|
cmp $$0x1000,%rax
|
||||||
|
@ -37,7 +37,7 @@ pub unsafe fn ___chkstk_ms() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn __alloca() {
|
pub unsafe fn __alloca() {
|
||||||
asm!("mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
|
llvm_asm!("mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
|
||||||
jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
|
jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable"
|
||||||
::: "memory" : "volatile");
|
::: "memory" : "volatile");
|
||||||
intrinsics::unreachable();
|
intrinsics::unreachable();
|
||||||
|
@ -47,7 +47,7 @@ pub unsafe fn __alloca() {
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn ___chkstk() {
|
pub unsafe fn ___chkstk() {
|
||||||
asm!(
|
llvm_asm!(
|
||||||
"
|
"
|
||||||
push %rcx
|
push %rcx
|
||||||
cmp $$0x1000,%rax
|
cmp $$0x1000,%rax
|
||||||
|
|
Loading…
Reference in New Issue