-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asm experiments. NOT FOR MERGE #17
Conversation
Why should the Swap function accept null pointers? |
By the way, I was experimenting to use the But ... Since |
Swap: it dedupes code. Because save is first half of swap, and load is the second. I don't like code duping. Less code, less possible typos and errors. Especially in assembly. By this trick we have 3 funcs in 1. If first arg is null, there's no save. If second one is null, there's no load. Asm: that's why I'm digging into prebuilt binaries. If asm becomes stable, we could try to migrate. As per your troubles, the first one I can see is uncontrollable stack and argument management done by Rust compiler. Like, in swap we need to pick return address from stack. There should be something like Anyway, what do you say? I mean, does this look sound and promising? |
My experiment is in branch The author of Redox OS is pushing the I suspected that my problem is cause by messing up with the stack frame, but can't find a clue. But the original code in By the way, the |
I took them from Boost.Context assembly, and stumbled upon some mentions that x87 and MMX control words should be preserved. Also I didn't find any mentions about MMX registers needed to be preserved. As per your trouble, I suspect it's really around the stack mess. Please note that common function prolog is storing stack base pointer on stack to preserve parent call frame and then setting BP to SP to establish new one. After this, most argument lookup, at least for the ones on stack, is done relative to BP. So the funcs which mess with context should have no such prolog code. But it's established via compiler automatically. That's why I assume So, if you find the proposed way Ok, I'll try to move Rust piece this direction. I'd prefer using ASM from Boost as guidance further. In particular, I don't think we really need segmented stacks support - they look more as leftover from abandoned design. |
Agree. I personally don't like the segmented stacks, it has obviously overhead on the boundary. By the way, do you know how to let Rust's runtime to print |
Here is the So tiny and fast. |
Checked lthread. Some issues:
So it's barely a subset of what context-rs should be. |
Agree. One more thing for the #16 issue, I found that Rust will always generate a function like this
So the problem is the As what I did in https://github.com/zonyitoo/context-rs/blob/feature-inlineasm/src/detail/x86_64.rs#L125. If you are interested in bring inline asm into this crate, I am happy to discuss in #16 . |
I'm closing this one from my side for now. Will make PR when I'll have complete solution. |
Note. This PR is incomplete and just shows some raw ideas. Don't accep
Please pay attention to asm/x86_64-linux.S, src/backend.rs
lib/libx86_64-linux.a is built from mentioned ASM file.