Skip to content

Commit c88c73c

Browse files
authored
Merge pull request #9 from mfrischknecht/fix-rust-cross-mingw-compilation
Add/expand compile guards for VAES (fixing MinGW cross compilation)
2 parents a71b0ba + 3ce51b1 commit c88c73c

File tree

12 files changed

+88
-60
lines changed

12 files changed

+88
-60
lines changed

src/aegis128x2/aegis128x2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,12 @@ aegis128x2_pick_best_implementation(void)
187187
#endif
188188

189189
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86)
190+
# ifdef HAVE_VAESINTRIN_H
190191
if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) {
191192
implementation = &aegis128x2_avx2_implementation;
192193
return 0;
193194
}
195+
# endif
194196
if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) {
195197
implementation = &aegis128x2_aesni_implementation;
196198
return 0;

src/aegis128x2/aegis128x2_avx2.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@
1010
# include "aegis128x2.h"
1111
# include "aegis128x2_avx2.h"
1212

13-
# ifdef __clang__
14-
# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function)
15-
# elif defined(__GNUC__)
16-
# pragma GCC target("vaes,avx2")
17-
# endif
13+
# ifdef HAVE_VAESINTRIN_H
14+
15+
# ifdef __clang__
16+
# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function)
17+
# elif defined(__GNUC__)
18+
# pragma GCC target("vaes,avx2")
19+
# endif
1820

19-
# include <immintrin.h>
21+
# include <immintrin.h>
2022

21-
# define AES_BLOCK_LENGTH 32
23+
# define AES_BLOCK_LENGTH 32
2224

2325
typedef __m256i aes_block_t;
2426

25-
# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B))
26-
# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B))
27-
# define AES_BLOCK_LOAD128_BROADCAST(A) \
28-
_mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A)))
29-
# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A))
30-
# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B)))
31-
# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B))
32-
# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B))
27+
# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B))
28+
# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B))
29+
# define AES_BLOCK_LOAD128_BROADCAST(A) \
30+
_mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A)))
31+
# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A))
32+
# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B)))
33+
# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B))
34+
# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B))
3335

3436
static inline void
3537
aegis128x2_update(aes_block_t *const state, const aes_block_t d1, const aes_block_t d2)
@@ -50,7 +52,7 @@ aegis128x2_update(aes_block_t *const state, const aes_block_t d1, const aes_bloc
5052
state[4] = AES_BLOCK_XOR(state[4], d2);
5153
}
5254

53-
# include "aegis128x2_common.h"
55+
# include "aegis128x2_common.h"
5456

5557
struct aegis128x2_implementation aegis128x2_avx2_implementation = {
5658
.encrypt_detached = encrypt_detached,
@@ -66,8 +68,10 @@ struct aegis128x2_implementation aegis128x2_avx2_implementation = {
6668
.state_decrypt_detached_final = state_decrypt_detached_final,
6769
};
6870

69-
# ifdef __clang__
70-
# pragma clang attribute pop
71+
# ifdef __clang__
72+
# pragma clang attribute pop
73+
# endif
74+
7175
# endif
7276

7377
#endif

src/aegis128x2/aegis128x2_avx2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "../common/common.h"
55
#include "implementations.h"
66

7+
#ifdef HAVE_VAESINTRIN_H
78
extern struct aegis128x2_implementation aegis128x2_avx2_implementation;
9+
#endif
810

911
#endif

src/aegis128x4/aegis128x4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ aegis128x4_pick_best_implementation(void)
193193
implementation = &aegis128x4_avx512_implementation;
194194
return 0;
195195
}
196-
# endif
197196
if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) {
198197
implementation = &aegis128x4_avx2_implementation;
199198
return 0;
200199
}
200+
# endif
201201
if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) {
202202
implementation = &aegis128x4_aesni_implementation;
203203
return 0;

src/aegis128x4/aegis128x4_avx2.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
# include "aegis128x4.h"
1111
# include "aegis128x4_avx2.h"
1212

13-
# ifdef __clang__
14-
# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function)
15-
# elif defined(__GNUC__)
16-
# pragma GCC target("vaes,avx2")
17-
# endif
13+
# ifdef HAVE_VAESINTRIN_H
14+
15+
# ifdef __clang__
16+
# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function)
17+
# elif defined(__GNUC__)
18+
# pragma GCC target("vaes,avx2")
19+
# endif
1820

19-
# include <immintrin.h>
21+
# include <immintrin.h>
2022

21-
# define AES_BLOCK_LENGTH 64
23+
# define AES_BLOCK_LENGTH 64
2224

2325
typedef struct {
2426
__m256i b0;
@@ -83,7 +85,7 @@ aegis128x4_update(aes_block_t *const state, const aes_block_t d1, const aes_bloc
8385
state[4] = AES_BLOCK_XOR(state[4], d2);
8486
}
8587

86-
# include "aegis128x4_common.h"
88+
# include "aegis128x4_common.h"
8789

8890
struct aegis128x4_implementation aegis128x4_avx2_implementation = {
8991
.encrypt_detached = encrypt_detached,
@@ -99,8 +101,10 @@ struct aegis128x4_implementation aegis128x4_avx2_implementation = {
99101
.state_decrypt_detached_final = state_decrypt_detached_final,
100102
};
101103

102-
# ifdef __clang__
103-
# pragma clang attribute pop
104+
# ifdef __clang__
105+
# pragma clang attribute pop
106+
# endif
107+
104108
# endif
105109

106-
#endif
110+
#endif

src/aegis128x4/aegis128x4_avx2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "../common/common.h"
55
#include "implementations.h"
66

7+
#ifdef HAVE_VAESINTRIN_H
78
extern struct aegis128x4_implementation aegis128x4_avx2_implementation;
9+
#endif
810

911
#endif

src/aegis256x2/aegis256x2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,12 @@ aegis256x2_pick_best_implementation(void)
187187
#endif
188188

189189
#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86)
190+
# ifdef HAVE_VAESINTRIN_H
190191
if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) {
191192
implementation = &aegis256x2_avx2_implementation;
192193
return 0;
193194
}
195+
# endif
194196
if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) {
195197
implementation = &aegis256x2_aesni_implementation;
196198
return 0;

src/aegis256x2/aegis256x2_avx2.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@
1010
# include "aegis256x2.h"
1111
# include "aegis256x2_avx2.h"
1212

13-
# ifdef __clang__
14-
# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function)
15-
# elif defined(__GNUC__)
16-
# pragma GCC target("vaes,avx2")
17-
# endif
13+
# ifdef HAVE_VAESINTRIN_H
14+
15+
# ifdef __clang__
16+
# pragma clang attribute push(__attribute__((target("vaes,avx2"))), apply_to = function)
17+
# elif defined(__GNUC__)
18+
# pragma GCC target("vaes,avx2")
19+
# endif
1820

19-
# include <immintrin.h>
21+
# include <immintrin.h>
2022

21-
# define AES_BLOCK_LENGTH 32
23+
# define AES_BLOCK_LENGTH 32
2224

2325
typedef __m256i aes_block_t;
2426

25-
# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B))
26-
# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B))
27-
# define AES_BLOCK_LOAD128_BROADCAST(A) \
28-
_mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A)))
29-
# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A))
30-
# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B)))
31-
# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B))
32-
# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B))
27+
# define AES_BLOCK_XOR(A, B) _mm256_xor_si256((A), (B))
28+
# define AES_BLOCK_AND(A, B) _mm256_and_si256((A), (B))
29+
# define AES_BLOCK_LOAD128_BROADCAST(A) \
30+
_mm256_broadcastsi128_si256(_mm_loadu_si128((const void *) (A)))
31+
# define AES_BLOCK_LOAD(A) _mm256_loadu_si256((const aes_block_t *) (const void *) (A))
32+
# define AES_BLOCK_LOAD_64x2(A, B) _mm256_broadcastsi128_si256(_mm_set_epi64x((A), (B)))
33+
# define AES_BLOCK_STORE(A, B) _mm256_storeu_si256((aes_block_t *) (void *) (A), (B))
34+
# define AES_ENC(A, B) _mm256_aesenc_epi128((A), (B))
3335

3436
static inline void
3537
aegis256x2_update(aes_block_t *const state, const aes_block_t d)
@@ -45,7 +47,7 @@ aegis256x2_update(aes_block_t *const state, const aes_block_t d)
4547
state[0] = AES_BLOCK_XOR(AES_ENC(tmp, state[0]), d);
4648
}
4749

48-
# include "aegis256x2_common.h"
50+
# include "aegis256x2_common.h"
4951

5052
struct aegis256x2_implementation aegis256x2_avx2_implementation = {
5153
.encrypt_detached = encrypt_detached,
@@ -61,8 +63,10 @@ struct aegis256x2_implementation aegis256x2_avx2_implementation = {
6163
.state_decrypt_detached_final = state_decrypt_detached_final,
6264
};
6365

64-
# ifdef __clang__
65-
# pragma clang attribute pop
66+
# ifdef __clang__
67+
# pragma clang attribute pop
68+
# endif
69+
6670
# endif
6771

68-
#endif
72+
#endif

src/aegis256x2/aegis256x2_avx2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "../common/common.h"
55
#include "implementations.h"
66

7+
#ifdef HAVE_VAESINTRIN_H
78
extern struct aegis256x2_implementation aegis256x2_avx2_implementation;
9+
#endif
810

911
#endif

src/aegis256x4/aegis256x4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ aegis256x4_pick_best_implementation(void)
193193
implementation = &aegis256x4_avx512_implementation;
194194
return 0;
195195
}
196-
# endif
197196
if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) {
198197
implementation = &aegis256x4_avx2_implementation;
199198
return 0;
200199
}
200+
# endif
201201
if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) {
202202
implementation = &aegis256x4_aesni_implementation;
203203
return 0;

0 commit comments

Comments
 (0)