OpLayoutsAsmJs.h 27 KB

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