From a6c435dcb7f515d233ed3ebb5fdb9b5579f322e9 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Mon, 12 Nov 2018 14:33:28 -0400 Subject: [PATCH] Implement main conversion instructions --- include/sirit/sirit.h | 16 ++++++++++++++++ src/insts/conversion.cpp | 22 ++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index a4c8fb0..f583a2b 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -321,6 +321,22 @@ class Module { // Conversion + Id OpConvertFToU(Id result_type, Id operand); + + Id OpConvertFToS(Id result_type, Id operand); + + Id OpConvertSToF(Id result_type, Id operand); + + Id OpConvertUToF(Id result_type, Id operand); + + Id OpUConvert(Id result_type, Id operand); + + Id OpSConvert(Id result_type, Id operand); + + Id OpFConvert(Id result_type, Id operand); + + Id OpQuantizeToF16(Id result_type, Id operand); + /// Bit pattern-preserving type conversion. Id OpBitcast(Id result_type, Id operand); diff --git a/src/insts/conversion.cpp b/src/insts/conversion.cpp index 4f13bf1..2301c8e 100644 --- a/src/insts/conversion.cpp +++ b/src/insts/conversion.cpp @@ -11,10 +11,20 @@ namespace Sirit { -Id Module::OpBitcast(Id result_type, Id operand) { - auto op{std::make_unique(spv::Op::OpBitcast, bound++, result_type)}; - op->Add(operand); - return AddCode(std::move(op)); -} +#define DEFINE_UNARY(opcode) \ + Id Module::opcode(Id result_type, Id operand) { \ + auto op{std::make_unique(spv::Op::opcode, bound++, result_type)}; \ + op->Add(operand); \ + return AddCode(std::move(op)); \ + } +DEFINE_UNARY(OpConvertFToU) +DEFINE_UNARY(OpConvertFToS) +DEFINE_UNARY(OpConvertSToF) +DEFINE_UNARY(OpConvertUToF) +DEFINE_UNARY(OpUConvert) +DEFINE_UNARY(OpSConvert) +DEFINE_UNARY(OpFConvert) +DEFINE_UNARY(OpQuantizeToF16) +DEFINE_UNARY(OpBitcast) -} // namespace Sirit \ No newline at end of file +} // namespace Sirit