Skip to content

Commit 0f86174

Browse files
authored
Merge pull request #446 from Amanieu/asm
2 parents 4d7a530 + 102b7fa commit 0f86174

File tree

10 files changed

+60
-48
lines changed

10 files changed

+60
-48
lines changed

build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ mod c {
560560
file,
561561
"#include \"{}\"",
562562
outlined_atomics_file.canonicalize().unwrap().display()
563-
);
563+
)
564+
.unwrap();
564565
drop(file);
565566
cfg.file(path);
566567

src/arm.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use core::intrinsics;
1111
#[naked]
1212
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
1313
pub unsafe extern "C" fn __aeabi_uidivmod() {
14-
asm!(
14+
core::arch::asm!(
1515
"push {{lr}}",
1616
"sub sp, sp, #4",
1717
"mov r2, sp",
@@ -27,7 +27,7 @@ pub unsafe extern "C" fn __aeabi_uidivmod() {
2727
#[naked]
2828
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
2929
pub unsafe extern "C" fn __aeabi_uidivmod() {
30-
asm!(
30+
core::arch::asm!(
3131
"push {{lr}}",
3232
"sub sp, sp, #4",
3333
"mov r2, sp",
@@ -43,7 +43,7 @@ pub unsafe extern "C" fn __aeabi_uidivmod() {
4343
#[naked]
4444
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
4545
pub unsafe extern "C" fn __aeabi_uldivmod() {
46-
asm!(
46+
core::arch::asm!(
4747
"push {{r4, lr}}",
4848
"sub sp, sp, #16",
4949
"add r4, sp, #8",
@@ -61,7 +61,7 @@ pub unsafe extern "C" fn __aeabi_uldivmod() {
6161
#[naked]
6262
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
6363
pub unsafe extern "C" fn __aeabi_uldivmod() {
64-
asm!(
64+
core::arch::asm!(
6565
"push {{r4, lr}}",
6666
"sub sp, sp, #16",
6767
"add r4, sp, #8",
@@ -79,7 +79,7 @@ pub unsafe extern "C" fn __aeabi_uldivmod() {
7979
#[naked]
8080
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
8181
pub unsafe extern "C" fn __aeabi_idivmod() {
82-
asm!(
82+
core::arch::asm!(
8383
"push {{r0, r1, r4, lr}}",
8484
"bl __aeabi_idiv",
8585
"pop {{r1, r2}}",
@@ -94,7 +94,7 @@ pub unsafe extern "C" fn __aeabi_idivmod() {
9494
#[naked]
9595
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
9696
pub unsafe extern "C" fn __aeabi_idivmod() {
97-
asm!(
97+
core::arch::asm!(
9898
"push {{r0, r1, r4, lr}}",
9999
"bl ___aeabi_idiv",
100100
"pop {{r1, r2}}",
@@ -109,7 +109,7 @@ pub unsafe extern "C" fn __aeabi_idivmod() {
109109
#[naked]
110110
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
111111
pub unsafe extern "C" fn __aeabi_ldivmod() {
112-
asm!(
112+
core::arch::asm!(
113113
"push {{r4, lr}}",
114114
"sub sp, sp, #16",
115115
"add r4, sp, #8",
@@ -127,7 +127,7 @@ pub unsafe extern "C" fn __aeabi_ldivmod() {
127127
#[naked]
128128
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
129129
pub unsafe extern "C" fn __aeabi_ldivmod() {
130-
asm!(
130+
core::arch::asm!(
131131
"push {{r4, lr}}",
132132
"sub sp, sp, #16",
133133
"add r4, sp, #8",

src/float/div.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ where
132132
// This doubles the number of correct binary digits in the approximation
133133
// with each iteration, so after three iterations, we have about 28 binary
134134
// digits of accuracy.
135-
let mut correction: u32;
136-
correction = negate_u32(((reciprocal as u64).wrapping_mul(q31b as u64) >> 32) as u32);
135+
136+
let mut correction: u32 =
137+
negate_u32(((reciprocal as u64).wrapping_mul(q31b as u64) >> 32) as u32);
137138
reciprocal = ((reciprocal as u64).wrapping_mul(correction as u64) as u64 >> 31) as u32;
138139
correction = negate_u32(((reciprocal as u64).wrapping_mul(q31b as u64) >> 32) as u32);
139140
reciprocal = ((reciprocal as u64).wrapping_mul(correction as u64) as u64 >> 31) as u32;
@@ -342,8 +343,9 @@ where
342343
// This doubles the number of correct binary digits in the approximation
343344
// with each iteration, so after three iterations, we have about 28 binary
344345
// digits of accuracy.
345-
let mut correction32: u32;
346-
correction32 = negate_u32(((recip32 as u64).wrapping_mul(q31b as u64) >> 32) as u32);
346+
347+
let mut correction32: u32 =
348+
negate_u32(((recip32 as u64).wrapping_mul(q31b as u64) >> 32) as u32);
347349
recip32 = ((recip32 as u64).wrapping_mul(correction32 as u64) >> 31) as u32;
348350
correction32 = negate_u32(((recip32 as u64).wrapping_mul(q31b as u64) >> 32) as u32);
349351
recip32 = ((recip32 as u64).wrapping_mul(correction32 as u64) >> 31) as u32;
@@ -359,16 +361,15 @@ where
359361
// We need to perform one more iteration to get us to 56 binary digits;
360362
// The last iteration needs to happen with extra precision.
361363
let q63blo = CastInto::<u32>::cast(b_significand << 11.cast());
362-
let correction: u64;
363-
let mut reciprocal: u64;
364-
correction = negate_u64(
364+
365+
let correction: u64 = negate_u64(
365366
(recip32 as u64)
366367
.wrapping_mul(q31b as u64)
367368
.wrapping_add((recip32 as u64).wrapping_mul(q63blo as u64) >> 32),
368369
);
369370
let c_hi = (correction >> 32) as u32;
370371
let c_lo = correction as u32;
371-
reciprocal = (recip32 as u64)
372+
let mut reciprocal: u64 = (recip32 as u64)
372373
.wrapping_mul(c_hi as u64)
373374
.wrapping_add((recip32 as u64).wrapping_mul(c_lo as u64) >> 32);
374375

src/int/leading_zeros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
public_test_dep! {
77
/// Returns the number of leading binary zeros in `x`.
8+
#[allow(dead_code)]
89
pub(crate) fn usize_leading_zeros_default(x: usize) -> usize {
910
// The basic idea is to test if the higher bits of `x` are zero and bisect the number
1011
// of leading zeros. It is possible for all branches of the bisection to use the same
@@ -78,6 +79,7 @@ pub(crate) fn usize_leading_zeros_default(x: usize) -> usize {
7879

7980
public_test_dep! {
8081
/// Returns the number of leading binary zeros in `x`.
82+
#[allow(dead_code)]
8183
pub(crate) fn usize_leading_zeros_riscv(x: usize) -> usize {
8284
let mut x = x;
8385
// the number of potential leading zeros

src/int/specialized_div_rem/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ unsafe fn u128_by_u64_div_rem(duo: u128, div: u64) -> (u64, u64) {
184184
// divides the combined registers rdx:rax (`duo` is split into two 64 bit parts to do this)
185185
// by `div`. The quotient is stored in rax and the remainder in rdx.
186186
// FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust.
187-
asm!(
187+
core::arch::asm!(
188188
"div {0}",
189189
in(reg) div,
190190
inlateout("rax") duo_lo => quo,
@@ -271,7 +271,7 @@ unsafe fn u64_by_u32_div_rem(duo: u64, div: u32) -> (u32, u32) {
271271
// divides the combined registers rdx:rax (`duo` is split into two 32 bit parts to do this)
272272
// by `div`. The quotient is stored in rax and the remainder in rdx.
273273
// FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust.
274-
asm!(
274+
core::arch::asm!(
275275
"div {0}",
276276
in(reg) div,
277277
inlateout("rax") duo_lo => quo,

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#![allow(improper_ctypes, improper_ctypes_definitions)]
1919
// `mem::swap` cannot be used because it may generate references to memcpy in unoptimized code.
2020
#![allow(clippy::manual_swap)]
21+
// Support compiling on both stage0 and stage1 which may differ in supported stable features.
22+
#![allow(stable_features)]
2123

2224
// We disable #[no_mangle] for tests so that we can verify the test results
2325
// against the native compiler-rt implementations of the builtins.

src/mem/x86_64.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#[cfg(target_feature = "ermsb")]
2121
pub unsafe fn copy_forward(dest: *mut u8, src: *const u8, count: usize) {
2222
// FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust.
23-
asm!(
23+
core::arch::asm!(
2424
"repe movsb (%rsi), (%rdi)",
2525
inout("rcx") count => _,
2626
inout("rdi") dest => _,
@@ -35,7 +35,7 @@ pub unsafe fn copy_forward(dest: *mut u8, src: *const u8, count: usize) {
3535
let qword_count = count >> 3;
3636
let byte_count = count & 0b111;
3737
// FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust.
38-
asm!(
38+
core::arch::asm!(
3939
"repe movsq (%rsi), (%rdi)",
4040
"mov {byte_count:e}, %ecx",
4141
"repe movsb (%rsi), (%rdi)",
@@ -52,7 +52,7 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
5252
let qword_count = count >> 3;
5353
let byte_count = count & 0b111;
5454
// FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust.
55-
asm!(
55+
core::arch::asm!(
5656
"std",
5757
"repe movsq (%rsi), (%rdi)",
5858
"movl {byte_count:e}, %ecx",
@@ -72,7 +72,7 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, count: usize) {
7272
#[cfg(target_feature = "ermsb")]
7373
pub unsafe fn set_bytes(dest: *mut u8, c: u8, count: usize) {
7474
// FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust.
75-
asm!(
75+
core::arch::asm!(
7676
"repe stosb %al, (%rdi)",
7777
inout("rcx") count => _,
7878
inout("rdi") dest => _,
@@ -87,7 +87,7 @@ pub unsafe fn set_bytes(dest: *mut u8, c: u8, count: usize) {
8787
let qword_count = count >> 3;
8888
let byte_count = count & 0b111;
8989
// FIXME: Use the Intel syntax once we drop LLVM 9 support on rust-lang/rust.
90-
asm!(
90+
core::arch::asm!(
9191
"repe stosq %rax, (%rdi)",
9292
"mov {byte_count:e}, %ecx",
9393
"repe stosb %al, (%rdi)",

src/probestack.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
#![cfg(not(feature = "no-asm"))]
4949
// We only define stack probing for these architectures today.
5050
#![cfg(any(target_arch = "x86_64", target_arch = "x86"))]
51-
// We need to add .att_syntax for bootstraping the new global_asm!
52-
#![allow(unknown_lints, bad_asm_style)]
5351

5452
extern "C" {
5553
pub fn __rust_probestack();
@@ -65,7 +63,6 @@ macro_rules! define_rust_probestack {
6563
($body: expr) => {
6664
concat!(
6765
"
68-
.att_syntax
6966
.pushsection .text.__rust_probestack
7067
.globl __rust_probestack
7168
.type __rust_probestack, @function
@@ -86,7 +83,6 @@ macro_rules! define_rust_probestack {
8683
($body: expr) => {
8784
concat!(
8885
"
89-
.att_syntax
9086
.globl __rust_probestack
9187
__rust_probestack:
9288
",
@@ -102,7 +98,6 @@ macro_rules! define_rust_probestack {
10298
($body: expr) => {
10399
concat!(
104100
"
105-
.att_syntax
106101
.globl ___rust_probestack
107102
___rust_probestack:
108103
",
@@ -117,7 +112,6 @@ macro_rules! define_rust_probestack {
117112
($body: expr) => {
118113
concat!(
119114
"
120-
.att_syntax
121115
.globl ___rust_probestack
122116
___rust_probestack:
123117
",
@@ -137,8 +131,9 @@ macro_rules! define_rust_probestack {
137131
target_arch = "x86_64",
138132
not(all(target_env = "sgx", target_vendor = "fortanix"))
139133
))]
140-
global_asm!(define_rust_probestack!(
141-
"
134+
core::arch::global_asm!(
135+
define_rust_probestack!(
136+
"
142137
.cfi_startproc
143138
pushq %rbp
144139
.cfi_adjust_cfa_offset 8
@@ -188,7 +183,9 @@ global_asm!(define_rust_probestack!(
188183
ret
189184
.cfi_endproc
190185
"
191-
));
186+
),
187+
options(att_syntax)
188+
);
192189

193190
// This function is the same as above, except that some instructions are
194191
// [manually patched for LVI].
@@ -198,8 +195,9 @@ global_asm!(define_rust_probestack!(
198195
target_arch = "x86_64",
199196
all(target_env = "sgx", target_vendor = "fortanix")
200197
))]
201-
global_asm!(define_rust_probestack!(
202-
"
198+
core::arch::global_asm!(
199+
define_rust_probestack!(
200+
"
203201
.cfi_startproc
204202
pushq %rbp
205203
.cfi_adjust_cfa_offset 8
@@ -251,16 +249,19 @@ global_asm!(define_rust_probestack!(
251249
jmp *%r11
252250
.cfi_endproc
253251
"
254-
));
252+
),
253+
options(att_syntax)
254+
);
255255

256256
#[cfg(all(target_arch = "x86", not(target_os = "uefi")))]
257257
// This is the same as x86_64 above, only translated for 32-bit sizes. Note
258258
// that on Unix we're expected to restore everything as it was, this
259259
// function basically can't tamper with anything.
260260
//
261261
// The ABI here is the same as x86_64, except everything is 32-bits large.
262-
global_asm!(define_rust_probestack!(
263-
"
262+
core::arch::global_asm!(
263+
define_rust_probestack!(
264+
"
264265
.cfi_startproc
265266
push %ebp
266267
.cfi_adjust_cfa_offset 4
@@ -291,7 +292,9 @@ global_asm!(define_rust_probestack!(
291292
ret
292293
.cfi_endproc
293294
"
294-
));
295+
),
296+
options(att_syntax)
297+
);
295298

296299
#[cfg(all(target_arch = "x86", target_os = "uefi"))]
297300
// UEFI target is windows like target. LLVM will do _chkstk things like windows.
@@ -304,8 +307,9 @@ global_asm!(define_rust_probestack!(
304307
// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust %esp themselves.
305308
// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust %rsp
306309
// themselves.
307-
global_asm!(define_rust_probestack!(
308-
"
310+
core::arch::global_asm!(
311+
define_rust_probestack!(
312+
"
309313
.cfi_startproc
310314
push %ebp
311315
.cfi_adjust_cfa_offset 4
@@ -341,4 +345,6 @@ global_asm!(define_rust_probestack!(
341345
ret
342346
.cfi_endproc
343347
"
344-
));
348+
),
349+
options(att_syntax)
350+
);

src/x86.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use core::intrinsics;
1717
#[naked]
1818
#[no_mangle]
1919
pub unsafe extern "C" fn ___chkstk_ms() {
20-
asm!(
20+
core::arch::asm!(
2121
"push %ecx",
2222
"push %eax",
2323
"cmp $0x1000,%eax",
@@ -49,7 +49,7 @@ pub unsafe extern "C" fn ___chkstk_ms() {
4949
#[naked]
5050
#[no_mangle]
5151
pub unsafe extern "C" fn __alloca() {
52-
asm!(
52+
core::arch::asm!(
5353
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
5454
options(noreturn, att_syntax)
5555
);
@@ -64,7 +64,7 @@ pub unsafe extern "C" fn __alloca() {
6464
#[naked]
6565
#[no_mangle]
6666
pub unsafe extern "C" fn ___chkstk() {
67-
asm!(
67+
core::arch::asm!(
6868
"push %ecx",
6969
"cmp $0x1000,%eax",
7070
"lea 8(%esp),%ecx", // esp before calling this routine -> ecx

src/x86_64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use core::intrinsics;
1717
#[naked]
1818
#[no_mangle]
1919
pub unsafe extern "C" fn ___chkstk_ms() {
20-
asm!(
20+
core::arch::asm!(
2121
"push %rcx",
2222
"push %rax",
2323
"cmp $0x1000,%rax",
@@ -48,7 +48,7 @@ pub unsafe extern "C" fn ___chkstk_ms() {
4848
#[naked]
4949
#[no_mangle]
5050
pub unsafe extern "C" fn __alloca() {
51-
asm!(
51+
core::arch::asm!(
5252
"mov %rcx,%rax", // x64 _alloca is a normal function with parameter in rcx
5353
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
5454
options(noreturn, att_syntax)
@@ -64,7 +64,7 @@ pub unsafe extern "C" fn __alloca() {
6464
#[naked]
6565
#[no_mangle]
6666
pub unsafe extern "C" fn ___chkstk() {
67-
asm!(
67+
core::arch::asm!(
6868
"push %rcx",
6969
"cmp $0x1000,%rax",
7070
"lea 16(%rsp),%rcx", // rsp before calling this routine -> rcx

0 commit comments

Comments
 (0)