MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / regalloc_arithmetic_branches_and_loops

Function regalloc_arithmetic_branches_and_loops

tests/integration/regalloc.rs:89–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87
88#[test]
89fn regalloc_arithmetic_branches_and_loops() {
90 let ((base_lines, base_cycles), (alloc_lines, alloc_cycles)) = assert_equivalent(
91 r#"
92compute: (n: i64) -> i64 {
93 a: i64 = n + 1
94 b: i64 = a * 2
95 c: i64 = 0
96 if b > 10 {
97 c = b - a
98 } else {
99 c = a + b
100 }
101 d: i64 = c + a
102 return d
103}
104
105main: () -> i32 {
106 total: i64 = 0
107 i: i64 = 0
108 while i < 50 {
109 total = total + compute(i)
110 i = i + 1
111 }
112 return (total % 256) as i32
113}
114"#,
115 );
116 assert!(
117 alloc_lines < base_lines,
118 "register allocation should remove slot traffic: {base_lines} -> {alloc_lines}"
119 );
120 assert!(
121 alloc_cycles < base_cycles,
122 "register allocation should reduce executed cycles: {base_cycles} -> {alloc_cycles}"
123 );
124}
125
126#[test]
127fn regalloc_hot_loop_is_substantially_faster() {

Callers

nothing calls this directly

Calls 1

assert_equivalentFunction · 0.85

Tested by

no test coverage detected