diff options
-rw-r--r-- | board/cr50/dcrypto/app_cipher.c | 4 | ||||
-rw-r--r-- | board/cr50/dcrypto/compare.c | 2 | ||||
-rw-r--r-- | board/cr50/dcrypto/internal.h | 13 |
3 files changed, 16 insertions, 3 deletions
diff --git a/board/cr50/dcrypto/app_cipher.c b/board/cr50/dcrypto/app_cipher.c index 811d6feda1..9b7961f209 100644 --- a/board/cr50/dcrypto/app_cipher.c +++ b/board/cr50/dcrypto/app_cipher.c @@ -11,8 +11,8 @@ * compiler to optimize for speed here. Incidentally -O produces * faster code than -O2! */ -static int __attribute__((optimize("O"))) -inner_loop(uint32_t **out, const uint32_t **in, size_t len) +static int __optimize("O") inner_loop(uint32_t **out, const uint32_t **in, + size_t len) { uint32_t *outw = *out; const uint32_t *inw = *in; diff --git a/board/cr50/dcrypto/compare.c b/board/cr50/dcrypto/compare.c index 09bbd36fd1..494e26617e 100644 --- a/board/cr50/dcrypto/compare.c +++ b/board/cr50/dcrypto/compare.c @@ -12,7 +12,7 @@ #define CRYPTO_FAST_COMPARE 0 /* Constant time, hardened comparator. */ -enum dcrypto_result __attribute__((optimize("-O1"))) DCRYPTO_equals( +enum dcrypto_result __optimize("O1") DCRYPTO_equals( const void *a, const void *b, size_t len) { uintptr_t a_addr = (uintptr_t)a; diff --git a/board/cr50/dcrypto/internal.h b/board/cr50/dcrypto/internal.h index fd4fa62f43..6df2df3ef9 100644 --- a/board/cr50/dcrypto/internal.h +++ b/board/cr50/dcrypto/internal.h @@ -265,6 +265,19 @@ void *always_memset(void *s, int c, size_t n); #define __alias(func) __attribute__((alias(#func))) #endif +/** + * Macro to control optimization at function level. Typically used in + * very tight and critical loops to override -Os and get a better code. + * Only supported by gcc, so ignore it for clang. + */ +#ifndef __optimize +#ifndef __clang__ +#define __optimize(a) __attribute__((optimize(a))) +#else +#define __optimize(a) +#endif +#endif + /* rotate 32-bit value right */ static inline uint32_t ror(uint32_t value, int bits) { |