Expand description
Optional hand-tuned x86 assembly acceleration using openh264’s BSD-2 kernels.
This crate is deliberately not #![forbid(unsafe_code)]: it links and calls
hand-written assembly through FFI. It is the opt-in “speed over the pure-safe-Rust
guarantee” path — the rest of the codec stays forbid(unsafe) and falls back to
the scalar/wide implementations when this crate is not enabled.
openh264 asm is BSD-2 licensed; attribution lives in openh264/LICENSE.
The vendored kernels are x86-64 only. On every other architecture this crate
compiles to an empty lib (the whole module is gated on target_arch = "x86_64") and
callers fall back to the pure-Rust scalar path — selected by the accel cfg that the
consumer crates’ build scripts set only for x86_64 + the asm feature. This is what
lets a downstream default-features build (e.g. rff) succeed on arm64 macOS.
Structs§
Functions§
- bs_
motion_ masks - Safe dispatcher: AVX2 when present, else the caller’s scalar twin.
Returns
Nonewhen AVX2 is unavailable so the caller keeps its own oracle path. - bs_
motion_ masks_ two_ list - Safe dispatcher for the two-list masks kernel;
Nonewhen AVX2 is absent. - chroma8x8_
pred - 8×8 chroma intra prediction into
pred(16-aligned, ≥64 bytes) via openh264’sWelsIChromaPred{V,Plane}_sse2.rec[base]= chroma MB top-left; reads the top row / left col from the aligned plane.mode: 2=Vertical, 3=Plane (the only modes with sse2; DC/Horizontal are C-only → caller uses scalar). Bit-identical tochroma8x8_pred. - dct_
four_ t4 - Forward 4×4 core DCT of an 8×8 region (four 4×4 blocks) of the residual
src - pred, via openh264’sWelsDctFourT4_sse2. Writes 64i16coefficients todct: blocks in(0,0),(4,0),(0,4),(4,4)order, raster within each block. The integer core transform is bit-identical to our scalarforward_core(out0=s0+s1, out1=2·s3+s2, out2=s0-s1, out3=s3-2·s2), so quantizing these coefficients yields identical levels — a pure speedup, byte-for-byte. - deblock_
chroma_ eq4_ h - Chroma strong filter (
bS == 4) of a vertical edge, Cb+Cr, viaDeblockChromaEq4H_ssse3. - deblock_
chroma_ eq4_ v - Chroma strong filter (
bS == 4) of a horizontal edge, Cb+Cr, viaDeblockChromaEq4V_ssse3. - deblock_
chroma_ lt4_ h - Chroma loop filter of a vertical edge (
bS < 4), Cb+Cr, viaDeblockChromaLt4H_ssse3(p/q horizontal).*_p1start atp1= 2 cols left ofq0;pPix = p1 + 2.tcas_v. - deblock_
chroma_ lt4_ v - Chroma loop filter of a horizontal edge (
bS < 4), Cb+Cr together, viaDeblockChromaLt4V_ssse3(p/q vertical).*_p1start atp1= 2 rows aboveq0;pPix = p1 + 2·stride.tc[i]per 2-sample segment (the spec chromatc0+1;0= skip). Bit-identical to ourfilter_chroma_line. - deblock_
luma_ eq4_ h - In-place loop filter of a vertical luma edge (
bS == 4, strong) via transpose →DeblockLumaEq4V→ transpose-back.p4as indeblock_luma_lt4_h. - deblock_
luma_ eq4_ v - In-place loop filter of a horizontal luma edge (
bS == 4, strong) via openh264’sDeblockLumaEq4V_ssse3.p3as indeblock_luma_lt4_v. - deblock_
luma_ lt4_ h - In-place loop filter of a vertical luma edge (
bS < 4) via transpose →DeblockLumaLt4V→ transpose-back (openh264’sDeblockLumaLt4HC wrapper).p4starts atp3= columnx−4of the top row; the kernels transpose the 16×8 region, filter the now-horizontal edge, and write back. Bit-identical to our spec filter. - deblock_
luma_ lt4_ v - In-place loop filter of a horizontal luma edge (
bS < 4) via openh264’sDeblockLumaLt4V_ssse3. The “V” filter direction is vertical (p0 = pPix[-stride]), applied across a horizontal edge’s 16 columns;tc[i]per 4-column segment (−1= skip).p3starts atp3= 4 rows aboveq0(same column);pPix = q0 = +4·stride. Bit-identical to the spec filter (ourfilter_luma_line). - dequant_
4x4 - Safe dispatcher.
None= no AVX2, caller keeps its scalar twin (the oracle). - hpel_
fused - Builds the three half-pel planes from the edge-padded full-pel plane
f(pw×ph, row stridepw). Returnsfalse(no work done) when AVX2 is unavailable or the plane is too narrow for the vector interior — the caller falls back to its scalar/tile path. - i16x16_
luma_ pred - 16×16 luma intra prediction into
pred(must be 16-aligned, ≥256 bytes) via openh264’sWelsI16x16LumaPred{V,H,Dc,Plane}_sse2.rec[base]= MB top-left; the kernel reads the top row (rec[base−stride+i]) and/or left col (rec[base−1+i·stride]) and writes the 16×16 prediction.mode: 0=V, 1=H, 2=DC, 3=Plane — caller ensures the required neighbors exist (both for DC/Plane). Bit-identical to the spec predictor. - idct_
four_ t4_ rec - mb_
uniform - Safe dispatcher for [
mb_uniform_avx2];Nonemeans “no AVX2, use your scalar twin”. - mc_
centre - Centre half-pel luma plane (
McHorVer22, the(2,2)separable 6-tap) of aw×hblock, via openh264’s 2-stageHorFirst(horizontal 6-tap → full-precision i16 tap buffer) +VerLastAlign(vertical 6-tap →clip((·+512)>>10)). width-16 = two width-8 halves. The 2D 6-tap is separable, so H-first matches our V-firstluma_centreexactly.t[half·8 + row·ts]feeds each half’s HorFirst (the tile’s 2-col/2-row border = thepSrc−2shift). Bit-identical. - mc_
chroma_ w4 - Eighth-pel chroma bilinear MC of a 4-wide block (
McChromaWidthEq4_mmx) — same formula andabcdweights asmc_chroma_w8, for the narrower block. - mc_
chroma_ w8 - Eighth-pel chroma bilinear MC of an 8-wide block (
McChromaWidthEq8_sse2):dst[r,c] = (A·s[r,c] + B·s[r,c+1] + C·s[r+1,c] + D·s[r+1,c+1] + 32) >> 6, whereabcd = [A,B,C,D] = [(8−fx)(8−fy), fx(8−fy), (8−fx)fy, fx·fy](g_kuiABCD).srcis the edge-clamped9×(height+1)tile (stridesrc_stride ≥ 9); the kernel reads 9 cols (movqatsrcandsrc+1) ×height+1rows. Bit-identical to the scalar bilinear ininter::mc_chroma. - mc_
hor20 - Horizontal half-pel luma plane (
McHorVer20, the(2,0)6-tap) of aw×hblock.src[off]is the first output pixel in the (border-padded) tile, stridets; the kernel readssrc[off−2 .. off+3]per row. Writes the contiguousw·hresult intodst.w∈ {8,16}. Bit-identical to ourluma_h. - mc_
ver02 - Vertical half-pel luma plane (
McHorVer02, the(0,2)6-tap) of aw×hblock. width-16 = two width-8 halves into a stride-16 scratch (no sse2 02WidthEq16). Readssrc[off−2·ts .. off+3·ts]per column. Bit-identical to ourluma_v.w∈ {8,16}. - pixel_
avg - Per-pixel average of two
w×hblocks at independent strides:dst[i] = (a[i] + b[i] + 1) >> 1, written contiguously at stridew. - quant_
four_ 4x4 - In-place quantization of four 4×4 DCT-coefficient blocks (64
i16) via openh264’sWelsQuantFour4x4_sse2:level = sign·(((|c| + FF)·MF) >> 16)with the per-positionFF/MFtables (8 entries each, reused for both halves). NOTE: this is openh264’s quantizer (deadzone added before the multiply, fixed>>16), structurally different from our(|c|·MF + F) >> qbits— so it is NOT bit-identical to ourquantize. Exposed for the kernel ranking + an openh264-semantics path;dctmust be 16-byte aligned. - sad_
8x16 - SAD of an 8×16 luma block. Bit-identical to
Σ|a−b|. - sad_
16x8 - SAD of a 16×8 luma block. Bit-identical to
Σ|a−b|. - sad_
16x16 - SAD of a 16×16 luma block against another via openh264’s SSE2
psadbwkernel. Trivially bit-identical toΣ|a−b|.stride*in samples. - sad_x4
- SADs of one
w×hsource block vs four offsetsointobase(striders), for every ME partition shape. Values are exactlyΣ|a−b|per candidate.Nonewithout AVX2 or for an uncovered shape. - satd_
4x4 - SATD (sum of absolute Hadamard-transformed differences) of two 4×4 blocks via
openh264’s SSE2 kernel.
stride*are in samples (bytes). Bit-identical to openh264’sWelsSampleSatd4x4_c((Σ|H·d| + 1) >> 1). - satd_
8x8 - SATD of a 8×8 block pair via openh264’s Hadamard kernel (AVX2 when available, else SSE2 — bit-identical). Equal to the sum of the constituent 4×4 SATDs.
- satd_
8x16 - SATD of a 8×16 block pair via openh264’s Hadamard kernel (AVX2 when available, else SSE2 — bit-identical). Equal to the sum of the constituent 4×4 SATDs.
- satd_
16x8 - SATD of a 16×8 block pair via openh264’s Hadamard kernel (AVX2 when available, else SSE2 — bit-identical). Equal to the sum of the constituent 4×4 SATDs.
- satd_
16x16 - SATD of a 16×16 block pair via openh264’s Hadamard kernel (AVX2 when available, else SSE2 — bit-identical). Equal to the sum of the constituent 4×4 SATDs.
- satd_
avg - Fused
SATD(src, (a+b+1)>>1)of aw×hblock —Σ|H·d|, the SAME valuesatd_pxcomputes on the materialized average (NOT the(Σ+1)>>1theWelsSampleSatd*wrappers return).Nonewhen AVX2 is unavailable or the size is unsupported — the caller then materializes and takes the old path, so a non-AVX2 machine is byte-identical by construction. - satd_
avg_ x4 - Four fused avg+SATDs of one
w×hsource block:(plane_a, off_a, plane_b, off_b)per candidate, shared stride — the quarter-pel ring for every ME partition shape.Nonewithout AVX2 or for an uncovered shape. - satd_x4
Σ|H·d|SATDs of onew×hsource block vs four offsetsointobase(striders) — the diamond’s shape, for every ME partition. The exact scalar-Hadamard value (satd_pxdomain, NOT the(Σ+1)>>1the Wels wrappers return).Nonewithout AVX2 or for an uncovered shape.- satd_
x4p - Four SATDs (
Σ|H·d|) of onew×hsource block vs four INDEPENDENT plane operands (shared stride) — the sub-pel ring’s shape, now for every ME partition.Nonewithout AVX2 or for an uncovered shape. - x4_
shape - True iff the x4 family covers this ME partition shape.