diff --git a/include/sirit/sirit.h b/include/sirit/sirit.h index 94211c1..b4429b2 100644 --- a/include/sirit/sirit.h +++ b/include/sirit/sirit.h @@ -286,20 +286,53 @@ class Module { // Arithmetic + /// Floating-point subtract of Operand from zero. + Id OpSNegate(Id result_type, Id operand); + /// Floating-point subtract of Operand from zero. Id OpFNegate(Id result_type, Id operand); + /// Integer addition of Operand 1 and Operand 2. + Id OpIAdd(Id result_type, Id operand_1, Id operand_2); + + /// Floating-point addition of Operand 1 and Operand 2. + Id OpFAdd(Id result_type, Id operand_1, Id operand_2); + + /// Integer substraction of Operand 1 and Operand 2. + Id OpISub(Id result_type, Id operand_1, Id operand_2); + + /// Floating-point substraction of Operand 1 and Operand 2. + Id OpFSub(Id result_type, Id operand_1, Id operand_2); + + /// Integer multiplication of Operand 1 and Operand 2. + Id OpIMul(Id result_type, Id operand_1, Id operand_2); + + /// Floating-point multiplication of Operand 1 and Operand 2. + Id OpFMul(Id result_type, Id operand_1, Id operand_2); + /// Unsigned-integer division of Operand 1 divided by Operand 2. Id OpUDiv(Id result_type, Id operand_1, Id operand_2); - /// Unsigned modulo operation of Operand 1 modulo Operand 2. - Id OpUMod(Id result_type, Id operand_1, Id operand_2); + /// signed-integer division of Operand 1 divided by Operand 2. + Id OpSDiv(Id result_type, Id operand_1, Id operand_2); /// Floating-point division of Operand 1 divided by Operand 2. Id OpFDiv(Id result_type, Id operand_1, Id operand_2); - /// Integer addition of Operand 1 and Operand 2. - Id OpIAdd(Id result_type, Id operand_1, Id operand_2); + /// Unsigned modulo operation of Operand 1 modulo Operand 2. + Id OpUMod(Id result_type, Id operand_1, Id operand_2); + + /// Signed modulo operation of Operand 1 modulo Operand 2. + Id OpSMod(Id result_type, Id operand_1, Id operand_2); + + /// Floating-point modulo operation of Operand 1 modulo Operand 2. + Id OpFMod(Id result_type, Id operand_1, Id operand_2); + + /// Signed reminder operation of Operand 1 modulo Operand 2. + Id OpSRem(Id result_type, Id operand_1, Id operand_2); + + /// Floating-point reminder operation of Operand 1 modulo Operand 2. + Id OpFRem(Id result_type, Id operand_1, Id operand_2); // Extensions diff --git a/src/insts/arithmetic.cpp b/src/insts/arithmetic.cpp index 64a6a8a..f54d5d1 100644 --- a/src/insts/arithmetic.cpp +++ b/src/insts/arithmetic.cpp @@ -26,11 +26,33 @@ namespace Sirit { return AddCode(std::move(op)); \ } -DEFINE_UNARY(OpFNegate, spv::Op::OpFNegate); +#define DEFINE_TRINARY(funcname, opcode) \ + Id Module::funcname(Id result_type, Id operand_1, Id operand_2, \ + Id operand_3) { \ + auto op{std::make_unique(opcode, bound++, result_type)}; \ + op->Add(operand_1); \ + op->Add(operand_2); \ + op->Add(operand_3); \ + return AddCode(std::move(op)); \ + } + +DEFINE_UNARY(OpSNegate, spv::Op::OpSNegate) +DEFINE_UNARY(OpFNegate, spv::Op::OpFNegate) -DEFINE_BINARY(OpUDiv, spv::Op::OpUDiv) -DEFINE_BINARY(OpUMod, spv::Op::OpUMod) -DEFINE_BINARY(OpFDiv, spv::Op::OpFDiv) DEFINE_BINARY(OpIAdd, spv::Op::OpIAdd) +DEFINE_BINARY(OpFAdd, spv::Op::OpFAdd) +DEFINE_BINARY(OpISub, spv::Op::OpISub) +DEFINE_BINARY(OpFSub, spv::Op::OpFSub) +DEFINE_BINARY(OpIMul, spv::Op::OpIMul) +DEFINE_BINARY(OpFMul, spv::Op::OpFMul) +DEFINE_BINARY(OpUDiv, spv::Op::OpUDiv) +DEFINE_BINARY(OpSDiv, spv::Op::OpSDiv) +DEFINE_BINARY(OpFDiv, spv::Op::OpFDiv) +DEFINE_BINARY(OpUMod, spv::Op::OpUMod) +DEFINE_BINARY(OpSMod, spv::Op::OpSMod) +DEFINE_BINARY(OpFMod, spv::Op::OpFMod) +DEFINE_BINARY(OpSRem, spv::Op::OpSRem) +DEFINE_BINARY(OpFRem, spv::Op::OpFRem) -} // namespace Sirit \ No newline at end of file + +} // namespace Sirit