Live data from Hacker News

Web server for Linux written in amd64 assembly

github.com

21–30 of 59 posts

Re: Web server for Linux written in amd64 assembly

#21

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

> Is handwritten assembly faster than GCC/clang-written assembly?

Sometimes, but the biggest case is if you can carefully arrange a tight inner loop, especially one that case make use of SIMD, like some DSP and scientific-computing code. Auto-vectorizers are getting better, but still miss lots of cases, so a skilled asm programmer can beat the compiler. The more "spread out" the performance-critical code is, in general (i.e. performance not dominated by one or two tight loops), the harder it is for hand-coding asm to beat a compiler; humans are not that good at doing whole-program optimization on large codebases. The more cross-platform the code has to be, the worse for the asm programmer as well: beating gcc's code-gen on one architecture is easier than beating it everywhere.

Re: Web server for Linux written in amd64 assembly

#22
post #12

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…

> It's awesome how assembly these days is reasonably high level: There were macro assemblers already available in the 80's!

Indeed, I pretty much learned programming on the C64 using Turbo Assembler which had macro functionality.

Re: Web server for Linux written in amd64 assembly

#24
post #15
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.

A few more instruction cycles? Which architecture and which decade?

This decade :)

For modern out-of-order CPUs - xor reg1,reg2 is problematic because the result depends on the previous contents of the register. Hence it cannot be executed out of order.

However as a special case xor reg1,reg1 (along with sub reg1,reg1) will be detected by the cpu (intel anyway) as a 'zero idiom' instruction and because it has a smaller opcode than mov reg,0 its preferred.

There are also other complex reasons - for detailed info see 3.5.1.8 in the Intel optimization manual.

Re: Web server for Linux written in amd64 assembly

#25
post #12

Earlier quoted context omitted.

> It's awesome how assembly these days is reasonably high level: There were macro assemblers already available in the 80's!

Indeed, I pretty much learned programming on the C64 using Turbo Assembler which had macro functionality.

AFAIK the Turbo Assembler was producing x86 bytecode, how would that work?

Re: Web server for Linux written in amd64 assembly

#26

Earlier quoted context omitted.

Indeed, I pretty much learned programming on the C64 using Turbo Assembler which had macro functionality.

AFAIK the Turbo Assembler was producing x86 bytecode, how would that work?

http://turbo.style64.org/about-the-turbo-assembler-homepage

"Turbo Assembler is a native c64 assembler which was introduced in 1985 by the German company, Omikron."

Re: Web server for Linux written in amd64 assembly

#27
post #17

Why would you do this, write it in C and let the compiler do the hard work.

Why not? There are several http servers written in C already.

I am pretty sure that this was an exercise in practical user space assembly programing rather than an attempt to write yet another http server.

Re: Web server for Linux written in amd64 assembly

#28
post #12

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…

> It's awesome how assembly these days is reasonably high level: There were macro assemblers already available in the 80's!

Try the 60's.

Re: Web server for Linux written in amd64 assembly

#29

Earlier quoted context omitted.

Indeed, I pretty much learned programming on the C64 using Turbo Assembler which had macro functionality.

AFAIK the Turbo Assembler was producing x86 bytecode, how would that work?

> x86 bytecode

What?!

Post reply on HN