Debian Codegraph @

debian/rust-vendor/crc-fast/.kiro/specs/crc-width32-shared-base/tasks.md

raw
1 # Implementation Plan: CRC Width-32 Shared Base
2
3 ## Overview
4
5 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.
6
7 ## Tasks
8
9 - [x] 1. Create shared width32_ops module
10 - [x] 1.1 Create src/crc32/width32_ops.rs with shared constants
11 - Add module documentation explaining purpose
12 - Add WIDTH32_CONSTANTS_REFLECTED and WIDTH32_CONSTANTS_FORWARD
13 - Add load_constants() function
14 - _Requirements: 1.1, 1.4_
15
16 - [x] 1.2 Add shared fold operations to width32_ops
17 - Implement fold_16() function
18 - Implement fold_width() function
19 - _Requirements: 1.3_
20
21 - [x] 1.3 Add shared barrett_reduction to width32_ops
22 - Implement barrett_reduction() returning [u64; 2] for caller to extract bits
23 - _Requirements: 1.3_
24
25 - [x] 1.4 Add shared helper functions to width32_ops
26 - Implement create_coefficient() function
27 - Implement get_last_bytes_table_ptr() function
28 - _Requirements: 1.3, 1.5_
29
30 - [x] 1.5 Add shared process_0_to_15 to width32_ops
31 - Move the shared implementation from crc32/algorithm.rs
32 - _Requirements: 1.2_
33
34 - [x] 1.6 Update src/crc32/mod.rs to export width32_ops
35 - Add `pub(crate) mod width32_ops;`
36 - _Requirements: 1.1_
37
38 - [x] 2. Checkpoint - Verify module compiles
39 - Ensure `cargo check` passes
40
41 - [x] 3. Refactor Width32 implementation
42 - [x] 3.1 Update Width32 load_constants to delegate
43 - Call width32_ops::load_constants()
44 - _Requirements: 3.1_
45
46 - [x] 3.2 Update Width32 fold_16 to delegate
47 - Call width32_ops::fold_16()
48 - _Requirements: 3.1_
49
50 - [x] 3.3 Update Width32 fold_width to delegate
51 - Call width32_ops::fold_width()
52 - _Requirements: 3.2_
53
54 - [x] 3.4 Update Width32 barrett_reduction to delegate
55 - Call width32_ops::barrett_reduction() and extract 32-bit result
56 - _Requirements: 3.6_
57
58 - [x] 3.5 Update Width32 create_coefficient to delegate
59 - Call width32_ops::create_coefficient()
60 - _Requirements: 3.3_
61
62 - [x] 3.6 Update Width32 perform_final_reduction to delegate
63 - Call width32_ops::fold_width() and width32_ops::barrett_reduction()
64 - _Requirements: 3.4_
65
66 - [x] 3.7 Update Width32 get_last_bytes_table_ptr to delegate
67 - Call width32_ops::get_last_bytes_table_ptr()
68 - _Requirements: 3.5_
69
70 - [x] 3.8 Update crc32::algorithm::process_0_to_15 to delegate
71 - Call width32_ops::process_0_to_15()
72 - _Requirements: 3.7_
73
74 - [x] 4. Checkpoint - Verify CRC-32 still works
75 - Run `cargo test` to ensure CRC-32 tests pass
76
77 - [x] 5. Refactor Width16 implementation
78 - [x] 5.1 Update Width16 load_constants to delegate
79 - Call width32_ops::load_constants()
80 - _Requirements: 2.1_
81
82 - [x] 5.2 Update Width16 fold_16 to delegate
83 - Call width32_ops::fold_16()
84 - _Requirements: 2.1_
85
86 - [x] 5.3 Update Width16 fold_width to delegate
87 - Call width32_ops::fold_width()
88 - _Requirements: 2.2_
89
90 - [x] 5.4 Update Width16 barrett_reduction to delegate
91 - Call width32_ops::barrett_reduction() and extract 16-bit result
92 - _Requirements: 2.6_
93
94 - [x] 5.5 Update Width16 create_coefficient to delegate
95 - Call width32_ops::create_coefficient()
96 - _Requirements: 2.3_
97
98 - [x] 5.6 Update Width16 perform_final_reduction to delegate
99 - Call width32_ops::fold_width() and width32_ops::barrett_reduction()
100 - _Requirements: 2.4_
101
102 - [x] 5.7 Update Width16 get_last_bytes_table_ptr to delegate
103 - Call width32_ops::get_last_bytes_table_ptr()
104 - _Requirements: 2.5_
105
106 - [x] 5.8 Update crc16::algorithm::process_0_to_15 to delegate
107 - Call width32_ops::process_0_to_15()
108 - _Requirements: 2.7_
109
110 - [x] 6. Checkpoint - Verify CRC-16 still works
111 - Run `cargo test` to ensure CRC-16 tests pass
112
113 - [x] 7. Final verification and cleanup
114 - [x] 7.1 Run full test suite
115 - Run `cargo test` to verify all tests pass
116 - _Requirements: 4.5_
117
118 - [x] 7.2 Run code quality checks
119 - Run `cargo fmt --check`
120 - Run `cargo clippy -- -D warnings`
121 - _Requirements: 5.1, 5.2, 5.3_
122
123 - [x] 7.3 Verify CRC-64 unchanged
124 - Confirm CRC-64 tests still pass
125 - _Requirements: 4.3_
126
127 ## Notes
128
129 - This is a pure refactoring with no behavior changes
130 - All existing tests serve as regression tests
131 - The shared module is placed in crc32/ since CRC-32 is the "native" width for these operations
132 - CRC-16 scales to 32-bit space, uses shared ops, then scales back to 16 bits
133 - CRC-64 remains unchanged as it has different SIMD operations