4 ms·
Assembly is still quite useful in a number of circumstances. The compiler was generating terrible code for a ticket (spin) lock, and rewriting in assembly help
by jdsully 8y ago
Assembly is still quite useful in a number of circumstances. The compiler was generating terrible code for a ticket (spin) lock, and rewriting in assembly helped considerably [1].
Its also still the best way to get the most out of AVX and SSE. I find the register allocation to be extremely poor when using intrinsics.
1. https://github.com/JohnSully/KeyDB/blob/unstable/src/fastlock_x64.asm https://github.com/JohnSully/KeyDB/blob/unstable/src/fastloc...
- gpapilion 8y agoi agree with this, but find the complexity of writing assembly with modern processors instruction sets requires quite specialized knowledge.
- pjmlp 8y agoIt is, but someone needs to write compiler backends.
- elcomet 8y agoIt is quite scary to think that less and less people know how to write good assembly. So in a few years (decades?) we will have to rely on backends, with almost no one knowing how they really work, or how to write another one.
- reitanqild 8y agoLuckily it seems working on language design and compiler stuff is stuff is considered cool, almost as cool as game programming so I'm not too worried yet.
- pjmlp 8y agoI am not so negative, thankfully any good CS degree has enough compiler design lectures and assignments. And using sites like Godbolt is becoming trendy.
- stevekemp 8y agoI had fun recently generating Intel assembly for mathematical expressions: https://github.com/skx/math-compiler/ https://github.com/skx/math-compiler/ Mostly the project was to write something that compiled, from start to finish, but it was a nice refresher on assembly which I've otherwise not touched seriously for 20+ years.
- htfy96 8y agoThat's true, but not difficult as many people may think. In most cases you only need to remember most-used ~20 instructions and leave the remaining to reference. Sure it requires other domain knowledge, but it has almost nothing to do with asm itself.
- saagarjha 8y agoQuick question, I was skimming the code and came across this: xor eax, eax mov ax, 1 Was there a reason you didn't use the shorter xor eax, eax inc eax ?
- jdsully 8y agoI experimented with just mov eax, 1 and found it be slower - though I didn't try inc eax. Using 16-bit registers is tricky because they leave the upper bits unchanged. Its easy to trigger a partial register hazard inadvertently. p.s. the comments were nicely lined up in my editor, don't know what happened once it got to github.
- skissane 8y ago> p.s. the comments were nicely lined up in my editor, don't know what happened once it got to github. probably spaces-vs-tabs. GitHub has a different number of spaces-per-a-tab than your text editor. If one configures one's editor to expand tabs to spaces this won't happen.
- saagarjha 8y ago> If one configures one's editor to expand tabs to spaces this won't happen. …or you could use tabs for indentation, spaces for alignment, as they are intended to be used ;)
- skissane 8y ago> …or you could use tabs for indentation, spaces for alignment, as they are intended to be used ;) Yes. But, that is easier to stuff up. Getting rid of tabs completely, it disappoints some people who want to change the indentation amount to fit their personal preferences, but it reduces the likelihood of messes being made.
- saagarjha 8y ago> it disappoints some people who want to change the indentation amount to fit their personal preferences That's one issue I have with spaces, along with the fact that they are more annoying to delete. And I've seen people indent by 4n+1 spaces by accident at times (usually when there are no surrounding lines to provide context), so I wouldn't be so sure about it being the end-all, be-all for fixing indentation mistakes.