Skip to content

More fixes towards v1.0 #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions esp32_ulp/opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ def get_rel(arg):
if arg.type == IMM:
if arg.value & 3 != 0: # bitwise version of: arg.value % 4 != 0
raise ValueError('Relative offset must be a multiple of 4')
return arg.value >> 2 # bitwise version of: arg.value // 4
return IMM, arg.value >> 2 # bitwise version of: arg.value // 4
if arg.type == SYM:
return symbols.resolve_relative(arg.value)
return SYM, symbols.resolve_relative(arg.value)
raise TypeError('wanted: immediate, got: %s' % arg.raw)


Expand Down Expand Up @@ -652,7 +652,7 @@ def _jump_relr(threshold, cond, offset):


def i_jumpr(offset, threshold, condition):
offset = get_rel(offset)
offset_type, offset = get_rel(offset)
threshold = get_imm(threshold)
condition = get_cond(condition)
if condition == 'lt':
Expand All @@ -669,7 +669,11 @@ def i_jumpr(offset, threshold, condition):
# jump over next JUMPR
skip_ins = _jump_relr(threshold + 1, BRCOND_GE, 2)
# jump to target
offset -= 1 # adjust for the additional JUMPR instruction
if (offset_type == IMM and offset < 0) or offset_type == SYM:
# adjust for the additional JUMPR instruction
# for IMM offsets, the offset is relative to the 2nd instruction, so only backwards jumps need adjusting
# for SYM offsets, label offsets already include the extra instruction, so both directions need adjusting
offset -= 1
jump_ins = _jump_relr(threshold, BRCOND_GE, offset)
return (skip_ins, jump_ins)
else:
Expand All @@ -691,7 +695,7 @@ def _jump_rels(threshold, cond, offset):


def i_jumps(offset, threshold, condition):
offset = get_rel(offset)
offset_type, offset = get_rel(offset)
threshold = get_imm(threshold)
condition = get_cond(condition)
if condition == 'lt':
Expand All @@ -711,7 +715,11 @@ def i_jumps(offset, threshold, condition):
# jump over next JUMPS
skip_ins = _jump_rels(threshold, skip_cond, 2)
# jump to target
offset -= 1 # adjust for the additional JUMPS instruction
if (offset_type == IMM and offset < 0) or offset_type == SYM:
# adjust for the additional JUMPS instruction
# for IMM offsets, the offset is relative to the 2nd instruction, so only backwards jumps need adjusting
# for SYM offsets, label offsets already include the extra instruction, so both directions need adjusting
offset -= 1
jump_ins = _jump_rels(threshold, jump_cond, offset)

return (skip_ins, jump_ins)
Expand Down
6 changes: 6 additions & 0 deletions tests/compat/jumps.S
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ entry:

# jumps with immediate offset (specified in bytes, but real instruction uses words)
jumps 0, 42, lt
jumps 0, 42, eq #dual-instruction condition

jumps 4, 42, lt
jumps 4, 42, eq #dual-instruction condition
jumps 8, 42, lt
jumps 32, 42, lt

jumps -4, 42, lt
jumps -4, 42, eq #dual-instruction condition
jumps -8, 42, lt
jumps -32, 42, lt

Expand All @@ -52,12 +55,15 @@ entry:

# jumpr with immediate offset (specified in bytes, but real instruction uses words)
jumpr 0, 42, lt
jumpr 0, 42, eq #dual-instruction condition

jumpr 4, 42, lt
jumpr 4, 42, eq #dual-instruction condition
jumpr 8, 42, lt
jumpr 32, 42, lt

jumpr -4, 42, lt
jumpr -4, 42, eq #dual-instruction condition
jumpr -8, 42, lt
jumpr -32, 42, lt

Expand Down