Skip to content

Avoid generating JMP in conditionals since it forces NN #135

@patricksurry

Description

@patricksurry

Most user words with conditionals end up as NN because they involve absolute jmp either literally or via zero_branch_runtime. which uses an absolute target rather than a 16-bit offset.

We could replace these with bra in many cases, and the others using a jsr farbra / .word offset construct so that we never generate an absolute jump target. I believe all code generation for jmp is routed through cmpl_jump, cmpl_jump_later, cmpl_jump_tos, cmpl_0branch_tos and cmpl_0branch_later so it shouldn't be too difficult to rewrite them.

Performance/code-size would improve a little for jmp -> bra but would be a bit worse for jsr farbra. On the other hand, small conditional words would potentially benefit from inlining.

A 16-bit offset would only allow jump up to +/- 32Kb so it would fail if you wrote a word that contained a conditional jump across say a 32K+ alloc'd block. It's hard to see that being a significant restriction in practice so could generate an error message?

(feel free to assign this to me)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions