Uh oh!
There was an error while loading. Please reload this page.
Support SHA256_Transform_shani() with MSVC - #15312
Conversation
TimWolla
commented
Aug 9, 2024
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". |
Uh oh!
There was an error while loading. Please reload this page.
cmb69
commented
Aug 9, 2024
Indeed, but this only works if
would make sense, since that would support environments where So maybe we should start getting rid of the |
TimWolla
commented
Aug 9, 2024
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. |
cmb69
commented
Aug 9, 2024
Ah, indeed, I still didn't really understand that, and mixed up |
TimWolla
commented
Aug 9, 2024
The preprocessor check in hash_sha_ni.c can probably be replaced by: Then in php_hash_sha.h you would define |
cmb69
commented
Aug 9, 2024
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
andypost
commented
Aug 13, 2024
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. ClosesphpGH-15384. Related to phpGH-15312.
Uh oh!
There was an error while loading. Please reload this page.
cmb69
commented
Sep 3, 2024
Rebased, and removed the erroneous |
cmb69
commented
Sep 3, 2024
Generally, zend_portability defines 4 relevant macros for each intrinsic family:
In this case we have only |
arnaud-lb
left a comment
There was a problem hiding this comment.
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!
TimWolla
left a comment
There was a problem hiding this comment.
LGTM, except for the unresolved thread in hash_sha_ni.c.
Uh oh!
There was an error while loading. Please reload this page.
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-intrinsicsmight 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_PTRstyle which is likely supported everywhere.@TimWolla might want to have a look at this, although for now it's just a draft.