43
43
A simple swap function.
44
44
``` wasm
45
45
(func $swap (param i32 i32) (result i32 i32)
46
- (get_local 1) (get_local 0)
46
+ (local.get 1) (local.get 0)
47
47
)
48
48
```
49
49
50
50
An addition function returning an additional carry bit.
51
51
``` wasm
52
52
(func $add64_u_with_carry (param $i i64) (param $j i64) (param $c i32) (result i64 i32)
53
53
(local $k i64)
54
- (set_local $k
55
- (i64.add (i64.add (get_local $i) (get_local $j)) (i64.extend_u/i32 (get_local $c)))
54
+ (local.set $k
55
+ (i64.add (i64.add (local.get $i) (local.get $j)) (i64.extend_i32_u (local.get $c)))
56
56
)
57
- (return (get_local $k) (i64.lt_u (get_local $k) (get_local $i)))
57
+ (return (local.get $k) (i64.lt_u (local.get $k) (local.get $i)))
58
58
)
59
59
```
60
60
@@ -71,7 +71,7 @@ An addition function returning an additional carry bit.
71
71
Conditionally manipulating a stack operand without using a local.
72
72
``` wasm
73
73
(func $add64_u_saturated (param i64 i64) (result i64)
74
- ($i64.add_u_carry (get_local 0) (get_local 1) (i32.const 0))
74
+ (call $add64_u_with_carry (local.get 0) (local.get 1) (i32.const 0))
75
75
(if (param i64) (result i64)
76
76
(then (drop) (i64.const 0xffff_ffff_ffff_ffff))
77
77
)
@@ -80,14 +80,22 @@ Conditionally manipulating a stack operand without using a local.
80
80
81
81
An iterative factorial function whose loop doesn't use locals, but uses arguments like phis.
82
82
``` wasm
83
+ (func $pick0 (param i64) (result i64 i64)
84
+ (local.get 0) (local.get 0)
85
+ )
86
+
87
+ (func $pick1 (param i64 i64) (result i64 i64 i64)
88
+ (local.get 0) (local.get 1) (local.get 0)
89
+ )
90
+
83
91
(func $fac (param i64) (result i64)
84
- (i64.const 1) (get_local 0)
92
+ (i64.const 1) (local.get 0)
85
93
(loop $l (param i64 i64) (result i64)
86
- (pick 1 ) (pick 1 ) (i64.mul)
87
- (pick 1 ) (i64.const 1) (i64.sub)
88
- (pick 0 ) (i64.const 0) (i64.gt_u)
94
+ (call $pick1 ) (call $pick1 ) (i64.mul)
95
+ (call $pick1 ) (i64.const 1) (i64.sub)
96
+ (call $pick0 ) (i64.const 0) (i64.gt_u)
89
97
(br_if $l)
90
- (pick 1 ) (return)
98
+ (call $pick1 ) (return)
91
99
)
92
100
)
93
101
```
0 commit comments