On some architectures, we can provide an optimised (often single
instruction) count-leading-zero implementation. In order to do this
effectively, provide bn_clzw() as a static inline that can be replaced
by an architecture specific version. The default implementation defers
to the bn_word_clz() function (which may also be architecture specific).
ok tb@
-/* $OpenBSD: bn_internal.h,v 1.13 2023/06/21 07:41:55 jsing Exp $ */
+/* $OpenBSD: bn_internal.h,v 1.14 2023/06/21 07:48:41 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
}
#endif
+#ifndef HAVE_BN_CLZW
+static inline int
+bn_clzw(BN_ULONG w)
+{
+ return bn_word_clz(w);
+}
+#endif
+
/*
* Big number primitives are named as the operation followed by a suffix
* that indicates the number of words that it operates on, where 'w' means
-/* $OpenBSD: bn_lib.c,v 1.87 2023/06/21 07:41:55 jsing Exp $ */
+/* $OpenBSD: bn_lib.c,v 1.88 2023/06/21 07:48:41 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
int
BN_num_bits_word(BN_ULONG w)
{
- return BN_BITS2 - bn_word_clz(w);
+ return BN_BITS2 - bn_clzw(w);
}
int
-/* $OpenBSD: bn_primitives.c,v 1.1 2023/06/21 07:41:55 jsing Exp $ */
+/* $OpenBSD: bn_primitives.c,v 1.2 2023/06/21 07:48:41 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
#include "bn_internal.h"
#include "bn_local.h"
+#ifndef HAVE_BN_CLZW
#ifndef HAVE_BN_WORD_CLZ
int
bn_word_clz(BN_ULONG w)
return BN_BITS2 - bits;
}
#endif
+#endif
#ifndef HAVE_BN_BITSIZE
int
i++;
}
- return (n + 1) * BN_BITS2 - bn_word_clz(x);
+ return (n + 1) * BN_BITS2 - bn_clzw(x);
}
#endif