Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optimized assembly implementation of AES for GOARCH=arm. #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jwgcarlson
Copy link
Collaborator

Tested on an RPi Zero. Overall CPU usage for alohartcd went down when streaming to one peer, from ~26% to ~21%.

Untested. Some further work required.
The assembly in `encryptBlockAsm` now reads more like the pure Go
implementation in `crypto/aes.encryptBlockGo`.

Other small improvements:
- Use register `R11`, which is usually reserved by the Go linker. This
  avoids the need to push/pop `COUNT` from the stack.
- Rationalize register assignment, rather than the seemingly random
  choices from before. This just feels better.
- Load/store whole words from `SRC`/`DST`, rather than one byte at a
  time. This assumes we're running in little-endian mode, but Go is
  already making that assumption for `GOARCH=arm`.
- Re-use constant table from `crypto/aes.sbox0`, rather than re-defining
  our own. (We still have our own `dtable`, since Go's `te0`-`te3` were
  computed for big-endian implementations.)
@jwgcarlson jwgcarlson requested a review from thinkski April 3, 2020 19:35
Copy link
Member

@thinkski thinkski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like great work, something I think that would be worthwhile to try and merge upstream to Golang itself.

@@ -0,0 +1,403 @@
// +build arm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for arm-only or also for arm64?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only arm. The Go standard library already has assembly implementations for arm64.

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