mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
Merge pull request #7462 from daverodgman/clz_size_opt
clz size/perf optimisation
This commit is contained in:
@@ -309,6 +309,36 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_core_clz(int leading_zeros, int trailing_zeros)
|
||||
{
|
||||
if ((size_t) (leading_zeros + trailing_zeros) >= (sizeof(mbedtls_mpi_uint) * 8)) {
|
||||
// can't fit required number of leading and trailing zeros - skip test
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// Construct a test input value where the count of leading zeros and
|
||||
// trailing zeros is given in the test case, and we add ones to fill
|
||||
// the gap.
|
||||
mbedtls_mpi_uint x;
|
||||
if ((leading_zeros + trailing_zeros) > 0) {
|
||||
// some zero bits
|
||||
uint32_t s = (sizeof(mbedtls_mpi_uint) * 8 - leading_zeros - trailing_zeros);
|
||||
x = ((((mbedtls_mpi_uint) 1) << s) - 1) << trailing_zeros;
|
||||
} else {
|
||||
// all bits set
|
||||
x = ~((mbedtls_mpi_uint) 0);
|
||||
}
|
||||
|
||||
size_t n = mbedtls_mpi_core_clz(x);
|
||||
TEST_EQUAL(n, leading_zeros);
|
||||
exit:
|
||||
;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mpi_core_lt_ct(char *input_X, char *input_Y, int exp_ret)
|
||||
{
|
||||
|
@@ -491,3 +491,35 @@ mpi_core_fill_random:42:0:-1:0:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
Fill random core: 42 bytes, 5 missing limbs
|
||||
mpi_core_fill_random:42:0:-5:0:MBEDTLS_ERR_MPI_BAD_INPUT_DATA
|
||||
|
||||
CLZ: 0 0: all ones
|
||||
mpi_core_clz:0:0
|
||||
|
||||
CLZ: 1 0
|
||||
mpi_core_clz:1:0
|
||||
|
||||
CLZ: 1 1
|
||||
mpi_core_clz:1:1
|
||||
|
||||
CLZ: 4 5
|
||||
mpi_core_clz:4:5
|
||||
|
||||
CLZ: 8 16
|
||||
mpi_core_clz:8:16
|
||||
|
||||
CLZ: 31 0
|
||||
mpi_core_clz:31:0
|
||||
|
||||
CLZ: 32 0
|
||||
mpi_core_clz:32:0
|
||||
|
||||
CLZ: 33 0
|
||||
mpi_core_clz:33:0
|
||||
|
||||
CLZ: 63 0
|
||||
mpi_core_clz:63:0
|
||||
|
||||
CLZ: 64 0
|
||||
mpi_core_clz:64:0
|
||||
|
||||
CLZ: 100000 0: skip overly long input
|
||||
mpi_core_clz:100000:0
|
||||
|
Reference in New Issue
Block a user