Sign in Join
Wiki copytemporary

WebAssembly/Instructions: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: WebAssembly/Instructions

OldNewLine
1+This page is created because it's annoying to constantly jump around the official WebAssembly documentation.
2+
3+The page requires careful review as official specs are updated
4+
5+## Instructions
6+
7+**Instruction**
8+
9+**Byte Code**
10+
11+**Execution**
12+
13+**Notes**
14+
15+**unreachable**
16+
17+\$00
18+
19+
20+1\. Trap
21+
22+**nop**
23+
24+\$01
25+
26+
27+1\. Do nothing
28+
29+**block**
30+
31+\$02 *blocktype*
32+
33+
34+1\. Let n be the arity \|t?\| of the result type t?.
35+
36+2\. Let L be the label whose arity is n and whose continuation is the end of the block.
37+
38+3\. Enter the block instr∗ with label L.
39+
40+**block** must always be closed with **end**
41+
42+**loop**
43+
44+\$03
45+
46+**if**
47+
48+\$04
49+
50+**else**
51+
52+\$05
53+
54+can only be used with **if**. Only single **else** is allowed per **if**
55+
56+(reserved)
57+
58+\$06..\$0A
59+
60+**end**
61+
62+\$0B
63+
64+**end** can only close **block** or **loop** clocks
65+
66+**br** *labelidx*
67+
68+\$0C *labelidx*
69+
70+
71+1\. Assert: due to validation, the stack contains at least l+1 labels.
72+
73+2\. Let L be the l-th label appearing on the stack, starting from the top and counting from zero.
74+
75+3\. Let n be the arity of L.
76+
77+4\. Assert: due to validation, there are at least n values on the top of the stack.
78+
79+5\. Pop the values valn from the stack.
80+
81+6\. Repeat l+1 times:
82+
83+
84+a\. While the top of the stack is a value, do:
85+
86+
87+i\. Pop the value from the stack.
88+
89+b\. Assert: due to validation, the top of the stack now is a label.
90+
91+c\. Pop the label from the stack.
92+
93+7\. Push the values valn to the stack.
94+
95+8\. Jump to the continuation of L.
96+
97+Branching - Unconditional
98+
99+Branching is possible only within a block. The block itself defines labels where the branching can go to.
100+
101+**br_if** *labelidx*
102+
103+\$0D *labelidx*
104+
105+
106+1\. Assert: due to validation, a value of value type i32 is on the top of the stack.
107+
108+2\. Pop the value i32.const c from the stack.
109+
110+3\. If c is non-zero, then:
111+
112+
113+a\. Execute the instruction (br l).
114+
115+4\. Else:
116+
117+
118+b\. Do nothing.
119+
120+Branching - Conditional
121+
122+Branching is possible only within a block. The block itself defines labels where the branching can go to.
123+
124+**br_table** *vec(labelidxI)* *labelidx*
125+
126+\$0E
127+
128+**return**
129+
130+\$0F
131+
132+**call** *funcidx*
133+
134+\$10
135+
136+
137+1\. Let F be the current frame.
138+
139+2\. Assert: due to validation, F.module.funcaddrs\[x\] exists.
140+
141+3\. Let a be the function address F.module.funcaddrs\[x\].
142+
143+4\. Invoke the function instance at address a.
144+
145+**call_indirect** *typeuse*
146+
147+\$11
148+
149+
150+1\. Let F be the current frame.
151+
152+2\. Assert: due to validation, F.module.tableaddrs\[0\] exists.
153+
154+3\. Let ta be the table address F.module.tableaddrs\[0\].
155+
156+4\. Assert: due to validation, S.tables\[ta\] exists.
157+
158+5\. Let tab be the table instance S.tables\[ta\].
159+
160+6\. Assert: due to validation, F.module.types\[x\] exists.
161+
162+7\. Let ftexpect be the function type F.module.types\[x\].
163+
164+8\. Assert: due to validation, a value with value type i32 is on the top of the stack.
165+
166+9\. Pop the value i32.const i from the stack.
167+
168+10\. If i is not smaller than the length of tab.elem, then:
169+
170+
171+a\. Trap.
172+
173+11\. If tab.elem\[i\] is uninitialized, then:
174+
175+
176+a\. Trap.
177+
178+12\. Let a be the function address tab.elem\[i\].
179+
180+13\. Assert: due to validation, S.funcs\[a\] exists.
181+
182+14\. Let f be the function instance S.funcs\[a\].
183+
184+15\. Let ft<sub>actual</sub> be the function type f.type.
185+
186+16\. If ft<sub>actual</sub> and ft<sub>expect</sub> differ, then:
187+
188+
189+a\. Trap.
190+
191+17\. Invoke the function instance at address a.
192+
193+Note that **call_indirect** text syntax is different:
194+
195+`call_indirect (type x)`
196+
197+A plain numeric value is treated as table number, not function signature. The signature can also be explicitly specified
198+
199+`call_indirect (param i32)(param f32)(result f64)`
200+
201+In this case the assembly would assign the proper type.
202+
203+(reserved)
204+
205+\$12..\$19
206+
207+**drop**
208+
209+\$1A
210+
211+\[t\]→\[\]
212+
213+**select**
214+
215+\$1B
216+
217+\[t t i32\]→\[t\]
218+
219+(reserved)
220+
221+\$1C..\$1F
222+
223+**local.get** x
224+
225+\$20
226+
227+**local.set** x
228+
229+\$21
230+
231+**local.tee** x
232+
233+\$22
234+
235+**global.get** x
236+
237+\$23
238+
239+**global.set** x
240+
241+\$24
242+
243+(reserved)
244+
245+\$25..\$27
246+
247+**i32.load** memarg
248+
249+\$28
250+
251+**t**.load **memarg** and **t**.load**N**_**sx** **memarg**
252+
253+
254+1\. Let F be the current frame.
255+
256+2\. Assert: due to validation, F.module.memaddrs\[0\] exists.
257+
258+3\. Let a be the memory address F.module.memaddrs\[0\].
259+
260+4\. Assert: due to validation, S.mems\[a\] exists.
261+
262+5\. Let mem be the memory instance S.mems\[a\].
263+
264+6\. Assert: due to validation, a value of value type i32 is on the top of the stack.
265+
266+7\. Pop the value i32.const i from the stack.
267+
268+8\. Let ea be the integer i+memarg.offset.
269+
270+9\. If N is not part of the instruction, then:
271+
272+
273+a\. Let N be the bit width \|t\| of value type t.
274+
275+10\. If ea+N/8 is larger than the length of mem.data, then:
276+
277+
278+a\. Trap.
279+
280+11\. Let b∗ be the byte sequence mem.data\[ea:N/8\].
281+
282+12\. If N and sx are part of the instruction, then:
283+
284+
285+a\. Let n be the integer for which bytesiN(n)=b∗.
286+
287+b\. Let c be the result of computing extend_sxN,\|t\|(n).
288+
289+13\. Else:
290+
291+
292+a\. Let c be the constant for which bytest(c)=b∗.
293+
294+14\. Push the value t.const c to the stack.
295+
296+**i64.load** memarg
297+
298+\$29
299+
300+**f32.load** memarg
301+
302+\$2A
303+
304+**f64.load** memarg
305+
306+\$2B
307+
308+**i32.load8_s** memarg
309+
310+\$2C
311+
312+**i32.load8_u** memarg
313+
314+\$2D
315+
316+**i32.load16_s** memarg
317+
318+\$2E
319+
320+**i32.load16_u** memarg
321+
322+\$2F
323+
324+**i64.load8_s** memarg
325+
326+\$30
327+
328+**i64.load8_u** memarg
329+
330+\$31
331+
332+**i64.load16_s** memarg
333+
334+\$32
335+
336+**i64.load16_u** memarg
337+
338+\$33
339+
340+**i64.load32_s** memarg
341+
342+\$34
343+
344+**i64.load32_u** memarg
345+
346+\$35
347+
348+**i32.store** memarg
349+
350+\$36
351+
352+**t**.store **memarg** and **t**.store**N** **memarg**
353+
354+
355+1\. Let F be the current frame.
356+
357+2\. Assert: due to validation, F.module.memaddrs\[0\] exists.
358+
359+3\. Let a be the memory address F.module.memaddrs\[0\].
360+
361+4\. Assert: due to validation, S.mems\[a\] exists.
362+
363+5\. Let mem be the memory instance S.mems\[a\].
364+
365+5\. Assert: due to validation, a value of value type t is on the top of the stack.
366+
367+7\. Pop the value t.const c from the stack.
368+
369+8\. Assert: due to validation, a value of value type i32 is on the top of the stack.
370+
371+9\. Pop the value i32.const i from the stack.
372+
373+10\. Let ea be the integer i+memarg.offset.
374+
375+11\. If N is not part of the instruction, then:
376+
377+
378+a\. Let N be the bit width \|t\| of value type t.
379+
380+12\. If ea+N/8 is larger than the length of mem.data, then:
381+
382+
383+a\. Trap.
384+
385+13\. If N is part of the instruction, then:
386+
387+
388+a\. Let n be the result of computing wrap\|t\|,N(c).
389+
390+b\. Let b∗ be the byte sequence bytesiN(n).
391+
392+14\. Else:
393+
394+
395+a\. Let b∗ be the byte sequence bytest(c).
396+
397+15\. Replace the bytes mem.data\[ea:N/8\] with b∗.
398+
399+**i64.store** memarg
400+
401+\$37
402+
403+**f32.store** memarg
404+
405+\$38
406+
407+**f64.store** memarg
408+
409+\$39
410+
411+**i32.store8** memarg
412+
413+\$3A
414+
415+**i32.store16** memarg
416+
417+\$3B
418+
419+**i64.store8** memarg
420+
421+\$3C
422+
423+**i64.store16** memarg
424+
425+\$3D
426+
427+**i64.store32** memarg
428+
429+\$3E
430+
431+**memory.size**
432+
433+\$3F
434+
435+**memory.grow**
436+
437+\$40
438+
439+**i32.const** i32
440+
441+\$41
442+
443+**i64.const** i64
444+
445+\$42
446+
447+**f32.const** f32
448+
449+\$43
450+
451+**f64.const** f64
452+
453+\$44
454+
455+**i32.eqz**
456+
457+\$45
458+
459+Return 1 if i is zero, 0 otherwise.
460+
461+**i32.eq**
462+
463+\$46
464+
465+Return 1 if i1 equals i2, 0 otherwise.
466+
467+**i32.ne**
468+
469+\$47
470+
471+Return 1 if i1 does not equal i2, 0 otherwise.
472+
473+**i32.lt_s**
474+
475+\$48
476+
477+Let j1 be the signed interpretation of i1.
478+
479+Let j2 be the signed interpretation of i2.
480+
481+Return 1 if j1 is less than j2, 0 otherwise.
482+
483+**i32.lt_u**
484+
485+\$49
486+
487+Return 1 if i1 is less than i2, 0 otherwise.
488+
489+**i32.gt_s**
490+
491+\$4A
492+
493+**i32.gt_u**
494+
495+\$4B
496+
497+**i32.le_s**
498+
499+\$4C
500+
501+**i32.le_u**
502+
503+\$4D
504+
505+**i32.ge_s**
506+
507+\$4E
508+
509+**i32.ge_u**
510+
511+\$4F
512+
513+**i64.eqz**
514+
515+\$50
516+
517+Return 1 if i is zero, 0 otherwise.
518+
519+**i64.eq**
520+
521+\$51
522+
523+Return 1 if i1 equals i2, 0 otherwise.
524+
525+**i64.ne**
526+
527+\$52
528+
529+Return 1 if i1 does not equal i2, 0 otherwise.
530+
531+**i64.lt_s**
532+
533+\$53
534+
535+Let j1 be the signed interpretation of i1.
536+
537+Let j2 be the signed interpretation of i2.
538+
539+Return 1 if j1 is less than j2, 0 otherwise.
540+
541+**i64.lt_u**
542+
543+\$54
544+
545+Return 1 if i1 is less than i2, 0 otherwise.
546+
547+**i64.gt_s**
548+
549+\$55
550+
551+**i64.gt_u**
552+
553+\$56
554+
555+**i64.le_s**
556+
557+\$57
558+
559+**i64.le_u**
560+
561+\$58
562+
563+**i64.ge_s**
564+
565+\$59
566+
567+**i64.ge_u**
568+
569+\$5A
570+
571+**f32.eq**
572+
573+\$5B
574+
575+Return 1 if i1 equals i2, 0 otherwise.
576+
577+**f32.ne**
578+
579+\$5C
580+
581+Return 1 if i1 does not equal i2, 0 otherwise.
582+
583+**f32.lt**
584+
585+\$5D
586+
587+**f32.gt**
588+
589+\$5E
590+
591+**f32.le**
592+
593+\$5F
594+
595+**f32.ge**
596+
597+\$60
598+
599+**f64.eq**
600+
601+\$61
602+
603+Return 1 if i1 equals i2, 0 otherwise.
604+
605+**f64.ne**
606+
607+\$62
608+
609+Return 1 if i1 does not equal i2, 0 otherwise.
610+
611+**f64.lt**
612+
613+\$63
614+
615+**f64.gt**
616+
617+\$64
618+
619+**f64.le**
620+
621+\$65
622+
623+**f64.ge**
624+
625+\$66
626+
627+**i32.clz**
628+
629+\$67
630+
631+**i32.ctz**
632+
633+\$68
634+
635+**i32.popcnt**
636+
637+\$69
638+
639+**i32.add**
640+
641+\$6A
642+
643+**i32.sub**
644+
645+\$6B
646+
647+**i32.mul**
648+
649+\$6C
650+
651+**i32.div_s**
652+
653+\$6D
654+
655+**i32.div_u**
656+
657+\$6E
658+
659+**i32.rem_s**
660+
661+\$6F
662+
663+**i32.rem_u**
664+
665+\$70
666+
667+**i32.and**
668+
669+\$71
670+
671+**i32.or**
672+
673+\$72
674+
675+**i32.xor**
676+
677+\$73
678+
679+**i32.shl**
680+
681+\$74
682+
683+**i32.shr_s**
684+
685+\$75
686+
687+**i32.shr_u**
688+
689+\$76
690+
691+**i32.rotl**
692+
693+\$77
694+
695+**i32.rotr**
696+
697+\$78
698+
699+**i64.clz**
700+
701+\$79
702+
703+**i64.ctz**
704+
705+\$7A
706+
707+**i64.popcnt**
708+
709+\$7B
710+
711+**i64.add**
712+
713+\$7C
714+
715+**i64.sub**
716+
717+\$7D
718+
719+**i64.mul**
720+
721+\$7E
722+
723+**i64.div_s**
724+
725+\$7F
726+
727+**i64.div_u**
728+
729+\$80
730+
731+**i64.rem_s**
732+
733+\$81
734+
735+**i64.rem_u**
736+
737+\$82
738+
739+**i64.and**
740+
741+\$83
742+
743+**i64.or**
744+
745+\$84
746+
747+**i64.xor**
748+
749+\$85
750+
751+**i64.shl**
752+
753+\$86
754+
755+**i64.shr_s**
756+
757+\$87
758+
759+**i64.shr_u**
760+
761+\$88
762+
763+**i64.rotl**
764+
765+\$89
766+
767+**i64.rotr**
768+
769+\$8A
770+
771+**f32.abs**
772+
773+\$8B
774+
775+**f32.neg**
776+
777+\$8C
778+
779+**f32.ceil**
780+
781+\$8D
782+
783+**f32.floor**
784+
785+\$8E
786+
787+**f32.trunc**
788+
789+\$8F
790+
791+**f32.nearest**
792+
793+\$90
794+
795+**f32.sqrt**
796+
797+\$91
798+
799+**f32.add**
800+
801+\$92
802+
803+**f32.sub**
804+
805+\$93
806+
807+**f32.mul**
808+
809+\$94
810+
811+**f32.div**
812+
813+\$95
814+
815+**f32.min**
816+
817+\$96
818+
819+**f32.max**
820+
821+\$97
822+
823+**f32.copysign**
824+
825+\$98
826+
827+**f64.abs**
828+
829+\$99
830+
831+**f64.neg**
832+
833+\$9A
834+
835+**f64.ceil**
836+
837+\$9B
838+
839+**f64.floor**
840+
841+\$9C
842+
843+**f64.trunc**
844+
845+\$9D
846+
847+**f64.nearest**
848+
849+\$9E
850+
851+**f64.sqrt**
852+
853+\$9F
854+
855+**f64.add**
856+
857+\$A0
858+
859+**f64.sub**
860+
861+\$A1
862+
863+**f64.mul**
864+
865+\$A2
866+
867+**f64.div**
868+
869+\$A3
870+
871+**f64.min**
872+
873+\$A4
874+
875+**f64.max**
876+
877+\$A5
878+
879+**f64.copysign**
880+
881+\$A6
882+
883+**i32.wrap_i64**
884+
885+\$A7
886+
887+**i32.trunc_f32_s**
888+
889+\$A8
890+
891+**i32.trunc_f32_u**
892+
893+\$A9
894+
895+**i32.trunc_f64_s**
896+
897+\$AA
898+
899+**i32.trunc_f64_u**
900+
901+\$AB
902+
903+**i64.extend_i32_s**
904+
905+\$AC
906+
907+**i64.extend_i32_u**
908+
909+\$AD
910+
911+**i64.trunc_f32_s**
912+
913+\$AE
914+
915+**i64.trunc_f32_u**
916+
917+\$AF
918+
919+**i64.trunc_f64_s**
920+
921+\$B0
922+
923+**i64.trunc_f64_u**
924+
925+\$B1
926+
927+**f32.convert_i32_s**
928+
929+\$B2
930+
931+**f32.convert_i32_u**
932+
933+\$B3
934+
935+**f32.convert_i64_s**
936+
937+\$B4
938+
939+**f32.convert_i64_u**
940+
941+\$B5
942+
943+**f32.demote_f64**
944+
945+\$B6
946+
947+**f64.convert_i32_s**
948+
949+\$B7
950+
951+**f64.convert_i32_u**
952+
953+\$B8
954+
955+**f64.convert_i64_s**
956+
957+\$B9
958+
959+**f64.convert_i64_u**
960+
961+\$BA
962+
963+**f64.promote_f32**
964+
965+\$BB
966+
967+**i32.reinterpret_f32**
968+
969+\$BC
970+
971+**i64.reinterpret_f64**
972+
973+\$BD
974+
975+**f32.reinterpret_i32**
976+
977+\$BE
978+
979+**f64.reinterpret_i64**
980+
981+\$BF
982+
983+## See Also
984+
985+- [[WebAssembly]]
986+- <http://webassembly.github.io/spec/core/intro/index.html> - official documentation
987+
988+---
989+*From the Free Pascal wiki, page "WebAssembly/Instructions", as it stood on 2019-10-24 after a change by Skalogryz, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
990+Category: WebAssembly

Back to history