diff options
Diffstat (limited to 'roms/opensbi/lib/sbi/sbi_math.c')
-rw-r--r-- | roms/opensbi/lib/sbi/sbi_math.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/roms/opensbi/lib/sbi/sbi_math.c b/roms/opensbi/lib/sbi/sbi_math.c new file mode 100644 index 000000000..8ba0831d8 --- /dev/null +++ b/roms/opensbi/lib/sbi/sbi_math.c @@ -0,0 +1,23 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Common helper functions used across OpenSBI project. + * + * Authors: + * Atish Patra <atish.patra@wdc.com> + */ + +unsigned long log2roundup(unsigned long x) +{ + unsigned long ret = 0; + + while (ret < __riscv_xlen) { + if (x <= (1UL << ret)) + break; + ret++; + } + + return ret; +} |