From 685e6c04ecd6da86ffdcf4cb28645350b221196a Mon Sep 17 00:00:00 2001 From: stnolting <22944758+stnolting@users.noreply.github.com> Date: Sat, 18 May 2024 17:34:50 +0200 Subject: [PATCH 1/3] [sw/common] add -ffp-contract=off flag Prevent GCC from emitting fused / multiply-add floating-point operations --- sw/common/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sw/common/common.mk b/sw/common/common.mk index b85c12325..c2066f79d 100644 --- a/sw/common/common.mk +++ b/sw/common/common.mk @@ -111,7 +111,7 @@ IMAGE_GEN = $(NEORV32_EXG_PATH)/image_gen # Compiler & linker flags CC_OPTS = -march=$(MARCH) -mabi=$(MABI) $(EFFORT) -Wall -ffunction-sections -fdata-sections -nostartfiles -mno-fdiv -CC_OPTS += -mstrict-align -mbranch-cost=10 -g -Wl,--gc-sections +CC_OPTS += -mstrict-align -mbranch-cost=10 -g -Wl,--gc-sections -ffp-contract=off CC_OPTS += $(USER_FLAGS) LD_LIBS = -lm -lc -lgcc LD_LIBS += $(USER_LIBS) From e567fd16141b005c63fb5e373db4314aadf39e1c Mon Sep 17 00:00:00 2001 From: stnolting <22944758+stnolting@users.noreply.github.com> Date: Sat, 18 May 2024 17:35:09 +0200 Subject: [PATCH 2/3] [docs] update FPU fused/MAC section --- docs/datasheet/cpu.adoc | 10 +++++++--- docs/datasheet/software.adoc | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/datasheet/cpu.adoc b/docs/datasheet/cpu.adoc index 632d6bdca..7af38debe 100644 --- a/docs/datasheet/cpu.adoc +++ b/docs/datasheet/cpu.adoc @@ -680,10 +680,14 @@ register file-related load/store or move instructions. The `Zfinx` extension'S f via dedicated <<_floating_point_csrs>>. This ISA extension is implemented as multi-cycle ALU co-process (`rtl/core/neorv32_cpu_cp_fpu.vhd`). -.Fused Multiply-Add and Division Instructions +.Fused / Multiply-Add Instructions [WARNING] -Fused multiply-add instructions `f[n]m[add/sub].s` are not supported! -Division `fdiv.s` and square root `fsqrt.s` instructions are not supported yet! +Fused multiply-add instructions `f[n]m[add/sub].s` are not supported. A special GCC switch is used to prevent the +compiler from emitting contracted/fused floating-point operations (see <<_default_compiler_flags>>). + +.Division and Squarer Root Instructions +[WARNING] +Division `fdiv.s` and square root `fsqrt.s` instructions are not supported yet. .Subnormal Number [WARNING] diff --git a/docs/datasheet/software.adoc b/docs/datasheet/software.adoc index 7a98bb020..94f07dc3c 100644 --- a/docs/datasheet/software.adoc +++ b/docs/datasheet/software.adoc @@ -286,6 +286,7 @@ The makefile's `CC_OPTS` is exported as **define** to be available within a C pr | `-g` | Include debugging information/symbols in ELF. | `-mstrict-align` | Unaligned memory accesses cannot be resolved by the hardware and require emulation. | `-mbranch-cost=10` | Branching costs a lot of cycles. +| `-ffp-contract=off` | Do not allow contraction of floatind-point operations (no fused operations as they are not supported). |======================= :sectnums: From 316b6c69c981d3b1f9d90d52b59cc121dde173cb Mon Sep 17 00:00:00 2001 From: stnolting <22944758+stnolting@users.noreply.github.com> Date: Sat, 18 May 2024 18:04:24 +0200 Subject: [PATCH 3/3] [sw] minor clean-ups --- sw/common/common.mk | 67 +++++++++++------------------------- sw/lib/source/neorv32_uart.c | 26 +++++++------- 2 files changed, 34 insertions(+), 59 deletions(-) diff --git a/sw/common/common.mk b/sw/common/common.mk index c2066f79d..8aecfb401 100644 --- a/sw/common/common.mk +++ b/sw/common/common.mk @@ -324,72 +324,45 @@ clean_all: clean # Show configuration # ----------------------------------------------------------------------------- info: - @echo "------------------------------------------------------" - @echo "-- Project" - @echo "------------------------------------------------------" - @echo "Project folder: $(shell basename $(CURDIR))" - @echo "Source files: $(APP_SRC)" - @echo "Include folder(s): $(APP_INC)" + @echo "******************************************************" + @echo "Project / Makfile Configuration" + @echo "******************************************************" + @echo "Project folder: $(shell basename $(CURDIR))" + @echo "Source files: $(APP_SRC)" + @echo "Include folder(s): $(APP_INC)" @echo "ASM include folder(s): $(ASM_INC)" - @echo "------------------------------------------------------" - @echo "-- NEORV32" - @echo "------------------------------------------------------" @echo "NEORV32 home folder (NEORV32_HOME): $(NEORV32_HOME)" @echo "IMAGE_GEN: $(IMAGE_GEN)" @echo "Core source files:" @echo "$(CORE_SRC)" @echo "Core include folder:" @echo "$(NEORV32_INC_PATH)" - @echo "------------------------------------------------------" - @echo "-- Objects" - @echo "------------------------------------------------------" @echo "Project object files:" @echo "$(OBJ)" - @echo "------------------------------------------------------" - @echo "-- RISC-V CPU" - @echo "------------------------------------------------------" - @echo "MARCH: $(MARCH)" - @echo "MABI: $(MABI)" - @echo "------------------------------------------------------" - @echo "-- Toolchain" - @echo "------------------------------------------------------" - @echo "CC: $(CC)" - @echo "OBJDUMP: $(OBJDUMP)" - @echo "OBJCOPY: $(OBJCOPY)" - @echo "SIZE: $(SIZE)" - @echo "DEBUGGER: $(GDB)" - @echo "------------------------------------------------------" - @echo "-- GDB Arguments" - @echo "------------------------------------------------------" - @echo "GDB_ARGS: $(GDB_ARGS)" - @echo "------------------------------------------------------" - @echo "-- GHDL Run Arguments" - @echo "------------------------------------------------------" - @echo "GHDL_RUN_FLAGS: $(GHDL_RUN_FLAGS)" - @echo "------------------------------------------------------" - @echo "-- Libraries" - @echo "------------------------------------------------------" @echo "LIBGCC:" @$(CC) -print-libgcc-file-name @echo "SEARCH-DIRS:" @$(CC) -print-search-dirs - @echo "------------------------------------------------------" - @echo "-- Compiler Flags" - @echo "------------------------------------------------------" - @echo "USER_FLAGS: $(USER_FLAGS)" - @echo "CC_OPTS: $(CC_OPTS)" - @echo "------------------------------------------------------" - @echo "-- Libraries" - @echo "------------------------------------------------------" - @echo "USER_LIBS: $(USER_LIBS)" - @echo "LD_LIBS: $(LD_LIBS)" + @echo "USER_LIBS: $(USER_LIBS)" + @echo "LD_LIBS: $(LD_LIBS)" + @echo "MARCH: $(MARCH)" + @echo "MABI: $(MABI)" + @echo "CC: $(CC)" + @echo "OBJDUMP: $(OBJDUMP)" + @echo "OBJCOPY: $(OBJCOPY)" + @echo "SIZE: $(SIZE)" + @echo "DEBUGGER: $(GDB)" + @echo "GDB_ARGS: $(GDB_ARGS)" + @echo "GHDL_RUN_FLAGS: $(GHDL_RUN_FLAGS)" + @echo "USER_FLAGS: $(USER_FLAGS)" + @echo "CC_OPTS: $(CC_OPTS)" # ----------------------------------------------------------------------------- # Help # ----------------------------------------------------------------------------- help: - @echo "NEORV32 Software Application Makefile" + @echo "NEORV32 Software Makefile" @echo "Find more information at https://github.com/stnolting/neorv32" @echo "" @echo "Targets:" diff --git a/sw/lib/source/neorv32_uart.c b/sw/lib/source/neorv32_uart.c index 6c0504fb6..9e6fca84f 100644 --- a/sw/lib/source/neorv32_uart.c +++ b/sw/lib/source/neorv32_uart.c @@ -284,21 +284,12 @@ void neorv32_uart_puts(neorv32_uart_t *UARTx, const char *s) { /**********************************************************************//** * Custom version of 'vprintf' printing to UART. * + * @warning: This functions only provides a minimal subset of the 'vprintf' formating features! * @note This function is blocking. * * @param[in,out] UARTx Hardware handle to UART register struct, #neorv32_uart_t. * @param[in] format Pointer to format string. * @param[in] args A value identifying a variable arguments list. - * - * - * - * - * - * - * - * - * - *
%sString (array of chars, zero-terminated)
%cSingle char
%d/%i32-bit signed number, printed as decimal
%u32-bit unsigned number, printed as decimal
%x32-bit number, printed as 8-char hexadecimal - lower-case
%X32-bit number, printed as 8-char hexadecimal - upper-case
%p32-bit pointer, printed as 8-char hexadecimal - lower-case
**************************************************************************/ void neorv32_uart_vprintf(neorv32_uart_t *UARTx, const char *format, va_list args) { @@ -344,11 +335,21 @@ void neorv32_uart_vprintf(neorv32_uart_t *UARTx, const char *format, va_list arg neorv32_uart_puts(UARTx, string_buf); break; +// case 'f': // floating point: print binary representation in hex +// union { double fp64; uint32_t u32[2]; } fp2hex; +// neorv32_uart_puts(UARTx, "FP64:0x"); +// fp2hex.fp64 = va_arg(args, double); // C promotes float to double! +// __neorv32_uart_tohex(fp2hex.u32[0], string_buf); +// neorv32_uart_puts(UARTx, string_buf); +// __neorv32_uart_tohex(fp2hex.u32[1], string_buf); +// neorv32_uart_puts(UARTx, string_buf); +// break; + case '%': // escaped percent sign - neorv32_uart_putc(UARTx, '%'); + neorv32_uart_putc(UARTx, c); break; - default: // unsupported format + default: // unsupported formating character neorv32_uart_putc(UARTx, '%'); neorv32_uart_putc(UARTx, c); break; @@ -367,6 +368,7 @@ void neorv32_uart_vprintf(neorv32_uart_t *UARTx, const char *format, va_list arg /**********************************************************************//** * Custom version of 'printf' printing to UART. * + * @warning: This functions only provides a minimal subset of the 'printf' formating features! * @note This function is blocking. * * @param[in,out] UARTx Hardware handle to UART register struct, #neorv32_uart_t.