Skip to content

Commit

Permalink
Use clang pragmas to enable features rather than depend on compiler s…
Browse files Browse the repository at this point in the history
…ettings
  • Loading branch information
jedisct1 committed Apr 27, 2024
1 parent 3de5e50 commit bf972ef
Show file tree
Hide file tree
Showing 16 changed files with 448 additions and 256 deletions.
523 changes: 324 additions & 199 deletions build.zig

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#if defined(HAVE_TMMINTRIN_H) && defined(HAVE_WMMINTRIN_H)

#ifdef __GNUC__
#pragma GCC target("avx,aes,pclmul")
#endif
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("aes,avx,pclmul"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("aes,avx,pclmul")
# endif

#if !defined(_MSC_VER) || _MSC_VER < 1800
#define __vectorcall
Expand Down Expand Up @@ -1006,4 +1008,8 @@ crypto_aead_aes256gcm_is_available(void)
return sodium_runtime_has_pclmul() & sodium_runtime_has_aesni() & sodium_runtime_has_avx();
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# pragma GCC target("sse4.1")
# pragma GCC target("avx2")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1,avx2")
# endif

# include <emmintrin.h>
Expand Down Expand Up @@ -46,4 +45,8 @@ blake2b_compress_avx2(blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES])
return 0;
}

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && \
defined(HAVE_SMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# pragma GCC target("sse4.1")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1")
# endif

# include <emmintrin.h>
Expand Down Expand Up @@ -84,4 +84,8 @@ blake2b_compress_sse41(blake2b_state *S,
return 0;
}

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3")
# endif

# include <emmintrin.h>
Expand Down Expand Up @@ -87,4 +88,8 @@ blake2b_compress_ssse3(blake2b_state *S,
return 0;
}

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#if defined(HAVE_TI_MODE) && defined(HAVE_EMMINTRIN_H)

# ifdef __GNUC__
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2")
# endif

Expand Down Expand Up @@ -946,4 +948,8 @@ struct crypto_onetimeauth_poly1305_implementation
SODIUM_C99(.onetimeauth_final =) crypto_onetimeauth_poly1305_sse2_final
};

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
14 changes: 9 additions & 5 deletions src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# pragma GCC target("sse4.1")
# pragma GCC target("avx2")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1,avx2")
# endif

# ifdef _MSC_VER
Expand Down Expand Up @@ -236,4 +235,9 @@ argon2_fill_segment_avx2(const argon2_instance_t *instance,
}
}
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
15 changes: 9 additions & 6 deletions src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx512f.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
#if defined(HAVE_AVX512FINTRIN_H) && defined(HAVE_AVX2INTRIN_H) && \
defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# pragma GCC target("sse4.1")
# pragma GCC target("avx2")
# pragma GCC target("avx512f")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2,avx512f"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1,avx2,avx512f")
# endif

# ifdef _MSC_VER
Expand Down Expand Up @@ -241,4 +239,9 @@ argon2_fill_segment_avx512f(const argon2_instance_t *instance,
}
}
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
12 changes: 9 additions & 3 deletions src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3")
# endif

# ifdef _MSC_VER
Expand Down Expand Up @@ -235,4 +236,9 @@ argon2_fill_segment_ssse3(const argon2_instance_t *instance,
}
}
}

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@

#ifdef HAVE_EMMINTRIN_H

# ifdef __GNUC__
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2")
# endif

# include <emmintrin.h>
# if defined(__XOP__) && defined(DISABLED)
# include <x86intrin.h>
# endif

# include "private/sse2_64_32.h"

# include "../crypto_scrypt.h"
Expand Down Expand Up @@ -397,4 +398,9 @@ escrypt_kdf_sse(escrypt_local_t *local, const uint8_t *passwd, size_t passwdlen,
/* Success! */
return 0;
}

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# pragma GCC target("sse4.1")
# pragma GCC target("avx2")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1,avx2")
# endif

# include <emmintrin.h>
Expand Down Expand Up @@ -174,4 +173,8 @@ struct crypto_stream_chacha20_implementation
SODIUM_C99(.stream_ietf_ext_xor_ic =) stream_ietf_ext_ref_xor_ic
};

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

#if defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3")
# endif

# include <emmintrin.h>
Expand Down Expand Up @@ -168,4 +169,8 @@ struct crypto_stream_chacha20_implementation
SODIUM_C99(.stream_ietf_ext_xor_ic =) stream_ietf_ext_ref_xor_ic
};

# ifdef __clang__
# pragma clang attribute pop
# endif

#endif
23 changes: 13 additions & 10 deletions src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
#if defined(HAVE_AVX2INTRIN_H) && defined(HAVE_EMMINTRIN_H) && \
defined(HAVE_TMMINTRIN_H) && defined(HAVE_SMMINTRIN_H)

# ifdef __GNUC__
# pragma GCC target("sse2")
# pragma GCC target("ssse3")
# pragma GCC target("sse4.1")
# pragma GCC target("avx2")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2,ssse3,sse4.1,avx2"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2,ssse3,sse4.1,avx2")
# endif

#include <emmintrin.h>
#include <immintrin.h>
#include <smmintrin.h>
#include <tmmintrin.h>
#include "private/sse2_64_32.h"
# include <emmintrin.h>
# include <immintrin.h>
# include <smmintrin.h>
# include <tmmintrin.h>
# include "private/sse2_64_32.h"

# include "../stream_salsa20.h"
# include "salsa20_xmm6int-avx2.h"
Expand Down Expand Up @@ -128,4 +127,8 @@ struct crypto_stream_salsa20_implementation
SODIUM_C99(.stream_xor_ic =) stream_avx2_xor_ic
};

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

#ifdef HAVE_EMMINTRIN_H

# ifdef __GNUC__
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("sse2"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("sse2")
# endif
# include <emmintrin.h>
Expand Down Expand Up @@ -119,4 +121,8 @@ struct crypto_stream_salsa20_implementation
SODIUM_C99(.stream_xor_ic =) stream_sse2_xor_ic
};

#ifdef __clang__
# pragma clang attribute pop
#endif

#endif
3 changes: 0 additions & 3 deletions src/libsodium/crypto_verify/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ crypto_verify_64_bytes(void)

#if defined(HAVE_EMMINTRIN_H) && defined(__SSE2__)

# ifdef __GNUC__
# pragma GCC target("sse2")
# endif
# include <emmintrin.h>

static inline int
Expand Down
12 changes: 11 additions & 1 deletion src/libsodium/randombytes/internal/randombytes_internal_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
# include <poll.h>
#endif
#ifdef HAVE_RDRAND
# pragma GCC target("rdrnd")
# ifdef __clang__
# pragma clang attribute push(__attribute__((target("rdrnd"))), apply_to = function)
# elif defined(__GNUC__)
# pragma GCC target("rdrnd")
# endif
# include <immintrin.h>
#endif

Expand Down Expand Up @@ -633,3 +637,9 @@ struct randombytes_implementation randombytes_internal_implementation = {
SODIUM_C99(.buf =) randombytes_internal_random_buf,
SODIUM_C99(.close =) randombytes_internal_random_close
};

#ifdef HAVE_RDRAND
# ifdef __clang__
# pragma clang attribute pop
# endif
#endif

0 comments on commit bf972ef

Please sign in to comment.