-
Notifications
You must be signed in to change notification settings - Fork 0
spec: BITWISE chip
#138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
spec: BITWISE chip
#138
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a2413e5
spec: introduce BITWISE
erik-3milabs ee0385e
Merge branch 'spec/main' into spec/BITWISE
erik-3milabs 99b2abf
spec: BITWISE: outline optimizations
erik-3milabs 44f6366
spec: BITWISE: fix SLL naming mismatch
erik-3milabs 6c1e775
spec: BITWISE: fix length computation mistake
erik-3milabs 769fc5e
spec: drop `dot` in `expr_to_code` when multiplying constant with sin…
erik-3milabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #import "/book.typ": book-page, rj | ||
| #import "/src.typ": load_config, load_chip | ||
| #import "/chip.typ": ( | ||
| render_chip_assumptions, | ||
| render_chip_column_table, | ||
| total_nr_variables, | ||
| total_nr_instantiated_columns, | ||
| render_constraint_table, | ||
| ) | ||
|
|
||
| #let config = load_config() | ||
| #let chip = load_chip("src/bitwise.toml", config) | ||
|
|
||
| #let bitwise = raw(chip.name) | ||
|
|
||
| #show: book-page.with(title: "BRANCH chip") | ||
|
|
||
| = #bitwise chip | ||
|
|
||
| == Columns | ||
| #let nr_variables = total_nr_variables(chip) | ||
| #let nr_columns = total_nr_instantiated_columns(chip, config) | ||
| #let nr_precomputed = ("input", "output").map(c => chip.variables.at(c)).flatten().len() | ||
|
|
||
| The #bitwise chip is comprised of #nr_variables variables that are expressed using #nr_columns columns. | ||
| Of these, the _input_ and _output_ variables (#nr_precomputed in total) are precomputed. | ||
| #render_chip_column_table(chip, config) | ||
|
|
||
| *Note*: This table contains one row for every possible value of `(X, Y, Z)`. | ||
| As such, it has length $2^8 dot 2^8 dot 2^4 = 2^(20)$. | ||
|
|
||
| == Lookup | ||
| This chip adds the following interactions to the lookup: | ||
| #render_constraint_table(chip, config) | ||
|
|
||
| == Areas of Optimization | ||
| The following ideas may prove to be optimizations for the #bitwise chip: | ||
| + Extend `IS_BYTE[X]` to `ARE_BYTES[X, Y]`, such that two bytes are range checked at once. | ||
| When only a single check is required, one can still execute `IS_BYTE[X] := ARE_BYTES[X, 0]`. | ||
| + Drop `MSB8` column, and instead define the `MSB8` lookup as `MSB8<X> := MSB16[256X]`. | ||
| Note: currently, `MSB8` also implicity range checks the input `X` (the lookup fails if `X` is not a `Byte`). | ||
| This optimization should only be executed when all chips leveraging `MSB8` do _not_ need this implicit range check. | ||
| + Place the 16-bit (`AND`, `OR`, `XOR`, `MSB16`, `ZERO`, etc.) and 20-bit (`HWSL`, `HWSLC`, `IS_B20`) lookups in separate tables. | ||
| + Combine `HWSL` and `HWSLC` into a single lookup (see also \#119). |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| name = "BITWISE" | ||
|
|
||
| [[variables.input]] | ||
| name = "X" | ||
| type = "Byte" | ||
| desc = "" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.input]] | ||
| name = "Y" | ||
| type = "Byte" | ||
| desc = "" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.input]] | ||
| name = "Z" | ||
| type = "B4" | ||
| desc = "" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "AND" | ||
| type = "Byte" | ||
| desc = "the binary AND of `X` and `Y`" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "OR" | ||
| type = "Byte" | ||
| desc = "the binary OR of `X` and `Y`" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "XOR" | ||
| type = "Byte" | ||
| desc = "the binary XOR of `X` and `Y`" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "MSB8" | ||
| type = "Bit" | ||
| desc = "the most significant bit of `X`" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "MSB16" | ||
| type = "Bit" | ||
| desc = "the most significant bit of `Y`" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "ZERO" | ||
| type = "Bit" | ||
| desc = "whether $#`X` = 0 and #`Y` = 0$" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "SLL" | ||
| type = "Half" | ||
| desc = "`X||Y` logically left-shifted by `Z`: $((#`X` + 256#`Y`) #`<<` #`Z`) mod 2^16$" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.output]] | ||
| name = "SLLC" | ||
| type = "Half" | ||
| desc = "`X||Y` logically right-shifted by `Z`: $(#`X` + 256#`Y`) #`>>` (16 - #`Z`)$" | ||
| precomputed = "true" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_AND" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_OR" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_XOR" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_MSB8" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_MSB16" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_ZERO" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_IS_BYTE" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_IS_HALF" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_IS_B20" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_HWSL" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
| [[variables.multiplicity]] | ||
| name = "μ_HWSLC" | ||
| type = "BaseField" | ||
| desc = "" | ||
|
|
||
|
|
||
| [[constraint_groups]] | ||
| name = "contributions" | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "AND_BYTE" | ||
| input = ["X", "Y"] | ||
| output = "AND" | ||
| multiplicity = ["-", "μ_AND"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "OR_BYTE" | ||
| input = ["X", "Y"] | ||
| output = "OR" | ||
| multiplicity = ["-", "μ_OR"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "XOR_BYTE" | ||
| input = ["X", "Y"] | ||
| output = "XOR" | ||
| multiplicity = ["-", "μ_XOR"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "MSB8" | ||
| input = ["X"] | ||
| output = "MSB8" | ||
| multiplicity = ["-", "μ_MSB8"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "MSB16" | ||
| input = [["+", "X", ["*", 256, "Y"]]] | ||
| output = "MSB16" | ||
| multiplicity = ["-", "μ_MSB16"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "ZERO" | ||
| input = [["+", "X", ["*", 256, "Y"]]] | ||
| output = "ZERO" | ||
| multiplicity = ["-", "μ_ZERO"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "IS_BYTE" | ||
| input = ["X"] | ||
| multiplicity = ["-", "μ_IS_BYTE"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "IS_HALF" | ||
| input = [["+", "X", ["*", 256, "Y"]]] | ||
| multiplicity = ["-", "μ_IS_HALF"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "IS_B20" | ||
| input = [["+", "X", ["*", 256, "Y"], ["*", 65536, "Z"]]] | ||
| multiplicity = ["-", "μ_IS_B20"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "HWSL" | ||
| input = [["+", "X", ["*", 256, "Y"]], "Z"] | ||
| output = "SLL" | ||
| multiplicity = ["-", "μ_HWSL"] | ||
|
|
||
| [[constraints.contributions]] | ||
| kind = "interaction" | ||
| tag = "HWSLC" | ||
| input = [["+", "X", ["*", 256, "Y"]], "Z"] | ||
| output = "SLLC" | ||
| multiplicity = ["-", "μ_HWSLC"] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.