aboutsummaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_math.c
diff options
context:
space:
mode:
authorAtish Patra <atish.patra@wdc.com>2020-05-09 16:47:25 -0700
committerAnup Patel <anup@brainfault.org>2020-05-10 09:59:24 +0530
commit13ca20d8df3b402d12e5701c651a53409db167d8 (patch)
treec7afbf73b0047ab7534379f64f465c86ea1fcea6 /lib/sbi/sbi_math.c
parentaef9a60d521a7810557d1caf826311bc349691ac (diff)
lib: Create a separate math helper function file
There may be few common mathematics helper functions which can be used anywhere in OpenSBI project. Add a separate math helper function file to add these functions. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'lib/sbi/sbi_math.c')
-rw-r--r--lib/sbi/sbi_math.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sbi/sbi_math.c b/lib/sbi/sbi_math.c
new file mode 100644
index 0000000..8ba0831
--- /dev/null
+++ b/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;
+}