arduino / arduino/ArduinoCore-avr
bloated/inefficient code in init()
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
init() excessively uses the sbi/cbi macros, which rarely compile to the sbi/cbi instructions. For addresses over 0x3F, the sbi macro results in lds + ori + sts. I tried cleaning up the ADC setup code as follows:
```
uint8_t prescaler = _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS2);
ADCSRA = prescaler | _BV(ADEN);
```
This compiles to ldi + sts, and reduced the size of the Blink sketch (built for m328p) from 924 to 890 bytes. Doing the same for the timer setup code would save even more. I'm willing to prepare a pull request if there is interest in these improvements
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating init() and its ADC and timer setup code, then inspect the generated AVR instructions for the existing sbi/cbi usage and the proposed register assignments. Build the Blink sketch for the m328p and compare size and behavior; done means the setup remains equivalent while producing smaller code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100