Skip to content

Commit caafd5d

Browse files
authored
Merge pull request #728 from ckormanyos/global_pointerp_esp32_p4
Use the global small data pointer
2 parents 72dc796 + 88b31ff commit caafd5d

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

ref_app/src/math/functions/math_functions_bessel.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2014 - 2025.
2+
// Copyright Christopher Kormanyos 2014 - 2026.
33
// Distributed under the Boost Software License,
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt
55
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -22,11 +22,24 @@
2222
// Compute the Taylor series representation of cyl_bessel_j.
2323
// There are no checks on input range or parameter boundaries.
2424

25+
// The following low-precision analysis has been carried out
26+
// for another perspective on small arguments.
27+
28+
// Series[BesselJ[n, x], {x, 0, 7}]
29+
// Normal[%]
30+
// FullSimplify[%]
31+
// Then explicitly take the polynomial part and run it through HornerForm[...].
32+
// The result is the following.
33+
// (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)))
34+
// This should provide good precision for 32-bit float for arguments having (x/n) <= 3/10.
35+
2536
const T x_half = x / 2;
2637
const T v_plus_one = v + 1;
2738

28-
const T hypergeometric_0f1_term =
29-
math::functions::hypergeometric_0f1(v_plus_one, -(x_half * x_half));
39+
const T hypergeometric_0f1_term
40+
{
41+
math::functions::hypergeometric_0f1(v_plus_one, -(x_half * x_half))
42+
};
3043

3144
using std::pow;
3245
using std::tgamma;

ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4.ld

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ SECTIONS
122122
*(.data*)
123123
. = ALIGN(4);
124124
KEEP (*(.data*))
125+
_small_ram_begin = .;
125126
*(.sdata)
126127
. = ALIGN(4);
127128
KEEP (*(.sdata))
@@ -135,18 +136,19 @@ SECTIONS
135136
.bss : ALIGN(4)
136137
{
137138
_bss_begin = .;
138-
*(.bss)
139-
. = ALIGN(4);
140-
KEEP (*(.bss))
141-
*(.bss*)
142-
. = ALIGN(4);
143-
KEEP (*(.bss*))
144139
*(.sbss)
145140
. = ALIGN(4);
146141
KEEP (*(.sbss))
147142
*(.sbss*)
148143
. = ALIGN(4);
149144
KEEP (*(.sbss*))
145+
_small_ram_end = .;
146+
*(.bss)
147+
. = ALIGN(4);
148+
KEEP (*(.bss))
149+
*(.bss*)
150+
. = ALIGN(4);
151+
KEEP (*(.bss*))
150152
_bss_end = .;
151153
} > RAM
152154

@@ -174,4 +176,6 @@ SECTIONS
174176
printf = 0x4fc00024;
175177

176178
_rom_data_begin = LOADADDR(.data);
179+
180+
_global_pointer = _small_ram_begin + (_small_ram_end - _small_ram_begin) / 2;
177181
}

ref_app/target/micros/xtensa_esp32_p4/make/xtensa_esp32_p4_flags.gmk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ TGT_ALLFLAGS = -O2
2121
-march=rv32imafc_zicsr_zifencei_xesppie \
2222
-mabi=ilp32f \
2323
-msmall-data-limit=32 \
24+
-mrelax \
25+
-mrelax \
26+
-fno-common \
2427
-falign-functions=4 \
2528
-fomit-frame-pointer \
2629
-DHP_CORES_SMP_MODE
@@ -40,6 +43,7 @@ TGT_AFLAGS =
4043

4144
TGT_LDFLAGS = -nostdlib \
4245
-nostartfiles \
46+
$(TGT_ALLFLAGS) \
4347
-Wl,--no-warn-rwx-segments \
4448
-Wl,-z,max-page-size=4096 \
4549
-Wl,-Map,$(APP).map \

ref_app/target/micros/xtensa_esp32_p4/startup/Code/Startup/boot.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
.align 2
3939
.globl _start
4040
.extern main_x
41+
.extern _global_pointer
4142

4243
.set mtvt, 0x307
4344
.set msip, 0x20000000
@@ -56,6 +57,9 @@ _start:
5657
csrs mstatus, t0
5758
fscsr x0
5859

60+
/* Set/enable the global pointer for small ram */
61+
la gp, _global_pointer
62+
5963
/* Read machine hart ID */
6064
csrr a0, mhartid
6165
bnez a0, .L_core1

0 commit comments

Comments
 (0)