Repository navigation
examples/static_net: WaveOf binds its source to a local for right shifts (wave4 44 B → 42 B) - #10
Merged
Merged
Conversation
…fts (wave4 44 B -> 42 B) avr-gcc 7.3 -Os does a right shift followed by a mask in 8 bits only when the shifted byte is a variable and nothing narrows it before the mask. WaveOf read the byte as Src::get(in) inside the expression and cast the shift to u8, so the shift stayed in int and register allocation added a copy: the Banknote cell was 28 instructions where the same cell in plain C is 27. WaveOf::proc now reads the source into a local and, for right shifts, shifts, adds and masks without narrowing in between. Left shifts keep the early u8 cast: without it gcc 7.3 does them in 16 bits (mixed_avr_size grows by 30 B). The result is the same for every n, s in -7..7, p, m and input byte (3.0e9 cases, host). check/build.sh: 65 ok. banknote_avr_check is 2344 B (was 2346); every other program keeps its size. compare_emlearn: wave4 42 B, 24 cycles (was 44 B, 25). measure/'s bn_wave is unchanged at 23 cycles. tests/single_header/run.sh: 36 ok. The READMEs quoting the figures are updated; silicon_results.md notes its ELFs predate the change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Roy · project thread
Before: on avr-gcc 7.3 the Banknote
wave4cell was one instruction longer than the same cell written in plain C (28 vs 27 instructions, #9). The extra instruction was a register copy. static_net reported it as 44 B and 25 cycles.After: the HAPI cell is byte-identical to the plain C one. static_net's
wave4is 42 B, 24 cycles, and every other program ofcheck/build.shkeeps its size.gcc 7.3 at
-Osdoes a right shift followed by a mask in 8 bits only when the shifted byte is a variable and nothing narrows it before the mask.WaveOfread the byte asSrc::get(in)inside the expression and cast the shift tou8, so the shift stayed inint. AVR gcc 16.1 folds the old spelling as well, so this is a 7.3 workaround in the example's cell, not a change to HAPI.How:
examples/static_net/include/waveCell.h:WaveOf::procreads the source into a local first.u8: without it gcc 7.3 does them in 16 bits, andmixed_avr_sizegrows by 30 B.n, everysin −7..7, and everyp,mand input byte (3.0e9 cases, host).check/build.shpasses 65 ok. The only expectation that changed isbanknote_avr_check: 2344 B, was 2346.compare_emlearn/run.sh:wave4is 42 B, 24 cycles, 274/274 correct, was 44 B, 25 cycles.results.mdis regenerated and only that row changed.measure/'sbn_waveis unchanged at 23 cycles.tests/single_header/run.shpasses 36 ok.examples/static_net/README.md, including its ratios against emlearn.RnD/openDerivation/godbolt/README.mdmeasure/silicon_results.mdnow notes that its ELFs predate this change. The newwave4ELF has not been run on a chip.Not changed:
.RnD/openDerivation/round2has failed onmainsince #6 (5 ok, 32 FAIL): its:sources still usesnet::Slot. Its copy ofwaveCell.hand theFINDINGS.mdfigures are left as that round's record.🤖 Generated with Claude Code
https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
Generated by Claude Code