-
Notifications
You must be signed in to change notification settings - Fork 123
feat: support fixed-width Nat types as array and blob indices #5929
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
Open
q-uint
wants to merge
13
commits into
caffeinelabs:master
Choose a base branch
from
q-uint:quint/nat64-array-indexing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dc74761
feat: support native Nat64 array indexing
q-uint d489db5
fix: scope Nat64 index dispatch to array branch in surface interpreter
q-uint d631d4c
refactor: extract check_array_idx_typ helper in check_ir.ml
q-uint 7dd01f4
feat: support all fixed-width Nat types as array and blob indices
q-uint b90e782
refactor: deduplicate index helpers, add trap tests, extend bench
q-uint afb1546
fix: update M0245 comment to reflect all fixed-width Nat index types
q-uint 4299689
perf: inline scalar fast path for plain Nat array/blob indexing
q-uint 68fc428
Merge branch 'master' into quint/nat64-array-indexing
Kamirus ec5bc44
fix: add missing tc-human ok files for nat64-index fail test
q-uint 2d707d6
fix: update gc-random-test ok files for new M0155 index warning
q-uint 54786d8
perf: elide NatN.toNat() conversion in array/blob index position
q-uint c6f05a8
refactor: remove type system changes, keep codegen peephole only
q-uint d15bf9f
refactor: replace inline scalar fast path with toNat peephole
q-uint 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
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,164 @@ | ||
| // Benchmark: NatN.toNat() peephole vs plain Nat array indexing | ||
|
q-uint marked this conversation as resolved.
|
||
| //MOC-FLAG --package core $MOTOKO_CORE | ||
| import Nat64 "mo:core/Nat64"; | ||
| import Nat32 "mo:core/Nat32"; | ||
| import { | ||
| performanceCounter; | ||
| debugPrint; | ||
| rts_heap_size; | ||
| Array_init; | ||
| natToNat32; | ||
| natToNat64; | ||
| nat32ToNat; | ||
| nat64ToNat; | ||
| } = "mo:⛔"; | ||
|
|
||
| persistent actor NatXIndex { | ||
|
|
||
| transient let arrSize = 256; | ||
| transient let arr : [var Nat64] = Array_init<Nat64>(arrSize, 0); | ||
|
|
||
| func counters() : (Int, Nat64) = (rts_heap_size(), performanceCounter(0)); | ||
|
|
||
| public func setup() : async () { | ||
| var k = 0; | ||
| while (k < arrSize) { | ||
| arr[k] := natToNat64(k * 0x12345); | ||
| k += 1; | ||
| }; | ||
| }; | ||
|
|
||
| // Baseline: Nat loop counter, Nat index | ||
| public func natIndex() : async () { | ||
| let (m0, n0) = counters(); | ||
| var outer = 0; | ||
| while (outer < 1000) { | ||
| var acc : Nat64 = 0; | ||
| var n = 0; | ||
| while (n < arrSize) { | ||
| acc +%= arr[n]; | ||
| n += 1; | ||
| }; | ||
| outer += 1; | ||
| }; | ||
| let (m1, n1) = counters(); | ||
| debugPrint("nat_index: " # debug_show (m1 - m0, n1 - n0)); | ||
| }; | ||
|
|
||
| // Prim: nat32ToNat() | ||
| public func nat32PrimIndex() : async () { | ||
| let (m0, n0) = counters(); | ||
| let arrSize32 : Nat32 = natToNat32(arrSize); | ||
| var outer = 0; | ||
| while (outer < 1000) { | ||
| var acc : Nat64 = 0; | ||
| var n : Nat32 = 0; | ||
| while (n < arrSize32) { | ||
| acc +%= arr[nat32ToNat(n)]; | ||
| n +%= 1; | ||
| }; | ||
| outer += 1; | ||
| }; | ||
| let (m1, n1) = counters(); | ||
| debugPrint("nat32_prim_index: " # debug_show (m1 - m0, n1 - n0)); | ||
| }; | ||
|
|
||
| // Core lib: Nat32.toNat() | ||
| public func nat32CoreIndex() : async () { | ||
| let (m0, n0) = counters(); | ||
| let arrSize32 : Nat32 = natToNat32(arrSize); | ||
| var outer = 0; | ||
| while (outer < 1000) { | ||
| var acc : Nat64 = 0; | ||
| var n : Nat32 = 0; | ||
| while (n < arrSize32) { | ||
| acc +%= arr[Nat32.toNat(n)]; | ||
| n +%= 1; | ||
| }; | ||
| outer += 1; | ||
| }; | ||
| let (m1, n1) = counters(); | ||
| debugPrint("nat32_core_index: " # debug_show (m1 - m0, n1 - n0)); | ||
| }; | ||
|
|
||
| // Method: n.toNat() | ||
| public func nat32MethodIndex() : async () { | ||
| let (m0, n0) = counters(); | ||
| let arrSize32 : Nat32 = natToNat32(arrSize); | ||
| var outer = 0; | ||
| while (outer < 1000) { | ||
| var acc : Nat64 = 0; | ||
| var n : Nat32 = 0; | ||
| while (n < arrSize32) { | ||
| acc +%= arr[n.toNat()]; | ||
| n +%= 1; | ||
| }; | ||
| outer += 1; | ||
| }; | ||
| let (m1, n1) = counters(); | ||
| debugPrint("nat32_method_index: " # debug_show (m1 - m0, n1 - n0)); | ||
| }; | ||
|
|
||
| // Prim: nat64ToNat() | ||
| public func nat64PrimIndex() : async () { | ||
| let (m0, n0) = counters(); | ||
| let arrSize64 : Nat64 = natToNat64(arrSize); | ||
| var outer = 0; | ||
| while (outer < 1000) { | ||
| var acc : Nat64 = 0; | ||
| var n : Nat64 = 0; | ||
| while (n < arrSize64) { | ||
| acc +%= arr[nat64ToNat(n)]; | ||
| n += 1; | ||
| }; | ||
| outer += 1; | ||
| }; | ||
| let (m1, n1) = counters(); | ||
| debugPrint("nat64_prim_index: " # debug_show (m1 - m0, n1 - n0)); | ||
| }; | ||
|
|
||
| // Core lib: Nat64.toNat() | ||
| public func nat64CoreIndex() : async () { | ||
| let (m0, n0) = counters(); | ||
| let arrSize64 : Nat64 = natToNat64(arrSize); | ||
| var outer = 0; | ||
| while (outer < 1000) { | ||
| var acc : Nat64 = 0; | ||
| var n : Nat64 = 0; | ||
| while (n < arrSize64) { | ||
| acc +%= arr[Nat64.toNat(n)]; | ||
| n += 1; | ||
| }; | ||
| outer += 1; | ||
| }; | ||
| let (m1, n1) = counters(); | ||
| debugPrint("nat64_core_index: " # debug_show (m1 - m0, n1 - n0)); | ||
| }; | ||
|
|
||
| // Method: n.toNat() | ||
| public func nat64MethodIndex() : async () { | ||
| let (m0, n0) = counters(); | ||
| let arrSize64 : Nat64 = natToNat64(arrSize); | ||
| var outer = 0; | ||
| while (outer < 1000) { | ||
| var acc : Nat64 = 0; | ||
| var n : Nat64 = 0; | ||
| while (n < arrSize64) { | ||
| acc +%= arr[n.toNat()]; | ||
| n += 1; | ||
| }; | ||
| outer += 1; | ||
| }; | ||
| let (m1, n1) = counters(); | ||
| debugPrint("nat64_method_index: " # debug_show (m1 - m0, n1 - n0)); | ||
| }; | ||
| }; | ||
|
|
||
| //CALL ingress setup 0x4449444C0000 | ||
| //CALL ingress natIndex 0x4449444C0000 | ||
| //CALL ingress nat32PrimIndex 0x4449444C0000 | ||
| //CALL ingress nat32CoreIndex 0x4449444C0000 | ||
| //CALL ingress nat32MethodIndex 0x4449444C0000 | ||
| //CALL ingress nat64PrimIndex 0x4449444C0000 | ||
| //CALL ingress nat64CoreIndex 0x4449444C0000 | ||
| //CALL ingress nat64MethodIndex 0x4449444C0000 | ||
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,17 @@ | ||
| ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101 | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| debug.print: nat_index: (0, 25_687_306) | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| debug.print: nat32_prim_index: (0, 10_567_324) | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| debug.print: nat32_core_index: (0, 10_567_324) | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| debug.print: nat32_method_index: (0, 10_567_324) | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| debug.print: nat64_prim_index: (0, 17_991_325) | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| debug.print: nat64_core_index: (0, 17_991_325) | ||
| ingress Completed: Reply: 0x4449444c0000 | ||
| debug.print: nat64_method_index: (0, 17_991_325) | ||
| ingress Completed: Reply: 0x4449444c0000 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess one could even iterate this for deeper projection paths, but probably not worth it.