4 ms·
I wonder if there are cpus with 1-instr state save ps: thank you all for the answers
by agumonkey 8y ago
I wonder if there are cpus with 1-instr state save
ps: thank you all for the answers
- blattimwind 8y agoSure. It's called windowed registers and you have one instruction each to move the window right/left.
- saagarjha 8y agoEven if there was one, you'd still be saving registers unnecessarily. If you only clobber one register in a procedure there's no need to save and restore all of them.
- kijiki 8y agox86 has LOADALL and SAVEALL. https://en.wikipedia.org/wiki/LOADALL https://en.wikipedia.org/wiki/LOADALL
- msla 8y agoThose undocumented instructions don't exist on x86_64, and they could be used to do bizarre things on the processors which had them: > As the two LOADALL instructions were never documented and do not exist on later processors, the opcodes were reused in the AMD64 architecture.[8] The opcode for the 286 LOADALL instruction, 0F05, became the AMD64 instruction SYSCALL; the 386 LOADALL instruction, 0F07, became the SYSRET instruction. These definitions were cemented even on Intel CPUs with the introduction of the Intel 64 implementation of AMD64.[9] [snip] > Because LOADALL did not perform any checks on the validity of the data loaded into processor registers, it was possible to load a processor state that could not be normally entered, such as using real mode (PE=0) together with paging (PG=1) on 386-class CPUs.[7]
- scandinavian 8y agoWhat about PUSHAD and POPAD for x86, those are not undocumented right?
- jamieiles 8y agoThere is no pusha in long mode though, you need to push individual regs.
- rwmj 8y agoARMv7 (not AArch64) has the STM instruction that lets you push a register set, selected by bitmask. eg: STMFD sp!, {r3-r7,lr} (I believe the "FD" suffix is to do with the stack growing down - "full descending") Of course this is just implemented with microcode so it's not really any more efficient than a series of PUSHes, except there's a bit less I-cache pressure.
- jlarcombe 8y agoIn the original ARM design the multiple register transfers were much more efficient than the equivalent single register transfers because of the simple architecture which had an inherent load delay (it couldn't fetch an instruction and a data word in a single cycle). When they switched to the Harvard model they lost their advantage. Talking of the ARM reminds me of older heroic feats of assembly-programmed internet software in the Acorn days, such as Ben Dooks' all-asm TCP/IP stack and Jon Ribbens' web browser. Probably not been done that often...
- pjc50 8y agoARM has stmdb / ldmia which appear in practically every function prolog/epilog. It also has "banking" systems to swap to a different set of registers on interrupts, which saves time and stack space.
- elcritch 8y agoBeagleBone’s processor the AM335x PRU processors by TI has two “PRU” coprocessors. They have “xin” and “xout” instructions that can copy a register bank in 1 cycle. Pretty handy for quick data gathering but tricky to use in C.
- PeCaN 8y agoItanium does this automatically. You declare what registers you're using in the the function prologue and it handles popping/pushing/renaming. No register window exceptions too.
- TomMarius 8y agoIsn't Itanium obsolete? I'd love to learn otherwise.
- PeCaN 8y agoSadly it's dead now. In a cruel twist of fate, Intel killed it off shortly before we found out about all the speculative execution attacks and found that everything else is horrifically vulnerable.
- TomMarius 8y agoDo you mean that Itanium would have been safe?
- PeCaN 8y agoIt's inherently not vulnerable to the Spectre/Meltdown family of attacks. They rely on speculative, out-of-order execution on modern CPUs, but Itanium is an in-order core with very limited (and software-controlled) speculation. It's actually not vulnerable to a bunch of other attacks as well (e.g. a buffer overflow cannot overwrite the return address on Itanium).
- pwg 8y agoAnother one: the old Z-80 CPU had two sets of registers, and a single instruction to swap between the main and the alternate register set. http://landley.net/history/mirror/cpm/z80.html http://landley.net/history/mirror/cpm/z80.html (search for "alternate registers").
- nineteen999 8y agoSadly it appears that none of the Z80 C compilers (at least the ones I've used, Hi-Tech C and sdcc) are smart enough to use it.