Skip to content

Commit c351b78

Browse files
Raimo33Claudio Raimondi
authored andcommitted
Fix endian detection macro
1 parent 22e9772 commit c351b78

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"immintrin.h": "c",
66
"x86gprintrin.h": "c",
77
"xmmintrin.h": "c",
8-
"mmintrin.h": "c"
8+
"mmintrin.h": "c",
9+
"random": "c"
910
}
1011
}

src/hash_impl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
} while(0)
3030

3131
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash) {
32+
#ifdef __AVX2__
33+
const __m256i vec = _mm256_setr_epi32(
34+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
35+
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
36+
);
37+
_mm256_storeu_si256((__m256i*)hash->s, vec);
38+
#else
3239
hash->s[0] = 0x6a09e667ul;
3340
hash->s[1] = 0xbb67ae85ul;
3441
hash->s[2] = 0x3c6ef372ul;
@@ -37,6 +44,7 @@ static void secp256k1_sha256_initialize(secp256k1_sha256 *hash) {
3744
hash->s[5] = 0x9b05688cul;
3845
hash->s[6] = 0x1f83d9abul;
3946
hash->s[7] = 0x5be0cd19ul;
47+
#endif
4048
hash->bytes = 0;
4149
}
4250

src/util.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@
3737
#endif
3838

3939
/* endianess detection macro */
40-
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
41-
#define LITTLE_ENDIAN
42-
#elif defined(_WIN32)
43-
#define LITTLE_ENDIAN
40+
#ifndef LITTLE_ENDIAN
41+
#define LITTLE_ENDIAN (*(char*)&(int){1})
4442
#endif
4543

4644
#define STR_(x) #x

0 commit comments

Comments
 (0)