From 846d07d7b596b2efb4c7a37bc5b9f0eb078b80aa Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sat, 6 Aug 2016 06:09:47 +0100 Subject: [PATCH] Add Sub64 opcode --- src/backend_x64/emit_x64.cpp | 10 ++++++++++ src/frontend/ir/ir_emitter.cpp | 4 ++++ src/frontend/ir/ir_emitter.h | 1 + src/frontend/ir/opcodes.inc | 1 + 4 files changed, 16 insertions(+) diff --git a/src/backend_x64/emit_x64.cpp b/src/backend_x64/emit_x64.cpp index 2293f5a4..ad71baaf 100644 --- a/src/backend_x64/emit_x64.cpp +++ b/src/backend_x64/emit_x64.cpp @@ -845,6 +845,16 @@ void EmitX64::EmitSubWithCarry(IR::Block& block, IR::Inst* inst) { } } +void EmitX64::EmitSub64(IR::Block& block, IR::Inst* inst) { + IR::Value a = inst->GetArg(0); + IR::Value b = inst->GetArg(1); + + X64Reg result = reg_alloc.UseDefRegister(a, inst, any_gpr); + OpArg op_arg = reg_alloc.UseOpArg(b, any_gpr); + + code->SUB(64, R(result), op_arg); +} + void EmitX64::EmitMul(IR::Block&, IR::Inst* inst) { IR::Value a = inst->GetArg(0); IR::Value b = inst->GetArg(1); diff --git a/src/frontend/ir/ir_emitter.cpp b/src/frontend/ir/ir_emitter.cpp index b5315cca..e9b5b87d 100644 --- a/src/frontend/ir/ir_emitter.cpp +++ b/src/frontend/ir/ir_emitter.cpp @@ -210,6 +210,10 @@ IR::Value IREmitter::Sub(const IR::Value& a, const IR::Value& b) { return Inst(IR::Opcode::SubWithCarry, {a, b, Imm1(1)}); } +IR::Value IREmitter::Sub64(const IR::Value& a, const IR::Value& b) { + return Inst(IR::Opcode::Sub64, {a, b}); +} + IR::Value IREmitter::Mul(const IR::Value& a, const IR::Value& b) { return Inst(IR::Opcode::Mul, {a, b}); } diff --git a/src/frontend/ir/ir_emitter.h b/src/frontend/ir/ir_emitter.h index 2a7a16e1..c0e312c9 100644 --- a/src/frontend/ir/ir_emitter.h +++ b/src/frontend/ir/ir_emitter.h @@ -75,6 +75,7 @@ public: IR::Value Add64(const IR::Value& a, const IR::Value& b); ResultAndCarryAndOverflow SubWithCarry(const IR::Value& a, const IR::Value& b, const IR::Value& carry_in); IR::Value Sub(const IR::Value& a, const IR::Value& b); + IR::Value Sub64(const IR::Value& a, const IR::Value& b); IR::Value Mul(const IR::Value& a, const IR::Value& b); IR::Value Mul64(const IR::Value& a, const IR::Value& b); IR::Value And(const IR::Value& a, const IR::Value& b); diff --git a/src/frontend/ir/opcodes.inc b/src/frontend/ir/opcodes.inc index 68736934..7c17a45e 100644 --- a/src/frontend/ir/opcodes.inc +++ b/src/frontend/ir/opcodes.inc @@ -42,6 +42,7 @@ OPCODE(RotateRightExtended, T::U32, T::U32, T::U1 OPCODE(AddWithCarry, T::U32, T::U32, T::U32, T::U1 ) OPCODE(SubWithCarry, T::U32, T::U32, T::U32, T::U1 ) OPCODE(Add64, T::U64, T::U64, T::U64 ) +OPCODE(Sub64, T::U64, T::U64, T::U64 ) OPCODE(Mul, T::U32, T::U32, T::U32 ) OPCODE(Mul64, T::U64, T::U64, T::U64 ) OPCODE(And, T::U32, T::U32, T::U32 )