Merge pull request #1 from FernandoS27/arith

Added more arithmetic instructions
This commit is contained in:
ReinUsesLisp 2018-11-11 14:21:47 -03:00 committed by GitHub
commit 6790490271
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 9 deletions

View file

@ -286,20 +286,53 @@ class Module {
// Arithmetic // Arithmetic
/// Floating-point subtract of Operand from zero.
Id OpSNegate(Id result_type, Id operand);
/// Floating-point subtract of Operand from zero. /// Floating-point subtract of Operand from zero.
Id OpFNegate(Id result_type, Id operand); 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. /// Unsigned-integer division of Operand 1 divided by Operand 2.
Id OpUDiv(Id result_type, Id operand_1, Id operand_2); Id OpUDiv(Id result_type, Id operand_1, Id operand_2);
/// Unsigned modulo operation of Operand 1 modulo Operand 2. /// signed-integer division of Operand 1 divided by Operand 2.
Id OpUMod(Id result_type, Id operand_1, Id operand_2); Id OpSDiv(Id result_type, Id operand_1, Id operand_2);
/// Floating-point division of Operand 1 divided by Operand 2. /// Floating-point division of Operand 1 divided by Operand 2.
Id OpFDiv(Id result_type, Id operand_1, Id operand_2); Id OpFDiv(Id result_type, Id operand_1, Id operand_2);
/// Integer addition of Operand 1 and Operand 2. /// Unsigned modulo operation of Operand 1 modulo Operand 2.
Id OpIAdd(Id result_type, Id operand_1, Id 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 // Extensions

View file

@ -26,11 +26,33 @@ namespace Sirit {
return AddCode(std::move(op)); \ 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<Op>(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(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 } // namespace Sirit