Skip to content

Meaning of "taken" for IF instructions #35

Description

@kripken

The spec says:

A Branch Hint is a code metadata item with format branch_hint.

It can only be attached to BRIF and IF instructions.

Its payload indicates whether the branch is likely or unlikely to be taken.

For br_if the meaning is clear I think, but for if I am less sure:

..condition..
if
  ..A..
else
  ..B..
end

If the condition is true then we reach A. That means we do not branch, since A is the basic block right after the condition. Should the hint be false if A is likely - is this code fragment correct?

(@metadata.code.branch_hint "\00")
if
  ..very likely to be reached..
else
  ..
end

OTOH, maybe entering A is considered a branch? Technically a VM might branch to get there. And, if A is "branching" then IF and BRIF hints behave the same wrt their conditions (true condition === branch).

The underlying confusion for me is that BRIF has "branch" in the name - it branches if the condition is true. But IF is a control flow structure - is entering it a branch, or avoiding it, or reaching the else?

Anyhow, to clarify this, perhaps

  • If the hint in the last code fragment should be 0, the spec could mention "for IF, a branch is considered taken if the condition is FALSE; for BRIF, if the condition is TRUE"
  • Or, if the hint should be 1, a way to unify the text could be "the branch hint refers to the likelihood of the condition being TRUE (for IF or BRIF)"
  • Either way, examples in the overview could be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions