OpLayoutsCommon.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. namespace Js {
  7. typedef uint8 ArgSlot_OneByte;
  8. typedef uint32 CacheId;
  9. typedef uint8 CacheId_OneByte;
  10. typedef uint16 CacheId_TwoByte;
  11. typedef uint32 RootCacheId;
  12. typedef uint16 PropertyIdIndexType_TwoByte;
  13. typedef uint32 PropertyIdIndexType;
  14. #ifdef BYTECODE_BRANCH_ISLAND
  15. typedef int16 JumpOffset;
  16. typedef int32 LongJumpOffset;
  17. #else
  18. typedef int32 JumpOffset;
  19. #endif
  20. // This is used to estimate when we need to emit long branches
  21. uint const MaxLayoutSize = 76; // Increase this when we see larger layout
  22. uint const MaxOpCodeSize = 2;
  23. enum LayoutSize
  24. {
  25. SmallLayout,
  26. MediumLayout,
  27. LargeLayout,
  28. LayoutCount
  29. };
  30. template <LayoutSize layoutSize>
  31. struct LayoutSizePolicy;
  32. template <>
  33. struct LayoutSizePolicy<LargeLayout>
  34. {
  35. typedef RegSlot RegSlotType;
  36. typedef RegSlot RegSlotSType;
  37. typedef ArgSlot ArgSlotType;
  38. typedef CacheId CacheIdType;
  39. typedef PropertyIdIndexType PropertyIdIndexType;
  40. typedef uint32 UnsignedType;
  41. static const LayoutSize LayoutEnum = LargeLayout;
  42. template <typename T>
  43. static bool Assign(T& dst, T src) { dst = src; return true; }
  44. };
  45. typedef LayoutSizePolicy<LargeLayout> LargeLayoutSizePolicy;
  46. template <>
  47. struct LayoutSizePolicy<SmallLayout>
  48. {
  49. typedef RegSlot_OneByte RegSlotType;
  50. typedef RegSlot_OneSByte RegSlotSType;
  51. typedef ArgSlot_OneByte ArgSlotType;
  52. typedef CacheId_OneByte CacheIdType;
  53. typedef PropertyIdIndexType_TwoByte PropertyIdIndexType;
  54. typedef byte UnsignedType;
  55. static const LayoutSize LayoutEnum = SmallLayout;
  56. template <typename T1, typename T2>
  57. static bool Assign(T1& dst, T2 src)
  58. {
  59. #ifdef BYTECODE_TESTING
  60. if (Configuration::Global.flags.LargeByteCodeLayout
  61. || Configuration::Global.flags.MediumByteCodeLayout)
  62. {
  63. return false;
  64. }
  65. #endif
  66. dst = (T1)src;
  67. return ((T2)dst == src);
  68. }
  69. };
  70. typedef LayoutSizePolicy<SmallLayout> SmallLayoutSizePolicy;
  71. template <>
  72. struct LayoutSizePolicy<MediumLayout>
  73. {
  74. typedef RegSlot_TwoByte RegSlotType;
  75. typedef RegSlot_TwoSByte RegSlotSType;
  76. typedef ArgSlot_OneByte ArgSlotType;
  77. typedef CacheId_TwoByte CacheIdType;
  78. typedef PropertyIdIndexType_TwoByte PropertyIdIndexType;
  79. typedef uint16 UnsignedType;
  80. static const LayoutSize LayoutEnum = MediumLayout;
  81. template <typename T1, typename T2>
  82. static bool Assign(T1& dst, T2 src)
  83. {
  84. #ifdef BYTECODE_TESTING
  85. if (Configuration::Global.flags.LargeByteCodeLayout)
  86. {
  87. return false;
  88. }
  89. #endif
  90. dst = (T1)src;
  91. return ((T2)dst == src);
  92. }
  93. };
  94. typedef LayoutSizePolicy<MediumLayout> MediumLayoutSizePolicy;
  95. struct OpLayoutEmpty
  96. {
  97. // Although empty structs are one byte, the Empty layout are not written out.
  98. };
  99. } // namespace Js