Skip to content

Commit

Permalink
Merge pull request #146 from shattered/_a2dcf481
Browse files Browse the repository at this point in the history
pdp11: use bit test insn when possible.  cowasm: don't add extra padd…
  • Loading branch information
davidgiven authored May 28, 2024
2 parents f412ec4 + fb16060 commit 2f7fd7f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cowasm/cowasm.coh
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,10 @@ sub AlignCb implements SymbolCallback is
SimpleError("alignment must be a power of two");
end if;

if [currentProgramCounter] & (tokenNumber - 1) == 0 then
return;
end if;

var newpc := ([currentProgramCounter] + tokenNumber) & ~(tokenNumber - 1);
while [currentProgramCounter] != newpc loop
Emit8(0);
Expand Down
13 changes: 12 additions & 1 deletion src/cowbe/archpdp11.cow.ng
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ gen r32 := SUB4($$, r32:rhs)
}
gen r32 := SUB4($$, CONSTANT():c) { E_subi4($c.value, $$); }

// XXX use BIT when BEQx(ANDx())
gen r8 := AND1($$, r8:rhs) uses r5b { E_and($rhs, $$); }
gen r8 := AND1($$, CONSTANT():c) { E_andi($c.value, $$); }
gen r16 := AND2($$, r16:rhs) uses r5 { E_and($rhs, $$); }
Expand Down Expand Up @@ -1468,8 +1467,20 @@ gen BEQ0(CONSTANT():c1, CONSTANT():c2):b uses all { beqc(self.n[0], $c1.value, $

gen BEQ1(r8:lhs, r8:rhs):b uses all { E_cmp($lhs, $rhs); CmpJumpsJe(self.n[0]); }
gen BEQ1(r8:lhs, CONSTANT():c):b uses all { if ($c.value == 0) then E_tst($lhs); else E_cmpi($c.value, $lhs); end if; CmpJumpsJe(self.n[0]); }
gen BEQ1(AND1(r8:lhs, r8:rhs), CONSTANT(value==0)):b { E_alu2("BIT", $rhs, $lhs); CmpJumpsJe(self.n[0]); }
gen BEQ1(AND1(r8:lhs, CONSTANT(value!=0):c), CONSTANT(value==0)):b
{
E_alu2i("BIT", $c.value, $lhs);
CmpJumpsJe(self.n[0]);
}
gen BEQ2(r16:lhs, r16:rhs):b uses all { E_cmp($lhs, $rhs); CmpJumpsJe(self.n[0]); }
gen BEQ2(r16:lhs, CONSTANT():c):b uses all { if ($c.value == 0) then E_tst($lhs); else E_cmpi($c.value, $lhs); end if; CmpJumpsJe(self.n[0]); }
gen BEQ2(AND2(r16:lhs, r16:rhs), CONSTANT(value==0)):b { E_alu2("BIT", $rhs, $lhs); CmpJumpsJe(self.n[0]); }
gen BEQ2(AND2(r16:lhs, CONSTANT(value!=0):c), CONSTANT(value==0)):b
{
E_alu2i("BIT", $c.value, $lhs);
CmpJumpsJe(self.n[0]);
}
gen BEQ4(r32:lhs, r32:rhs):b uses all { E_cmpeq4($lhs, $rhs); CmpJumpsJe(self.n[0]); }
//n BEQ4(r32:lhs, CONSTANT():c):b uses all { E_cmpi4($c.value, $lhs); CmpJumpsJe(self.n[0]); } // XXX deadlock

Expand Down
2 changes: 2 additions & 0 deletions tests/logic-16bit.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
two|one==three: yes
three&two==two: yes
two&one==ZERO: yes
two&ONE==ZERO: yes
two^one==three: yes
three^one==two: yes
~zero==mone: yes
Expand Down
4 changes: 4 additions & 0 deletions tests/logic-16bit.test.cow
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ var three: uint16 := 0x3003;
var four: uint16 := 0x4004;

const NOTFOUR := ~0x4004;
const ZERO := 0;
const ONE := 0x1001;

print("two|one==three"); if (two|one) == three then yes(); else no(); end if;
print("three&two==two"); if (three&two) == two then yes(); else no(); end if;
print("two&one==ZERO"); if (two&one) == ZERO then yes(); else no(); end if;
print("two&ONE==ZERO"); if (two&ONE) == ZERO then yes(); else no(); end if;
print("two^one==three"); if (two^one) == three then yes(); else no(); end if;
print("three^one==two"); if (three^one) == two then yes(); else no(); end if;
print("~zero==mone"); if ~zero == mone then yes(); else no(); end if;
Expand Down
2 changes: 2 additions & 0 deletions tests/logic-8bit.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
two|one==three: yes
three&two==two: yes
two&one==ZERO: yes
two&ONE==ZERO: yes
two^one==three: yes
three^one==two: yes
~zero==mone: yes
Expand Down
4 changes: 4 additions & 0 deletions tests/logic-8bit.test.cow
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ var three: int8 := 3;
var four: int8 := 4;

const NOTFOUR := ~4;
const ZERO := 0;
const ONE := 1;

print("two|one==three"); if (two|one) == three then yes(); else no(); end if;
print("three&two==two"); if (three&two) == two then yes(); else no(); end if;
print("two&one==ZERO"); if (two&one) == ZERO then yes(); else no(); end if;
print("two&ONE==ZERO"); if (two&ONE) == ZERO then yes(); else no(); end if;
print("two^one==three"); if (two^one) == three then yes(); else no(); end if;
print("three^one==two"); if (three^one) == two then yes(); else no(); end if;
print("~zero==mone"); if ~zero == mone then yes(); else no(); end if;
Expand Down

0 comments on commit 2f7fd7f

Please sign in to comment.