InstEmitMemoryExHelper.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using ARMeilleure.IntermediateRepresentation;
  2. using ARMeilleure.Translation;
  3. using System;
  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. Delegate fallbackMethodDlg = null;
  15. if (exclusive)
  16. {
  17. switch (size)
  18. {
  19. case 0: fallbackMethodDlg = new _U8_U64(NativeInterface.ReadByteExclusive); break;
  20. case 1: fallbackMethodDlg = new _U16_U64(NativeInterface.ReadUInt16Exclusive); break;
  21. case 2: fallbackMethodDlg = new _U32_U64(NativeInterface.ReadUInt32Exclusive); break;
  22. case 3: fallbackMethodDlg = new _U64_U64(NativeInterface.ReadUInt64Exclusive); break;
  23. case 4: fallbackMethodDlg = new _V128_U64(NativeInterface.ReadVector128Exclusive); break;
  24. }
  25. }
  26. else
  27. {
  28. switch (size)
  29. {
  30. case 0: fallbackMethodDlg = new _U8_U64(NativeInterface.ReadByte); break;
  31. case 1: fallbackMethodDlg = new _U16_U64(NativeInterface.ReadUInt16); break;
  32. case 2: fallbackMethodDlg = new _U32_U64(NativeInterface.ReadUInt32); break;
  33. case 3: fallbackMethodDlg = new _U64_U64(NativeInterface.ReadUInt64); break;
  34. case 4: fallbackMethodDlg = new _V128_U64(NativeInterface.ReadVector128); break;
  35. }
  36. }
  37. return context.Call(fallbackMethodDlg, 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. Delegate fallbackMethodDlg = null;
  51. if (exclusive)
  52. {
  53. switch (size)
  54. {
  55. case 0: fallbackMethodDlg = new _S32_U64_U8(NativeInterface.WriteByteExclusive); break;
  56. case 1: fallbackMethodDlg = new _S32_U64_U16(NativeInterface.WriteUInt16Exclusive); break;
  57. case 2: fallbackMethodDlg = new _S32_U64_U32(NativeInterface.WriteUInt32Exclusive); break;
  58. case 3: fallbackMethodDlg = new _S32_U64_U64(NativeInterface.WriteUInt64Exclusive); break;
  59. case 4: fallbackMethodDlg = new _S32_U64_V128(NativeInterface.WriteVector128Exclusive); break;
  60. }
  61. return context.Call(fallbackMethodDlg, address, value);
  62. }
  63. else
  64. {
  65. switch (size)
  66. {
  67. case 0: fallbackMethodDlg = new _Void_U64_U8(NativeInterface.WriteByte); break;
  68. case 1: fallbackMethodDlg = new _Void_U64_U16(NativeInterface.WriteUInt16); break;
  69. case 2: fallbackMethodDlg = new _Void_U64_U32(NativeInterface.WriteUInt32); break;
  70. case 3: fallbackMethodDlg = new _Void_U64_U64(NativeInterface.WriteUInt64); break;
  71. case 4: fallbackMethodDlg = new _Void_U64_V128(NativeInterface.WriteVector128); break;
  72. }
  73. context.Call(fallbackMethodDlg, address, value);
  74. return null;
  75. }
  76. }
  77. }
  78. }