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

Confusing semantics of br-instructions #1259

Open
joelonsql opened this issue Jan 21, 2019 · 4 comments
Open

Confusing semantics of br-instructions #1259

joelonsql opened this issue Jan 21, 2019 · 4 comments

Comments

@joelonsql
Copy link

From https://webassembly.org/docs/semantics/

"br: branch to a given label in an enclosing construct"

The br-family instructions in WebAssembly are very different from assemblies like LLVM IR where you can jump to arbitrary labels. I think this should be pointed out in the documentation.

I think this would be a better description of this instruction:

"br: break to block at given nesting-level in an enclosing construct"

Since "br" works more like a "break" in C than a "goto" in C or a "br" in LLVM IR.

@kripken
Copy link
Member

kripken commented Jan 21, 2019

I agree. Earlier discussion here: #445

Still not too late to fix this! :)

@binji
Copy link
Member

binji commented Jan 21, 2019

@joelonsql The semantics document is useful as an overview, but has not been updated in a long time. You may want to look at the spec instead. In particular, br is defined here:

Each structured control instruction introduces an implicit label. Labels are targets for branch instructions that reference them with label indices. Unlike with other index spaces, indexing of labels is relative by nesting depth, that is, label 0 refers to the innermost structured control instruction enclosing the referring branch instruction, while increasing indices refer to those farther out. Consequently, labels can only be referenced from within the associated structured control instruction. This also implies that branches can only be directed outwards, “breaking” from the block of the control construct they target. The exact effect depends on that control construct. In case of block or if it is a forward jump, resuming execution after the matching end. In case of loop it is a backward jump to the beginning of the loop.

@amirouche
Copy link

@binji The spec is still not clear enough. And @joelonsql point still holds.

@binji
Copy link
Member

binji commented Jan 14, 2020

@amirouche how is the spec unclear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants