Commit 2e9fc11fed for openssl.org

commit 2e9fc11fed771f3423287ab033130c4b621f5f75
Author: Alexander Troosh <trush@yandex.ru>
Date:   Mon Sep 1 21:27:59 2025 +0300

    bn_lib.c: Special-case the BN_num_bits_word function for the Elbrus2000 arch

    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)

diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c
index 226c0c615c..ee4a45b7e0 100644
--- a/crypto/bn/bn_lib.c
+++ b/crypto/bn/bn_lib.c
@@ -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