to affect multiple platforms.
const1 = { INT num; } 1 num.
const2 = { INT num; } 2 num.
-smallconst2 = { INT num; } 2 num.
+smallpconst2 = { INT num; } 2 num. /* Byte-sized positive constant */
+smallnconst2 = { INT num; } 2 num. /* Byte-sized negative constant */
label = { ADDR off; } 2 off.
m = { } 2 cost(0,3) "m".
reg1 = reg + lbreg + m.
b_d_h_sp = regpair + stackpointer.
b_d_h_psw = regpair + psword.
-immediate = smallconst2 + const2 + label.
+immediate = smallpconst2 + smallnconst2 + const2 + label.
src1 = reg.
src2 = hl_or_de + const2 + label.
src1or2 = src1 + src2.
from hl_or_de yields %1.2
-from smallconst2
+from smallpconst2
+ yields {const2, %1.num}
+
+from smallnconst2
yields {const2, %1.num}
from const2
/* Group 1: Load instructions */
/*********************************************/
-pat loc sfit($1, 8)
- yields {smallconst2, $1}
+pat loc ufit($1, 8)
+ yields {smallpconst2, $1}
+
+pat loc sfit($1, 8) && ($1<0)
+ yields {smallnconst2, $1}
pat loc
yields {const2, $1}
yields %2 {const2, 0-%1.num}
leaving
adi 2
- with smallconst2 hl_or_de
- yields %2 {smallconst2, 0-%1.num}
+ with smallnconst2 hl_or_de
+ yields %2 {smallpconst2, 0-%1.num}
leaving
adi 2
with hl_or_de const2
/*****************************************/
pat and $1==2
- with hl_or_de smallconst2
+ with hl_or_de smallpconst2
+ uses areg
+ gen
+ mov a, %1.2
+ ani {const1, %2.num & 0xff}
+ yields a
+ with smallpconst2 hl_or_de
+ yields %1 %2
+ leaving
+ and 2
+ with hl_or_de smallnconst2
uses areg
gen
mov a, %1.2
ani {const1, %2.num & 0xff}
mov %1.2, a
- mvi %1.1, {const1, 0}
yields %1
+ with smallnconst2 hl_or_de
+ yields %1 %2
+ leaving
+ and 2
with hl_or_de const2
uses areg
gen
mov %1.1, a
yields %1
with const2 hl_or_de
- uses areg
- gen
- mov a, %2.2
- ani {const1, %1.num & 0xff}
- mov %2.2, a
- mov a, %2.1
- ani {const1, %1.num >> 8}
- mov %2.1, a
- yields %2
- with smallconst2 hl_or_de
- uses areg
- gen
- mov a, %2.2
- ani {const1, %1.num & 0xff}
- mov %2.2, a
- mvi %2.1, {const1, 0}
- yields %2
+ yields %1 %2
+ leaving
+ and 2
with hl_or_de hl_or_de
uses areg
gen
Call {label,".and"}
pat ior $1==2
- with hl_or_de smallconst2
+ with hl_or_de smallpconst2
+ uses areg
+ gen
+ mov a, %1.2
+ ori {const1, %2.num & 0xff}
+ mov %1.2, a
+ yields %1
+ with smallpconst2 hl_or_de
+ yields %1 %2
+ leaving
+ ior 2
+ with hl_or_de smallnconst2
uses areg
gen
mov a, %1.2
ori {const1, %2.num & 0xff}
mov %1.2, a
+ move {const1, 0xff}, %1.1
yields %1
+ with smallnconst2 hl_or_de
+ yields %1 %2
+ leaving
+ ior 2
with hl_or_de const2
uses areg
gen
mov %1.1, a
yields %1
with const2 hl_or_de
- uses areg
- gen
- mov a, %2.2
- ori {const1, %1.num & 0xff}
- mov %2.2, a
- mov a, %2.1
- ori {const1, %1.num >> 8}
- mov %2.1, a
- yields %2
- with smallconst2 hl_or_de
- uses areg
- gen
- mov a, %2.2
- ori {const1, %1.num & 0xff}
- mov %2.2, a
- yields %2
+ yields %1 %2
+ leaving
+ ior 2
with hl_or_de hl_or_de
uses areg
gen
gen Call {label,".ior"}
pat xor $1==2
- with hl_or_de smallconst2
+ with hl_or_de smallpconst2
uses areg
gen
mov a, %1.2
xri {const1, %2.num & 0xff}
mov %1.2, a
yields %1
+ with smallpconst2 hl_or_de
+ yields %1 %2
+ leaving
+ xor 2
with hl_or_de const2
uses areg
gen
mov %1.1, a
yields %1
with const2 hl_or_de
- uses areg
- gen
- mov a, %2.2
- xri {const1, %1.num & 0xff}
- mov %2.2, a
- mov a, %2.1
- xri {const1, %1.num >> 8}
- mov %2.1, a
- yields %2
- with smallconst2 hl_or_de
- uses areg
- gen
- mov a, %2.2
- xri {const1, %1.num & 0xff}
- mov %2.2, a
- yields %2
+ yields %1 %2
+ leaving
+ xor 2
with hl_or_de hl_or_de
uses areg
gen
cost 4; \
/* reg + const */
- #define ALUC(name, instr) \
+ #define ALUC(name, instr, predicate) \
out:(int)reg = name(left:intregorzero, right:CONST.I) \
- when signed_constant(%right, 16) \
+ when predicate(%right, 16) \
emit instr " %out, %left, $right" \
cost 4; \
/* const + reg */
- #define ALUC_reversed(name, instr) \
+ #define ALUC_reversed(name, instr, predicate) \
out:(int)reg = name(left:CONST.I, right:intregorzero) \
- when signed_constant(%left, 16) \
+ when predicate(%left, 16) \
emit instr " %out, %right, $left" \
cost 4; \
/* reg + const AND const + reg */
- #define ALUCC(name, instr) \
- ALUC(name, instr) \
- ALUC_reversed(name, instr)
+ #define ALUCC(name, instr, predicate) \
+ ALUC(name, instr, predicate) \
+ ALUC_reversed(name, instr, predicate)
ALUR(ADD.I, "addu")
- ALUCC(ADD.I, "addiu")
+ ALUCC(ADD.I, "addiu", signed_constant)
out:(int)reg = SUB.I(left:intregorzero, right:intregorzero)
emit "subu %out, %left, %right"
ALUR(MUL.I, "mul")
ALUR(ASL.I, "sllv")
- ALUC(ASL.I, "sll")
+ ALUC(ASL.I, "sll", signed_constant)
ALUR(ASR.I, "srav")
- ALUC(ASR.I, "sra")
+ ALUC(ASR.I, "sra", signed_constant)
ALUR(LSL.I, "sllv")
- ALUC(LSL.I, "sll")
+ ALUC(LSL.I, "sll", signed_constant)
ALUR(LSR.I, "srlv")
- ALUC(LSR.I, "srl")
+ ALUC(LSR.I, "srl", signed_constant)
out:(int)reg = NEG.I(left:intregorzero)
emit "subu %out, zero, %left"
cost 4;
ALUR(AND.I, "and")
- ALUCC(AND.I, "andi")
+ ALUCC(AND.I, "andi", signed_constant)
ALUR(OR.I, "or")
- ALUCC(OR.I, "ori")
+ ALUCC(OR.I, "ori", unsigned_constant)
ALUR(EOR.I, "xor")
- ALUCC(EOR.I, "xori")
+ ALUCC(EOR.I, "xori", unsigned_constant)
out:(int)reg = value:LABEL.I
emit "lui %out, hi16[$value]"
yields {OR_RIS, %2, hi(%1.val)}
with REG CONST_STACK-UCONST2-CONST_HI_ZR
uses reusing %1, REG={OR_RIS, %1, hi(%2.val)}
- yields {OR_RC, %1, lo(%2.val)}
+ yields {OR_RC, %a, lo(%2.val)}
with CONST_STACK-UCONST2-CONST_HI_ZR REG
uses reusing %2, REG={OR_RIS, %2, hi(%1.val)}
- yields {OR_RC, %2, lo(%1.val)}
+ yields {OR_RC, %a, lo(%1.val)}
pat ior defined($1) /* OR set */
leaving
yields {XOR_RIS, %2, hi(%1.val)}
with REG CONST_STACK-UCONST2-CONST_HI_ZR
uses reusing %1, REG={XOR_RIS, %1, hi(%2.val)}
- yields {XOR_RC, %1, lo(%2.val)}
+ yields {XOR_RC, %a, lo(%2.val)}
with CONST_STACK-UCONST2-CONST_HI_ZR REG
uses reusing %2, REG={XOR_RIS, %2, hi(%1.val)}
- yields {XOR_RC, %2, lo(%1.val)}
+ yields {XOR_RC, %a, lo(%1.val)}
pat xor defined($1) /* XOR set */
leaving
mone
rom -1
big
- rom 257
+ rom 258
/* Or var with var */
asp 4
1
- /* Or var with const */
+ /* Or big var with const */
- loe zero
+ loe big
loc 1
ior EM_WSIZE
- loc 1
+ loc 259
cmu EM_WSIZE
zeq *2
loe big
loc -1
ior EM_WSIZE
- loe big
+ loc -1
cmu EM_WSIZE
zeq *7