1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00
Files
6eanut 3cdcd64fb0 MDEV-41271 Add RISC-V Zvbc accelerated CRC-32C implementation
Extend the RISC-V CRC-32C path with a Zvbc vector implementation:

  - mysys/CMakeLists.txt: detect Zvbc + RVV intrinsics under
    -march=rv64gc_zbb_zvbc; when available rebuild the new
    crc32c_riscv_zvbc.cc with that march (optional, Zbc unaffected);
  - mysys/crc32/crc32c_riscv_zvbc.cc (new): K-lane vector core --
    4 lanes x 128-bit folding, vlseg2e64 de-interleaved 64B loads,
    vclmul_vx broadcast constants, single-element vector CLMUL for
    the Barrett merge (no scalar Zbc instruction anywhere), bit-exact
    with the Zbc core (same fold constants k1..k4 and Barrett math);
  - adaptive VLEN: one e64m1 vector pair at VLEN>=256, two pairs at
    VLEN=128, so 128-bit cores execute the vector path at full width;
  - mysys/crc32/crc32c_riscv.cc + crc32c.cc: runtime dispatch via
    riscv_hwprobe -- Zbc is preferred when present (existing
    deployments keep the optimized scalar core); the Zvbc vector
    path accelerates cores that implement Zvbc but not scalar Zbc.

Correctness: RFC 3720 + random/chained/boundary inputs bit-identical
to slicing-by-4; official unittest/mysys/crc32-t.c 36/36.

Performance on Spacemit X100 (k3, VLEN=256, gcc 14.3.0), vs inherited
slicing-by-4 crc32c_slow (official slow path, same my_crc32c entry):

    len      slow (MB/s)   PR-B2 Zvbc (MB/s)   vs slow
    128 B        289            1147              4.0x
    256 B        296            2105              7.1x
    1 KiB        297            5466             18.5x
    4 KiB        297            9116             30.7x
    64 KiB       296           11398             38.7x

Dispatch prefers the scalar Zbc path when Zbc is available, so
existing Zbc deployments see no behavior change or regression;
the vector path is selected on cores without scalar Zbc.
No behavior change on non-riscv64 builds or toolchains without
Zvbc (optional compile check).

Review revisions requested on PR #5746 (dr-m):

  - mysys/crc32/crc32c_riscv.cc: assemble the ZBC/ZVBC extension bits
    without a branch at both sites, dropping the redundant intermediate
    variable; replace `(void) hwprobe;` with `std::ignore = hwprobe;` and
    include <tuple>.  <tuple> introduces no static constructor, so the
    ifunc resolver's load-time constraint is unaffected.
  - mysys/crc32/crc32c.cc: expand the comment above the Zbc preference
    with the structural reason -- the vector core deliberately reuses the
    scalar fold to stay bit-exact, so its vl is capped at 4 and a wider
    VLEN buys nothing; scalar Zbc is preferred because the two are level
    on large input and the scalar path is clearly ahead on small input.
    Comment-only.

Assisted-by: YuanSheng:DeepSeek-V4-Flash
Co-authored-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn>
2026-10-01 10:26:01 +03:00
..
2025-10-07 13:01:57 +03:00