Skip to content

chacha20poly1305: Implement SIMD optimizations for tag comparison - #258

Closed
matbech wants to merge 2 commits into
utelle:mainfrom
matbech:poly1305
Closed

chacha20poly1305: Implement SIMD optimizations for tag comparison#258
matbech wants to merge 2 commits into
utelle:mainfrom
matbech:poly1305

Conversation

@matbech

@matbech matbech commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

Add SIMD support for poly1305 tag comparison.

Type of Change

  • Feature / Enhancement (new functionality)

Problem / Motivation

Improves performance for WASM SIMD and -msse4.1 or /arch:SSE4.2 with MSVC.

Checklist

  • I have independently verified the issue
  • I am not submitting unverified or speculative changes
  • I understand that AI-assisted changes must be reviewed by a human before submission

Add SIMD support for poly1305 tag comparison
@matbech matbech changed the title Implement SIMD optimizations for tag comparison chacha20poly1305: Implement SIMD optimizations for tag comparison Sep 3, 2026
@utelle

utelle commented Sep 3, 2026

Copy link
Copy Markdown
Owner

In its current form I can't accept this PR unfortunately. For SQLite3MC I chose the approach to instruct the compiler by setting target attributes, which CPU features to use. But which code branch is actually used is decided at runtime by checking the available CPU features.

Your approach requires to specify the correct compile options, otherwise the fallback branch is used, even if the CPU is able to excute better variant.

Since the amount of code is small, I can handle the implementation in SQLite3MC's style.

@matbech

matbech commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

I could remove the implementations for the x86 and aarch64 architectures, which would only leave WASM SIMD. Would that be acceptable?

@utelle

utelle commented Sep 3, 2026

Copy link
Copy Markdown
Owner

I could remove the implementations for the x86 and aarch64 architectures, which would only leave WASM SIMD.

That's not the point. Of course, it makes sense to make use of available CPU features and to accelerate the implementation for the x86 and aarch64 architecture, too.

I already started to code it in the way that the best available implementation is chosen at runtime.

Yes, I know it's different for WASM, because feature detection at runtime is not supported. So, for WASM using SIMD can only achieved by using the corresponding compile time option.

@matbech

matbech commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

I agree. Architecture-specific implementations should be separated into their own files. I'll close this PR for now, but feel free to open a new one with the restructured approach.

@matbech matbech closed this Sep 3, 2026
@utelle

utelle commented Sep 3, 2026

Copy link
Copy Markdown
Owner

I agree. Architecture-specific implementations should be separated into their own files. I'll close this PR for now, but feel free to open a new one with the restructured approach.

I added the architecture-specific poly1305_tagcmp implementations in branch hwaccel to make sure I didn't introduce any bugs. The CI runs succeeded, so that the changes can be applied to the main branch.

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