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.**_
```rust, edition2018
# #![feature(llvm_asm, naked_functions)]
# use std::ptr;
```rust, edition2021
# #![feature(naked_functions)]
# use std::{arch::asm, ptr};
#
# const DEFAULT_STACK_SIZE: usize = 1024 * 1024 * 2;
# 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 {
# let mut pos = self.current;
# 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 {
# let old: *mut ThreadContext = &mut self.threads[old_pos].ctx;
# let new: *const ThreadContext = &self.threads[pos].ctx;
# llvm_asm!(
# "mov $0, %rdi
# mov $1, %rsi"::"r"(old), "r"(new)
# );
# switch();
# asm!("call switch", in("rdi") old, in("rsi") new, clobber_abi("C"));
# }
# true
# self.threads.len() > 0
# }
#
# 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]
# fn skip() { }
# unsafe fn skip() {
# asm!("ret", options(noreturn))
# }
#
# fn guard() {
# unsafe {
@@ -321,32 +320,30 @@ _**Press the expand icon in the top right corner to show the example code.**_
# (*rt_ptr).t_yield();
# };
# }
#
# #[naked]
# #[inline(never)]
# #[no_mangle]
# unsafe fn switch() {
# llvm_asm!("
# mov %rsp, 0x00(%rdi)
# mov %r15, 0x08(%rdi)
# mov %r14, 0x10(%rdi)
# mov %r13, 0x18(%rdi)
# mov %r12, 0x20(%rdi)
# mov %rbx, 0x28(%rdi)
# mov %rbp, 0x30(%rdi)
#
# mov 0x00(%rsi), %rsp
# mov 0x08(%rsi), %r15
# mov 0x10(%rsi), %r14
# mov 0x18(%rsi), %r13
# mov 0x20(%rsi), %r12
# mov 0x28(%rsi), %rbx
# mov 0x30(%rsi), %rbp
# mov 0x38(%rsi), %rdi
# "
# asm!(
# "mov 0x00[rdi], rsp",
# "mov 0x08[rdi], r15",
# "mov 0x10[rdi], r14",
# "mov 0x18[rdi], r13",
# "mov 0x20[rdi], r12",
# "mov 0x28[rdi], rbx",
# "mov 0x30[rdi], rbp",
# "mov rsp, 0x00[rsi]",
# "mov r15, 0x08[rsi]",
# "mov r14, 0x10[rsi]",
# "mov r13, 0x18[rsi]",
# "mov r12, 0x20[rsi]",
# "mov rbx, 0x28[rsi]",
# "mov rbp, 0x30[rsi]",
# "mov rdi, 0x38[rsi]",
# "ret", options(noreturn)
# );
# }
# #[cfg(not(windows))]
fn main() {
pub fn run() {
let mut runtime = Runtime::new();
runtime.init();
Runtime::spawn(|| {