Skip to content

Commit cd6c23b

Browse files
committed
transpile: revert __builtin_ia32_pause from spin_loop to _mm_pause
`_mm_pause` is the more direct, unstable equivalent of `__builtin_ia2_pause`. Fixes 2nd half of <#1263 (comment)>.
1 parent a6d0986 commit cd6c23b

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

c2rust-transpile/src/translator/builtins.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ impl<'c> Translation<'c> {
381381
}
382382

383383
"__builtin_ia32_pause" => {
384-
// `spin_loop()` is implemented as `_mm_pause()` (the `pause` instruction) on `x86`/`x86_64`,
385-
// but it's the safe and cross-platform version of it, so prefer it.
386-
let spin_loop = mk().abs_path_expr(vec!["core", "hint", "spin_loop"]);
387-
let call = mk().call_expr(spin_loop, vec![]);
384+
let fn_name = "_mm_pause";
385+
self.import_simd_function(fn_name)?;
386+
let ident = mk().ident_expr(fn_name);
387+
let call = mk().call_expr(ident, vec![]);
388388
self.convert_side_effects_expr(
389389
ctx,
390390
WithStmts::new_val(call),

c2rust-transpile/tests/snapshots/arch-specific/spin.x86_64.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
unused_assignments,
88
unused_mut
99
)]
10+
#![feature(stdsimd)]
11+
#[cfg(target_arch = "x86")]
12+
pub use core::arch::x86::_mm_pause;
13+
#[cfg(target_arch = "x86_64")]
14+
pub use core::arch::x86_64::_mm_pause;
1015
#[no_mangle]
1116
pub unsafe extern "C" fn spin() {
12-
::core::hint::spin_loop();
17+
_mm_pause();
1318
}

c2rust-transpile/tests/snapshots/[email protected]

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ input_file: c2rust-transpile/tests/snapshots/arch-specific/spin.c
1212
unused_assignments,
1313
unused_mut
1414
)]
15+
#![feature(stdsimd)]
16+
#[cfg(target_arch = "x86")]
17+
pub use core::arch::x86::_mm_pause;
18+
#[cfg(target_arch = "x86_64")]
19+
pub use core::arch::x86_64::_mm_pause;
1520
#[no_mangle]
1621
pub unsafe extern "C" fn spin() {
17-
::core::hint::spin_loop();
22+
_mm_pause();
1823
}

0 commit comments

Comments
 (0)