Skip to content

Commit

Permalink
optionally move float emulation code into iram (#8958)
Browse files Browse the repository at this point in the history
* optionally move float emulation code into iram
allows doing float operation in iram
suitable for libraries like AccelStepper when called from ISR
* proposed changes for pio from @mcspr
  • Loading branch information
d-a-v authored Nov 12, 2023
1 parent 74c04c8 commit d0f7293
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 9 deletions.
153 changes: 153 additions & 0 deletions boards.txt

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions doc/ideoptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ See our issue tracker in regards to default version selection.

Notice that 3.x.x is provided **as-is** and remains **experimental**.

Floating Point operations
~~~~~~~~~~~~~~~~~~~~~~~~~

- ``in IROM``: This provides more free space in IRAM but disallows using floating operations inside ISRs.
- ``allowed in ISR``: Floats can be used in ISRs, cost is ~1KB IRAM when floats are used.

SSL Support
~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion package/package_esp8266com_index.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,4 @@
]
}
]
}
}
9 changes: 6 additions & 3 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ build.spiffs_start=
build.spiffs_end=
build.spiffs_blocksize=

# soft float location
build.iramfloat=-DFP_IN_IROM

# Fully qualified file names for processing sketch global options
globals.h.source.fqfn={build.source.path}/{build.project_name}.globals.h
commonhfile.fqfn={build.core.path}/CommonHFile.h
Expand All @@ -79,7 +82,7 @@ compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_S
compiler.libraries.ldflags=

compiler.c.cmd=xtensa-lx106-elf-gcc
compiler.c.flags=-c "{compiler.warning_flags}-cflags" -std=gnu17 {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
compiler.c.flags=-c "{compiler.warning_flags}-cflags" -std=gnu17 {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags} {build.iramfloat}

compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls "-I{runtime.tools.xtensa-lx106-elf-gcc.path}/include/"
Expand All @@ -90,7 +93,7 @@ compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc

compiler.cpp.cmd=xtensa-lx106-elf-g++
compiler.cpp.flags=-c "{compiler.warning_flags}-cppflags" {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags}
compiler.cpp.flags=-c "{compiler.warning_flags}-cppflags" {build.stacksmash_flags} -g -free -fipa-pta -Werror=return-type -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 {build.stdcpp_level} -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} {build.mmuflags} {build.non32xferflags} {build.iramfloat}

compiler.as.cmd=xtensa-lx106-elf-as

Expand Down Expand Up @@ -128,7 +131,7 @@ recipe.hooks.prebuild.2.pattern="{runtime.tools.python3.path}/python3" -I "{runt
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.mkdir}" -p "{build.path}/ld_h/"
recipe.hooks.linking.prelink.2.pattern="{runtime.tools.python3.path}/python3" -I "{runtime.tools.cp}" "{runtime.platform.path}/tools/sdk/ld/{build.flash_ld}" "{build.path}/ld_h/local.eagle.flash.ld.h"
recipe.hooks.linking.prelink.3.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} {build.mmuflags} "{build.path}/ld_h/local.eagle.flash.ld.h" -o "{build.path}/local.eagle.flash.ld"
recipe.hooks.linking.prelink.4.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} {build.mmuflags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
recipe.hooks.linking.prelink.4.pattern="{compiler.path}{compiler.c.cmd}" {build.iramfloat} -CC -E -P {build.vtable_flags} {build.mmuflags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" -DARDUINO_BOARD_ID="{_id}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
Expand Down
14 changes: 14 additions & 0 deletions tools/boards.txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,17 @@ def sdk ():

################################################################

def float_in_iram ():
return { 'iramfloat': collections.OrderedDict([
('.menu.iramfloat.no', 'in IROM'),
('.menu.iramfloat.no.build.iramfloat', '-DFP_IN_IROM'),
('.menu.iramfloat.yes', 'allowed in ISR'),
('.menu.iramfloat.yes.build.iramfloat', '-DFP_IN_IRAM'),
])
}

################################################################

def all_boards ():

if boardsgen or boardslocalgen:
Expand Down Expand Up @@ -1709,6 +1720,7 @@ def all_boards ():
macros.update(led('led', led_default, range(0,led_max+1)))
macros.update(led('led216', 2, { 16 }))
macros.update(sdk())
macros.update(float_in_iram())

if boardfilteropt or excludeboards:
print('#')
Expand Down Expand Up @@ -1754,6 +1766,7 @@ def all_boards ():
print('menu.stacksmash=Stack Protection')
print('menu.wipe=Erase Flash')
print('menu.sdk=NONOS SDK Version')
print('menu.iramfloat=Floating Point operations')
print('menu.ssl=SSL Support')
print('menu.mmu=MMU')
print('menu.non32xfer=Non-32-Bit Access')
Expand Down Expand Up @@ -1791,6 +1804,7 @@ def all_boards ():
macrolist += speeds[default_speed]

macrolist += [ 'autoflash' ]
macrolist += [ 'iramfloat' ]

for block in macrolist:
for optname in macros[block]:
Expand Down
16 changes: 11 additions & 5 deletions tools/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,23 @@ def scons_patched_match_splitext(path, suffixes=None):
#

current_vtables = None
fp_in_irom = ""
current_fp = None
for d in flatten_cppdefines:
if str(d).startswith("VTABLES_IN_"):
current_vtables = d
if str(d) == "FP_IN_IROM":
fp_in_irom = "-DFP_IN_IROM"
if str(d).startswith("FP_IN_"):
current_fp = d

if not current_vtables:
current_vtables = "VTABLES_IN_FLASH"
env.Append(CPPDEFINES=[current_vtables])
assert current_vtables

if not current_fp:
current_fp = "FP_IN_IROM"
env.Append(CPPDEFINES=[current_fp])
assert current_fp

#
# MMU
#
Expand Down Expand Up @@ -363,17 +369,17 @@ def scons_patched_match_splitext(path, suffixes=None):
join("$BUILD_DIR", "ld", "local.eagle.app.v6.common.ld"),
join(FRAMEWORK_DIR, "tools", "sdk", "ld", "eagle.app.v6.common.ld.h"),
env.VerboseAction(
"$CC -CC -E -P -D%s %s %s $SOURCE -o $TARGET"
"$CC -CC -E -P -D%s -D%s %s $SOURCE -o $TARGET"
% (
current_vtables,
current_fp,
# String representation of MMU flags
" ".join(
[
"-D%s=%s" % f if isinstance(f, (tuple, list)) else "-D" + f
for f in mmu_flags
]
),
fp_in_irom,
),
"Generating LD script $TARGET",
),
Expand Down
10 changes: 10 additions & 0 deletions tools/sdk/ld/eagle.app.v6.common.ld.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ SECTIONS

/* all functional callers are placed in IRAM (including SPI/IRQ callbacks/etc) here */
*(.text._ZNKSt8functionIF*EE*) /* std::function<any(...)>::operator()() const */

#ifdef FP_IN_IRAM
*libgcc.a:*f2.o(.literal .text)
*libgcc.a:*f3.o(.literal .text)
*libgcc.a:*fsi.o(.literal .text)
*libgcc.a:*fdi.o(.literal .text)
*libgcc.a:*ifs.o(.literal .text)
*libgcc.a:*idf.o(.literal .text)
#endif

} >iram1_0_seg :iram1_0_phdr

.irom0.text : ALIGN(4)
Expand Down

0 comments on commit d0f7293

Please sign in to comment.