summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Marheine <pmarheine@chromium.org>2022-05-09 14:55:49 +1000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-11 00:49:26 +0000
commit7afbd0553f0520c17865edb9431f72ae21541acf (patch)
treed46489ce046b691a5556440c1afa0b28785933b5
parent16f2a778078f94b4a6c69537322b828cfd3fbf05 (diff)
downloadchrome-ec-7afbd0553f0520c17865edb9431f72ae21541acf.tar.gz
zephyr/riscv: implement FPU support functions for RV32F
EC floating-point depends on custom implementations of `fqrtf` and `fabsf` since Zephyr doesn't provide them. Implement them in terms of the standard F extension's instructions for those operations. BUG=b:227961840 TEST=Nereid now builds if CONFIG_FPU is enabled BRANCH=none Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: I904084f297d6a6c85f69feb9e0e72775dbabf83f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3631854 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/Kconfig4
-rw-r--r--zephyr/shim/include/fpu.h18
2 files changed, 18 insertions, 4 deletions
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index 9d8b53ad03..4170225255 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -339,7 +339,7 @@ config PLATFORM_EC_FLASH_CROS
config PLATFORM_EC_FPU
bool "Support floating point"
- depends on FPU && CPU_CORTEX_M && !NEWLIB_LIBC
+ depends on FPU && (CPU_CORTEX_M || RISCV) && !NEWLIB_LIBC
default y
help
This enables support for floating point. This is generally already
@@ -347,8 +347,6 @@ config PLATFORM_EC_FPU
available which are not available with Zephyr's minimal lib: sqrtf()
and fabsf(). Enabling this options defines them.
- For now this is only supported on Cortex-M4.
-
config PLATFORM_EC_HOOKS
bool "Hooks and deferred compatibility shim"
default y
diff --git a/zephyr/shim/include/fpu.h b/zephyr/shim/include/fpu.h
index da36f50492..8f78fb587d 100644
--- a/zephyr/shim/include/fpu.h
+++ b/zephyr/shim/include/fpu.h
@@ -47,9 +47,25 @@ static inline float fabsf(float v)
return root;
}
+#elif CONFIG_RISCV
+static inline float sqrtf(float v)
+{
+ float root;
+
+ __asm__("fsqrt.s %0, %1" : "=f"(root) : "f"(v));
+ return root;
+}
+
+static inline float fabsf(float v)
+{
+ float abs;
+
+ __asm__("fabs.s %0, %1" : "=f"(abs) : "f"(v));
+ return abs;
+}
#else
#error "Unsupported core: please add an implementation"
-#endif /* CONFIG_CPU_CORTEX_M */
+#endif
#endif /* CONFIG_PLATFORM_EC_FPU */