Sign in Join
Wiki copytemporary

WebAssembly/Instructions: what changed

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

OldNewLine
11This page is created because it's annoying to constantly jump around the official WebAssembly documentation.
22
33The page requires careful review as official specs are updated
44
55## Instructions
66
77**Instruction**
88
99**Byte Code**
1010
1111**Execution**
1212
1313**Notes**
1414
1515**unreachable**
1616
1717\$00
1818
1919
20201\. Trap
2121
2222**nop**
2323
2424\$01
2525
2626
27271\. Do nothing
2828
2929**block**
3030
3131\$02 *blocktype*
3232
3333
34341\. Let n be the arity \|t?\| of the result type t?.
3535
36362\. Let L be the label whose arity is n and whose continuation is the end of the block.
3737
38383\. Enter the block instr∗ with label L.
3939
4040**block** must always be closed with **end**
4141
4242**loop**
4343
4444\$03
4545
4646**if**
4747
4848\$04
4949
5050**else**
5151
5252\$05
5353
5454can only be used with **if**. Only single **else** is allowed per **if**
5555
5656(reserved)
5757
5858\$06..\$0A
5959
6060**end**
6161
6262\$0B
6363
6464**end** can only close **block** or **loop** clocks
6565
6666**br** *labelidx*
6767
6868\$0C *labelidx*
6969
7070
71711\. Assert: due to validation, the stack contains at least l+1 labels.
7272
73732\. Let L be the l-th label appearing on the stack, starting from the top and counting from zero.
7474
75753\. Let n be the arity of L.
7676
77774\. Assert: due to validation, there are at least n values on the top of the stack.
7878
79795\. Pop the values valn from the stack.
8080
81816\. Repeat l+1 times:
8282
8383
8484a\. While the top of the stack is a value, do:
8585
8686
8787i\. Pop the value from the stack.
8888
8989b\. Assert: due to validation, the top of the stack now is a label.
9090
9191c\. Pop the label from the stack.
9292
93937\. Push the values valn to the stack.
9494
95958\. Jump to the continuation of L.
9696
9797Branching - Unconditional
9898
9999Branching is possible only within a block. The block itself defines labels where the branching can go to.
100100
101101**br_if** *labelidx*
102102
103103\$0D *labelidx*
104104
105105
1061061\. Assert: due to validation, a value of value type i32 is on the top of the stack.
107107
1081082\. Pop the value i32.const c from the stack.
109109
1101103\. If c is non-zero, then:
111111
112112
113113a\. Execute the instruction (br l).
114114
1151154\. Else:
116116
117117
118118b\. Do nothing.
119119
120120Branching - Conditional
121121
122122Branching is possible only within a block. The block itself defines labels where the branching can go to.
123123
124124**br_table** *vec(labelidxI)* *labelidx*
125125
126126\$0E
127127
128128**return**
129129
130130\$0F
131131
132132**call** *funcidx*
133133
134134\$10
135135
136136
1371371\. Let F be the current frame.
138138
1391392\. Assert: due to validation, F.module.funcaddrs\[x\] exists.
140140
1411413\. Let a be the function address F.module.funcaddrs\[x\].
142142
1431434\. Invoke the function instance at address a.
144144
145145**call_indirect** *typeuse*
146146
147147\$11
148148
149149
1501501\. Let F be the current frame.
151151
1521522\. Assert: due to validation, F.module.tableaddrs\[0\] exists.
153153
1541543\. Let ta be the table address F.module.tableaddrs\[0\].
155155
1561564\. Assert: due to validation, S.tables\[ta\] exists.
157157
1581585\. Let tab be the table instance S.tables\[ta\].
159159
1601606\. Assert: due to validation, F.module.types\[x\] exists.
161161
1621627\. Let ftexpect be the function type F.module.types\[x\].
163163
1641648\. Assert: due to validation, a value with value type i32 is on the top of the stack.
165165
1661669\. Pop the value i32.const i from the stack.
167167
16816810\. If i is not smaller than the length of tab.elem, then:
169169
170170
171171a\. Trap.
172172
17317311\. If tab.elem\[i\] is uninitialized, then:
174174
175175
176176a\. Trap.
177177
17817812\. Let a be the function address tab.elem\[i\].
179179
18018013\. Assert: due to validation, S.funcs\[a\] exists.
181181
18218214\. Let f be the function instance S.funcs\[a\].
183183
18418415\. Let ft<sub>actual</sub> be the function type f.type.
185185
18618616\. If ft<sub>actual</sub> and ft<sub>expect</sub> differ, then:
187187
188188
189189a\. Trap.
190190
19119117\. Invoke the function instance at address a.
192192
193193Note that **call_indirect** text syntax is different:
194194
195-`call_indirect (type x)`
195+``` pascal
196+call_indirect (type x)
197+```
196198
197199A plain numeric value is treated as table number, not function signature. The signature can also be explicitly specified
198200
199-`call_indirect (param i32)(param f32)(result f64)`
201+```text
202+call_indirect (param i32)(param f32)(result f64)
203+```
200204
201205In this case the assembly would assign the proper type.
202206
203207(reserved)
204208
205209\$12..\$19
206210
207211**drop**
208212
209213\$1A
210214
211215\[t\]→\[\]
212216
213217**select**
214218
215219\$1B
216220
217221\[t t i32\]→\[t\]
218222
219223(reserved)
220224
221225\$1C..\$1F
222226
223227**local.get** x
224228
225229\$20
226230
227231**local.set** x
228232
229233\$21
230234
231235**local.tee** x
232236
233237\$22
234238
235239**global.get** x
236240
237241\$23
238242
239243**global.set** x
240244
241245\$24
242246
243247(reserved)
244248
245249\$25..\$27
246250
247251**i32.load** memarg
248252
249253\$28
250254
251255**t**.load **memarg** and **t**.load**N**_**sx** **memarg**
252256
253257
2542581\. Let F be the current frame.
255259
2562602\. Assert: due to validation, F.module.memaddrs\[0\] exists.
257261
2582623\. Let a be the memory address F.module.memaddrs\[0\].
259263
2602644\. Assert: due to validation, S.mems\[a\] exists.
261265
2622665\. Let mem be the memory instance S.mems\[a\].
263267
2642686\. Assert: due to validation, a value of value type i32 is on the top of the stack.
265269
2662707\. Pop the value i32.const i from the stack.
267271
2682728\. Let ea be the integer i+memarg.offset.
269273
2702749\. If N is not part of the instruction, then:
271275
272276
273277a\. Let N be the bit width \|t\| of value type t.
274278
27527910\. If ea+N/8 is larger than the length of mem.data, then:
276280
277281
278282a\. Trap.
279283
28028411\. Let b∗ be the byte sequence mem.data\[ea:N/8\].
281285
28228612\. If N and sx are part of the instruction, then:
283287
284288
285289a\. Let n be the integer for which bytesiN(n)=b∗.
286290
287291b\. Let c be the result of computing extend_sxN,\|t\|(n).
288292
28929313\. Else:
290294
291295
292296a\. Let c be the constant for which bytest(c)=b∗.
293297
29429814\. Push the value t.const c to the stack.
295299
296300**i64.load** memarg
297301
298302\$29
299303
300304**f32.load** memarg
301305
302306\$2A
303307
304308**f64.load** memarg
305309
306310\$2B
307311
308312**i32.load8_s** memarg
309313
310314\$2C
311315
312316**i32.load8_u** memarg
313317
314318\$2D
315319
316320**i32.load16_s** memarg
317321
318322\$2E
319323
320324**i32.load16_u** memarg
321325
322326\$2F
323327
324328**i64.load8_s** memarg
325329
326330\$30
327331
328332**i64.load8_u** memarg
329333
330334\$31
331335
332336**i64.load16_s** memarg
333337
334338\$32
335339
336340**i64.load16_u** memarg
337341
338342\$33
339343
340344**i64.load32_s** memarg
341345
342346\$34
343347
344348**i64.load32_u** memarg
345349
346350\$35
347351
348352**i32.store** memarg
349353
350354\$36
351355
352356**t**.store **memarg** and **t**.store**N** **memarg**
353357
354358
3553591\. Let F be the current frame.
356360
3573612\. Assert: due to validation, F.module.memaddrs\[0\] exists.
358362
3593633\. Let a be the memory address F.module.memaddrs\[0\].
360364
3613654\. Assert: due to validation, S.mems\[a\] exists.
362366
3633675\. Let mem be the memory instance S.mems\[a\].
364368
3653695\. Assert: due to validation, a value of value type t is on the top of the stack.
366370
3673717\. Pop the value t.const c from the stack.
368372
3693738\. Assert: due to validation, a value of value type i32 is on the top of the stack.
370374
3713759\. Pop the value i32.const i from the stack.
372376
37337710\. Let ea be the integer i+memarg.offset.
374378
37537911\. If N is not part of the instruction, then:
376380
377381
378382a\. Let N be the bit width \|t\| of value type t.
379383
38038412\. If ea+N/8 is larger than the length of mem.data, then:
381385
382386
383387a\. Trap.
384388
38538913\. If N is part of the instruction, then:
386390
387391
388392a\. Let n be the result of computing wrap\|t\|,N(c).
389393
390394b\. Let b∗ be the byte sequence bytesiN(n).
391395
39239614\. Else:
393397
394398
395399a\. Let b∗ be the byte sequence bytest(c).
396400
39740115\. Replace the bytes mem.data\[ea:N/8\] with b∗.
398402
399403**i64.store** memarg
400404
401405\$37
402406
403407**f32.store** memarg
404408
405409\$38
406410
407411**f64.store** memarg
408412
409413\$39
410414
411415**i32.store8** memarg
412416
413417\$3A
414418
415419**i32.store16** memarg
416420
417421\$3B
418422
419423**i64.store8** memarg
420424
421425\$3C
422426
423427**i64.store16** memarg
424428
425429\$3D
426430
427431**i64.store32** memarg
428432
429433\$3E
430434
431435**memory.size**
432436
433437\$3F
434438
435439**memory.grow**
436440
437441\$40
438442
439443**i32.const** i32
440444
441445\$41
442446
443447**i64.const** i64
444448
445449\$42
446450
447451**f32.const** f32
448452
449453\$43
450454
451455**f64.const** f64
452456
453457\$44
454458
455459**i32.eqz**
456460
457461\$45
458462
459463Return 1 if i is zero, 0 otherwise.
460464
461465**i32.eq**
462466
463467\$46
464468
465469Return 1 if i1 equals i2, 0 otherwise.
466470
467471**i32.ne**
468472
469473\$47
470474
471475Return 1 if i1 does not equal i2, 0 otherwise.
472476
473477**i32.lt_s**
474478
475479\$48
476480
477481Let j1 be the signed interpretation of i1.
478482
479483Let j2 be the signed interpretation of i2.
480484
481485Return 1 if j1 is less than j2, 0 otherwise.
482486
483487**i32.lt_u**
484488
485489\$49
486490
487491Return 1 if i1 is less than i2, 0 otherwise.
488492
489493**i32.gt_s**
490494
491495\$4A
492496
493497**i32.gt_u**
494498
495499\$4B
496500
497501**i32.le_s**
498502
499503\$4C
500504
501505**i32.le_u**
502506
503507\$4D
504508
505509**i32.ge_s**
506510
507511\$4E
508512
509513**i32.ge_u**
510514
511515\$4F
512516
513517**i64.eqz**
514518
515519\$50
516520
517521Return 1 if i is zero, 0 otherwise.
518522
519523**i64.eq**
520524
521525\$51
522526
523527Return 1 if i1 equals i2, 0 otherwise.
524528
525529**i64.ne**
526530
527531\$52
528532
529533Return 1 if i1 does not equal i2, 0 otherwise.
530534
531535**i64.lt_s**
532536
533537\$53
534538
535539Let j1 be the signed interpretation of i1.
536540
537541Let j2 be the signed interpretation of i2.
538542
539543Return 1 if j1 is less than j2, 0 otherwise.
540544
541545**i64.lt_u**
542546
543547\$54
544548
545549Return 1 if i1 is less than i2, 0 otherwise.
546550
547551**i64.gt_s**
548552
549553\$55
550554
551555**i64.gt_u**
552556
553557\$56
554558
555559**i64.le_s**
556560
557561\$57
558562
559563**i64.le_u**
560564
561565\$58
562566
563567**i64.ge_s**
564568
565569\$59
566570
567571**i64.ge_u**
568572
569573\$5A
570574
571575**f32.eq**
572576
573577\$5B
574578
575579Return 1 if i1 equals i2, 0 otherwise.
576580
577581**f32.ne**
578582
579583\$5C
580584
581585Return 1 if i1 does not equal i2, 0 otherwise.
582586
583587**f32.lt**
584588
585589\$5D
586590
587591**f32.gt**
588592
589593\$5E
590594
591595**f32.le**
592596
593597\$5F
594598
595599**f32.ge**
596600
597601\$60
598602
599603**f64.eq**
600604
601605\$61
602606
603607Return 1 if i1 equals i2, 0 otherwise.
604608
605609**f64.ne**
606610
607611\$62
608612
609613Return 1 if i1 does not equal i2, 0 otherwise.
610614
611615**f64.lt**
612616
613617\$63
614618
615619**f64.gt**
616620
617621\$64
618622
619623**f64.le**
620624
621625\$65
622626
623627**f64.ge**
624628
625629\$66
626630
627631**i32.clz**
628632
629633\$67
630634
631635**i32.ctz**
632636
633637\$68
634638
635639**i32.popcnt**
636640
637641\$69
638642
639643**i32.add**
640644
641645\$6A
642646
643647**i32.sub**
644648
645649\$6B
646650
647651**i32.mul**
648652
649653\$6C
650654
651655**i32.div_s**
652656
653657\$6D
654658
655659**i32.div_u**
656660
657661\$6E
658662
659663**i32.rem_s**
660664
661665\$6F
662666
663667**i32.rem_u**
664668
665669\$70
666670
667671**i32.and**
668672
669673\$71
670674
671675**i32.or**
672676
673677\$72
674678
675679**i32.xor**
676680
677681\$73
678682
679683**i32.shl**
680684
681685\$74
682686
683687**i32.shr_s**
684688
685689\$75
686690
687691**i32.shr_u**
688692
689693\$76
690694
691695**i32.rotl**
692696
693697\$77
694698
695699**i32.rotr**
696700
697701\$78
698702
699703**i64.clz**
700704
701705\$79
702706
703707**i64.ctz**
704708
705709\$7A
706710
707711**i64.popcnt**
708712
709713\$7B
710714
711715**i64.add**
712716
713717\$7C
714718
715719**i64.sub**
716720
717721\$7D
718722
719723**i64.mul**
720724
721725\$7E
722726
723727**i64.div_s**
724728
725729\$7F
726730
727731**i64.div_u**
728732
729733\$80
730734
731735**i64.rem_s**
732736
733737\$81
734738
735739**i64.rem_u**
736740
737741\$82
738742
739743**i64.and**
740744
741745\$83
742746
743747**i64.or**
744748
745749\$84
746750
747751**i64.xor**
748752
749753\$85
750754
751755**i64.shl**
752756
753757\$86
754758
755759**i64.shr_s**
756760
757761\$87
758762
759763**i64.shr_u**
760764
761765\$88
762766
763767**i64.rotl**
764768
765769\$89
766770
767771**i64.rotr**
768772
769773\$8A
770774
771775**f32.abs**
772776
773777\$8B
774778
775779**f32.neg**
776780
777781\$8C
778782
779783**f32.ceil**
780784
781785\$8D
782786
783787**f32.floor**
784788
785789\$8E
786790
787791**f32.trunc**
788792
789793\$8F
790794
791795**f32.nearest**
792796
793797\$90
794798
795799**f32.sqrt**
796800
797801\$91
798802
799803**f32.add**
800804
801805\$92
802806
803807**f32.sub**
804808
805809\$93
806810
807811**f32.mul**
808812
809813\$94
810814
811815**f32.div**
812816
813817\$95
814818
815819**f32.min**
816820
817821\$96
818822
819823**f32.max**
820824
821825\$97
822826
823827**f32.copysign**
824828
825829\$98
826830
827831**f64.abs**
828832
829833\$99
830834
831835**f64.neg**
832836
833837\$9A
834838
835839**f64.ceil**
836840
837841\$9B
838842
839843**f64.floor**
840844
841845\$9C
842846
843847**f64.trunc**
844848
845849\$9D
846850
847851**f64.nearest**
848852
849853\$9E
850854
851855**f64.sqrt**
852856
853857\$9F
854858
855859**f64.add**
856860
857861\$A0
858862
859863**f64.sub**
860864
861865\$A1
862866
863867**f64.mul**
864868
865869\$A2
866870
867871**f64.div**
868872
869873\$A3
870874
871875**f64.min**
872876
873877\$A4
874878
875879**f64.max**
876880
877881\$A5
878882
879883**f64.copysign**
880884
881885\$A6
882886
883887**i32.wrap_i64**
884888
885889\$A7
886890
887891**i32.trunc_f32_s**
888892
889893\$A8
890894
891895**i32.trunc_f32_u**
892896
893897\$A9
894898
895899**i32.trunc_f64_s**
896900
897901\$AA
898902
899903**i32.trunc_f64_u**
900904
901905\$AB
902906
903907**i64.extend_i32_s**
904908
905909\$AC
906910
907911**i64.extend_i32_u**
908912
909913\$AD
910914
911915**i64.trunc_f32_s**
912916
913917\$AE
914918
915919**i64.trunc_f32_u**
916920
917921\$AF
918922
919923**i64.trunc_f64_s**
920924
921925\$B0
922926
923927**i64.trunc_f64_u**
924928
925929\$B1
926930
927931**f32.convert_i32_s**
928932
929933\$B2
930934
931935**f32.convert_i32_u**
932936
933937\$B3
934938
935939**f32.convert_i64_s**
936940
937941\$B4
938942
939943**f32.convert_i64_u**
940944
941945\$B5
942946
943947**f32.demote_f64**
944948
945949\$B6
946950
947951**f64.convert_i32_s**
948952
949953\$B7
950954
951955**f64.convert_i32_u**
952956
953957\$B8
954958
955959**f64.convert_i64_s**
956960
957961\$B9
958962
959963**f64.convert_i64_u**
960964
961965\$BA
962966
963967**f64.promote_f32**
964968
965969\$BB
966970
967971**i32.reinterpret_f32**
968972
969973\$BC
970974
971975**i64.reinterpret_f64**
972976
973977\$BD
974978
975979**f32.reinterpret_i32**
976980
977981\$BE
978982
979983**f64.reinterpret_i64**
980984
981985\$BF
982986
983987## See Also
984988
985989- [[WebAssembly]]
986990- <http://webassembly.github.io/spec/core/intro/index.html> - official documentation
987991
988992---
989993*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).*
990994Category: WebAssembly

Back to history