Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-ffunction-sections -fdata-sections)
add_link_options(-Wl,--gc-sections -Wl,-Map=mapfile.map)

# AVR is the tightest target in the footprint tables, and the one place
# where a further -Os knob still pays: -mcall-prologues replaces each
# function's register-save prologue and epilogue with a call to the shared
# __prologue_saves__ / __epilogue_restores__ pair in libgcc. Measured on
# atmega8, full configuration (tools/footprint.sh, and a linked image to net
# out the helpers):
#
# libsofabuffers.a 8572 B -> 7550 B (-1022 B)
# linked image 8980 B -> 8068 B ( -912 B)
#
# The 110 B difference is that helper pair, which the image pays once; a
# firmware built with the same flag amortises it and keeps the full -1022 B.
# The cost is cycles -- every call now enters and leaves through a shared
# routine -- which is the trade this library makes deliberately: flash is the
# scarce resource on these parts, speed is subordinate.
#
# Guarded on the processor rather than the compiler because the flag is
# AVR-only; CMAKE_SYSTEM_PROCESSOR is set by utils/avr/toolchain-avr.cmake.
# `naked` functions (utils/avr/startup.c) emit no prologue and are
# unaffected. Other architectures measured no gain from their equivalents:
# RISC-V -msave-restore wins 308 B in the archive but only 56 B in a linked
# image, because the __riscv_save_*/__riscv_restore_* set costs 1284 B there,
# and on ARMv6-m every comparable knob came out at ±0 B or worse.
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "avr")
add_compile_options(-mcall-prologues)
endif()

if(SOFAB_ENABLE_LTO)
# -O3 rather than the -Os above: this leg is not measuring footprint, it
# is trying to give the optimiser every reason to act on a type-based
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,14 +713,26 @@ is `.text` (flash). The tables are `size libsofabuffers.a` at `-Os`, regenerated
configuration; `atmega8` is the exception, its workflow being on manual dispatch
until the test image links again.

The AVR rows carry one flag beyond `-Os`: `-mcall-prologues`, which routes every
prologue and epilogue through libgcc's shared save/restore pair. It is worth
1022 B of the `atmega8` *Full* row and is applied by the top-level
`CMakeLists.txt` for that processor only, so a hand-rolled AVR build without it
measures about 1 KB more. In a linked image it nets 912 B — the shared
pair costs 110 B once, which a firmware built with the same flag amortises.
It buys flash with cycles, which is the trade this library makes on these parts.
The equivalents elsewhere do not pay and are deliberately not set: RISC-V
`-msave-restore` saves 308 B in the archive but only 56 B in an image
(its helper set costs 1284 B there), and on ARMv6-m every comparable knob
measured ±0 B or worse.

**Full configuration**

| Architecture | .text | .data | .bss |
| - | - | - | - |
| ARMv6-m | ~3.9KB | 0.0KB | 0.0KB |
| ARMv7-m+fp.dp | ~3.9KB | 0.0KB | 0.0KB |
| RV32IMC | ~5.0KB | 0.0KB | 0.0KB |
| atmega8 | ~8.4KB | 0.0KB | 0.0KB |
| atmega8 | ~7.4KB | 0.0KB | 0.0KB |

**Full configuration, strict UTF-8 on** — the only rows where the validator
(`utf8.c`) is compiled in. The delta over *Full* above is its entire
Expand All @@ -731,10 +743,10 @@ until the test image links again.
| ARMv6-m | ~4.1KB | 0.0KB | 0.0KB |
| ARMv7-m+fp.dp | ~4.1KB | 0.0KB | 0.0KB |
| RV32IMC | ~5.2KB | 0.0KB | 0.0KB |
| atmega8 | ~8.8KB | 0.0KB | 0.0KB |
| atmega8 | ~7.8KB | 0.0KB | 0.0KB |

The [hold-back framing](#sequence-framing-and-the-hold-back-window) is part of
those *Full* rows: 276 B on ARMv6-m, 512 B on atmega8. A pure-C consumer
those *Full* rows: 276 B on ARMv6-m, 398 B on atmega8. A pure-C consumer
encoding only through `sofab_object_encode()` takes it back out with
`SOFAB_DISABLE_LAZY_SEQ_SUPPORT` — ARMv6-m returns to 3684 B, `sofab_ostream_t`
shrinks from 56 B to 20 B per stream, and a typical encode drops
Expand All @@ -750,7 +762,7 @@ unaffected.
| ARMv6-m | ~1.1KB | 0.0KB | 0.0KB |
| ARMv7-m+fp.dp | ~1.1KB | 0.0KB | 0.0KB |
| RV32IMC | ~1.4KB | 0.0KB | 0.0KB |
| atmega8 | ~2.8KB | 0.0KB | 0.0KB |
| atmega8 | ~2.4KB | 0.0KB | 0.0KB |

Same minimal configuration, additionally without `object.c`
(`SOFAB_DISABLE_OBJECT_API`):
Expand All @@ -760,7 +772,7 @@ Same minimal configuration, additionally without `object.c`
| ARMv6-m | ~0.7KB | 0.0KB | 0.0KB |
| ARMv7-m+fp.dp | ~0.7KB | 0.0KB | 0.0KB |
| RV32IMC | ~0.9KB | 0.0KB | 0.0KB |
| atmega8 | ~1.9KB | 0.0KB | 0.0KB |
| atmega8 | ~1.6KB | 0.0KB | 0.0KB |

#### What each switch is worth

Expand Down
Loading