-
Notifications
You must be signed in to change notification settings - Fork 0
Hints for Smaller Code
Inspired by Earle F. Philhower, III's PR
Use int
instead of char
, uint8_t
, etc for byte-oriented types.
Where it doesn't make a functional difference, make global variables
ints and not uint8_t. Bytewide updates and extracts require multiple
instructions and hence increase code size as well as runtime.
Or unsigned
for uint8_t
and char
(char
on ESP8266 is unsigned) instead of int
if the sitiation calls for it.
Check if inlining short functions save iRAM. Certain conditions can be statically evaluated by GCC. There is also a cost of saving locals before the call is made.
GCC won't use a lookup table for some switch statements, so it ends up using a series of straight-line compare-jump, compare-jumps to figure out which branch of code to execute for each state. For branches that have multiple states that call them, this can expand to a lot of code.
Short-circuit the whole thing by converting the FSM to a 1-hot encoding while executing it, and then just and-ing the 1-hot state with the bitmask of states with the same code.
Move all global objects into a struct. This lets a single base pointer register to be used in place of constantly reloading the address of each individual variable.
Moving to a C++ implementation based on a class object might be an alternative.
Use enums
instead of #define
, in the hope that it will
allow GCC to more easily flag problems and general good code
organization.
Group like types together such that the structure is naturally packed.
- Keeping the Lights On - how to manage GPIO state across reboots and crashes
- Boot fails when SPI Bus used
- GPIO Drive Strength and Ringing
- LDO Regulators WIP
- ESP8266 Power Considerations This is only a rough outline, needs a lot of development.
- Upgrading Flash Chips, QIO, and DIO
- Dodgy Extra 2K of DRAM or CONT - WIP
- WDTracks - Print last call before WDT
- 5V Tolerant I/O?
Arduino IDE specific
Misc.
- Exception Causes
- ESP8266 will not boot
- Stacks sys and cont
- WIP Boot ROM and SDK Notes
- Multi-segment Boot ROM Loader, notes
- Cache_Read_Enable How to turn off and on instruction cache execution.