DarkShikari

Joined 18 years ago

Karma
6,761
Submissions
886
Member since
Jul 15
I'm the lead developer of the x264 project and also an ffmpeg developer. I do consulting and contract-coding work related to video compression; more details can be found here, along with a CV: http://x264.nl/developers/Dark_Shikari/CV.pdf .

My blog: http://x264dev.multimedia.cx/

My email: [email protected]

View on Hacker News

Recent submissions

Comment · 13 years ago
Original thread: https://news.ycombinator.com/item?id=5598010

Relatedly, it'd be cool if one of the AMD people involved in the OpenCL work (which was committed at the same time) could do a writeup of those optimizations.

Comment · 13 years ago
The penalty is at most ~1 cycle of latency -- in practice I find it gets completely absorbed by the OOE engine. I've never measured any significant penalty in any code for mixing float and int SSE operations on any x86 microarchitecture.

Floating point bitwise operations exist too: xorps, andps, and so on.

Comment · 13 years ago
x264 actually turns off vectorization in the configure script, because it's caused crashes and bugs in the past on various platforms. But even if you enable it, it usually almost never triggers. Even the Intel compiler's autovectorization only triggers in a few functions, despite its reputation, and typically does an pretty mediocre job.

The problem has many parts:

1. Autovectorization in general is just extremely difficult and even trivial code segments often get compiled very badly. It feels like the compiler is trying to fit the code into a few autovectorization special cases -- for example, a 16x16->16 multiply gets compiled into a 16x16->32 multiply, and then it laboriously extracts the 16 bits, probably because nobody wrote code to explicitly handle the former variant. A good autovectorizer would have to have a vast array of these sort of things to "know what to do" in a particular case, I'd imagine.

A lot of autovectorization resources seem to be tuned towards floating point math (which typically doesn't need the same sort of tricks), which probably exacerbates the problem in x264's case.

2. The compiler doesn't know enough. It can't guarantee alignment, it doesn't know about the possible ranges of the input values or the relationship among them, it doesn't know the things the programmer knows.

3. SIMD algorithms are often wildly different from the original C. Much of the process of writing assembly is figuring out how to restructure, reorder, and transform algorithms to be more suitable for SIMD. The compiler can't really realistically do this; its job is to translate your C operations into machine operations, not rewrite your algorithm.

Part of this problem is that C is just not a great vector math language, but part of it is also that the optimal algorithm structure will depend on the capabilities of your SIMD instructions and their performance. For example, when the pmaddubsw instruction is available, it's faster to do x264's SATD using a horizontal transform first, but if not, it's faster to do it with a vertical transform first. The Atom CPU has pmaddubsw, but only has a 64-bit multiplier, making it too slow to utilize the horizontal version (so it gets the vertical version instead).

You can definitely finagle code into getting hit by the autovectorizer, especially with Intel's compiler, but it takes a lot of futzing to make it happy, and even when it is happy, it can be many times slower than proper assembly. Of course, it's not useless -- it can get you some relatively free performance improvements without writing actual SIMD code. But it's not a replacement.

Comment · 13 years ago
I almost never spend more than a few seconds considering register allocation/naming when writing assembly (part of this is because x264's abstraction layer lets macros swap their arguments, so you don't have to track "what happens to be in xmm0 right now" mentally). In some rare cases it can get tricky when you start pushing up against the register cap, but that's exactly the case where the compiler tends to do terribly, and you'd want to do it yourself.

The pain of not having a proper macro assembler in C intrinsics is orders of magnitude worse than having to do my own register allocation in yasm, so for now, yasm is the lesser of two evils.

Comment · 13 years ago
Intrinsics aren't really C; they work in a C-like syntax, but you're still doing the exact same thing as assembly: you still have to write out every instruction you want to use, so you're not really saving any effort compared to just skipping the middleman.

In return, you are stuck with an extremely ugly syntax and a much less functional preprocessor, with the added bonus of a compiler that mangles your code.

Comment · 13 years ago
"C libraries for things like SSE2"? Do you mean math libraries that have SIMD implementations of various functions that are callable from C? This here is effectively writing those libraries; they don't exist until we write the code.
Comment · 13 years ago
Comment · 13 years ago
In all fairness, Intel's emulator is incredibly easy to use; it literally works like this:

sde -- ./myprogram myargs

instead of

./myprogram myargs

There's also probably a decent number of people at this point who have prerelease CPUs; they tend to breed quite explosively in the month or two before the official release.

Comment · 13 years ago
I only pushed the code a few minutes ago, but binaries should probably be up at http://x264.nl/ relatively soonish (it's not my site though, so I wouldn't know exactly).

If you want to test without a physical Haswell, the Intel Software Development Emulator should work okay, albeit somewhat slowly. I'd post overall numbers for real Haswells, but Intel has apparently said we can't do that yet.

Regarding FMA, FMA3/4 are floating point only. Since x264 has just one floating point assembly function, only two FMA3/FMA4 instructions get used in all of x264 (not counting duplicates from different-architecture versions of the function). An FMA4 version has been included for a while; the new AVX2 version does include FMA3, but of course that won't run on AMD CPUs (yet).

XOP had some integer FMA instructions, but I generally didn't find them that useful (there's a few places I found they could be slotted in, though).

Comment · 13 years ago
I'm going to check with CoreCodec (the folks helping us administer x264 LLC) and see what's going on here. If they're abusing the terms of the license, we'll make sure things get fixed. If not, we'll publish all the changes they've made -- and honestly, I would be shocked if they've done anything significant besides change the program name.
Comment · 14 years ago
There's still a lot of cases where it's very hard for even a consumer-facing US-based web startup to get traction in another country, for language and cultural reasons. Japan is a particularly notable case; it's often said that companies without an office in Japan never succeed there. Some examples:

Pixiv vs. DeviantArt

Mixi vs. Facebook

Nico Nico Douga vs. Youtube

China is an even more extreme case, though that also has problems of corruption, legal wrangling, censorship, and so on.

Comment · 14 years ago
Candy is hardly a gendered product, and foreign interest in Japanese culture and food isn't either. Adding gendered advertising in such a way is unlikely to gain many new leads, but will certainly limit the audience dramatically.

For some reason, the "testimonials from random Japanese people" idea seems rather unsettling to me. It makes it feel exoticized, touristy, and fake.

Comment · 14 years ago
The sparse Fourier transform is also probably not useful for any of that stuff, because accurate results are needed (not just getting one or two of the main tones). Transforms are not the bottleneck at all in video encoding, and even in audio encoding, split-radix FFTs and the like are very fast.

High-res Dirac video encoding is definitely possible in real-time, you just need a very optimized encoder, which doesn't really exist. Dirac's main speed cost comes from the overlapped-block motion compensation, not the transform.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton