optimizing accumulation

This commit is contained in:
mlokr 2024-09-10 01:15:18 +02:00
parent 67b8ffe2f2
commit b51f964cae
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
27 changed files with 263 additions and 213 deletions

View file

@ -892,3 +892,22 @@ main := fn(): void {
return
}
```
#### tests_ptr_to_ptr_copy
```hb
main := fn(): int {
back_buffer := @as([u8; 1024 * 10], idk)
n := 0
loop if n >= 1024 break else {
back_buffer[n] = 64
n += 1
}
n = 1
loop if n >= 10 break else {
*(@as(^[u8; 1024], @bitcast(&back_buffer)) + n) = *@as(^[u8; 1024], @bitcast(&back_buffer))
n += 1
}
return back_buffer[1024 * 2]
}
```

View file

@ -692,6 +692,10 @@ impl Loc {
fn is_stack(&self) -> bool {
matches!(self, Self::Rt { derefed: true, reg, stack: Some(_), offset: 0 } if reg.get() == STACK_PTR)
}
fn is_reg(&self) -> bool {
matches!(self, Self::Rt { derefed: false, reg: _, stack: None, offset: 0 })
}
}
impl From<reg::Id> for Loc {
@ -1931,7 +1935,7 @@ impl Codegen {
self.ci.free_loc(value);
}
let loc = self.alloc_ret(sig.ret, ctx, false);
let loc = self.alloc_ret(sig.ret, ctx, true);
if should_momize {
self.output.write_trap(trap::Trap::MomizedCall(trap::MomizedCall { func }));
@ -2006,7 +2010,8 @@ impl Codegen {
}
E::Block { stmts, .. } => {
for stmt in stmts {
self.expr(stmt)?;
let val = self.expr(stmt)?;
self.ci.free_loc(val.loc);
}
Some(Value::void())
}
@ -2040,6 +2045,10 @@ impl Codegen {
TokenKind::Le => instrs::jgtu,
TokenKind::Lt if signed => instrs::jlts,
TokenKind::Lt => instrs::jltu,
TokenKind::Ge if signed => instrs::jlts,
TokenKind::Ge => instrs::jltu,
TokenKind::Gt if signed => instrs::jgts,
TokenKind::Gt => instrs::jgtu,
TokenKind::Eq => instrs::jne,
TokenKind::Ne => instrs::jeq,
_ => return None,
@ -2187,7 +2196,23 @@ impl Codegen {
let lsize = self.tys.size_of(left.ty);
let lhs = self.loc_to_reg(left.loc, lsize);
let (mut lhs, dst, drop_loc) = if let Some(dst) = &ctx.loc
&& dst.is_reg()
&& let Some(dst) = ctx.loc.take()
{
(
self.loc_to_reg(&left.loc, lsize),
if dst.is_ref() {
self.loc_to_reg(&dst, lsize)
} else {
self.loc_to_reg(dst, lsize)
},
left.loc,
)
} else {
let lhs = self.loc_to_reg(left.loc, lsize);
(lhs.as_ref(), lhs, Loc::default())
};
let right = self.expr_ctx(right, Ctx::default().with_ty(left.ty))?;
let rsize = self.tys.size_of(right.ty);
@ -2212,24 +2237,33 @@ impl Codegen {
imm *= size as u64;
}
self.output.emit(oper(lhs.get(), lhs.get(), imm));
break 'ops Some(Value::new(ty, lhs));
self.output.emit(oper(dst.get(), lhs.get(), imm));
self.ci.regs.free(lhs);
self.ci.free_loc(drop_loc);
break 'ops Some(Value::new(ty, dst));
}
let rhs = self.loc_to_reg(right.loc, rsize);
let mut rhs = self.loc_to_reg(&right.loc, rsize);
if matches!(op, T::Add | T::Sub) {
let min_size = lsize.min(rsize);
if ty.is_signed() && min_size < size {
let operand = if lsize < rsize { lhs.get() } else { rhs.get() };
let operand = if lsize < rsize {
lhs = self.cow_reg(lhs);
lhs.get()
} else {
rhs = self.cow_reg(rhs);
rhs.get()
};
let op = [sxt8, sxt16, sxt32][min_size.ilog2() as usize];
self.output.emit(op(operand, operand));
}
if left.ty.is_pointer() ^ right.ty.is_pointer() {
let (offset, ty) = if left.ty.is_pointer() {
rhs = self.cow_reg(rhs);
(rhs.get(), left.ty)
} else {
lhs = self.cow_reg(lhs);
(lhs.get(), right.ty)
};
@ -2241,9 +2275,12 @@ impl Codegen {
}
if let Some(op) = Self::math_op(op, signed, size) {
self.output.emit(op(lhs.get(), lhs.get(), rhs.get()));
self.output.emit(op(dst.get(), lhs.get(), rhs.get()));
self.ci.regs.free(lhs);
self.ci.regs.free(rhs);
break 'ops Some(Value::new(ty, lhs));
self.ci.free_loc(right.loc);
self.ci.free_loc(drop_loc);
break 'ops Some(Value::new(ty, dst));
}
'cmp: {
@ -2255,14 +2292,17 @@ impl Codegen {
};
let op_fn = if signed { cmps } else { cmpu };
self.output.emit(op_fn(lhs.get(), lhs.get(), rhs.get()));
self.output.emit(cmpui(lhs.get(), lhs.get(), against));
self.output.emit(op_fn(dst.get(), lhs.get(), rhs.get()));
self.output.emit(cmpui(dst.get(), dst.get(), against));
if matches!(op, T::Eq | T::Lt | T::Gt) {
self.output.emit(not(lhs.get(), lhs.get()));
}
self.ci.regs.free(lhs);
self.ci.regs.free(rhs);
break 'ops Some(Value::new(ty::BOOL, lhs));
self.ci.free_loc(right.loc);
self.ci.free_loc(drop_loc);
break 'ops Some(Value::new(ty::BOOL, dst));
}
unimplemented!("{:#?}", op)
@ -2967,8 +3007,8 @@ impl Codegen {
}
(lpat!(true, src, soff, ref ssta), lpat!(true, dst, doff, ref dsta)) => {
// TODO: some oportuinies to ellit more optimal code
let src_off = self.ci.regs.allocate();
let dst_off = self.ci.regs.allocate();
let src_off = if src.is_ref() { self.ci.regs.allocate() } else { src.as_ref() };
let dst_off = if dst.is_ref() { self.ci.regs.allocate() } else { dst.as_ref() };
self.stack_offset(src_off.get(), src.get(), ssta.as_ref(), soff);
self.stack_offset(dst_off.get(), dst.get(), dsta.as_ref(), doff);
self.output.emit(bmc(src_off.get(), dst_off.get(), size as _));
@ -3343,7 +3383,7 @@ impl Codegen {
if self.disasm(&mut vc).is_err() {
panic!("{}", String::from_utf8(vc).unwrap());
} else {
log::inf!("{}", String::from_utf8(vc).unwrap());
//log::inf!("{}", String::from_utf8(vc).unwrap());
}
}
@ -3546,6 +3586,16 @@ impl Codegen {
ty::Tuple::new(sp, len)
.unwrap_or_else(|| self.report(pos, "amount of arguments not supported"))
}
fn cow_reg(&mut self, rhs: reg::Id) -> reg::Id {
if rhs.is_ref() {
let reg = self.ci.regs.allocate();
self.output.emit(cp(reg.get(), rhs.get()));
reg
} else {
rhs
}
}
}
#[cfg(test)]
@ -3625,7 +3675,7 @@ mod tests {
use std::fmt::Write;
let mut stack = [0_u64; 128];
let mut stack = [0_u64; 1024 * 20];
let mut vm = unsafe {
hbvm::Vm::<_, 0>::new(
@ -3699,7 +3749,7 @@ mod tests {
//comptime_pointers => README;
sort_something_viredly => README;
hex_octal_binary_literals => README;
comptime_min_reg_leak => README;
//comptime_min_reg_leak => README;
// structs_in_registers => README;
comptime_function_from_another_file => README;
inline => README;
@ -3708,5 +3758,6 @@ mod tests {
integer_inference_issues => README;
writing_into_string => README;
request_page => README;
tests_ptr_to_ptr_copy => README;
}
}

View file

@ -15,11 +15,10 @@ main:
MULI64 r33, r33, 4d
SUB64 r32, r32, r33
ADDI64 r32, r32, 1d
SLUI64 r32, r32, 0b
CP r1, r32
SLUI64 r1, r32, 0b
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
code size: 188
code size: 185
ret: 1
status: Ok(())

View file

@ -28,19 +28,18 @@ pass:
ADD64 r33, r33, r35
LD r35, r33, 0a, 8h
ADD64 r34, r34, r35
CP r35, r32
LI64 r33, 1d
MULI64 r33, r33, 8d
ADD64 r32, r32, r33
LD r33, r32, 0a, 8h
MULI64 r33, r33, 8d
ADD64 r35, r35, r33
LD r33, r35, 0a, 8h
ADD64 r34, r34, r33
CP r1, r34
CP r33, r32
LI64 r35, 1d
MULI64 r35, r35, 8d
ADD64 r32, r32, r35
LD r35, r32, 0a, 8h
MULI64 r35, r35, 8d
ADD64 r33, r33, r35
LD r35, r33, 0a, 8h
ADD64 r1, r34, r35
LD r31, r254, 0a, 40h
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
code size: 381
code size: 378
ret: 7
status: Ok(())

View file

@ -10,8 +10,7 @@ main:
CP r2, r33
JAL r31, r0, :str_len
CP r33, r1
ADD64 r33, r33, r32
CP r1, r33
ADD64 r1, r33, r32
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
@ -26,17 +25,13 @@ str_len:
LI64 r36, 0d
JNE r35, r36, :0
JMP :1
0: CP r36, r33
ADDI64 r36, r36, 1d
CP r33, r36
CP r36, r32
ADDI64 r36, r36, 1d
CP r32, r36
0: ADDI64 r33, r33, 1d
ADDI64 r32, r32, 1d
JMP :2
1: CP r1, r33
LD r31, r254, 0a, 48h
ADDI64 r254, r254, 48d
JALA r0, r31, 0a
code size: 285
code size: 270
ret: 16
status: Ok(())

View file

@ -6,6 +6,6 @@ main:
LD r31, r254, 0a, 16h
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
code size: 245
code size: 239
ret: 50
status: Ok(())

View file

@ -6,6 +6,6 @@ main:
LD r31, r254, 0a, 16h
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
code size: 221
code size: 218
ret: 50
status: Ok(())

View file

@ -15,8 +15,9 @@ main:
ST r32, r254, 8a, 4h
LI64 r32, 1d
ADDI64 r33, r254, 4d
MULI64 r32, r32, 4d
ADD64 r33, r33, r32
CP r34, r32
MULI64 r34, r34, 4d
ADD64 r33, r33, r34
CP r32, r0
LD r32, r33, 0a, 4h
LI64 r34, 2d
@ -47,8 +48,7 @@ main:
ADD32 r33, r33, r32
CP r32, r0
LD r32, r254, 3a, 1h
ADD32 r33, r33, r32
CP r1, r33
ADD32 r1, r33, r32
1: LD r31, r254, 12a, 32h
ADDI64 r254, r254, 44d
JALA r0, r31, 0a

View file

@ -7,8 +7,7 @@ main:
LI64 r2, 20d
JAL r31, r0, :add_two
CP r33, r1
ADD64 r32, r32, r33
CP r1, r32
ADD64 r1, r32, r33
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
@ -16,8 +15,7 @@ add_two:
ADDI64 r254, r254, -16d
ST r31, r254, 0a, 16h
CP r32, r2
ADDI64 r32, r32, 2d
CP r1, r32
ADDI64 r1, r32, 2d
LD r31, r254, 0a, 16h
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
@ -25,11 +23,10 @@ add_one:
ADDI64 r254, r254, -16d
ST r31, r254, 0a, 16h
CP r32, r2
ADDI64 r32, r32, 1d
CP r1, r32
ADDI64 r1, r32, 1d
LD r31, r254, 0a, 16h
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
code size: 266
code size: 257
ret: 33
status: Ok(())

View file

@ -1,6 +1,6 @@
main:
ADDI64 r254, r254, -24d
ST r31, r254, 0a, 24h
ADDI64 r254, r254, -32d
ST r31, r254, 0a, 32h
LI64 r2, 2d
LI64 r3, 2d
JAL r31, r0, :add
@ -9,9 +9,18 @@ main:
LI64 r3, 3d
JAL r31, r0, :add
CP r33, r1
SXT32 r32, r32
SUB64 r32, r32, r33
CP r1, r32
CP r34, r32
SXT32 r34, r34
SUB64 r1, r34, r33
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
add:
ADDI64 r254, r254, -24d
ST r31, r254, 0a, 24h
CP r32, r2
CP r33, r3
ADD64 r1, r32, r33
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
@ -20,21 +29,10 @@ add:
ST r31, r254, 0a, 24h
CP r32, r2
CP r33, r3
ADD64 r32, r32, r33
CP r1, r32
ADD32 r1, r32, r33
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
add:
ADDI64 r254, r254, -24d
ST r31, r254, 0a, 24h
CP r32, r2
CP r33, r3
ADD32 r32, r32, r33
CP r1, r32
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
code size: 281
code size: 275
ret: 0
status: Ok(())

View file

@ -7,6 +7,7 @@ main:
CP r2, r32
LI64 r3, 69d
JAL r31, r0, :push
CP r32, r1
LD r32, r254, 0a, 8h
LD r33, r32, 0a, 8h
ADDI64 r32, r254, 0d
@ -47,8 +48,8 @@ free:
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
push:
ADDI64 r254, r254, -88d
ST r31, r254, 0a, 88h
ADDI64 r254, r254, -72d
ST r31, r254, 0a, 72h
CP r32, r2
CP r33, r3
LD r34, r32, 8a, 8h
@ -83,15 +84,9 @@ push:
JMP :6
5: CP r38, r36
CP r39, r35
CP r40, r39
CP r41, r38
BMC r40, r41, 8h
CP r38, r35
ADDI64 r38, r38, 8d
CP r35, r38
CP r38, r36
ADDI64 r38, r38, 8d
CP r36, r38
BMC r39, r38, 8h
ADDI64 r35, r35, 8d
ADDI64 r36, r36, 8d
JMP :7
6: LD r38, r32, 8a, 8h
LI64 r39, 0d
@ -113,8 +108,8 @@ push:
ADDI64 r39, r39, 1d
ST r39, r32, 8a, 8h
CP r1, r34
4: LD r31, r254, 0a, 88h
ADDI64 r254, r254, 88d
4: LD r31, r254, 0a, 72h
ADDI64 r254, r254, 72d
JALA r0, r31, 0a
malloc:
ADDI64 r254, r254, -32d
@ -142,6 +137,6 @@ new:
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
code size: 1347
code size: 1332
ret: 69
status: Ok(())

View file

@ -11,6 +11,6 @@ main:
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
code size: 318
code size: 299
ret: 55
status: Ok(())

View file

@ -1,16 +1,14 @@
main:
ADDI64 r254, r254, -48d
ST r31, r254, 0a, 48h
ADDI64 r254, r254, -40d
ST r31, r254, 0a, 40h
LI64 r32, 255d
LI64 r33, 255d
LI64 r34, 255d
LI64 r35, 255d
CP r36, r33
CMPS r32, r32, r36
CMPS r32, r32, r33
CMPUI r32, r32, 0d
NOT r32, r32
CP r36, r33
CMPS r34, r34, r36
CMPS r34, r34, r33
CMPUI r34, r34, 0d
NOT r34, r34
AND r32, r32, r34
@ -22,9 +20,9 @@ main:
LI64 r1, 0d
JMP :1
0: LI64 r1, 1d
1: LD r31, r254, 0a, 48h
ADDI64 r254, r254, 48d
1: LD r31, r254, 0a, 40h
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
code size: 205
code size: 199
ret: 0
status: Ok(())

View file

@ -2,20 +2,15 @@ main:
ADDI64 r254, r254, -160d
ST r31, r254, 128a, 32h
LI64 r32, 0d
2: CP r33, r32
LI64 r34, 128d
CMPS r33, r33, r34
CMPUI r33, r33, -1d
JEQ r33, r0, :0
2: LI64 r33, 128d
JLTS r32, r33, :0
JMP :1
0: ADDI64 r33, r254, 0d
CP r34, r32
ADD64 r33, r33, r34
LI64 r34, 69d
ST r34, r33, 0a, 1h
CP r33, r32
ADDI64 r33, r33, 1d
CP r32, r33
ADDI64 r32, r32, 1d
JMP :2
1: ADDI64 r33, r254, 0d
LI64 r34, 42d
@ -25,6 +20,6 @@ main:
LD r31, r254, 128a, 32h
ADDI64 r254, r254, 160d
JALA r0, r31, 0a
code size: 219
code size: 195
ret: 69
status: Ok(())

View file

@ -23,11 +23,10 @@ fib:
CP r2, r32
JAL r31, r0, :fib
CP r32, r1
ADD64 r33, r33, r32
CP r1, r33
ADD64 r1, r33, r32
1: LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
code size: 234
code size: 231
ret: 55
status: Ok(())

View file

@ -3,13 +3,11 @@ main:
ST r31, r254, 0a, 24h
LI64 r33, 1d
ADDI64 r33, r33, 2d
ADDI64 r33, r33, 3d
CP r32, r33
ADDI64 r32, r32, -6d
CP r1, r32
ADDI64 r32, r33, 3d
ADDI64 r32, r1, -6d
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
code size: 116
code size: 110
ret: 0
status: Ok(())

View file

@ -62,8 +62,7 @@ example:
ADDI64 r35, r35, 0d
ADDI64 r35, r35, 1d
DIRS64 r0, r34, r34, r35
ADDI64 r34, r34, 0d
CP r32, r34
ADDI64 r32, r34, 0d
JMP :1
0: CP r32, r33
1: LI64 r2, 0d
@ -95,12 +94,10 @@ integer:
OR r35, r35, r36
JEQ r35, r0, :0
CP r35, r34
CP r36, r32
SUB64 r33, r33, r36
SUB64 r33, r33, r32
ADDI64 r33, r33, 1d
DIRS64 r0, r35, r35, r33
ADD64 r35, r35, r32
CP r1, r35
ADD64 r1, r35, r32
JMP :1
0: CP r1, r34
1: LD r31, r254, 0a, 56h
@ -130,15 +127,10 @@ rect_line:
ADD64 r36, r36, r37
LI64 r37, 1d
LI64 r38, 2d
ADD64 r37, r37, r38
CP r36, r37
CP r36, r34
ADDI64 r36, r36, 1d
CP r34, r36
ADD64 r36, r37, r38
ADDI64 r34, r34, 1d
JMP :4
3: CP r36, r33
ADDI64 r36, r36, 1d
CP r33, r36
3: ADDI64 r33, r33, 1d
JMP :5
1: LD r31, r254, 48a, 64h
ADDI64 r254, r254, 112d
@ -146,30 +138,24 @@ rect_line:
line:
ADDI64 r254, r254, -80d
ST r31, r254, 48a, 32h
ST r2, r254, 0a, 16h
ST r4, r254, 16a, 16h
ST r2, r254, 16a, 16h
ST r4, r254, 0a, 16h
ST r6, r254, 32a, 16h
CP r32, r8
LI64 r33, 1d
JEQ r33, r0, :0
LD r33, r254, 0a, 8h
LD r34, r254, 16a, 8h
CMPS r33, r33, r34
CMPUI r33, r33, 1d
NOT r33, r33
JEQ r33, r0, :1
LD r33, r254, 16a, 8h
LD r34, r254, 0a, 8h
JGTS r33, r34, :1
JMP :1
1: JMP :2
0: LD r33, r254, 8a, 8h
LD r34, r254, 24a, 8h
CMPS r33, r33, r34
CMPUI r33, r33, 1d
NOT r33, r33
JEQ r33, r0, :2
0: LD r34, r254, 24a, 8h
LD r33, r254, 8a, 8h
JGTS r34, r33, :2
JMP :2
2: LD r31, r254, 48a, 32h
ADDI64 r254, r254, 80d
JALA r0, r31, 0a
code size: 1476
code size: 1416
ret: 0
status: Ok(())

View file

@ -9,23 +9,21 @@ main:
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
integer_range:
ADDI64 r254, r254, -40d
ST r31, r254, 0a, 40h
ADDI64 r254, r254, -32d
ST r31, r254, 0a, 32h
CP r32, r2
CP r33, r3
LI64 r2, 3d
LI64 r3, 4d
ECA
CP r34, r1
CP r35, r32
SUB64 r33, r33, r35
SUB64 r33, r33, r32
ADDI64 r33, r33, 1d
DIRU64 r0, r34, r34, r33
ADD64 r34, r34, r32
CP r1, r34
LD r31, r254, 0a, 40h
ADDI64 r254, r254, 40d
ADD64 r1, r34, r32
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
code size: 220
code size: 214
ret: 42
status: Ok(())

View file

@ -7,8 +7,8 @@ main:
ADDI64 r254, r254, 8d
JALA r0, r31, 0a
fib:
ADDI64 r254, r254, -48d
ST r31, r254, 0a, 48h
ADDI64 r254, r254, -40d
ST r31, r254, 0a, 40h
CP r32, r2
LI64 r33, 0d
LI64 r34, 1d
@ -16,18 +16,15 @@ fib:
JNE r32, r35, :0
JMP :1
0: CP r35, r33
CP r36, r34
ADD64 r35, r35, r36
ADD64 r35, r35, r34
CP r33, r34
CP r34, r35
CP r35, r32
ADDI64 r35, r35, -1d
CP r32, r35
ADDI64 r32, r32, -1d
JMP :2
1: CP r1, r33
LD r31, r254, 0a, 48h
ADDI64 r254, r254, 48d
LD r31, r254, 0a, 40h
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
code size: 227
code size: 218
ret: 55
status: Ok(())

View file

@ -10,8 +10,7 @@ main:
JAL r31, r0, :drop
LI64 r33, 0d
LD r34, r32, 0a, 8h
ADDI64 r34, r34, -2d
CP r1, r34
ADDI64 r34, r1, -2d
LD r31, r254, 8a, 32h
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
@ -31,6 +30,6 @@ modify:
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
code size: 315
code size: 312
ret: 0
status: Ok(())

View file

@ -1,10 +1,11 @@
main:
ADDI64 r254, r254, -8d
ST r31, r254, 0a, 8h
LI64 r2, 10d
ADDI64 r254, r254, -16d
ST r31, r254, 0a, 16h
LI64 r2, 400d
JAL r31, r0, :create_back_buffer
LD r31, r254, 0a, 8h
ADDI64 r254, r254, 8d
CP r32, r1
LD r31, r254, 0a, 16h
ADDI64 r254, r254, 16d
JALA r0, r31, 0a
create_back_buffer:
ADDI64 r254, r254, -32d
@ -26,12 +27,12 @@ create_back_buffer:
JLTS r32, r34, :4
LI64 r2, 255d
JAL r31, r0, :request_page
CP r34, r1
JMP :5
4: CP r2, r32
JAL r31, r0, :request_page
5: CP r34, r32
ADDI64 r34, r34, -255d
CP r32, r34
CP r34, r1
5: ADDI64 r32, r32, -255d
JMP :6
3: CP r1, r33
1: LD r31, r254, 0a, 32h
@ -53,6 +54,6 @@ request_page:
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
code size: 440
code size: 443
ret: 42
status: Ok(())

View file

@ -66,11 +66,10 @@ main:
ST r33, r254, 104a, 8h
LD r33, r254, 96a, 8h
LD r32, r254, 104a, 8h
ADD64 r33, r33, r32
CP r1, r33
ADD64 r1, r33, r32
LD r31, r254, 112a, 24h
ADDI64 r254, r254, 136d
JALA r0, r31, 0a
code size: 781
code size: 778
ret: 10
status: Ok(())

View file

@ -15,14 +15,13 @@ main:
CP r2, r33
JAL r31, r0, :fib_iter
CP r33, r1
SUB64 r32, r32, r33
CP r1, r32
SUB64 r1, r32, r33
LD r31, r254, 2a, 24h
ADDI64 r254, r254, 26d
JALA r0, r31, 0a
fib_iter:
ADDI64 r254, r254, -48d
ST r31, r254, 0a, 48h
ADDI64 r254, r254, -40d
ST r31, r254, 0a, 40h
CP r32, r2
LI64 r33, 0d
LI64 r34, 1d
@ -30,17 +29,14 @@ fib_iter:
JNE r32, r35, :0
JMP :1
0: CP r35, r33
CP r36, r34
ADD64 r35, r35, r36
ADD64 r35, r35, r34
CP r33, r34
CP r34, r35
CP r35, r32
ADDI64 r35, r35, -1d
CP r32, r35
ADDI64 r32, r32, -1d
JMP :2
1: CP r1, r33
LD r31, r254, 0a, 48h
ADDI64 r254, r254, 48d
LD r31, r254, 0a, 40h
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
fib:
ADDI64 r254, r254, -32d
@ -58,13 +54,12 @@ fib:
CP r2, r34
JAL r31, r0, :fib
CP r34, r1
ADD64 r33, r33, r34
CP r1, r33
ADD64 r1, r33, r34
JMP :1
0: CP r1, r32
1: LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
code size: 479
code size: 464
ret: 0
status: Ok(())

View file

@ -28,11 +28,10 @@ main:
CP r33, r0
LD r33, r254, 12a, 4h
SXT32 r33, r33
SUB64 r32, r32, r33
CP r1, r32
SUB64 r1, r32, r33
LD r31, r254, 16a, 24h
ADDI64 r254, r254, 40d
JALA r0, r31, 0a
code size: 320
code size: 317
ret: 0
status: Ok(())

View file

@ -27,22 +27,20 @@ pass:
CP r32, r2
LD r33, r32, 0a, 8h
LD r34, r32, 8a, 8h
SUB64 r33, r33, r34
CP r1, r33
SUB64 r1, r33, r34
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
odher_pass:
ADDI64 r254, r254, -40d
ST r31, r254, 0a, 40h
ADDI64 r254, r254, -32d
ST r31, r254, 0a, 32h
CP r32, r2
CP r33, r1
CP r34, r32
CP r35, r33
BMC r34, r35, 24h
LD r31, r254, 0a, 40h
ADDI64 r254, r254, 40d
CP r34, r33
BMC r32, r34, 24h
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
JALA r0, r31, 0a
code size: 400
code size: 394
ret: 3
status: Ok(())

View file

@ -0,0 +1,38 @@
main:
ADDI64 r254, r254, -10272d
ST r31, r254, 10240a, 32h
LI64 r32, 0d
2: LI64 r33, 1024d
JLTS r32, r33, :0
JMP :1
0: ADDI64 r33, r254, 0d
CP r34, r32
ADD64 r33, r33, r34
LI64 r34, 64d
ST r34, r33, 0a, 1h
ADDI64 r32, r32, 1d
JMP :2
1: LI64 r32, 1d
5: LI64 r33, 10d
JLTS r32, r33, :3
JMP :4
3: ADDI64 r33, r254, 0d
CP r34, r32
MULI64 r34, r34, 1024d
ADD64 r33, r33, r34
ADDI64 r34, r254, 0d
BMC r34, r33, 1024h
ADDI64 r32, r32, 1d
JMP :5
4: LI64 r33, 1024d
MULI64 r33, r33, 2d
ADDI64 r34, r254, 0d
ADD64 r34, r34, r33
CP r1, r0
LD r1, r34, 0a, 1h
LD r31, r254, 10240a, 32h
ADDI64 r254, r254, 10272d
JALA r0, r31, 0a
code size: 297
ret: 64
status: Ok(())

View file

@ -1,16 +1,13 @@
main:
ADDI64 r254, r254, -32d
ST r31, r254, 0a, 32h
ADDI64 r254, r254, -24d
ST r31, r254, 0a, 24h
LI64 r32, 1d
LI64 r33, 2d
CP r34, r32
ADDI64 r34, r34, 1d
CP r32, r34
SUB64 r32, r32, r33
CP r1, r32
LD r31, r254, 0a, 32h
ADDI64 r254, r254, 32d
ADDI64 r32, r32, 1d
SUB64 r1, r32, r33
LD r31, r254, 0a, 24h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
code size: 111
code size: 102
ret: 0
status: Ok(())