From 41fd6e003cb10f8a02023311319566233d621201 Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Wed, 18 Aug 2021 21:04:45 +0900 Subject: [PATCH] arch: arm: aarch32: Add half-precision floating-point configs This commit adds the half-precision (16-bit) floating-point configurations to the ARM AArch32 architectures. Enabling CONFIG_FP16 has the effect of specifying `-mfp16-format` option (in case of GCC) which allows using the half-precision floating point types such as `__fp16` and `_Float16`. Note that this configuration can be used regardless of whether a hardware FPU is available or supports half-precision operations. When an FP16-capable FPU is not available, the compiler will automatically provide the software emulations. Signed-off-by: Stephanos Ioannidis --- arch/arm/core/aarch32/Kconfig | 31 +++++++++++++++++++++++++++++ cmake/compiler/gcc/target_arm.cmake | 10 ++++++++++ 2 files changed, 41 insertions(+) diff --git a/arch/arm/core/aarch32/Kconfig b/arch/arm/core/aarch32/Kconfig index 022bfba4fe2..1fe06790b5c 100644 --- a/arch/arm/core/aarch32/Kconfig +++ b/arch/arm/core/aarch32/Kconfig @@ -260,6 +260,37 @@ config FP_SOFTABI endchoice +config FP16 + bool "Half-precision floating point support" + default y + help + This option enables the half-precision (16-bit) floating point support + via the `__fp16` (both IEEE and ARM alternative formats) and the + `_Float16` (IEEE format only) types. + +choice + prompt "FP16 format" + default FP16_IEEE + depends on FP16 + +config FP16_IEEE + bool "FP16 IEEE format" + help + This option selects the IEEE 754-2008 format for FP16. This format can + represent normalized values in the range of 2^(-14) to 65504. There are + 11 bits of significand precision, approximately 3 decimal digits. + +config FP16_ALT + bool "FP16 ARM alternative format" + help + This option selects the ARM alternative format for FP16. This + representation is similar to the IEEE 754-2008 format, but does not + support infinites or NaNs. Instead, the range of exponents is extended, + so that this format can represent normalized values in the range of + 2^(-14) to 131008. + +endchoice + rsource "cortex_m/Kconfig" rsource "cortex_a_r/Kconfig" diff --git a/cmake/compiler/gcc/target_arm.cmake b/cmake/compiler/gcc/target_arm.cmake index fb939c23238..36b0513458a 100644 --- a/cmake/compiler/gcc/target_arm.cmake +++ b/cmake/compiler/gcc/target_arm.cmake @@ -38,3 +38,13 @@ if(CONFIG_FPU) list(APPEND TOOLCHAIN_LD_FLAGS -mfloat-abi=hard) endif() endif() + +if(CONFIG_FP16) + if (CONFIG_FP16_IEEE) + list(APPEND TOOLCHAIN_C_FLAGS -mfp16-format=ieee) + list(APPEND TOOLCHAIN_LD_FLAGS -mfp16-format=ieee) + elseif(CONFIG_FP16_ALT) + list(APPEND TOOLCHAIN_C_FLAGS -mfp16-format=alternative) + list(APPEND TOOLCHAIN_LD_FLAGS -mfp16-format=alternative) + endif() +endif()