Fix issue with logical operations and small signed constants which turned out
to affect multiple platforms.
This commit is contained in:
parent
eb57db75a4
commit
8200f041c2
|
@ -46,7 +46,8 @@ TOKENS
|
||||||
|
|
||||||
const1 = { INT num; } 1 num.
|
const1 = { INT num; } 1 num.
|
||||||
const2 = { INT num; } 2 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.
|
label = { ADDR off; } 2 off.
|
||||||
m = { } 2 cost(0,3) "m".
|
m = { } 2 cost(0,3) "m".
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ SETS
|
||||||
reg1 = reg + lbreg + m.
|
reg1 = reg + lbreg + m.
|
||||||
b_d_h_sp = regpair + stackpointer.
|
b_d_h_sp = regpair + stackpointer.
|
||||||
b_d_h_psw = regpair + psword.
|
b_d_h_psw = regpair + psword.
|
||||||
immediate = smallconst2 + const2 + label.
|
immediate = smallpconst2 + smallnconst2 + const2 + label.
|
||||||
src1 = reg.
|
src1 = reg.
|
||||||
src2 = hl_or_de + const2 + label.
|
src2 = hl_or_de + const2 + label.
|
||||||
src1or2 = src1 + src2.
|
src1or2 = src1 + src2.
|
||||||
|
@ -226,7 +227,10 @@ gen move %1,%a.2
|
||||||
|
|
||||||
from hl_or_de yields %1.2
|
from hl_or_de yields %1.2
|
||||||
|
|
||||||
from smallconst2
|
from smallpconst2
|
||||||
|
yields {const2, %1.num}
|
||||||
|
|
||||||
|
from smallnconst2
|
||||||
yields {const2, %1.num}
|
yields {const2, %1.num}
|
||||||
|
|
||||||
from const2
|
from const2
|
||||||
|
@ -243,8 +247,11 @@ PATTERNS
|
||||||
/* Group 1: Load instructions */
|
/* Group 1: Load instructions */
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
|
|
||||||
pat loc sfit($1, 8)
|
pat loc ufit($1, 8)
|
||||||
yields {smallconst2, $1}
|
yields {smallpconst2, $1}
|
||||||
|
|
||||||
|
pat loc sfit($1, 8) && ($1<0)
|
||||||
|
yields {smallnconst2, $1}
|
||||||
|
|
||||||
pat loc
|
pat loc
|
||||||
yields {const2, $1}
|
yields {const2, $1}
|
||||||
|
@ -651,8 +658,8 @@ pat sbi $1==2
|
||||||
yields %2 {const2, 0-%1.num}
|
yields %2 {const2, 0-%1.num}
|
||||||
leaving
|
leaving
|
||||||
adi 2
|
adi 2
|
||||||
with smallconst2 hl_or_de
|
with smallnconst2 hl_or_de
|
||||||
yields %2 {smallconst2, 0-%1.num}
|
yields %2 {smallpconst2, 0-%1.num}
|
||||||
leaving
|
leaving
|
||||||
adi 2
|
adi 2
|
||||||
with hl_or_de const2
|
with hl_or_de const2
|
||||||
|
@ -1176,14 +1183,27 @@ leaving loc $1 loc $2 cal ".cfu" asp 4+$1 lfr 4
|
||||||
/*****************************************/
|
/*****************************************/
|
||||||
|
|
||||||
pat and $1==2
|
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
|
uses areg
|
||||||
gen
|
gen
|
||||||
mov a, %1.2
|
mov a, %1.2
|
||||||
ani {const1, %2.num & 0xff}
|
ani {const1, %2.num & 0xff}
|
||||||
mov %1.2, a
|
mov %1.2, a
|
||||||
mvi %1.1, {const1, 0}
|
|
||||||
yields %1
|
yields %1
|
||||||
|
with smallnconst2 hl_or_de
|
||||||
|
yields %1 %2
|
||||||
|
leaving
|
||||||
|
and 2
|
||||||
with hl_or_de const2
|
with hl_or_de const2
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
|
@ -1195,23 +1215,9 @@ pat and $1==2
|
||||||
mov %1.1, a
|
mov %1.1, a
|
||||||
yields %1
|
yields %1
|
||||||
with const2 hl_or_de
|
with const2 hl_or_de
|
||||||
uses areg
|
yields %1 %2
|
||||||
gen
|
leaving
|
||||||
mov a, %2.2
|
and 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
|
|
||||||
with hl_or_de hl_or_de
|
with hl_or_de hl_or_de
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
|
@ -1246,13 +1252,29 @@ pat and !defined($1)
|
||||||
Call {label,".and"}
|
Call {label,".and"}
|
||||||
|
|
||||||
pat ior $1==2
|
pat ior $1==2
|
||||||
with hl_or_de smallconst2
|
with hl_or_de smallpconst2
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
mov a, %1.2
|
mov a, %1.2
|
||||||
ori {const1, %2.num & 0xff}
|
ori {const1, %2.num & 0xff}
|
||||||
mov %1.2, a
|
mov %1.2, a
|
||||||
yields %1
|
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
|
with hl_or_de const2
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
|
@ -1264,22 +1286,9 @@ pat ior $1==2
|
||||||
mov %1.1, a
|
mov %1.1, a
|
||||||
yields %1
|
yields %1
|
||||||
with const2 hl_or_de
|
with const2 hl_or_de
|
||||||
uses areg
|
yields %1 %2
|
||||||
gen
|
leaving
|
||||||
mov a, %2.2
|
ior 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
|
|
||||||
with hl_or_de hl_or_de
|
with hl_or_de hl_or_de
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
|
@ -1312,13 +1321,17 @@ kills ALL
|
||||||
gen Call {label,".ior"}
|
gen Call {label,".ior"}
|
||||||
|
|
||||||
pat xor $1==2
|
pat xor $1==2
|
||||||
with hl_or_de smallconst2
|
with hl_or_de smallpconst2
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
mov a, %1.2
|
mov a, %1.2
|
||||||
xri {const1, %2.num & 0xff}
|
xri {const1, %2.num & 0xff}
|
||||||
mov %1.2, a
|
mov %1.2, a
|
||||||
yields %1
|
yields %1
|
||||||
|
with smallpconst2 hl_or_de
|
||||||
|
yields %1 %2
|
||||||
|
leaving
|
||||||
|
xor 2
|
||||||
with hl_or_de const2
|
with hl_or_de const2
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
|
@ -1330,22 +1343,9 @@ pat xor $1==2
|
||||||
mov %1.1, a
|
mov %1.1, a
|
||||||
yields %1
|
yields %1
|
||||||
with const2 hl_or_de
|
with const2 hl_or_de
|
||||||
uses areg
|
yields %1 %2
|
||||||
gen
|
leaving
|
||||||
mov a, %2.2
|
xor 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
|
|
||||||
with hl_or_de hl_or_de
|
with hl_or_de hl_or_de
|
||||||
uses areg
|
uses areg
|
||||||
gen
|
gen
|
||||||
|
|
|
@ -799,26 +799,26 @@ PATTERNS
|
||||||
cost 4; \
|
cost 4; \
|
||||||
|
|
||||||
/* reg + const */
|
/* reg + const */
|
||||||
#define ALUC(name, instr) \
|
#define ALUC(name, instr, predicate) \
|
||||||
out:(int)reg = name(left:intregorzero, right:CONST.I) \
|
out:(int)reg = name(left:intregorzero, right:CONST.I) \
|
||||||
when signed_constant(%right, 16) \
|
when predicate(%right, 16) \
|
||||||
emit instr " %out, %left, $right" \
|
emit instr " %out, %left, $right" \
|
||||||
cost 4; \
|
cost 4; \
|
||||||
|
|
||||||
/* const + reg */
|
/* const + reg */
|
||||||
#define ALUC_reversed(name, instr) \
|
#define ALUC_reversed(name, instr, predicate) \
|
||||||
out:(int)reg = name(left:CONST.I, right:intregorzero) \
|
out:(int)reg = name(left:CONST.I, right:intregorzero) \
|
||||||
when signed_constant(%left, 16) \
|
when predicate(%left, 16) \
|
||||||
emit instr " %out, %right, $left" \
|
emit instr " %out, %right, $left" \
|
||||||
cost 4; \
|
cost 4; \
|
||||||
|
|
||||||
/* reg + const AND const + reg */
|
/* reg + const AND const + reg */
|
||||||
#define ALUCC(name, instr) \
|
#define ALUCC(name, instr, predicate) \
|
||||||
ALUC(name, instr) \
|
ALUC(name, instr, predicate) \
|
||||||
ALUC_reversed(name, instr)
|
ALUC_reversed(name, instr, predicate)
|
||||||
|
|
||||||
ALUR(ADD.I, "addu")
|
ALUR(ADD.I, "addu")
|
||||||
ALUCC(ADD.I, "addiu")
|
ALUCC(ADD.I, "addiu", signed_constant)
|
||||||
|
|
||||||
out:(int)reg = SUB.I(left:intregorzero, right:intregorzero)
|
out:(int)reg = SUB.I(left:intregorzero, right:intregorzero)
|
||||||
emit "subu %out, %left, %right"
|
emit "subu %out, %left, %right"
|
||||||
|
@ -851,14 +851,14 @@ PATTERNS
|
||||||
ALUR(MUL.I, "mul")
|
ALUR(MUL.I, "mul")
|
||||||
|
|
||||||
ALUR(ASL.I, "sllv")
|
ALUR(ASL.I, "sllv")
|
||||||
ALUC(ASL.I, "sll")
|
ALUC(ASL.I, "sll", signed_constant)
|
||||||
ALUR(ASR.I, "srav")
|
ALUR(ASR.I, "srav")
|
||||||
ALUC(ASR.I, "sra")
|
ALUC(ASR.I, "sra", signed_constant)
|
||||||
|
|
||||||
ALUR(LSL.I, "sllv")
|
ALUR(LSL.I, "sllv")
|
||||||
ALUC(LSL.I, "sll")
|
ALUC(LSL.I, "sll", signed_constant)
|
||||||
ALUR(LSR.I, "srlv")
|
ALUR(LSR.I, "srlv")
|
||||||
ALUC(LSR.I, "srl")
|
ALUC(LSR.I, "srl", signed_constant)
|
||||||
|
|
||||||
out:(int)reg = NEG.I(left:intregorzero)
|
out:(int)reg = NEG.I(left:intregorzero)
|
||||||
emit "subu %out, zero, %left"
|
emit "subu %out, zero, %left"
|
||||||
|
@ -869,13 +869,13 @@ PATTERNS
|
||||||
cost 4;
|
cost 4;
|
||||||
|
|
||||||
ALUR(AND.I, "and")
|
ALUR(AND.I, "and")
|
||||||
ALUCC(AND.I, "andi")
|
ALUCC(AND.I, "andi", signed_constant)
|
||||||
|
|
||||||
ALUR(OR.I, "or")
|
ALUR(OR.I, "or")
|
||||||
ALUCC(OR.I, "ori")
|
ALUCC(OR.I, "ori", unsigned_constant)
|
||||||
|
|
||||||
ALUR(EOR.I, "xor")
|
ALUR(EOR.I, "xor")
|
||||||
ALUCC(EOR.I, "xori")
|
ALUCC(EOR.I, "xori", unsigned_constant)
|
||||||
|
|
||||||
out:(int)reg = value:LABEL.I
|
out:(int)reg = value:LABEL.I
|
||||||
emit "lui %out, hi16[$value]"
|
emit "lui %out, hi16[$value]"
|
||||||
|
|
|
@ -1574,10 +1574,10 @@ PATTERNS
|
||||||
yields {OR_RIS, %2, hi(%1.val)}
|
yields {OR_RIS, %2, hi(%1.val)}
|
||||||
with REG CONST_STACK-UCONST2-CONST_HI_ZR
|
with REG CONST_STACK-UCONST2-CONST_HI_ZR
|
||||||
uses reusing %1, REG={OR_RIS, %1, hi(%2.val)}
|
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
|
with CONST_STACK-UCONST2-CONST_HI_ZR REG
|
||||||
uses reusing %2, REG={OR_RIS, %2, hi(%1.val)}
|
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 */
|
pat ior defined($1) /* OR set */
|
||||||
leaving
|
leaving
|
||||||
|
@ -1602,10 +1602,10 @@ PATTERNS
|
||||||
yields {XOR_RIS, %2, hi(%1.val)}
|
yields {XOR_RIS, %2, hi(%1.val)}
|
||||||
with REG CONST_STACK-UCONST2-CONST_HI_ZR
|
with REG CONST_STACK-UCONST2-CONST_HI_ZR
|
||||||
uses reusing %1, REG={XOR_RIS, %1, hi(%2.val)}
|
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
|
with CONST_STACK-UCONST2-CONST_HI_ZR REG
|
||||||
uses reusing %2, REG={XOR_RIS, %2, hi(%1.val)}
|
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 */
|
pat xor defined($1) /* XOR set */
|
||||||
leaving
|
leaving
|
||||||
|
|
|
@ -11,7 +11,7 @@ one
|
||||||
mone
|
mone
|
||||||
rom -1
|
rom -1
|
||||||
big
|
big
|
||||||
rom 257
|
rom 258
|
||||||
|
|
||||||
/* Or var with var */
|
/* Or var with var */
|
||||||
|
|
||||||
|
@ -27,12 +27,12 @@ big
|
||||||
asp 4
|
asp 4
|
||||||
1
|
1
|
||||||
|
|
||||||
/* Or var with const */
|
/* Or big var with const */
|
||||||
|
|
||||||
loe zero
|
loe big
|
||||||
loc 1
|
loc 1
|
||||||
ior EM_WSIZE
|
ior EM_WSIZE
|
||||||
loc 1
|
loc 259
|
||||||
cmu EM_WSIZE
|
cmu EM_WSIZE
|
||||||
zeq *2
|
zeq *2
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ big
|
||||||
loe big
|
loe big
|
||||||
loc -1
|
loc -1
|
||||||
ior EM_WSIZE
|
ior EM_WSIZE
|
||||||
loe big
|
loc -1
|
||||||
cmu EM_WSIZE
|
cmu EM_WSIZE
|
||||||
zeq *7
|
zeq *7
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue