]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
bn_lib.c: Special-case the BN_num_bits_word function for the Elbrus2000 arch
authorAlexander Troosh <trush@yandex.ru>
Mon, 1 Sep 2025 18:27:59 +0000 (21:27 +0300)
committerAndrew Dinh <andrewd@openssl.org>
Fri, 31 Jul 2026 16:48:53 +0000 (23:48 +0700)
Co-authored-by: Gleb Popov <arrowd@FreeBSD.org>

Reviewed-by: Andrew Dinh <andrewd@openssl.org>
Reviewed-by: Igor Ustinov <igus@openssl.foundation>
MergeDate: Fri Jul 31 16:49:41 2026
(Merged from https://github.com/openssl/openssl/pull/31269)

crypto/bn/bn_lib.c

index 226c0c615ca63537411dbbfd34664fbc641dd769..ee4a45b7e05049c5d3bc354f0f4d9493ecfb1846 100644 (file)
@@ -89,6 +89,7 @@ const BIGNUM *BN_value_one(void)
     return &const_one;
 }
 
+#ifndef __e2k__
 int BN_num_bits_word(BN_ULONG l)
 {
     BN_ULONG x, mask;
@@ -133,6 +134,20 @@ int BN_num_bits_word(BN_ULONG l)
 
     return bits;
 }
+#else /* __e2k__ */
+#include <x86gprintrin.h>
+int BN_num_bits_word(BN_ULONG l)
+{
+    /* clz(0) is well-defined on e2k, hence no if (l == 0) return 0;
+     * is required here.
+     */
+#if BN_BITS2 > 32
+    return 64 - __builtin_clzll(l);
+#else
+    return 32 - __builtin_clz(l);
+#endif
+}
+#endif /* __e2k__ */
 
 /*
  * This function still leaks `a->dmax`: it's caller's responsibility to