emit_glasm_bitwise_conversion.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2021 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "shader_recompiler/backend/glasm/emit_context.h"
  5. #include "shader_recompiler/backend/glasm/emit_glasm_instructions.h"
  6. #include "shader_recompiler/frontend/ir/value.h"
  7. namespace Shader::Backend::GLASM {
  8. static void Alias(IR::Inst& inst, const IR::Value& value) {
  9. if (value.IsImmediate()) {
  10. return;
  11. }
  12. IR::Inst& value_inst{RegAlloc::AliasInst(*value.Inst())};
  13. value_inst.DestructiveAddUsage(inst.UseCount());
  14. value_inst.DestructiveRemoveUsage();
  15. inst.SetDefinition(value_inst.Definition<Id>());
  16. }
  17. void EmitIdentity(EmitContext&, IR::Inst& inst, const IR::Value& value) {
  18. Alias(inst, value);
  19. }
  20. void EmitBitCastU16F16(EmitContext&, IR::Inst& inst, const IR::Value& value) {
  21. Alias(inst, value);
  22. }
  23. void EmitBitCastU32F32(EmitContext&, IR::Inst& inst, const IR::Value& value) {
  24. Alias(inst, value);
  25. }
  26. void EmitBitCastU64F64(EmitContext&, IR::Inst& inst, const IR::Value& value) {
  27. Alias(inst, value);
  28. }
  29. void EmitBitCastF16U16(EmitContext&, IR::Inst& inst, const IR::Value& value) {
  30. Alias(inst, value);
  31. }
  32. void EmitBitCastF32U32(EmitContext&, IR::Inst& inst, const IR::Value& value) {
  33. Alias(inst, value);
  34. }
  35. void EmitBitCastF64U64(EmitContext&, IR::Inst& inst, const IR::Value& value) {
  36. Alias(inst, value);
  37. }
  38. void EmitPackUint2x32(EmitContext& ctx, IR::Inst& inst, Register value) {
  39. ctx.LongAdd("PK64.U {}.x,{};", inst, value);
  40. }
  41. void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, Register value) {
  42. ctx.Add("UP64.U {}.xy,{}.x;", inst, value);
  43. }
  44. void EmitPackFloat2x16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register value) {
  45. throw NotImplementedException("GLASM instruction");
  46. }
  47. void EmitUnpackFloat2x16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] Register value) {
  48. throw NotImplementedException("GLASM instruction");
  49. }
  50. void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, Register value) {
  51. ctx.Add("PK2H {}.x,{};", inst, value);
  52. }
  53. void EmitUnpackHalf2x16(EmitContext& ctx, IR::Inst& inst, Register value) {
  54. ctx.Add("UP2H {}.xy,{}.x;", inst, value);
  55. }
  56. void EmitPackDouble2x32(EmitContext& ctx, IR::Inst& inst, Register value) {
  57. ctx.LongAdd("PK64 {}.x,{};", inst, value);
  58. }
  59. void EmitUnpackDouble2x32(EmitContext& ctx, IR::Inst& inst, Register value) {
  60. ctx.Add("UP64 {}.xy,{}.x;", inst, value);
  61. }
  62. } // namespace Shader::Backend::GLASM