-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support SHA256_Transform_shani() with MSVC #15312
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
Conversation
As the CI failure explains: The declaration with the target attribute is necessary for the build to work / for making the intrinsics actually legal to use within the function. Passing the flags to the compiler directly is the "native support". |
Indeed, but this only works if
would make sense, since that would support environments where So maybe we should start getting rid of the |
I don't follow here. The attribute is necessary to make the intrinsics available even if The CPU check at runtime is orthogonal to that.
I expect the branch to be easily predicted by a CPU, given that is will either always be taken or never be taken. In any case, a single SHA-256 transform still is fairly expensive and I expect it will easily dwarf the type to check the CPU features, as indicated by the 5x improvement that is already achieved with the current very simple implementation. |
Ah, indeed, I still didn't really understand that, and mixed up |
The preprocessor check in hash_sha_ni.c can probably be replaced by:
Then in php_hash_sha.h you would define |
it solved issue with build on Alpine, thank you! |
…on of SHA256_Transform_shani This fixes the build for amd64 platforms that do not have `HAVE_FUNC_ATTRIBUTE_TARGET`, specifically Alpine/Musl as of now. Closes phpGH-15384. Related to phpGH-15312.
f32be3b
to
0ecec94
Compare
Rebased, and removed the erroneous |
Generally, zend_portability defines 4 relevant macros for each intrinsic family:
In this case we have only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried in a VM: it uses SHA256_Transform_shani() as expected when the CPU has SSSE3/SHA features (with runtime detection), and the default implementation otherwise.
I get that MSVC can use the sha intrinsics without __attribute__((target))
.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except for the unresolved thread in hash_sha_ni.c
.
This requires #15292 to be fixed; I've used the same macro guards as proposed by #15301.
I've only did most minimal cleanup; given that the implementation apparently does not rely on
HAVE_FUNC_ATTRIBUTE_TARGET
, I've removed the forward declaration and changed the guard.As is, this does not support compile time
__SHA__
detection, because that macro is apparently never defined on Windows. We would need to work around that in confutils.js like with other non standard MSVC macros:php-src/win32/build/confutils.js
Lines 3341 to 3346 in bd77462
However, I wouldn't know where to insert
__SHA__
; likely this is "non-linear", and as such the whole--enable-native-intrinsics
might need to be changed, or an extra configure option be introduced. Probably low priority, since official builds only use SSE(2) anyway.Note also that the current implementation appears to be suboptimal since there is
neither proper support for, nor forHAVE_FUNC_ATTRIBUTE_TARGET
(which is not available with MSVC anyway)ZEND_INTRIN_*_FUNC_PTR
style which is likely supported everywhere.@TimWolla might want to have a look at this, although for now it's just a draft.