Skip to content

Commit c0e8301

Browse files
committed
Add syntactic requirements to the branchHints section.
See #2
1 parent dadcb83 commit c0e8301

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

document/core/appendix/custom.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,15 @@ An implementation is not required to follow the hints, and this section can be e
162162

163163
The section contains a vector of *function branch hints* each representing the branch hints for a single function.
164164

165-
Each *function function hints* structure consists of
165+
Each *function branch hints* structure consists of
166166

167167
* the :ref:`function index <binary-funcidx>` of the function the hints are referring to,
168168
* a single 0 byte,
169169
* a vector of *branch hints* for the function.
170170

171+
Elements of the *function branch hints* vector must appear in increasing function index order,
172+
and a function index can appear at most once.
173+
171174
Each *branch hint* structure consists of
172175

173176
* a |U32| indicating the meaning of the hint:
@@ -181,6 +184,10 @@ Value Meaning
181184

182185
* the |U32| byte offset of the hinted instruction from the first instruction of the function.
183186

187+
Elements of the *branch hints* vector must appear in increasing byte offset order,
188+
and a byte offset can appear at most once. A |BRIF| or |IF| instruction must be present
189+
in the code section at the specified offset.
190+
184191

185192
.. math::
186193
\begin{array}{llclll}

proposals/branch-hinting/Overview.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ https://github.com/WebAssembly/meetings/blob/master/main/2021/CG-02-16.md
5151
The *branch hints section* is a custom section whose name string is "branchHints".
5252
The branch hints section should appear only once in a module, and only before the code section.
5353

54-
The purpose of this section is to aid the compilation of conditional branch instructions, by providing a hint that a branch is very likely (or unlikely) to be taken.
54+
The purpose of this section is to aid the compilation of conditional branch instructions,
55+
by providing a hint that a branch is very likely (or unlikely) to be taken.
5556

5657
An implementation is not required to follow the hints, and this section can be entirely ignored.
5758

@@ -63,6 +64,9 @@ Each *function hints* structure consists of
6364
* a single 0 byte
6465
* a vector of *branch hints* for the function.
6566

67+
Elements of the *function hints* vector must appear in increasing function index order,
68+
and a function index can appear at most once.
69+
6670
Each *branch hint* structure consists of
6771

6872
* a u32 indicating the meaning of the hint:
@@ -72,5 +76,9 @@ Each *branch hint* structure consists of
7276
| 0 | likely not taken |
7377
| 1 | likely taken |
7478

75-
* the u32 byte offset of the hinted instruction from the first instruction of the function
79+
* the u32 byte offset of the hinted instruction from the first instruction of the function.
80+
81+
Elements of the *branch hints* vector must appear in increasing byte offset order,
82+
and a byte offset can appear at most once. A `br_if` or `if` instruction must be present
83+
in the code section at the specified offset.
7684

0 commit comments

Comments
 (0)