OXYGENHUB
# b63fc7a77fc6 oxygen / vendor / crc-fast / .kiro / specs / crc-width32-shared-base / tasks.md
4.5 KiB · Markdown · last changed Strata: the cloud stores send through ureq, so every release target links 1 month ago renderedsource blame history raw

Implementation Plan: CRC Width-32 Shared Base

Overview

This implementation refactors CRC-16 and CRC-32 to share common 32-bit-space operations, eliminating ~200 lines of duplicated code. The refactoring creates a new width32_ops.rs module and updates both Width16 and Width32 implementations to delegate to it.

Tasks

  • 1. Create shared width32_ops module

    • 1.1 Create src/crc32/width32_ops.rs with shared constants

      • Add module documentation explaining purpose
      • Add WIDTH32_CONSTANTS_REFLECTED and WIDTH32_CONSTANTS_FORWARD
      • Add load_constants() function
      • Requirements: 1.1, 1.4
    • 1.2 Add shared fold operations to width32_ops

      • Implement fold_16() function
      • Implement fold_width() function
      • Requirements: 1.3
    • 1.3 Add shared barrett_reduction to width32_ops

      • Implement barrett_reduction() returning [u64; 2] for caller to extract bits
      • Requirements: 1.3
    • 1.4 Add shared helper functions to width32_ops

      • Implement create_coefficient() function
      • Implement get_last_bytes_table_ptr() function
      • Requirements: 1.3, 1.5
    • 1.5 Add shared process_0_to_15 to width32_ops

      • Move the shared implementation from crc32/algorithm.rs
      • Requirements: 1.2
    • 1.6 Update src/crc32/mod.rs to export width32_ops

      • Add pub(crate) mod width32_ops;
      • Requirements: 1.1
  • 2. Checkpoint - Verify module compiles

    • Ensure cargo check passes
  • 3. Refactor Width32 implementation

    • 3.1 Update Width32 load_constants to delegate

      • Call width32_ops::load_constants()
      • Requirements: 3.1
    • 3.2 Update Width32 fold_16 to delegate

      • Call width32_ops::fold_16()
      • Requirements: 3.1
    • 3.3 Update Width32 fold_width to delegate

      • Call width32_ops::fold_width()
      • Requirements: 3.2
    • 3.4 Update Width32 barrett_reduction to delegate

      • Call width32_ops::barrett_reduction() and extract 32-bit result
      • Requirements: 3.6
    • 3.5 Update Width32 create_coefficient to delegate

      • Call width32_ops::create_coefficient()
      • Requirements: 3.3
    • 3.6 Update Width32 perform_final_reduction to delegate

      • Call width32_ops::fold_width() and width32_ops::barrett_reduction()
      • Requirements: 3.4
    • 3.7 Update Width32 get_last_bytes_table_ptr to delegate

      • Call width32_ops::get_last_bytes_table_ptr()
      • Requirements: 3.5
    • 3.8 Update crc32::algorithm::process_0_to_15 to delegate

      • Call width32_ops::process_0_to_15()
      • Requirements: 3.7
  • 4. Checkpoint - Verify CRC-32 still works

    • Run cargo test to ensure CRC-32 tests pass
  • 5. Refactor Width16 implementation

    • 5.1 Update Width16 load_constants to delegate

      • Call width32_ops::load_constants()
      • Requirements: 2.1
    • 5.2 Update Width16 fold_16 to delegate

      • Call width32_ops::fold_16()
      • Requirements: 2.1
    • 5.3 Update Width16 fold_width to delegate

      • Call width32_ops::fold_width()
      • Requirements: 2.2
    • 5.4 Update Width16 barrett_reduction to delegate

      • Call width32_ops::barrett_reduction() and extract 16-bit result
      • Requirements: 2.6
    • 5.5 Update Width16 create_coefficient to delegate

      • Call width32_ops::create_coefficient()
      • Requirements: 2.3
    • 5.6 Update Width16 perform_final_reduction to delegate

      • Call width32_ops::fold_width() and width32_ops::barrett_reduction()
      • Requirements: 2.4
    • 5.7 Update Width16 get_last_bytes_table_ptr to delegate

      • Call width32_ops::get_last_bytes_table_ptr()
      • Requirements: 2.5
    • 5.8 Update crc16::algorithm::process_0_to_15 to delegate

      • Call width32_ops::process_0_to_15()
      • Requirements: 2.7
  • 6. Checkpoint - Verify CRC-16 still works

    • Run cargo test to ensure CRC-16 tests pass
  • 7. Final verification and cleanup

    • 7.1 Run full test suite

      • Run cargo test to verify all tests pass
      • Requirements: 4.5
    • 7.2 Run code quality checks

      • Run cargo fmt --check
      • Run cargo clippy -- -D warnings
      • Requirements: 5.1, 5.2, 5.3
    • 7.3 Verify CRC-64 unchanged

      • Confirm CRC-64 tests still pass
      • Requirements: 4.3

Notes

  • This is a pure refactoring with no behavior changes
  • All existing tests serve as regression tests
  • The shared module is placed in crc32/ since CRC-32 is the "native" width for these operations
  • CRC-16 scales to 32-bit space, uses shared ops, then scales back to 16 bits
  • CRC-64 remains unchanged as it has different SIMD operations