Live data from Hacker News

Web server for Linux written in amd64 assembly

github.com

31–40 of 59 posts

Re: Web server for Linux written in amd64 assembly

#32
post #29

Earlier quoted context omitted.

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

> x86 bytecode What?!

I guess he's talking about Borland's Turbo Assembler that was coming with Turbo Pascal: http://en.wikipedia.org/wiki/Turbo_Assembler

Re: Web server for Linux written in amd64 assembly

#33
post #17

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

I agree. There's little justification for this other than 'I can'. If you need to hit the metal you can inline assembly in both c and c++.

> There's little justification for this other than 'I can'.

And why isn't that enough?

Re: Web server for Linux written in amd64 assembly

#34

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…

TASM from Borland had bunch of macros/shortcut keywords for the patterns you describe. There's dozens of library files to do similar things in MASM as well. mammon_ had written a bunch of macros [1] that do same thing for NASM. See how he exploits NASM's preprocessor for this in his "Extending NASM" article in the Assembly Language Journal, Feb/Mar 1998, Issue 3. He also demonstrates how do all the control structures in NASM's preprocessor (for, if, switch/case, while, do/while, etc.).

[1] http://mammon.github.io/Text/nasm_apj.txt

Re: Web server for Linux written in amd64 assembly

#36
post #33

Earlier quoted context omitted.

I agree. There's little justification for this other than 'I can'. If you need to hit the metal you can inline assembly in both c and c++.

> There's little justification for this other than 'I can'. And why isn't that enough?

Security through transparency and readability for a bigger audience.

Re: Web server for Linux written in amd64 assembly

#37

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

I don't want to be too harsh - this is a fun idea, and I'm prone to silly fantasies about rewriting slow code in assembly myself - but this particular assembly doesn't take advantage of many of the "dirty tricks" that are available in low-level code.

As one example, check out the content-type detection, which is essentially a long chain of repeated strlen + strcmp; assembly language doesn't magically make bad algorithms fast.

Re: Web server for Linux written in amd64 assembly

#38
post #36
post #33

Earlier quoted context omitted.

> There's little justification for this other than 'I can'. And why isn't that enough?

Security through transparency and readability for a bigger audience.

That's a great reason not to use this. Doesn't seem a reason not to do it.

Re: Web server for Linux written in amd64 assembly

#39
post #24
post #15

Earlier quoted context omitted.

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…

>This decade :)

The initial claim was that mov reg,0 was slower to execute.

Re: Web server for Linux written in amd64 assembly

#40
post #20
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!

In my OS/architecture class we used a textbook whose author had piled on so much macro assembling on top of SPARC asm (macros all in m4, naturally) that he in effect was writing the book using a personal high-level language constructed out of gobs of m4. Like the bizarro-world version of personalized language construction in Lisp-land... Was this book (the first review complains about the same thing): http://www.amaz…

I used this book for OS/architecture class as well.

I think the use of m4 needlessly complicated the material.

Post reply on HN