InstEmitMemoryExHelper.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using ARMeilleure.IntermediateRepresentation;
  2. using ARMeilleure.Translation;
  3. using System.Reflection;
  4. namespace ARMeilleure.Instructions
  5. {
  6. static class InstEmitMemoryExHelper
  7. {
  8. public static Operand EmitLoadExclusive(
  9. ArmEmitterContext context,
  10. Operand address,
  11. bool exclusive,
  12. int size)
  13. {
  14. MethodInfo info = null;
  15. if (exclusive)
  16. {
  17. switch (size)
  18. {
  19. case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByteExclusive)); break;
  20. case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16Exclusive)); break;
  21. case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32Exclusive)); break;
  22. case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64Exclusive)); break;
  23. case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadVector128Exclusive)); break;
  24. }
  25. }
  26. else
  27. {
  28. switch (size)
  29. {
  30. case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadByte)); break;
  31. case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt16)); break;
  32. case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt32)); break;
  33. case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadUInt64)); break;
  34. case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.ReadVector128)); break;
  35. }
  36. }
  37. return context.Call(info, address);
  38. }
  39. public static Operand EmitStoreExclusive(
  40. ArmEmitterContext context,
  41. Operand address,
  42. Operand value,
  43. bool exclusive,
  44. int size)
  45. {
  46. if (size < 3)
  47. {
  48. value = context.ConvertI64ToI32(value);
  49. }
  50. MethodInfo info = null;
  51. if (exclusive)
  52. {
  53. switch (size)
  54. {
  55. case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByteExclusive)); break;
  56. case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16Exclusive)); break;
  57. case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32Exclusive)); break;
  58. case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64Exclusive)); break;
  59. case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteVector128Exclusive)); break;
  60. }
  61. return context.Call(info, address, value);
  62. }
  63. else
  64. {
  65. switch (size)
  66. {
  67. case 0: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteByte)); break;
  68. case 1: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt16)); break;
  69. case 2: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt32)); break;
  70. case 3: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteUInt64)); break;
  71. case 4: info = typeof(NativeInterface).GetMethod(nameof(NativeInterface.WriteVector128)); break;
  72. }
  73. context.Call(info, address, value);
  74. return null;
  75. }
  76. }
  77. }
  78. }