Live data from Hacker News

Web server for Linux written in amd64 assembly

github.com

1–10 of 59 posts

Re: Web server for Linux written in amd64 assembly

#3

    xor rax,rax
I used this construct often to zero a register, in the time that memory and CPU cycles were scarce. But nowadays, my time is a more valuable resource, and I tend to write:

    mov rax, 0
It takes a somewhat longer instruction code, and a few CPU cycles more, but it conveys meaning better.

Re: Web server for Linux written in amd64 assembly

#4
Pretty neat! It's awesome how assembly these days is reasonably high level:

https://github.com/nemasu/asmttpd/blob/master/http.asm

It dawns on me why we couldn't have shortcuts for several patterns that show up everywhere:

- mov, mov, mov then call/syscall could just be written as call(arg, arg, arg) since it's not that difficult to figure out which argument needs to go to which register if there was a defined order of arguments.

- push push push push pop pop pop pop could just be a define really. I realize that there are cases where you wouldn't necessarily do that, but that seems to be the minority. The compiler could just figure out what registers you use in the routine and push / pop those. If you want to keep a register, there could be added syntax for that.

It seems in both of these cases the language optimizes for simplicity and flexibility, ignoring the common case. Neither of these strike me as situations where introducing the abstraction would require a lot of compiler "magic" to guess and optimize. It's almost just string replacement.

Then again, you could just write all this in C and let the compiler figure it out. Interesting stuff!

Re: Web server for Linux written in amd64 assembly

#7
post #3

xor rax,rax I used this construct often to zero a register, in the time that memory and CPU cycles were scarce. But nowadays, my time is a more valuable resource, and I tend to write: mov rax, 0 It takes a somewhat longer instruction code, and a few CPU cycles more, but it conveys meaning better.

> It takes a somewhat longer instruction code, and a few CPU cycles more, but it conveys meaning better.

So do webservers written in Python. I don't think that was the point of this project.

Re: Web server for Linux written in amd64 assembly

#8
post #3

xor rax,rax I used this construct often to zero a register, in the time that memory and CPU cycles were scarce. But nowadays, my time is a more valuable resource, and I tend to write: mov rax, 0 It takes a somewhat longer instruction code, and a few CPU cycles more, but it conveys meaning better.

Couldn't you just find-replace this in a makefile?

Then again almost everything about assembly gets a bit "isn't that what we made other languages for?"

Re: Web server for Linux written in amd64 assembly

#9

Pretty neat! It's awesome how assembly these days is reasonably high level: https://github.com/nemasu/asmttpd/blob/master/http.asm It dawns on me why we couldn't have shortcuts for several patterns that show up everywhere: - mov, mov, mov then call/syscall could just be written as call(arg, arg, arg) since it's not that difficult to figure out which argument needs to go to which register if there was a defined order…

Most decent assemblers supports macros, some of them fairly complicated.

And there is Randall Hyde's High Level Assembly: http://www.plantation-productions.com/Webster/

Re: Web server for Linux written in amd64 assembly

#10

I wonder how fast is this server. Is handwritten assembly faster than GCC/clang-written assembly?

Maybe, maybe not, but for a web server, if asm vs. C is making a noticeable impact on the overall performance, one of them is doing something very wrong - they should spend most of their time in sys-calls to shuffle data to/from the network, not executing web server userland code.
Post reply on HN