OpLayoutsAsmJs.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #ifdef ASMJS_PLAT
  7. namespace Js
  8. {
  9. ///----------------------------------------------------------------------------
  10. ///
  11. /// enum OpCodeAsmJs
  12. ///
  13. /// OpCodeAsmJs defines the set of p-code instructions available for byte-code in Asm.Js.
  14. ///
  15. ///----------------------------------------------------------------------------
  16. enum class OpCodeAsmJs : ushort {
  17. #define DEF_OP(x, y, ...) x,
  18. #include "OpCodeListAsmJs.h"
  19. MaxByteSizedOpcodes = 255,
  20. #include "ExtendedOpCodeListAsmJs.h"
  21. ByteCodeLast,
  22. #undef DEF_OP
  23. Count // Number of operations
  24. };
  25. inline OpCodeAsmJs operator+(OpCodeAsmJs o1, OpCodeAsmJs o2) { return (OpCodeAsmJs)((uint)o1 + (uint)o2); }
  26. inline uint operator+(OpCodeAsmJs o1, uint i) { return ((uint)o1 + i); }
  27. inline uint operator+(uint i, OpCodeAsmJs &o2) { return (i + (uint)o2); }
  28. inline OpCodeAsmJs operator++(OpCodeAsmJs &o) { return o = (OpCodeAsmJs)(o + 1U); }
  29. inline OpCodeAsmJs operator++(OpCodeAsmJs &o, int) { OpCodeAsmJs prev_o = o; o = (OpCodeAsmJs)(o + 1U); return prev_o; }
  30. inline OpCodeAsmJs operator-(OpCodeAsmJs o1, OpCodeAsmJs o2) { return (OpCodeAsmJs)((uint)o1 - (uint)o2); }
  31. inline uint operator-(OpCodeAsmJs o1, uint i) { return ((uint)o1 - i); }
  32. inline uint operator-(uint i, OpCodeAsmJs &o2) { return (i - (uint)o2); }
  33. inline OpCodeAsmJs operator--(OpCodeAsmJs &o) { return o = (OpCodeAsmJs)(o - 1U); }
  34. inline OpCodeAsmJs operator--(OpCodeAsmJs &o, int) { return o = (OpCodeAsmJs)(o - 1U); }
  35. inline uint operator<<(OpCodeAsmJs o1, uint i) { return ((uint)o1 << i); }
  36. inline OpCodeAsmJs& operator+=(OpCodeAsmJs &o, uint i) { return (o = (OpCodeAsmJs)(o + i)); }
  37. inline OpCodeAsmJs& operator-=(OpCodeAsmJs &o, uint i) { return (o = (OpCodeAsmJs)(o - i)); }
  38. inline bool operator==(OpCodeAsmJs &o, uint i) { return ((uint)(o) == i); }
  39. inline bool operator==(uint i, OpCodeAsmJs &o) { return (i == (uint)(o)); }
  40. inline bool operator!=(OpCodeAsmJs &o, uint i) { return ((uint)(o) != i); }
  41. inline bool operator!=(uint i, OpCodeAsmJs &o) { return (i != (uint)(o)); }
  42. inline bool operator<(OpCodeAsmJs &o, uint i) { return ((uint)(o) < i); }
  43. inline bool operator<(uint i, OpCodeAsmJs &o) { return (i < (uint)(o)); }
  44. inline bool operator<=(OpCodeAsmJs &o, uint i) { return ((uint)(o) <= i); }
  45. inline bool operator<=(uint i, OpCodeAsmJs &o) { return (i <= (uint)(o)); }
  46. inline bool operator<=(OpCodeAsmJs o1, OpCode o2) { return ((OpCode)o1 <= (o2)); }
  47. inline bool operator>(OpCodeAsmJs &o, uint i) { return ((uint)(o) > i); }
  48. inline bool operator>(uint i, OpCodeAsmJs &o) { return (i > (uint)(o)); }
  49. inline bool operator>=(OpCodeAsmJs &o, uint i) { return ((uint)(o) >= i); }
  50. inline bool operator>=(uint i, OpCodeAsmJs &o) { return (i >= (uint)(o)); }
  51. inline BOOL IsSimd128AsmJsOpcode(OpCodeAsmJs o)
  52. {
  53. return (o > Js::OpCodeAsmJs::Simd128_Start && o < Js::OpCodeAsmJs::Simd128_End) || (o > Js::OpCodeAsmJs::Simd128_Start_Extend && o < Js::OpCodeAsmJs::Simd128_End_Extend);
  54. }
  55. inline uint Simd128AsmJsOpcodeCount()
  56. {
  57. return (uint)(Js::OpCodeAsmJs::Simd128_End - Js::OpCodeAsmJs::Simd128_Start) + 1 + (uint)(Js::OpCodeAsmJs::Simd128_End_Extend - Js::OpCodeAsmJs::Simd128_Start_Extend) + 1;
  58. }
  59. ///----------------------------------------------------------------------------
  60. ///
  61. /// enum OpLayoutTypeAsmJs
  62. ///
  63. /// OpLayoutTypeAsmJs defines a set of layouts available for OpCodes. These layouts
  64. /// correspond to "OpLayout" structs defined below, such as "OpLayoutReg1".
  65. ///
  66. ///----------------------------------------------------------------------------
  67. BEGIN_ENUM_UINT( OpLayoutTypeAsmJs )
  68. // This define only one enum for each layout type, but not for each layout variant
  69. #define LAYOUT_TYPE(x) x,
  70. #define LAYOUT_TYPE_WMS LAYOUT_TYPE
  71. #include "LayoutTypesAsmJs.h"
  72. Count,
  73. END_ENUM_UINT()
  74. #pragma pack(push, 1)
  75. /// Asm.js Layout
  76. template <typename SizePolicy>
  77. struct OpLayoutT_AsmTypedArr
  78. {
  79. // force encode 4 bytes because it can be a value
  80. uint32 SlotIndex;
  81. typename SizePolicy::RegSlotType Value;
  82. Js::ArrayBufferView::ViewType ViewType;
  83. };
  84. template <typename SizePolicy>
  85. struct OpLayoutT_WasmMemAccess
  86. {
  87. uint32 Offset;
  88. typename SizePolicy::RegSlotType SlotIndex;
  89. typename SizePolicy::RegSlotType Value;
  90. Js::ArrayBufferView::ViewType ViewType;
  91. };
  92. template <typename SizePolicy>
  93. struct OpLayoutT_AsmCall
  94. {
  95. typename SizePolicy::ArgSlotType ArgCount;
  96. typename SizePolicy::RegSlotSType Return;
  97. typename SizePolicy::RegSlotType Function;
  98. int8 ReturnType;
  99. };
  100. template <typename SizePolicy>
  101. struct OpLayoutT_AsmReg1
  102. {
  103. typename SizePolicy::RegSlotType R0;
  104. };
  105. template <typename SizePolicy>
  106. struct OpLayoutT_AsmReg2
  107. {
  108. typename SizePolicy::RegSlotType R0;
  109. typename SizePolicy::RegSlotType R1;
  110. };
  111. template <typename SizePolicy>
  112. struct OpLayoutT_AsmReg3
  113. {
  114. typename SizePolicy::RegSlotType R0;
  115. typename SizePolicy::RegSlotType R1;
  116. typename SizePolicy::RegSlotType R2;
  117. };
  118. template <typename SizePolicy>
  119. struct OpLayoutT_AsmReg4
  120. {
  121. typename SizePolicy::RegSlotType R0;
  122. typename SizePolicy::RegSlotType R1;
  123. typename SizePolicy::RegSlotType R2;
  124. typename SizePolicy::RegSlotType R3;
  125. };
  126. template <typename SizePolicy>
  127. struct OpLayoutT_AsmReg5
  128. {
  129. typename SizePolicy::RegSlotType R0;
  130. typename SizePolicy::RegSlotType R1;
  131. typename SizePolicy::RegSlotType R2;
  132. typename SizePolicy::RegSlotType R3;
  133. typename SizePolicy::RegSlotType R4;
  134. };
  135. template <typename SizePolicy>
  136. struct OpLayoutT_AsmReg6
  137. {
  138. typename SizePolicy::RegSlotType R0;
  139. typename SizePolicy::RegSlotType R1;
  140. typename SizePolicy::RegSlotType R2;
  141. typename SizePolicy::RegSlotType R3;
  142. typename SizePolicy::RegSlotType R4;
  143. typename SizePolicy::RegSlotType R5;
  144. };
  145. template <typename SizePolicy>
  146. struct OpLayoutT_AsmReg7
  147. {
  148. typename SizePolicy::RegSlotType R0;
  149. typename SizePolicy::RegSlotType R1;
  150. typename SizePolicy::RegSlotType R2;
  151. typename SizePolicy::RegSlotType R3;
  152. typename SizePolicy::RegSlotType R4;
  153. typename SizePolicy::RegSlotType R5;
  154. typename SizePolicy::RegSlotType R6;
  155. };
  156. template <typename SizePolicy>
  157. struct OpLayoutT_AsmReg9
  158. {
  159. typename SizePolicy::RegSlotType R0;
  160. typename SizePolicy::RegSlotType R1;
  161. typename SizePolicy::RegSlotType R2;
  162. typename SizePolicy::RegSlotType R3;
  163. typename SizePolicy::RegSlotType R4;
  164. typename SizePolicy::RegSlotType R5;
  165. typename SizePolicy::RegSlotType R6;
  166. typename SizePolicy::RegSlotType R7;
  167. typename SizePolicy::RegSlotType R8;
  168. };
  169. template <typename SizePolicy>
  170. struct OpLayoutT_AsmReg10
  171. {
  172. typename SizePolicy::RegSlotType R0;
  173. typename SizePolicy::RegSlotType R1;
  174. typename SizePolicy::RegSlotType R2;
  175. typename SizePolicy::RegSlotType R3;
  176. typename SizePolicy::RegSlotType R4;
  177. typename SizePolicy::RegSlotType R5;
  178. typename SizePolicy::RegSlotType R6;
  179. typename SizePolicy::RegSlotType R7;
  180. typename SizePolicy::RegSlotType R8;
  181. typename SizePolicy::RegSlotType R9;
  182. };
  183. template <typename SizePolicy>
  184. struct OpLayoutT_AsmReg11
  185. {
  186. typename SizePolicy::RegSlotType R0;
  187. typename SizePolicy::RegSlotType R1;
  188. typename SizePolicy::RegSlotType R2;
  189. typename SizePolicy::RegSlotType R3;
  190. typename SizePolicy::RegSlotType R4;
  191. typename SizePolicy::RegSlotType R5;
  192. typename SizePolicy::RegSlotType R6;
  193. typename SizePolicy::RegSlotType R7;
  194. typename SizePolicy::RegSlotType R8;
  195. typename SizePolicy::RegSlotType R9;
  196. typename SizePolicy::RegSlotType R10;
  197. };
  198. template <typename SizePolicy>
  199. struct OpLayoutT_AsmReg17
  200. {
  201. typename SizePolicy::RegSlotType R0;
  202. typename SizePolicy::RegSlotType R1;
  203. typename SizePolicy::RegSlotType R2;
  204. typename SizePolicy::RegSlotType R3;
  205. typename SizePolicy::RegSlotType R4;
  206. typename SizePolicy::RegSlotType R5;
  207. typename SizePolicy::RegSlotType R6;
  208. typename SizePolicy::RegSlotType R7;
  209. typename SizePolicy::RegSlotType R8;
  210. typename SizePolicy::RegSlotType R9;
  211. typename SizePolicy::RegSlotType R10;
  212. typename SizePolicy::RegSlotType R11;
  213. typename SizePolicy::RegSlotType R12;
  214. typename SizePolicy::RegSlotType R13;
  215. typename SizePolicy::RegSlotType R14;
  216. typename SizePolicy::RegSlotType R15;
  217. typename SizePolicy::RegSlotType R16;
  218. };
  219. template <typename SizePolicy>
  220. struct OpLayoutT_AsmReg18
  221. {
  222. typename SizePolicy::RegSlotType R0;
  223. typename SizePolicy::RegSlotType R1;
  224. typename SizePolicy::RegSlotType R2;
  225. typename SizePolicy::RegSlotType R3;
  226. typename SizePolicy::RegSlotType R4;
  227. typename SizePolicy::RegSlotType R5;
  228. typename SizePolicy::RegSlotType R6;
  229. typename SizePolicy::RegSlotType R7;
  230. typename SizePolicy::RegSlotType R8;
  231. typename SizePolicy::RegSlotType R9;
  232. typename SizePolicy::RegSlotType R10;
  233. typename SizePolicy::RegSlotType R11;
  234. typename SizePolicy::RegSlotType R12;
  235. typename SizePolicy::RegSlotType R13;
  236. typename SizePolicy::RegSlotType R14;
  237. typename SizePolicy::RegSlotType R15;
  238. typename SizePolicy::RegSlotType R16;
  239. typename SizePolicy::RegSlotType R17;
  240. };
  241. template <typename SizePolicy>
  242. struct OpLayoutT_AsmReg19
  243. {
  244. typename SizePolicy::RegSlotType R0;
  245. typename SizePolicy::RegSlotType R1;
  246. typename SizePolicy::RegSlotType R2;
  247. typename SizePolicy::RegSlotType R3;
  248. typename SizePolicy::RegSlotType R4;
  249. typename SizePolicy::RegSlotType R5;
  250. typename SizePolicy::RegSlotType R6;
  251. typename SizePolicy::RegSlotType R7;
  252. typename SizePolicy::RegSlotType R8;
  253. typename SizePolicy::RegSlotType R9;
  254. typename SizePolicy::RegSlotType R10;
  255. typename SizePolicy::RegSlotType R11;
  256. typename SizePolicy::RegSlotType R12;
  257. typename SizePolicy::RegSlotType R13;
  258. typename SizePolicy::RegSlotType R14;
  259. typename SizePolicy::RegSlotType R15;
  260. typename SizePolicy::RegSlotType R16;
  261. typename SizePolicy::RegSlotType R17;
  262. typename SizePolicy::RegSlotType R18;
  263. };
  264. #define RegLayoutType typename SizePolicy::RegSlotType
  265. #define IntLayoutType typename SizePolicy::RegSlotType
  266. #define LongLayoutType typename SizePolicy::RegSlotType
  267. #define FloatLayoutType typename SizePolicy::RegSlotType
  268. #define DoubleLayoutType typename SizePolicy::RegSlotType
  269. #define IntConstLayoutType int
  270. #define LongConstLayoutType int64
  271. #define FloatConstLayoutType float
  272. #define DoubleConstLayoutType double
  273. #define Float32x4LayoutType typename SizePolicy::RegSlotType
  274. #define Bool32x4LayoutType typename SizePolicy::RegSlotType
  275. #define Int32x4LayoutType typename SizePolicy::RegSlotType
  276. #define Float64x2LayoutType typename SizePolicy::RegSlotType
  277. #define Int16x8LayoutType typename SizePolicy::RegSlotType
  278. #define Bool16x8LayoutType typename SizePolicy::RegSlotType
  279. #define Int8x16LayoutType typename SizePolicy::RegSlotType
  280. #define Bool8x16LayoutType typename SizePolicy::RegSlotType
  281. #define Uint32x4LayoutType typename SizePolicy::RegSlotType
  282. #define Uint16x8LayoutType typename SizePolicy::RegSlotType
  283. #define Uint8x16LayoutType typename SizePolicy::RegSlotType
  284. #define LAYOUT_FIELDS_HELPER(x, y) x ## y
  285. #define LAYOUT_FIELDS_DEF(x, y) LAYOUT_FIELDS_HELPER(x, y)
  286. #define LAYOUT_TYPE_WMS_REG2(layout, t0, t1) \
  287. template <typename SizePolicy> struct OpLayoutT_##layout\
  288. {\
  289. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  290. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  291. };
  292. #define LAYOUT_TYPE_WMS_REG3(layout, t0, t1, t2) \
  293. template <typename SizePolicy> struct OpLayoutT_##layout\
  294. {\
  295. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  296. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  297. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  298. };
  299. #define LAYOUT_TYPE_WMS_REG4(layout, t0, t1, t2, t3)\
  300. template <typename SizePolicy> struct OpLayoutT_##layout\
  301. {\
  302. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  303. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  304. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  305. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  306. };
  307. #define LAYOUT_TYPE_WMS_REG5(layout, t0, t1, t2, t3, t4)\
  308. template <typename SizePolicy> struct OpLayoutT_##layout\
  309. {\
  310. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  311. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  312. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  313. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  314. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  315. };
  316. #define LAYOUT_TYPE_WMS_REG6(layout, t0, t1, t2, t3, t4, t5)\
  317. template <typename SizePolicy> struct OpLayoutT_##layout\
  318. {\
  319. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  320. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  321. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  322. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  323. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  324. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  325. };
  326. #define LAYOUT_TYPE_WMS_REG7(layout, t0, t1, t2, t3, t4, t5, t6)\
  327. template <typename SizePolicy> struct OpLayoutT_##layout\
  328. {\
  329. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  330. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  331. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  332. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  333. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  334. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  335. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  336. };
  337. #define LAYOUT_TYPE_WMS_REG9(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8)\
  338. template <typename SizePolicy> struct OpLayoutT_##layout\
  339. {\
  340. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  341. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  342. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  343. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  344. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  345. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  346. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  347. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  348. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  349. };
  350. #define LAYOUT_TYPE_WMS_REG10(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)\
  351. template <typename SizePolicy> struct OpLayoutT_##layout\
  352. {\
  353. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  354. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  355. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  356. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  357. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  358. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  359. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  360. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  361. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  362. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  363. };
  364. #define LAYOUT_TYPE_WMS_REG11(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)\
  365. template <typename SizePolicy> struct OpLayoutT_##layout\
  366. {\
  367. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  368. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  369. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  370. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  371. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  372. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  373. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  374. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  375. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  376. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  377. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  378. };
  379. #define LAYOUT_TYPE_WMS_REG17(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)\
  380. template <typename SizePolicy> struct OpLayoutT_##layout\
  381. {\
  382. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  383. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  384. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  385. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  386. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  387. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  388. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  389. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  390. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  391. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  392. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  393. t11##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t11(), 11);\
  394. t12##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t12(), 12);\
  395. t13##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t13(), 13);\
  396. t14##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t14(), 14);\
  397. t15##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t15(), 15);\
  398. t16##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t16(), 16);\
  399. };
  400. #define LAYOUT_TYPE_WMS_REG18(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17)\
  401. template <typename SizePolicy> struct OpLayoutT_##layout\
  402. {\
  403. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  404. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  405. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  406. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  407. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  408. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  409. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  410. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  411. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  412. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  413. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  414. t11##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t11(), 11);\
  415. t12##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t12(), 12);\
  416. t13##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t13(), 13);\
  417. t14##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t14(), 14);\
  418. t15##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t15(), 15);\
  419. t16##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t16(), 16);\
  420. t17##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t17(), 17);\
  421. };
  422. #define LAYOUT_TYPE_WMS_REG19(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18)\
  423. template <typename SizePolicy> struct OpLayoutT_##layout\
  424. {\
  425. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  426. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  427. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  428. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  429. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  430. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  431. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  432. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  433. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  434. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  435. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  436. t11##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t11(), 11);\
  437. t12##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t12(), 12);\
  438. t13##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t13(), 13);\
  439. t14##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t14(), 14);\
  440. t15##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t15(), 15);\
  441. t16##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t16(), 16);\
  442. t17##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t17(), 17);\
  443. t18##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t18(), 18);\
  444. };
  445. #include "LayoutTypesAsmJs.h"
  446. #undef RegLayoutType
  447. #undef IntLayoutType
  448. #undef LongLayoutType
  449. #undef FloatLayoutType
  450. #undef DoubleLayoutType
  451. #undef IntConstLayoutType
  452. #undef LongConstLayoutType
  453. #undef FloatConstLayoutType
  454. #undef DoubleConstLayoutType
  455. #undef Float32x4LayoutType
  456. #undef Bool32x4LayoutType
  457. #undef Int32x4LayoutType
  458. #undef Float64x2LayoutType
  459. #undef Int16x8LayoutType
  460. #undef Bool16x8LayoutType
  461. #undef Int8x16LayoutType
  462. #undef Bool8x16LayoutType
  463. #undef Uint32x4LayoutType
  464. #undef Uint16x8LayoutType
  465. #undef Uint8x16LayoutType
  466. template <typename SizePolicy>
  467. struct OpLayoutT_AsmUnsigned1
  468. {
  469. typename SizePolicy::UnsignedType C1;
  470. };
  471. struct OpLayoutAsmBr
  472. {
  473. int32 RelativeJumpOffset;
  474. };
  475. template <typename SizePolicy>
  476. struct OpLayoutT_BrInt1
  477. {
  478. int32 RelativeJumpOffset;
  479. typename SizePolicy::RegSlotType I1;
  480. };
  481. template <typename SizePolicy>
  482. struct OpLayoutT_BrInt2
  483. {
  484. int32 RelativeJumpOffset;
  485. typename SizePolicy::RegSlotType I1;
  486. typename SizePolicy::RegSlotType I2;
  487. };
  488. template <typename SizePolicy>
  489. struct OpLayoutT_BrInt1Const1
  490. {
  491. int32 RelativeJumpOffset;
  492. typename SizePolicy::RegSlotType I1;
  493. int32 C1;
  494. };
  495. template <typename SizePolicy>
  496. struct OpLayoutT_AsmSimdTypedArr
  497. {
  498. // force encode 4 bytes because it can be a value
  499. uint32 SlotIndex;
  500. typename SizePolicy::RegSlotType Value;
  501. ArrayBufferView::ViewType ViewType;
  502. int8 DataWidth; // # of bytes to load/store
  503. };
  504. // Generate the multi size layout type defs
  505. #define LAYOUT_TYPE_WMS(layout) \
  506. typedef OpLayoutT_##layout<LargeLayoutSizePolicy> OpLayout##layout##_Large; \
  507. typedef OpLayoutT_##layout<MediumLayoutSizePolicy> OpLayout##layout##_Medium; \
  508. typedef OpLayoutT_##layout<SmallLayoutSizePolicy> OpLayout##layout##_Small;
  509. #include "LayoutTypesAsmJs.h"
  510. #pragma pack(pop)
  511. // Generate structure to automatically map layout to its info
  512. template <OpLayoutTypeAsmJs::_E layout> struct OpLayoutInfoAsmJs;
  513. #define LAYOUT_TYPE(layout) \
  514. CompileAssert(sizeof(OpLayout##layout) <= MaxLayoutSize); \
  515. template <> struct OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout> \
  516. { \
  517. static const bool HasMultiSizeLayout = false; \
  518. };
  519. #define LAYOUT_TYPE_WMS(layout) \
  520. CompileAssert(sizeof(OpLayout##layout##_Large) <= MaxLayoutSize); \
  521. template <> struct OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout> \
  522. { \
  523. static const bool HasMultiSizeLayout = true; \
  524. };
  525. #include "LayoutTypesAsmJs.h"
  526. // Generate structure to automatically map opcode to its info
  527. // Also generate assert to make sure the layout and opcode use the same macro with and without multiple size layout
  528. template <OpCodeAsmJs opcode> struct OpCodeInfoAsmJs;
  529. #define DEFINE_OPCODEINFO(op, layout, extended) \
  530. CompileAssert(!OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout>::HasMultiSizeLayout); \
  531. template <> struct OpCodeInfoAsmJs<OpCodeAsmJs::op> \
  532. { \
  533. static const OpLayoutTypeAsmJs::_E Layout = OpLayoutTypeAsmJs::layout; \
  534. static const bool HasMultiSizeLayout = false; \
  535. static const bool IsExtendedOpcode = extended; \
  536. typedef OpLayout##layout LayoutType; \
  537. };
  538. #define DEFINE_OPCODEINFO_WMS(op, layout, extended) \
  539. CompileAssert(OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout>::HasMultiSizeLayout); \
  540. template <> struct OpCodeInfoAsmJs<OpCodeAsmJs::op> \
  541. { \
  542. static const OpLayoutTypeAsmJs::_E Layout = OpLayoutTypeAsmJs::layout; \
  543. static const bool HasMultiSizeLayout = true; \
  544. static const bool IsExtendedOpcode = extended; \
  545. typedef OpLayout##layout##_Large LayoutType_Large; \
  546. typedef OpLayout##layout##_Medium LayoutType_Medium; \
  547. typedef OpLayout##layout##_Small LayoutType_Small; \
  548. };
  549. #define MACRO(op, layout, ...) DEFINE_OPCODEINFO(op, layout, false)
  550. #define MACRO_WMS(op, layout, ...) DEFINE_OPCODEINFO_WMS(op, layout, false)
  551. #define MACRO_EXTEND(op, layout, ...) DEFINE_OPCODEINFO(op, layout, true)
  552. #define MACRO_EXTEND_WMS(op, layout, ...) DEFINE_OPCODEINFO_WMS(op, layout, true)
  553. #include "OpCodesAsmJs.h"
  554. #undef DEFINE_OPCODEINFO
  555. #undef DEFINE_OPCODEINFO_WMS
  556. }
  557. #endif