Skip to content
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

Document branch relaxation #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions riscv-asm.md
Expand Up @@ -449,6 +449,36 @@ as seen by `objdump`:
14: 00028067 jr t0 # 0x10
```

Branches
--------------------

Unconditional branches are implemented by the `j(al)?r?` pseudoinstructions.
(The underlying instructions are `jalr?`.)
The `j(al)?` targets can be any symbol or address.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it really be any symbol/address? I haven't tried them all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Any” is indeed an overstatement, since the call/tail macros have a maximum displacement of roughly 2 GB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll read up on this and improve it.


Conditional branches are implemented by the `b(l|g)(t|e)(z|u)?` and `b(eq|ne)z?` pseudoinstructions.
(The underlying instructions are `b(lt|ge)u?` and `b(eq|ne)`.)
Again, the targets can be any symbol or address.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same as above.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, except there’s a 1 MiB limit.


Various relaxations are performed when the target's offset from the branch exceeds the range of the underlying instruction's immediate field.

For example,

```assembly
beqz t0, foo
```

may be relaxed to a sequence of the form

```assembly
bnez t0, 1f
j foo
1:
```

The `bnez` is further relaxed to `bne`, while `j` is relaxed to `jal` with a relocation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not relaxations. These are pure aliases for specific forms (bne with a zero register, and jal with a zero register).



Floating-point rounding modes
-----------------------------

Expand Down