Updated inline asm from llvm_asm to new asm syntax

This commit is contained in:
Carl Fredrik Samson
2022-01-26 00:43:09 +01:00
committed by GitHub
parent 6adb910e51
commit 250918b362

View File

@@ -147,9 +147,9 @@ A green threads example could look something like this:
_**Press the expand icon in the top right corner to show the example code.**_ _**Press the expand icon in the top right corner to show the example code.**_
```rust, edition2018 ```rust, edition2021
# #![feature(llvm_asm, naked_functions)] # #![feature(naked_functions)]
# use std::ptr; # use std::{arch::asm, ptr};
# #
# const DEFAULT_STACK_SIZE: usize = 1024 * 1024 * 2; # const DEFAULT_STACK_SIZE: usize = 1024 * 1024 * 2;
# const MAX_THREADS: usize = 4; # const MAX_THREADS: usize = 4;
@@ -240,6 +240,7 @@ _**Press the expand icon in the top right corner to show the example code.**_
# } # }
# } # }
# #
# #[inline(never)]
# fn t_yield(&mut self) -> bool { # fn t_yield(&mut self) -> bool {
# let mut pos = self.current; # let mut pos = self.current;
# while self.threads[pos].state != State::Ready { # while self.threads[pos].state != State::Ready {
@@ -263,13 +264,9 @@ _**Press the expand icon in the top right corner to show the example code.**_
# unsafe { # unsafe {
# let old: *mut ThreadContext = &mut self.threads[old_pos].ctx; # let old: *mut ThreadContext = &mut self.threads[old_pos].ctx;
# let new: *const ThreadContext = &self.threads[pos].ctx; # let new: *const ThreadContext = &self.threads[pos].ctx;
# llvm_asm!( # asm!("call switch", in("rdi") old, in("rsi") new, clobber_abi("C"));
# "mov $0, %rdi
# mov $1, %rsi"::"r"(old), "r"(new)
# );
# switch();
# } # }
# true # self.threads.len() > 0
# } # }
# #
# pub fn spawn<F: Fn() + 'static>(f: F){ # pub fn spawn<F: Fn() + 'static>(f: F){
@@ -304,7 +301,9 @@ _**Press the expand icon in the top right corner to show the example code.**_
# } # }
# #
# #[naked] # #[naked]
# fn skip() { } # unsafe fn skip() {
# asm!("ret", options(noreturn))
# }
# #
# fn guard() { # fn guard() {
# unsafe { # unsafe {
@@ -321,32 +320,30 @@ _**Press the expand icon in the top right corner to show the example code.**_
# (*rt_ptr).t_yield(); # (*rt_ptr).t_yield();
# }; # };
# } # }
#
# #[naked] # #[naked]
# #[inline(never)] # #[no_mangle]
# unsafe fn switch() { # unsafe fn switch() {
# llvm_asm!(" # asm!(
# mov %rsp, 0x00(%rdi) # "mov 0x00[rdi], rsp",
# mov %r15, 0x08(%rdi) # "mov 0x08[rdi], r15",
# mov %r14, 0x10(%rdi) # "mov 0x10[rdi], r14",
# mov %r13, 0x18(%rdi) # "mov 0x18[rdi], r13",
# mov %r12, 0x20(%rdi) # "mov 0x20[rdi], r12",
# mov %rbx, 0x28(%rdi) # "mov 0x28[rdi], rbx",
# mov %rbp, 0x30(%rdi) # "mov 0x30[rdi], rbp",
# # "mov rsp, 0x00[rsi]",
# mov 0x00(%rsi), %rsp # "mov r15, 0x08[rsi]",
# mov 0x08(%rsi), %r15 # "mov r14, 0x10[rsi]",
# mov 0x10(%rsi), %r14 # "mov r13, 0x18[rsi]",
# mov 0x18(%rsi), %r13 # "mov r12, 0x20[rsi]",
# mov 0x20(%rsi), %r12 # "mov rbx, 0x28[rsi]",
# mov 0x28(%rsi), %rbx # "mov rbp, 0x30[rsi]",
# mov 0x30(%rsi), %rbp # "mov rdi, 0x38[rsi]",
# mov 0x38(%rsi), %rdi # "ret", options(noreturn)
# "
# ); # );
# } # }
# #[cfg(not(windows))] # #[cfg(not(windows))]
fn main() { pub fn run() {
let mut runtime = Runtime::new(); let mut runtime = Runtime::new();
runtime.init(); runtime.init();
Runtime::spawn(|| { Runtime::spawn(|| {