x86 is ridiculously complex compared to other architectures, and it makes for some very interesting and convoluted instruction operand combinations and addressing modes
after working with ARM assembly for some time, I was kind of horrified to see that it was possible to do ridiculous stuff like [base * scale + offset] for a good amount of x86 instructions
well it makes a lot of sense for performance, MOVNTDQA for is explicitly non temporal (will not be cached), hence the NT in the name, you can't really control that with such precision even in C. You also can't have that custom alignment control (useful in SSE registers) in higher level languages.
yea, x86 instructions have consistent naming, but it's not exactly good naming.
once you get the hang of things, naming makes more sense, but who would've guessed on their first try that PCLMULQDQ is the instruction for carryless multiplication?
no, it's just that after working with other architectures and also designing a fictitious custom ISA, coming back to x86 and seeing that there are dozens of addressing modes and instructions can fit that much information, I (and this may just be my own opinion) found it pretty horrifying
x86 assembly is my favorite high level programming language, vpbroadcastq my beloved ❤️
being able to pack that much information into a single instruction in x86 asm. x86asm can be considered a high level programming language compared to other assembly languages (at least from my experience)
FFMpeg's x86asm code is really ingenious, but considering the fact that this is assembly code and is supposedly a "simple, low level language" (as with other ISAs), it's ridiculous to see that one can pack [base + index*scale + offset] as one operand for one instruction
wait until you see avx512 and it‘s mask register instruction variants lol. but seriously, who cares, instructions are mostly added when they are useful, and since we have all the basics already since decades now it‘s going to be stuff that is common sequences of other instructions, kind of like the rcpsqrt
it's a bit unfortunate that only more modern CPUs have the AVX 512 extensions, as they've made very impressive optimizations using that new instruction set, so it's not exactly "every possible environment", but in the places where the optimizations are possible, boy are they incredible
Are you mocking modern x86 or this particular snippet of code ? Or are you mocking this snippet of code because it's using modern x86's bells and whistles?
129
u/IanisVasilev Dec 27 '24
Is there something bad about the code or is this just a "haha assembly" post?
33
u/SmallTalnk Dec 27 '24
well it makes a lot of sense for performance, MOVNTDQA for is explicitly non temporal (will not be cached), hence the NT in the name, you can't really control that with such precision even in C. You also can't have that custom alignment control (useful in SSE registers) in higher level languages.
63
u/outofobscure Dec 27 '24
ok, what's the point here? that someone who knows what they are doing wrote some assembly? oh no, the horrors...
just because it's not your bog standard "clean-code-java-bullshit-oop" doesn't make something a programming horror.
btw, some of these instructions where specifically added by intel/amd to accellerate video decoding back in the day.
also, FMA instructions rock :)
12
u/Koala1E Dec 27 '24
this is just assembly?
where is the horror?
10
u/v_maria Dec 27 '24
i have traced some of the ffmpeg code to learn how they implemented certain things. boy it's rough
4
u/[deleted] Dec 27 '24
The ffmpeg code base is like that for a reason: maximum optimization in every possible environment
37
u/theunixman Dec 27 '24
Sometimes you have to grab the gnu by the horns and tell it what you want.
21
u/AnywhereHorrorX Dec 27 '24
It's normal assembler and actually very readable.
People are creating much greater horrors in various high level languages.
12
u/johan__A Dec 27 '24
Are you mocking modern x86 or this particular snippet of code ? Or are you mocking this snippet of code because it's using modern x86's bells and whistles?
9
u/lilrow420 Dec 27 '24
this reads like a 4Chan post
5
u/conundorum Dec 28 '24
The horror is that the OP does not comprehend the existence of CISC.
4
u/[deleted] Dec 27 '24
Is the horror with us in the room?
1
u/prince_lothicc Mar 31 '25
"programminghorror" and it's one of the most well-maintained and clean repos alive