Repository navigation
RnD openDerivation/godbolt: compare the HAPI wave4 cell with the same cell in plain C - #9
Merged
Merged
Conversation
… cell in plain C The Compiler Explorer demo compared the hand-written APIOf cell with the Open Derivation translation of it, the same program, so its empty diff showed only that the translator is faithful. wave4_c.c writes the cell in plain C as the comparator. verify.sh now compiles it as C++ and C, lists the instructions that differ from the HAPI cell (one register copy: 28 vs 27 instructions, 56 vs 54 B) and checks both give the same answer on all 2^32 inputs. The README shows the two listings side by side, explains the difference and links both sources on Compiler Explorer. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
…ove the extra mov Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
… with no HAPI Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
…e extra mov Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
…he input through Src::get Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
…he mov on gcc 7.3, and gcc 16.1's result 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: the Compiler Explorer demo in
.RnD/openDerivation/godboltcompared the hand-writtenhapi::APIOfcell with the Open Derivation translation of it. Those are the same program, so the empty diff (https://godbolt.org/z/TvM334frd) only showed that the translator is faithful.After: the demo compares the HAPI cell with the same trained cell written by hand in plain C,
bool wave4(const uint8_t* x)inwave4_c.c. The README shows both listings side by side. On AVR gcc 7.3.0 (-std=c++17 -Os -mmcu=atmega328p) HAPI is 28 instructions / 56 B and plain C 27 / 54 B. The only difference is one register copy (ldd r25,Z+3; mov r24,r25).The README explains where that
movcomes from: gcc 7.3 narrows(x >> k) & mto an 8-bit shift only when it sees the byte as a variable. In the HAPI cell the byte arrives as a call,Src::get(in). Plain C++ that reads through an accessor hits the samemov. It is not HAPI's composition and not the:translation. Moving the input into static data on the terminal does not help: that comes to 30 instructions. AVR gcc 16.1 on Compiler Explorer compiles both to the same 24 instructions.The README also records a
WaveOf::procspelling (bind the source to a local, no casts between shift and mask) that makes the HAPI cell byte-identical towave4_c.con 7.3. It is not applied here, because it changesexamples/static_net/include/waveCell.hand static_net's measured figures. That change goes in a separate PR.How:
wave4_c.c(new): the plain C cell. It compiles as C and as C++ to the same code.verify.sh:wave4_c.cas C++ and as Cwave4_c.cgive the same class on all 2^32 inputs (host g++)verify.log)README.md(godbolt) and thegodbolt/row in.RnD/openDerivation/README.mdare updated.The Compiler Explorer link in the README is still a long
/clientstate/link that has not been opened: godbolt.org is unreachable from the session that wrote it. Draft until it is replaced by short links for the 7.3.0 and 16.1 comparisons.🤖 Generated with Claude Code
https://claude.ai/code/session_01PttWicEZBc92PTtygV18zb
Generated by Claude Code