Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

Refactors XtsMode following CtrMode128 pattern to eliminate virtual call overhead and keep tweak data in registers instead of spilling to stack.

Changes

  • XtsMode128.cs: Generic implementation using IBlock16Cipher<T> constraints for devirtualization. Uses Vector128<byte> directly for tweaks instead of VectorBuffer16 to avoid register/stack transfers.

  • XtsMode128.Avx2.cs: 8-block processing with Vector256<byte> and Gf128MulV256 using carryless multiply.

  • XtsMode128.Avx512.cs: 16/32-block processing with Vector512<byte> and Gf128MulV512.

Usage

// Before (interface-based, virtual calls)
new XtsMode(AesCrypto.CreateCore(key1), AesCrypto.CreateCore(key2))

// After (generic, devirtualized + inlined)
new XtsMode128<AesCipher, AesCipher>(AesCipher.Create(key1), AesCipher.Create(key2))

All XTS logic (XOR-encrypt-XOR, ciphertext stealing) preserved exactly. All methods marked [MethodImpl(MethodImplOptions.AggressiveInlining)].

Original prompt

参考 CtrMode128 重构 XtsMode,不要随意更改/优化逻辑;重点考虑零抽象开销,保持展开保证 inline,避免类似现在的实现会导致数据在寄存器和堆栈来回读写;


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Refactor XtsMode based on CtrMode128 Add XtsMode128<TDataCipher, TTweakCipher> with zero-abstraction overhead Dec 1, 2025
Copilot AI requested a review from HMBSbige December 1, 2025 15:02
@HMBSbige HMBSbige marked this pull request as ready for review December 2, 2025 10:14
@HMBSbige HMBSbige merged commit ef900f6 into master Dec 2, 2025
6 checks passed
@HMBSbige HMBSbige deleted the copilot/refactor-xts-mode branch December 2, 2025 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants