Earlier quoted context omitted.
This is for heavily vectorized code, using every hack possible to fully utilize the CPU. Compilers are smart when it comes to normal code, but codecs are not really normal code. Not a ffmpeg programmer, but have some background dealing with audio.
> codecs are not really normal code. Not really a fair comment. They are entirely normal code in most senses. They differ in one important way: they are (frequently) perfect examples of where "single instruction, multiple data" completely makes sense. "Do this to every sample" is the order of the day, and that is a bit odd when compared with text processing or numerical computation. But this is true of the majority o…
FFmpeg School of Assembly Language
111–120 of 226 posts
Re: FFmpeg School of Assembly Language
#112Asm is 10x faster than C? That was definitely true at some point but is it still true today? Have compilers really stagnated so badly they can't come close to hand coded asm?
C compilers are still pretty bad at auto vectorization. For problems where SIMD is applicable, you can reasonably expect a 2x-16x speed up over the naive scalar implementation.
Re: FFmpeg School of Assembly Language
#113Asm is 10x faster than C? That was definitely true at some point but is it still true today? Have compilers really stagnated so badly they can't come close to hand coded asm?
This gets even more complex once you start looking at dynamic compilations. Some of the JIT compilers have the ability to hot patch functions based upon runtime statistics. In very large, enterprisey applications with unknowns regarding how they will actually be used at build time, this can make a difference. You can go nuclear option with your static compilations and turn on all the optimizations everywhere, but thi…
In ffmpeg's case you can just always be the correct thing.
Re: FFmpeg School of Assembly Language
#114Earlier quoted context omitted.
Probably some very niche things. I know I can't write ASM that's 10x better than C, but I wouldn't assume no one can.
It depends on what you're trying to do. I would in general only expect such substantial speedups when considering writing computation kernels (for audio, video, etc). Compilers today are liable in most circumstances to know many more tricks than you do. Especially if you make use of hints (e.g. "this memory is almost always accessed sequentially", "this branch is almost never taken", etc) to guide it.
Re: FFmpeg School of Assembly Language
#115What's the cost of shuttling data in and out of SIMD land?
SIMD doesn’t operate on a separate memory space or anything like that. You just load data from normal memory into the SIMD registers, just like you would have to load it into the scalar registers if you wanted to operate on it with normal instructions.
Re: FFmpeg School of Assembly Language
#116The only thing I don't like about this is the focus on x86 assembly, which is a sinking ship because RISC-V is coming to eat its lunch, FAST.
Re: FFmpeg School of Assembly Language
#117Ask me anything.
Re: FFmpeg School of Assembly Language
#118I am the author of these lessons. Ask me anything.
Hi thank you for writing this!
Re: FFmpeg School of Assembly Language
#119Earlier quoted context omitted.
"The FFmpeg devs are somewhat infamously against intrinsics (they don't allow them in their codebase even if the performance is as good as equivalent assembly)" Why?
Have you seen C code with SIMD intrinsics? They are an eyesore
Re: FFmpeg School of Assembly Language
#120I am the author of these lessons. Ask me anything.
I have a question, as someone who can just about read assembly but still do not intuitively understand how to write or decompose ideas to utilise assembly, do you have any suggestions to learn / improve this?
As in, at what point would someone realise this thing can be sped up by using assembly? If one found a function that would be really performant in assembly how do you go about writing it? Would you take the output from a compiler that's been converted to assembly or would you start from scratch? Does it even matter?