| 1 |
from rpython.jit.backend.zarch import locations as loc |
| 2 |
from rpython.rlib.objectmodel import specialize |
| 3 |
|
| 4 |
class ConditionLocation(loc.ImmLocation): |
| 5 |
_immutable_ = True |
| 6 |
def __repr__(self): |
| 7 |
s = "" |
| 8 |
if self.value & 0x1 != 0: |
| 9 |
s += "OF" |
| 10 |
if self.value & 0x2 != 0: |
| 11 |
s += " GT" |
| 12 |
if self.value & 0x4 != 0: |
| 13 |
s += " LT" |
| 14 |
if self.value & 0x8 != 0: |
| 15 |
s += " EQ" |
| 16 |
return "cond(%s)" % s |
| 17 |
|
| 18 |
|
| 19 |
FLOAT = ConditionLocation(0x10) |
| 20 |
|
| 21 |
VEQI = EQ = ConditionLocation(0x8) |
| 22 |
LT = ConditionLocation(0x4) |
| 23 |
GT = ConditionLocation(0x2) |
| 24 |
OF = ConditionLocation(0x1) |
| 25 |
|
| 26 |
LE = ConditionLocation(EQ.value | LT.value | OF.value) |
| 27 |
FLE = ConditionLocation(EQ.value | LT.value) |
| 28 |
GE = ConditionLocation(EQ.value | GT.value | OF.value) |
| 29 |
FGE = ConditionLocation(EQ.value | GT.value) |
| 30 |
VNEI = NE = ConditionLocation(LT.value | GT.value | OF.value) |
| 31 |
NO = ConditionLocation(0xe) |
| 32 |
|
| 33 |
FGT = ConditionLocation(GT.value | OF.value) |
| 34 |
FLT = ConditionLocation(LT.value | OF.value) |
| 35 |
|
| 36 |
ANY = ConditionLocation(0xf) |
| 37 |
|
| 38 |
FP_ROUND_DEFAULT = loc.imm(0x0) |
| 39 |
FP_TOWARDS_ZERO = loc.imm(0x5) |
| 40 |
|
| 41 |
cond_none = loc.imm(-1) |
| 42 |
|
| 43 |
opposites = [None] * 16 |
| 44 |
opposites[0] = ANY |
| 45 |
|
| 46 |
opposites[OF.value] = NO |
| 47 |
opposites[GT.value] = LE |
| 48 |
opposites[LT.value] = GE |
| 49 |
opposites[EQ.value] = NE |
| 50 |
|
| 51 |
opposites[NO.value] = OF |
| 52 |
opposites[LE.value] = GT |
| 53 |
opposites[GE.value] = LT |
| 54 |
opposites[NE.value] = EQ |
| 55 |
|
| 56 |
opposites[FGE.value] = FLT |
| 57 |
opposites[FLE.value] = FGT |
| 58 |
|
| 59 |
opposites[FGT.value] = FLE |
| 60 |
opposites[FLT.value] = FGE |
| 61 |
|
| 62 |
opposites[ANY.value] = ConditionLocation(0) |
| 63 |
|
| 64 |
def negate(cond): |
| 65 |
cc = opposites[cond.value] |
| 66 |
if cc is None: |
| 67 |
assert 0, "provide a sane value to negate" |
| 68 |
return cc |
| 69 |
|
| 70 |
def _assert_value(v1, v2): |
| 71 |
assert v1.value == v2.value |
| 72 |
_assert_value(negate(EQ), NE) |
| 73 |
_assert_value(negate(NE), EQ) |
| 74 |
_assert_value(negate(LT), GE) |
| 75 |
_assert_value(negate(LE), GT) |
| 76 |
_assert_value(negate(GT), LE) |
| 77 |
_assert_value(negate(GE), LT) |
| 78 |
_assert_value(negate(NO), OF) |
| 79 |
_assert_value(negate(OF), NO) |
| 80 |
|
| 81 |
_assert_value(negate(FLE), FGT) |
| 82 |
_assert_value(negate(FGT), FLE) |
| 83 |
|
| 84 |
_assert_value(negate(FGE), FLT) |
| 85 |
_assert_value(negate(FLT), FGE) |
| 86 |
|
| 87 |
del _assert_value |