News for hackers. Stuff that matters.
Re:Let's write a setjmp by pjmlp on Sunday February 12, 2023 @04:02AM (#34761258)
Besides external Assembler, MSVC's way is to use intrinsics.

https://learn.microsoft.com/en-us/cpp/intrinsics/compiler-in...

Which is kind of nice and already proven in 1961 as a better way to do low level coding in Burroughs B5000, nowadays still sold as Unisys ClearPath MCP (naturally with improvements).

Intrinsics can be better understood by the compiler type system, both for safety and optimization algorithms.

Re:Let's write a setjmp by flohofwoe on Sunday February 12, 2023 @05:36AM (#34761759)
Do the intrinsics allow to load and store registers from and to memory? That's kind of the whole point why assembly is required.

Most cross-platform co-routine libraries I've seens for C or C++ use a small separate assembly file for stack switching on MSVC, so if it's possible to intrinsics, then it's definitely not a well known technique ;)

PS: at least the list of cross-platform intrinsics looks way too high level for a self-rolled setjmp/longjmp: https://learn.microsoft.com/en-us/cpp/intrinsics/intrinsics-...

Re:Let's write a setjmp by megous on Sunday February 12, 2023 @06:41AM (#34762072)
setjmp/longjmp don't switch stacks (they just "move" up the current stack)