Opcode.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DistinctNumeric.h>
  8. namespace Wasm {
  9. TYPEDEF_DISTINCT_ORDERED_ID(u32, OpCode);
  10. namespace Instructions {
  11. static constexpr OpCode unreachable = 0x00,
  12. nop = 0x01,
  13. block = 0x02,
  14. loop = 0x03,
  15. if_ = 0x04,
  16. br = 0x0c,
  17. br_if = 0x0d,
  18. br_table = 0x0e,
  19. return_ = 0x0f,
  20. call = 0x10,
  21. call_indirect = 0x11,
  22. drop = 0x1a,
  23. select = 0x1b,
  24. select_typed = 0x1c,
  25. local_get = 0x20,
  26. local_set = 0x21,
  27. local_tee = 0x22,
  28. global_get = 0x23,
  29. global_set = 0x24,
  30. table_get = 0x25,
  31. table_set = 0x26,
  32. i32_load = 0x28,
  33. i64_load = 0x29,
  34. f32_load = 0x2a,
  35. f64_load = 0x2b,
  36. i32_load8_s = 0x2c,
  37. i32_load8_u = 0x2d,
  38. i32_load16_s = 0x2e,
  39. i32_load16_u = 0x2f,
  40. i64_load8_s = 0x30,
  41. i64_load8_u = 0x31,
  42. i64_load16_s = 0x32,
  43. i64_load16_u = 0x33,
  44. i64_load32_s = 0x34,
  45. i64_load32_u = 0x35,
  46. i32_store = 0x36,
  47. i64_store = 0x37,
  48. f32_store = 0x38,
  49. f64_store = 0x39,
  50. i32_store8 = 0x3a,
  51. i32_store16 = 0x3b,
  52. i64_store8 = 0x3c,
  53. i64_store16 = 0x3d,
  54. i64_store32 = 0x3e,
  55. memory_size = 0x3f,
  56. memory_grow = 0x40,
  57. i32_const = 0x41,
  58. i64_const = 0x42,
  59. f32_const = 0x43,
  60. f64_const = 0x44,
  61. i32_eqz = 0x45,
  62. i32_eq = 0x46,
  63. i32_ne = 0x47,
  64. i32_lts = 0x48,
  65. i32_ltu = 0x49,
  66. i32_gts = 0x4a,
  67. i32_gtu = 0x4b,
  68. i32_les = 0x4c,
  69. i32_leu = 0x4d,
  70. i32_ges = 0x4e,
  71. i32_geu = 0x4f,
  72. i64_eqz = 0x50,
  73. i64_eq = 0x51,
  74. i64_ne = 0x52,
  75. i64_lts = 0x53,
  76. i64_ltu = 0x54,
  77. i64_gts = 0x55,
  78. i64_gtu = 0x56,
  79. i64_les = 0x57,
  80. i64_leu = 0x58,
  81. i64_ges = 0x59,
  82. i64_geu = 0x5a,
  83. f32_eq = 0x5b,
  84. f32_ne = 0x5c,
  85. f32_lt = 0x5d,
  86. f32_gt = 0x5e,
  87. f32_le = 0x5f,
  88. f32_ge = 0x60,
  89. f64_eq = 0x61,
  90. f64_ne = 0x62,
  91. f64_lt = 0x63,
  92. f64_gt = 0x64,
  93. f64_le = 0x65,
  94. f64_ge = 0x66,
  95. i32_clz = 0x67,
  96. i32_ctz = 0x68,
  97. i32_popcnt = 0x69,
  98. i32_add = 0x6a,
  99. i32_sub = 0x6b,
  100. i32_mul = 0x6c,
  101. i32_divs = 0x6d,
  102. i32_divu = 0x6e,
  103. i32_rems = 0x6f,
  104. i32_remu = 0x70,
  105. i32_and = 0x71,
  106. i32_or = 0x72,
  107. i32_xor = 0x73,
  108. i32_shl = 0x74,
  109. i32_shrs = 0x75,
  110. i32_shru = 0x76,
  111. i32_rotl = 0x77,
  112. i32_rotr = 0x78,
  113. i64_clz = 0x79,
  114. i64_ctz = 0x7a,
  115. i64_popcnt = 0x7b,
  116. i64_add = 0x7c,
  117. i64_sub = 0x7d,
  118. i64_mul = 0x7e,
  119. i64_divs = 0x7f,
  120. i64_divu = 0x80,
  121. i64_rems = 0x81,
  122. i64_remu = 0x82,
  123. i64_and = 0x83,
  124. i64_or = 0x84,
  125. i64_xor = 0x85,
  126. i64_shl = 0x86,
  127. i64_shrs = 0x87,
  128. i64_shru = 0x88,
  129. i64_rotl = 0x89,
  130. i64_rotr = 0x8a,
  131. f32_abs = 0x8b,
  132. f32_neg = 0x8c,
  133. f32_ceil = 0x8d,
  134. f32_floor = 0x8e,
  135. f32_trunc = 0x8f,
  136. f32_nearest = 0x90,
  137. f32_sqrt = 0x91,
  138. f32_add = 0x92,
  139. f32_sub = 0x93,
  140. f32_mul = 0x94,
  141. f32_div = 0x95,
  142. f32_min = 0x96,
  143. f32_max = 0x97,
  144. f32_copysign = 0x98,
  145. f64_abs = 0x99,
  146. f64_neg = 0x9a,
  147. f64_ceil = 0x9b,
  148. f64_floor = 0x9c,
  149. f64_trunc = 0x9d,
  150. f64_nearest = 0x9e,
  151. f64_sqrt = 0x9f,
  152. f64_add = 0xa0,
  153. f64_sub = 0xa1,
  154. f64_mul = 0xa2,
  155. f64_div = 0xa3,
  156. f64_min = 0xa4,
  157. f64_max = 0xa5,
  158. f64_copysign = 0xa6,
  159. i32_wrap_i64 = 0xa7,
  160. i32_trunc_sf32 = 0xa8,
  161. i32_trunc_uf32 = 0xa9,
  162. i32_trunc_sf64 = 0xaa,
  163. i32_trunc_uf64 = 0xab,
  164. i64_extend_si32 = 0xac,
  165. i64_extend_ui32 = 0xad,
  166. i64_trunc_sf32 = 0xae,
  167. i64_trunc_uf32 = 0xaf,
  168. i64_trunc_sf64 = 0xb0,
  169. i64_trunc_uf64 = 0xb1,
  170. f32_convert_si32 = 0xb2,
  171. f32_convert_ui32 = 0xb3,
  172. f32_convert_si64 = 0xb4,
  173. f32_convert_ui64 = 0xb5,
  174. f32_demote_f64 = 0xb6,
  175. f64_convert_si32 = 0xb7,
  176. f64_convert_ui32 = 0xb8,
  177. f64_convert_si64 = 0xb9,
  178. f64_convert_ui64 = 0xba,
  179. f64_promote_f32 = 0xbb,
  180. i32_reinterpret_f32 = 0xbc,
  181. i64_reinterpret_f64 = 0xbd,
  182. f32_reinterpret_i32 = 0xbe,
  183. f64_reinterpret_i64 = 0xbf,
  184. i32_extend8_s = 0xc0,
  185. i32_extend16_s = 0xc1,
  186. i64_extend8_s = 0xc2,
  187. i64_extend16_s = 0xc3,
  188. i64_extend32_s = 0xc4,
  189. ref_null = 0xd0,
  190. ref_is_null = 0xd1,
  191. ref_func = 0xd2;
  192. // These are synthetic opcodes, they are _not_ seen in wasm with these values.
  193. static constexpr OpCode i32_trunc_sat_f32_s = 0xfc00,
  194. i32_trunc_sat_f32_u = 0xfc01,
  195. i32_trunc_sat_f64_s = 0xfc02,
  196. i32_trunc_sat_f64_u = 0xfc03,
  197. i64_trunc_sat_f32_s = 0xfc04,
  198. i64_trunc_sat_f32_u = 0xfc05,
  199. i64_trunc_sat_f64_s = 0xfc06,
  200. i64_trunc_sat_f64_u = 0xfc07,
  201. memory_init = 0xfc08,
  202. data_drop = 0xfc09,
  203. memory_copy = 0xfc0a,
  204. memory_fill = 0x0fc0b,
  205. table_init = 0xfc0c,
  206. elem_drop = 0xfc0d,
  207. table_copy = 0xfc0e,
  208. table_grow = 0xfc0f,
  209. table_size = 0xfc10,
  210. table_fill = 0xfc11,
  211. structured_else = 0xff00,
  212. structured_end = 0xff01;
  213. static constexpr u32 i32_trunc_sat_f32_s_second = 0,
  214. i32_trunc_sat_f32_u_second = 1,
  215. i32_trunc_sat_f64_s_second = 2,
  216. i32_trunc_sat_f64_u_second = 3,
  217. i64_trunc_sat_f32_s_second = 4,
  218. i64_trunc_sat_f32_u_second = 5,
  219. i64_trunc_sat_f64_s_second = 6,
  220. i64_trunc_sat_f64_u_second = 7,
  221. memory_init_second = 8,
  222. data_drop_second = 9,
  223. memory_copy_second = 10,
  224. memory_fill_second = 11,
  225. table_init_second = 12,
  226. elem_drop_second = 13,
  227. table_copy_second = 14,
  228. table_grow_second = 15,
  229. table_size_second = 16,
  230. table_fill_second = 17;
  231. }
  232. }