-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcond.py
127 lines (106 loc) · 3.28 KB
/
cond.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
##########################################################################
# This file is part of d00ks.
#
# d00ks is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# d00ks is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with d00ks. If not, see <http://www.gnu.org/licenses/>.
##########################################################################
"""
This file contains condition functions which when given a set
of registers will return whether or not the condition passes,
given that conditions are based on the CPSR.
"""
import promise
@promise.sensible()
@promise.pure()
def EQ(r):
"""Passes if zero flag is set."""
return bool(r[r.CPSR] & r.Z)
@promise.sensible()
@promise.pure()
def NE(r):
"""Passes is zero flag is not set."""
return not bool(r[r.CPSR] & r.Z)
@promise.sensible()
@promise.pure()
def CS(r):
"""Passes if carry set / Unsigned higher or same"""
return bool(r[r.CPSR] & r.C)
@promise.sensible()
@promise.pure()
def HS(r):
return bool(r[r.CPSR] & r.C)
@promise.sensible()
@promise.pure()
def CC(r):
"""Passes if carry clear / Unsigned lower"""
return not bool(r[r.CPSR] & r.C)
@promise.sensible()
@promise.pure()
def LO(r):
return not bool(r[r.CPSR] & r.C)
@promise.sensible()
@promise.pure()
def MI(r):
"""Passes if negative flag is set / Less than"""
return bool(r[r.CPSR] & r.N)
@promise.sensible()
@promise.pure()
def PL(r):
"""Passes if positive or zero"""
return not bool(r[r.CPSR] & r.N)
@promise.sensible()
@promise.pure()
def VS(r):
"""Passes if overflow set"""
return bool(r[r.CPSR] & r.V)
@promise.sensible()
@promise.pure()
def VC(r):
"""Passes if overflow not set"""
return not bool(r[r.CPSR] & r.V)
@promise.sensible()
@promise.pure()
def HI(r):
"""Unsigned higher / C and not Z"""
return bool(r[r.CPSR] & r.C) and not bool(r[r.CPSR] & r.Z)
@promise.sensible()
@promise.pure()
def LS(r):
"""Unsigned lower or same"""
return (not bool(r[r.CPSR] & r.C)) or bool(r[r.CPSR] & r.Z)
@promise.sensible()
@promise.pure()
def GE(r):
"""Signed greater than or equal"""
return (bool(r[r.CPSR] & r.N) and bool(r[r.CPSR] & r.V)) or ((not bool(r[r.CPSR] & r.N)) and (not bool(r[r.CPSR] & r.V)))
@promise.sensible()
@promise.pure()
def LT(r):
"""Signed less than"""
return (bool(r[r.CPSR] & r.N) and (not bool(r[r.CPSR] & r.V))) or ((not bool(r[r.CPSR] & r.N)) and bool(r[r.CPSR] & r.V))
@promise.sensible()
@promise.pure()
def GT(r):
"""Signed greater than"""
return (not bool(r[r.CPSR] & r.Z)) and ((bool(r[r.CPSR] & r.N) and bool(r[r.CPSR] & r.V)) or ((not bool(r[r.CPSR] & r.N)) and (not bool(r[r.CPSR] & r.V))))
@promise.sensible()
@promise.pure()
def LE(r):
"""Signed less than or equal"""
return bool(r[r.CPSR] & r.Z) or (bool(r[r.CPSR] & r.N) and (not bool(r[r.CPSR] & r.V))) or ((not bool(r[r.CPSR] & r.N)) and bool(r[r.CPSR] & r.V))
@promise.sensible()
@promise.pure()
def AL(R):
"""Always"""
return True
AL.__name__ = ""