Skip to content

Request to revert: polyval: use avx+pclmulqdq features on x86/x86_64 #317 #346

Description

@SirDMZ

PCLMULQDQ: Introduced in 2010. Fairly Old. The code needs this. Safe to feature gate out.

VEX: vpclmulqdq in asm in this code base is VEX-encoded 128-bit (needs only AVX+PCLMULQDQ) AVX came out in 2011. Fairly Old.

Per Issue 184, the desire is to have vpclmulqdq asm produced. Per my benchmarking it is 0.5% faster, and potentially 4% faster depending on other factors.
Per issue 315, while AVX is fairly old, some... cheaper CPU's didn't/don't ship with it, breaking the goal of producing VEX (vpclmulqdq in asm).

So cool. Lets feature gate up this high. Fairly old. AVX2 came out in full in 2017 (AMD Zen1), so almost 10 years ago.

There's potential further discussion to have with AVX1 vs AVX2, but someone else can advocate for that.

VPCLMULQDQ the CPUID Flag: arrives with Intel Ice Lake and newer, and AMD Zen 4. Which rules out a lot of actually still in use CPU's. Feature gating this high prevents fast code on cpu's that support it. This is VEX.256. The code doesn't currently use such widths.

The performance hit is 0.26GiB/s vs 5.94GiB/s in my benchmarks on a LOT of genuinely still used CPU's.

; Legacy SSE (PCLMULQDQ flag)
pclmulqdq xmm0, xmm1, 0x00 ; xmm0 = xmm0 * xmm1

; VEX 128-bit (AVX + PCLMULQDQ — NOT the new flag)
vpclmulqdq xmm0, xmm1, xmm2, 0x00 ; 3-operand, 1 multiply

; VPCLMULQDQ flag — YMM (VEX.256)
vpclmulqdq ymm0, ymm1, ymm2, 0x11 ; 2 independent 64x64→128 multiplies

; VPCLMULQDQ + AVX512F — ZMM (EVEX.512)
vpclmulqdq zmm0, zmm1, zmm2, 0x10 ; 4 independent multiplies

Maybe in future, the codebase could get optimisations for these wider options. There's currently a separate issue for that.

#318 can still be technically correct. it IS optimised for VEX 128-bit which in asm is vpclmulqdq . I don't propose reverting it.

Steam hardware survey doesn't appear to expose these exact flags, but AVX 2 is at 95% and AVX512F is at 23%.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions