From 88b31ff8a43c105dc3ed123b6f4af7ff27286c37 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Fri, 20 Feb 2026 21:30:07 +0100 Subject: [PATCH] Use the global small data pointer --- .../math/functions/math_functions_bessel.h | 19 ++++++++++++++++--- .../xtensa_esp32_p4/make/xtensa_esp32_p4.ld | 16 ++++++++++------ .../make/xtensa_esp32_p4_flags.gmk | 4 ++++ .../startup/Code/Startup/boot.s | 4 ++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/ref_app/src/math/functions/math_functions_bessel.h b/ref_app/src/math/functions/math_functions_bessel.h index 20bf91a1c..2f376b606 100644 --- a/ref_app/src/math/functions/math_functions_bessel.h +++ b/ref_app/src/math/functions/math_functions_bessel.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2014 - 2025. +// Copyright Christopher Kormanyos 2014 - 2026. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -22,11 +22,24 @@ // Compute the Taylor series representation of cyl_bessel_j. // There are no checks on input range or parameter boundaries. + // The following low-precision analysis has been carried out + // for another perspective on small arguments. + + // Series[BesselJ[n, x], {x, 0, 7}] + // Normal[%] + // FullSimplify[%] + // Then explicitly take the polynomial part and run it through HornerForm[...]. + // The result is the following. + // (1/(3 Gamma[4 + n])) 2^(-7 - n) x^n (384 (1 + n) (2 + n) (3 + n) - x^2 (576 + n (480 + 96 n) + x^2 (36 + 12 n - x^2))) + // This should provide good precision for 32-bit float for arguments having (x/n) <= 3/10. + const T x_half = x / 2; const T v_plus_one = v + 1; - const T hypergeometric_0f1_term = - math::functions::hypergeometric_0f1(v_plus_one, -(x_half * x_half)); + const T hypergeometric_0f1_term + { + math::functions::hypergeometric_0f1(v_plus_one, -(x_half * x_half)) + }; using std::pow; using std::tgamma; diff --git a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld index ac1a7b1c4..ce2830aec 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld +++ b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld @@ -122,6 +122,7 @@ SECTIONS *(.data*) . = ALIGN(4); KEEP (*(.data*)) + _small_ram_begin = .; *(.sdata) . = ALIGN(4); KEEP (*(.sdata)) @@ -135,18 +136,19 @@ SECTIONS .bss : ALIGN(4) { _bss_begin = .; - *(.bss) - . = ALIGN(4); - KEEP (*(.bss)) - *(.bss*) - . = ALIGN(4); - KEEP (*(.bss*)) *(.sbss) . = ALIGN(4); KEEP (*(.sbss)) *(.sbss*) . = ALIGN(4); KEEP (*(.sbss*)) + _small_ram_end = .; + *(.bss) + . = ALIGN(4); + KEEP (*(.bss)) + *(.bss*) + . = ALIGN(4); + KEEP (*(.bss*)) _bss_end = .; } > RAM @@ -174,4 +176,6 @@ SECTIONS printf = 0x4fc00024; _rom_data_begin = LOADADDR(.data); + + _global_pointer = _small_ram_begin + (_small_ram_end - _small_ram_begin) / 2; } diff --git a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk index 221ac7ebd..72dc8f211 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk +++ b/ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk @@ -21,6 +21,9 @@ TGT_ALLFLAGS = -O2 -march=rv32imafc_zicsr_zifencei_xesppie \ -mabi=ilp32f \ -msmall-data-limit=32 \ + -mrelax \ + -mrelax \ + -fno-common \ -falign-functions=4 \ -fomit-frame-pointer \ -DHP_CORES_SMP_MODE @@ -40,6 +43,7 @@ TGT_AFLAGS = TGT_LDFLAGS = -nostdlib \ -nostartfiles \ + $(TGT_ALLFLAGS) \ -Wl,--no-warn-rwx-segments \ -Wl,-z,max-page-size=4096 \ -Wl,-Map,$(APP).map \ diff --git a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/boot.s b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/boot.s index 2af61f36c..bca56bd30 100644 --- a/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/boot.s +++ b/ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/boot.s @@ -38,6 +38,7 @@ .align 2 .globl _start .extern main_x +.extern _global_pointer .set mtvt, 0x307 .set msip, 0x20000000 @@ -56,6 +57,9 @@ _start: csrs mstatus, t0 fscsr x0 + /* Set/enable the global pointer for small ram */ + la gp, _global_pointer + /* Read machine hart ID */ csrr a0, mhartid bnez a0, .L_core1