A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
;;! target = "pulley64"
;;! test = "compile"
;;! flags = "-Wbranch-hinting"
;; Pulley honors branch hints too: the cold path is laid out after the hot path
;; in the generated bytecode (the branch-hinting optimization lives in
;; target-independent Cranelift code, so it applies on every backend).
(module
;; condition likely false: the then-block is cold.
(func $if_unlikely (param i32) (result i32)
local.get 0
(@metadata.code.branch_hint "\00")
if (result i32)
i32.const 10
else
i32.const 20
end
)
;; condition likely true: the fallthrough is cold.
(func $br_if_likely (param i32) (result i32)
(block $b (result i32)
i32.const 10
local.get 0
(@metadata.code.branch_hint "\01")
br_if $b
drop
i32.const 20
)
)
)
;; wasm[0]::function[0]::if_unlikely:
;; push_frame
;; br_if32 x2, 0xb // target = 0xc
;; 7: xconst8 x0, 20
;; pop_frame
;; ret
;; c: xconst8 x0, 10
;; f: jump -0x5 // target = 0xa
;;
;; wasm[0]::function[1]::br_if_likely:
;; push_frame
;; xconst8 x0, 10
;; br_if_not32 x2, 0x8 // target = 0x20
;; 1e: pop_frame
;; ret
;; 20: xconst8 x0, 20
;; 23: jump -0x5 // target = 0x1e