Skip to content

perf(mp3): vectorise the fixed-point IMDCT twiddle/window loop #4109

Closed

Description

@zackees

Carved out of #4055, which deliberately left L3_imdct36 scalar.

Why it was skipped

L3_imdct36 is ~13% of decode instructions, but only part of it is addressable:

  • Its inner transform is a 9-point DCT-III (L3_dct3_9) whose butterfly does not map onto four lanes.
  • Vectorising across bands would need stride-18 gathers. The DCT-32 vectorises cleanly because it works across bands, so four consecutive bands are four consecutive int32; the IMDCT works within a band, so they are not.

What is left is the closing twiddle-and-window loop, which is exactly what upstream's float kernel vectorises. With roughly half the kernel addressable, the ceiling is around 2% of whole-decode time.

What it would take

The loop runs i = 0..8 — two vectors of four plus a scalar tail — over contiguous co/si/overlap/twiddle/window arrays. The reversed grbuf[17 - i] store needs a lane reverse, the same shape upstream's float kernel uses VREV for.

The primitives already exist in minimp3.h (MP3D_V_MUL_LO/HI accept two vectors, so vector-by-vector twiddle multiplies work), and it needs one addition: a rounded, saturating narrow from two int64x2 accumulators to int32x4 — the tail of mp3d_v_mulshift, factored out.

The bar

Exact PCM equality with the scalar fixed-point path. mp3d_narrow_q30 rounds once for the whole accumulation rather than once per product, and a vector version must do the same or the results will differ in the low bit.

Worth doing when 2% is worth more than the smaller diff.

Refs #4055, FastLED/license#14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions