Skip to content

Commit

Permalink
Merge pull request #3863 from randombit/jack/cleanup-macros
Browse files Browse the repository at this point in the history
Small cleanups for compiler.h
  • Loading branch information
randombit authored Feb 16, 2024
2 parents a570dfd + 42e7591 commit d0b2107
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/lib/block/serpent/serpent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void Serpent::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const

const Key_Inserter key_xor(m_round_key.data());

BOTAN_PARALLEL_SIMD_FOR(size_t i = 0; i < blocks; ++i) {
for(size_t i = 0; i < blocks; ++i) {
uint32_t B0, B1, B2, B3;
load_le(in + 16 * i, B0, B1, B2, B3);

Expand Down Expand Up @@ -208,7 +208,7 @@ void Serpent::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const

const Key_Inserter key_xor(m_round_key.data());

BOTAN_PARALLEL_SIMD_FOR(size_t i = 0; i < blocks; ++i) {
for(size_t i = 0; i < blocks; ++i) {
uint32_t B0, B1, B2, B3;
load_le(in + 16 * i, B0, B1, B2, B3);

Expand Down
4 changes: 2 additions & 2 deletions src/lib/block/threefish_512/threefish_512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void Threefish_512::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks)

const Key_Inserter key(m_K.data(), m_T.data());

BOTAN_PARALLEL_SIMD_FOR(size_t i = 0; i < blocks; ++i) {
for(size_t i = 0; i < blocks; ++i) {
uint64_t X0, X1, X2, X3, X4, X5, X6, X7;
load_le(in + BLOCK_SIZE * i, X0, X1, X2, X3, X4, X5, X6, X7);

Expand All @@ -223,7 +223,7 @@ void Threefish_512::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks)

const Key_Inserter key(m_K.data(), m_T.data());

BOTAN_PARALLEL_SIMD_FOR(size_t i = 0; i < blocks; ++i) {
for(size_t i = 0; i < blocks; ++i) {
uint64_t X0, X1, X2, X3, X4, X5, X6, X7;
load_le(in + BLOCK_SIZE * i, X0, X1, X2, X3, X4, X5, X6, X7);

Expand Down
40 changes: 19 additions & 21 deletions src/lib/utils/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

#include <botan/build.h>

/*
NOTE: Avoid using BOTAN_COMPILER_IS_XXX macros anywhere in this file
This macro is set based on what compiler was used to build the
library, but it is possible that the library is built with one
compiler and then the application is built using another.
For example using BOTAN_COMPILER_IS_CLANG would trigger (incorrectly)
when the application is later compiled using GCC.
*/

/**
* Used to annotate API exports which are public and supported.
* These APIs will not be broken/removed unless strictly required for
Expand Down Expand Up @@ -156,32 +167,19 @@

#endif

/*
* Define BOTAN_PARALLEL_SIMD_FOR
*/
#if !defined(BOTAN_PARALLEL_SIMD_FOR)

#if defined(BOTAN_BUILD_COMPILER_IS_GCC)
#define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
#else
#define BOTAN_PARALLEL_SIMD_FOR for
#endif

#endif

#if defined(BOTAN_BUILD_COMPILER_IS_GCC)
#define BOTAN_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
#define BOTAN_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#elif defined(BOTAN_BUILD_COMPILER_IS_CLANG)
#if defined(__clang__)
#define BOTAN_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
#define BOTAN_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC)
#elif defined(__GNUG__)
#define BOTAN_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
#define BOTAN_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#elif defined(_MSC_VER)
#define BOTAN_DIAGNOSTIC_PUSH __pragma(warning(push))
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS __pragma(warning(disable : 4996))
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE __pragma(warning(disable : 4250))
Expand Down

0 comments on commit d0b2107

Please sign in to comment.