Skipping stuff
Its nice to be able to take shortcuts in the encoding process–its even better when we can take a shortcut that doesn’t even change the output.
A recent example was my intra skip patch. The basic idea behind intra skip lies in the method by which intra analysis works. For each block of an i4x4 or i8x8 block, all 9 prediction modes are analyzed and the best chosen. The prediction modes use the top, left, and/or top-right pixels to predict the block–so the blocks to the top, left, and top-right of the current block have to be encoded in order to know which pixels we will be predicting with:
The numbers show the order in which the blocks are encoded, in order to make sure all the necessary edge pixels are available during analysis. The gray blocks are from neighboring macroblocks which have already been encoded. Note that the “16″ block never gets encoded as part of intra analysis, since it isn’t needed for the edges of anything else.
As a result, we have to encode each block as we go along in the analysis process. Once we’re done, we can save the results of the encoding so that later, if that intra mode is chosen, we can just restore the backup, saving over 2500 clocks of predict/DCT/quant/zigzag/dequant/iDCT.
Next, there’s my p/bskip patch. When pskip/bskip analysis is done, motion compensation on the block is done (with respect to the “skip” motion vector) and then analysis follows. If the skip is chosen, the analysis terminates and the block is encoded… where the motion compensation gets done again. But we can’t just turn off all skip-based motion compensation, because there are some cases where you can have a skip in which the motion compensation wasn’t the last thing that was done. So I made a variable that told the encoder whether it could skip it or not.
Finally, there’s my upcoming fast probe_skip patch, which takes a number of shortcuts in the skip check process:
1. The current skip_check does a full 16×16 DCT (16 4×4 DCTs), and then checks each 4×4 block individually. Quite often, it’ll be able to tell after the first block or two that the block won’t be a skip; in this case, doing the full 16×16 DCT is a good waste of a few hundred clock cycles. So I made it to an 8×8 DCT (4 4×4 DCTs) for each 8×8 block. Why didn’t I do each 4×4 DCT as I went along? The 8×4 DCT (2 4×4 DCTs) is much faster than the 4×4 because its SSE2-accelerated, so I just went ahead and did the 8×8, which is coded as two 8x4s.
2. When checking for a skip, its highly likely that if one got past the first DCT block or two without terminating, most of the rest of the blocks will be zero. As a result, its efficient to check if they’re all zero before zigzag/decimate_score; this only takes a few clocks and quite often allows us to skip the aforementioned somewhat time-consuming steps.
As you can see, its quite good when we can skip something entirely; its even better than speeding up a function; its calling a function less often.

May 4th, 2008 at 7:29 am
Don’t label a diagonal stripe as the same color, since blocks can also be predicted from their top-right neighbor.
May 4th, 2008 at 3:17 pm
Fixed.