Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-41115

Add RISC-V Zbc accelerated CRC32C implementation

    XMLWordPrintable

Details

    • Add hardware-accelerated CRC32C support for RISC-V processors with the Zbc carry-less multiplication extension.

    Description

      Problem

      MariaDB currently provides hardware-accelerated CRC32C implementations for several architectures, but there is no accelerated CRC32C implementation for RISC-V.

      On 64-bit RISC-V processors supporting the Zbc extension, the carry-less multiplication instructions clmul and clmulh can be used to accelerate CRC32C computation.

      This task proposes adding a RISC-V Zbc accelerated CRC32C implementation.

      Proposed solution

      Add an accelerated CRC32C implementation for 64-bit RISC-V systems with the Zbc extension.

      The implementation uses 128-bit CRC folding with carry-less multiplication and Barrett reduction.

      The proposed change includes:

      • a RISC-V-specific Zbc CRC32C implementation
      • build-time detection of compiler/toolchain support
      • runtime detection of Zbc support
      • integration with the existing CRC32C implementation dispatch
      • fallback to the existing implementation when Zbc is unavailable

      The change is intended for the main branch and does not change CRC32C behavior on other architectures.

      Correctness

      The implementation was validated against MariaDB's existing CRC32C implementation on a Spacemit X100 RISC-V system.

      The following tests passed:

      • MariaDB unittest/mysys/crc32-t.c via ctest -R crc32: 36/36 tests passed
      • RFC 3720 test vector: crc32c("123456789") == 0xE3069283
      • exhaustive comparison with the existing implementation for input lengths from 0 through 4096 bytes
      • 500 randomized test cases
      • 100 chained CRC calculations
      • unaligned input offsets from 1 through 17 bytes

      All tested results were bit-identical to the existing implementation.

      Test platform:

      Architecture: RISC-V 64-bit
      CPU: Spacemit X100
      CPU cores: 8
      Memory: 31 GB
      Compiler: GCC 14.3.0 (Ubuntu)
      

      Performance

      A microbenchmark was run on the same Spacemit X100 system, comparing the proposed Zbc implementation with MariaDB's existing slicing-by-4 CRC32C slow path through the same my_crc32c interface.

      Buffer       Existing slow    Zbc       Speedup
      (MB/s)           (MB/s)
       
      128 B        289              1118      3.87x
      256 B        296              1082      3.65x
      1 KiB        297              1123      3.79x
      4 KiB        297              1073      3.62x
      64 KiB       295              1069      3.63x
      

      The Zbc implementation provides approximately 3.6x-3.9x higher CRC32C throughput for the tested buffer sizes.

      These are local engineering measurements on the system described above and are not intended as cross-platform performance guarantees.

      Compatibility

      The accelerated implementation is built only when the required RISC-V toolchain support is available and is selected only when runtime Zbc support is detected.

      Systems without Zbc continue to use the existing CRC32C implementation.

      Non-RISC-V platforms are unaffected.

      There is no API change and no change to the CRC32C values produced.

      Attachments

        Issue Links

          Activity

            People

              marko Marko Mäkelä
              6eanut Jiakai Xu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0d
                  0d
                  Logged:
                  Time Spent - 1.25h
                  1.25h

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.