OpLayoutsAsmJs.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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. int8 ViewType;
  83. };
  84. template <typename SizePolicy>
  85. struct OpLayoutT_AsmCall
  86. {
  87. typename SizePolicy::ArgSlotType ArgCount;
  88. typename SizePolicy::RegSlotSType Return;
  89. typename SizePolicy::RegSlotType Function;
  90. int8 ReturnType;
  91. };
  92. template <typename SizePolicy>
  93. struct OpLayoutT_AsmReg1
  94. {
  95. typename SizePolicy::RegSlotType R0;
  96. };
  97. template <typename SizePolicy>
  98. struct OpLayoutT_AsmReg2
  99. {
  100. typename SizePolicy::RegSlotType R0;
  101. typename SizePolicy::RegSlotType R1;
  102. };
  103. template <typename SizePolicy>
  104. struct OpLayoutT_AsmReg3
  105. {
  106. typename SizePolicy::RegSlotType R0;
  107. typename SizePolicy::RegSlotType R1;
  108. typename SizePolicy::RegSlotType R2;
  109. };
  110. template <typename SizePolicy>
  111. struct OpLayoutT_AsmReg4
  112. {
  113. typename SizePolicy::RegSlotType R0;
  114. typename SizePolicy::RegSlotType R1;
  115. typename SizePolicy::RegSlotType R2;
  116. typename SizePolicy::RegSlotType R3;
  117. };
  118. template <typename SizePolicy>
  119. struct OpLayoutT_AsmReg5
  120. {
  121. typename SizePolicy::RegSlotType R0;
  122. typename SizePolicy::RegSlotType R1;
  123. typename SizePolicy::RegSlotType R2;
  124. typename SizePolicy::RegSlotType R3;
  125. typename SizePolicy::RegSlotType R4;
  126. };
  127. template <typename SizePolicy>
  128. struct OpLayoutT_AsmReg6
  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. typename SizePolicy::RegSlotType R5;
  136. };
  137. template <typename SizePolicy>
  138. struct OpLayoutT_AsmReg7
  139. {
  140. typename SizePolicy::RegSlotType R0;
  141. typename SizePolicy::RegSlotType R1;
  142. typename SizePolicy::RegSlotType R2;
  143. typename SizePolicy::RegSlotType R3;
  144. typename SizePolicy::RegSlotType R4;
  145. typename SizePolicy::RegSlotType R5;
  146. typename SizePolicy::RegSlotType R6;
  147. };
  148. template <typename SizePolicy>
  149. struct OpLayoutT_AsmReg9
  150. {
  151. typename SizePolicy::RegSlotType R0;
  152. typename SizePolicy::RegSlotType R1;
  153. typename SizePolicy::RegSlotType R2;
  154. typename SizePolicy::RegSlotType R3;
  155. typename SizePolicy::RegSlotType R4;
  156. typename SizePolicy::RegSlotType R5;
  157. typename SizePolicy::RegSlotType R6;
  158. typename SizePolicy::RegSlotType R7;
  159. typename SizePolicy::RegSlotType R8;
  160. };
  161. template <typename SizePolicy>
  162. struct OpLayoutT_AsmReg10
  163. {
  164. typename SizePolicy::RegSlotType R0;
  165. typename SizePolicy::RegSlotType R1;
  166. typename SizePolicy::RegSlotType R2;
  167. typename SizePolicy::RegSlotType R3;
  168. typename SizePolicy::RegSlotType R4;
  169. typename SizePolicy::RegSlotType R5;
  170. typename SizePolicy::RegSlotType R6;
  171. typename SizePolicy::RegSlotType R7;
  172. typename SizePolicy::RegSlotType R8;
  173. typename SizePolicy::RegSlotType R9;
  174. };
  175. template <typename SizePolicy>
  176. struct OpLayoutT_AsmReg11
  177. {
  178. typename SizePolicy::RegSlotType R0;
  179. typename SizePolicy::RegSlotType R1;
  180. typename SizePolicy::RegSlotType R2;
  181. typename SizePolicy::RegSlotType R3;
  182. typename SizePolicy::RegSlotType R4;
  183. typename SizePolicy::RegSlotType R5;
  184. typename SizePolicy::RegSlotType R6;
  185. typename SizePolicy::RegSlotType R7;
  186. typename SizePolicy::RegSlotType R8;
  187. typename SizePolicy::RegSlotType R9;
  188. typename SizePolicy::RegSlotType R10;
  189. };
  190. template <typename SizePolicy>
  191. struct OpLayoutT_AsmReg17
  192. {
  193. typename SizePolicy::RegSlotType R0;
  194. typename SizePolicy::RegSlotType R1;
  195. typename SizePolicy::RegSlotType R2;
  196. typename SizePolicy::RegSlotType R3;
  197. typename SizePolicy::RegSlotType R4;
  198. typename SizePolicy::RegSlotType R5;
  199. typename SizePolicy::RegSlotType R6;
  200. typename SizePolicy::RegSlotType R7;
  201. typename SizePolicy::RegSlotType R8;
  202. typename SizePolicy::RegSlotType R9;
  203. typename SizePolicy::RegSlotType R10;
  204. typename SizePolicy::RegSlotType R11;
  205. typename SizePolicy::RegSlotType R12;
  206. typename SizePolicy::RegSlotType R13;
  207. typename SizePolicy::RegSlotType R14;
  208. typename SizePolicy::RegSlotType R15;
  209. typename SizePolicy::RegSlotType R16;
  210. };
  211. template <typename SizePolicy>
  212. struct OpLayoutT_AsmReg18
  213. {
  214. typename SizePolicy::RegSlotType R0;
  215. typename SizePolicy::RegSlotType R1;
  216. typename SizePolicy::RegSlotType R2;
  217. typename SizePolicy::RegSlotType R3;
  218. typename SizePolicy::RegSlotType R4;
  219. typename SizePolicy::RegSlotType R5;
  220. typename SizePolicy::RegSlotType R6;
  221. typename SizePolicy::RegSlotType R7;
  222. typename SizePolicy::RegSlotType R8;
  223. typename SizePolicy::RegSlotType R9;
  224. typename SizePolicy::RegSlotType R10;
  225. typename SizePolicy::RegSlotType R11;
  226. typename SizePolicy::RegSlotType R12;
  227. typename SizePolicy::RegSlotType R13;
  228. typename SizePolicy::RegSlotType R14;
  229. typename SizePolicy::RegSlotType R15;
  230. typename SizePolicy::RegSlotType R16;
  231. typename SizePolicy::RegSlotType R17;
  232. };
  233. template <typename SizePolicy>
  234. struct OpLayoutT_AsmReg19
  235. {
  236. typename SizePolicy::RegSlotType R0;
  237. typename SizePolicy::RegSlotType R1;
  238. typename SizePolicy::RegSlotType R2;
  239. typename SizePolicy::RegSlotType R3;
  240. typename SizePolicy::RegSlotType R4;
  241. typename SizePolicy::RegSlotType R5;
  242. typename SizePolicy::RegSlotType R6;
  243. typename SizePolicy::RegSlotType R7;
  244. typename SizePolicy::RegSlotType R8;
  245. typename SizePolicy::RegSlotType R9;
  246. typename SizePolicy::RegSlotType R10;
  247. typename SizePolicy::RegSlotType R11;
  248. typename SizePolicy::RegSlotType R12;
  249. typename SizePolicy::RegSlotType R13;
  250. typename SizePolicy::RegSlotType R14;
  251. typename SizePolicy::RegSlotType R15;
  252. typename SizePolicy::RegSlotType R16;
  253. typename SizePolicy::RegSlotType R17;
  254. typename SizePolicy::RegSlotType R18;
  255. };
  256. #define RegLayoutType typename SizePolicy::RegSlotType
  257. #define IntLayoutType typename SizePolicy::RegSlotType
  258. #define LongLayoutType typename SizePolicy::RegSlotType
  259. #define FloatLayoutType typename SizePolicy::RegSlotType
  260. #define DoubleLayoutType typename SizePolicy::RegSlotType
  261. #define IntConstLayoutType int
  262. #define LongConstLayoutType int64
  263. #define FloatConstLayoutType float
  264. #define DoubleConstLayoutType double
  265. #define Float32x4LayoutType typename SizePolicy::RegSlotType
  266. #define Bool32x4LayoutType typename SizePolicy::RegSlotType
  267. #define Int32x4LayoutType typename SizePolicy::RegSlotType
  268. #define Float64x2LayoutType typename SizePolicy::RegSlotType
  269. #define Int16x8LayoutType typename SizePolicy::RegSlotType
  270. #define Bool16x8LayoutType typename SizePolicy::RegSlotType
  271. #define Int8x16LayoutType typename SizePolicy::RegSlotType
  272. #define Bool8x16LayoutType typename SizePolicy::RegSlotType
  273. #define Uint32x4LayoutType typename SizePolicy::RegSlotType
  274. #define Uint16x8LayoutType typename SizePolicy::RegSlotType
  275. #define Uint8x16LayoutType typename SizePolicy::RegSlotType
  276. #define LAYOUT_FIELDS_HELPER(x, y) x ## y
  277. #define LAYOUT_FIELDS_DEF(x, y) LAYOUT_FIELDS_HELPER(x, y)
  278. #define LAYOUT_TYPE_WMS_REG2(layout, t0, t1) \
  279. template <typename SizePolicy> struct OpLayoutT_##layout\
  280. {\
  281. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  282. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  283. };
  284. #define LAYOUT_TYPE_WMS_REG3(layout, t0, t1, t2) \
  285. template <typename SizePolicy> struct OpLayoutT_##layout\
  286. {\
  287. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  288. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  289. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  290. };
  291. #define LAYOUT_TYPE_WMS_REG4(layout, t0, t1, t2, t3)\
  292. template <typename SizePolicy> struct OpLayoutT_##layout\
  293. {\
  294. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  295. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  296. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  297. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  298. };
  299. #define LAYOUT_TYPE_WMS_REG5(layout, t0, t1, t2, t3, t4)\
  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. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  307. };
  308. #define LAYOUT_TYPE_WMS_REG6(layout, t0, t1, t2, t3, t4, t5)\
  309. template <typename SizePolicy> struct OpLayoutT_##layout\
  310. {\
  311. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  312. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  313. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  314. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  315. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  316. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  317. };
  318. #define LAYOUT_TYPE_WMS_REG7(layout, t0, t1, t2, t3, t4, t5, t6)\
  319. template <typename SizePolicy> struct OpLayoutT_##layout\
  320. {\
  321. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  322. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  323. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  324. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  325. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  326. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  327. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  328. };
  329. #define LAYOUT_TYPE_WMS_REG9(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8)\
  330. template <typename SizePolicy> struct OpLayoutT_##layout\
  331. {\
  332. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  333. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  334. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  335. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  336. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  337. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  338. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  339. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  340. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  341. };
  342. #define LAYOUT_TYPE_WMS_REG10(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)\
  343. template <typename SizePolicy> struct OpLayoutT_##layout\
  344. {\
  345. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  346. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  347. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  348. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  349. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  350. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  351. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  352. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  353. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  354. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  355. };
  356. #define LAYOUT_TYPE_WMS_REG11(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)\
  357. template <typename SizePolicy> struct OpLayoutT_##layout\
  358. {\
  359. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  360. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  361. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  362. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  363. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  364. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  365. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  366. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  367. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  368. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  369. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  370. };
  371. #define LAYOUT_TYPE_WMS_REG17(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16)\
  372. template <typename SizePolicy> struct OpLayoutT_##layout\
  373. {\
  374. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  375. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  376. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  377. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  378. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  379. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  380. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  381. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  382. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  383. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  384. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  385. t11##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t11(), 11);\
  386. t12##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t12(), 12);\
  387. t13##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t13(), 13);\
  388. t14##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t14(), 14);\
  389. t15##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t15(), 15);\
  390. t16##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t16(), 16);\
  391. };
  392. #define LAYOUT_TYPE_WMS_REG18(layout, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17)\
  393. template <typename SizePolicy> struct OpLayoutT_##layout\
  394. {\
  395. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  396. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  397. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  398. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  399. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  400. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  401. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  402. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  403. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  404. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  405. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  406. t11##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t11(), 11);\
  407. t12##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t12(), 12);\
  408. t13##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t13(), 13);\
  409. t14##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t14(), 14);\
  410. t15##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t15(), 15);\
  411. t16##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t16(), 16);\
  412. t17##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t17(), 17);\
  413. };
  414. #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)\
  415. template <typename SizePolicy> struct OpLayoutT_##layout\
  416. {\
  417. t0##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t0(), 0);\
  418. t1##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t1(), 1);\
  419. t2##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t2(), 2);\
  420. t3##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t3(), 3);\
  421. t4##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t4(), 4);\
  422. t5##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t5(), 5);\
  423. t6##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t6(), 6);\
  424. t7##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t7(), 7);\
  425. t8##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t8(), 8);\
  426. t9##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t9(), 9);\
  427. t10##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t10(), 10);\
  428. t11##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t11(), 11);\
  429. t12##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t12(), 12);\
  430. t13##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t13(), 13);\
  431. t14##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t14(), 14);\
  432. t15##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t15(), 15);\
  433. t16##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t16(), 16);\
  434. t17##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t17(), 17);\
  435. t18##LayoutType LAYOUT_FIELDS_DEF(LAYOUT_PREFIX_##t18(), 18);\
  436. };
  437. #include "LayoutTypesAsmJs.h"
  438. #undef RegLayoutType
  439. #undef IntLayoutType
  440. #undef LongLayoutType
  441. #undef FloatLayoutType
  442. #undef DoubleLayoutType
  443. #undef IntConstLayoutType
  444. #undef LongConstLayoutType
  445. #undef FloatConstLayoutType
  446. #undef DoubleConstLayoutType
  447. #undef Float32x4LayoutType
  448. #undef Bool32x4LayoutType
  449. #undef Int32x4LayoutType
  450. #undef Float64x2LayoutType
  451. #undef Int16x8LayoutType
  452. #undef Bool16x8LayoutType
  453. #undef Int8x16LayoutType
  454. #undef Bool8x16LayoutType
  455. #undef Uint32x4LayoutType
  456. #undef Uint16x8LayoutType
  457. #undef Uint8x16LayoutType
  458. template <typename SizePolicy>
  459. struct OpLayoutT_AsmUnsigned1
  460. {
  461. typename SizePolicy::UnsignedType C1;
  462. };
  463. struct OpLayoutAsmBr
  464. {
  465. int32 RelativeJumpOffset;
  466. };
  467. template <typename SizePolicy>
  468. struct OpLayoutT_BrInt1
  469. {
  470. int32 RelativeJumpOffset;
  471. typename SizePolicy::RegSlotType I1;
  472. };
  473. template <typename SizePolicy>
  474. struct OpLayoutT_BrInt2
  475. {
  476. int32 RelativeJumpOffset;
  477. typename SizePolicy::RegSlotType I1;
  478. typename SizePolicy::RegSlotType I2;
  479. };
  480. template <typename SizePolicy>
  481. struct OpLayoutT_BrInt1Const1
  482. {
  483. int32 RelativeJumpOffset;
  484. typename SizePolicy::RegSlotType I1;
  485. int32 C1;
  486. };
  487. template <typename SizePolicy>
  488. struct OpLayoutT_AsmSimdTypedArr
  489. {
  490. // force encode 4 bytes because it can be a value
  491. uint32 SlotIndex;
  492. typename SizePolicy::RegSlotType Value;
  493. int8 ViewType;
  494. int8 DataWidth; // # of bytes to load/store
  495. };
  496. // Generate the multi size layout type defs
  497. #define LAYOUT_TYPE_WMS(layout) \
  498. typedef OpLayoutT_##layout<LargeLayoutSizePolicy> OpLayout##layout##_Large; \
  499. typedef OpLayoutT_##layout<MediumLayoutSizePolicy> OpLayout##layout##_Medium; \
  500. typedef OpLayoutT_##layout<SmallLayoutSizePolicy> OpLayout##layout##_Small;
  501. #include "LayoutTypesAsmJs.h"
  502. #pragma pack(pop)
  503. // Generate structure to automatically map layout to its info
  504. template <OpLayoutTypeAsmJs::_E layout> struct OpLayoutInfoAsmJs;
  505. #define LAYOUT_TYPE(layout) \
  506. CompileAssert(sizeof(OpLayout##layout) <= MaxLayoutSize); \
  507. template <> struct OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout> \
  508. { \
  509. static const bool HasMultiSizeLayout = false; \
  510. };
  511. #define LAYOUT_TYPE_WMS(layout) \
  512. CompileAssert(sizeof(OpLayout##layout##_Large) <= MaxLayoutSize); \
  513. template <> struct OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout> \
  514. { \
  515. static const bool HasMultiSizeLayout = true; \
  516. };
  517. #include "LayoutTypesAsmJs.h"
  518. // Generate structure to automatically map opcode to its info
  519. // Also generate assert to make sure the layout and opcode use the same macro with and without multiple size layout
  520. template <OpCodeAsmJs opcode> struct OpCodeInfoAsmJs;
  521. #define DEFINE_OPCODEINFO(op, layout, extended) \
  522. CompileAssert(!OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout>::HasMultiSizeLayout); \
  523. template <> struct OpCodeInfoAsmJs<OpCodeAsmJs::op> \
  524. { \
  525. static const OpLayoutTypeAsmJs::_E Layout = OpLayoutTypeAsmJs::layout; \
  526. static const bool HasMultiSizeLayout = false; \
  527. static const bool IsExtendedOpcode = extended; \
  528. typedef OpLayout##layout LayoutType; \
  529. };
  530. #define DEFINE_OPCODEINFO_WMS(op, layout, extended) \
  531. CompileAssert(OpLayoutInfoAsmJs<OpLayoutTypeAsmJs::layout>::HasMultiSizeLayout); \
  532. template <> struct OpCodeInfoAsmJs<OpCodeAsmJs::op> \
  533. { \
  534. static const OpLayoutTypeAsmJs::_E Layout = OpLayoutTypeAsmJs::layout; \
  535. static const bool HasMultiSizeLayout = true; \
  536. static const bool IsExtendedOpcode = extended; \
  537. typedef OpLayout##layout##_Large LayoutType_Large; \
  538. typedef OpLayout##layout##_Medium LayoutType_Medium; \
  539. typedef OpLayout##layout##_Small LayoutType_Small; \
  540. };
  541. #define MACRO(op, layout, ...) DEFINE_OPCODEINFO(op, layout, false)
  542. #define MACRO_WMS(op, layout, ...) DEFINE_OPCODEINFO_WMS(op, layout, false)
  543. #define MACRO_EXTEND(op, layout, ...) DEFINE_OPCODEINFO(op, layout, true)
  544. #define MACRO_EXTEND_WMS(op, layout, ...) DEFINE_OPCODEINFO_WMS(op, layout, true)
  545. #include "OpCodesAsmJs.h"
  546. #undef DEFINE_OPCODEINFO
  547. #undef DEFINE_OPCODEINFO_WMS
  548. }
  549. #endif