From 99c64e142eadb8823190f84a6547da8e9c3504ae Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Tue, 6 Oct 2020 12:25:28 +0300 Subject: [PATCH] Use builtin CLZ Signed-off-by: Kevin Bracey --- tinycrypt/ecc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinycrypt/ecc.c b/tinycrypt/ecc.c index ee9195718..3407aaf96 100644 --- a/tinycrypt/ecc.c +++ b/tinycrypt/ecc.c @@ -424,9 +424,13 @@ bitcount_t uECC_vli_numBits(const uECC_word_t *vli) } digit = vli[num_digits - 1]; +#if defined __GNUC__ || defined __clang__ || defined __CC_ARM + i = uECC_WORD_BITS - __builtin_clz(digit); +#else for (i = 0; digit; ++i) { digit >>= 1; } +#endif return (((bitcount_t)(num_digits - 1) << uECC_WORD_BITS_SHIFT) + i); }