[GH-ISSUE #630] Try to assess why 32-bit SHA-1 SSE2 assembler code is faster than the interleaved intrinsics version #290

Closed
opened 2026-10-14 03:00:05 +07:00 by bsakaguchi · 8 comments
Owner

Originally created by @magnumripper on GitHub (Jun 8, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/630

We should try to establish why the 32-bit SHA1 SSE2 assembler is (sometimes) faster than the intrinsics version even though the latter can do interleaved code and use XOP and stuff. This always bothered me - is there some optimization we can do to the intrinsics? Compiler hints? Compiler flags?

Originally created by @magnumripper on GitHub (Jun 8, 2014). Original GitHub issue: https://github.com/openwall/john/issues/630 We should try to establish why the 32-bit SHA1 SSE2 assembler is (sometimes) faster than the intrinsics version even though the latter can do interleaved code and use XOP and stuff. This always bothered me - is there some optimization we can do to the intrinsics? Compiler hints? Compiler flags?
bsakaguchi 2026-10-14 03:00:05 +07:00
Author
Owner

@jfoug commented on GitHub (Jun 8, 2014):

Or is the actual algorithm used the same between the 2? Could we be doing a 'full' sha1, but a shortcut within the old mmx code ?? Yes, this one has not made me overly happy either. Seems very counter intuitive, unless the intrinsics are simply NOT good at the ROL's, which is highly likely. I do not think MDx has ROL's, only sha1.

<!-- gh-comment-id:45451319 --> @jfoug commented on GitHub (Jun 8, 2014): Or is the actual algorithm used the same between the 2? Could we be doing a 'full' sha1, but a shortcut within the old mmx code ?? Yes, this one has not made me overly happy either. Seems very counter intuitive, unless the intrinsics are simply NOT good at the ROL's, which is highly likely. I do not think MDx has ROL's, only sha1.
Author
Owner

@magnumripper commented on GitHub (Jun 18, 2014):

But if the assembler is using vector rotates, there ought to be intrinsics for the very same instructions. And I can't see how any significant shortcuts could be used as both versions can do iterated formats and full-length blocks.

Here's a (poor) way to try to compare apples to apples. It's probably better to look at the .S file with intact macros and compare it to the intrinsics.

$ ln -fs x86-sse.h arch.h
$ gcc -m32 -msse2 -O2 -DSHA1_SSE_PARA=1 -S -fverbose-asm sha1-intrinsics.c -o sse32i.s
$ ln -fs x86-sse.h unused/arch.h
$ gcc -E -P unused/sha1-mmx.S -o sha1-mmx.s
$ meld sse32i.s sha1-mmx.s

(edit: I did the above after chopping all non-SHA1 code from the intrinsics)

<!-- gh-comment-id:46498445 --> @magnumripper commented on GitHub (Jun 18, 2014): But if the assembler is using vector rotates, there ought to be intrinsics for the very same instructions. And I can't see how any significant shortcuts could be used as both versions can do iterated formats and full-length blocks. Here's a (poor) way to try to compare apples to apples. It's probably better to look at the .S file with intact macros and compare it to the intrinsics. ``` $ ln -fs x86-sse.h arch.h $ gcc -m32 -msse2 -O2 -DSHA1_SSE_PARA=1 -S -fverbose-asm sha1-intrinsics.c -o sse32i.s $ ln -fs x86-sse.h unused/arch.h $ gcc -E -P unused/sha1-mmx.S -o sha1-mmx.s $ meld sse32i.s sha1-mmx.s ``` (edit: I did the above after chopping all non-SHA1 code from the intrinsics)
Author
Owner

@magnumripper commented on GitHub (Jun 18, 2014):

I see an awful lot of movl... they are not SIMD are they?

<!-- gh-comment-id:46499296 --> @magnumripper commented on GitHub (Jun 18, 2014): I see an awful lot of `movl`... they are not SIMD are they?
Author
Owner

@jfoug commented on GitHub (Jun 18, 2014):

movl is CPU

<!-- gh-comment-id:46500056 --> @jfoug commented on GitHub (Jun 18, 2014): movl is CPU
Author
Owner

@magnumripper commented on GitHub (Jun 18, 2014):

-fverbose-asm made it a whole lot easier to follow

<!-- gh-comment-id:46500747 --> @magnumripper commented on GitHub (Jun 18, 2014): -fverbose-asm made it a whole lot easier to follow
Author
Owner

@magnumripper commented on GitHub (Jun 18, 2014):

It might be that those movl's are from conversion to flat buffer. I'll edit it out and see how it looks

<!-- gh-comment-id:46501262 --> @magnumripper commented on GitHub (Jun 18, 2014): It might be that those movl's are from conversion to flat buffer. I'll edit it out and see how it looks
Author
Owner

@magnumripper commented on GitHub (Jun 18, 2014):

Yeah that was it.

<!-- gh-comment-id:46501566 --> @magnumripper commented on GitHub (Jun 18, 2014): Yeah that was it.
Author
Owner

@magnumripper commented on GitHub (Jun 18, 2014):

Note to self: http://arctic.org/~dean/crypto/sha1.html

<!-- gh-comment-id:46508448 --> @magnumripper commented on GitHub (Jun 18, 2014): Note to self: http://arctic.org/~dean/crypto/sha1.html
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#290
No description provided.