refactor: shift 单遍融合内核化并整体 constexpr - #5
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
shift_left/shift_right原先「先整块拷贝 + 原地移位」,数据被扫 2~3 遍,位移循环的 carry 在字间串行传播,且shift_*_array用memset是「变换类算法整体非 constexpr」这一已知限制的直接来源。改动
detail/word_ops.hpp:删除shift_left_array/shift_right_array,新增 constexpr 单遍融合内核shift_left_fused/shift_right_fused(读入写出,每输出字只依赖两个独立输入字,无串行 carry 依赖链)。count==0、count>=N*64、bit_shift==0(短路防>>64UB)均由公式天然正确处理,无特判分支;assert(out != in)声明不承诺重叠。删除不再使用的<cstring>。algorithms.hpp:compose_shifted_block删预拷贝循环、改 constexpr;shift_left/shift_right(span 与 bit_block 两种形态)整体 constexpr。tests/test_bitcal.cpp:新增 constexpr 编译期断言(static_assert,覆盖 count=64/65/256)+ 128 位词内位移极端(count=1/63)+ 纯词移(count=64)确定性用例 + 512 位随机对照。共 49 用例。NOTES.md:已知限制缩窄为「仅bit_*非 constexpr」;CHANGELOG.md:加 ♻️ 重构 / 🧪 测试 / 📚 文档条目。验证
-mno-avx2)两套构建 ctest 100% 通过——constexpr static_assert 在两个配置编译,验证「constexpr 与后端无关」。公开 API 签名与语义不变,非破坏性变更。