OperandType.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. namespace ARMeilleure.IntermediateRepresentation
  3. {
  4. enum OperandType
  5. {
  6. None,
  7. I32,
  8. I64,
  9. FP32,
  10. FP64,
  11. V128
  12. }
  13. static class OperandTypeExtensions
  14. {
  15. public static bool IsInteger(this OperandType type)
  16. {
  17. return type == OperandType.I32 ||
  18. type == OperandType.I64;
  19. }
  20. public static RegisterType ToRegisterType(this OperandType type)
  21. {
  22. switch (type)
  23. {
  24. case OperandType.FP32: return RegisterType.Vector;
  25. case OperandType.FP64: return RegisterType.Vector;
  26. case OperandType.I32: return RegisterType.Integer;
  27. case OperandType.I64: return RegisterType.Integer;
  28. case OperandType.V128: return RegisterType.Vector;
  29. }
  30. throw new InvalidOperationException($"Invalid operand type \"{type}\".");
  31. }
  32. public static int GetSizeInBytes(this OperandType type)
  33. {
  34. switch (type)
  35. {
  36. case OperandType.FP32: return 4;
  37. case OperandType.FP64: return 8;
  38. case OperandType.I32: return 4;
  39. case OperandType.I64: return 8;
  40. case OperandType.V128: return 16;
  41. }
  42. throw new InvalidOperationException($"Invalid operand type \"{type}\".");
  43. }
  44. public static int GetSizeInBytesLog2(this OperandType type)
  45. {
  46. switch (type)
  47. {
  48. case OperandType.FP32: return 2;
  49. case OperandType.FP64: return 3;
  50. case OperandType.I32: return 2;
  51. case OperandType.I64: return 3;
  52. case OperandType.V128: return 4;
  53. }
  54. throw new InvalidOperationException($"Invalid operand type \"{type}\".");
  55. }
  56. }
  57. }