Skip to content

Commit 628f7ca

Browse files
committed
Ugly, but hopefully working
1 parent a497c1e commit 628f7ca

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

ext/hash/hash_sha.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static void SHA256Transform(uint32_t state[8], const unsigned char block[64])
164164
#if defined(PHP_HASH_INTRIN_SHA_NATIVE)
165165
SHA256_Transform_shani(state, block);
166166
return;
167-
#elif defined(PHP_HASH_INTRIN_SHA_RESOLVER)
167+
#elif defined(PHP_HASH_INTRIN_SHA_RESOLVER) || (defined(_M_X64) || defined(_M_IX86)) && ZEND_INTRIN_SSSE3_RESOLVER
168168
if (zend_cpu_supports(ZEND_CPU_FEATURE_SSSE3) && zend_cpu_supports(ZEND_CPU_FEATURE_SHA)) {
169169
SHA256_Transform_shani(state, block);
170170
return;

ext/hash/hash_sha_ni.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@
2727
#include "php_hash.h"
2828
#include "php_hash_sha.h"
2929

30-
#if (defined(__i386__) || defined(__x86_64__)) && defined(HAVE_IMMINTRIN_H) || defined(_M_X64) || defined(_M_IX86)
30+
#if (defined(__i386__) || defined(__x86_64__)) && defined(HAVE_IMMINTRIN_H) || (defined(_M_X64) || defined(_M_IX86)) && ZEND_INTRIN_SSSE3_RESOLVER
3131

3232
# include <immintrin.h>
3333

34+
# if PHP_HASH_INTRIN_SHA_RESOLVER
35+
static __m128i be32dec_128(const uint8_t * src) __attribute__((target("ssse3")));
36+
void SHA256_Transform_shani(uint32_t state[PHP_STATIC_RESTRICT 8], const uint8_t block[PHP_STATIC_RESTRICT 64]) __attribute__((target("ssse3,sha")));
37+
# endif
38+
3439
/* Original implementation from libcperciva follows.
3540
*
3641
* Modified to use `PHP_STATIC_RESTRICT` for MSVC compatibility.

ext/hash/php_hash_sha.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ PHP_HASH_API void PHP_SHA256Update(PHP_SHA256_CTX *, const unsigned char *, size
5656
void SHA256_Transform_sse2(uint32_t state[PHP_STATIC_RESTRICT 8], const uint8_t block[PHP_STATIC_RESTRICT 64], uint32_t W[PHP_STATIC_RESTRICT 64], uint32_t S[PHP_STATIC_RESTRICT 8]);
5757
#endif
5858

59-
#if (defined(__i386__) || defined(__x86_64__)) && defined(HAVE_IMMINTRIN_H) || defined(_M_X64) || defined(_M_IX86)
59+
#if (defined(__i386__) || defined(__x86_64__)) && defined(HAVE_IMMINTRIN_H)
6060
# if defined(__SSSE3__) && defined(__SHA__)
6161
# define PHP_HASH_INTRIN_SHA_NATIVE 1
62-
# elif defined(ZEND_INTRIN_SSSE3_RESOLVER)
62+
# elif defined(HAVE_FUNC_ATTRIBUTE_TARGET)
6363
# define PHP_HASH_INTRIN_SHA_RESOLVER 1
6464
# endif
6565

0 commit comments

Comments
 (0)