-
-
Notifications
You must be signed in to change notification settings - Fork 45
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 support for big endian platforms #81
Conversation
correctly on big endian platforms.
Thanks for this. Could you show how the perf is degraded after this change? |
Yes I'll try. I've been using the benchmarks to watch performance. I've also been using the nodejs profiler to check if any new functions have started popping up in the cpu profile. On little-endian, my changes should not run any extra byte swapping or loops over the data since that's guarded with Here is the output of
|
Good job Jonathan. Proper pull request! |
Thanks for reviewing and merging @paulmillr! |
This PR adds support for big endian platforms. It adds byte swapping where needed so that all hash functions can run correctly on both big and little endian platforms. It tries to avoid any significant performance degradation on little endian platforms.
The hash families that are affected by this PR are:
All of the other hash families already worked correctly on big endian platforms.
I have included all of the changes in this PR to hopefully make it easy to give feedback on the approach. I'm happy to split it into smaller PRs if preferred.
Most of the byte swapping is done in-place on
Uint32Array
s which gives the best performance of the things I tried.In the blake base class (_blake.ts)
update()
function, there is one spot where the byte swapping is done on thedata32
Uint32Array
which is backed by the input message. The byte swapping is reversed before theupdate()
function returns but while theupdate()
function is running the users input message will have been mutated if they passed it in as aUint32Array
. I'm not sure if its ok for the input to be temporarily mutated but, if not, I have a different fix that avoids mutation but has a bit worse performance.Except for that spot, all other byte swapping should be done only on internal or output buffers.
Thanks in advance for looking at this. I'm happy to make any changes necessary.