sbi_math.c 397 B

1234567891011121314151617181920212223
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  5. *
  6. * Common helper functions used across OpenSBI project.
  7. *
  8. * Authors:
  9. * Atish Patra <atish.patra@wdc.com>
  10. */
  11. unsigned long log2roundup(unsigned long x)
  12. {
  13. unsigned long ret = 0;
  14. while (ret < __riscv_xlen) {
  15. if (x <= (1UL << ret))
  16. break;
  17. ret++;
  18. }
  19. return ret;
  20. }