Skip to content

Commit fa3e44f

Browse files
get_cond() accepts all conditions, caller checks for supported
1 parent 89c9450 commit fa3e44f

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

demo.s

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ start: ld r0, r1, 0 # a comment!
2121
stage_dec 23
2222

2323
# jumping to labels not supported yet
24-
jumpr -1, 42, LT
24+
jumpr -1, 42, lt
2525
jumpr +1, 23, GE
2626
jump 0
2727
jump 0, eq
28-
jump 0, ov
28+
jump 0, OV
2929
jump r0
30-
jump r0, eq
30+
jump r0, EQ
3131
jump r0, ov
32-
jumps -1, 42, LT
32+
jumps -1, 42, lt
3333
jumps +1, 23, GT
34-
jumps 0, 0xAD, EQ
34+
jumps 0, 0xAD, Eq
3535

3636
reg_rd 0x3ff48000, 7, 0
3737
reg_wr 0x3ff48000, 7, 0, 42

esp32_ulp/opcodes.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def make_ins(layout):
250250

251251
# assembler opcode definitions
252252

253-
REG, IMM, COND_FLAGS, COND_COMP = 0, 1, 2, 3
253+
REG, IMM, COND = 0, 1, 2
254254
ARG = namedtuple('ARG', ('type', 'value', 'raw'))
255255

256256

@@ -268,10 +268,8 @@ def arg_qualify(arg):
268268
if 0 <= reg <= 3:
269269
return ARG(REG, reg, arg)
270270
raise ValueError('arg_qualify: valid registers are r0, r1, r2, r3. Given: %s' % arg)
271-
if len(arg) == 2 and arg in ['--', 'eq', 'ov']:
272-
return ARG(COND_FLAGS, arg.lower(), arg)
273-
if len(arg) == 2 and arg in ['EQ', 'LT', 'GT', 'GE']:
274-
return ARG(COND_COMP, arg.lower(), arg)
271+
if len(arg) == 2 and arg.lower() in ['--', 'eq', 'ov', 'lt', 'gt', 'ge']:
272+
return ARG(COND, arg.lower(), arg)
275273
try:
276274
return ARG(IMM, int(arg), arg)
277275
except ValueError:
@@ -293,18 +291,11 @@ def get_imm(arg):
293291
raise TypeError('wanted: immediate, got: %s' % arg.raw)
294292

295293

296-
def get_cond_flags(arg):
294+
def get_cond(arg):
297295
arg = arg_qualify(arg)
298-
if arg.type == COND_FLAGS:
296+
if arg.type == COND:
299297
return arg.value
300-
raise TypeError('wanted: flags condition, got: %s' % arg.raw)
301-
302-
303-
def get_cond_comp(arg):
304-
arg = arg_qualify(arg)
305-
if arg.type == COND_COMP:
306-
return arg.value
307-
raise TypeError('wanted: comparison condition, got: %s' % arg.raw)
298+
raise TypeError('wanted: condition, got: %s' % arg.raw)
308299

309300

310301
def _soc_reg_to_ulp_periph_sel(reg):
@@ -544,13 +535,15 @@ def i_sleep(timer_idx):
544535

545536
def i_jump(target, condition='--'):
546537
target = arg_qualify(target)
547-
condition = get_cond_flags(condition)
538+
condition = get_cond(condition)
548539
if condition == 'eq':
549540
jump_type = BX_JUMP_TYPE_ZERO
550541
elif condition == 'ov':
551542
jump_type = BX_JUMP_TYPE_OVF
552-
else: # '--' means unconditional
543+
elif condition == '--': # means unconditional
553544
jump_type = BX_JUMP_TYPE_DIRECT
545+
else:
546+
raise ValueError("invalid flags condition")
554547
if target.type == IMM:
555548
_bx.dreg = 0
556549
_bx.addr = target.value
@@ -575,7 +568,7 @@ def i_jump(target, condition='--'):
575568
def i_jumpr(offset, threshold, condition):
576569
offset = get_imm(offset)
577570
threshold = get_imm(threshold)
578-
condition = get_cond_comp(condition)
571+
condition = get_cond(condition)
579572
if condition == 'lt':
580573
cmp_op = B_CMP_L
581574
elif condition == 'ge':
@@ -594,7 +587,7 @@ def i_jumpr(offset, threshold, condition):
594587
def i_jumps(offset, threshold, condition):
595588
offset = get_imm(offset)
596589
threshold = get_imm(threshold)
597-
condition = get_cond_comp(condition)
590+
condition = get_cond(condition)
598591
if condition == 'lt':
599592
cmp_op = BC_CMP_LT
600593
elif condition == 'gt':

0 commit comments

Comments
 (0)