News for hackers. Stuff that matters.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by agumonkey on Friday July 13, 2018 @04:21PM (#17526354)
I wonder if there are cpus with 1-instr state save

ps: thank you all for the answers

Re:Asmttpd: Web server for Linux written in amd64 assembly (... by rwmj on Friday July 13, 2018 @05:29PM (#17526875)
ARMv7 (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.

Re:Asmttpd: Web server for Linux written in amd64 assembly (... by jlarcombe on Saturday July 14, 2018 @03:23AM (#17529255)
In 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...

Re:Asmttpd: Web server for Linux written in amd64 assembly (... by PeCaN on Friday July 13, 2018 @06:19PM (#17527355)
Itanium 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.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by TomMarius on Friday July 13, 2018 @11:25PM (#17528635)
Isn't Itanium obsolete? I'd love to learn otherwise.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by PeCaN on Saturday July 14, 2018 @12:29AM (#17528826)
Sadly 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.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by TomMarius on Saturday July 14, 2018 @06:19AM (#17529699)
Do you mean that Itanium would have been safe?
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by PeCaN on Saturday July 14, 2018 @11:57AM (#17530817)
It'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).

Re:Asmttpd: Web server for Linux written in amd64 assembly (... by pjc50 on Friday July 13, 2018 @05:40PM (#17526969)
ARM 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.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by pwg on Friday July 13, 2018 @11:21PM (#17528616)
Another 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 (search for "alternate registers").

Re:Asmttpd: Web server for Linux written in amd64 assembly (... by nineteen999 on Monday July 16, 2018 @12:49AM (#17538838)
Sadly 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.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by saagarjha on Friday July 13, 2018 @04:27PM (#17526397)
Even 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.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by kijiki on Friday July 13, 2018 @04:35PM (#17526468)
x86 has LOADALL and SAVEALL.

https://en.wikipedia.org/wiki/LOADALL

Re:Asmttpd: Web server for Linux written in amd64 assembly (... by msla on Friday July 13, 2018 @04:57PM (#17526638)
Those 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]

Re:Asmttpd: Web server for Linux written in amd64 assembly (... by scandinavian on Friday July 13, 2018 @05:25PM (#17526830)
What about PUSHAD and POPAD for x86, those are not undocumented right?
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by jamieiles on Friday July 13, 2018 @05:36PM (#17526927)
There is no pusha in long mode though, you need to push individual regs.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by elcritch on Friday July 13, 2018 @05:59PM (#17527161)
BeagleBone’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.
Re:Asmttpd: Web server for Linux written in amd64 assembly (... by blattimwind on Friday July 13, 2018 @04:22PM (#17526360)
Sure. It's called windowed registers and you have one instruction each to move the window right/left.