Skip to content

Commit 8fc4556

Browse files
committed
optimize decoding
1 parent 79bc2af commit 8fc4556

File tree

5 files changed

+283
-8
lines changed

5 files changed

+283
-8
lines changed

test/src/e2e_vm_tests/test_programs/should_pass/language/array/array_repeat/stdout.snap

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,238 @@ source: test/src/snapshot/mod.rs
33
---
44
> forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/array/array_repeat --experimental const_generics --ir final --asm final --bytecode | filter-fn array_repeat array_fn
55

6+
fn array_fn_should_use_mcli_small_u8_1(__ret_value: __ptr [u8; 5]) -> () {
7+
local [u8; 5] __anon_0
8+
9+
entry(__ret_value: __ptr [u8; 5]):
10+
v0 = get_local __ptr [u8; 5], __anon_0
11+
mem_clear_val v0
12+
mem_copy_val __ret_value, v0
13+
v1 = const unit ()
14+
ret () v1
15+
}
16+
17+
18+
fn array_fn_should_use_mcli_small_u16_2(__ret_value: __ptr [u64; 5]) -> () {
19+
local [u64; 5] __anon_0
20+
21+
entry(__ret_value: __ptr [u64; 5]):
22+
v0 = get_local __ptr [u64; 5], __anon_0
23+
mem_clear_val v0
24+
mem_copy_val __ret_value, v0
25+
v1 = const unit ()
26+
ret () v1
27+
}
28+
29+
30+
fn array_fn_should_use_mcli_small_u32_3(__ret_value: __ptr [u64; 5]) -> () {
31+
local [u64; 5] __anon_0
32+
33+
entry(__ret_value: __ptr [u64; 5]):
34+
v0 = get_local __ptr [u64; 5], __anon_0
35+
mem_clear_val v0
36+
mem_copy_val __ret_value, v0
37+
v1 = const unit ()
38+
ret () v1
39+
}
40+
41+
42+
fn array_fn_should_use_mcli_small_u64_4(__ret_value: __ptr [u64; 5]) -> () {
43+
local [u64; 5] __anon_0
44+
45+
entry(__ret_value: __ptr [u64; 5]):
46+
v0 = get_local __ptr [u64; 5], __anon_0
47+
mem_clear_val v0
48+
mem_copy_val __ret_value, v0
49+
v1 = const unit ()
50+
ret () v1
51+
}
52+
53+
54+
fn array_fn_should_use_mcli_small_u256_5(__ret_value: __ptr [u256; 5]) -> () {
55+
local [u256; 5] __anon_0
56+
57+
entry(__ret_value: __ptr [u256; 5]):
58+
v0 = get_local __ptr [u256; 5], __anon_0
59+
mem_clear_val v0
60+
mem_copy_val __ret_value, v0
61+
v1 = const unit ()
62+
ret () v1
63+
}
64+
65+
66+
fn array_fn_should_use_mcli_small_b256_6(__ret_value: __ptr [b256; 5]) -> () {
67+
local [b256; 5] __anon_0
68+
69+
entry(__ret_value: __ptr [b256; 5]):
70+
v0 = get_local __ptr [b256; 5], __anon_0
71+
mem_clear_val v0
72+
mem_copy_val __ret_value, v0
73+
v1 = const unit ()
74+
ret () v1
75+
}
76+
77+
78+
fn array_fn_should_use_mcli_small_bool_7(__ret_value: __ptr [bool; 5]) -> () {
79+
local [bool; 5] __anon_0
80+
81+
entry(__ret_value: __ptr [bool; 5]):
82+
v0 = get_local __ptr [bool; 5], __anon_0
83+
mem_clear_val v0
84+
mem_copy_val __ret_value, v0
85+
v1 = const unit ()
86+
ret () v1
87+
}
88+
89+
90+
fn array_fn_should_use_mcli_big_u8_8(__ret_value: __ptr [u8; 25]) -> () {
91+
local [u8; 25] __anon_0
92+
93+
entry(__ret_value: __ptr [u8; 25]):
94+
v0 = get_local __ptr [u8; 25], __anon_0
95+
mem_clear_val v0
96+
mem_copy_val __ret_value, v0
97+
v1 = const unit ()
98+
ret () v1
99+
}
100+
101+
102+
fn array_fn_should_use_mcli_big_u16_9(__ret_value: __ptr [u64; 25]) -> () {
103+
local [u64; 25] __anon_0
104+
105+
entry(__ret_value: __ptr [u64; 25]):
106+
v0 = get_local __ptr [u64; 25], __anon_0
107+
mem_clear_val v0
108+
mem_copy_val __ret_value, v0
109+
v1 = const unit ()
110+
ret () v1
111+
}
112+
113+
114+
fn array_fn_should_use_mcli_big_u32_10(__ret_value: __ptr [u64; 25]) -> () {
115+
local [u64; 25] __anon_0
116+
117+
entry(__ret_value: __ptr [u64; 25]):
118+
v0 = get_local __ptr [u64; 25], __anon_0
119+
mem_clear_val v0
120+
mem_copy_val __ret_value, v0
121+
v1 = const unit ()
122+
ret () v1
123+
}
124+
125+
126+
fn array_fn_should_use_mcli_big_u64_11(__ret_value: __ptr [u64; 25]) -> () {
127+
local [u64; 25] __anon_0
128+
129+
entry(__ret_value: __ptr [u64; 25]):
130+
v0 = get_local __ptr [u64; 25], __anon_0
131+
mem_clear_val v0
132+
mem_copy_val __ret_value, v0
133+
v1 = const unit ()
134+
ret () v1
135+
}
136+
137+
138+
fn array_fn_should_use_mcli_big_u256_12(__ret_value: __ptr [u256; 25]) -> () {
139+
local [u256; 25] __anon_0
140+
141+
entry(__ret_value: __ptr [u256; 25]):
142+
v0 = get_local __ptr [u256; 25], __anon_0
143+
mem_clear_val v0
144+
mem_copy_val __ret_value, v0
145+
v1 = const unit ()
146+
ret () v1
147+
}
148+
149+
150+
fn array_fn_should_use_mcli_big_b256_13(__ret_value: __ptr [b256; 25]) -> () {
151+
local [b256; 25] __anon_0
152+
153+
entry(__ret_value: __ptr [b256; 25]):
154+
v0 = get_local __ptr [b256; 25], __anon_0
155+
mem_clear_val v0
156+
mem_copy_val __ret_value, v0
157+
v1 = const unit ()
158+
ret () v1
159+
}
160+
161+
162+
fn array_fn_should_use_mcli_big_bool_14(__ret_value: __ptr [bool; 25]) -> () {
163+
local [bool; 25] __anon_0
164+
165+
entry(__ret_value: __ptr [bool; 25]):
166+
v0 = get_local __ptr [bool; 25], __anon_0
167+
mem_clear_val v0
168+
mem_copy_val __ret_value, v0
169+
v1 = const unit ()
170+
ret () v1
171+
}
172+
173+
174+
fn array_fn_should_store_each_item_bool_15(__ret_value: __ptr [bool; 5]) -> () {
175+
local [bool; 5] __anon_0
176+
177+
entry(__ret_value: __ptr [bool; 5]):
178+
v0 = get_local __ptr [bool; 5], __anon_0
179+
v1 = const u64 0
180+
v2 = get_elem_ptr v0, __ptr bool, v1
181+
v3 = const bool true
182+
store v3 to v2
183+
v4 = const u64 1
184+
v5 = get_elem_ptr v0, __ptr bool, v4
185+
store v3 to v5
186+
v6 = const u64 2
187+
v7 = get_elem_ptr v0, __ptr bool, v6
188+
store v3 to v7
189+
v8 = const u64 3
190+
v9 = get_elem_ptr v0, __ptr bool, v8
191+
store v3 to v9
192+
v10 = const u64 4
193+
v11 = get_elem_ptr v0, __ptr bool, v10
194+
store v3 to v11
195+
mem_copy_val __ret_value, v0
196+
v12 = const unit ()
197+
ret () v12
198+
}
199+
200+
201+
fn array_fn_should_loop_bool_16(__ret_value: __ptr [bool; 25]) -> () {
202+
local [bool; 25] __anon_0
203+
204+
entry(__ret_value: __ptr [bool; 25]):
205+
v0 = get_local __ptr [bool; 25], __anon_0
206+
v1 = const u64 0
207+
br array_init_loop(v1)
208+
209+
array_init_loop(v2: u64):
210+
v3 = get_elem_ptr v0, __ptr bool, v2
211+
v4 = const bool true
212+
store v4 to v3
213+
v5 = const u64 1
214+
v6 = add v2, v5
215+
v7 = const u64 25
216+
v8 = cmp lt v6 v7
217+
cbr v8, array_init_loop(v6), array_init_exit()
218+
219+
array_init_exit():
220+
mem_copy_val __ret_value, v0
221+
v9 = const unit ()
222+
ret () v9
223+
}
224+
225+
226+
fn array_fn_should_use_mcl_u8_17(__ret_value: __ptr [u8; 262145]) -> () {
227+
local [u8; 262145] __anon_0
228+
229+
entry(__ret_value: __ptr [u8; 262145]):
230+
v0 = get_local __ptr [u8; 262145], __anon_0
231+
mem_clear_val v0
232+
mem_copy_val __ret_value, v0
233+
v1 = const unit ()
234+
ret () v1
235+
}
236+
237+
6238
pshl i3 ; save registers 16..40
7239
pshh i524288 ; save registers 40..64
8240
move $$locbase $sp ; save locals base register for function array_fn_should_use_mcli_small_u8_1

test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,47 @@ The following snapshot should contain only one `abi_decode_in_place_0` function.
66

77
> forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode --release --ir final --asm final | filter-fn configurable_dedup_decode abi_decode_in_place
88

9+
pub fn abi_decode_in_place_0(ptr: ptr, len: u64, target: ptr) -> () {
10+
local { ptr } __anon_0
11+
local { u64 } __anon_00
12+
local mut { ptr } buffer
13+
local { u64 } temp
14+
15+
entry(ptr: ptr, len: u64, target: ptr):
16+
v0 = get_local __ptr { ptr }, __anon_0
17+
v1 = const u64 0
18+
v2 = get_elem_ptr v0, __ptr ptr, v1
19+
store ptr to v2
20+
v3 = get_local __ptr { ptr }, buffer
21+
mem_copy_val v3, v0
22+
v4 = get_local __ptr { ptr }, buffer
23+
v5 = const u64 0
24+
v6 = get_elem_ptr v4, __ptr ptr, v5
25+
v7 = load v6
26+
v8 = asm(ptr: v7, val) -> u64 val {
27+
lw val ptr i0
28+
}
29+
v9 = load v6
30+
v10 = const u64 8
31+
v11 = add v9, v10
32+
store v11 to v6
33+
v12 = get_local __ptr { u64 }, __anon_00
34+
v13 = const u64 0
35+
v14 = get_elem_ptr v12, __ptr u64, v13
36+
store v8 to v14
37+
v15 = get_local __ptr { u64 }, temp
38+
mem_copy_val v15, v12
39+
v16 = get_local __ptr { u64 }, temp
40+
v17 = cast_ptr v16 to ptr
41+
v18 = const u64 8
42+
v19 = asm(target: target, temp: v17, size: v18) -> () {
43+
mcp target temp size
44+
}
45+
v20 = const unit ()
46+
ret () v20
47+
}
48+
49+
950
pshl i31 ; save registers 16..40
1051
pshh i524288 ; save registers 40..64
1152
move $$locbase $sp ; save locals base register for function abi_decode_in_place_0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cmds = [
2-
"echo Because this test receives and returns an `u64`, we should not see any encoding/decoding whatsoever. Just loading from the `script_data` pointer directly, and simply returning a pointer to a local variable inside `__entry` stack frame.",
2+
"echo Because this test receives and returns an `u64`, we should see decoding loading from the `script_data` pointer directly, and encoding just returning a pointer to a local variable inside `__entry` stack frame.",
33
"forc build --path {root} --release --ir final --asm final --bytecode | filter-fn {name} __entry",
44
]

test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_one_u64/stdout.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
source: test/src/snapshot/mod.rs
33
---
4-
Because this test receives and returns an `u64`, we should not see any encoding/decoding
5-
whatsoever. Just loading from the `script_data` pointer directly, and simply returning
6-
a pointer to a local variable inside `__entry` stack frame.
4+
Because this test receives and returns an `u64`, we should see decoding loading
5+
from the `script_data` pointer directly, and encoding just returning a pointer to
6+
a local variable inside `__entry` stack frame.
77

88
> forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/main_args/main_args_one_u64 --release --ir final --asm final --bytecode | filter-fn main_args_one_u64 __entry
99

test/src/snapshot/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ pub(super) async fn run(filter_regex: Option<&regex::Regex>) -> Result<()> {
167167

168168
for m in ir.module_iter() {
169169
for f in m.function_iter(&ir) {
170-
if fns.contains(f.get_name(&ir)) {
171-
snapshot.push('\n');
172-
function_print(&mut snapshot, &ir, f, false).unwrap();
173-
snapshot.push('\n');
170+
for candidate in fns.iter() {
171+
if f.get_name(&ir).contains(candidate) {
172+
snapshot.push('\n');
173+
function_print(&mut snapshot, &ir, f, false).unwrap();
174+
snapshot.push('\n');
175+
}
174176
}
175177
}
176178
}

0 commit comments

Comments
 (0)