Improve binary folding

This commit is contained in:
2026-01-01 15:57:35 -07:00
parent e3a38ec110
commit 647c3d29d5
4 changed files with 73 additions and 11 deletions

View File

@@ -74,4 +74,20 @@ mod bitwise_tests {
let output = compile_with_and_without_optimization(source);
insta::assert_snapshot!(output);
}
#[test]
fn test_sorter_bitwise_operations() {
let source = indoc! {r#"
device self = "db";
device sorter = "d0";
loop {
yield();
// allow Hay with an op_code of `1`
sorter[0] = (hash("ItemCropHay") << 8) | 1;
}
"#};
let output = compile_with_and_without_optimization(source);
insta::assert_snapshot!(output);
}
}

View File

@@ -0,0 +1,20 @@
---
source: libs/integration_tests/src/bitwise_tests.rs
assertion_line: 91
expression: output
---
## Unoptimized Output
j main
main:
__internal_L1:
yield
put d0 0 55164456193
j __internal_L1
__internal_L2:
## Optimized Output
yield
put d0 0 55164456193
j 0

View File

@@ -7,19 +7,13 @@ expression: output
j main
main:
sll r1 -952768015 16
or r2 r1 2560
or r3 r2 50
move r8 r3
move r8 -62440604628430
put d0 255 r8
get r4 d0 255
move r9 r4
get r1 d0 255
move r9 r1
## Optimized Output
move r1 -62440604631040
move r2 -62440604628480
move r3 -62440604628430
move r8 -62440604628430
put d0 255 r8
get r9 d0 255