Skip to content

Commit

Permalink
8080: flush register from cache when it's modified by ALU insn
Browse files Browse the repository at this point in the history
  • Loading branch information
shattered committed Jun 12, 2024
1 parent 5f51a2c commit d6534dc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/cowbe/arch8080.cow.ng
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ gen a := ADD1(b|d|h:lhs, a)
{ E_add($lhs); }

gen a := ADD1(DEREF1(hl), a)
{ E("\tadd m\n"); }
{ R_flush(REG_A); E("\tadd m\n"); }

gen a|b|d|h := ADD1($$, CONSTANT(value==-1))
{ E_dcr($$); }
Expand All @@ -904,7 +904,7 @@ gen a := SUB1(a, b|d|h:rhs)
{ E_sub($rhs); }

gen a := SUB1(a, DEREF1(hl))
{ E("\tsub m\n"); }
{ R_flush(REG_A); E("\tsub m\n"); }

gen a|b|d|h := SUB1($$, CONSTANT(value==1))
{ E_dcr($$); }
Expand All @@ -928,7 +928,7 @@ gen a := OR1(a, b|d|h:lhs)
{ E_ora($lhs); }

gen a := OR1(a, DEREF1(hl))
{ E("\tora m\n"); }
{ R_flush(REG_A); E("\tora m\n"); }

gen a := OR1(a, CONSTANT():c)
{ E_ori($c.value as uint8); }
Expand All @@ -937,7 +937,7 @@ gen a := AND1(a, b|d|h:lhs)
{ E_ana($lhs); }

gen a := AND1(a, DEREF1(hl))
{ E("\tana m\n"); }
{ R_flush(REG_A); E("\tana m\n"); }

gen a := AND1(a, CONSTANT():c)
{ E_ani($c.value as uint8); }
Expand All @@ -946,7 +946,7 @@ gen a := EOR1(a, b|d|h:lhs)
{ E_xra($lhs); }

gen a := EOR1(a, DEREF1(hl))
{ E("\txra m\n"); }
{ R_flush(REG_A); E("\txra m\n"); }

gen a := EOR1(a, CONSTANT():c)
{ E_xri($c.value as uint8); }
Expand Down
1 change: 1 addition & 0 deletions tests/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"recordinitialisers",
"records",
"regalloc",
"regcache",
"shifts-16bit",
"shifts-32bit",
"shifts-8bit",
Expand Down
5 changes: 5 additions & 0 deletions tests/regcache.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
regcache1 add: yes
regcache1 sub: yes
regcache1 or: yes
regcache1 xor: yes
regcache1 and: yes
31 changes: 31 additions & 0 deletions tests/regcache.test.cow
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
include "cowgol.coh";
include "tests/_framework.coh";

# ALU insns referencing memory should flush cached target register value
sub cache1() is
var a: uint8 := 2;
var b: uint8 := 1;
var c: uint8;
var d: uint8;

c := a + b;
d := a;
print("regcache1 add"); if c == 3 and d == 2 then yes(); else no(); end if;

c := a - b;
d := a;
print("regcache1 sub"); if c == 1 and d == 2 then yes(); else no(); end if;

c := a | b;
d := a;
print("regcache1 or"); if c == 3 and d == 2 then yes(); else no(); end if;

c := a ^ b;
d := a;
print("regcache1 xor"); if c == 3 and d == 2 then yes(); else no(); end if;

c := a & b;
d := a;
print("regcache1 and"); if c == 0 and d == 2 then yes(); else no(); end if;
end sub;
cache1();

0 comments on commit d6534dc

Please sign in to comment.