LIR skeleton, renaming some types to prevent conflict.

This commit is contained in:
Ben Vanik 2013-12-29 14:28:46 -08:00
parent 7d83ba0021
commit 3d01efffac
66 changed files with 817 additions and 762 deletions

View File

@ -15,7 +15,7 @@
namespace alloy { namespace alloy {
namespace hir { namespace hir {
class FunctionBuilder; class HIRBuilder;
} }
namespace runtime { namespace runtime {
class DebugInfo; class DebugInfo;
@ -41,7 +41,7 @@ public:
virtual void Reset(); virtual void Reset();
virtual int Assemble( virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::FunctionBuilder* builder, runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
runtime::DebugInfo* debug_info, runtime::Function** out_function) = 0; runtime::DebugInfo* debug_info, runtime::Function** out_function) = 0;
protected: protected:

View File

@ -13,7 +13,7 @@
#include <alloy/backend/tracing.h> #include <alloy/backend/tracing.h>
#include <alloy/backend/ivm/ivm_intcode.h> #include <alloy/backend/ivm/ivm_intcode.h>
#include <alloy/backend/ivm/ivm_function.h> #include <alloy/backend/ivm/ivm_function.h>
#include <alloy/hir/function_builder.h> #include <alloy/hir/hir_builder.h>
#include <alloy/hir/label.h> #include <alloy/hir/label.h>
#include <alloy/runtime/runtime.h> #include <alloy/runtime/runtime.h>
@ -54,7 +54,7 @@ void IVMAssembler::Reset() {
} }
int IVMAssembler::Assemble( int IVMAssembler::Assemble(
FunctionInfo* symbol_info, FunctionBuilder* builder, FunctionInfo* symbol_info, HIRBuilder* builder,
DebugInfo* debug_info, Function** out_function) { DebugInfo* debug_info, Function** out_function) {
IVMFunction* fn = new IVMFunction(symbol_info); IVMFunction* fn = new IVMFunction(symbol_info);
fn->set_debug_info(debug_info); fn->set_debug_info(debug_info);

View File

@ -30,7 +30,7 @@ public:
virtual void Reset(); virtual void Reset();
virtual int Assemble( virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::FunctionBuilder* builder, runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
runtime::DebugInfo* debug_info, runtime::Function** out_function); runtime::DebugInfo* debug_info, runtime::Function** out_function);
private: private:

View File

@ -31,14 +31,15 @@ namespace backend {
namespace ivm { namespace ivm {
//#define DPRINT printf
//#define DFLUSH() fflush(stdout)
#define DPRINT
#define DFLUSH()
//#define IPRINT printf
//#define IFLUSH() fflush(stdout)
#define IPRINT #define IPRINT
#define IFLUSH() #define IFLUSH()
#define DPRINT
#define DFLUSH()
//#define IPRINT if (ics.thread_state->thread_id() == 1) printf
//#define IFLUSH() fflush(stdout)
//#define DPRINT if (ics.thread_state->thread_id() == 1) printf
//#define DFLUSH() fflush(stdout)
uint32_t IntCode_INT_LOAD_CONSTANT(IntCodeState& ics, const IntCode* i) { uint32_t IntCode_INT_LOAD_CONSTANT(IntCodeState& ics, const IntCode* i) {

View File

View File

View File

View File

View File

View File

View File

@ -0,0 +1,12 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'lir_builder.cc',
'lir_builder.h',
'lir_instr.h',
'lircodes.cc',
'lircodes.h',
'lircodes.inl',
'tracing.h',
],
}

View File

View File

@ -0,0 +1,7 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'redundant_mov_pass.cc',
'redundant_mov_pass.h',
],
}

View File

@ -0,0 +1,15 @@
# Copyright 2013 Ben Vanik. All Rights Reserved.
{
'sources': [
'optimizer.cc',
'optimizer.h',
'optimizer_pass.cc',
'optimizer_pass.h',
'optimizer_passes.h',
'tracing.h',
],
'includes': [
'passes/sources.gypi',
],
}

View File

@ -1,5 +1,21 @@
# Copyright 2013 Ben Vanik. All Rights Reserved. # Copyright 2013 Ben Vanik. All Rights Reserved.
{ {
'sources': [ 'sources': [
'tracing.h',
'x64_assembler.cc',
'x64_assembler.h',
'x64_backend.cc',
'x64_backend.h',
'x64_codegen.cc',
'x64_codegen.h',
'x64_emitter.cc',
'x64_emitter.h',
'x64_function.cc',
'x64_function.h',
],
'includes': [
'lir/sources.gypi',
'optimizer/sources.gypi',
], ],
} }

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

@ -9,7 +9,7 @@
#include <alloy/compiler/compiler.h> #include <alloy/compiler/compiler.h>
#include <alloy/compiler/pass.h> #include <alloy/compiler/compiler_pass.h>
#include <alloy/compiler/tracing.h> #include <alloy/compiler/tracing.h>
using namespace alloy; using namespace alloy;
@ -27,8 +27,8 @@ Compiler::Compiler(Runtime* runtime) :
Compiler::~Compiler() { Compiler::~Compiler() {
Reset(); Reset();
for (PassList::iterator it = passes_.begin(); it != passes_.end(); ++it) { for (auto it = passes_.begin(); it != passes_.end(); ++it) {
Pass* pass = *it; CompilerPass* pass = *it;
delete pass; delete pass;
} }
@ -36,7 +36,7 @@ Compiler::~Compiler() {
})); }));
} }
void Compiler::AddPass(Pass* pass) { void Compiler::AddPass(CompilerPass* pass) {
pass->Initialize(this); pass->Initialize(this);
passes_.push_back(pass); passes_.push_back(pass);
} }
@ -44,11 +44,11 @@ void Compiler::AddPass(Pass* pass) {
void Compiler::Reset() { void Compiler::Reset() {
} }
int Compiler::Compile(FunctionBuilder* builder) { int Compiler::Compile(HIRBuilder* builder) {
// TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they // TODO(benvanik): sophisticated stuff. Run passes in parallel, run until they
// stop changing things, etc. // stop changing things, etc.
for (PassList::iterator it = passes_.begin(); it != passes_.end(); ++it) { for (auto it = passes_.begin(); it != passes_.end(); ++it) {
Pass* pass = *it; CompilerPass* pass = *it;
if (pass->Run(builder)) { if (pass->Run(builder)) {
return 1; return 1;
} }

View File

@ -11,7 +11,7 @@
#define ALLOY_COMPILER_COMPILER_H_ #define ALLOY_COMPILER_COMPILER_H_
#include <alloy/core.h> #include <alloy/core.h>
#include <alloy/hir/function_builder.h> #include <alloy/hir/hir_builder.h>
namespace alloy { namespace runtime { class Runtime; } } namespace alloy { namespace runtime { class Runtime; } }
@ -19,7 +19,7 @@ namespace alloy { namespace runtime { class Runtime; } }
namespace alloy { namespace alloy {
namespace compiler { namespace compiler {
class Pass; class CompilerPass;
class Compiler { class Compiler {
@ -29,16 +29,16 @@ public:
runtime::Runtime* runtime() const { return runtime_; } runtime::Runtime* runtime() const { return runtime_; }
void AddPass(Pass* pass); void AddPass(CompilerPass* pass);
void Reset(); void Reset();
int Compile(hir::FunctionBuilder* builder); int Compile(hir::HIRBuilder* builder);
private: private:
runtime::Runtime* runtime_; runtime::Runtime* runtime_;
typedef std::vector<Pass*> PassList; typedef std::vector<CompilerPass*> PassList;
PassList passes_; PassList passes_;
}; };

View File

@ -7,7 +7,7 @@
****************************************************************************** ******************************************************************************
*/ */
#include <alloy/compiler/pass.h> #include <alloy/compiler/compiler_pass.h>
#include <alloy/compiler/compiler.h> #include <alloy/compiler/compiler.h>
@ -15,14 +15,14 @@ using namespace alloy;
using namespace alloy::compiler; using namespace alloy::compiler;
Pass::Pass() : CompilerPass::CompilerPass() :
runtime_(0), compiler_(0) { runtime_(0), compiler_(0) {
} }
Pass::~Pass() { CompilerPass::~CompilerPass() {
} }
int Pass::Initialize(Compiler* compiler) { int CompilerPass::Initialize(Compiler* compiler) {
runtime_ = compiler->runtime(); runtime_ = compiler->runtime();
compiler_ = compiler; compiler_ = compiler;
return 0; return 0;

View File

@ -7,12 +7,12 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_COMPILER_PASS_H_ #ifndef ALLOY_COMPILER_COMPILER_PASS_H_
#define ALLOY_COMPILER_PASS_H_ #define ALLOY_COMPILER_COMPILER_PASS_H_
#include <alloy/core.h> #include <alloy/core.h>
#include <alloy/hir/function_builder.h> #include <alloy/hir/hir_builder.h>
namespace alloy { namespace runtime { class Runtime; } } namespace alloy { namespace runtime { class Runtime; } }
@ -23,14 +23,14 @@ namespace compiler {
class Compiler; class Compiler;
class Pass { class CompilerPass {
public: public:
Pass(); CompilerPass();
virtual ~Pass(); virtual ~CompilerPass();
virtual int Initialize(Compiler* compiler); virtual int Initialize(Compiler* compiler);
virtual int Run(hir::FunctionBuilder* builder) = 0; virtual int Run(hir::HIRBuilder* builder) = 0;
protected: protected:
runtime::Runtime* runtime_; runtime::Runtime* runtime_;
@ -42,4 +42,4 @@ protected:
} // namespace alloy } // namespace alloy
#endif // ALLOY_COMPILER_PASS_H_ #endif // ALLOY_COMPILER_COMPILER_PASS_H_

View File

@ -7,8 +7,8 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_COMPILER_PASSES_H_ #ifndef ALLOY_COMPILER_COMPILER_PASSES_H_
#define ALLOY_COMPILER_PASSES_H_ #define ALLOY_COMPILER_COMPILER_PASSES_H_
#include <alloy/compiler/passes/constant_propagation_pass.h> #include <alloy/compiler/passes/constant_propagation_pass.h>
#include <alloy/compiler/passes/context_promotion_pass.h> #include <alloy/compiler/passes/context_promotion_pass.h>
@ -133,4 +133,4 @@
// branch_true v5, ... // branch_true v5, ...
// //
#endif // ALLOY_COMPILER_PASSES_H_ #endif // ALLOY_COMPILER_COMPILER_PASSES_H_

View File

@ -16,13 +16,13 @@ using namespace alloy::hir;
ConstantPropagationPass::ConstantPropagationPass() : ConstantPropagationPass::ConstantPropagationPass() :
Pass() { CompilerPass() {
} }
ConstantPropagationPass::~ConstantPropagationPass() { ConstantPropagationPass::~ConstantPropagationPass() {
} }
int ConstantPropagationPass::Run(FunctionBuilder* builder) { int ConstantPropagationPass::Run(HIRBuilder* builder) {
// Once ContextPromotion has run there will likely be a whole slew of // Once ContextPromotion has run there will likely be a whole slew of
// constants that can be pushed through the function. // constants that can be pushed through the function.
// Example: // Example:

View File

@ -10,7 +10,7 @@
#ifndef ALLOY_COMPILER_PASSES_CONSTANT_PROPAGATION_PASS_H_ #ifndef ALLOY_COMPILER_PASSES_CONSTANT_PROPAGATION_PASS_H_
#define ALLOY_COMPILER_PASSES_CONSTANT_PROPAGATION_PASS_H_ #define ALLOY_COMPILER_PASSES_CONSTANT_PROPAGATION_PASS_H_
#include <alloy/compiler/pass.h> #include <alloy/compiler/compiler_pass.h>
namespace alloy { namespace alloy {
@ -18,12 +18,12 @@ namespace compiler {
namespace passes { namespace passes {
class ConstantPropagationPass : public Pass { class ConstantPropagationPass : public CompilerPass {
public: public:
ConstantPropagationPass(); ConstantPropagationPass();
virtual ~ConstantPropagationPass(); virtual ~ConstantPropagationPass();
virtual int Run(hir::FunctionBuilder* builder); virtual int Run(hir::HIRBuilder* builder);
private: private:
}; };

View File

@ -22,7 +22,7 @@ using namespace alloy::runtime;
ContextPromotionPass::ContextPromotionPass() : ContextPromotionPass::ContextPromotionPass() :
context_values_size_(0), context_values_(0), context_values_size_(0), context_values_(0),
Pass() { CompilerPass() {
} }
ContextPromotionPass::~ContextPromotionPass() { ContextPromotionPass::~ContextPromotionPass() {
@ -32,7 +32,7 @@ ContextPromotionPass::~ContextPromotionPass() {
} }
int ContextPromotionPass::Initialize(Compiler* compiler) { int ContextPromotionPass::Initialize(Compiler* compiler) {
if (Pass::Initialize(compiler)) { if (CompilerPass::Initialize(compiler)) {
return 1; return 1;
} }
@ -44,7 +44,7 @@ int ContextPromotionPass::Initialize(Compiler* compiler) {
return 0; return 0;
} }
int ContextPromotionPass::Run(FunctionBuilder* builder) { int ContextPromotionPass::Run(HIRBuilder* builder) {
// Like mem2reg, but because context memory is unaliasable it's easier to // Like mem2reg, but because context memory is unaliasable it's easier to
// check and convert LoadContext/StoreContext into value operations. // check and convert LoadContext/StoreContext into value operations.
// Example of load->value promotion: // Example of load->value promotion:

View File

@ -10,7 +10,7 @@
#ifndef ALLOY_COMPILER_PASSES_CONTEXT_PROMOTION_PASS_H_ #ifndef ALLOY_COMPILER_PASSES_CONTEXT_PROMOTION_PASS_H_
#define ALLOY_COMPILER_PASSES_CONTEXT_PROMOTION_PASS_H_ #define ALLOY_COMPILER_PASSES_CONTEXT_PROMOTION_PASS_H_
#include <alloy/compiler/pass.h> #include <alloy/compiler/compiler_pass.h>
namespace alloy { namespace alloy {
@ -18,14 +18,14 @@ namespace compiler {
namespace passes { namespace passes {
class ContextPromotionPass : public Pass { class ContextPromotionPass : public CompilerPass {
public: public:
ContextPromotionPass(); ContextPromotionPass();
virtual ~ContextPromotionPass(); virtual ~ContextPromotionPass();
virtual int Initialize(Compiler* compiler); virtual int Initialize(Compiler* compiler);
virtual int Run(hir::FunctionBuilder* builder); virtual int Run(hir::HIRBuilder* builder);
private: private:
void PromoteBlock(hir::Block* block); void PromoteBlock(hir::Block* block);

View File

@ -16,13 +16,13 @@ using namespace alloy::hir;
DeadCodeEliminationPass::DeadCodeEliminationPass() : DeadCodeEliminationPass::DeadCodeEliminationPass() :
Pass() { CompilerPass() {
} }
DeadCodeEliminationPass::~DeadCodeEliminationPass() { DeadCodeEliminationPass::~DeadCodeEliminationPass() {
} }
int DeadCodeEliminationPass::Run(FunctionBuilder* builder) { int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
// ContextPromotion/DSE will likely leave around a lot of dead statements. // ContextPromotion/DSE will likely leave around a lot of dead statements.
// Code generated for comparison/testing produces many unused statements and // Code generated for comparison/testing produces many unused statements and
// with proper use analysis it should be possible to remove most of them: // with proper use analysis it should be possible to remove most of them:

View File

@ -10,7 +10,7 @@
#ifndef ALLOY_COMPILER_PASSES_DEAD_CODE_ELIMINATION_PASS_H_ #ifndef ALLOY_COMPILER_PASSES_DEAD_CODE_ELIMINATION_PASS_H_
#define ALLOY_COMPILER_PASSES_DEAD_CODE_ELIMINATION_PASS_H_ #define ALLOY_COMPILER_PASSES_DEAD_CODE_ELIMINATION_PASS_H_
#include <alloy/compiler/pass.h> #include <alloy/compiler/compiler_pass.h>
namespace alloy { namespace alloy {
@ -18,12 +18,12 @@ namespace compiler {
namespace passes { namespace passes {
class DeadCodeEliminationPass : public Pass { class DeadCodeEliminationPass : public CompilerPass {
public: public:
DeadCodeEliminationPass(); DeadCodeEliminationPass();
virtual ~DeadCodeEliminationPass(); virtual ~DeadCodeEliminationPass();
virtual int Run(hir::FunctionBuilder* builder); virtual int Run(hir::HIRBuilder* builder);
private: private:
void MakeNopRecursive(hir::Instr* i); void MakeNopRecursive(hir::Instr* i);

View File

@ -16,13 +16,13 @@ using namespace alloy::hir;
SimplificationPass::SimplificationPass() : SimplificationPass::SimplificationPass() :
Pass() { CompilerPass() {
} }
SimplificationPass::~SimplificationPass() { SimplificationPass::~SimplificationPass() {
} }
int SimplificationPass::Run(FunctionBuilder* builder) { int SimplificationPass::Run(HIRBuilder* builder) {
// Run over the instructions and rename assigned variables: // Run over the instructions and rename assigned variables:
// v1 = v0 // v1 = v0
// v2 = v1 // v2 = v1

View File

@ -10,7 +10,7 @@
#ifndef ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_ #ifndef ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_
#define ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_ #define ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_
#include <alloy/compiler/pass.h> #include <alloy/compiler/compiler_pass.h>
namespace alloy { namespace alloy {
@ -18,12 +18,12 @@ namespace compiler {
namespace passes { namespace passes {
class SimplificationPass : public Pass { class SimplificationPass : public CompilerPass {
public: public:
SimplificationPass(); SimplificationPass();
virtual ~SimplificationPass(); virtual ~SimplificationPass();
virtual int Run(hir::FunctionBuilder* builder); virtual int Run(hir::HIRBuilder* builder);
private: private:
hir::Value* CheckValue(hir::Value* value); hir::Value* CheckValue(hir::Value* value);

View File

@ -3,9 +3,9 @@
'sources': [ 'sources': [
'compiler.cc', 'compiler.cc',
'compiler.h', 'compiler.h',
'pass.cc', 'compiler_pass.cc',
'pass.h', 'compiler_pass.h',
'passes.h', 'compiler_passes.h',
'tracing.h', 'tracing.h',
], ],

View File

@ -24,8 +24,8 @@ namespace ppc {
#define XEREGISTERINSTR(name, opcode) \ #define XEREGISTERINSTR(name, opcode) \
RegisterInstrDisassemble(opcode, (InstrDisassembleFn)InstrDisasm_##name); RegisterInstrDisassemble(opcode, (InstrDisassembleFn)InstrDisasm_##name);
//#define XEINSTRNOTIMPLEMENTED() #define XEINSTRNOTIMPLEMENTED()
#define XEINSTRNOTIMPLEMENTED XEASSERTALWAYS //#define XEINSTRNOTIMPLEMENTED XEASSERTALWAYS
} // namespace ppc } // namespace ppc

View File

@ -24,8 +24,9 @@ namespace ppc {
#define XEREGISTERINSTR(name, opcode) \ #define XEREGISTERINSTR(name, opcode) \
RegisterInstrEmit(opcode, (InstrEmitFn)InstrEmit_##name); RegisterInstrEmit(opcode, (InstrEmitFn)InstrEmit_##name);
//#define XEINSTRNOTIMPLEMENTED() #define XEINSTRNOTIMPLEMENTED()
#define XEINSTRNOTIMPLEMENTED XEASSERTALWAYS //#define XEINSTRNOTIMPLEMENTED XEASSERTALWAYS
//#define XEINSTRNOTIMPLEMENTED() __debugbreak()
} // namespace ppc } // namespace ppc

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
#include <alloy/frontend/ppc/ppc_emit-private.h> #include <alloy/frontend/ppc/ppc_emit-private.h>
#include <alloy/frontend/ppc/ppc_context.h> #include <alloy/frontend/ppc/ppc_context.h>
#include <alloy/frontend/ppc/ppc_function_builder.h> #include <alloy/frontend/ppc/ppc_hir_builder.h>
using namespace alloy::frontend::ppc; using namespace alloy::frontend::ppc;
@ -25,7 +25,7 @@ namespace ppc {
// Integer arithmetic (A-3) // Integer arithmetic (A-3)
XEEMITTER(addx, 0x7C000214, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addx, 0x7C000214, XO )(PPCHIRBuilder& f, InstrData& i) {
// RD <- (RA) + (RB) // RD <- (RA) + (RB)
Value* v = f.Add( Value* v = f.Add(
f.LoadGPR(i.XO.RA), f.LoadGPR(i.XO.RA),
@ -41,7 +41,7 @@ XEEMITTER(addx, 0x7C000214, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addcx, 0x7C000014, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addcx, 0x7C000014, XO )(PPCHIRBuilder& f, InstrData& i) {
// RD <- (RA) + (RB) // RD <- (RA) + (RB)
// CA <- carry bit // CA <- carry bit
Value* v = f.Add( Value* v = f.Add(
@ -60,7 +60,7 @@ XEEMITTER(addcx, 0x7C000014, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addex, 0x7C000114, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addex, 0x7C000114, XO )(PPCHIRBuilder& f, InstrData& i) {
// RD <- (RA) + (RB) + XER[CA] // RD <- (RA) + (RB) + XER[CA]
Value* v = f.AddWithCarry( Value* v = f.AddWithCarry(
f.LoadGPR(i.XO.RA), f.LoadGPR(i.XO.RA),
@ -79,7 +79,7 @@ XEEMITTER(addex, 0x7C000114, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addi, 0x38000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addi, 0x38000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// RT <- EXTS(SI) // RT <- EXTS(SI)
// else // else
@ -93,7 +93,7 @@ XEEMITTER(addi, 0x38000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addic, 0x30000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addic, 0x30000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RT <- (RA) + EXTS(SI) // RT <- (RA) + EXTS(SI)
Value* v = f.Add( Value* v = f.Add(
f.LoadGPR(i.D.RA), f.LoadGPR(i.D.RA),
@ -104,7 +104,7 @@ XEEMITTER(addic, 0x30000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addicx, 0x34000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addicx, 0x34000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RT <- (RA) + EXTS(SI) // RT <- (RA) + EXTS(SI)
Value* v = f.Add( Value* v = f.Add(
f.LoadGPR(i.D.RA), f.LoadGPR(i.D.RA),
@ -116,7 +116,7 @@ XEEMITTER(addicx, 0x34000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addis, 0x3C000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addis, 0x3C000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// RT <- EXTS(SI) || i16.0 // RT <- EXTS(SI) || i16.0
// else // else
@ -130,7 +130,7 @@ XEEMITTER(addis, 0x3C000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addmex, 0x7C0001D4, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addmex, 0x7C0001D4, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- (RA) + CA - 1 // RT <- (RA) + CA - 1
Value* v = f.AddWithCarry( Value* v = f.AddWithCarry(
f.LoadGPR(i.XO.RA), f.LoadGPR(i.XO.RA),
@ -152,7 +152,7 @@ XEEMITTER(addmex, 0x7C0001D4, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(addzex, 0x7C000194, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(addzex, 0x7C000194, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- (RA) + CA // RT <- (RA) + CA
Value* v = f.AddWithCarry( Value* v = f.AddWithCarry(
f.LoadGPR(i.XO.RA), f.LoadGPR(i.XO.RA),
@ -174,7 +174,7 @@ XEEMITTER(addzex, 0x7C000194, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(divdx, 0x7C0003D2, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(divdx, 0x7C0003D2, XO )(PPCHIRBuilder& f, InstrData& i) {
// dividend <- (RA) // dividend <- (RA)
// divisor <- (RB) // divisor <- (RB)
// if divisor = 0 then // if divisor = 0 then
@ -200,7 +200,7 @@ XEEMITTER(divdx, 0x7C0003D2, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(divdux, 0x7C000392, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(divdux, 0x7C000392, XO )(PPCHIRBuilder& f, InstrData& i) {
// dividend <- (RA) // dividend <- (RA)
// divisor <- (RB) // divisor <- (RB)
// if divisor = 0 then // if divisor = 0 then
@ -226,7 +226,7 @@ f.StoreGPR(i.XO.RT, v);
return 0; return 0;
} }
XEEMITTER(divwx, 0x7C0003D6, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(divwx, 0x7C0003D6, XO )(PPCHIRBuilder& f, InstrData& i) {
// dividend[0:31] <- (RA)[32:63] // dividend[0:31] <- (RA)[32:63]
// divisor[0:31] <- (RB)[32:63] // divisor[0:31] <- (RB)[32:63]
// if divisor = 0 then // if divisor = 0 then
@ -254,7 +254,7 @@ XEEMITTER(divwx, 0x7C0003D6, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(divwux, 0x7C000396, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(divwux, 0x7C000396, XO )(PPCHIRBuilder& f, InstrData& i) {
// dividend[0:31] <- (RA)[32:63] // dividend[0:31] <- (RA)[32:63]
// divisor[0:31] <- (RB)[32:63] // divisor[0:31] <- (RB)[32:63]
// if divisor = 0 then // if divisor = 0 then
@ -282,17 +282,17 @@ XEEMITTER(divwux, 0x7C000396, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(mulhdx, 0x7C000092, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mulhdx, 0x7C000092, XO )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mulhdux, 0x7C000012, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mulhdux, 0x7C000012, XO )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mulhwx, 0x7C000096, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mulhwx, 0x7C000096, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT[32:64] <- ((RA)[32:63] × (RB)[32:63])[0:31] // RT[32:64] <- ((RA)[32:63] × (RB)[32:63])[0:31]
if (i.XO.OE) { if (i.XO.OE) {
// With XER update. // With XER update.
@ -310,7 +310,7 @@ XEEMITTER(mulhwx, 0x7C000096, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(mulhwux, 0x7C000016, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mulhwux, 0x7C000016, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT[32:64] <- ((RA)[32:63] × (RB)[32:63])[0:31] // RT[32:64] <- ((RA)[32:63] × (RB)[32:63])[0:31]
if (i.XO.OE) { if (i.XO.OE) {
// With XER update. // With XER update.
@ -328,7 +328,7 @@ XEEMITTER(mulhwux, 0x7C000016, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(mulldx, 0x7C0001D2, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mulldx, 0x7C0001D2, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ((RA) × (RB))[64:127] // RT <- ((RA) × (RB))[64:127]
if (i.XO.OE) { if (i.XO.OE) {
// With XER update. // With XER update.
@ -343,7 +343,7 @@ XEEMITTER(mulldx, 0x7C0001D2, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(mulli, 0x1C000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mulli, 0x1C000000, D )(PPCHIRBuilder& f, InstrData& i) {
// prod[0:127] <- (RA) × EXTS(SI) // prod[0:127] <- (RA) × EXTS(SI)
// RT <- prod[64:127] // RT <- prod[64:127]
Value* v = f.Mul(f.LoadGPR(i.D.RA), f.LoadConstant(XEEXTS16(i.D.DS))); Value* v = f.Mul(f.LoadGPR(i.D.RA), f.LoadConstant(XEEXTS16(i.D.DS)));
@ -351,7 +351,7 @@ XEEMITTER(mulli, 0x1C000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(mullwx, 0x7C0001D6, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mullwx, 0x7C0001D6, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- (RA)[32:63] × (RB)[32:63] // RT <- (RA)[32:63] × (RB)[32:63]
if (i.XO.OE) { if (i.XO.OE) {
// With XER update. // With XER update.
@ -368,7 +368,7 @@ XEEMITTER(mullwx, 0x7C0001D6, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(negx, 0x7C0000D0, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(negx, 0x7C0000D0, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + 1 // RT <- ¬(RA) + 1
if (i.XO.OE) { if (i.XO.OE) {
// With XER update. // With XER update.
@ -401,7 +401,7 @@ XEEMITTER(negx, 0x7C0000D0, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(subfx, 0x7C000050, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(subfx, 0x7C000050, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + (RB) + 1 // RT <- ¬(RA) + (RB) + 1
Value* v = f.Sub(f.LoadGPR(i.XO.RB), f.LoadGPR(i.XO.RA)); Value* v = f.Sub(f.LoadGPR(i.XO.RB), f.LoadGPR(i.XO.RA));
f.StoreGPR(i.XO.RT, v); f.StoreGPR(i.XO.RT, v);
@ -415,7 +415,7 @@ XEEMITTER(subfx, 0x7C000050, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(subfcx, 0x7C000010, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(subfcx, 0x7C000010, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + (RB) + 1 // RT <- ¬(RA) + (RB) + 1
Value* v = f.Sub( Value* v = f.Sub(
f.LoadGPR(i.XO.RB), f.LoadGPR(i.XO.RB),
@ -433,7 +433,7 @@ XEEMITTER(subfcx, 0x7C000010, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(subficx, 0x20000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(subficx, 0x20000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + EXTS(SI) + 1 // RT <- ¬(RA) + EXTS(SI) + 1
Value* v = f.Sub( Value* v = f.Sub(
f.LoadConstant(XEEXTS16(i.D.DS)), f.LoadConstant(XEEXTS16(i.D.DS)),
@ -444,7 +444,7 @@ XEEMITTER(subficx, 0x20000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(subfex, 0x7C000110, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(subfex, 0x7C000110, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + (RB) + CA // RT <- ¬(RA) + (RB) + CA
Value* v = f.AddWithCarry( Value* v = f.AddWithCarry(
f.Not(f.LoadGPR(i.XO.RA)), f.Not(f.LoadGPR(i.XO.RA)),
@ -463,7 +463,7 @@ XEEMITTER(subfex, 0x7C000110, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(subfmex, 0x7C0001D0, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(subfmex, 0x7C0001D0, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + CA - 1 // RT <- ¬(RA) + CA - 1
Value* v = f.AddWithCarry( Value* v = f.AddWithCarry(
f.Not(f.LoadGPR(i.XO.RA)), f.Not(f.LoadGPR(i.XO.RA)),
@ -482,7 +482,7 @@ XEEMITTER(subfmex, 0x7C0001D0, XO )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(subfzex, 0x7C000190, XO )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(subfzex, 0x7C000190, XO )(PPCHIRBuilder& f, InstrData& i) {
// RT <- ¬(RA) + CA // RT <- ¬(RA) + CA
Value* v = f.AddWithCarry( Value* v = f.AddWithCarry(
f.Not(f.LoadGPR(i.XO.RA)), f.Not(f.LoadGPR(i.XO.RA)),
@ -504,7 +504,7 @@ XEEMITTER(subfzex, 0x7C000190, XO )(PPCFunctionBuilder& f, InstrData& i) {
// Integer compare (A-4) // Integer compare (A-4)
XEEMITTER(cmp, 0x7C000000, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(cmp, 0x7C000000, X )(PPCHIRBuilder& f, InstrData& i) {
// if L = 0 then // if L = 0 then
// a <- EXTS((RA)[32:63]) // a <- EXTS((RA)[32:63])
// b <- EXTS((RB)[32:63]) // b <- EXTS((RB)[32:63])
@ -533,7 +533,7 @@ XEEMITTER(cmp, 0x7C000000, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(cmpi, 0x2C000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(cmpi, 0x2C000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if L = 0 then // if L = 0 then
// a <- EXTS((RA)[32:63]) // a <- EXTS((RA)[32:63])
// else // else
@ -560,7 +560,7 @@ XEEMITTER(cmpi, 0x2C000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(cmpl, 0x7C000040, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(cmpl, 0x7C000040, X )(PPCHIRBuilder& f, InstrData& i) {
// if L = 0 then // if L = 0 then
// a <- i32.0 || (RA)[32:63] // a <- i32.0 || (RA)[32:63]
// b <- i32.0 || (RB)[32:63] // b <- i32.0 || (RB)[32:63]
@ -589,7 +589,7 @@ XEEMITTER(cmpl, 0x7C000040, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(cmpli, 0x28000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(cmpli, 0x28000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if L = 0 then // if L = 0 then
// a <- i32.0 || (RA)[32:63] // a <- i32.0 || (RA)[32:63]
// else // else
@ -619,7 +619,7 @@ XEEMITTER(cmpli, 0x28000000, D )(PPCFunctionBuilder& f, InstrData& i) {
// Integer logical (A-5) // Integer logical (A-5)
XEEMITTER(andx, 0x7C000038, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(andx, 0x7C000038, X )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) & (RB) // RA <- (RS) & (RB)
Value* ra = f.And(f.LoadGPR(i.X.RT), f.LoadGPR(i.X.RB)); Value* ra = f.And(f.LoadGPR(i.X.RT), f.LoadGPR(i.X.RB));
if (i.X.Rc) { if (i.X.Rc) {
@ -629,7 +629,7 @@ XEEMITTER(andx, 0x7C000038, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(andcx, 0x7C000078, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(andcx, 0x7C000078, X )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) & ¬(RB) // RA <- (RS) & ¬(RB)
Value* ra = f.And(f.LoadGPR(i.X.RT), f.Not(f.LoadGPR(i.X.RB))); Value* ra = f.And(f.LoadGPR(i.X.RT), f.Not(f.LoadGPR(i.X.RB)));
if (i.X.Rc) { if (i.X.Rc) {
@ -639,7 +639,7 @@ XEEMITTER(andcx, 0x7C000078, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(andix, 0x70000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(andix, 0x70000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) & (i48.0 || UI) // RA <- (RS) & (i48.0 || UI)
Value* ra = f.And( Value* ra = f.And(
f.LoadGPR(i.D.RT), f.LoadGPR(i.D.RT),
@ -649,7 +649,7 @@ XEEMITTER(andix, 0x70000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(andisx, 0x74000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(andisx, 0x74000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) & (i32.0 || UI || i16.0) // RA <- (RS) & (i32.0 || UI || i16.0)
Value* ra = f.And( Value* ra = f.And(
f.LoadGPR(i.D.RT), f.LoadGPR(i.D.RT),
@ -659,7 +659,7 @@ XEEMITTER(andisx, 0x74000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(cntlzdx, 0x7C000074, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(cntlzdx, 0x7C000074, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- 0 // n <- 0
// do while n < 64 // do while n < 64
// if (RS)[n] = 1 then leave n // if (RS)[n] = 1 then leave n
@ -674,7 +674,7 @@ XEEMITTER(cntlzdx, 0x7C000074, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(cntlzwx, 0x7C000034, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(cntlzwx, 0x7C000034, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- 32 // n <- 32
// do while n < 64 // do while n < 64
// if (RS)[n] = 1 then leave n // if (RS)[n] = 1 then leave n
@ -690,7 +690,7 @@ XEEMITTER(cntlzwx, 0x7C000034, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(eqvx, 0x7C000238, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(eqvx, 0x7C000238, X )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) == (RB) // RA <- (RS) == (RB)
Value* ra = f.Xor(f.LoadGPR(i.X.RT), f.LoadGPR(i.X.RB)); Value* ra = f.Xor(f.LoadGPR(i.X.RT), f.LoadGPR(i.X.RB));
ra = f.Not(ra); ra = f.Not(ra);
@ -701,7 +701,7 @@ XEEMITTER(eqvx, 0x7C000238, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(extsbx, 0x7C000774, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(extsbx, 0x7C000774, X )(PPCHIRBuilder& f, InstrData& i) {
// s <- (RS)[56] // s <- (RS)[56]
// RA[56:63] <- (RS)[56:63] // RA[56:63] <- (RS)[56:63]
// RA[0:55] <- i56.s // RA[0:55] <- i56.s
@ -714,7 +714,7 @@ XEEMITTER(extsbx, 0x7C000774, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(extshx, 0x7C000734, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(extshx, 0x7C000734, X )(PPCHIRBuilder& f, InstrData& i) {
// s <- (RS)[48] // s <- (RS)[48]
// RA[48:63] <- (RS)[48:63] // RA[48:63] <- (RS)[48:63]
// RA[0:47] <- 48.s // RA[0:47] <- 48.s
@ -727,7 +727,7 @@ XEEMITTER(extshx, 0x7C000734, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(extswx, 0x7C0007B4, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(extswx, 0x7C0007B4, X )(PPCHIRBuilder& f, InstrData& i) {
// s <- (RS)[32] // s <- (RS)[32]
// RA[32:63] <- (RS)[32:63] // RA[32:63] <- (RS)[32:63]
// RA[0:31] <- i32.s // RA[0:31] <- i32.s
@ -740,12 +740,12 @@ XEEMITTER(extswx, 0x7C0007B4, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(nandx, 0x7C0003B8, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(nandx, 0x7C0003B8, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(norx, 0x7C0000F8, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(norx, 0x7C0000F8, X )(PPCHIRBuilder& f, InstrData& i) {
// RA <- ¬((RS) | (RB)) // RA <- ¬((RS) | (RB))
Value* ra = f.Or( Value* ra = f.Or(
f.LoadGPR(i.X.RT), f.LoadGPR(i.X.RT),
@ -758,7 +758,7 @@ XEEMITTER(norx, 0x7C0000F8, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(orx, 0x7C000378, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(orx, 0x7C000378, X )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) | (RB) // RA <- (RS) | (RB)
if (i.X.RT == i.X.RB && i.X.RT == i.X.RA && if (i.X.RT == i.X.RB && i.X.RT == i.X.RA &&
!i.X.Rc) { !i.X.Rc) {
@ -781,7 +781,7 @@ XEEMITTER(orx, 0x7C000378, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(orcx, 0x7C000338, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(orcx, 0x7C000338, X )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) | ¬(RB) // RA <- (RS) | ¬(RB)
Value* ra = f.Or( Value* ra = f.Or(
f.LoadGPR(i.X.RT), f.LoadGPR(i.X.RT),
@ -793,7 +793,7 @@ XEEMITTER(orcx, 0x7C000338, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(ori, 0x60000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(ori, 0x60000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) | (i48.0 || UI) // RA <- (RS) | (i48.0 || UI)
if (!i.D.RA && !i.D.RT && !i.D.DS) { if (!i.D.RA && !i.D.RT && !i.D.DS) {
f.Nop(); f.Nop();
@ -806,7 +806,7 @@ XEEMITTER(ori, 0x60000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(oris, 0x64000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(oris, 0x64000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) | (i32.0 || UI || i16.0) // RA <- (RS) | (i32.0 || UI || i16.0)
Value* ra = f.Or( Value* ra = f.Or(
f.LoadGPR(i.D.RT), f.LoadGPR(i.D.RT),
@ -815,7 +815,7 @@ XEEMITTER(oris, 0x64000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(xorx, 0x7C000278, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(xorx, 0x7C000278, X )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) XOR (RB) // RA <- (RS) XOR (RB)
Value* ra = f.Xor( Value* ra = f.Xor(
f.LoadGPR(i.X.RT), f.LoadGPR(i.X.RT),
@ -827,7 +827,7 @@ XEEMITTER(xorx, 0x7C000278, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(xori, 0x68000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(xori, 0x68000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) XOR (i48.0 || UI) // RA <- (RS) XOR (i48.0 || UI)
Value* ra = f.Xor( Value* ra = f.Xor(
f.LoadGPR(i.D.RT), f.LoadGPR(i.D.RT),
@ -836,7 +836,7 @@ XEEMITTER(xori, 0x68000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(xoris, 0x6C000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(xoris, 0x6C000000, D )(PPCHIRBuilder& f, InstrData& i) {
// RA <- (RS) XOR (i32.0 || UI || i16.0) // RA <- (RS) XOR (i32.0 || UI || i16.0)
Value* ra = f.Xor( Value* ra = f.Xor(
f.LoadGPR(i.D.RT), f.LoadGPR(i.D.RT),
@ -848,7 +848,7 @@ XEEMITTER(xoris, 0x6C000000, D )(PPCFunctionBuilder& f, InstrData& i) {
// Integer rotate (A-6) // Integer rotate (A-6)
XEEMITTER(rld, 0x78000000, MDS)(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(rld, 0x78000000, MDS)(PPCHIRBuilder& f, InstrData& i) {
if (i.MD.idx == 0) { if (i.MD.idx == 0) {
// XEEMITTER(rldiclx, 0x78000000, MD ) // XEEMITTER(rldiclx, 0x78000000, MD )
// n <- sh[5] || sh[0:4] // n <- sh[5] || sh[0:4]
@ -941,7 +941,7 @@ XEEMITTER(rld, 0x78000000, MDS)(PPCFunctionBuilder& f, InstrData& i) {
} }
} }
XEEMITTER(rlwimix, 0x50000000, M )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(rlwimix, 0x50000000, M )(PPCHIRBuilder& f, InstrData& i) {
// n <- SH // n <- SH
// r <- ROTL32((RS)[32:63], n) // r <- ROTL32((RS)[32:63], n)
// m <- MASK(MB+32, ME+32) // m <- MASK(MB+32, ME+32)
@ -965,7 +965,7 @@ XEEMITTER(rlwimix, 0x50000000, M )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(rlwinmx, 0x54000000, M )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(rlwinmx, 0x54000000, M )(PPCHIRBuilder& f, InstrData& i) {
// n <- SH // n <- SH
// r <- ROTL32((RS)[32:63], n) // r <- ROTL32((RS)[32:63], n)
// m <- MASK(MB+32, ME+32) // m <- MASK(MB+32, ME+32)
@ -992,7 +992,7 @@ XEEMITTER(rlwinmx, 0x54000000, M )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(rlwnmx, 0x5C000000, M )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(rlwnmx, 0x5C000000, M )(PPCHIRBuilder& f, InstrData& i) {
// n <- (RB)[59:63] // n <- (RB)[59:63]
// r <- ROTL32((RS)[32:63], n) // r <- ROTL32((RS)[32:63], n)
// m <- MASK(MB+32, ME+32) // m <- MASK(MB+32, ME+32)
@ -1016,7 +1016,7 @@ XEEMITTER(rlwnmx, 0x5C000000, M )(PPCFunctionBuilder& f, InstrData& i) {
// Integer shift (A-7) // Integer shift (A-7)
XEEMITTER(sldx, 0x7C000036, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sldx, 0x7C000036, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- (RB)[59:63] // n <- (RB)[59:63]
// r <- ROTL64((RS), n) // r <- ROTL64((RS), n)
// if (RB)[58] = 0 then // if (RB)[58] = 0 then
@ -1032,7 +1032,7 @@ XEEMITTER(sldx, 0x7C000036, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(slwx, 0x7C000030, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(slwx, 0x7C000030, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- (RB)[59:63] // n <- (RB)[59:63]
// r <- ROTL32((RS)[32:63], n) // r <- ROTL32((RS)[32:63], n)
// if (RB)[58] = 0 then // if (RB)[58] = 0 then
@ -1050,7 +1050,7 @@ XEEMITTER(slwx, 0x7C000030, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(srdx, 0x7C000436, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(srdx, 0x7C000436, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- (RB)[58:63] // n <- (RB)[58:63]
// r <- ROTL64((RS), 64-n) // r <- ROTL64((RS), 64-n)
// if (RB)[57] = 0 then // if (RB)[57] = 0 then
@ -1067,7 +1067,7 @@ XEEMITTER(srdx, 0x7C000436, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(srwx, 0x7C000430, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(srwx, 0x7C000430, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- (RB)[59:63] // n <- (RB)[59:63]
// r <- ROTL32((RS)[32:63], 64-n) // r <- ROTL32((RS)[32:63], 64-n)
// if (RB)[58] = 0 then // if (RB)[58] = 0 then
@ -1086,7 +1086,7 @@ XEEMITTER(srwx, 0x7C000430, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
// XEEMITTER(sradx, 0x7C000634, X )(PPCFunctionBuilder& f, InstrData& i) { // XEEMITTER(sradx, 0x7C000634, X )(PPCHIRBuilder& f, InstrData& i) {
// // n <- rB[58-63] // // n <- rB[58-63]
// // r <- ROTL[64](rS, 64 - n) // // r <- ROTL[64](rS, 64 - n)
// // if rB[57] = 0 then m ← MASK(n, 63) // // if rB[57] = 0 then m ← MASK(n, 63)
@ -1138,7 +1138,7 @@ XEEMITTER(srwx, 0x7C000430, X )(PPCFunctionBuilder& f, InstrData& i) {
// return 0; // return 0;
// } // }
XEEMITTER(sradix, 0x7C000674, XS )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sradix, 0x7C000674, XS )(PPCHIRBuilder& f, InstrData& i) {
// n <- sh[5] || sh[0-4] // n <- sh[5] || sh[0-4]
// r <- ROTL[64](rS, 64 - n) // r <- ROTL[64](rS, 64 - n)
// m ← MASK(n, 63) // m ← MASK(n, 63)
@ -1167,7 +1167,7 @@ XEEMITTER(sradix, 0x7C000674, XS )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(srawx, 0x7C000630, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(srawx, 0x7C000630, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- rB[59-63] // n <- rB[59-63]
// r <- ROTL32((RS)[32:63], 64-n) // r <- ROTL32((RS)[32:63], 64-n)
// m <- MASK(n+32, 63) // m <- MASK(n+32, 63)
@ -1196,7 +1196,7 @@ XEEMITTER(srawx, 0x7C000630, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(srawix, 0x7C000670, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(srawix, 0x7C000670, X )(PPCHIRBuilder& f, InstrData& i) {
// n <- SH // n <- SH
// r <- ROTL32((RS)[32:63], 64-n) // r <- ROTL32((RS)[32:63], 64-n)
// m <- MASK(n+32, 63) // m <- MASK(n+32, 63)

View File

@ -10,7 +10,7 @@
#include <alloy/frontend/ppc/ppc_emit-private.h> #include <alloy/frontend/ppc/ppc_emit-private.h>
#include <alloy/frontend/ppc/ppc_context.h> #include <alloy/frontend/ppc/ppc_context.h>
#include <alloy/frontend/ppc/ppc_function_builder.h> #include <alloy/frontend/ppc/ppc_hir_builder.h>
using namespace alloy::frontend::ppc; using namespace alloy::frontend::ppc;
@ -24,7 +24,7 @@ namespace ppc {
int InstrEmit_branch( int InstrEmit_branch(
PPCFunctionBuilder& f, const char* src, uint64_t cia, PPCHIRBuilder& f, const char* src, uint64_t cia,
Value* nia, bool lk, Value* cond = NULL, bool expect_true = true) { Value* nia, bool lk, Value* cond = NULL, bool expect_true = true) {
uint32_t call_flags = 0; uint32_t call_flags = 0;
@ -93,7 +93,7 @@ int InstrEmit_branch(
} }
XEEMITTER(bx, 0x48000000, I )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(bx, 0x48000000, I )(PPCHIRBuilder& f, InstrData& i) {
// if AA then // if AA then
// NIA <- EXTS(LI || 0b00) // NIA <- EXTS(LI || 0b00)
// else // else
@ -112,7 +112,7 @@ XEEMITTER(bx, 0x48000000, I )(PPCFunctionBuilder& f, InstrData& i) {
f, "bx", i.address, f.LoadConstant(nia), i.I.LK); f, "bx", i.address, f.LoadConstant(nia), i.I.LK);
} }
XEEMITTER(bcx, 0x40000000, B )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(bcx, 0x40000000, B )(PPCHIRBuilder& f, InstrData& i) {
// if ¬BO[2] then // if ¬BO[2] then
// CTR <- CTR - 1 // CTR <- CTR - 1
// ctr_ok <- BO[2] | ((CTR[0:63] != 0) XOR BO[3]) // ctr_ok <- BO[2] | ((CTR[0:63] != 0) XOR BO[3])
@ -188,7 +188,7 @@ XEEMITTER(bcx, 0x40000000, B )(PPCFunctionBuilder& f, InstrData& i) {
f, "bcx", i.address, f.LoadConstant(nia), i.B.LK, ok, expect_true); f, "bcx", i.address, f.LoadConstant(nia), i.B.LK, ok, expect_true);
} }
XEEMITTER(bcctrx, 0x4C000420, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(bcctrx, 0x4C000420, XL )(PPCHIRBuilder& f, InstrData& i) {
// cond_ok <- BO[0] | (CR[BI+32] ≡ BO[1]) // cond_ok <- BO[0] | (CR[BI+32] ≡ BO[1])
// if cond_ok then // if cond_ok then
// NIA <- CTR[0:61] || 0b00 // NIA <- CTR[0:61] || 0b00
@ -220,7 +220,7 @@ XEEMITTER(bcctrx, 0x4C000420, XL )(PPCFunctionBuilder& f, InstrData& i) {
f, "bcctrx", i.address, f.LoadCTR(), i.XL.LK, cond_ok, expect_true); f, "bcctrx", i.address, f.LoadCTR(), i.XL.LK, cond_ok, expect_true);
} }
XEEMITTER(bclrx, 0x4C000020, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(bclrx, 0x4C000020, XL )(PPCHIRBuilder& f, InstrData& i) {
// if ¬BO[2] then // if ¬BO[2] then
// CTR <- CTR - 1 // CTR <- CTR - 1
// ctr_ok <- BO[2] | ((CTR[0:63] != 0) XOR BO[3] // ctr_ok <- BO[2] | ((CTR[0:63] != 0) XOR BO[3]
@ -314,47 +314,47 @@ XEEMITTER(bclrx, 0x4C000020, XL )(PPCFunctionBuilder& f, InstrData& i) {
// Condition register logical (A-23) // Condition register logical (A-23)
XEEMITTER(crand, 0x4C000202, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(crand, 0x4C000202, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(crandc, 0x4C000102, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(crandc, 0x4C000102, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(creqv, 0x4C000242, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(creqv, 0x4C000242, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(crnand, 0x4C0001C2, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(crnand, 0x4C0001C2, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(crnor, 0x4C000042, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(crnor, 0x4C000042, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(cror, 0x4C000382, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(cror, 0x4C000382, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(crorc, 0x4C000342, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(crorc, 0x4C000342, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(crxor, 0x4C000182, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(crxor, 0x4C000182, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mcrf, 0x4C000000, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mcrf, 0x4C000000, XL )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
@ -362,7 +362,7 @@ XEEMITTER(mcrf, 0x4C000000, XL )(PPCFunctionBuilder& f, InstrData& i) {
// System linkage (A-24) // System linkage (A-24)
XEEMITTER(sc, 0x44000002, SC )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sc, 0x44000002, SC )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
@ -370,7 +370,7 @@ XEEMITTER(sc, 0x44000002, SC )(PPCFunctionBuilder& f, InstrData& i) {
// Trap (A-25) // Trap (A-25)
int InstrEmit_trap(PPCFunctionBuilder& f, InstrData& i, int InstrEmit_trap(PPCHIRBuilder& f, InstrData& i,
Value* va, Value* vb, uint32_t TO) { Value* va, Value* vb, uint32_t TO) {
// if (a < b) & TO[0] then TRAP // if (a < b) & TO[0] then TRAP
// if (a > b) & TO[1] then TRAP // if (a > b) & TO[1] then TRAP
@ -406,7 +406,7 @@ int InstrEmit_trap(PPCFunctionBuilder& f, InstrData& i,
return 0; return 0;
} }
XEEMITTER(td, 0x7C000088, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(td, 0x7C000088, X )(PPCHIRBuilder& f, InstrData& i) {
// a <- (RA) // a <- (RA)
// b <- (RB) // b <- (RB)
// if (a < b) & TO[0] then TRAP // if (a < b) & TO[0] then TRAP
@ -419,7 +419,7 @@ XEEMITTER(td, 0x7C000088, X )(PPCFunctionBuilder& f, InstrData& i) {
return InstrEmit_trap(f, i, ra, rb, i.X.RT); return InstrEmit_trap(f, i, ra, rb, i.X.RT);
} }
XEEMITTER(tdi, 0x08000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(tdi, 0x08000000, D )(PPCHIRBuilder& f, InstrData& i) {
// a <- (RA) // a <- (RA)
// if (a < EXTS(SI)) & TO[0] then TRAP // if (a < EXTS(SI)) & TO[0] then TRAP
// if (a > EXTS(SI)) & TO[1] then TRAP // if (a > EXTS(SI)) & TO[1] then TRAP
@ -431,7 +431,7 @@ XEEMITTER(tdi, 0x08000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return InstrEmit_trap(f, i, ra, rb, i.D.RT); return InstrEmit_trap(f, i, ra, rb, i.D.RT);
} }
XEEMITTER(tw, 0x7C000008, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(tw, 0x7C000008, X )(PPCHIRBuilder& f, InstrData& i) {
// a <- EXTS((RA)[32:63]) // a <- EXTS((RA)[32:63])
// b <- EXTS((RB)[32:63]) // b <- EXTS((RB)[32:63])
// if (a < b) & TO[0] then TRAP // if (a < b) & TO[0] then TRAP
@ -446,7 +446,7 @@ XEEMITTER(tw, 0x7C000008, X )(PPCFunctionBuilder& f, InstrData& i) {
return InstrEmit_trap(f, i, ra, rb, i.X.RT); return InstrEmit_trap(f, i, ra, rb, i.X.RT);
} }
XEEMITTER(twi, 0x0C000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(twi, 0x0C000000, D )(PPCHIRBuilder& f, InstrData& i) {
// a <- EXTS((RA)[32:63]) // a <- EXTS((RA)[32:63])
// if (a < EXTS(SI)) & TO[0] then TRAP // if (a < EXTS(SI)) & TO[0] then TRAP
// if (a > EXTS(SI)) & TO[1] then TRAP // if (a > EXTS(SI)) & TO[1] then TRAP
@ -462,12 +462,12 @@ XEEMITTER(twi, 0x0C000000, D )(PPCFunctionBuilder& f, InstrData& i) {
// Processor control (A-26) // Processor control (A-26)
XEEMITTER(mfcr, 0x7C000026, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mfcr, 0x7C000026, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mfspr, 0x7C0002A6, XFX)(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mfspr, 0x7C0002A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
// n <- spr[5:9] || spr[0:4] // n <- spr[5:9] || spr[0:4]
// if length(SPR(n)) = 64 then // if length(SPR(n)) = 64 then
// RT <- SPR(n) // RT <- SPR(n)
@ -497,7 +497,7 @@ XEEMITTER(mfspr, 0x7C0002A6, XFX)(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(mftb, 0x7C0002E6, XFX)(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mftb, 0x7C0002E6, XFX)(PPCHIRBuilder& f, InstrData& i) {
Value* time; Value* time;
LARGE_INTEGER counter; LARGE_INTEGER counter;
if (QueryPerformanceCounter(&counter)) { if (QueryPerformanceCounter(&counter)) {
@ -510,12 +510,12 @@ XEEMITTER(mftb, 0x7C0002E6, XFX)(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(mtcrf, 0x7C000120, XFX)(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtcrf, 0x7C000120, XFX)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mtspr, 0x7C0003A6, XFX)(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtspr, 0x7C0003A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
// n <- spr[5:9] || spr[0:4] // n <- spr[5:9] || spr[0:4]
// if length(SPR(n)) = 64 then // if length(SPR(n)) = 64 then
// SPR(n) <- (RS) // SPR(n) <- (RS)
@ -549,17 +549,17 @@ XEEMITTER(mtspr, 0x7C0003A6, XFX)(PPCFunctionBuilder& f, InstrData& i) {
// TODO(benvanik): MSR is used for toggling interrupts, and it'd be nice to // TODO(benvanik): MSR is used for toggling interrupts, and it'd be nice to
// obey that setting. It's usually guarding atomic stores. // obey that setting. It's usually guarding atomic stores.
XEEMITTER(mfmsr, 0x7C0000A6, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mfmsr, 0x7C0000A6, X )(PPCHIRBuilder& f, InstrData& i) {
f.Nop(); f.Nop();
return 0; return 0;
} }
XEEMITTER(mtmsr, 0x7C000124, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtmsr, 0x7C000124, X )(PPCHIRBuilder& f, InstrData& i) {
f.Nop(); f.Nop();
return 0; return 0;
} }
XEEMITTER(mtmsrd, 0x7C000164, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtmsrd, 0x7C000164, X )(PPCHIRBuilder& f, InstrData& i) {
f.Nop(); f.Nop();
return 0; return 0;
} }

View File

@ -10,7 +10,7 @@
#include <alloy/frontend/ppc/ppc_emit-private.h> #include <alloy/frontend/ppc/ppc_emit-private.h>
#include <alloy/frontend/ppc/ppc_context.h> #include <alloy/frontend/ppc/ppc_context.h>
#include <alloy/frontend/ppc/ppc_function_builder.h> #include <alloy/frontend/ppc/ppc_hir_builder.h>
using namespace alloy::frontend::ppc; using namespace alloy::frontend::ppc;
@ -35,7 +35,7 @@ namespace ppc {
// Floating-point arithmetic (A-8) // Floating-point arithmetic (A-8)
XEEMITTER(faddx, 0xFC00002A, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(faddx, 0xFC00002A, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) + (frB) // frD <- (frA) + (frB)
Value* v = f.Add(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB)); Value* v = f.Add(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v); f.StoreFPR(i.A.FRT, v);
@ -48,7 +48,7 @@ XEEMITTER(faddx, 0xFC00002A, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(faddsx, 0xEC00002A, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(faddsx, 0xEC00002A, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) + (frB) // frD <- (frA) + (frB)
Value* v = f.Add(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB)); Value* v = f.Add(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE); v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE);
@ -62,7 +62,7 @@ XEEMITTER(faddsx, 0xEC00002A, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fdivx, 0xFC000024, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fdivx, 0xFC000024, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- frA / frB // frD <- frA / frB
Value* v = f.Div(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB)); Value* v = f.Div(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v); f.StoreFPR(i.A.FRT, v);
@ -75,7 +75,7 @@ XEEMITTER(fdivx, 0xFC000024, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fdivsx, 0xEC000024, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fdivsx, 0xEC000024, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- frA / frB // frD <- frA / frB
Value* v = f.Div(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB)); Value* v = f.Div(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE); v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE);
@ -89,7 +89,7 @@ XEEMITTER(fdivsx, 0xEC000024, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fmulx, 0xFC000032, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fmulx, 0xFC000032, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) x (frC) // frD <- (frA) x (frC)
Value* v = f.Mul(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC)); Value* v = f.Mul(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC));
f.StoreFPR(i.A.FRT, v); f.StoreFPR(i.A.FRT, v);
@ -102,7 +102,7 @@ XEEMITTER(fmulx, 0xFC000032, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fmulsx, 0xEC000032, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fmulsx, 0xEC000032, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) x (frC) // frD <- (frA) x (frC)
Value* v = f.Mul(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC)); Value* v = f.Mul(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC));
v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE); v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE);
@ -116,17 +116,17 @@ XEEMITTER(fmulsx, 0xEC000032, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fresx, 0xEC000030, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fresx, 0xEC000030, A )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(frsqrtex, 0xFC000034, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(frsqrtex, 0xFC000034, A )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(fsubx, 0xFC000028, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fsubx, 0xFC000028, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) - (frB) // frD <- (frA) - (frB)
Value* v = f.Sub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB)); Value* v = f.Sub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v); f.StoreFPR(i.A.FRT, v);
@ -139,7 +139,7 @@ XEEMITTER(fsubx, 0xFC000028, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fsubsx, 0xEC000028, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fsubsx, 0xEC000028, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) - (frB) // frD <- (frA) - (frB)
Value* v = f.Sub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB)); Value* v = f.Sub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE); v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE);
@ -153,7 +153,7 @@ XEEMITTER(fsubsx, 0xEC000028, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fselx, 0xFC00002E, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fselx, 0xFC00002E, A )(PPCHIRBuilder& f, InstrData& i) {
// if (frA) >= 0.0 // if (frA) >= 0.0
// then frD <- (frC) // then frD <- (frC)
// else frD <- (frB) // else frD <- (frB)
@ -168,7 +168,7 @@ XEEMITTER(fselx, 0xFC00002E, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fsqrtx, 0xFC00002C, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fsqrtx, 0xFC00002C, A )(PPCHIRBuilder& f, InstrData& i) {
// Double precision: // Double precision:
// frD <- sqrt(frB) // frD <- sqrt(frB)
Value* v = f.Sqrt(f.LoadFPR(i.A.FRA)); Value* v = f.Sqrt(f.LoadFPR(i.A.FRA));
@ -182,7 +182,7 @@ XEEMITTER(fsqrtx, 0xFC00002C, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fsqrtsx, 0xEC00002C, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fsqrtsx, 0xEC00002C, A )(PPCHIRBuilder& f, InstrData& i) {
// Single precision: // Single precision:
// frD <- sqrt(frB) // frD <- sqrt(frB)
Value* v = f.Sqrt(f.LoadFPR(i.A.FRA)); Value* v = f.Sqrt(f.LoadFPR(i.A.FRA));
@ -200,7 +200,7 @@ XEEMITTER(fsqrtsx, 0xEC00002C, A )(PPCFunctionBuilder& f, InstrData& i) {
// Floating-point multiply-add (A-9) // Floating-point multiply-add (A-9)
XEEMITTER(fmaddx, 0xFC00003A, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fmaddx, 0xFC00003A, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) + frB // frD <- (frA x frC) + frB
Value* v = f.MulAdd( Value* v = f.MulAdd(
f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRA),
@ -216,7 +216,7 @@ XEEMITTER(fmaddx, 0xFC00003A, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fmaddsx, 0xEC00003A, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fmaddsx, 0xEC00003A, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) + frB // frD <- (frA x frC) + frB
Value* v = f.MulAdd( Value* v = f.MulAdd(
f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRA),
@ -233,7 +233,7 @@ XEEMITTER(fmaddsx, 0xEC00003A, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fmsubx, 0xFC000038, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fmsubx, 0xFC000038, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) - frB // frD <- (frA x frC) - frB
Value* v = f.MulSub( Value* v = f.MulSub(
f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRA),
@ -249,7 +249,7 @@ XEEMITTER(fmsubx, 0xFC000038, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fmsubsx, 0xEC000038, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fmsubsx, 0xEC000038, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) - frB // frD <- (frA x frC) - frB
Value* v = f.MulSub( Value* v = f.MulSub(
f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRA),
@ -266,17 +266,17 @@ XEEMITTER(fmsubsx, 0xEC000038, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fnmaddx, 0xFC00003E, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fnmaddx, 0xFC00003E, A )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(fnmaddsx, 0xEC00003E, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fnmaddsx, 0xEC00003E, A )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(fnmsubx, 0xFC00003C, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fnmsubx, 0xFC00003C, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- -([frA x frC] - frB) // frD <- -([frA x frC] - frB)
Value* v = f.Neg(f.MulSub( Value* v = f.Neg(f.MulSub(
f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRA),
@ -292,7 +292,7 @@ XEEMITTER(fnmsubx, 0xFC00003C, A )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fnmsubsx, 0xEC00003C, A )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fnmsubsx, 0xEC00003C, A )(PPCHIRBuilder& f, InstrData& i) {
// frD <- -([frA x frC] - frB) // frD <- -([frA x frC] - frB)
Value* v = f.Neg(f.MulSub( Value* v = f.Neg(f.MulSub(
f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRA),
@ -312,7 +312,7 @@ XEEMITTER(fnmsubsx, 0xEC00003C, A )(PPCFunctionBuilder& f, InstrData& i) {
// Floating-point rounding and conversion (A-10) // Floating-point rounding and conversion (A-10)
XEEMITTER(fcfidx, 0xFC00069C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fcfidx, 0xFC00069C, X )(PPCHIRBuilder& f, InstrData& i) {
// frD <- signed_int64_to_double( frB ) // frD <- signed_int64_to_double( frB )
Value* v = f.Convert( Value* v = f.Convert(
f.Cast(f.LoadFPR(i.A.FRB), INT64_TYPE), f.Cast(f.LoadFPR(i.A.FRB), INT64_TYPE),
@ -327,7 +327,7 @@ XEEMITTER(fcfidx, 0xFC00069C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fctidx, 0xFC00065C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fctidx, 0xFC00065C, X )(PPCHIRBuilder& f, InstrData& i) {
// frD <- double_to_signed_int64( frB ) // frD <- double_to_signed_int64( frB )
// TODO(benvanik): pull from FPSCR[RN] // TODO(benvanik): pull from FPSCR[RN]
RoundMode round_mode = ROUND_TO_ZERO; RoundMode round_mode = ROUND_TO_ZERO;
@ -343,12 +343,12 @@ XEEMITTER(fctidx, 0xFC00065C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fctidzx, 0xFC00065E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fctidzx, 0xFC00065E, X )(PPCHIRBuilder& f, InstrData& i) {
// TODO(benvanik): assuming round to zero is always set, is that ok? // TODO(benvanik): assuming round to zero is always set, is that ok?
return InstrEmit_fctidx(f, i); return InstrEmit_fctidx(f, i);
} }
XEEMITTER(fctiwx, 0xFC00001C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fctiwx, 0xFC00001C, X )(PPCHIRBuilder& f, InstrData& i) {
// frD <- double_to_signed_int32( frB ) // frD <- double_to_signed_int32( frB )
// TODO(benvanik): pull from FPSCR[RN] // TODO(benvanik): pull from FPSCR[RN]
RoundMode round_mode = ROUND_TO_ZERO; RoundMode round_mode = ROUND_TO_ZERO;
@ -364,12 +364,12 @@ XEEMITTER(fctiwx, 0xFC00001C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fctiwzx, 0xFC00001E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fctiwzx, 0xFC00001E, X )(PPCHIRBuilder& f, InstrData& i) {
// TODO(benvanik): assuming round to zero is always set, is that ok? // TODO(benvanik): assuming round to zero is always set, is that ok?
return InstrEmit_fctiwx(f, i); return InstrEmit_fctiwx(f, i);
} }
XEEMITTER(frspx, 0xFC000018, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(frspx, 0xFC000018, X )(PPCHIRBuilder& f, InstrData& i) {
// frD <- Round_single(frB) // frD <- Round_single(frB)
// TODO(benvanik): pull from FPSCR[RN] // TODO(benvanik): pull from FPSCR[RN]
RoundMode round_mode = ROUND_TO_ZERO; RoundMode round_mode = ROUND_TO_ZERO;
@ -388,7 +388,7 @@ XEEMITTER(frspx, 0xFC000018, X )(PPCFunctionBuilder& f, InstrData& i) {
// Floating-point compare (A-11) // Floating-point compare (A-11)
int InstrEmit_fcmpx_(PPCFunctionBuilder& f, InstrData& i, bool ordered) { int InstrEmit_fcmpx_(PPCHIRBuilder& f, InstrData& i, bool ordered) {
// if (FRA) is a NaN or (FRB) is a NaN then // if (FRA) is a NaN or (FRB) is a NaN then
// c <- 0b0001 // c <- 0b0001
// else if (FRA) < (FRB) then // else if (FRA) < (FRB) then
@ -410,42 +410,42 @@ int InstrEmit_fcmpx_(PPCFunctionBuilder& f, InstrData& i, bool ordered) {
f.UpdateCR(crf, f.LoadFPR(i.X.RA), f.LoadFPR(i.X.RB), false); f.UpdateCR(crf, f.LoadFPR(i.X.RA), f.LoadFPR(i.X.RB), false);
return 0; return 0;
} }
XEEMITTER(fcmpo, 0xFC000040, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fcmpo, 0xFC000040, X )(PPCHIRBuilder& f, InstrData& i) {
return InstrEmit_fcmpx_(f, i, true); return InstrEmit_fcmpx_(f, i, true);
} }
XEEMITTER(fcmpu, 0xFC000000, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fcmpu, 0xFC000000, X )(PPCHIRBuilder& f, InstrData& i) {
return InstrEmit_fcmpx_(f, i, false); return InstrEmit_fcmpx_(f, i, false);
} }
// Floating-point status and control register (A // Floating-point status and control register (A
XEEMITTER(mcrfs, 0xFC000080, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mcrfs, 0xFC000080, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mffsx, 0xFC00048E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mffsx, 0xFC00048E, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mtfsb0x, 0xFC00008C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtfsb0x, 0xFC00008C, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mtfsb1x, 0xFC00004C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtfsb1x, 0xFC00004C, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mtfsfx, 0xFC00058E, XFL)(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtfsfx, 0xFC00058E, XFL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(mtfsfix, 0xFC00010C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(mtfsfix, 0xFC00010C, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
@ -453,7 +453,7 @@ XEEMITTER(mtfsfix, 0xFC00010C, X )(PPCFunctionBuilder& f, InstrData& i) {
// Floating-point move (A-21) // Floating-point move (A-21)
XEEMITTER(fabsx, 0xFC000210, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fabsx, 0xFC000210, X )(PPCHIRBuilder& f, InstrData& i) {
// frD <- abs(frB) // frD <- abs(frB)
Value* v = f.Abs(f.LoadFPR(i.X.RB)); Value* v = f.Abs(f.LoadFPR(i.X.RB));
f.StoreFPR(i.X.RT, v); f.StoreFPR(i.X.RT, v);
@ -465,7 +465,7 @@ XEEMITTER(fabsx, 0xFC000210, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fmrx, 0xFC000090, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fmrx, 0xFC000090, X )(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frB) // frD <- (frB)
Value* v = f.LoadFPR(i.X.RB); Value* v = f.LoadFPR(i.X.RB);
f.StoreFPR(i.X.RT, v); f.StoreFPR(i.X.RT, v);
@ -477,12 +477,12 @@ XEEMITTER(fmrx, 0xFC000090, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(fnabsx, 0xFC000110, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fnabsx, 0xFC000110, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(fnegx, 0xFC000050, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(fnegx, 0xFC000050, X )(PPCHIRBuilder& f, InstrData& i) {
// frD <- ¬ frB[0] || frB[1-63] // frD <- ¬ frB[0] || frB[1-63]
Value* v = f.Neg(f.LoadFPR(i.X.RB)); Value* v = f.Neg(f.LoadFPR(i.X.RB));
f.StoreFPR(i.X.RT, v); f.StoreFPR(i.X.RT, v);

View File

@ -10,7 +10,7 @@
#include <alloy/frontend/ppc/ppc_emit-private.h> #include <alloy/frontend/ppc/ppc_emit-private.h>
#include <alloy/frontend/ppc/ppc_context.h> #include <alloy/frontend/ppc/ppc_context.h>
#include <alloy/frontend/ppc/ppc_function_builder.h> #include <alloy/frontend/ppc/ppc_hir_builder.h>
using namespace alloy::frontend::ppc; using namespace alloy::frontend::ppc;
@ -24,7 +24,7 @@ namespace ppc {
#define TRUNCATE_ADDRESSES 0 #define TRUNCATE_ADDRESSES 0
Value* CalculateEA(PPCFunctionBuilder& f, uint32_t ra, uint32_t rb) { Value* CalculateEA(PPCHIRBuilder& f, uint32_t ra, uint32_t rb) {
#if TRUNCATE_ADDRESSES #if TRUNCATE_ADDRESSES
return f.ZeroExtend(f.Add( return f.ZeroExtend(f.Add(
f.Truncate(f.LoadGPR(ra), INT32_TYPE), f.Truncate(f.LoadGPR(ra), INT32_TYPE),
@ -34,7 +34,7 @@ Value* CalculateEA(PPCFunctionBuilder& f, uint32_t ra, uint32_t rb) {
#endif // TRUNCATE_ADDRESSES #endif // TRUNCATE_ADDRESSES
} }
Value* CalculateEA_0(PPCFunctionBuilder& f, uint32_t ra, uint32_t rb) { Value* CalculateEA_0(PPCHIRBuilder& f, uint32_t ra, uint32_t rb) {
#if TRUNCATE_ADDRESSES #if TRUNCATE_ADDRESSES
if (ra) { if (ra) {
return f.ZeroExtend(f.Add( return f.ZeroExtend(f.Add(
@ -52,7 +52,7 @@ Value* CalculateEA_0(PPCFunctionBuilder& f, uint32_t ra, uint32_t rb) {
#endif // TRUNCATE_ADDRESSES #endif // TRUNCATE_ADDRESSES
} }
Value* CalculateEA_i(PPCFunctionBuilder& f, uint32_t ra, uint64_t imm) { Value* CalculateEA_i(PPCHIRBuilder& f, uint32_t ra, uint64_t imm) {
#if TRUNCATE_ADDRESSES #if TRUNCATE_ADDRESSES
return f.ZeroExtend(f.Add( return f.ZeroExtend(f.Add(
f.Truncate(f.LoadGPR(ra), INT32_TYPE), f.Truncate(f.LoadGPR(ra), INT32_TYPE),
@ -62,7 +62,7 @@ Value* CalculateEA_i(PPCFunctionBuilder& f, uint32_t ra, uint64_t imm) {
#endif // TRUNCATE_ADDRESSES #endif // TRUNCATE_ADDRESSES
} }
Value* CalculateEA_0_i(PPCFunctionBuilder& f, uint32_t ra, uint64_t imm) { Value* CalculateEA_0_i(PPCHIRBuilder& f, uint32_t ra, uint64_t imm) {
#if TRUNCATE_ADDRESSES #if TRUNCATE_ADDRESSES
if (ra) { if (ra) {
return f.ZeroExtend(f.Add( return f.ZeroExtend(f.Add(
@ -83,7 +83,7 @@ Value* CalculateEA_0_i(PPCFunctionBuilder& f, uint32_t ra, uint64_t imm) {
// Integer load (A-13) // Integer load (A-13)
XEEMITTER(lbz, 0x88000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lbz, 0x88000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -96,7 +96,7 @@ XEEMITTER(lbz, 0x88000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lbzu, 0x8C000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lbzu, 0x8C000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// RT <- i56.0 || MEM(EA, 1) // RT <- i56.0 || MEM(EA, 1)
// RA <- EA // RA <- EA
@ -107,7 +107,7 @@ XEEMITTER(lbzu, 0x8C000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lbzux, 0x7C0000EE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lbzux, 0x7C0000EE, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// RT <- i56.0 || MEM(EA, 1) // RT <- i56.0 || MEM(EA, 1)
// RA <- EA // RA <- EA
@ -118,7 +118,7 @@ XEEMITTER(lbzux, 0x7C0000EE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lbzx, 0x7C0000AE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lbzx, 0x7C0000AE, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -131,7 +131,7 @@ XEEMITTER(lbzx, 0x7C0000AE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lha, 0xA8000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lha, 0xA8000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -144,17 +144,17 @@ XEEMITTER(lha, 0xA8000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lhau, 0xAC000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhau, 0xAC000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(lhaux, 0x7C0002EE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhaux, 0x7C0002EE, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(lhax, 0x7C0002AE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhax, 0x7C0002AE, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -167,7 +167,7 @@ XEEMITTER(lhax, 0x7C0002AE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lhz, 0xA0000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhz, 0xA0000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -180,7 +180,7 @@ XEEMITTER(lhz, 0xA0000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lhzu, 0xA4000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhzu, 0xA4000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// RT <- i48.0 || MEM(EA, 2) // RT <- i48.0 || MEM(EA, 2)
// RA <- EA // RA <- EA
@ -191,7 +191,7 @@ XEEMITTER(lhzu, 0xA4000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lhzux, 0x7C00026E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhzux, 0x7C00026E, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// RT <- i48.0 || MEM(EA, 2) // RT <- i48.0 || MEM(EA, 2)
// RA <- EA // RA <- EA
@ -202,7 +202,7 @@ XEEMITTER(lhzux, 0x7C00026E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lhzx, 0x7C00022E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhzx, 0x7C00022E, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -215,7 +215,7 @@ XEEMITTER(lhzx, 0x7C00022E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwa, 0xE8000002, DS )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwa, 0xE8000002, DS )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -228,7 +228,7 @@ XEEMITTER(lwa, 0xE8000002, DS )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwaux, 0x7C0002EA, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwaux, 0x7C0002EA, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// RT <- EXTS(MEM(EA, 4)) // RT <- EXTS(MEM(EA, 4))
// RA <- EA // RA <- EA
@ -239,7 +239,7 @@ XEEMITTER(lwaux, 0x7C0002EA, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwax, 0x7C0002AA, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwax, 0x7C0002AA, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -252,7 +252,7 @@ XEEMITTER(lwax, 0x7C0002AA, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwz, 0x80000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwz, 0x80000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -265,7 +265,7 @@ XEEMITTER(lwz, 0x80000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwzu, 0x84000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwzu, 0x84000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// RT <- i32.0 || MEM(EA, 4) // RT <- i32.0 || MEM(EA, 4)
// RA <- EA // RA <- EA
@ -276,7 +276,7 @@ XEEMITTER(lwzu, 0x84000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwzux, 0x7C00006E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwzux, 0x7C00006E, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// RT <- i32.0 || MEM(EA, 4) // RT <- i32.0 || MEM(EA, 4)
// RA <- EA // RA <- EA
@ -287,7 +287,7 @@ XEEMITTER(lwzux, 0x7C00006E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwzx, 0x7C00002E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwzx, 0x7C00002E, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -301,7 +301,7 @@ XEEMITTER(lwzx, 0x7C00002E, X )(PPCFunctionBuilder& f, InstrData& i) {
} }
XEEMITTER(ld, 0xE8000000, DS )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(ld, 0xE8000000, DS )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -314,7 +314,7 @@ XEEMITTER(ld, 0xE8000000, DS )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(ldu, 0xE8000001, DS )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(ldu, 0xE8000001, DS )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(DS || 0b00) // EA <- (RA) + EXTS(DS || 0b00)
// RT <- MEM(EA, 8) // RT <- MEM(EA, 8)
// RA <- EA // RA <- EA
@ -325,7 +325,7 @@ XEEMITTER(ldu, 0xE8000001, DS )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(ldux, 0x7C00006A, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(ldux, 0x7C00006A, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// RT <- MEM(EA, 8) // RT <- MEM(EA, 8)
// RA <- EA // RA <- EA
@ -336,7 +336,7 @@ XEEMITTER(ldux, 0x7C00006A, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(ldx, 0x7C00002A, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(ldx, 0x7C00002A, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -352,7 +352,7 @@ XEEMITTER(ldx, 0x7C00002A, X )(PPCFunctionBuilder& f, InstrData& i) {
// Integer store (A-14) // Integer store (A-14)
XEEMITTER(stb, 0x98000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stb, 0x98000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -364,7 +364,7 @@ XEEMITTER(stb, 0x98000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stbu, 0x9C000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stbu, 0x9C000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// MEM(EA, 1) <- (RS)[56:63] // MEM(EA, 1) <- (RS)[56:63]
// RA <- EA // RA <- EA
@ -374,7 +374,7 @@ XEEMITTER(stbu, 0x9C000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stbux, 0x7C0001EE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stbux, 0x7C0001EE, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// MEM(EA, 1) <- (RS)[56:63] // MEM(EA, 1) <- (RS)[56:63]
// RA <- EA // RA <- EA
@ -384,7 +384,7 @@ XEEMITTER(stbux, 0x7C0001EE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stbx, 0x7C0001AE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stbx, 0x7C0001AE, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -396,7 +396,7 @@ XEEMITTER(stbx, 0x7C0001AE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(sth, 0xB0000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sth, 0xB0000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -408,7 +408,7 @@ XEEMITTER(sth, 0xB0000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(sthu, 0xB4000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sthu, 0xB4000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// MEM(EA, 2) <- (RS)[48:63] // MEM(EA, 2) <- (RS)[48:63]
// RA <- EA // RA <- EA
@ -418,7 +418,7 @@ XEEMITTER(sthu, 0xB4000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(sthux, 0x7C00036E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sthux, 0x7C00036E, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// MEM(EA, 2) <- (RS)[48:63] // MEM(EA, 2) <- (RS)[48:63]
// RA <- EA // RA <- EA
@ -428,7 +428,7 @@ XEEMITTER(sthux, 0x7C00036E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(sthx, 0x7C00032E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sthx, 0x7C00032E, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -440,7 +440,7 @@ XEEMITTER(sthx, 0x7C00032E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stw, 0x90000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stw, 0x90000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -452,7 +452,7 @@ XEEMITTER(stw, 0x90000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stwu, 0x94000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stwu, 0x94000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// MEM(EA, 4) <- (RS)[32:63] // MEM(EA, 4) <- (RS)[32:63]
// RA <- EA // RA <- EA
@ -462,7 +462,7 @@ XEEMITTER(stwu, 0x94000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stwux, 0x7C00016E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stwux, 0x7C00016E, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// MEM(EA, 4) <- (RS)[32:63] // MEM(EA, 4) <- (RS)[32:63]
// RA <- EA // RA <- EA
@ -472,7 +472,7 @@ XEEMITTER(stwux, 0x7C00016E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stwx, 0x7C00012E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stwx, 0x7C00012E, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -484,7 +484,7 @@ XEEMITTER(stwx, 0x7C00012E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(std, 0xF8000000, DS )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(std, 0xF8000000, DS )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -496,7 +496,7 @@ XEEMITTER(std, 0xF8000000, DS )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stdu, 0xF8000001, DS )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stdu, 0xF8000001, DS )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(DS || 0b00) // EA <- (RA) + EXTS(DS || 0b00)
// MEM(EA, 8) <- (RS) // MEM(EA, 8) <- (RS)
// RA <- EA // RA <- EA
@ -506,7 +506,7 @@ XEEMITTER(stdu, 0xF8000001, DS )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stdux, 0x7C00016A, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stdux, 0x7C00016A, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// MEM(EA, 8) <- (RS) // MEM(EA, 8) <- (RS)
// RA <- EA // RA <- EA
@ -516,7 +516,7 @@ XEEMITTER(stdux, 0x7C00016A, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stdx, 0x7C00012A, X)(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stdx, 0x7C00012A, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -531,7 +531,7 @@ XEEMITTER(stdx, 0x7C00012A, X)(PPCFunctionBuilder& f, InstrData& i) {
// Integer load and store with byte reverse (A-1 // Integer load and store with byte reverse (A-1
XEEMITTER(lhbrx, 0x7C00062C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lhbrx, 0x7C00062C, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -544,7 +544,7 @@ XEEMITTER(lhbrx, 0x7C00062C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwbrx, 0x7C00042C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwbrx, 0x7C00042C, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -557,7 +557,7 @@ XEEMITTER(lwbrx, 0x7C00042C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(ldbrx, 0x7C000428, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(ldbrx, 0x7C000428, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -570,7 +570,7 @@ XEEMITTER(ldbrx, 0x7C000428, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(sthbrx, 0x7C00072C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sthbrx, 0x7C00072C, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -582,7 +582,7 @@ XEEMITTER(sthbrx, 0x7C00072C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stwbrx, 0x7C00052C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stwbrx, 0x7C00052C, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -594,7 +594,7 @@ XEEMITTER(stwbrx, 0x7C00052C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stdbrx, 0x7C000528, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stdbrx, 0x7C000528, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -609,12 +609,12 @@ XEEMITTER(stdbrx, 0x7C000528, X )(PPCFunctionBuilder& f, InstrData& i) {
// Integer load and store multiple (A-16) // Integer load and store multiple (A-16)
XEEMITTER(lmw, 0xB8000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lmw, 0xB8000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(stmw, 0xBC000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stmw, 0xBC000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
@ -622,22 +622,22 @@ XEEMITTER(stmw, 0xBC000000, D )(PPCFunctionBuilder& f, InstrData& i) {
// Integer load and store string (A-17) // Integer load and store string (A-17)
XEEMITTER(lswi, 0x7C0004AA, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lswi, 0x7C0004AA, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(lswx, 0x7C00042A, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lswx, 0x7C00042A, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(stswi, 0x7C0005AA, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stswi, 0x7C0005AA, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
XEEMITTER(stswx, 0x7C00052A, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stswx, 0x7C00052A, X )(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED(); XEINSTRNOTIMPLEMENTED();
return 1; return 1;
} }
@ -645,25 +645,25 @@ XEEMITTER(stswx, 0x7C00052A, X )(PPCFunctionBuilder& f, InstrData& i) {
// Memory synchronization (A-18) // Memory synchronization (A-18)
XEEMITTER(eieio, 0x7C0006AC, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(eieio, 0x7C0006AC, X )(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
f.Nop(); f.Nop();
return 0; return 0;
} }
XEEMITTER(sync, 0x7C0004AC, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(sync, 0x7C0004AC, X )(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
f.Nop(); f.Nop();
return 0; return 0;
} }
XEEMITTER(isync, 0x4C00012C, XL )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(isync, 0x4C00012C, XL )(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
f.Nop(); f.Nop();
return 0; return 0;
} }
XEEMITTER(ldarx, 0x7C0000A8, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(ldarx, 0x7C0000A8, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -679,7 +679,7 @@ XEEMITTER(ldarx, 0x7C0000A8, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lwarx, 0x7C000028, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lwarx, 0x7C000028, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -695,7 +695,7 @@ XEEMITTER(lwarx, 0x7C000028, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stdcx, 0x7C0001AD, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stdcx, 0x7C0001AD, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -712,7 +712,7 @@ XEEMITTER(stdcx, 0x7C0001AD, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stwcx, 0x7C00012D, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stwcx, 0x7C00012D, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -732,7 +732,7 @@ XEEMITTER(stwcx, 0x7C00012D, X )(PPCFunctionBuilder& f, InstrData& i) {
// Floating-point load (A-19) // Floating-point load (A-19)
XEEMITTER(lfd, 0xC8000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfd, 0xC8000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -745,7 +745,7 @@ XEEMITTER(lfd, 0xC8000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lfdu, 0xCC000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfdu, 0xCC000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// FRT <- MEM(EA, 8) // FRT <- MEM(EA, 8)
// RA <- EA // RA <- EA
@ -756,7 +756,7 @@ XEEMITTER(lfdu, 0xCC000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lfdux, 0x7C0004EE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfdux, 0x7C0004EE, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// FRT <- MEM(EA, 8) // FRT <- MEM(EA, 8)
// RA <- EA // RA <- EA
@ -767,7 +767,7 @@ XEEMITTER(lfdux, 0x7C0004EE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lfdx, 0x7C0004AE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfdx, 0x7C0004AE, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -780,7 +780,7 @@ XEEMITTER(lfdx, 0x7C0004AE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lfs, 0xC0000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfs, 0xC0000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -795,7 +795,7 @@ XEEMITTER(lfs, 0xC0000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lfsu, 0xC4000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfsu, 0xC4000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// FRT <- DOUBLE(MEM(EA, 4)) // FRT <- DOUBLE(MEM(EA, 4))
// RA <- EA // RA <- EA
@ -808,7 +808,7 @@ XEEMITTER(lfsu, 0xC4000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lfsux, 0x7C00046E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfsux, 0x7C00046E, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// FRT <- DOUBLE(MEM(EA, 4)) // FRT <- DOUBLE(MEM(EA, 4))
// RA <- EA // RA <- EA
@ -821,7 +821,7 @@ XEEMITTER(lfsux, 0x7C00046E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(lfsx, 0x7C00042E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(lfsx, 0x7C00042E, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -839,7 +839,7 @@ XEEMITTER(lfsx, 0x7C00042E, X )(PPCFunctionBuilder& f, InstrData& i) {
// Floating-point store (A-20) // Floating-point store (A-20)
XEEMITTER(stfd, 0xD8000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfd, 0xD8000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -851,7 +851,7 @@ XEEMITTER(stfd, 0xD8000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfdu, 0xDC000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfdu, 0xDC000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// MEM(EA, 8) <- (FRS) // MEM(EA, 8) <- (FRS)
// RA <- EA // RA <- EA
@ -861,7 +861,7 @@ XEEMITTER(stfdu, 0xDC000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfdux, 0x7C0005EE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfdux, 0x7C0005EE, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// MEM(EA, 8) <- (FRS) // MEM(EA, 8) <- (FRS)
// RA <- EA // RA <- EA
@ -871,7 +871,7 @@ XEEMITTER(stfdux, 0x7C0005EE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfdx, 0x7C0005AE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfdx, 0x7C0005AE, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -883,7 +883,7 @@ XEEMITTER(stfdx, 0x7C0005AE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfiwx, 0x7C0007AE, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfiwx, 0x7C0007AE, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -895,7 +895,7 @@ XEEMITTER(stfiwx, 0x7C0007AE, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfs, 0xD0000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfs, 0xD0000000, D )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -908,7 +908,7 @@ XEEMITTER(stfs, 0xD0000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfsu, 0xD4000000, D )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfsu, 0xD4000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D) // EA <- (RA) + EXTS(D)
// MEM(EA, 4) <- SINGLE(FRS) // MEM(EA, 4) <- SINGLE(FRS)
// RA <- EA // RA <- EA
@ -919,7 +919,7 @@ XEEMITTER(stfsu, 0xD4000000, D )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfsux, 0x7C00056E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfsux, 0x7C00056E, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB) // EA <- (RA) + (RB)
// MEM(EA, 4) <- SINGLE(FRS) // MEM(EA, 4) <- SINGLE(FRS)
// RA <- EA // RA <- EA
@ -930,7 +930,7 @@ XEEMITTER(stfsux, 0x7C00056E, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(stfsx, 0x7C00052E, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(stfsx, 0x7C00052E, X )(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then // if RA = 0 then
// b <- 0 // b <- 0
// else // else
@ -946,7 +946,7 @@ XEEMITTER(stfsx, 0x7C00052E, X )(PPCFunctionBuilder& f, InstrData& i) {
// Cache management (A-27) // Cache management (A-27)
XEEMITTER(dcbf, 0x7C0000AC, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(dcbf, 0x7C0000AC, X )(PPCHIRBuilder& f, InstrData& i) {
// No-op for now. // No-op for now.
// TODO(benvanik): use prefetch // TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
@ -954,7 +954,7 @@ XEEMITTER(dcbf, 0x7C0000AC, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(dcbst, 0x7C00006C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(dcbst, 0x7C00006C, X )(PPCHIRBuilder& f, InstrData& i) {
// No-op for now. // No-op for now.
// TODO(benvanik): use prefetch // TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
@ -962,7 +962,7 @@ XEEMITTER(dcbst, 0x7C00006C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(dcbt, 0x7C00022C, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(dcbt, 0x7C00022C, X )(PPCHIRBuilder& f, InstrData& i) {
// No-op for now. // No-op for now.
// TODO(benvanik): use prefetch // TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
@ -970,7 +970,7 @@ XEEMITTER(dcbt, 0x7C00022C, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(dcbtst, 0x7C0001EC, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(dcbtst, 0x7C0001EC, X )(PPCHIRBuilder& f, InstrData& i) {
// No-op for now. // No-op for now.
// TODO(benvanik): use prefetch // TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
@ -978,7 +978,7 @@ XEEMITTER(dcbtst, 0x7C0001EC, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(dcbz, 0x7C0007EC, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(dcbz, 0x7C0007EC, X )(PPCHIRBuilder& f, InstrData& i) {
// No-op for now. // No-op for now.
// TODO(benvanik): use prefetch // TODO(benvanik): use prefetch
// or dcbz128 0x7C2007EC // or dcbz128 0x7C2007EC
@ -987,7 +987,7 @@ XEEMITTER(dcbz, 0x7C0007EC, X )(PPCFunctionBuilder& f, InstrData& i) {
return 0; return 0;
} }
XEEMITTER(icbi, 0x7C0007AC, X )(PPCFunctionBuilder& f, InstrData& i) { XEEMITTER(icbi, 0x7C0007AC, X )(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED(); // XEINSTRNOTIMPLEMENTED();
f.Nop(); f.Nop();
return 0; return 0;

View File

@ -7,7 +7,7 @@
****************************************************************************** ******************************************************************************
*/ */
#include <alloy/frontend/ppc/ppc_function_builder.h> #include <alloy/frontend/ppc/ppc_hir_builder.h>
#include <alloy/frontend/tracing.h> #include <alloy/frontend/tracing.h>
#include <alloy/frontend/ppc/ppc_context.h> #include <alloy/frontend/ppc/ppc_context.h>
@ -23,24 +23,24 @@ using namespace alloy::hir;
using namespace alloy::runtime; using namespace alloy::runtime;
PPCFunctionBuilder::PPCFunctionBuilder(PPCFrontend* frontend) : PPCHIRBuilder::PPCHIRBuilder(PPCFrontend* frontend) :
frontend_(frontend), frontend_(frontend),
FunctionBuilder() { HIRBuilder() {
} }
PPCFunctionBuilder::~PPCFunctionBuilder() { PPCHIRBuilder::~PPCHIRBuilder() {
} }
void PPCFunctionBuilder::Reset() { void PPCHIRBuilder::Reset() {
start_address_ = 0; start_address_ = 0;
instr_offset_list_ = NULL; instr_offset_list_ = NULL;
label_list_ = NULL; label_list_ = NULL;
FunctionBuilder::Reset(); HIRBuilder::Reset();
} }
const bool FLAGS_annotate_disassembly = true; const bool FLAGS_annotate_disassembly = true;
int PPCFunctionBuilder::Emit(FunctionInfo* symbol_info) { int PPCHIRBuilder::Emit(FunctionInfo* symbol_info) {
Memory* memory = frontend_->memory(); Memory* memory = frontend_->memory();
const uint8_t* p = memory->membase(); const uint8_t* p = memory->membase();
@ -118,7 +118,7 @@ int PPCFunctionBuilder::Emit(FunctionInfo* symbol_info) {
continue; continue;
} }
typedef int (*InstrEmitter)(PPCFunctionBuilder& f, InstrData& i); typedef int (*InstrEmitter)(PPCHIRBuilder& f, InstrData& i);
InstrEmitter emit = (InstrEmitter)i.type->emit; InstrEmitter emit = (InstrEmitter)i.type->emit;
/*if (i.address == FLAGS_break_on_instruction) { /*if (i.address == FLAGS_break_on_instruction) {
@ -130,7 +130,7 @@ int PPCFunctionBuilder::Emit(FunctionInfo* symbol_info) {
XELOGCPU("Unimplemented instr %.8X %.8X %s", XELOGCPU("Unimplemented instr %.8X %.8X %s",
i.address, i.code, i.type->name); i.address, i.code, i.type->name);
Comment("UNIMPLEMENTED!"); Comment("UNIMPLEMENTED!");
DebugBreak(); //DebugBreak();
//TraceInvalidInstruction(i); //TraceInvalidInstruction(i);
// This printf is handy for sort/uniquify to find instructions. // This printf is handy for sort/uniquify to find instructions.
@ -155,14 +155,14 @@ int PPCFunctionBuilder::Emit(FunctionInfo* symbol_info) {
return Finalize(); return Finalize();
} }
void PPCFunctionBuilder::AnnotateLabel(uint64_t address, Label* label) { void PPCHIRBuilder::AnnotateLabel(uint64_t address, Label* label) {
char name_buffer[13]; char name_buffer[13];
xesnprintfa(name_buffer, XECOUNT(name_buffer), "loc_%.8X", address); xesnprintfa(name_buffer, XECOUNT(name_buffer), "loc_%.8X", address);
label->name = (char*)arena_->Alloc(sizeof(name_buffer)); label->name = (char*)arena_->Alloc(sizeof(name_buffer));
xe_copy_struct(label->name, name_buffer, sizeof(name_buffer)); xe_copy_struct(label->name, name_buffer, sizeof(name_buffer));
} }
FunctionInfo* PPCFunctionBuilder::LookupFunction(uint64_t address) { FunctionInfo* PPCHIRBuilder::LookupFunction(uint64_t address) {
Runtime* runtime = frontend_->runtime(); Runtime* runtime = frontend_->runtime();
FunctionInfo* symbol_info; FunctionInfo* symbol_info;
if (runtime->LookupFunctionInfo(address, &symbol_info)) { if (runtime->LookupFunctionInfo(address, &symbol_info)) {
@ -171,7 +171,7 @@ FunctionInfo* PPCFunctionBuilder::LookupFunction(uint64_t address) {
return symbol_info; return symbol_info;
} }
Label* PPCFunctionBuilder::LookupLabel(uint64_t address) { Label* PPCHIRBuilder::LookupLabel(uint64_t address) {
if (address < start_address_) { if (address < start_address_) {
return NULL; return NULL;
} }
@ -206,50 +206,50 @@ Label* PPCFunctionBuilder::LookupLabel(uint64_t address) {
return label; return label;
} }
//Value* PPCFunctionBuilder::LoadXER() { //Value* PPCHIRBuilder::LoadXER() {
//} //}
// //
//void PPCFunctionBuilder::StoreXER(Value* value) { //void PPCHIRBuilder::StoreXER(Value* value) {
//} //}
Value* PPCFunctionBuilder::LoadLR() { Value* PPCHIRBuilder::LoadLR() {
return LoadContext(offsetof(PPCContext, lr), INT64_TYPE); return LoadContext(offsetof(PPCContext, lr), INT64_TYPE);
} }
void PPCFunctionBuilder::StoreLR(Value* value) { void PPCHIRBuilder::StoreLR(Value* value) {
XEASSERT(value->type == INT64_TYPE); XEASSERT(value->type == INT64_TYPE);
StoreContext(offsetof(PPCContext, lr), value); StoreContext(offsetof(PPCContext, lr), value);
} }
Value* PPCFunctionBuilder::LoadCTR() { Value* PPCHIRBuilder::LoadCTR() {
return LoadContext(offsetof(PPCContext, ctr), INT64_TYPE); return LoadContext(offsetof(PPCContext, ctr), INT64_TYPE);
} }
void PPCFunctionBuilder::StoreCTR(Value* value) { void PPCHIRBuilder::StoreCTR(Value* value) {
XEASSERT(value->type == INT64_TYPE); XEASSERT(value->type == INT64_TYPE);
StoreContext(offsetof(PPCContext, ctr), value); StoreContext(offsetof(PPCContext, ctr), value);
} }
Value* PPCFunctionBuilder::LoadCR(uint32_t n) { Value* PPCHIRBuilder::LoadCR(uint32_t n) {
XEASSERTALWAYS(); XEASSERTALWAYS();
return 0; return 0;
} }
Value* PPCFunctionBuilder::LoadCRField(uint32_t n, uint32_t bit) { Value* PPCHIRBuilder::LoadCRField(uint32_t n, uint32_t bit) {
return LoadContext(offsetof(PPCContext, cr0) + (4 * n) + bit, INT8_TYPE); return LoadContext(offsetof(PPCContext, cr0) + (4 * n) + bit, INT8_TYPE);
} }
void PPCFunctionBuilder::StoreCR(uint32_t n, Value* value) { void PPCHIRBuilder::StoreCR(uint32_t n, Value* value) {
// TODO(benvanik): split bits out and store in values. // TODO(benvanik): split bits out and store in values.
XEASSERTALWAYS(); XEASSERTALWAYS();
} }
void PPCFunctionBuilder::UpdateCR( void PPCHIRBuilder::UpdateCR(
uint32_t n, Value* lhs, bool is_signed) { uint32_t n, Value* lhs, bool is_signed) {
UpdateCR(n, lhs, LoadZero(lhs->type), is_signed); UpdateCR(n, lhs, LoadZero(lhs->type), is_signed);
} }
void PPCFunctionBuilder::UpdateCR( void PPCHIRBuilder::UpdateCR(
uint32_t n, Value* lhs, Value* rhs, bool is_signed) { uint32_t n, Value* lhs, Value* rhs, bool is_signed) {
Value* lt; Value* lt;
Value* gt; Value* gt;
@ -269,7 +269,7 @@ void PPCFunctionBuilder::UpdateCR(
// StoreContext(offsetof(PPCContext, cr) + (4 * n) + 3, so); // StoreContext(offsetof(PPCContext, cr) + (4 * n) + 3, so);
} }
void PPCFunctionBuilder::UpdateCR6(Value* src_value) { void PPCHIRBuilder::UpdateCR6(Value* src_value) {
// Testing for all 1's and all 0's. // Testing for all 1's and all 0's.
// if (Rc) CR6 = all_equal | 0 | none_equal | 0 // if (Rc) CR6 = all_equal | 0 | none_equal | 0
// TODO(benvanik): efficient instruction? // TODO(benvanik): efficient instruction?
@ -277,51 +277,51 @@ void PPCFunctionBuilder::UpdateCR6(Value* src_value) {
StoreContext(offsetof(PPCContext, cr6.cr6_none_equal), IsFalse(src_value)); StoreContext(offsetof(PPCContext, cr6.cr6_none_equal), IsFalse(src_value));
} }
Value* PPCFunctionBuilder::LoadXER() { Value* PPCHIRBuilder::LoadXER() {
XEASSERTALWAYS(); XEASSERTALWAYS();
return NULL; return NULL;
} }
void PPCFunctionBuilder::StoreXER(Value* value) { void PPCHIRBuilder::StoreXER(Value* value) {
XEASSERTALWAYS(); XEASSERTALWAYS();
} }
Value* PPCFunctionBuilder::LoadCA() { Value* PPCHIRBuilder::LoadCA() {
return LoadContext(offsetof(PPCContext, xer_ca), INT8_TYPE); return LoadContext(offsetof(PPCContext, xer_ca), INT8_TYPE);
} }
void PPCFunctionBuilder::StoreCA(Value* value) { void PPCHIRBuilder::StoreCA(Value* value) {
StoreContext(offsetof(PPCContext, xer_ca), value); StoreContext(offsetof(PPCContext, xer_ca), value);
} }
Value* PPCFunctionBuilder::LoadGPR(uint32_t reg) { Value* PPCHIRBuilder::LoadGPR(uint32_t reg) {
return LoadContext( return LoadContext(
offsetof(PPCContext, r) + reg * 8, INT64_TYPE); offsetof(PPCContext, r) + reg * 8, INT64_TYPE);
} }
void PPCFunctionBuilder::StoreGPR(uint32_t reg, Value* value) { void PPCHIRBuilder::StoreGPR(uint32_t reg, Value* value) {
XEASSERT(value->type == INT64_TYPE); XEASSERT(value->type == INT64_TYPE);
StoreContext( StoreContext(
offsetof(PPCContext, r) + reg * 8, value); offsetof(PPCContext, r) + reg * 8, value);
} }
Value* PPCFunctionBuilder::LoadFPR(uint32_t reg) { Value* PPCHIRBuilder::LoadFPR(uint32_t reg) {
return LoadContext( return LoadContext(
offsetof(PPCContext, f) + reg * 8, FLOAT64_TYPE); offsetof(PPCContext, f) + reg * 8, FLOAT64_TYPE);
} }
void PPCFunctionBuilder::StoreFPR(uint32_t reg, Value* value) { void PPCHIRBuilder::StoreFPR(uint32_t reg, Value* value) {
XEASSERT(value->type == FLOAT64_TYPE); XEASSERT(value->type == FLOAT64_TYPE);
StoreContext( StoreContext(
offsetof(PPCContext, f) + reg * 8, value); offsetof(PPCContext, f) + reg * 8, value);
} }
Value* PPCFunctionBuilder::LoadVR(uint32_t reg) { Value* PPCHIRBuilder::LoadVR(uint32_t reg) {
return LoadContext( return LoadContext(
offsetof(PPCContext, v) + reg * 16, VEC128_TYPE); offsetof(PPCContext, v) + reg * 16, VEC128_TYPE);
} }
void PPCFunctionBuilder::StoreVR(uint32_t reg, Value* value) { void PPCHIRBuilder::StoreVR(uint32_t reg, Value* value) {
XEASSERT(value->type == VEC128_TYPE); XEASSERT(value->type == VEC128_TYPE);
StoreContext( StoreContext(
offsetof(PPCContext, v) + reg * 16, value); offsetof(PPCContext, v) + reg * 16, value);

View File

@ -7,11 +7,11 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_FRONTEND_PPC_PPC_FUNCTION_BUILDER_H_ #ifndef ALLOY_FRONTEND_PPC_PPC_HIR_BUILDER_H_
#define ALLOY_FRONTEND_PPC_PPC_FUNCTION_BUILDER_H_ #define ALLOY_FRONTEND_PPC_PPC_HIR_BUILDER_H_
#include <alloy/core.h> #include <alloy/core.h>
#include <alloy/hir/function_builder.h> #include <alloy/hir/hir_builder.h>
#include <alloy/runtime/function.h> #include <alloy/runtime/function.h>
#include <alloy/runtime/symbol_info.h> #include <alloy/runtime/symbol_info.h>
@ -23,13 +23,13 @@ namespace ppc {
class PPCFrontend; class PPCFrontend;
class PPCFunctionBuilder : public hir::FunctionBuilder { class PPCHIRBuilder : public hir::HIRBuilder {
using Instr = alloy::hir::Instr; using Instr = alloy::hir::Instr;
using Label = alloy::hir::Label; using Label = alloy::hir::Label;
using Value = alloy::hir::Value; using Value = alloy::hir::Value;
public: public:
PPCFunctionBuilder(PPCFrontend* frontend); PPCHIRBuilder(PPCFrontend* frontend);
virtual ~PPCFunctionBuilder(); virtual ~PPCHIRBuilder();
virtual void Reset(); virtual void Reset();
@ -83,4 +83,4 @@ private:
} // namespace alloy } // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_FUNCTION_BUILDER_H_ #endif // ALLOY_FRONTEND_PPC_PPC_HIR_BUILDER_H_

View File

@ -10,10 +10,10 @@
#include <alloy/frontend/ppc/ppc_translator.h> #include <alloy/frontend/ppc/ppc_translator.h>
#include <alloy/alloy-private.h> #include <alloy/alloy-private.h>
#include <alloy/compiler/passes.h> #include <alloy/compiler/compiler_passes.h>
#include <alloy/frontend/tracing.h> #include <alloy/frontend/tracing.h>
#include <alloy/frontend/ppc/ppc_frontend.h> #include <alloy/frontend/ppc/ppc_frontend.h>
#include <alloy/frontend/ppc/ppc_function_builder.h> #include <alloy/frontend/ppc/ppc_hir_builder.h>
#include <alloy/frontend/ppc/ppc_instr.h> #include <alloy/frontend/ppc/ppc_instr.h>
#include <alloy/frontend/ppc/ppc_scanner.h> #include <alloy/frontend/ppc/ppc_scanner.h>
#include <alloy/runtime/runtime.h> #include <alloy/runtime/runtime.h>
@ -30,7 +30,7 @@ using namespace alloy::runtime;
PPCTranslator::PPCTranslator(PPCFrontend* frontend) : PPCTranslator::PPCTranslator(PPCFrontend* frontend) :
frontend_(frontend) { frontend_(frontend) {
scanner_ = new PPCScanner(frontend); scanner_ = new PPCScanner(frontend);
builder_ = new PPCFunctionBuilder(frontend); builder_ = new PPCHIRBuilder(frontend);
compiler_ = new Compiler(frontend->runtime()); compiler_ = new Compiler(frontend->runtime());

View File

@ -21,7 +21,7 @@ namespace frontend {
namespace ppc { namespace ppc {
class PPCFrontend; class PPCFrontend;
class PPCFunctionBuilder; class PPCHIRBuilder;
class PPCScanner; class PPCScanner;
@ -43,7 +43,7 @@ private:
private: private:
PPCFrontend* frontend_; PPCFrontend* frontend_;
PPCScanner* scanner_; PPCScanner* scanner_;
PPCFunctionBuilder* builder_; PPCHIRBuilder* builder_;
compiler::Compiler* compiler_; compiler::Compiler* compiler_;
backend::Assembler* assembler_; backend::Assembler* assembler_;

View File

@ -19,8 +19,8 @@
'ppc_emit_memory.cc', 'ppc_emit_memory.cc',
'ppc_frontend.cc', 'ppc_frontend.cc',
'ppc_frontend.h', 'ppc_frontend.h',
'ppc_function_builder.cc', 'ppc_hir_builder.cc',
'ppc_function_builder.h', 'ppc_hir_builder.h',
'ppc_instr.cc', 'ppc_instr.cc',
'ppc_instr.h', 'ppc_instr.h',
'ppc_instr_tables.h', 'ppc_instr_tables.h',

View File

@ -16,7 +16,7 @@
namespace alloy { namespace alloy {
namespace hir { namespace hir {
class FunctionBuilder; class HIRBuilder;
class Instr; class Instr;
class Label; class Label;

View File

@ -7,7 +7,7 @@
****************************************************************************** ******************************************************************************
*/ */
#include <alloy/hir/function_builder.h> #include <alloy/hir/hir_builder.h>
#include <alloy/hir/block.h> #include <alloy/hir/block.h>
#include <alloy/hir/instr.h> #include <alloy/hir/instr.h>
@ -26,17 +26,17 @@ using namespace alloy::runtime;
#define ASSERT_TYPES_EQUAL(value1, value2) #define ASSERT_TYPES_EQUAL(value1, value2)
FunctionBuilder::FunctionBuilder() { HIRBuilder::HIRBuilder() {
arena_ = new Arena(); arena_ = new Arena();
Reset(); Reset();
} }
FunctionBuilder::~FunctionBuilder() { HIRBuilder::~HIRBuilder() {
Reset(); Reset();
delete arena_; delete arena_;
} }
void FunctionBuilder::Reset() { void HIRBuilder::Reset() {
attributes_ = 0; attributes_ = 0;
next_label_id_ = 0; next_label_id_ = 0;
next_value_ordinal_ = 0; next_value_ordinal_ = 0;
@ -44,7 +44,7 @@ void FunctionBuilder::Reset() {
current_block_ = NULL; current_block_ = NULL;
} }
int FunctionBuilder::Finalize() { int HIRBuilder::Finalize() {
// Scan blocks in order and add fallthrough branches. These are needed for // Scan blocks in order and add fallthrough branches. These are needed for
// analysis passes to work. We may have also added blocks out of order and // analysis passes to work. We may have also added blocks out of order and
// need to ensure they fall through in the right order. // need to ensure they fall through in the right order.
@ -79,7 +79,7 @@ int FunctionBuilder::Finalize() {
return 0; return 0;
} }
void FunctionBuilder::DumpValue(StringBuffer* str, Value* value) { void HIRBuilder::DumpValue(StringBuffer* str, Value* value) {
if (value->IsConstant()) { if (value->IsConstant()) {
switch (value->type) { switch (value->type) {
case INT8_TYPE: str->Append("%X", value->constant.i8); break; case INT8_TYPE: str->Append("%X", value->constant.i8); break;
@ -103,7 +103,7 @@ void FunctionBuilder::DumpValue(StringBuffer* str, Value* value) {
} }
} }
void FunctionBuilder::DumpOp( void HIRBuilder::DumpOp(
StringBuffer* str, OpcodeSignatureType sig_type, Instr::Op* op) { StringBuffer* str, OpcodeSignatureType sig_type, Instr::Op* op) {
switch (sig_type) { switch (sig_type) {
case OPCODE_SIG_TYPE_X: case OPCODE_SIG_TYPE_X:
@ -127,7 +127,7 @@ void FunctionBuilder::DumpOp(
} }
} }
void FunctionBuilder::Dump(StringBuffer* str) { void HIRBuilder::Dump(StringBuffer* str) {
if (attributes_) { if (attributes_) {
str->Append("; attributes = %.8X\n", attributes_); str->Append("; attributes = %.8X\n", attributes_);
} }
@ -199,11 +199,11 @@ void FunctionBuilder::Dump(StringBuffer* str) {
} }
} }
Block* FunctionBuilder::current_block() const { Block* HIRBuilder::current_block() const {
return current_block_; return current_block_;
} }
Instr* FunctionBuilder::last_instr() const { Instr* HIRBuilder::last_instr() const {
if (current_block_ && current_block_->instr_tail) { if (current_block_ && current_block_->instr_tail) {
return current_block_->instr_tail; return current_block_->instr_tail;
} else if (block_tail_) { } else if (block_tail_) {
@ -212,7 +212,7 @@ Instr* FunctionBuilder::last_instr() const {
return NULL; return NULL;
} }
Label* FunctionBuilder::NewLabel() { Label* HIRBuilder::NewLabel() {
Label* label = arena_->Alloc<Label>(); Label* label = arena_->Alloc<Label>();
label->next = label->prev = NULL; label->next = label->prev = NULL;
label->block = NULL; label->block = NULL;
@ -221,7 +221,7 @@ Label* FunctionBuilder::NewLabel() {
return label; return label;
} }
void FunctionBuilder::MarkLabel(Label* label, Block* block) { void HIRBuilder::MarkLabel(Label* label, Block* block) {
if (!block) { if (!block) {
if (current_block_ && current_block_->instr_tail) { if (current_block_ && current_block_->instr_tail) {
EndBlock(); EndBlock();
@ -242,7 +242,7 @@ void FunctionBuilder::MarkLabel(Label* label, Block* block) {
} }
} }
void FunctionBuilder::InsertLabel(Label* label, Instr* prev_instr) { void HIRBuilder::InsertLabel(Label* label, Instr* prev_instr) {
// If we are adding to the end just use the normal path. // If we are adding to the end just use the normal path.
if (prev_instr == last_instr()) { if (prev_instr == last_instr()) {
MarkLabel(label); MarkLabel(label);
@ -319,7 +319,7 @@ void FunctionBuilder::InsertLabel(Label* label, Instr* prev_instr) {
} }
} }
Block* FunctionBuilder::AppendBlock() { Block* HIRBuilder::AppendBlock() {
Block* block = arena_->Alloc<Block>(); Block* block = arena_->Alloc<Block>();
block->arena = arena_; block->arena = arena_;
block->next = NULL; block->next = NULL;
@ -337,7 +337,7 @@ Block* FunctionBuilder::AppendBlock() {
return block; return block;
} }
void FunctionBuilder::EndBlock() { void HIRBuilder::EndBlock() {
if (current_block_ && !current_block_->instr_tail) { if (current_block_ && !current_block_->instr_tail) {
// Block never had anything added to it. Since it likely has an // Block never had anything added to it. Since it likely has an
// incoming edge, just keep it around. // incoming edge, just keep it around.
@ -346,7 +346,7 @@ void FunctionBuilder::EndBlock() {
current_block_ = NULL; current_block_ = NULL;
} }
bool FunctionBuilder::IsUnconditionalJump(Instr* instr) { bool HIRBuilder::IsUnconditionalJump(Instr* instr) {
if (instr->opcode == &OPCODE_CALL_info || if (instr->opcode == &OPCODE_CALL_info ||
instr->opcode == &OPCODE_CALL_INDIRECT_info) { instr->opcode == &OPCODE_CALL_INDIRECT_info) {
return (instr->flags & CALL_TAIL) != 0; return (instr->flags & CALL_TAIL) != 0;
@ -358,7 +358,7 @@ bool FunctionBuilder::IsUnconditionalJump(Instr* instr) {
return false; return false;
} }
Instr* FunctionBuilder::AppendInstr( Instr* HIRBuilder::AppendInstr(
const OpcodeInfo& opcode_info, uint16_t flags, Value* dest) { const OpcodeInfo& opcode_info, uint16_t flags, Value* dest) {
if (!current_block_) { if (!current_block_) {
AppendBlock(); AppendBlock();
@ -388,7 +388,7 @@ Instr* FunctionBuilder::AppendInstr(
return instr; return instr;
} }
Value* FunctionBuilder::AllocValue(TypeName type) { Value* HIRBuilder::AllocValue(TypeName type) {
Value* value = arena_->Alloc<Value>(); Value* value = arena_->Alloc<Value>();
value->ordinal = next_value_ordinal_++; value->ordinal = next_value_ordinal_++;
value->type = type; value->type = type;
@ -399,7 +399,7 @@ Value* FunctionBuilder::AllocValue(TypeName type) {
return value; return value;
} }
Value* FunctionBuilder::CloneValue(Value* source) { Value* HIRBuilder::CloneValue(Value* source) {
Value* value = arena_->Alloc<Value>(); Value* value = arena_->Alloc<Value>();
value->ordinal = next_value_ordinal_++; value->ordinal = next_value_ordinal_++;
value->type = source->type; value->type = source->type;
@ -411,7 +411,7 @@ Value* FunctionBuilder::CloneValue(Value* source) {
return value; return value;
} }
void FunctionBuilder::Comment(const char* format, ...) { void HIRBuilder::Comment(const char* format, ...) {
char buffer[1024]; char buffer[1024];
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@ -428,24 +428,24 @@ void FunctionBuilder::Comment(const char* format, ...) {
i->src2.value = i->src3.value = NULL; i->src2.value = i->src3.value = NULL;
} }
void FunctionBuilder::Nop() { void HIRBuilder::Nop() {
Instr* i = AppendInstr(OPCODE_NOP_info, 0); Instr* i = AppendInstr(OPCODE_NOP_info, 0);
i->src1.value = i->src2.value = i->src3.value = NULL; i->src1.value = i->src2.value = i->src3.value = NULL;
} }
void FunctionBuilder::SourceOffset(uint64_t offset) { void HIRBuilder::SourceOffset(uint64_t offset) {
Instr* i = AppendInstr(OPCODE_SOURCE_OFFSET_info, 0); Instr* i = AppendInstr(OPCODE_SOURCE_OFFSET_info, 0);
i->src1.offset = offset; i->src1.offset = offset;
i->src2.value = i->src3.value = NULL; i->src2.value = i->src3.value = NULL;
} }
void FunctionBuilder::DebugBreak() { void HIRBuilder::DebugBreak() {
Instr* i = AppendInstr(OPCODE_DEBUG_BREAK_info, 0); Instr* i = AppendInstr(OPCODE_DEBUG_BREAK_info, 0);
i->src1.value = i->src2.value = i->src3.value = NULL; i->src1.value = i->src2.value = i->src3.value = NULL;
EndBlock(); EndBlock();
} }
void FunctionBuilder::DebugBreakTrue(Value* cond) { void HIRBuilder::DebugBreakTrue(Value* cond) {
if (cond->IsConstant()) { if (cond->IsConstant()) {
if (cond->IsConstantTrue()) { if (cond->IsConstantTrue()) {
DebugBreak(); DebugBreak();
@ -459,13 +459,13 @@ void FunctionBuilder::DebugBreakTrue(Value* cond) {
EndBlock(); EndBlock();
} }
void FunctionBuilder::Trap() { void HIRBuilder::Trap() {
Instr* i = AppendInstr(OPCODE_TRAP_info, 0); Instr* i = AppendInstr(OPCODE_TRAP_info, 0);
i->src1.value = i->src2.value = i->src3.value = NULL; i->src1.value = i->src2.value = i->src3.value = NULL;
EndBlock(); EndBlock();
} }
void FunctionBuilder::TrapTrue(Value* cond) { void HIRBuilder::TrapTrue(Value* cond) {
if (cond->IsConstant()) { if (cond->IsConstant()) {
if (cond->IsConstantTrue()) { if (cond->IsConstantTrue()) {
Trap(); Trap();
@ -479,7 +479,7 @@ void FunctionBuilder::TrapTrue(Value* cond) {
EndBlock(); EndBlock();
} }
void FunctionBuilder::Call( void HIRBuilder::Call(
FunctionInfo* symbol_info, uint32_t call_flags) { FunctionInfo* symbol_info, uint32_t call_flags) {
Instr* i = AppendInstr(OPCODE_CALL_info, call_flags); Instr* i = AppendInstr(OPCODE_CALL_info, call_flags);
i->src1.symbol_info = symbol_info; i->src1.symbol_info = symbol_info;
@ -487,7 +487,7 @@ void FunctionBuilder::Call(
EndBlock(); EndBlock();
} }
void FunctionBuilder::CallTrue( void HIRBuilder::CallTrue(
Value* cond, FunctionInfo* symbol_info, uint32_t call_flags) { Value* cond, FunctionInfo* symbol_info, uint32_t call_flags) {
if (cond->IsConstant()) { if (cond->IsConstant()) {
if (cond->IsConstantTrue()) { if (cond->IsConstantTrue()) {
@ -503,7 +503,7 @@ void FunctionBuilder::CallTrue(
EndBlock(); EndBlock();
} }
void FunctionBuilder::CallIndirect( void HIRBuilder::CallIndirect(
Value* value, uint32_t call_flags) { Value* value, uint32_t call_flags) {
ASSERT_ADDRESS_TYPE(value); ASSERT_ADDRESS_TYPE(value);
Instr* i = AppendInstr(OPCODE_CALL_INDIRECT_info, call_flags); Instr* i = AppendInstr(OPCODE_CALL_INDIRECT_info, call_flags);
@ -512,7 +512,7 @@ void FunctionBuilder::CallIndirect(
EndBlock(); EndBlock();
} }
void FunctionBuilder::CallIndirectTrue( void HIRBuilder::CallIndirectTrue(
Value* cond, Value* value, uint32_t call_flags) { Value* cond, Value* value, uint32_t call_flags) {
if (cond->IsConstant()) { if (cond->IsConstant()) {
if (cond->IsConstantTrue()) { if (cond->IsConstantTrue()) {
@ -529,26 +529,26 @@ void FunctionBuilder::CallIndirectTrue(
EndBlock(); EndBlock();
} }
void FunctionBuilder::Return() { void HIRBuilder::Return() {
Instr* i = AppendInstr(OPCODE_RETURN_info, 0); Instr* i = AppendInstr(OPCODE_RETURN_info, 0);
i->src1.value = i->src2.value = i->src3.value = NULL; i->src1.value = i->src2.value = i->src3.value = NULL;
EndBlock(); EndBlock();
} }
void FunctionBuilder::SetReturnAddress(Value* value) { void HIRBuilder::SetReturnAddress(Value* value) {
Instr* i = AppendInstr(OPCODE_SET_RETURN_ADDRESS_info, 0); Instr* i = AppendInstr(OPCODE_SET_RETURN_ADDRESS_info, 0);
i->set_src1(value); i->set_src1(value);
i->src2.value = i->src3.value = NULL; i->src2.value = i->src3.value = NULL;
} }
void FunctionBuilder::Branch(Label* label, uint32_t branch_flags) { void HIRBuilder::Branch(Label* label, uint32_t branch_flags) {
Instr* i = AppendInstr(OPCODE_BRANCH_info, branch_flags); Instr* i = AppendInstr(OPCODE_BRANCH_info, branch_flags);
i->src1.label = label; i->src1.label = label;
i->src2.value = i->src3.value = NULL; i->src2.value = i->src3.value = NULL;
EndBlock(); EndBlock();
} }
void FunctionBuilder::Branch(Block* block, uint32_t branch_flags) { void HIRBuilder::Branch(Block* block, uint32_t branch_flags) {
if (!block->label_head) { if (!block->label_head) {
// Block needs a label. // Block needs a label.
Label* label = NewLabel(); Label* label = NewLabel();
@ -557,7 +557,7 @@ void FunctionBuilder::Branch(Block* block, uint32_t branch_flags) {
Branch(block->label_head, branch_flags); Branch(block->label_head, branch_flags);
} }
void FunctionBuilder::BranchTrue( void HIRBuilder::BranchTrue(
Value* cond, Label* label, uint32_t branch_flags) { Value* cond, Label* label, uint32_t branch_flags) {
if (cond->IsConstant()) { if (cond->IsConstant()) {
if (cond->IsConstantTrue()) { if (cond->IsConstantTrue()) {
@ -573,7 +573,7 @@ void FunctionBuilder::BranchTrue(
EndBlock(); EndBlock();
} }
void FunctionBuilder::BranchFalse( void HIRBuilder::BranchFalse(
Value* cond, Label* label, uint32_t branch_flags) { Value* cond, Label* label, uint32_t branch_flags) {
if (cond->IsConstant()) { if (cond->IsConstant()) {
if (cond->IsConstantFalse()) { if (cond->IsConstantFalse()) {
@ -591,7 +591,7 @@ void FunctionBuilder::BranchFalse(
// phi type_name, Block* b1, Value* v1, Block* b2, Value* v2, etc // phi type_name, Block* b1, Value* v1, Block* b2, Value* v2, etc
Value* FunctionBuilder::Assign(Value* value) { Value* HIRBuilder::Assign(Value* value) {
if (value->IsConstant()) { if (value->IsConstant()) {
return value; return value;
} }
@ -604,7 +604,7 @@ Value* FunctionBuilder::Assign(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Cast(Value* value, TypeName target_type) { Value* HIRBuilder::Cast(Value* value, TypeName target_type) {
if (value->type == target_type) { if (value->type == target_type) {
return value; return value;
} else if (value->IsConstant()) { } else if (value->IsConstant()) {
@ -621,7 +621,7 @@ Value* FunctionBuilder::Cast(Value* value, TypeName target_type) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::ZeroExtend(Value* value, TypeName target_type) { Value* HIRBuilder::ZeroExtend(Value* value, TypeName target_type) {
if (value->type == target_type) { if (value->type == target_type) {
return value; return value;
} else if (value->IsConstant()) { } else if (value->IsConstant()) {
@ -638,7 +638,7 @@ Value* FunctionBuilder::ZeroExtend(Value* value, TypeName target_type) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::SignExtend(Value* value, TypeName target_type) { Value* HIRBuilder::SignExtend(Value* value, TypeName target_type) {
if (value->type == target_type) { if (value->type == target_type) {
return value; return value;
} else if (value->IsConstant()) { } else if (value->IsConstant()) {
@ -655,7 +655,7 @@ Value* FunctionBuilder::SignExtend(Value* value, TypeName target_type) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Truncate(Value* value, TypeName target_type) { Value* HIRBuilder::Truncate(Value* value, TypeName target_type) {
ASSERT_INTEGER_TYPE(value->type); ASSERT_INTEGER_TYPE(value->type);
ASSERT_INTEGER_TYPE(target_type); ASSERT_INTEGER_TYPE(target_type);
@ -675,7 +675,7 @@ Value* FunctionBuilder::Truncate(Value* value, TypeName target_type) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Convert(Value* value, TypeName target_type, Value* HIRBuilder::Convert(Value* value, TypeName target_type,
RoundMode round_mode) { RoundMode round_mode) {
if (value->type == target_type) { if (value->type == target_type) {
return value; return value;
@ -693,7 +693,7 @@ Value* FunctionBuilder::Convert(Value* value, TypeName target_type,
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Round(Value* value, RoundMode round_mode) { Value* HIRBuilder::Round(Value* value, RoundMode round_mode) {
ASSERT_FLOAT_TYPE(value); ASSERT_FLOAT_TYPE(value);
if (value->IsConstant()) { if (value->IsConstant()) {
@ -710,7 +710,7 @@ Value* FunctionBuilder::Round(Value* value, RoundMode round_mode) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::VectorConvertI2F(Value* value) { Value* HIRBuilder::VectorConvertI2F(Value* value) {
ASSERT_VECTOR_TYPE(value); ASSERT_VECTOR_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -721,7 +721,7 @@ Value* FunctionBuilder::VectorConvertI2F(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::VectorConvertF2I(Value* value, RoundMode round_mode) { Value* HIRBuilder::VectorConvertF2I(Value* value, RoundMode round_mode) {
ASSERT_VECTOR_TYPE(value); ASSERT_VECTOR_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -732,80 +732,80 @@ Value* FunctionBuilder::VectorConvertF2I(Value* value, RoundMode round_mode) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::LoadZero(TypeName type) { Value* HIRBuilder::LoadZero(TypeName type) {
// TODO(benvanik): cache zeros per block/fn? Prevents tons of dupes. // TODO(benvanik): cache zeros per block/fn? Prevents tons of dupes.
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_zero(type); dest->set_zero(type);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(int8_t value) { Value* HIRBuilder::LoadConstant(int8_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(uint8_t value) { Value* HIRBuilder::LoadConstant(uint8_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(int16_t value) { Value* HIRBuilder::LoadConstant(int16_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(uint16_t value) { Value* HIRBuilder::LoadConstant(uint16_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(int32_t value) { Value* HIRBuilder::LoadConstant(int32_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(uint32_t value) { Value* HIRBuilder::LoadConstant(uint32_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(int64_t value) { Value* HIRBuilder::LoadConstant(int64_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(uint64_t value) { Value* HIRBuilder::LoadConstant(uint64_t value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(float value) { Value* HIRBuilder::LoadConstant(float value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(double value) { Value* HIRBuilder::LoadConstant(double value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadConstant(const vec128_t& value) { Value* HIRBuilder::LoadConstant(const vec128_t& value) {
Value* dest = AllocValue(); Value* dest = AllocValue();
dest->set_constant(value); dest->set_constant(value);
return dest; return dest;
} }
Value* FunctionBuilder::LoadVectorShl(Value* sh) { Value* HIRBuilder::LoadVectorShl(Value* sh) {
XEASSERT(sh->type == INT8_TYPE); XEASSERT(sh->type == INT8_TYPE);
Instr* i = AppendInstr( Instr* i = AppendInstr(
OPCODE_LOAD_VECTOR_SHL_info, 0, OPCODE_LOAD_VECTOR_SHL_info, 0,
@ -815,7 +815,7 @@ Value* FunctionBuilder::LoadVectorShl(Value* sh) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::LoadVectorShr(Value* sh) { Value* HIRBuilder::LoadVectorShr(Value* sh) {
XEASSERT(sh->type == INT8_TYPE); XEASSERT(sh->type == INT8_TYPE);
Instr* i = AppendInstr( Instr* i = AppendInstr(
OPCODE_LOAD_VECTOR_SHR_info, 0, OPCODE_LOAD_VECTOR_SHR_info, 0,
@ -825,7 +825,7 @@ Value* FunctionBuilder::LoadVectorShr(Value* sh) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::LoadContext(size_t offset, TypeName type) { Value* HIRBuilder::LoadContext(size_t offset, TypeName type) {
Instr* i = AppendInstr( Instr* i = AppendInstr(
OPCODE_LOAD_CONTEXT_info, 0, OPCODE_LOAD_CONTEXT_info, 0,
AllocValue(type)); AllocValue(type));
@ -834,14 +834,14 @@ Value* FunctionBuilder::LoadContext(size_t offset, TypeName type) {
return i->dest; return i->dest;
} }
void FunctionBuilder::StoreContext(size_t offset, Value* value) { void HIRBuilder::StoreContext(size_t offset, Value* value) {
Instr* i = AppendInstr(OPCODE_STORE_CONTEXT_info, 0); Instr* i = AppendInstr(OPCODE_STORE_CONTEXT_info, 0);
i->src1.offset = offset; i->src1.offset = offset;
i->set_src2(value); i->set_src2(value);
i->src3.value = NULL; i->src3.value = NULL;
} }
Value* FunctionBuilder::Load( Value* HIRBuilder::Load(
Value* address, TypeName type, uint32_t load_flags) { Value* address, TypeName type, uint32_t load_flags) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -852,7 +852,7 @@ Value* FunctionBuilder::Load(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::LoadAcquire( Value* HIRBuilder::LoadAcquire(
Value* address, TypeName type, uint32_t load_flags) { Value* address, TypeName type, uint32_t load_flags) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -863,7 +863,7 @@ Value* FunctionBuilder::LoadAcquire(
return i->dest; return i->dest;
} }
void FunctionBuilder::Store( void HIRBuilder::Store(
Value* address, Value* value, uint32_t store_flags) { Value* address, Value* value, uint32_t store_flags) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
Instr* i = AppendInstr(OPCODE_STORE_info, store_flags); Instr* i = AppendInstr(OPCODE_STORE_info, store_flags);
@ -872,7 +872,7 @@ void FunctionBuilder::Store(
i->src3.value = NULL; i->src3.value = NULL;
} }
Value* FunctionBuilder::StoreRelease( Value* HIRBuilder::StoreRelease(
Value* address, Value* value, uint32_t store_flags) { Value* address, Value* value, uint32_t store_flags) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
Instr* i = AppendInstr(OPCODE_STORE_RELEASE_info, store_flags, Instr* i = AppendInstr(OPCODE_STORE_RELEASE_info, store_flags,
@ -883,7 +883,7 @@ Value* FunctionBuilder::StoreRelease(
return i->dest; return i->dest;
} }
void FunctionBuilder::Prefetch( void HIRBuilder::Prefetch(
Value* address, size_t length, uint32_t prefetch_flags) { Value* address, size_t length, uint32_t prefetch_flags) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
Instr* i = AppendInstr(OPCODE_PREFETCH_info, prefetch_flags); Instr* i = AppendInstr(OPCODE_PREFETCH_info, prefetch_flags);
@ -892,7 +892,7 @@ void FunctionBuilder::Prefetch(
i->src3.value = NULL; i->src3.value = NULL;
} }
Value* FunctionBuilder::Max(Value* value1, Value* value2) { Value* HIRBuilder::Max(Value* value1, Value* value2) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
if (value1->type != VEC128_TYPE && if (value1->type != VEC128_TYPE &&
@ -909,7 +909,7 @@ Value* FunctionBuilder::Max(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Min(Value* value1, Value* value2) { Value* HIRBuilder::Min(Value* value1, Value* value2) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
if (value1->type != VEC128_TYPE && if (value1->type != VEC128_TYPE &&
@ -926,7 +926,7 @@ Value* FunctionBuilder::Min(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Select(Value* cond, Value* value1, Value* value2) { Value* HIRBuilder::Select(Value* cond, Value* value1, Value* value2) {
XEASSERT(cond->type == INT8_TYPE); // for now XEASSERT(cond->type == INT8_TYPE); // for now
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -943,7 +943,7 @@ Value* FunctionBuilder::Select(Value* cond, Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::IsTrue(Value* value) { Value* HIRBuilder::IsTrue(Value* value) {
if (value->IsConstant()) { if (value->IsConstant()) {
return LoadConstant(value->IsConstantTrue() ? 1 : 0); return LoadConstant(value->IsConstantTrue() ? 1 : 0);
} }
@ -956,7 +956,7 @@ Value* FunctionBuilder::IsTrue(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::IsFalse(Value* value) { Value* HIRBuilder::IsFalse(Value* value) {
if (value->IsConstant()) { if (value->IsConstant()) {
return LoadConstant(value->IsConstantFalse() ? 1 : 0); return LoadConstant(value->IsConstantFalse() ? 1 : 0);
} }
@ -969,7 +969,7 @@ Value* FunctionBuilder::IsFalse(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::CompareXX( Value* HIRBuilder::CompareXX(
const OpcodeInfo& opcode, Value* value1, Value* value2) { const OpcodeInfo& opcode, Value* value1, Value* value2) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
if (value1->IsConstant() && value2->IsConstant()) { if (value1->IsConstant() && value2->IsConstant()) {
@ -985,47 +985,47 @@ Value* FunctionBuilder::CompareXX(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::CompareEQ(Value* value1, Value* value2) { Value* HIRBuilder::CompareEQ(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_EQ_info, value1, value2); return CompareXX(OPCODE_COMPARE_EQ_info, value1, value2);
} }
Value* FunctionBuilder::CompareNE(Value* value1, Value* value2) { Value* HIRBuilder::CompareNE(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_NE_info, value1, value2); return CompareXX(OPCODE_COMPARE_NE_info, value1, value2);
} }
Value* FunctionBuilder::CompareSLT(Value* value1, Value* value2) { Value* HIRBuilder::CompareSLT(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_SLT_info, value1, value2); return CompareXX(OPCODE_COMPARE_SLT_info, value1, value2);
} }
Value* FunctionBuilder::CompareSLE(Value* value1, Value* value2) { Value* HIRBuilder::CompareSLE(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_SLE_info, value1, value2); return CompareXX(OPCODE_COMPARE_SLE_info, value1, value2);
} }
Value* FunctionBuilder::CompareSGT(Value* value1, Value* value2) { Value* HIRBuilder::CompareSGT(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_SGT_info, value1, value2); return CompareXX(OPCODE_COMPARE_SGT_info, value1, value2);
} }
Value* FunctionBuilder::CompareSGE(Value* value1, Value* value2) { Value* HIRBuilder::CompareSGE(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_SGE_info, value1, value2); return CompareXX(OPCODE_COMPARE_SGE_info, value1, value2);
} }
Value* FunctionBuilder::CompareULT(Value* value1, Value* value2) { Value* HIRBuilder::CompareULT(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_ULT_info, value1, value2); return CompareXX(OPCODE_COMPARE_ULT_info, value1, value2);
} }
Value* FunctionBuilder::CompareULE(Value* value1, Value* value2) { Value* HIRBuilder::CompareULE(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_ULE_info, value1, value2); return CompareXX(OPCODE_COMPARE_ULE_info, value1, value2);
} }
Value* FunctionBuilder::CompareUGT(Value* value1, Value* value2) { Value* HIRBuilder::CompareUGT(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_UGT_info, value1, value2); return CompareXX(OPCODE_COMPARE_UGT_info, value1, value2);
} }
Value* FunctionBuilder::CompareUGE(Value* value1, Value* value2) { Value* HIRBuilder::CompareUGE(Value* value1, Value* value2) {
return CompareXX(OPCODE_COMPARE_UGE_info, value1, value2); return CompareXX(OPCODE_COMPARE_UGE_info, value1, value2);
} }
Value* FunctionBuilder::DidCarry(Value* value) { Value* HIRBuilder::DidCarry(Value* value) {
Instr* i = AppendInstr( Instr* i = AppendInstr(
OPCODE_DID_CARRY_info, 0, OPCODE_DID_CARRY_info, 0,
AllocValue(INT8_TYPE)); AllocValue(INT8_TYPE));
@ -1034,7 +1034,7 @@ Value* FunctionBuilder::DidCarry(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::DidOverflow(Value* value) { Value* HIRBuilder::DidOverflow(Value* value) {
Instr* i = AppendInstr( Instr* i = AppendInstr(
OPCODE_DID_OVERFLOW_info, 0, OPCODE_DID_OVERFLOW_info, 0,
AllocValue(INT8_TYPE)); AllocValue(INT8_TYPE));
@ -1043,7 +1043,7 @@ Value* FunctionBuilder::DidOverflow(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::VectorCompareXX( Value* HIRBuilder::VectorCompareXX(
const OpcodeInfo& opcode, Value* value1, Value* value2, const OpcodeInfo& opcode, Value* value1, Value* value2,
TypeName part_type) { TypeName part_type) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1060,37 +1060,37 @@ Value* FunctionBuilder::VectorCompareXX(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::VectorCompareEQ( Value* HIRBuilder::VectorCompareEQ(
Value* value1, Value* value2, TypeName part_type) { Value* value1, Value* value2, TypeName part_type) {
return VectorCompareXX( return VectorCompareXX(
OPCODE_VECTOR_COMPARE_EQ_info, value1, value2, part_type); OPCODE_VECTOR_COMPARE_EQ_info, value1, value2, part_type);
} }
Value* FunctionBuilder::VectorCompareSGT( Value* HIRBuilder::VectorCompareSGT(
Value* value1, Value* value2, TypeName part_type) { Value* value1, Value* value2, TypeName part_type) {
return VectorCompareXX( return VectorCompareXX(
OPCODE_VECTOR_COMPARE_SGT_info, value1, value2, part_type); OPCODE_VECTOR_COMPARE_SGT_info, value1, value2, part_type);
} }
Value* FunctionBuilder::VectorCompareSGE( Value* HIRBuilder::VectorCompareSGE(
Value* value1, Value* value2, TypeName part_type) { Value* value1, Value* value2, TypeName part_type) {
return VectorCompareXX( return VectorCompareXX(
OPCODE_VECTOR_COMPARE_SGE_info, value1, value2, part_type); OPCODE_VECTOR_COMPARE_SGE_info, value1, value2, part_type);
} }
Value* FunctionBuilder::VectorCompareUGT( Value* HIRBuilder::VectorCompareUGT(
Value* value1, Value* value2, TypeName part_type) { Value* value1, Value* value2, TypeName part_type) {
return VectorCompareXX( return VectorCompareXX(
OPCODE_VECTOR_COMPARE_UGT_info, value1, value2, part_type); OPCODE_VECTOR_COMPARE_UGT_info, value1, value2, part_type);
} }
Value* FunctionBuilder::VectorCompareUGE( Value* HIRBuilder::VectorCompareUGE(
Value* value1, Value* value2, TypeName part_type) { Value* value1, Value* value2, TypeName part_type) {
return VectorCompareXX( return VectorCompareXX(
OPCODE_VECTOR_COMPARE_UGE_info, value1, value2, part_type); OPCODE_VECTOR_COMPARE_UGE_info, value1, value2, part_type);
} }
Value* FunctionBuilder::Add( Value* HIRBuilder::Add(
Value* value1, Value* value2, uint32_t arithmetic_flags) { Value* value1, Value* value2, uint32_t arithmetic_flags) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1116,7 +1116,7 @@ Value* FunctionBuilder::Add(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::AddWithCarry( Value* HIRBuilder::AddWithCarry(
Value* value1, Value* value2, Value* value3, Value* value1, Value* value2, Value* value3,
uint32_t arithmetic_flags) { uint32_t arithmetic_flags) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1131,7 +1131,7 @@ Value* FunctionBuilder::AddWithCarry(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Sub( Value* HIRBuilder::Sub(
Value* value1, Value* value2, uint32_t arithmetic_flags) { Value* value1, Value* value2, uint32_t arithmetic_flags) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1144,7 +1144,7 @@ Value* FunctionBuilder::Sub(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Mul(Value* value1, Value* value2) { Value* HIRBuilder::Mul(Value* value1, Value* value2) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1156,7 +1156,7 @@ Value* FunctionBuilder::Mul(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Div(Value* value1, Value* value2) { Value* HIRBuilder::Div(Value* value1, Value* value2) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1168,7 +1168,7 @@ Value* FunctionBuilder::Div(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Rem(Value* value1, Value* value2) { Value* HIRBuilder::Rem(Value* value1, Value* value2) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1180,7 +1180,7 @@ Value* FunctionBuilder::Rem(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::MulAdd(Value* value1, Value* value2, Value* value3) { Value* HIRBuilder::MulAdd(Value* value1, Value* value2, Value* value3) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
ASSERT_TYPES_EQUAL(value1, value3); ASSERT_TYPES_EQUAL(value1, value3);
@ -1201,7 +1201,7 @@ Value* FunctionBuilder::MulAdd(Value* value1, Value* value2, Value* value3) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::MulSub(Value* value1, Value* value2, Value* value3) { Value* HIRBuilder::MulSub(Value* value1, Value* value2, Value* value3) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
ASSERT_TYPES_EQUAL(value1, value3); ASSERT_TYPES_EQUAL(value1, value3);
@ -1222,7 +1222,7 @@ Value* FunctionBuilder::MulSub(Value* value1, Value* value2, Value* value3) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Neg(Value* value) { Value* HIRBuilder::Neg(Value* value) {
ASSERT_NON_VECTOR_TYPE(value); ASSERT_NON_VECTOR_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1233,7 +1233,7 @@ Value* FunctionBuilder::Neg(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Abs(Value* value) { Value* HIRBuilder::Abs(Value* value) {
ASSERT_NON_VECTOR_TYPE(value); ASSERT_NON_VECTOR_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1244,7 +1244,7 @@ Value* FunctionBuilder::Abs(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Sqrt(Value* value) { Value* HIRBuilder::Sqrt(Value* value) {
ASSERT_FLOAT_TYPE(value); ASSERT_FLOAT_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1255,7 +1255,7 @@ Value* FunctionBuilder::Sqrt(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::RSqrt(Value* value) { Value* HIRBuilder::RSqrt(Value* value) {
ASSERT_FLOAT_TYPE(value); ASSERT_FLOAT_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1266,7 +1266,7 @@ Value* FunctionBuilder::RSqrt(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::DotProduct3(Value* value1, Value* value2) { Value* HIRBuilder::DotProduct3(Value* value1, Value* value2) {
ASSERT_VECTOR_TYPE(value1); ASSERT_VECTOR_TYPE(value1);
ASSERT_VECTOR_TYPE(value2); ASSERT_VECTOR_TYPE(value2);
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1280,7 +1280,7 @@ Value* FunctionBuilder::DotProduct3(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::DotProduct4(Value* value1, Value* value2) { Value* HIRBuilder::DotProduct4(Value* value1, Value* value2) {
ASSERT_VECTOR_TYPE(value1); ASSERT_VECTOR_TYPE(value1);
ASSERT_VECTOR_TYPE(value2); ASSERT_VECTOR_TYPE(value2);
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1294,7 +1294,7 @@ Value* FunctionBuilder::DotProduct4(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::And(Value* value1, Value* value2) { Value* HIRBuilder::And(Value* value1, Value* value2) {
ASSERT_INTEGER_TYPE(value1); ASSERT_INTEGER_TYPE(value1);
ASSERT_INTEGER_TYPE(value2); ASSERT_INTEGER_TYPE(value2);
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1316,7 +1316,7 @@ Value* FunctionBuilder::And(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Or(Value* value1, Value* value2) { Value* HIRBuilder::Or(Value* value1, Value* value2) {
ASSERT_INTEGER_TYPE(value1); ASSERT_INTEGER_TYPE(value1);
ASSERT_INTEGER_TYPE(value2); ASSERT_INTEGER_TYPE(value2);
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1338,7 +1338,7 @@ Value* FunctionBuilder::Or(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Xor(Value* value1, Value* value2) { Value* HIRBuilder::Xor(Value* value1, Value* value2) {
ASSERT_INTEGER_TYPE(value1); ASSERT_INTEGER_TYPE(value1);
ASSERT_INTEGER_TYPE(value2); ASSERT_INTEGER_TYPE(value2);
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1356,7 +1356,7 @@ Value* FunctionBuilder::Xor(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Not(Value* value) { Value* HIRBuilder::Not(Value* value) {
ASSERT_INTEGER_TYPE(value); ASSERT_INTEGER_TYPE(value);
if (value->IsConstant()) { if (value->IsConstant()) {
@ -1373,7 +1373,7 @@ Value* FunctionBuilder::Not(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Shl(Value* value1, Value* value2) { Value* HIRBuilder::Shl(Value* value1, Value* value2) {
ASSERT_INTEGER_TYPE(value1); ASSERT_INTEGER_TYPE(value1);
ASSERT_INTEGER_TYPE(value2); ASSERT_INTEGER_TYPE(value2);
@ -1394,11 +1394,11 @@ Value* FunctionBuilder::Shl(Value* value1, Value* value2) {
i->src3.value = NULL; i->src3.value = NULL;
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Shl(Value* value1, int8_t value2) { Value* HIRBuilder::Shl(Value* value1, int8_t value2) {
return Shl(value1, LoadConstant(value2)); return Shl(value1, LoadConstant(value2));
} }
Value* FunctionBuilder::VectorShl(Value* value1, Value* value2, Value* HIRBuilder::VectorShl(Value* value1, Value* value2,
TypeName part_type) { TypeName part_type) {
ASSERT_VECTOR_TYPE(value1); ASSERT_VECTOR_TYPE(value1);
ASSERT_VECTOR_TYPE(value2); ASSERT_VECTOR_TYPE(value2);
@ -1412,7 +1412,7 @@ Value* FunctionBuilder::VectorShl(Value* value1, Value* value2,
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Shr(Value* value1, Value* value2) { Value* HIRBuilder::Shr(Value* value1, Value* value2) {
ASSERT_INTEGER_TYPE(value1); ASSERT_INTEGER_TYPE(value1);
ASSERT_INTEGER_TYPE(value2); ASSERT_INTEGER_TYPE(value2);
@ -1431,11 +1431,11 @@ Value* FunctionBuilder::Shr(Value* value1, Value* value2) {
i->src3.value = NULL; i->src3.value = NULL;
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Shr(Value* value1, int8_t value2) { Value* HIRBuilder::Shr(Value* value1, int8_t value2) {
return Shr(value1, LoadConstant(value2)); return Shr(value1, LoadConstant(value2));
} }
Value* FunctionBuilder::Sha(Value* value1, Value* value2) { Value* HIRBuilder::Sha(Value* value1, Value* value2) {
ASSERT_INTEGER_TYPE(value1); ASSERT_INTEGER_TYPE(value1);
ASSERT_INTEGER_TYPE(value2); ASSERT_INTEGER_TYPE(value2);
@ -1454,11 +1454,11 @@ Value* FunctionBuilder::Sha(Value* value1, Value* value2) {
i->src3.value = NULL; i->src3.value = NULL;
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Sha(Value* value1, int8_t value2) { Value* HIRBuilder::Sha(Value* value1, int8_t value2) {
return Sha(value1, LoadConstant(value2)); return Sha(value1, LoadConstant(value2));
} }
Value* FunctionBuilder::RotateLeft(Value* value1, Value* value2) { Value* HIRBuilder::RotateLeft(Value* value1, Value* value2) {
ASSERT_INTEGER_TYPE(value1); ASSERT_INTEGER_TYPE(value1);
ASSERT_INTEGER_TYPE(value2); ASSERT_INTEGER_TYPE(value2);
@ -1479,7 +1479,7 @@ Value* FunctionBuilder::RotateLeft(Value* value1, Value* value2) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::ByteSwap(Value* value) { Value* HIRBuilder::ByteSwap(Value* value) {
if (value->type == INT8_TYPE) { if (value->type == INT8_TYPE) {
return value; return value;
} }
@ -1492,7 +1492,7 @@ Value* FunctionBuilder::ByteSwap(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::CountLeadingZeros(Value* value) { Value* HIRBuilder::CountLeadingZeros(Value* value) {
ASSERT_INTEGER_TYPE(value); ASSERT_INTEGER_TYPE(value);
if (value->IsConstantZero()) { if (value->IsConstantZero()) {
@ -1508,7 +1508,7 @@ Value* FunctionBuilder::CountLeadingZeros(Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Insert(Value* value, Value* index, Value* part) { Value* HIRBuilder::Insert(Value* value, Value* index, Value* part) {
// TODO(benvanik): could do some of this as constants. // TODO(benvanik): could do some of this as constants.
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1520,11 +1520,11 @@ Value* FunctionBuilder::Insert(Value* value, Value* index, Value* part) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Insert(Value* value, uint64_t index, Value* part) { Value* HIRBuilder::Insert(Value* value, uint64_t index, Value* part) {
return Insert(value, LoadConstant(index), part); return Insert(value, LoadConstant(index), part);
} }
Value* FunctionBuilder::Extract(Value* value, Value* index, Value* HIRBuilder::Extract(Value* value, Value* index,
TypeName target_type) { TypeName target_type) {
// TODO(benvanik): could do some of this as constants. // TODO(benvanik): could do some of this as constants.
@ -1537,12 +1537,12 @@ Value* FunctionBuilder::Extract(Value* value, Value* index,
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Extract(Value* value, uint64_t index, Value* HIRBuilder::Extract(Value* value, uint64_t index,
TypeName target_type) { TypeName target_type) {
return Extract(value, LoadConstant(index), target_type); return Extract(value, LoadConstant(index), target_type);
} }
Value* FunctionBuilder::Splat(Value* value, TypeName target_type) { Value* HIRBuilder::Splat(Value* value, TypeName target_type) {
// TODO(benvanik): could do some of this as constants. // TODO(benvanik): could do some of this as constants.
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1553,7 +1553,7 @@ Value* FunctionBuilder::Splat(Value* value, TypeName target_type) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Permute( Value* HIRBuilder::Permute(
Value* control, Value* value1, Value* value2, TypeName part_type) { Value* control, Value* value1, Value* value2, TypeName part_type) {
ASSERT_TYPES_EQUAL(value1, value2); ASSERT_TYPES_EQUAL(value1, value2);
@ -1568,7 +1568,7 @@ Value* FunctionBuilder::Permute(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::Swizzle( Value* HIRBuilder::Swizzle(
Value* value, TypeName part_type, uint32_t swizzle_mask) { Value* value, TypeName part_type, uint32_t swizzle_mask) {
// For now. // For now.
XEASSERT(part_type == INT32_TYPE || part_type == FLOAT32_TYPE); XEASSERT(part_type == INT32_TYPE || part_type == FLOAT32_TYPE);
@ -1588,7 +1588,7 @@ Value* FunctionBuilder::Swizzle(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::CompareExchange( Value* HIRBuilder::CompareExchange(
Value* address, Value* compare_value, Value* exchange_value) { Value* address, Value* compare_value, Value* exchange_value) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
ASSERT_INTEGER_TYPE(compare_value); ASSERT_INTEGER_TYPE(compare_value);
@ -1603,7 +1603,7 @@ Value* FunctionBuilder::CompareExchange(
return i->dest; return i->dest;
} }
Value* FunctionBuilder::AtomicAdd(Value* address, Value* value) { Value* HIRBuilder::AtomicAdd(Value* address, Value* value) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
ASSERT_INTEGER_TYPE(value); ASSERT_INTEGER_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(
@ -1615,7 +1615,7 @@ Value* FunctionBuilder::AtomicAdd(Value* address, Value* value) {
return i->dest; return i->dest;
} }
Value* FunctionBuilder::AtomicSub(Value* address, Value* value) { Value* HIRBuilder::AtomicSub(Value* address, Value* value) {
ASSERT_ADDRESS_TYPE(address); ASSERT_ADDRESS_TYPE(address);
ASSERT_INTEGER_TYPE(value); ASSERT_INTEGER_TYPE(value);
Instr* i = AppendInstr( Instr* i = AppendInstr(

View File

@ -7,8 +7,8 @@
****************************************************************************** ******************************************************************************
*/ */
#ifndef ALLOY_HIR_FUNCTION_BUILDER_H_ #ifndef ALLOY_HIR_HIR_BUILDER_H_
#define ALLOY_HIR_FUNCTION_BUILDER_H_ #define ALLOY_HIR_HIR_BUILDER_H_
#include <alloy/core.h> #include <alloy/core.h>
#include <alloy/hir/block.h> #include <alloy/hir/block.h>
@ -25,10 +25,10 @@ enum FunctionAttributes {
}; };
class FunctionBuilder { class HIRBuilder {
public: public:
FunctionBuilder(); HIRBuilder();
virtual ~FunctionBuilder(); virtual ~HIRBuilder();
virtual void Reset(); virtual void Reset();
virtual int Finalize(); virtual int Finalize();
@ -232,4 +232,4 @@ protected:
} // namespace alloy } // namespace alloy
#endif // ALLOY_HIR_FUNCTION_BUILDER_H_ #endif // ALLOY_HIR_HIR_BUILDER_H_

View File

@ -168,6 +168,8 @@ enum Opcode {
OPCODE_COMPARE_EXCHANGE, OPCODE_COMPARE_EXCHANGE,
OPCODE_ATOMIC_ADD, OPCODE_ATOMIC_ADD,
OPCODE_ATOMIC_SUB, OPCODE_ATOMIC_SUB,
__OPCODE_MAX_VALUE, // Keep at end.
}; };
enum OpcodeFlags { enum OpcodeFlags {

View File

@ -2,8 +2,8 @@
{ {
'sources': [ 'sources': [
'block.h', 'block.h',
'function_builder.cc', 'hir_builder.cc',
'function_builder.h', 'hir_builder.h',
'instr.cc', 'instr.cc',
'instr.h', 'instr.h',
'label.h', 'label.h',

View File

@ -44,13 +44,7 @@ public:
Use_s* prev; Use_s* prev;
Use_s* next; Use_s* next;
} Use; } Use;
typedef union {
public:
uint32_t ordinal;
TypeName type;
uint32_t flags;
union {
int8_t i8; int8_t i8;
int16_t i16; int16_t i16;
int32_t i32; int32_t i32;
@ -58,7 +52,14 @@ public:
float f32; float f32;
double f64; double f64;
vec128_t v128; vec128_t v128;
} constant; } ConstantValue;
public:
uint32_t ordinal;
TypeName type;
uint32_t flags;
ConstantValue constant;
Instr* def; Instr* def;
Use* use_head; Use* use_head;