forgot to mul by 8

This commit is contained in:
Jakub Doka 2024-10-24 16:26:28 +02:00
parent aefa7e6405
commit 648bd24d0d
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
4 changed files with 51 additions and 7 deletions

View file

@ -553,7 +553,6 @@ main := fn(): int {
#### small_struct_assignment #### small_struct_assignment
```hb ```hb
Color := struct {r: u8, g: u8, b: u8, a: u8} Color := struct {r: u8, g: u8, b: u8, a: u8}
white := Color.(255, 255, 255, 255) white := Color.(255, 255, 255, 255)
black := Color.(0, 0, 0, 0) black := Color.(0, 0, 0, 0)
@ -564,6 +563,20 @@ main := fn(): int {
} }
``` ```
#### intcast_store
```hb
SetMsg := packed struct {a: u8, count: u32, size: u32, src: ^u8, dest: ^u8}
set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): u32 {
l := SetMsg.(5, @intcast(count), @intcast(@sizeof(Expr)), @bitcast(src), @bitcast(dest))
return l.count
}
main := fn(): int {
return set(int, &0, &0, 1024)
}
```
#### wide_ret #### wide_ret
```hb ```hb
OemIdent := struct { OemIdent := struct {

View file

@ -2514,7 +2514,7 @@ impl<'a> Codegen<'a> {
return Some(val); return Some(val);
} }
let value = (1i64 << self.tys.size_of(val.ty)) - 1; let value = (1i64 << (self.tys.size_of(ty) * 8)) - 1;
let mask = self.ci.nodes.new_node_nop(val.ty, Kind::CInt { value }, [VOID]); let mask = self.ci.nodes.new_node_nop(val.ty, Kind::CInt { value }, [VOID]);
let inps = [VOID, val.id, mask]; let inps = [VOID, val.id, mask];
Some(self.ci.nodes.new_node_lit(ty, Kind::BinOp { op: TokenKind::Band }, inps)) Some(self.ci.nodes.new_node_lit(ty, Kind::BinOp { op: TokenKind::Band }, inps))
@ -4282,15 +4282,13 @@ fn push_up(nodes: &mut Nodes) {
nodes nodes
.iter() .iter()
.map(|(n, _)| n) .map(|(n, _)| n)
.filter(|&n| !nodes.visited.get(n) .filter(|&n| !nodes.visited.get(n) && !matches!(nodes[n].kind, Kind::Arg | Kind::Mem))
&& !matches!(nodes[n].kind, Kind::Arg | Kind::Mem | Kind::End))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
vec![], vec![],
"{:?}", "{:?}",
nodes nodes
.iter() .iter()
.filter(|&(n, nod)| !nodes.visited.get(n) .filter(|&(n, nod)| !nodes.visited.get(n) && !matches!(nod.kind, Kind::Arg | Kind::Mem))
&& !matches!(nod.kind, Kind::Arg | Kind::Mem | Kind::End))
.collect::<Vec<_>>() .collect::<Vec<_>>()
); );
} }
@ -4468,6 +4466,7 @@ mod tests {
returning_global_struct; returning_global_struct;
small_struct_bitcast; small_struct_bitcast;
small_struct_assignment; small_struct_assignment;
intcast_store;
wide_ret; wide_ret;
comptime_min_reg_leak; comptime_min_reg_leak;
different_types; different_types;

View file

@ -4,7 +4,7 @@ main:
LI64 r7, 4d LI64 r7, 4d
LI64 r6, 1d LI64 r6, 1d
LI64 r5, 2d LI64 r5, 2d
LI64 r9, 3d LI64 r9, 255d
LI64 r8, 1d LI64 r8, 1d
LI64 r10, 0d LI64 r10, 0d
ADDI64 r12, r254, 0d ADDI64 r12, r254, 0d

View file

@ -0,0 +1,32 @@
main:
ADDI64 r254, r254, -24d
ST r31, r254, 16a, 8h
LI64 r4, 1024d
LI64 r2, 0d
ADDI64 r3, r254, 0d
ADDI64 r5, r254, 8d
ST r2, r254, 8a, 8h
ST r2, r254, 0a, 8h
CP r2, r5
JAL r31, r0, :set
ANDI r1, r1, 4294967295d
LD r31, r254, 16a, 8h
ADDI64 r254, r254, 24d
JALA r0, r31, 0a
set:
ADDI64 r254, r254, -25d
LI64 r9, 8d
LI64 r8, 5d
ANDI r10, r4, 4294967295d
ADDI64 r1, r254, 0d
ST r8, r254, 0a, 1h
ST r10, r254, 1a, 4h
ST r9, r254, 5a, 4h
ST r2, r254, 9a, 8h
ST r3, r254, 17a, 8h
LD r1, r254, 1a, 4h
ADDI64 r254, r254, 25d
JALA r0, r31, 0a
code size: 309
ret: 1024
status: Ok(())