diff --git a/src/cowasm/cowasm.coh b/src/cowasm/cowasm.coh index e17c11cb..3366e5b3 100644 --- a/src/cowasm/cowasm.coh +++ b/src/cowasm/cowasm.coh @@ -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); diff --git a/src/cowbe/archpdp11.cow.ng b/src/cowbe/archpdp11.cow.ng index dc3555dc..7de98d5e 100644 --- a/src/cowbe/archpdp11.cow.ng +++ b/src/cowbe/archpdp11.cow.ng @@ -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, $$); } @@ -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 diff --git a/tests/logic-16bit.good b/tests/logic-16bit.good index 191ded0f..1b1ec804 100644 --- a/tests/logic-16bit.good +++ b/tests/logic-16bit.good @@ -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 diff --git a/tests/logic-16bit.test.cow b/tests/logic-16bit.test.cow index e570622e..cfb9c9be 100644 --- a/tests/logic-16bit.test.cow +++ b/tests/logic-16bit.test.cow @@ -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; diff --git a/tests/logic-8bit.good b/tests/logic-8bit.good index 191ded0f..1b1ec804 100644 --- a/tests/logic-8bit.good +++ b/tests/logic-8bit.good @@ -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 diff --git a/tests/logic-8bit.test.cow b/tests/logic-8bit.test.cow index b9fc708c..b9b50198 100644 --- a/tests/logic-8bit.test.cow +++ b/tests/logic-8bit.test.cow @@ -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;