Running clang-format on alloy.

All except x64_sequences, which needs work.
This commit is contained in:
Ben Vanik 2014-07-10 20:20:00 -07:00
parent 0158380cfc
commit 7daa85179c
139 changed files with 6925 additions and 6998 deletions

View File

@ -14,7 +14,6 @@
#include <gflags/gflags.h>
DECLARE_bool(debug);
DECLARE_bool(always_disasm);
@ -23,10 +22,4 @@ DECLARE_bool(validate_hir);
DECLARE_uint64(break_on_instruction);
DECLARE_uint64(break_on_memory);
namespace alloy {
} // namespace alloy
#endif // ALLOY_ALLOY_PRIVATE_H_

View File

@ -12,7 +12,6 @@
using namespace alloy;
#if 0 && DEBUG
#define DEFAULT_DEBUG_FLAG true
#else
@ -20,15 +19,16 @@ using namespace alloy;
#endif
DEFINE_bool(debug, DEFAULT_DEBUG_FLAG,
"Allow debugging and retain debug information.");
DEFINE_bool(always_disasm, false,
"Allow debugging and retain debug information.");
DEFINE_bool(
always_disasm, false,
"Always add debug info to functions, even when no debugger is attached.");
DEFINE_bool(validate_hir, false,
"Perform validation checks on the HIR during compilation.");
"Perform validation checks on the HIR during compilation.");
// Breakpoints:
DEFINE_uint64(break_on_instruction, 0,
"int3 before the given guest address is executed.");
"int3 before the given guest address is executed.");
DEFINE_uint64(break_on_memory, 0,
"int3 on read/write to the given memory address.");
"int3 on read/write to the given memory address.");

View File

@ -18,10 +18,4 @@
#include <alloy/runtime/thread_state.h>
#include <alloy/tracing/tracing.h>
namespace alloy {
} // namespace alloy
#endif // ALLOY_ALLOY_H_

View File

@ -9,13 +9,10 @@
#include <alloy/arena.h>
using namespace alloy;
namespace alloy {
Arena::Arena(size_t chunk_size) :
chunk_size_(chunk_size),
head_chunk_(NULL), active_chunk_(NULL) {
}
Arena::Arena(size_t chunk_size)
: chunk_size_(chunk_size), head_chunk_(NULL), active_chunk_(NULL) {}
Arena::~Arena() {
Reset();
@ -48,7 +45,7 @@ void* Arena::Alloc(size_t size) {
if (active_chunk_->capacity - active_chunk_->offset < size + 4096) {
Chunk* next = active_chunk_->next;
if (!next) {
XEASSERT(size < chunk_size_); // need to support larger chunks
XEASSERT(size < chunk_size_); // need to support larger chunks
next = new Chunk(chunk_size_);
active_chunk_->next = next;
}
@ -88,9 +85,8 @@ void* Arena::CloneContents() {
return result;
}
Arena::Chunk::Chunk(size_t chunk_size) :
next(NULL),
capacity(chunk_size), buffer(0), offset(0) {
Arena::Chunk::Chunk(size_t chunk_size)
: next(NULL), capacity(chunk_size), buffer(0), offset(0) {
buffer = (uint8_t*)xe_malloc(capacity);
}
@ -99,3 +95,5 @@ Arena::Chunk::~Chunk() {
xe_free(buffer);
}
}
} // namespace alloy

View File

@ -12,12 +12,10 @@
#include <alloy/core.h>
namespace alloy {
class Arena {
public:
public:
Arena(size_t chunk_size = 4 * 1024 * 1024);
~Arena();
@ -25,33 +23,32 @@ public:
void DebugFill();
void* Alloc(size_t size);
template<typename T> T* Alloc() {
template <typename T>
T* Alloc() {
return (T*)Alloc(sizeof(T));
}
void* CloneContents();
private:
private:
class Chunk {
public:
public:
Chunk(size_t chunk_size);
~Chunk();
Chunk* next;
Chunk* next;
size_t capacity;
uint8_t* buffer;
size_t offset;
size_t capacity;
uint8_t* buffer;
size_t offset;
};
private:
size_t chunk_size_;
Chunk* head_chunk_;
Chunk* active_chunk_;
private:
size_t chunk_size_;
Chunk* head_chunk_;
Chunk* active_chunk_;
};
} // namespace alloy
#endif // ALLOY_ARENA_H_

View File

@ -11,22 +11,16 @@
#include <alloy/backend/tracing.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::runtime;
namespace alloy {
namespace backend {
Assembler::Assembler(Backend* backend) : backend_(backend) {}
Assembler::Assembler(Backend* backend) :
backend_(backend) {
}
Assembler::~Assembler() { Reset(); }
Assembler::~Assembler() {
Reset();
}
int Assembler::Initialize() { return 0; }
int Assembler::Initialize() {
return 0;
}
void Assembler::Reset() {}
void Assembler::Reset() {
}
} // namespace backend
} // namespace alloy

View File

@ -12,27 +12,25 @@
#include <alloy/core.h>
namespace alloy {
namespace hir {
class HIRBuilder;
}
} // namespace hir
namespace runtime {
class DebugInfo;
class Function;
class FunctionInfo;
class Runtime;
}
}
} // namespace runtime
} // namespace alloy
namespace alloy {
namespace backend {
class Backend;
class Assembler {
public:
public:
Assembler(Backend* backend);
virtual ~Assembler();
@ -40,18 +38,16 @@ public:
virtual void Reset();
virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
runtime::Function** out_function) = 0;
virtual int Assemble(runtime::FunctionInfo* symbol_info,
hir::HIRBuilder* builder, uint32_t debug_info_flags,
runtime::DebugInfo* debug_info,
runtime::Function** out_function) = 0;
protected:
protected:
Backend* backend_;
};
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_ASSEMBLER_H_

View File

@ -11,26 +11,22 @@
#include <alloy/backend/tracing.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::runtime;
namespace alloy {
namespace backend {
using alloy::runtime::Runtime;
Backend::Backend(Runtime* runtime) :
runtime_(runtime) {
Backend::Backend(Runtime* runtime) : runtime_(runtime) {
xe_zero_struct(&machine_info_, sizeof(machine_info_));
}
Backend::~Backend() {
}
Backend::~Backend() {}
int Backend::Initialize() {
return 0;
}
int Backend::Initialize() { return 0; }
void* Backend::AllocThreadData() {
return NULL;
}
void* Backend::AllocThreadData() { return NULL; }
void Backend::FreeThreadData(void* thread_data) {
}
void Backend::FreeThreadData(void* thread_data) {}
} // namespace backend
} // namespace alloy

View File

@ -13,17 +13,19 @@
#include <alloy/core.h>
#include <alloy/backend/machine_info.h>
namespace alloy { namespace runtime { class Runtime; } }
namespace alloy {
namespace runtime {
class Runtime;
} // namespace runtime
} // namespace alloy
namespace alloy {
namespace backend {
class Assembler;
class Backend {
public:
public:
Backend(runtime::Runtime* runtime);
virtual ~Backend();
@ -37,14 +39,12 @@ public:
virtual Assembler* CreateAssembler() = 0;
protected:
protected:
runtime::Runtime* runtime_;
MachineInfo machine_info_;
};
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_BACKEND_H_

View File

@ -17,21 +17,19 @@
#include <alloy/hir/label.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::ivm;
using namespace alloy::hir;
using namespace alloy::runtime;
namespace alloy {
namespace backend {
namespace ivm {
using alloy::hir::HIRBuilder;
using alloy::runtime::Function;
using alloy::runtime::FunctionInfo;
IVMAssembler::IVMAssembler(Backend* backend) :
source_map_arena_(128 * 1024),
Assembler(backend) {
}
IVMAssembler::IVMAssembler(Backend* backend)
: source_map_arena_(128 * 1024), Assembler(backend) {}
IVMAssembler::~IVMAssembler() {
alloy::tracing::WriteEvent(EventType::AssemblerDeinit({
}));
alloy::tracing::WriteEvent(EventType::AssemblerDeinit({}));
}
int IVMAssembler::Initialize() {
@ -40,8 +38,7 @@ int IVMAssembler::Initialize() {
return result;
}
alloy::tracing::WriteEvent(EventType::AssemblerInit({
}));
alloy::tracing::WriteEvent(EventType::AssemblerInit({}));
return result;
}
@ -53,10 +50,10 @@ void IVMAssembler::Reset() {
Assembler::Reset();
}
int IVMAssembler::Assemble(
FunctionInfo* symbol_info, HIRBuilder* builder,
uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
Function** out_function) {
int IVMAssembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
uint32_t debug_info_flags,
runtime::DebugInfo* debug_info,
Function** out_function) {
IVMFunction* fn = new IVMFunction(symbol_info);
fn->set_debug_info(debug_info);
@ -89,13 +86,13 @@ int IVMAssembler::Assemble(
auto block = builder->first_block();
while (block) {
Label* label = block->label_head;
auto label = block->label_head;
while (label) {
label->tag = (void*)(0x80000000 | ctx.intcode_count);
label = label->next;
}
Instr* i = block->instr_head;
auto i = block->instr_head;
while (i) {
int result = TranslateIntCodes(ctx, i);
i = i->next;
@ -108,7 +105,8 @@ int IVMAssembler::Assemble(
// Fixup label references.
LabelRef* label_ref = ctx.label_ref_head;
while (label_ref) {
label_ref->instr->src1_reg = (uint32_t)(intptr_t)label_ref->label->tag & ~0x80000000;
label_ref->instr->src1_reg =
(uint32_t)(intptr_t)label_ref->label->tag & ~0x80000000;
label_ref = label_ref->next;
}
@ -117,3 +115,7 @@ int IVMAssembler::Assemble(
*out_function = fn;
return 0;
}
} // namespace ivm
} // namespace backend
} // namespace alloy

View File

@ -14,14 +14,12 @@
#include <alloy/backend/assembler.h>
namespace alloy {
namespace backend {
namespace ivm {
class IVMAssembler : public Assembler {
public:
public:
IVMAssembler(Backend* backend);
virtual ~IVMAssembler();
@ -29,21 +27,19 @@ public:
virtual void Reset();
virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
runtime::Function** out_function);
virtual int Assemble(runtime::FunctionInfo* symbol_info,
hir::HIRBuilder* builder, uint32_t debug_info_flags,
runtime::DebugInfo* debug_info,
runtime::Function** out_function);
private:
Arena intcode_arena_;
Arena source_map_arena_;
Arena scratch_arena_;
private:
Arena intcode_arena_;
Arena source_map_arena_;
Arena scratch_arena_;
};
} // namespace ivm
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_IVM_IVM_ASSEMBLER_H_

View File

@ -13,20 +13,15 @@
#include <alloy/backend/ivm/ivm_stack.h>
#include <alloy/backend/ivm/tracing.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::ivm;
using namespace alloy::runtime;
namespace alloy {
namespace backend {
namespace ivm {
using alloy::runtime::Runtime;
IVMBackend::IVMBackend(Runtime* runtime) :
Backend(runtime) {
}
IVMBackend::IVMBackend(Runtime* runtime) : Backend(runtime) {}
IVMBackend::~IVMBackend() {
alloy::tracing::WriteEvent(EventType::Deinit({
}));
}
IVMBackend::~IVMBackend() { alloy::tracing::WriteEvent(EventType::Deinit({})); }
int IVMBackend::Initialize() {
int result = Backend::Initialize();
@ -35,34 +30,28 @@ int IVMBackend::Initialize() {
}
machine_info_.register_sets[0] = {
0,
"gpr",
MachineInfo::RegisterSet::INT_TYPES,
16,
0, "gpr", MachineInfo::RegisterSet::INT_TYPES, 16,
};
machine_info_.register_sets[1] = {
1,
"vec",
MachineInfo::RegisterSet::FLOAT_TYPES |
MachineInfo::RegisterSet::VEC_TYPES,
16,
1, "vec", MachineInfo::RegisterSet::FLOAT_TYPES |
MachineInfo::RegisterSet::VEC_TYPES,
16,
};
alloy::tracing::WriteEvent(EventType::Init({
}));
alloy::tracing::WriteEvent(EventType::Init({}));
return result;
}
void* IVMBackend::AllocThreadData() {
return new IVMStack();
}
void* IVMBackend::AllocThreadData() { return new IVMStack(); }
void IVMBackend::FreeThreadData(void* thread_data) {
auto stack = (IVMStack*)thread_data;
delete stack;
}
Assembler* IVMBackend::CreateAssembler() {
return new IVMAssembler(this);
}
Assembler* IVMBackend::CreateAssembler() { return new IVMAssembler(this); }
} // namespace ivm
} // namespace backend
} // namespace alloy

View File

@ -14,17 +14,14 @@
#include <alloy/backend/backend.h>
namespace alloy {
namespace backend {
namespace ivm {
#define ALLOY_HAS_IVM_BACKEND 1
class IVMBackend : public Backend {
public:
public:
IVMBackend(runtime::Runtime* runtime);
virtual ~IVMBackend();
@ -36,10 +33,8 @@ public:
virtual Assembler* CreateAssembler();
};
} // namespace ivm
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_IVM_IVM_BACKEND_H_

View File

@ -14,17 +14,21 @@
#include <alloy/runtime/runtime.h>
#include <alloy/runtime/thread_state.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::ivm;
using namespace alloy::runtime;
namespace alloy {
namespace backend {
namespace ivm {
using alloy::runtime::Breakpoint;
using alloy::runtime::FunctionInfo;
using alloy::runtime::ThreadState;
IVMFunction::IVMFunction(FunctionInfo* symbol_info) :
register_count_(0), intcode_count_(0), intcodes_(0),
source_map_count_(0), source_map_(0),
Function(symbol_info) {
}
IVMFunction::IVMFunction(FunctionInfo* symbol_info)
: register_count_(0),
intcode_count_(0),
intcodes_(0),
source_map_count_(0),
source_map_(0),
Function(symbol_info) {}
IVMFunction::~IVMFunction() {
xe_free(intcodes_);
@ -57,8 +61,7 @@ int IVMFunction::AddBreakpointImpl(Breakpoint* breakpoint) {
}
// TEMP breakpoints always overwrite normal ones.
if (!i->debug_flags ||
breakpoint->type() == Breakpoint::TEMP_TYPE) {
if (!i->debug_flags || breakpoint->type() == Breakpoint::TEMP_TYPE) {
uint64_t breakpoint_ptr = (uint64_t)breakpoint;
i->src2_reg = (uint32_t)breakpoint_ptr;
i->src3_reg = (uint32_t)(breakpoint_ptr >> 32);
@ -127,8 +130,8 @@ int IVMFunction::CallImpl(ThreadState* thread_state, uint64_t return_address) {
volatile int* suspend_flag_address = thread_state->suspend_flag_address();
// TODO(benvanik): DID_CARRY -- need HIR to set a OPCODE_FLAG_SET_CARRY
// or something so the fns can set an ics flag.
// TODO(benvanik): DID_CARRY -- need HIR to set a OPCODE_FLAG_SET_CARRY
// or something so the fns can set an ics flag.
#ifdef TRACE_SOURCE_OFFSET
size_t source_index = 0;
@ -177,3 +180,7 @@ int IVMFunction::CallImpl(ThreadState* thread_state, uint64_t return_address) {
return 0;
}
} // namespace ivm
} // namespace backend
} // namespace alloy

File diff suppressed because it is too large Load Diff

View File

@ -15,104 +15,96 @@
#include <alloy/hir/instr.h>
#include <alloy/hir/opcodes.h>
namespace alloy { namespace runtime { class ThreadState; } }
namespace alloy {
namespace runtime {
class ThreadState;
}
}
namespace alloy {
namespace backend {
namespace ivm {
typedef union {
int8_t i8;
uint8_t u8;
int16_t i16;
uint16_t u16;
int32_t i32;
uint32_t u32;
int64_t i64;
uint64_t u64;
float f32;
double f64;
vec128_t v128;
int8_t i8;
uint8_t u8;
int16_t i16;
uint16_t u16;
int32_t i32;
uint32_t u32;
int64_t i64;
uint64_t u64;
float f32;
double f64;
vec128_t v128;
} Register;
typedef struct {
Register* rf;
uint8_t* locals;
uint8_t* context;
uint8_t* membase;
uint8_t* page_table;
int8_t did_carry;
int8_t did_saturate;
Register* rf;
uint8_t* locals;
uint8_t* context;
uint8_t* membase;
uint8_t* page_table;
int8_t did_carry;
int8_t did_saturate;
runtime::ThreadState* thread_state;
uint64_t return_address;
uint64_t call_return_address;
uint64_t return_address;
uint64_t call_return_address;
} IntCodeState;
struct IntCode_s;
typedef uint32_t (*IntCodeFn)(
IntCodeState& ics, const struct IntCode_s* i);
typedef uint32_t (*IntCodeFn)(IntCodeState& ics, const struct IntCode_s* i);
#define IA_RETURN 0xA0000000
#define IA_NEXT 0xB0000000
#define IA_NEXT 0xB0000000
typedef struct IntCode_s {
IntCodeFn intcode_fn;
uint16_t flags;
uint16_t debug_flags;
uint16_t flags;
uint16_t debug_flags;
uint32_t dest_reg;
uint32_t dest_reg;
union {
struct {
uint32_t src1_reg;
uint32_t src2_reg;
uint32_t src3_reg;
uint32_t src1_reg;
uint32_t src2_reg;
uint32_t src3_reg;
// <4 bytes available>
};
struct {
Register constant;
Register constant;
};
};
// debugging info/etc
} IntCode;
typedef struct LabelRef_s {
hir::Label* label;
IntCode* instr;
IntCode* instr;
LabelRef_s* next;
} LabelRef;
typedef struct SourceMapEntry_s {
uint64_t source_offset;
uint64_t intcode_index;
uint64_t source_offset;
uint64_t intcode_index;
} SourceMapEntry;
typedef struct {
uint32_t register_count;
size_t intcode_count;
Arena* intcode_arena;
size_t source_map_count;
Arena* source_map_arena;
Arena* scratch_arena;
uint32_t register_count;
size_t intcode_count;
Arena* intcode_arena;
size_t source_map_count;
Arena* source_map_arena;
Arena* scratch_arena;
LabelRef* label_ref_head;
size_t stack_size;
size_t stack_size;
} TranslationContext;
int TranslateIntCodes(TranslationContext& ctx, hir::Instr* i);
} // namespace ivm
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_IVM_INTCODE_H_

View File

@ -9,15 +9,12 @@
#include <alloy/backend/ivm/ivm_stack.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::ivm;
namespace alloy {
namespace backend {
namespace ivm {
IVMStack::IVMStack() :
chunk_size_(2 * 1024 * 1024),
head_chunk_(NULL), active_chunk_(NULL) {
}
IVMStack::IVMStack()
: chunk_size_(2 * 1024 * 1024), head_chunk_(NULL), active_chunk_(NULL) {}
IVMStack::~IVMStack() {
Chunk* chunk = head_chunk_;
@ -35,7 +32,7 @@ Register* IVMStack::Alloc(size_t register_count) {
if (active_chunk_->capacity - active_chunk_->offset < size) {
Chunk* next = active_chunk_->next;
if (!next) {
XEASSERT(size < chunk_size_); // need to support larger chunks
XEASSERT(size < chunk_size_); // need to support larger chunks
next = new Chunk(chunk_size_);
next->prev = active_chunk_;
active_chunk_->next = next;
@ -66,9 +63,8 @@ void IVMStack::Free(size_t register_count) {
}
}
IVMStack::Chunk::Chunk(size_t chunk_size) :
prev(NULL), next(NULL),
capacity(chunk_size), buffer(0), offset(0) {
IVMStack::Chunk::Chunk(size_t chunk_size)
: prev(NULL), next(NULL), capacity(chunk_size), buffer(0), offset(0) {
buffer = (uint8_t*)xe_malloc(capacity);
}
@ -77,3 +73,7 @@ IVMStack::Chunk::~Chunk() {
xe_free(buffer);
}
}
} // namespace ivm
} // namespace backend
} // namespace alloy

View File

@ -14,44 +14,40 @@
#include <alloy/backend/ivm/ivm_intcode.h>
namespace alloy {
namespace backend {
namespace ivm {
class IVMStack {
public:
public:
IVMStack();
~IVMStack();
Register* Alloc(size_t register_count);
void Free(size_t register_count);
private:
private:
class Chunk {
public:
public:
Chunk(size_t chunk_size);
~Chunk();
Chunk* prev;
Chunk* next;
Chunk* prev;
Chunk* next;
size_t capacity;
uint8_t* buffer;
size_t offset;
size_t capacity;
uint8_t* buffer;
size_t offset;
};
private:
size_t chunk_size_;
Chunk* head_chunk_;
Chunk* active_chunk_;
private:
size_t chunk_size_;
Chunk* head_chunk_;
Chunk* active_chunk_;
};
} // namespace ivm
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_IVM_IVM_STACK_H_

View File

@ -12,24 +12,20 @@
#include <alloy/backend/tracing.h>
namespace alloy {
namespace backend {
namespace ivm {
const uint32_t ALLOY_BACKEND_IVM =
alloy::backend::EventType::ALLOY_BACKEND_IVM;
const uint32_t ALLOY_BACKEND_IVM = alloy::backend::EventType::ALLOY_BACKEND_IVM;
class EventType {
public:
public:
enum {
ALLOY_BACKEND_IVM_INIT = ALLOY_BACKEND_IVM | (1),
ALLOY_BACKEND_IVM_DEINIT = ALLOY_BACKEND_IVM | (2),
ALLOY_BACKEND_IVM_ASSEMBLER = ALLOY_BACKEND_IVM | (1 << 20),
ALLOY_BACKEND_IVM_ASSEMBLER_INIT = ALLOY_BACKEND_IVM_ASSEMBLER | (1),
ALLOY_BACKEND_IVM_ASSEMBLER_DEINIT = ALLOY_BACKEND_IVM_ASSEMBLER | (2),
ALLOY_BACKEND_IVM_INIT = ALLOY_BACKEND_IVM | (1),
ALLOY_BACKEND_IVM_DEINIT = ALLOY_BACKEND_IVM | (2),
ALLOY_BACKEND_IVM_ASSEMBLER = ALLOY_BACKEND_IVM | (1 << 20),
ALLOY_BACKEND_IVM_ASSEMBLER_INIT = ALLOY_BACKEND_IVM_ASSEMBLER | (1),
ALLOY_BACKEND_IVM_ASSEMBLER_DEINIT = ALLOY_BACKEND_IVM_ASSEMBLER | (2),
};
typedef struct Init_s {
@ -47,10 +43,8 @@ public:
} AssemblerDeinit;
};
} // namespace ivm
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_IVM_TRACING_H_

View File

@ -12,11 +12,9 @@
#include <alloy/core.h>
namespace alloy {
namespace backend {
struct MachineInfo {
struct RegisterSet {
enum Types {
@ -31,9 +29,7 @@ struct MachineInfo {
} register_sets[8];
};
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_MACHINE_INFO_H_

View File

@ -13,24 +13,20 @@
#include <alloy/tracing/tracing.h>
#include <alloy/tracing/event_type.h>
namespace alloy {
namespace backend {
const uint32_t ALLOY_BACKEND = alloy::tracing::EventType::ALLOY_BACKEND;
class EventType {
public:
public:
enum {
ALLOY_BACKEND_IVM = ALLOY_BACKEND | (1 << 24),
ALLOY_BACKEND_X64 = ALLOY_BACKEND | (2 << 24),
ALLOY_BACKEND_IVM = ALLOY_BACKEND | (1 << 24),
ALLOY_BACKEND_X64 = ALLOY_BACKEND | (2 << 24),
};
};
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_TRACING_H_

View File

@ -12,24 +12,20 @@
#include <alloy/backend/tracing.h>
namespace alloy {
namespace backend {
namespace x64 {
const uint32_t ALLOY_BACKEND_X64 =
alloy::backend::EventType::ALLOY_BACKEND_X64;
const uint32_t ALLOY_BACKEND_X64 = alloy::backend::EventType::ALLOY_BACKEND_X64;
class EventType {
public:
public:
enum {
ALLOY_BACKEND_X64_INIT = ALLOY_BACKEND_X64 | (1),
ALLOY_BACKEND_X64_DEINIT = ALLOY_BACKEND_X64 | (2),
ALLOY_BACKEND_X64_ASSEMBLER = ALLOY_BACKEND_X64 | (1 << 20),
ALLOY_BACKEND_X64_ASSEMBLER_INIT = ALLOY_BACKEND_X64_ASSEMBLER | (1),
ALLOY_BACKEND_X64_ASSEMBLER_DEINIT = ALLOY_BACKEND_X64_ASSEMBLER | (2),
ALLOY_BACKEND_X64_INIT = ALLOY_BACKEND_X64 | (1),
ALLOY_BACKEND_X64_DEINIT = ALLOY_BACKEND_X64 | (2),
ALLOY_BACKEND_X64_ASSEMBLER = ALLOY_BACKEND_X64 | (1 << 20),
ALLOY_BACKEND_X64_ASSEMBLER_INIT = ALLOY_BACKEND_X64_ASSEMBLER | (1),
ALLOY_BACKEND_X64_ASSEMBLER_DEINIT = ALLOY_BACKEND_X64_ASSEMBLER | (2),
};
typedef struct Init_s {
@ -47,10 +43,8 @@ public:
} AssemblerDeinit;
};
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_TRACING_H_

View File

@ -21,22 +21,23 @@ namespace BE {
#include <beaengine/BeaEngine.h>
}
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::x64;
using namespace alloy::hir;
namespace alloy {
namespace backend {
namespace x64 {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::runtime;
using alloy::hir::HIRBuilder;
using alloy::runtime::DebugInfo;
using alloy::runtime::Function;
using alloy::runtime::FunctionInfo;
X64Assembler::X64Assembler(X64Backend* backend) :
x64_backend_(backend),
emitter_(0), allocator_(0),
Assembler(backend) {
}
X64Assembler::X64Assembler(X64Backend* backend)
: x64_backend_(backend), emitter_(0), allocator_(0), Assembler(backend) {}
X64Assembler::~X64Assembler() {
alloy::tracing::WriteEvent(EventType::AssemblerDeinit({
}));
alloy::tracing::WriteEvent(EventType::AssemblerDeinit({}));
delete emitter_;
delete allocator_;
@ -51,8 +52,7 @@ int X64Assembler::Initialize() {
allocator_ = new XbyakAllocator();
emitter_ = new X64Emitter(x64_backend_, allocator_);
alloy::tracing::WriteEvent(EventType::AssemblerInit({
}));
alloy::tracing::WriteEvent(EventType::AssemblerInit({}));
return result;
}
@ -62,10 +62,9 @@ void X64Assembler::Reset() {
Assembler::Reset();
}
int X64Assembler::Assemble(
FunctionInfo* symbol_info, HIRBuilder* builder,
uint32_t debug_info_flags, DebugInfo* debug_info,
Function** out_function) {
int X64Assembler::Assemble(FunctionInfo* symbol_info, HIRBuilder* builder,
uint32_t debug_info_flags, DebugInfo* debug_info,
Function** out_function) {
SCOPE_profile_cpu_f("alloy");
int result = 0;
@ -73,13 +72,12 @@ int X64Assembler::Assemble(
// Lower HIR -> x64.
void* machine_code = 0;
size_t code_size = 0;
result = emitter_->Emit(builder,
debug_info_flags, debug_info,
machine_code, code_size);
result = emitter_->Emit(builder, debug_info_flags, debug_info, machine_code,
code_size);
XEEXPECTZERO(result);
// Stash generated machine code.
if (debug_info_flags & DEBUG_INFO_MACHINE_CODE_DISASM) {
if (debug_info_flags & DebugInfoFlags::DEBUG_INFO_MACHINE_CODE_DISASM) {
DumpMachineCode(debug_info, machine_code, code_size, &string_buffer_);
debug_info->set_machine_code_disasm(string_buffer_.ToString());
string_buffer_.Reset();
@ -100,10 +98,8 @@ XECLEANUP:
return result;
}
void X64Assembler::DumpMachineCode(
DebugInfo* debug_info,
void* machine_code, size_t code_size,
StringBuffer* str) {
void X64Assembler::DumpMachineCode(DebugInfo* debug_info, void* machine_code,
size_t code_size, StringBuffer* str) {
BE::DISASM disasm;
xe_zero_struct(&disasm, sizeof(disasm));
disasm.Archi = 64;
@ -113,8 +109,8 @@ void X64Assembler::DumpMachineCode(
uint64_t prev_source_offset = 0;
while (disasm.EIP < eip_end) {
// Look up source offset.
auto map_entry = debug_info->LookupCodeOffset(
disasm.EIP - (BE::UIntPtr)machine_code);
auto map_entry =
debug_info->LookupCodeOffset(disasm.EIP - (BE::UIntPtr)machine_code);
if (map_entry) {
if (map_entry->source_offset == prev_source_offset) {
str->Append(" ");
@ -134,3 +130,7 @@ void X64Assembler::DumpMachineCode(
disasm.EIP += len;
}
}
} // namespace x64
} // namespace backend
} // namespace alloy

View File

@ -14,7 +14,6 @@
#include <alloy/backend/assembler.h>
namespace alloy {
namespace backend {
namespace x64 {
@ -23,9 +22,8 @@ class X64Backend;
class X64Emitter;
class XbyakAllocator;
class X64Assembler : public Assembler {
public:
public:
X64Assembler(X64Backend* backend);
virtual ~X64Assembler();
@ -33,28 +31,25 @@ public:
virtual void Reset();
virtual int Assemble(
runtime::FunctionInfo* symbol_info, hir::HIRBuilder* builder,
uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
runtime::Function** out_function);
virtual int Assemble(runtime::FunctionInfo* symbol_info,
hir::HIRBuilder* builder, uint32_t debug_info_flags,
runtime::DebugInfo* debug_info,
runtime::Function** out_function);
private:
void DumpMachineCode(runtime::DebugInfo* debug_info,
void* machine_code, size_t code_size,
StringBuffer* str);
private:
void DumpMachineCode(runtime::DebugInfo* debug_info, void* machine_code,
size_t code_size, StringBuffer* str);
private:
X64Backend* x64_backend_;
X64Emitter* emitter_;
XbyakAllocator* allocator_;
private:
X64Backend* x64_backend_;
X64Emitter* emitter_;
XbyakAllocator* allocator_;
StringBuffer string_buffer_;
StringBuffer string_buffer_;
};
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_ASSEMBLER_H_

View File

@ -15,20 +15,16 @@
#include <alloy/backend/x64/x64_sequences.h>
#include <alloy/backend/x64/x64_thunk_emitter.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::x64;
using namespace alloy::runtime;
namespace alloy {
namespace backend {
namespace x64 {
using alloy::runtime::Runtime;
X64Backend::X64Backend(Runtime* runtime) :
code_cache_(0),
Backend(runtime) {
}
X64Backend::X64Backend(Runtime* runtime) : code_cache_(0), Backend(runtime) {}
X64Backend::~X64Backend() {
alloy::tracing::WriteEvent(EventType::Deinit({
}));
alloy::tracing::WriteEvent(EventType::Deinit({}));
delete code_cache_;
}
@ -41,17 +37,12 @@ int X64Backend::Initialize() {
RegisterSequences();
machine_info_.register_sets[0] = {
0,
"gpr",
MachineInfo::RegisterSet::INT_TYPES,
X64Emitter::GPR_COUNT,
0, "gpr", MachineInfo::RegisterSet::INT_TYPES, X64Emitter::GPR_COUNT,
};
machine_info_.register_sets[1] = {
1,
"xmm",
MachineInfo::RegisterSet::FLOAT_TYPES |
MachineInfo::RegisterSet::VEC_TYPES,
X64Emitter::XMM_COUNT,
1, "xmm", MachineInfo::RegisterSet::FLOAT_TYPES |
MachineInfo::RegisterSet::VEC_TYPES,
X64Emitter::XMM_COUNT,
};
code_cache_ = new X64CodeCache();
@ -67,12 +58,13 @@ int X64Backend::Initialize() {
delete thunk_emitter;
delete allocator;
alloy::tracing::WriteEvent(EventType::Init({
}));
alloy::tracing::WriteEvent(EventType::Init({}));
return result;
}
Assembler* X64Backend::CreateAssembler() {
return new X64Assembler(this);
}
Assembler* X64Backend::CreateAssembler() { return new X64Assembler(this); }
} // namespace x64
} // namespace backend
} // namespace alloy

View File

@ -14,22 +14,19 @@
#include <alloy/backend/backend.h>
namespace alloy {
namespace backend {
namespace x64 {
class X64CodeCache;
#define ALLOY_HAS_X64_BACKEND 1
typedef void* (*HostToGuestThunk)(void* target, void* arg0, void* arg1);
typedef void* (*GuestToHostThunk)(void* target, void* arg0, void* arg1);
class X64Backend : public Backend {
public:
public:
X64Backend(runtime::Runtime* runtime);
virtual ~X64Backend();
@ -41,16 +38,14 @@ public:
virtual Assembler* CreateAssembler();
private:
private:
X64CodeCache* code_cache_;
HostToGuestThunk host_to_guest_thunk_;
GuestToHostThunk guest_to_host_thunk_;
};
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_BACKEND_H_

View File

@ -11,24 +11,20 @@
#include <alloy/backend/x64/tracing.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::x64;
namespace alloy {
namespace backend {
namespace x64 {
class X64CodeChunk {
public:
public:
X64CodeChunk(size_t chunk_size);
~X64CodeChunk();
public:
public:
X64CodeChunk* next;
size_t capacity;
uint8_t* buffer;
size_t offset;
size_t capacity;
uint8_t* buffer;
size_t offset;
// Estimate of function sized use to determine initial table capacity.
const static uint32_t ESTIMATED_FN_SIZE = 512;
@ -36,24 +32,16 @@ public:
// TODO(benvanik): move this to emitter.
const static uint32_t UNWIND_INFO_SIZE = 4 + (2 * 1 + 2 + 2);
void* fn_table_handle;
void* fn_table_handle;
RUNTIME_FUNCTION* fn_table;
uint32_t fn_table_count;
uint32_t fn_table_capacity;
uint32_t fn_table_count;
uint32_t fn_table_capacity;
void AddTableEntry(uint8_t* code, size_t code_size, size_t stack_size);
};
} // namespace x64
} // namespace backend
} // namespace alloy
X64CodeCache::X64CodeCache(size_t chunk_size) :
chunk_size_(chunk_size),
head_chunk_(NULL), active_chunk_(NULL) {
}
X64CodeCache::X64CodeCache(size_t chunk_size)
: chunk_size_(chunk_size), head_chunk_(NULL), active_chunk_(NULL) {}
X64CodeCache::~X64CodeCache() {
std::lock_guard<std::mutex> guard(lock_);
@ -66,9 +54,7 @@ X64CodeCache::~X64CodeCache() {
head_chunk_ = NULL;
}
int X64CodeCache::Initialize() {
return 0;
}
int X64CodeCache::Initialize() { return 0; }
void* X64CodeCache::PlaceCode(void* machine_code, size_t code_size,
size_t stack_size) {
@ -87,7 +73,7 @@ void* X64CodeCache::PlaceCode(void* machine_code, size_t code_size,
if (active_chunk_->capacity - active_chunk_->offset < code_size) {
auto next = active_chunk_->next;
if (!next) {
XEASSERT(code_size < chunk_size_); // need to support larger chunks
XEASSERT(code_size < chunk_size_); // need to support larger chunks
next = new X64CodeChunk(chunk_size_);
active_chunk_->next = next;
}
@ -113,25 +99,19 @@ void* X64CodeCache::PlaceCode(void* machine_code, size_t code_size,
return final_address;
}
X64CodeChunk::X64CodeChunk(size_t chunk_size) :
next(NULL),
capacity(chunk_size), buffer(0), offset(0) {
buffer = (uint8_t*)VirtualAlloc(
NULL, capacity,
MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
X64CodeChunk::X64CodeChunk(size_t chunk_size)
: next(NULL), capacity(chunk_size), buffer(0), offset(0) {
buffer = (uint8_t*)VirtualAlloc(NULL, capacity, MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE);
fn_table_capacity = (uint32_t)XEROUNDUP(capacity / ESTIMATED_FN_SIZE, 16);
size_t table_size = fn_table_capacity * sizeof(RUNTIME_FUNCTION);
fn_table = (RUNTIME_FUNCTION*)xe_malloc(table_size);
fn_table_count = 0;
fn_table_handle = 0;
RtlAddGrowableFunctionTable(
&fn_table_handle,
fn_table,
fn_table_count,
fn_table_capacity,
(ULONG_PTR)buffer, (ULONG_PTR)buffer + capacity);
RtlAddGrowableFunctionTable(&fn_table_handle, fn_table, fn_table_count,
fn_table_capacity, (ULONG_PTR)buffer,
(ULONG_PTR)buffer + capacity);
}
X64CodeChunk::~X64CodeChunk() {
@ -157,7 +137,7 @@ typedef enum _UNWIND_OP_CODES {
UWOP_PUSH_MACHFRAME /* info == 0: no error-code, 1: error-code */
} UNWIND_CODE_OPS;
class UNWIND_REGISTER {
public:
public:
enum _ {
RAX = 0,
RCX = 1,
@ -182,25 +162,25 @@ typedef union _UNWIND_CODE {
struct {
uint8_t CodeOffset;
uint8_t UnwindOp : 4;
uint8_t OpInfo : 4;
uint8_t OpInfo : 4;
};
USHORT FrameOffset;
} UNWIND_CODE, *PUNWIND_CODE;
typedef struct _UNWIND_INFO {
uint8_t Version : 3;
uint8_t Flags : 5;
uint8_t Version : 3;
uint8_t Flags : 5;
uint8_t SizeOfProlog;
uint8_t CountOfCodes;
uint8_t FrameRegister : 4;
uint8_t FrameOffset : 4;
uint8_t FrameOffset : 4;
UNWIND_CODE UnwindCode[1];
/* UNWIND_CODE MoreUnwindCode[((CountOfCodes + 1) & ~1) - 1];
* union {
* OPTIONAL ULONG ExceptionHandler;
* OPTIONAL ULONG FunctionEntry;
* };
* OPTIONAL ULONG ExceptionData[]; */
/* UNWIND_CODE MoreUnwindCode[((CountOfCodes + 1) & ~1) - 1];
* union {
* OPTIONAL ULONG ExceptionHandler;
* OPTIONAL ULONG FunctionEntry;
* };
* OPTIONAL ULONG ExceptionData[]; */
} UNWIND_INFO, *PUNWIND_INFO;
} // namespace
@ -215,19 +195,17 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size,
RtlDeleteGrowableFunctionTable(fn_table_handle);
size_t old_size = fn_table_capacity * sizeof(RUNTIME_FUNCTION);
size_t new_size = old_size * 2;
auto new_table = (RUNTIME_FUNCTION*)xe_realloc(fn_table, old_size, new_size);
auto new_table =
(RUNTIME_FUNCTION*)xe_realloc(fn_table, old_size, new_size);
XEASSERTNOTNULL(new_table);
if (!new_table) {
return;
}
fn_table = new_table;
fn_table_capacity *= 2;
RtlAddGrowableFunctionTable(
&fn_table_handle,
fn_table,
fn_table_count,
fn_table_capacity,
(ULONG_PTR)buffer, (ULONG_PTR)buffer + capacity);
RtlAddGrowableFunctionTable(&fn_table_handle, fn_table, fn_table_count,
fn_table_capacity, (ULONG_PTR)buffer,
(ULONG_PTR)buffer + capacity);
}
// Allocate unwind data. We know we have space because we overallocated.
@ -261,7 +239,8 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size,
// http://msdn.microsoft.com/en-us/library/ck9asaa9.aspx
size_t co = 0;
auto& unwind_code = unwind_info->UnwindCode[co++];
unwind_code.CodeOffset = 14; // end of instruction + 1 == offset of next instruction
unwind_code.CodeOffset =
14; // end of instruction + 1 == offset of next instruction
unwind_code.UnwindOp = UWOP_ALLOC_SMALL;
unwind_code.OpInfo = stack_size / 8 - 1;
} else {
@ -280,7 +259,8 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size,
// http://msdn.microsoft.com/en-us/library/ck9asaa9.aspx
size_t co = 0;
auto& unwind_code = unwind_info->UnwindCode[co++];
unwind_code.CodeOffset = 7; // end of instruction + 1 == offset of next instruction
unwind_code.CodeOffset =
7; // end of instruction + 1 == offset of next instruction
unwind_code.UnwindOp = UWOP_ALLOC_LARGE;
unwind_code.OpInfo = 0;
unwind_code = unwind_info->UnwindCode[co++];
@ -296,3 +276,7 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size,
// Notify the function table that it has new entries.
RtlGrowFunctionTable(fn_table_handle, fn_table_count);
}
} // namespace x64
} // namespace backend
} // namespace alloy

View File

@ -14,7 +14,6 @@
#include <alloy/core.h>
namespace alloy {
namespace backend {
namespace x64 {
@ -22,7 +21,7 @@ namespace x64 {
class X64CodeChunk;
class X64CodeCache {
public:
public:
X64CodeCache(size_t chunk_size = DEFAULT_CHUNK_SIZE);
virtual ~X64CodeCache();
@ -34,18 +33,16 @@ public:
void* PlaceCode(void* machine_code, size_t code_size, size_t stack_size);
private:
private:
const static size_t DEFAULT_CHUNK_SIZE = 4 * 1024 * 1024;
std::mutex lock_;
size_t chunk_size_;
std::mutex lock_;
size_t chunk_size_;
X64CodeChunk* head_chunk_;
X64CodeChunk* active_chunk_;
};
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_CODE_CACHE_H_

View File

@ -20,18 +20,21 @@
#include <alloy/runtime/symbol_info.h>
#include <alloy/runtime/thread_state.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::x64;
namespace alloy {
namespace backend {
namespace x64 {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using namespace alloy::runtime;
using namespace Xbyak;
namespace alloy {
namespace backend {
namespace x64 {
using alloy::hir::HIRBuilder;
using alloy::hir::Instr;
using alloy::runtime::Function;
using alloy::runtime::FunctionInfo;
using alloy::runtime::SourceMapEntry;
using alloy::runtime::ThreadState;
static const size_t MAX_CODE_SIZE = 1 * 1024 * 1024;
@ -42,41 +45,29 @@ static const size_t STASH_OFFSET = 32;
// can get the value.
#define STORE_EFLAGS 1
} // namespace x64
} // namespace backend
} // namespace alloy
const uint32_t X64Emitter::gpr_reg_map_[X64Emitter::GPR_COUNT] = {
Operand::RBX,
Operand::R12, Operand::R13, Operand::R14, Operand::R15,
Operand::RBX, Operand::R12, Operand::R13, Operand::R14, Operand::R15,
};
const uint32_t X64Emitter::xmm_reg_map_[X64Emitter::XMM_COUNT] = {
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
};
X64Emitter::X64Emitter(X64Backend* backend, XbyakAllocator* allocator)
: runtime_(backend->runtime()),
backend_(backend),
code_cache_(backend->code_cache()),
allocator_(allocator),
current_instr_(0),
CodeGenerator(MAX_CODE_SIZE, AutoGrow, allocator) {}
X64Emitter::X64Emitter(X64Backend* backend, XbyakAllocator* allocator) :
runtime_(backend->runtime()),
backend_(backend),
code_cache_(backend->code_cache()),
allocator_(allocator),
current_instr_(0),
CodeGenerator(MAX_CODE_SIZE, AutoGrow, allocator) {
}
X64Emitter::~X64Emitter() {}
X64Emitter::~X64Emitter() {
}
int X64Emitter::Initialize() { return 0; }
int X64Emitter::Initialize() {
return 0;
}
int X64Emitter::Emit(
HIRBuilder* builder,
uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
void*& out_code_address, size_t& out_code_size) {
int X64Emitter::Emit(HIRBuilder* builder, uint32_t debug_info_flags,
runtime::DebugInfo* debug_info, void*& out_code_address,
size_t& out_code_size) {
SCOPE_profile_cpu_f("alloy");
// Reset.
@ -99,8 +90,7 @@ int X64Emitter::Emit(
// Stash source map.
if (debug_info_flags & DEBUG_INFO_SOURCE_MAP) {
debug_info->InitializeSourceMap(
source_map_count_,
(SourceMapEntry*)source_map_arena_.CloneContents());
source_map_count_, (SourceMapEntry*)source_map_arena_.CloneContents());
}
return 0;
@ -158,7 +148,7 @@ int X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) {
mov(qword[rsp + StackLayout::GUEST_RCX_HOME], rcx);
mov(qword[rsp + StackLayout::GUEST_RET_ADDR], rdx);
mov(qword[rsp + StackLayout::GUEST_CALL_RET_ADDR], 0);
mov(rdx, qword[rcx + 8]); // membase
mov(rdx, qword[rcx + 8]); // membase
}
// Body.
@ -208,9 +198,9 @@ int X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) {
void X64Emitter::MarkSourceOffset(const Instr* i) {
auto entry = source_map_arena_.Alloc<SourceMapEntry>();
entry->source_offset = i->src1.offset;
entry->hir_offset = uint32_t(i->block->ordinal << 16) | i->ordinal;
entry->code_offset = getSize();
entry->source_offset = i->src1.offset;
entry->hir_offset = uint32_t(i->block->ordinal << 16) | i->ordinal;
entry->code_offset = getSize();
source_map_count_++;
}
@ -221,20 +211,20 @@ void X64Emitter::DebugBreak() {
void X64Emitter::Trap(uint16_t trap_type) {
switch (trap_type) {
case 20:
// 0x0FE00014 is a 'debug print' where r3 = buffer r4 = length
// TODO(benvanik): debug print at runtime.
break;
case 0:
case 22:
// Always trap?
// TODO(benvanik): post software interrupt to debugger.
db(0xCC);
break;
default:
XELOGW("Unknown trap type %d", trap_type);
db(0xCC);
break;
case 20:
// 0x0FE00014 is a 'debug print' where r3 = buffer r4 = length
// TODO(benvanik): debug print at runtime.
break;
case 0:
case 22:
// Always trap?
// TODO(benvanik): post software interrupt to debugger.
db(0xCC);
break;
default:
XELOGW("Unknown trap type %d", trap_type);
db(0xCC);
break;
}
}
@ -258,7 +248,8 @@ const size_t ASM_OFFSET = 2 + 2 + 8 + 2 + 8;
// 6 bytes 66 NOP DWORD ptr [EAX + EAX*1 + 00H] 66 0F 1F 44 00 00H
// 7 bytes NOP DWORD ptr [EAX + 00000000H] 0F 1F 80 00 00 00 00H
// 8 bytes NOP DWORD ptr [EAX + EAX*1 + 00000000H] 0F 1F 84 00 00 00 00 00H
// 9 bytes 66 NOP DWORD ptr [EAX + EAX*1 + 00000000H] 66 0F 1F 84 00 00 00 00 00H
// 9 bytes 66 NOP DWORD ptr [EAX + EAX*1 + 00000000H] 66 0F 1F 84 00 00 00 00
// 00H
uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) {
// TODO(benvanik): generate this thunk at runtime? or a shim?
@ -275,7 +266,7 @@ uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) {
// Overwrite the call site.
// The return address points to ReloadRCX work after the call.
uint64_t return_address = reinterpret_cast<uint64_t>(_ReturnAddress());
#pragma pack(push, 1)
#pragma pack(push, 1)
struct Asm {
uint16_t mov_rax;
uint64_t rax_constant;
@ -284,7 +275,7 @@ uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) {
uint16_t call_rax;
uint8_t mov_rcx[5];
};
#pragma pack(pop)
#pragma pack(pop)
Asm* code = reinterpret_cast<Asm*>(return_address - ASM_OFFSET);
code->rax_constant = addr;
code->call_rax = 0x9066;
@ -293,7 +284,8 @@ uint64_t ResolveFunctionSymbol(void* raw_context, uint64_t symbol_info_ptr) {
return addr;
}
void X64Emitter::Call(const hir::Instr* instr, runtime::FunctionInfo* symbol_info) {
void X64Emitter::Call(const hir::Instr* instr,
runtime::FunctionInfo* symbol_info) {
auto fn = reinterpret_cast<X64Function*>(symbol_info->function());
// Resolve address to the function to call and store in rax.
// TODO(benvanik): caching/etc. For now this makes debugging easier.
@ -372,12 +364,12 @@ void X64Emitter::CallIndirect(const hir::Instr* instr, const Reg64& reg) {
uint64_t UndefinedCallExtern(void* raw_context, uint64_t symbol_info_ptr) {
auto symbol_info = reinterpret_cast<FunctionInfo*>(symbol_info_ptr);
XELOGW("undefined extern call to %.8X %s",
symbol_info->address(),
XELOGW("undefined extern call to %.8X %s", symbol_info->address(),
symbol_info->name());
return 0;
}
void X64Emitter::CallExtern(const hir::Instr* instr, const FunctionInfo* symbol_info) {
void X64Emitter::CallExtern(const hir::Instr* instr,
const FunctionInfo* symbol_info) {
XEASSERT(symbol_info->behavior() == FunctionInfo::BEHAVIOR_EXTERN);
if (!symbol_info->extern_handler()) {
CallNative(UndefinedCallExtern, reinterpret_cast<uint64_t>(symbol_info));
@ -405,21 +397,22 @@ void X64Emitter::CallNative(void* fn) {
ReloadEDX();
}
void X64Emitter::CallNative(uint64_t(*fn)(void* raw_context)) {
void X64Emitter::CallNative(uint64_t (*fn)(void* raw_context)) {
mov(rax, reinterpret_cast<uint64_t>(fn));
call(rax);
ReloadECX();
ReloadEDX();
}
void X64Emitter::CallNative(uint64_t(*fn)(void* raw_context, uint64_t arg0)) {
void X64Emitter::CallNative(uint64_t (*fn)(void* raw_context, uint64_t arg0)) {
mov(rax, reinterpret_cast<uint64_t>(fn));
call(rax);
ReloadECX();
ReloadEDX();
}
void X64Emitter::CallNative(uint64_t(*fn)(void* raw_context, uint64_t arg0), uint64_t arg0) {
void X64Emitter::CallNative(uint64_t (*fn)(void* raw_context, uint64_t arg0),
uint64_t arg0) {
mov(rdx, arg0);
mov(rax, reinterpret_cast<uint64_t>(fn));
call(rax);
@ -428,17 +421,17 @@ void X64Emitter::CallNative(uint64_t(*fn)(void* raw_context, uint64_t arg0), uin
}
void X64Emitter::CallNativeSafe(void* fn) {
// rcx = context
// rdx = target host function
// r8 = arg0
// r9 = arg1
mov(rdx, reinterpret_cast<uint64_t>(fn));
auto thunk = backend()->guest_to_host_thunk();
mov(rax, reinterpret_cast<uint64_t>(thunk));
call(rax);
ReloadECX();
ReloadEDX();
// rax = host return
// rcx = context
// rdx = target host function
// r8 = arg0
// r9 = arg1
mov(rdx, reinterpret_cast<uint64_t>(fn));
auto thunk = backend()->guest_to_host_thunk();
mov(rax, reinterpret_cast<uint64_t>(thunk));
call(rax);
ReloadECX();
ReloadEDX();
// rax = host return
}
void X64Emitter::SetReturnAddress(uint64_t value) {
@ -450,7 +443,7 @@ void X64Emitter::ReloadECX() {
}
void X64Emitter::ReloadEDX() {
mov(rdx, qword[rcx + 8]); // membase
mov(rdx, qword[rcx + 8]); // membase
}
void X64Emitter::LoadEflags() {
@ -459,7 +452,7 @@ void X64Emitter::LoadEflags() {
push(rax);
popf();
#else
// EFLAGS already present.
// EFLAGS already present.
#endif // STORE_EFLAGS
}
@ -468,8 +461,8 @@ void X64Emitter::StoreEflags() {
pushf();
pop(qword[rsp + STASH_OFFSET]);
#else
// EFLAGS should have CA set?
// (so long as we don't fuck with it)
// EFLAGS should have CA set?
// (so long as we don't fuck with it)
#endif // STORE_EFLAGS
}
@ -511,32 +504,51 @@ void X64Emitter::MovMem64(const RegExp& addr, uint64_t v) {
Address X64Emitter::GetXmmConstPtr(XmmConst id) {
static const vec128_t xmm_consts[] = {
/* XMMZero */ vec128f(0.0f, 0.0f, 0.0f, 0.0f),
/* XMMOne */ vec128f(1.0f, 1.0f, 1.0f, 1.0f),
/* XMMNegativeOne */ vec128f(-1.0f, -1.0f, -1.0f, -1.0f),
/* XMMMaskX16Y16 */ vec128i(0x0000FFFFu, 0xFFFF0000u, 0x00000000u, 0x00000000u),
/* XMMFlipX16Y16 */ vec128i(0x00008000u, 0x00000000u, 0x00000000u, 0x00000000u),
/* XMMFixX16Y16 */ vec128f(-32768.0f, 0.0f, 0.0f, 0.0f),
/* XMMNormalizeX16Y16 */ vec128f(1.0f / 32767.0f, 1.0f / (32767.0f * 65536.0f), 0.0f, 0.0f),
/* XMM0001 */ vec128f(0.0f, 0.0f, 0.0f, 1.0f),
/* XMM3301 */ vec128f(3.0f, 3.0f, 0.0f, 1.0f),
/* XMMSignMaskPS */ vec128i(0x80000000u, 0x80000000u, 0x80000000u, 0x80000000u),
/* XMMSignMaskPD */ vec128i(0x00000000u, 0x80000000u, 0x00000000u, 0x80000000u),
/* XMMAbsMaskPS */ vec128i(0x7FFFFFFFu, 0x7FFFFFFFu, 0x7FFFFFFFu, 0x7FFFFFFFu),
/* XMMAbsMaskPD */ vec128i(0xFFFFFFFFu, 0x7FFFFFFFu, 0xFFFFFFFFu, 0x7FFFFFFFu),
/* XMMByteSwapMask */ vec128i(0x00010203u, 0x04050607u, 0x08090A0Bu, 0x0C0D0E0Fu),
/* XMMPermuteControl15 */ vec128b(15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15),
/* XMMPackD3DCOLOR */ vec128i(0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu, 0x0C000408u),
/* XMMUnpackD3DCOLOR */ vec128i(0xFFFFFF0Eu, 0xFFFFFF0Du, 0xFFFFFF0Cu, 0xFFFFFF0Fu),
/* XMMOneOver255 */ vec128f(1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f),
/* XMMShiftMaskPS */ vec128i(0x0000001Fu, 0x0000001Fu, 0x0000001Fu, 0x0000001Fu),
/* XMMShiftByteMask */ vec128i(0x000000FFu, 0x000000FFu, 0x000000FFu, 0x000000FFu),
/* XMMUnsignedDwordMax */ vec128i(0xFFFFFFFFu, 0x00000000u, 0xFFFFFFFFu, 0x00000000u),
/* XMM255 */ vec128f(255.0f, 255.0f, 255.0f, 255.0f),
/* XMMSignMaskI8 */ vec128i(0x80808080u, 0x80808080u, 0x80808080u, 0x80808080u),
/* XMMSignMaskI16 */ vec128i(0x80008000u, 0x80008000u, 0x80008000u, 0x80008000u),
/* XMMSignMaskI32 */ vec128i(0x80000000u, 0x80000000u, 0x80000000u, 0x80000000u),
/* XMMSignMaskF32 */ vec128i(0x80000000u, 0x80000000u, 0x80000000u, 0x80000000u),
/* XMMZero */ vec128f(0.0f, 0.0f, 0.0f, 0.0f),
/* XMMOne */ vec128f(1.0f, 1.0f, 1.0f, 1.0f),
/* XMMNegativeOne */ vec128f(-1.0f, -1.0f, -1.0f, -1.0f),
/* XMMMaskX16Y16 */ vec128i(0x0000FFFFu, 0xFFFF0000u,
0x00000000u, 0x00000000u),
/* XMMFlipX16Y16 */ vec128i(0x00008000u, 0x00000000u,
0x00000000u, 0x00000000u),
/* XMMFixX16Y16 */ vec128f(-32768.0f, 0.0f, 0.0f, 0.0f),
/* XMMNormalizeX16Y16 */ vec128f(
1.0f / 32767.0f, 1.0f / (32767.0f * 65536.0f), 0.0f, 0.0f),
/* XMM0001 */ vec128f(0.0f, 0.0f, 0.0f, 1.0f),
/* XMM3301 */ vec128f(3.0f, 3.0f, 0.0f, 1.0f),
/* XMMSignMaskPS */ vec128i(0x80000000u, 0x80000000u,
0x80000000u, 0x80000000u),
/* XMMSignMaskPD */ vec128i(0x00000000u, 0x80000000u,
0x00000000u, 0x80000000u),
/* XMMAbsMaskPS */ vec128i(0x7FFFFFFFu, 0x7FFFFFFFu,
0x7FFFFFFFu, 0x7FFFFFFFu),
/* XMMAbsMaskPD */ vec128i(0xFFFFFFFFu, 0x7FFFFFFFu,
0xFFFFFFFFu, 0x7FFFFFFFu),
/* XMMByteSwapMask */ vec128i(0x00010203u, 0x04050607u,
0x08090A0Bu, 0x0C0D0E0Fu),
/* XMMPermuteControl15 */ vec128b(15, 15, 15, 15, 15, 15, 15, 15, 15,
15, 15, 15, 15, 15, 15, 15),
/* XMMPackD3DCOLOR */ vec128i(0xFFFFFFFFu, 0xFFFFFFFFu,
0xFFFFFFFFu, 0x0C000408u),
/* XMMUnpackD3DCOLOR */ vec128i(0xFFFFFF0Eu, 0xFFFFFF0Du,
0xFFFFFF0Cu, 0xFFFFFF0Fu),
/* XMMOneOver255 */ vec128f(1.0f / 255.0f, 1.0f / 255.0f,
1.0f / 255.0f, 1.0f / 255.0f),
/* XMMShiftMaskPS */ vec128i(0x0000001Fu, 0x0000001Fu,
0x0000001Fu, 0x0000001Fu),
/* XMMShiftByteMask */ vec128i(0x000000FFu, 0x000000FFu,
0x000000FFu, 0x000000FFu),
/* XMMUnsignedDwordMax */ vec128i(0xFFFFFFFFu, 0x00000000u,
0xFFFFFFFFu, 0x00000000u),
/* XMM255 */ vec128f(255.0f, 255.0f, 255.0f, 255.0f),
/* XMMSignMaskI8 */ vec128i(0x80808080u, 0x80808080u,
0x80808080u, 0x80808080u),
/* XMMSignMaskI16 */ vec128i(0x80008000u, 0x80008000u,
0x80008000u, 0x80008000u),
/* XMMSignMaskI32 */ vec128i(0x80000000u, 0x80000000u,
0x80000000u, 0x80000000u),
/* XMMSignMaskF32 */ vec128i(0x80000000u, 0x80000000u,
0x80000000u, 0x80000000u),
};
// TODO(benvanik): cache base pointer somewhere? stack? It'd be nice to
// prevent this move.
@ -568,7 +580,7 @@ void X64Emitter::LoadConstantXmm(Xbyak::Xmm dest, float v) {
union {
float f;
uint32_t i;
} x = { v };
} x = {v};
if (!v) {
// 0
vpxor(dest, dest);
@ -587,7 +599,7 @@ void X64Emitter::LoadConstantXmm(Xbyak::Xmm dest, double v) {
union {
double d;
uint64_t i;
} x = { v };
} x = {v};
if (!v) {
// 0
vpxor(dest, dest);
@ -614,3 +626,7 @@ Address X64Emitter::StashXmm(const vec128_t& v) {
vmovups(addr, xmm0);
return addr;
}
} // namespace x64
} // namespace backend
} // namespace alloy

View File

@ -31,12 +31,12 @@ class X64Backend;
class X64CodeCache;
enum RegisterFlags {
REG_DEST = (1 << 0),
REG_ABCD = (1 << 1),
REG_DEST = (1 << 0),
REG_ABCD = (1 << 1),
};
enum XmmConst {
XMMZero = 0,
XMMZero = 0,
XMMOne,
XMMNegativeOne,
XMMMaskX16Y16,
@ -66,12 +66,12 @@ enum XmmConst {
// Unfortunately due to the design of xbyak we have to pass this to the ctor.
class XbyakAllocator : public Xbyak::Allocator {
public:
virtual bool useProtect() const { return false; }
public:
virtual bool useProtect() const { return false; }
};
class X64Emitter : public Xbyak::CodeGenerator {
public:
public:
X64Emitter(X64Backend* backend, XbyakAllocator* allocator);
virtual ~X64Emitter();
@ -80,11 +80,11 @@ public:
int Initialize();
int Emit(hir::HIRBuilder* builder,
uint32_t debug_info_flags, runtime::DebugInfo* debug_info,
void*& out_code_address, size_t& out_code_size);
int Emit(hir::HIRBuilder* builder, uint32_t debug_info_flags,
runtime::DebugInfo* debug_info, void*& out_code_address,
size_t& out_code_size);
public:
public:
// Reserved: rsp
// Scratch: rax/rcx/rdx
// xmm0-2 (could be only xmm0 with some trickery)
@ -123,11 +123,13 @@ public:
void Call(const hir::Instr* instr, runtime::FunctionInfo* symbol_info);
void CallIndirect(const hir::Instr* instr, const Xbyak::Reg64& reg);
void CallExtern(const hir::Instr* instr, const runtime::FunctionInfo* symbol_info);
void CallExtern(const hir::Instr* instr,
const runtime::FunctionInfo* symbol_info);
void CallNative(void* fn);
void CallNative(uint64_t(*fn)(void* raw_context));
void CallNative(uint64_t(*fn)(void* raw_context, uint64_t arg0));
void CallNative(uint64_t(*fn)(void* raw_context, uint64_t arg0), uint64_t arg0);
void CallNative(uint64_t (*fn)(void* raw_context));
void CallNative(uint64_t (*fn)(void* raw_context, uint64_t arg0));
void CallNative(uint64_t (*fn)(void* raw_context, uint64_t arg0),
uint64_t arg0);
void CallNativeSafe(void* fn);
void SetReturnAddress(uint64_t value);
void ReloadECX();
@ -153,31 +155,29 @@ public:
size_t stack_size() const { return stack_size_; }
protected:
protected:
void* Emplace(size_t stack_size);
int Emit(hir::HIRBuilder* builder, size_t& out_stack_size);
protected:
protected:
runtime::Runtime* runtime_;
X64Backend* backend_;
X64CodeCache* code_cache_;
XbyakAllocator* allocator_;
X64Backend* backend_;
X64CodeCache* code_cache_;
XbyakAllocator* allocator_;
hir::Instr* current_instr_;
size_t source_map_count_;
Arena source_map_arena_;
size_t source_map_count_;
Arena source_map_arena_;
size_t stack_size_;
size_t stack_size_;
static const uint32_t gpr_reg_map_[GPR_COUNT];
static const uint32_t xmm_reg_map_[XMM_COUNT];
};
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_EMITTER_H_

View File

@ -14,16 +14,17 @@
#include <alloy/runtime/runtime.h>
#include <alloy/runtime/thread_state.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::x64;
using namespace alloy::runtime;
namespace alloy {
namespace backend {
namespace x64 {
using alloy::runtime::Breakpoint;
using alloy::runtime::Function;
using alloy::runtime::FunctionInfo;
using alloy::runtime::ThreadState;
X64Function::X64Function(FunctionInfo* symbol_info) :
machine_code_(NULL), code_size_(0),
Function(symbol_info) {
}
X64Function::X64Function(FunctionInfo* symbol_info)
: machine_code_(NULL), code_size_(0), Function(symbol_info) {}
X64Function::~X64Function() {
// machine_code_ is freed by code cache.
@ -34,20 +35,17 @@ void X64Function::Setup(void* machine_code, size_t code_size) {
code_size_ = code_size;
}
int X64Function::AddBreakpointImpl(Breakpoint* breakpoint) {
return 0;
}
int X64Function::AddBreakpointImpl(Breakpoint* breakpoint) { return 0; }
int X64Function::RemoveBreakpointImpl(Breakpoint* breakpoint) {
return 0;
}
int X64Function::RemoveBreakpointImpl(Breakpoint* breakpoint) { return 0; }
int X64Function::CallImpl(ThreadState* thread_state, uint64_t return_address) {
auto backend = (X64Backend*)thread_state->runtime()->backend();
auto thunk = backend->host_to_guest_thunk();
thunk(
machine_code_,
thread_state->raw_context(),
(void*)return_address);
thunk(machine_code_, thread_state->raw_context(), (void*)return_address);
return 0;
}
} // namespace x64
} // namespace backend
} // namespace alloy

View File

@ -14,14 +14,12 @@
#include <alloy/runtime/function.h>
#include <alloy/runtime/symbol_info.h>
namespace alloy {
namespace backend {
namespace x64 {
class X64Function : public runtime::Function {
public:
public:
X64Function(runtime::FunctionInfo* symbol_info);
virtual ~X64Function();
@ -30,21 +28,19 @@ public:
void Setup(void* machine_code, size_t code_size);
protected:
protected:
virtual int AddBreakpointImpl(runtime::Breakpoint* breakpoint);
virtual int RemoveBreakpointImpl(runtime::Breakpoint* breakpoint);
virtual int CallImpl(runtime::ThreadState* thread_state,
uint64_t return_address);
private:
void* machine_code_;
size_t code_size_;
private:
void* machine_code_;
size_t code_size_;
};
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_FUNCTION_H_

View File

@ -20,14 +20,12 @@ namespace x64 {
class X64Emitter;
void RegisterSequences();
bool SelectSequence(X64Emitter& e, const hir::Instr* i, const hir::Instr** new_tail);
bool SelectSequence(X64Emitter& e, const hir::Instr* i,
const hir::Instr** new_tail);
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_SEQUENCES_H_

View File

@ -11,21 +11,16 @@
#include <third_party/xbyak/xbyak/xbyak.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::backend::x64;
namespace alloy {
namespace backend {
namespace x64 {
using namespace Xbyak;
X64ThunkEmitter::X64ThunkEmitter(X64Backend* backend, XbyakAllocator* allocator)
: X64Emitter(backend, allocator) {}
X64ThunkEmitter::X64ThunkEmitter(
X64Backend* backend, XbyakAllocator* allocator) :
X64Emitter(backend, allocator) {
}
X64ThunkEmitter::~X64ThunkEmitter() {
}
X64ThunkEmitter::~X64ThunkEmitter() {}
HostToGuestThunk X64ThunkEmitter::EmitHostToGuestThunk() {
// rcx = target
@ -101,7 +96,7 @@ GuestToHostThunk X64ThunkEmitter::EmitGuestToHostThunk() {
// rdx = target function
// r8 = arg0
// r9 = arg1
const size_t stack_size = StackLayout::THUNK_STACK_SIZE;
// rsp + 0 = return address
mov(qword[rsp + 8 * 2], rdx);
@ -143,3 +138,7 @@ GuestToHostThunk X64ThunkEmitter::EmitGuestToHostThunk() {
void* fn = Emplace(stack_size);
return (HostToGuestThunk)fn;
}
} // namespace x64
} // namespace backend
} // namespace alloy

View File

@ -14,12 +14,10 @@
#include <alloy/backend/x64/x64_backend.h>
#include <alloy/backend/x64/x64_emitter.h>
namespace alloy {
namespace backend {
namespace x64 {
/**
* Stack Layout
* ----------------------------
@ -116,7 +114,7 @@ namespace x64 {
*/
class StackLayout {
public:
public:
const static size_t THUNK_STACK_SIZE = 120;
const static size_t GUEST_STACK_SIZE = 88;
@ -125,9 +123,8 @@ public:
const static size_t GUEST_CALL_RET_ADDR = 80;
};
class X64ThunkEmitter : public X64Emitter {
public:
public:
X64ThunkEmitter(X64Backend* backend, XbyakAllocator* allocator);
virtual ~X64ThunkEmitter();
@ -138,10 +135,8 @@ public:
GuestToHostThunk EmitGuestToHostThunk();
};
} // namespace x64
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_THUNK_EMITTER_H_

View File

@ -27,9 +27,12 @@ namespace x64 {
#define TARGET_THREAD 1
#define IFLUSH() fflush(stdout)
#define IPRINT if (thread_state->thread_id() == TARGET_THREAD) printf
#define IPRINT \
if (thread_state->thread_id() == TARGET_THREAD) printf
#define DFLUSH() fflush(stdout)
#define DPRINT DFLUSH(); if (thread_state->thread_id() == TARGET_THREAD) printf
#define DPRINT \
DFLUSH(); \
if (thread_state->thread_id() == TARGET_THREAD) printf
uint32_t GetTracingMode() {
uint32_t mode = 0;
@ -66,7 +69,8 @@ void TraceContextLoadI64(void* raw_context, uint64_t offset, uint64_t value) {
}
void TraceContextLoadF32(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("%e (%X) = ctx f32 +%d\n", value.m128_f32[0], value.m128_i32[0], offset);
DPRINT("%e (%X) = ctx f32 +%d\n", value.m128_f32[0], value.m128_i32[0],
offset);
}
void TraceContextLoadF64(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
@ -80,9 +84,9 @@ void TraceContextLoadF64(void* raw_context, uint64_t offset, __m128 value) {
void TraceContextLoadV128(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = ctx v128 +%d\n",
value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], value.m128_f32[3],
value.m128_i32[0], value.m128_i32[1], value.m128_i32[2], value.m128_i32[3],
offset);
value.m128_f32[0], value.m128_f32[1], value.m128_f32[2],
value.m128_f32[3], value.m128_i32[0], value.m128_i32[1],
value.m128_i32[2], value.m128_i32[3], offset);
}
void TraceContextStoreI8(void* raw_context, uint64_t offset, uint8_t value) {
@ -103,7 +107,8 @@ void TraceContextStoreI64(void* raw_context, uint64_t offset, uint64_t value) {
}
void TraceContextStoreF32(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("ctx f32 +%d = %e (%X)\n", offset, value.m128_i32[0], value.m128_f32[0]);
DPRINT("ctx f32 +%d = %e (%X)\n", offset, value.m128_i32[0],
value.m128_f32[0]);
}
void TraceContextStoreF64(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
@ -117,8 +122,9 @@ void TraceContextStoreF64(void* raw_context, uint64_t offset, __m128 value) {
void TraceContextStoreV128(void* raw_context, uint64_t offset, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("ctx v128 +%d = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n", offset,
value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], value.m128_f32[3],
value.m128_i32[0], value.m128_i32[1], value.m128_i32[2], value.m128_i32[3]);
value.m128_f32[0], value.m128_f32[1], value.m128_f32[2],
value.m128_f32[3], value.m128_i32[0], value.m128_i32[1],
value.m128_i32[2], value.m128_i32[3]);
}
void TraceMemoryLoadI8(void* raw_context, uint64_t address, uint8_t value) {
@ -139,7 +145,8 @@ void TraceMemoryLoadI64(void* raw_context, uint64_t address, uint64_t value) {
}
void TraceMemoryLoadF32(void* raw_context, uint64_t address, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("%e (%X) = load.f32 %.8X\n", value.m128_f32[0], value.m128_i32[0], address);
DPRINT("%e (%X) = load.f32 %.8X\n", value.m128_f32[0], value.m128_i32[0],
address);
}
void TraceMemoryLoadF64(void* raw_context, uint64_t address, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
@ -153,9 +160,9 @@ void TraceMemoryLoadF64(void* raw_context, uint64_t address, __m128 value) {
void TraceMemoryLoadV128(void* raw_context, uint64_t address, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("[%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X] = load.v128 %.8X\n",
value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], value.m128_f32[3],
value.m128_i32[0], value.m128_i32[1], value.m128_i32[2], value.m128_i32[3],
address);
value.m128_f32[0], value.m128_f32[1], value.m128_f32[2],
value.m128_f32[3], value.m128_i32[0], value.m128_i32[1],
value.m128_i32[2], value.m128_i32[3], address);
}
void TraceMemoryStoreI8(void* raw_context, uint64_t address, uint8_t value) {
@ -176,7 +183,8 @@ void TraceMemoryStoreI64(void* raw_context, uint64_t address, uint64_t value) {
}
void TraceMemoryStoreF32(void* raw_context, uint64_t address, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("store.f32 %.8X = %e (%X)\n", address, value.m128_f32[0], value.m128_i32[0]);
DPRINT("store.f32 %.8X = %e (%X)\n", address, value.m128_f32[0],
value.m128_i32[0]);
}
void TraceMemoryStoreF64(void* raw_context, uint64_t address, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
@ -189,12 +197,12 @@ void TraceMemoryStoreF64(void* raw_context, uint64_t address, __m128 value) {
}
void TraceMemoryStoreV128(void* raw_context, uint64_t address, __m128 value) {
auto thread_state = *((ThreadState**)raw_context);
DPRINT("store.v128 %.8X = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n", address,
value.m128_f32[0], value.m128_f32[1], value.m128_f32[2], value.m128_f32[3],
value.m128_i32[0], value.m128_i32[1], value.m128_i32[2], value.m128_i32[3]);
DPRINT("store.v128 %.8X = [%e, %e, %e, %e] [%.8X, %.8X, %.8X, %.8X]\n",
address, value.m128_f32[0], value.m128_f32[1], value.m128_f32[2],
value.m128_f32[3], value.m128_i32[0], value.m128_i32[1],
value.m128_i32[2], value.m128_i32[3]);
}
} // namespace x64
} // namespace backend
} // namespace alloy

View File

@ -16,19 +16,18 @@
#include <xmmintrin.h>
#else
typedef union __declspec(align(16)) __m128 {
float m128_f32[4];
uint64_t m128_u64[2];
int8_t m128_i8[16];
int16_t m128_i16[8];
int32_t m128_i32[4];
int64_t m128_i64[2];
uint8_t m128_u8[16];
uint16_t m128_u16[8];
uint32_t m128_u32[4];
float m128_f32[4];
uint64_t m128_u64[2];
int8_t m128_i8[16];
int16_t m128_i16[8];
int32_t m128_i32[4];
int64_t m128_i64[2];
uint8_t m128_u8[16];
uint16_t m128_u16[8];
uint32_t m128_u32[4];
} __m128;
#endif
namespace alloy {
namespace backend {
namespace x64 {
@ -81,5 +80,4 @@ void TraceMemoryStoreV128(void* raw_context, uint64_t address, __m128 value);
} // namespace backend
} // namespace alloy
#endif // ALLOY_BACKEND_X64_X64_TRACERS_H_

View File

@ -12,18 +12,16 @@
#include <alloy/compiler/compiler_pass.h>
#include <alloy/compiler/tracing.h>
using namespace alloy;
using namespace alloy::compiler;
using namespace alloy::hir;
using namespace alloy::runtime;
namespace alloy {
namespace compiler {
using alloy::hir::HIRBuilder;
using alloy::runtime::Runtime;
Compiler::Compiler(Runtime* runtime) :
runtime_(runtime) {
Compiler::Compiler(Runtime* runtime) : runtime_(runtime) {
scratch_arena_ = new Arena();
alloy::tracing::WriteEvent(EventType::Init({
}));
alloy::tracing::WriteEvent(EventType::Init({}));
}
Compiler::~Compiler() {
@ -36,8 +34,7 @@ Compiler::~Compiler() {
delete scratch_arena_;
alloy::tracing::WriteEvent(EventType::Deinit({
}));
alloy::tracing::WriteEvent(EventType::Deinit({}));
}
void Compiler::AddPass(CompilerPass* pass) {
@ -45,8 +42,7 @@ void Compiler::AddPass(CompilerPass* pass) {
passes_.push_back(pass);
}
void Compiler::Reset() {
}
void Compiler::Reset() {}
int Compiler::Compile(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -63,3 +59,6 @@ int Compiler::Compile(HIRBuilder* builder) {
return 0;
}
} // namespace compiler
} // namespace alloy

View File

@ -13,17 +13,19 @@
#include <alloy/core.h>
#include <alloy/hir/hir_builder.h>
namespace alloy { namespace runtime { class Runtime; } }
namespace alloy {
namespace runtime {
class Runtime;
} // namespace runtime
} // namespace alloy
namespace alloy {
namespace compiler {
class CompilerPass;
class Compiler {
public:
public:
Compiler(runtime::Runtime* runtime);
~Compiler();
@ -36,7 +38,7 @@ public:
int Compile(hir::HIRBuilder* builder);
private:
private:
runtime::Runtime* runtime_;
Arena* scratch_arena_;
@ -44,9 +46,7 @@ private:
PassList passes_;
};
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_COMPILER_H_

View File

@ -11,16 +11,12 @@
#include <alloy/compiler/compiler.h>
using namespace alloy;
using namespace alloy::compiler;
namespace alloy {
namespace compiler {
CompilerPass::CompilerPass() : runtime_(0), compiler_(0) {}
CompilerPass::CompilerPass() :
runtime_(0), compiler_(0) {
}
CompilerPass::~CompilerPass() {
}
CompilerPass::~CompilerPass() {}
int CompilerPass::Initialize(Compiler* compiler) {
runtime_ = compiler->runtime();
@ -31,3 +27,6 @@ int CompilerPass::Initialize(Compiler* compiler) {
Arena* CompilerPass::scratch_arena() const {
return compiler_->scratch_arena();
}
} // namespace compiler
} // namespace alloy

View File

@ -14,17 +14,19 @@
#include <alloy/hir/hir_builder.h>
namespace alloy { namespace runtime { class Runtime; } }
namespace alloy {
namespace runtime {
class Runtime;
} // namespace runtime
} // namespace alloy
namespace alloy {
namespace compiler {
class Compiler;
class CompilerPass {
public:
public:
CompilerPass();
virtual ~CompilerPass();
@ -32,17 +34,15 @@ public:
virtual int Run(hir::HIRBuilder* builder) = 0;
protected:
protected:
Arena* scratch_arena() const;
protected:
protected:
runtime::Runtime* runtime_;
Compiler* compiler_;
};
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_COMPILER_PASS_H_

View File

@ -15,7 +15,7 @@
#include <alloy/compiler/passes/context_promotion_pass.h>
#include <alloy/compiler/passes/data_flow_analysis_pass.h>
#include <alloy/compiler/passes/dead_code_elimination_pass.h>
//#include <alloy/compiler/passes/dead_store_elimination_pass.h>
//#include <alloy/compiler/passes/dead_store_elimination_pass.h>
#include <alloy/compiler/passes/finalization_pass.h>
#include <alloy/compiler/passes/register_allocation_pass.h>
#include <alloy/compiler/passes/simplification_pass.h>
@ -49,7 +49,6 @@
// Block gets:
// AddIncomingValue(Value* value, Block* src_block) ??
// Potentially interesting passes:
//
// Run order:

View File

@ -12,18 +12,20 @@
#include <alloy/runtime/function.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using alloy::hir::HIRBuilder;
using alloy::hir::TypeName;
using alloy::hir::Value;
ConstantPropagationPass::ConstantPropagationPass() :
CompilerPass() {
}
ConstantPropagationPass::ConstantPropagationPass() : CompilerPass() {}
ConstantPropagationPass::~ConstantPropagationPass() {
}
ConstantPropagationPass::~ConstantPropagationPass() {}
int ConstantPropagationPass::Run(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -55,379 +57,379 @@ int ConstantPropagationPass::Run(HIRBuilder* builder) {
// v1 = 19
// v2 = 0
Block* block = builder->first_block();
auto block = builder->first_block();
while (block) {
Instr* i = block->instr_head;
auto i = block->instr_head;
while (i) {
Value* v = i->dest;
auto v = i->dest;
switch (i->opcode->num) {
case OPCODE_DEBUG_BREAK_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
i->Replace(&OPCODE_DEBUG_BREAK_info, i->flags);
} else {
i->Remove();
case OPCODE_DEBUG_BREAK_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
i->Replace(&OPCODE_DEBUG_BREAK_info, i->flags);
} else {
i->Remove();
}
}
}
break;
break;
case OPCODE_TRAP_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
i->Replace(&OPCODE_TRAP_info, i->flags);
} else {
i->Remove();
case OPCODE_TRAP_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
i->Replace(&OPCODE_TRAP_info, i->flags);
} else {
i->Remove();
}
}
}
break;
break;
case OPCODE_CALL_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
auto symbol_info = i->src2.symbol_info;
case OPCODE_CALL_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
auto symbol_info = i->src2.symbol_info;
i->Replace(&OPCODE_CALL_info, i->flags);
i->src1.symbol_info = symbol_info;
} else {
i->Remove();
}
}
break;
case OPCODE_CALL_INDIRECT:
if (i->src1.value->IsConstant()) {
runtime::FunctionInfo* symbol_info;
if (runtime_->LookupFunctionInfo(
(uint32_t)i->src1.value->constant.i32, &symbol_info)) {
break;
}
i->Replace(&OPCODE_CALL_info, i->flags);
i->src1.symbol_info = symbol_info;
} else {
}
break;
case OPCODE_CALL_INDIRECT_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
auto value = i->src2.value;
i->Replace(&OPCODE_CALL_INDIRECT_info, i->flags);
i->set_src1(value);
} else {
i->Remove();
}
}
break;
case OPCODE_BRANCH_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
auto label = i->src2.label;
i->Replace(&OPCODE_BRANCH_info, i->flags);
i->src1.label = label;
} else {
i->Remove();
}
}
break;
case OPCODE_BRANCH_FALSE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantFalse()) {
auto label = i->src2.label;
i->Replace(&OPCODE_BRANCH_info, i->flags);
i->src1.label = label;
} else {
i->Remove();
}
}
break;
case OPCODE_CAST:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->Cast(target_type);
i->Remove();
}
}
break;
case OPCODE_CALL_INDIRECT:
if (i->src1.value->IsConstant()) {
runtime::FunctionInfo* symbol_info;
if (runtime_->LookupFunctionInfo(
(uint32_t)i->src1.value->constant.i32, &symbol_info)) {
break;
}
i->Replace(&OPCODE_CALL_info, i->flags);
i->src1.symbol_info = symbol_info;
}
break;
case OPCODE_CALL_INDIRECT_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
auto value = i->src2.value;
i->Replace(&OPCODE_CALL_INDIRECT_info, i->flags);
i->set_src1(value);
} else {
break;
case OPCODE_ZERO_EXTEND:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->ZeroExtend(target_type);
i->Remove();
}
}
break;
case OPCODE_BRANCH_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
auto label = i->src2.label;
i->Replace(&OPCODE_BRANCH_info, i->flags);
i->src1.label = label;
} else {
break;
case OPCODE_SIGN_EXTEND:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->SignExtend(target_type);
i->Remove();
}
}
break;
case OPCODE_BRANCH_FALSE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantFalse()) {
auto label = i->src2.label;
i->Replace(&OPCODE_BRANCH_info, i->flags);
i->src1.label = label;
} else {
break;
case OPCODE_TRUNCATE:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->Truncate(target_type);
i->Remove();
}
}
break;
break;
case OPCODE_CAST:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->Cast(target_type);
i->Remove();
}
break;
case OPCODE_ZERO_EXTEND:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->ZeroExtend(target_type);
i->Remove();
}
break;
case OPCODE_SIGN_EXTEND:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->SignExtend(target_type);
i->Remove();
}
break;
case OPCODE_TRUNCATE:
if (i->src1.value->IsConstant()) {
TypeName target_type = v->type;
v->set_from(i->src1.value);
v->Truncate(target_type);
i->Remove();
}
break;
case OPCODE_SELECT:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
v->set_from(i->src2.value);
} else {
v->set_from(i->src3.value);
case OPCODE_SELECT:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
v->set_from(i->src2.value);
} else {
v->set_from(i->src3.value);
}
i->Remove();
}
i->Remove();
}
break;
case OPCODE_IS_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
v->set_constant((int8_t)1);
} else {
v->set_constant((int8_t)0);
break;
case OPCODE_IS_TRUE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantTrue()) {
v->set_constant((int8_t)1);
} else {
v->set_constant((int8_t)0);
}
i->Remove();
}
i->Remove();
}
break;
case OPCODE_IS_FALSE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantFalse()) {
v->set_constant((int8_t)1);
} else {
v->set_constant((int8_t)0);
break;
case OPCODE_IS_FALSE:
if (i->src1.value->IsConstant()) {
if (i->src1.value->IsConstantFalse()) {
v->set_constant((int8_t)1);
} else {
v->set_constant((int8_t)0);
}
i->Remove();
}
i->Remove();
}
break;
break;
// TODO(benvanik): compares
case OPCODE_COMPARE_EQ:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantEQ(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_NE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantNE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_SLT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSLT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_SLE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSLE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_SGT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSGT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_SGE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSGE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_ULT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantULT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_ULE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantULE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_UGT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantUGT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_UGE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantUGE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_DID_CARRY:
XEASSERT(!i->src1.value->IsConstant());
break;
case OPCODE_DID_OVERFLOW:
XEASSERT(!i->src1.value->IsConstant());
break;
case OPCODE_DID_SATURATE:
XEASSERT(!i->src1.value->IsConstant());
break;
case OPCODE_ADD:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
bool did_carry = v->Add(i->src2.value);
bool propagate_carry = !!(i->flags & ARITHMETIC_SET_CARRY);
i->Remove();
// If carry is set find the DID_CARRY and fix it.
if (propagate_carry) {
PropagateCarry(v, did_carry);
// TODO(benvanik): compares
case OPCODE_COMPARE_EQ:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantEQ(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
}
break;
// TODO(benvanik): ADD_CARRY (w/ ARITHMETIC_SET_CARRY)
case OPCODE_SUB:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
bool did_carry = v->Sub(i->src2.value);
bool propagate_carry = !!(i->flags & ARITHMETIC_SET_CARRY);
i->Remove();
// If carry is set find the DID_CARRY and fix it.
if (propagate_carry) {
PropagateCarry(v, did_carry);
break;
case OPCODE_COMPARE_NE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantNE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
}
break;
case OPCODE_MUL:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Mul(i->src2.value);
i->Remove();
}
break;
case OPCODE_DIV:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Div(i->src2.value);
i->Remove();
}
break;
// case OPCODE_MUL_ADD:
// case OPCODE_MUL_SUB
case OPCODE_NEG:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Neg();
i->Remove();
}
break;
case OPCODE_ABS:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Abs();
i->Remove();
}
break;
case OPCODE_SQRT:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Sqrt();
i->Remove();
}
break;
case OPCODE_RSQRT:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->RSqrt();
i->Remove();
}
break;
break;
case OPCODE_COMPARE_SLT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSLT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_SLE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSLE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_SGT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSGT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_SGE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantSGE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_ULT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantULT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_ULE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantULE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_UGT:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantUGT(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_COMPARE_UGE:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
bool value = i->src1.value->IsConstantUGE(i->src2.value);
i->dest->set_constant(value);
i->Remove();
}
break;
case OPCODE_AND:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->And(i->src2.value);
i->Remove();
}
break;
case OPCODE_OR:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Or(i->src2.value);
i->Remove();
}
break;
case OPCODE_XOR:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Xor(i->src2.value);
i->Remove();
}
break;
case OPCODE_NOT:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Not();
i->Remove();
}
break;
case OPCODE_SHL:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Shl(i->src2.value);
i->Remove();
}
break;
// TODO(benvanik): VECTOR_SHL
case OPCODE_SHR:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Shr(i->src2.value);
i->Remove();
}
break;
case OPCODE_SHA:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Sha(i->src2.value);
i->Remove();
}
break;
// TODO(benvanik): ROTATE_LEFT
case OPCODE_BYTE_SWAP:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->ByteSwap();
i->Remove();
}
break;
case OPCODE_CNTLZ:
if (i->src1.value->IsConstant()) {
v->set_zero(v->type);
v->CountLeadingZeros(i->src1.value);
i->Remove();
}
break;
// TODO(benvanik): INSERT/EXTRACT
// TODO(benvanik): SPLAT/PERMUTE/SWIZZLE
case OPCODE_SPLAT:
if (i->src1.value->IsConstant()) {
// Quite a few of these, from building vec128s.
}
break;
case OPCODE_DID_CARRY:
XEASSERT(!i->src1.value->IsConstant());
break;
case OPCODE_DID_OVERFLOW:
XEASSERT(!i->src1.value->IsConstant());
break;
case OPCODE_DID_SATURATE:
XEASSERT(!i->src1.value->IsConstant());
break;
case OPCODE_ADD:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
bool did_carry = v->Add(i->src2.value);
bool propagate_carry = !!(i->flags & ARITHMETIC_SET_CARRY);
i->Remove();
// If carry is set find the DID_CARRY and fix it.
if (propagate_carry) {
PropagateCarry(v, did_carry);
}
}
break;
// TODO(benvanik): ADD_CARRY (w/ ARITHMETIC_SET_CARRY)
case OPCODE_SUB:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
bool did_carry = v->Sub(i->src2.value);
bool propagate_carry = !!(i->flags & ARITHMETIC_SET_CARRY);
i->Remove();
// If carry is set find the DID_CARRY and fix it.
if (propagate_carry) {
PropagateCarry(v, did_carry);
}
}
break;
case OPCODE_MUL:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Mul(i->src2.value);
i->Remove();
}
break;
case OPCODE_DIV:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Div(i->src2.value);
i->Remove();
}
break;
// case OPCODE_MUL_ADD:
// case OPCODE_MUL_SUB
case OPCODE_NEG:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Neg();
i->Remove();
}
break;
case OPCODE_ABS:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Abs();
i->Remove();
}
break;
case OPCODE_SQRT:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Sqrt();
i->Remove();
}
break;
case OPCODE_RSQRT:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->RSqrt();
i->Remove();
}
break;
case OPCODE_AND:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->And(i->src2.value);
i->Remove();
}
break;
case OPCODE_OR:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Or(i->src2.value);
i->Remove();
}
break;
case OPCODE_XOR:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Xor(i->src2.value);
i->Remove();
}
break;
case OPCODE_NOT:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->Not();
i->Remove();
}
break;
case OPCODE_SHL:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Shl(i->src2.value);
i->Remove();
}
break;
// TODO(benvanik): VECTOR_SHL
case OPCODE_SHR:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Shr(i->src2.value);
i->Remove();
}
break;
case OPCODE_SHA:
if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) {
v->set_from(i->src1.value);
v->Sha(i->src2.value);
i->Remove();
}
break;
// TODO(benvanik): ROTATE_LEFT
case OPCODE_BYTE_SWAP:
if (i->src1.value->IsConstant()) {
v->set_from(i->src1.value);
v->ByteSwap();
i->Remove();
}
break;
case OPCODE_CNTLZ:
if (i->src1.value->IsConstant()) {
v->set_zero(v->type);
v->CountLeadingZeros(i->src1.value);
i->Remove();
}
break;
// TODO(benvanik): INSERT/EXTRACT
// TODO(benvanik): SPLAT/PERMUTE/SWIZZLE
case OPCODE_SPLAT:
if (i->src1.value->IsConstant()) {
// Quite a few of these, from building vec128s.
}
break;
}
i = i->next;
}
@ -438,7 +440,7 @@ int ConstantPropagationPass::Run(HIRBuilder* builder) {
return 0;
}
void ConstantPropagationPass::PropagateCarry(hir::Value* v, bool did_carry) {
void ConstantPropagationPass::PropagateCarry(Value* v, bool did_carry) {
auto next = v->use_head;
while (next) {
auto use = next;
@ -450,3 +452,7 @@ void ConstantPropagationPass::PropagateCarry(hir::Value* v, bool did_carry) {
}
}
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -12,27 +12,23 @@
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class ConstantPropagationPass : public CompilerPass {
public:
public:
ConstantPropagationPass();
virtual ~ConstantPropagationPass();
virtual int Run(hir::HIRBuilder* builder);
private:
private:
void PropagateCarry(hir::Value* v, bool did_carry);
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_CONSTANT_PROPAGATION_PASS_H_

View File

@ -14,22 +14,24 @@
#include <alloy/compiler/compiler.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
using namespace alloy::frontend;
using namespace alloy::hir;
using namespace alloy::runtime;
DEFINE_bool(store_all_context_values, false,
"Don't strip dead context stores to aid in debugging.");
namespace alloy {
namespace compiler {
namespace passes {
ContextPromotionPass::ContextPromotionPass() :
context_values_size_(0), context_values_(0),
CompilerPass() {
}
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using alloy::frontend::ContextInfo;
using alloy::hir::Block;
using alloy::hir::HIRBuilder;
using alloy::hir::Instr;
using alloy::hir::Value;
ContextPromotionPass::ContextPromotionPass()
: context_values_size_(0), context_values_(0), CompilerPass() {}
ContextPromotionPass::~ContextPromotionPass() {
if (context_values_) {
@ -70,7 +72,7 @@ int ContextPromotionPass::Run(HIRBuilder* builder) {
// Promote loads to values.
// Process each block independently, for now.
Block* block = builder->first_block();
auto block = builder->first_block();
while (block) {
PromoteBlock(block);
block = block->next;
@ -121,7 +123,7 @@ void ContextPromotionPass::PromoteBlock(Block* block) {
void ContextPromotionPass::RemoveDeadStoresBlock(Block* block) {
// TODO(benvanik): use a bitvector.
// To avoid clearing the structure, we use a token.
Value* token = (Value*)block;
auto token = (Value*)block;
// Walk backwards and mark offsets that are written to.
// If the offset was written to earlier, ignore the store.
@ -141,3 +143,7 @@ void ContextPromotionPass::RemoveDeadStoresBlock(Block* block) {
i = prev;
}
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -12,14 +12,12 @@
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class ContextPromotionPass : public CompilerPass {
public:
public:
ContextPromotionPass();
virtual ~ContextPromotionPass();
@ -27,19 +25,17 @@ public:
virtual int Run(hir::HIRBuilder* builder);
private:
private:
void PromoteBlock(hir::Block* block);
void RemoveDeadStoresBlock(hir::Block* block);
private:
private:
size_t context_values_size_;
hir::Value** context_values_;
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_CONTEXT_PROMOTION_PASS_H_

View File

@ -13,21 +13,19 @@
#include <alloy/compiler/compiler.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
using namespace alloy::frontend;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using namespace alloy::runtime;
using alloy::hir::Edge;
using alloy::hir::HIRBuilder;
ControlFlowAnalysisPass::ControlFlowAnalysisPass() :
CompilerPass() {
}
ControlFlowAnalysisPass::ControlFlowAnalysisPass() : CompilerPass() {}
ControlFlowAnalysisPass::~ControlFlowAnalysisPass() {
}
ControlFlowAnalysisPass::~ControlFlowAnalysisPass() {}
int ControlFlowAnalysisPass::Run(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -46,7 +44,7 @@ int ControlFlowAnalysisPass::Run(HIRBuilder* builder) {
auto label = instr->src1.label;
builder->AddEdge(block, label->block, Edge::UNCONDITIONAL);
} else if (instr->opcode == &OPCODE_BRANCH_TRUE_info ||
instr->opcode == &OPCODE_BRANCH_FALSE_info) {
instr->opcode == &OPCODE_BRANCH_FALSE_info) {
auto label = instr->src2.label;
builder->AddEdge(block, label->block, 0);
}
@ -67,3 +65,7 @@ int ControlFlowAnalysisPass::Run(HIRBuilder* builder) {
return 0;
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -12,26 +12,22 @@
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class ControlFlowAnalysisPass : public CompilerPass {
public:
public:
ControlFlowAnalysisPass();
virtual ~ControlFlowAnalysisPass();
virtual int Run(hir::HIRBuilder* builder);
private:
private:
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_CONTROL_FLOW_ANALYSIS_PASS_H_

View File

@ -19,21 +19,20 @@
#include <llvm/ADT/BitVector.h>
#pragma warning(pop)
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
using namespace alloy::frontend;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using namespace alloy::runtime;
using alloy::hir::HIRBuilder;
using alloy::hir::OpcodeSignatureType;
using alloy::hir::Value;
DataFlowAnalysisPass::DataFlowAnalysisPass() :
CompilerPass() {
}
DataFlowAnalysisPass::DataFlowAnalysisPass() : CompilerPass() {}
DataFlowAnalysisPass::~DataFlowAnalysisPass() {
}
DataFlowAnalysisPass::~DataFlowAnalysisPass() {}
int DataFlowAnalysisPass::Run(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -66,15 +65,15 @@ void DataFlowAnalysisPass::AnalyzeFlow(HIRBuilder* builder,
// Stash for value map. We may want to maintain this during building.
auto arena = builder->arena();
Value** value_map = (Value**)arena->Alloc(
sizeof(Value*) * max_value_estimate);
Value** value_map =
(Value**)arena->Alloc(sizeof(Value*) * max_value_estimate);
// Allocate incoming bitvectors for use by blocks. We don't need outgoing
// because they are only used during the block iteration.
// Mapped by block ordinal.
// TODO(benvanik): cache this list, grow as needed, etc.
auto incoming_bitvectors = (llvm::BitVector**)arena->Alloc(
sizeof(llvm::BitVector*) * block_count);
auto incoming_bitvectors =
(llvm::BitVector**)arena->Alloc(sizeof(llvm::BitVector*) * block_count);
for (auto n = 0u; n < block_count; n++) {
incoming_bitvectors[n] = new llvm::BitVector(max_value_estimate);
}
@ -90,10 +89,10 @@ void DataFlowAnalysisPass::AnalyzeFlow(HIRBuilder* builder,
auto instr = block->instr_head;
while (instr) {
uint32_t signature = instr->opcode->signature;
#define SET_INCOMING_VALUE(v) \
if (v->def && v->def->block != block) { \
incoming_values.set(v->ordinal); \
} \
#define SET_INCOMING_VALUE(v) \
if (v->def && v->def->block != block) { \
incoming_values.set(v->ordinal); \
} \
XEASSERT(v->ordinal < max_value_estimate); \
value_map[v->ordinal] = v;
if (GET_OPCODE_SIG_TYPE_SRC1(signature) == OPCODE_SIG_TYPE_V) {
@ -201,3 +200,7 @@ void DataFlowAnalysisPass::AnalyzeFlow(HIRBuilder* builder,
delete incoming_bitvectors[n];
}
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -9,18 +9,20 @@
#include <alloy/compiler/passes/dead_code_elimination_pass.h>
using namespace alloy;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using alloy::hir::HIRBuilder;
using alloy::hir::Instr;
using alloy::hir::Value;
DeadCodeEliminationPass::DeadCodeEliminationPass() :
CompilerPass() {
}
DeadCodeEliminationPass::DeadCodeEliminationPass() : CompilerPass() {}
DeadCodeEliminationPass::~DeadCodeEliminationPass() {
}
DeadCodeEliminationPass::~DeadCodeEliminationPass() {}
int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -63,7 +65,7 @@ int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
bool any_instr_removed = false;
bool any_locals_removed = false;
Block* block = builder->first_block();
auto block = builder->first_block();
while (block) {
// Walk instructions in reverse.
Instr* i = block->instr_tail;
@ -71,8 +73,8 @@ int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
auto prev = i->prev;
auto opcode = i->opcode;
if (!(opcode->flags & OPCODE_FLAG_VOLATILE) &&
i->dest && !i->dest->use_head) {
if (!(opcode->flags & OPCODE_FLAG_VOLATILE) && i->dest &&
!i->dest->use_head) {
// Has no uses and is not volatile. This instruction can die!
MakeNopRecursive(i);
any_instr_removed = true;
@ -110,7 +112,7 @@ int DeadCodeEliminationPass::Run(HIRBuilder* builder) {
// Remove all nops.
if (any_instr_removed) {
Block* block = builder->first_block();
auto block = builder->first_block();
while (block) {
Instr* i = block->instr_head;
while (i) {
@ -148,19 +150,19 @@ void DeadCodeEliminationPass::MakeNopRecursive(Instr* i) {
i->dest->def = NULL;
i->dest = NULL;
#define MAKE_NOP_SRC(n) \
if (i->src##n##_use) { \
Value::Use* use = i->src##n##_use; \
Value* value = i->src##n##.value; \
i->src##n##_use = NULL; \
i->src##n##.value = NULL; \
value->RemoveUse(use); \
if (!value->use_head) { \
#define MAKE_NOP_SRC(n) \
if (i->src##n##_use) { \
Value::Use* use = i->src##n##_use; \
Value* value = i->src##n##.value; \
i->src##n##_use = NULL; \
i->src##n##.value = NULL; \
value->RemoveUse(use); \
if (!value->use_head) { \
/* Value is now unused, so recursively kill it. */ \
if (value->def && value->def != i) { \
MakeNopRecursive(value->def); \
} \
} \
if (value->def && value->def != i) { \
MakeNopRecursive(value->def); \
} \
} \
}
MAKE_NOP_SRC(1);
MAKE_NOP_SRC(2);
@ -209,3 +211,7 @@ bool DeadCodeEliminationPass::CheckLocalUse(Instr* i) {
return false;
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -13,21 +13,18 @@
#include <alloy/compiler/compiler.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
using namespace alloy::frontend;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using namespace alloy::runtime;
using alloy::hir::HIRBuilder;
FinalizationPass::FinalizationPass() :
CompilerPass() {
}
FinalizationPass::FinalizationPass() : CompilerPass() {}
FinalizationPass::~FinalizationPass() {
}
FinalizationPass::~FinalizationPass() {}
int FinalizationPass::Run(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -70,3 +67,7 @@ int FinalizationPass::Run(HIRBuilder* builder) {
return 0;
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -12,26 +12,22 @@
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class FinalizationPass : public CompilerPass {
public:
public:
FinalizationPass();
virtual ~FinalizationPass();
virtual int Run(hir::HIRBuilder* builder);
private:
private:
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_FINALIZATION_PASS_H_

View File

@ -11,20 +11,25 @@
#include <algorithm>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using alloy::backend::MachineInfo;
using alloy::hir::HIRBuilder;
using alloy::hir::Instr;
using alloy::hir::OpcodeSignatureType;
using alloy::hir::RegAssignment;
using alloy::hir::TypeName;
using alloy::hir::Value;
#define ASSERT_NO_CYCLES 0
RegisterAllocationPass::RegisterAllocationPass(
const MachineInfo* machine_info) :
machine_info_(machine_info),
CompilerPass() {
RegisterAllocationPass::RegisterAllocationPass(const MachineInfo* machine_info)
: machine_info_(machine_info), CompilerPass() {
// Initialize register sets.
// TODO(benvanik): rewrite in a way that makes sense - this is terrible.
auto mi_sets = machine_info->register_sets;
@ -88,7 +93,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
instr = block->instr_head;
while (instr) {
const OpcodeInfo* info = instr->opcode;
const auto info = instr->opcode;
uint32_t signature = info->signature;
// Update the register use heaps.
@ -101,7 +106,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// reuse it.
// NOTE: these checks require that the usage list be sorted!
bool has_preferred_reg = false;
RegAssignment preferred_reg = { 0 };
RegAssignment preferred_reg = {0};
if (GET_OPCODE_SIG_TYPE_SRC1(signature) == OPCODE_SIG_TYPE_V &&
!instr->src1.value->IsConstant()) {
if (!instr->src1_use->next) {
@ -117,7 +122,8 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// Must not have been set already.
XEASSERTNULL(instr->dest->reg.set);
// Sort the usage list. We depend on this in future uses of this variable.
// Sort the usage list. We depend on this in future uses of this
// variable.
SortUsageList(instr->dest);
// If we have a preferred register, use that.
@ -181,7 +187,6 @@ void RegisterAllocationPass::DumpUsage(const char* name) {
#endif
}
void RegisterAllocationPass::PrepareBlockState() {
for (size_t i = 0; i < XECOUNT(usage_sets_.all_sets); ++i) {
auto usage_set = usage_sets_.all_sets[i];
@ -249,9 +254,8 @@ bool RegisterAllocationPass::IsRegInUse(const RegAssignment& reg) {
return !usage_set->availability.test(reg.index);
}
RegisterAllocationPass::RegisterSetUsage*
RegisterAllocationPass::MarkRegUsed(const RegAssignment& reg,
Value* value, Value::Use* use) {
RegisterAllocationPass::RegisterSetUsage* RegisterAllocationPass::MarkRegUsed(
const RegAssignment& reg, Value* value, Value::Use* use) {
auto usage_set = RegisterSetForValue(value);
usage_set->availability.set(reg.index, false);
usage_set->upcoming_uses.emplace_back(value, use);
@ -298,7 +302,8 @@ bool RegisterAllocationPass::TryAllocateRegister(Value* value) {
// Find the first free register, if any.
// We have to ensure it's a valid one (in our count).
unsigned long first_unused = 0;
bool all_used = _BitScanForward(&first_unused, usage_set->availability.to_ulong()) == 0;
bool all_used =
_BitScanForward(&first_unused, usage_set->availability.to_ulong()) == 0;
if (!all_used && first_unused < usage_set->count) {
// Available! Use it!.
value->reg.set = usage_set->set;
@ -311,8 +316,8 @@ bool RegisterAllocationPass::TryAllocateRegister(Value* value) {
return false;
}
bool RegisterAllocationPass::SpillOneRegister(
HIRBuilder* builder, TypeName required_type) {
bool RegisterAllocationPass::SpillOneRegister(HIRBuilder* builder,
TypeName required_type) {
// Get the set that we will be picking from.
RegisterSetUsage* usage_set;
if (required_type <= INT64_TYPE) {
@ -326,17 +331,17 @@ bool RegisterAllocationPass::SpillOneRegister(
DumpUsage("SpillOneRegister (pre)");
// Pick the one with the furthest next use.
XEASSERT(!usage_set->upcoming_uses.empty());
auto furthest_usage = std::max_element(
usage_set->upcoming_uses.begin(), usage_set->upcoming_uses.end(),
RegisterUsage::Comparer());
Value* spill_value = furthest_usage->value;
auto furthest_usage = std::max_element(usage_set->upcoming_uses.begin(),
usage_set->upcoming_uses.end(),
RegisterUsage::Comparer());
auto spill_value = furthest_usage->value;
Value::Use* prev_use = furthest_usage->use->prev;
Value::Use* next_use = furthest_usage->use;
XEASSERTNOTNULL(next_use);
usage_set->upcoming_uses.erase(furthest_usage);
DumpUsage("SpillOneRegister (post)");
const auto reg = spill_value->reg;
// We know the spill_value use list is sorted, so we can cut it right now.
// This makes it easier down below.
auto new_head_use = next_use;
@ -367,7 +372,8 @@ bool RegisterAllocationPass::SpillOneRegister(
spill_value->last_use = spill_store;
} else if (prev_use) {
// We insert the store immediately before the previous use.
// If we were smarter we could then re-run allocation and reuse the register
// If we were smarter we could then re-run allocation and reuse the
// register
// once dropped.
spill_store->MoveBefore(prev_use->instr);
@ -396,7 +402,7 @@ bool RegisterAllocationPass::SpillOneRegister(
auto new_value = builder->LoadLocal(spill_value->local_slot);
auto spill_load = builder->last_instr();
spill_load->MoveBefore(next_use->instr);
// Note: implicit first use added.
// Note: implicit first use added.
#if ASSERT_NO_CYCLES
builder->AssertNoCycles();
@ -448,8 +454,7 @@ bool RegisterAllocationPass::SpillOneRegister(
}
RegisterAllocationPass::RegisterSetUsage*
RegisterAllocationPass::RegisterSetForValue(
const Value* value) {
RegisterAllocationPass::RegisterSetForValue(const Value* value) {
if (value->type <= INT64_TYPE) {
return usage_sets_.int_set;
} else if (value->type <= FLOAT64_TYPE) {
@ -498,16 +503,24 @@ void RegisterAllocationPass::SortUsageList(Value* value) {
Value::Use* e = nullptr;
if (psize == 0) {
// p is empty; e must come from q
e = q; q = q->next; qsize--;
e = q;
q = q->next;
qsize--;
} else if (qsize == 0 || !q) {
// q is empty; e must come from p
e = p; p = p->next; psize--;
e = p;
p = p->next;
psize--;
} else if (CompareValueUse(p, q) <= 0) {
// First element of p is lower (or same); e must come from p
e = p; p = p->next; psize--;
e = p;
p = p->next;
psize--;
} else {
// First element of q is lower; e must come from q
e = q; q = q->next; qsize--;
e = q;
q = q->next;
qsize--;
}
// add the next element to the merged list
if (tail) {
@ -537,3 +550,7 @@ void RegisterAllocationPass::SortUsageList(Value* value) {
value->use_head = head;
value->last_use = tail->instr;
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -17,20 +17,18 @@
#include <alloy/backend/machine_info.h>
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class RegisterAllocationPass : public CompilerPass {
public:
public:
RegisterAllocationPass(const backend::MachineInfo* machine_info);
virtual ~RegisterAllocationPass();
virtual int Run(hir::HIRBuilder* builder);
private:
private:
// TODO(benvanik): rewrite all this set shit -- too much indirection, the
// complexity is not needed.
struct RegisterUsage {
@ -70,7 +68,7 @@ private:
void SortUsageList(hir::Value* value);
private:
private:
const backend::MachineInfo* machine_info_;
struct {
RegisterSetUsage* int_set = nullptr;
@ -80,10 +78,8 @@ private:
} usage_sets_;
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_REGISTER_ALLOCATION_PASS_H_

View File

@ -9,18 +9,20 @@
#include <alloy/compiler/passes/simplification_pass.h>
using namespace alloy;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using alloy::hir::HIRBuilder;
using alloy::hir::Instr;
using alloy::hir::Value;
SimplificationPass::SimplificationPass() :
CompilerPass() {
}
SimplificationPass::SimplificationPass() : CompilerPass() {}
SimplificationPass::~SimplificationPass() {
}
SimplificationPass::~SimplificationPass() {}
int SimplificationPass::Run(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -65,7 +67,7 @@ void SimplificationPass::CheckTruncate(Instr* i) {
// Walk backward up src's chain looking for an extend. We may have
// assigns, so skip those.
auto src = i->src1.value;
Instr* def = src->def;
auto def = src->def;
while (def && def->opcode == &OPCODE_ASSIGN_info) {
// Skip asignments.
def = def->src1.value->def;
@ -93,7 +95,7 @@ void SimplificationPass::CheckByteSwap(Instr* i) {
// Walk backward up src's chain looking for a byte swap. We may have
// assigns, so skip those.
auto src = i->src1.value;
Instr* def = src->def;
auto def = src->def;
while (def && def->opcode == &OPCODE_ASSIGN_info) {
// Skip asignments.
def = def->src1.value->def;
@ -147,11 +149,11 @@ void SimplificationPass::SimplifyAssignments(HIRBuilder* builder) {
}
Value* SimplificationPass::CheckValue(Value* value) {
Instr* def = value->def;
auto def = value->def;
if (def && def->opcode == &OPCODE_ASSIGN_info) {
// Value comes from an assignment - recursively find if it comes from
// another assignment. It probably doesn't, if we already replaced it.
Value* replacement = def->src1.value;
auto replacement = def->src1.value;
while (true) {
def = replacement->def;
if (!def || def->opcode != &OPCODE_ASSIGN_info) {
@ -163,3 +165,7 @@ Value* SimplificationPass::CheckValue(Value* value) {
}
return value;
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -12,20 +12,18 @@
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class SimplificationPass : public CompilerPass {
public:
public:
SimplificationPass();
virtual ~SimplificationPass();
virtual int Run(hir::HIRBuilder* builder);
private:
private:
void EliminateConversions(hir::HIRBuilder* builder);
void CheckTruncate(hir::Instr* i);
void CheckByteSwap(hir::Instr* i);
@ -34,10 +32,8 @@ private:
hir::Value* CheckValue(hir::Value* value);
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_SIMPLIFICATION_PASS_H_

View File

@ -13,21 +13,22 @@
#include <alloy/compiler/compiler.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
using namespace alloy::frontend;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using namespace alloy::runtime;
using alloy::hir::Block;
using alloy::hir::HIRBuilder;
using alloy::hir::Instr;
using alloy::hir::OpcodeSignatureType;
using alloy::hir::Value;
ValidationPass::ValidationPass() :
CompilerPass() {
}
ValidationPass::ValidationPass() : CompilerPass() {}
ValidationPass::~ValidationPass() {
}
ValidationPass::~ValidationPass() {}
int ValidationPass::Run(HIRBuilder* builder) {
SCOPE_profile_cpu_f("alloy");
@ -90,7 +91,7 @@ int ValidationPass::ValidateInstruction(Block* block, Instr* instr) {
}
int ValidationPass::ValidateValue(Block* block, Instr* instr, Value* value) {
//if (value->def) {
// if (value->def) {
// auto def = value->def;
// XEASSERT(def->block == block);
// if (def->block != block) {
@ -99,3 +100,7 @@ int ValidationPass::ValidateValue(Block* block, Instr* instr, Value* value) {
//}
return 0;
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -12,28 +12,24 @@
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class ValidationPass : public CompilerPass {
public:
public:
ValidationPass();
virtual ~ValidationPass();
virtual int Run(hir::HIRBuilder* builder);
private:
private:
int ValidateInstruction(hir::Block* block, hir::Instr* instr);
int ValidateValue(hir::Block* block, hir::Instr* instr, hir::Value* value);
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_VALIDATION_PASS_H_

View File

@ -19,21 +19,20 @@
#include <llvm/ADT/BitVector.h>
#pragma warning(pop)
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::compiler;
using namespace alloy::compiler::passes;
using namespace alloy::frontend;
namespace alloy {
namespace compiler {
namespace passes {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using namespace alloy::runtime;
using alloy::hir::HIRBuilder;
using alloy::hir::OpcodeInfo;
using alloy::hir::Value;
ValueReductionPass::ValueReductionPass() :
CompilerPass() {
}
ValueReductionPass::ValueReductionPass() : CompilerPass() {}
ValueReductionPass::~ValueReductionPass() {
}
ValueReductionPass::~ValueReductionPass() {}
void ValueReductionPass::ComputeLastUse(Value* value) {
// TODO(benvanik): compute during construction?
@ -137,3 +136,7 @@ int ValueReductionPass::Run(HIRBuilder* builder) {
return 0;
}
} // namespace passes
} // namespace compiler
} // namespace alloy

View File

@ -12,27 +12,23 @@
#include <alloy/compiler/compiler_pass.h>
namespace alloy {
namespace compiler {
namespace passes {
class ValueReductionPass : public CompilerPass {
public:
public:
ValueReductionPass();
virtual ~ValueReductionPass();
virtual int Run(hir::HIRBuilder* builder);
private:
private:
void ComputeLastUse(hir::Value* value);
};
} // namespace passes
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_PASSES_VALUE_REDUCTION_PASS_H_

View File

@ -13,18 +13,16 @@
#include <alloy/tracing/tracing.h>
#include <alloy/tracing/event_type.h>
namespace alloy {
namespace compiler {
const uint32_t ALLOY_COMPILER = alloy::tracing::EventType::ALLOY_COMPILER;
class EventType {
public:
public:
enum {
ALLOY_COMPILER_INIT = ALLOY_COMPILER | (1),
ALLOY_COMPILER_DEINIT = ALLOY_COMPILER | (2),
ALLOY_COMPILER_INIT = ALLOY_COMPILER | (1),
ALLOY_COMPILER_DEINIT = ALLOY_COMPILER | (2),
};
typedef struct Init_s {
@ -35,9 +33,7 @@ public:
} Deinit;
};
} // namespace compiler
} // namespace alloy
#endif // ALLOY_COMPILER_TRACING_H_

View File

@ -17,61 +17,76 @@
#include <alloy/delegate.h>
#include <alloy/string_buffer.h>
namespace alloy {
typedef struct XECACHEALIGN vec128_s {
union {
struct {
float x;
float y;
float z;
float w;
float x;
float y;
float z;
float w;
};
struct {
uint32_t ix;
uint32_t iy;
uint32_t iz;
uint32_t iw;
uint32_t ix;
uint32_t iy;
uint32_t iz;
uint32_t iw;
};
float f4[4];
uint32_t i4[4];
uint16_t s8[8];
uint8_t b16[16];
float f4[4];
uint32_t i4[4];
uint16_t s8[8];
uint8_t b16[16];
struct {
uint64_t low;
uint64_t high;
uint64_t low;
uint64_t high;
};
};
bool operator== (const vec128_s& b) const {
bool operator==(const vec128_s& b) const {
return low == b.low && high == b.high;
}
} vec128_t;
XEFORCEINLINE vec128_t vec128i(uint32_t x, uint32_t y, uint32_t z, uint32_t w) {
vec128_t v;
v.i4[0] = x; v.i4[1] = y; v.i4[2] = z; v.i4[3] = w;
v.i4[0] = x;
v.i4[1] = y;
v.i4[2] = z;
v.i4[3] = w;
return v;
}
XEFORCEINLINE vec128_t vec128f(float x, float y, float z, float w) {
vec128_t v;
v.f4[0] = x; v.f4[1] = y; v.f4[2] = z; v.f4[3] = w;
v.f4[0] = x;
v.f4[1] = y;
v.f4[2] = z;
v.f4[3] = w;
return v;
}
XEFORCEINLINE vec128_t vec128b(
uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3,
uint8_t y0, uint8_t y1, uint8_t y2, uint8_t y3,
uint8_t z0, uint8_t z1, uint8_t z2, uint8_t z3,
uint8_t w0, uint8_t w1, uint8_t w2, uint8_t w3) {
XEFORCEINLINE vec128_t vec128b(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3,
uint8_t y0, uint8_t y1, uint8_t y2, uint8_t y3,
uint8_t z0, uint8_t z1, uint8_t z2, uint8_t z3,
uint8_t w0, uint8_t w1, uint8_t w2, uint8_t w3) {
vec128_t v;
v.b16[0] = x3; v.b16[1] = x2; v.b16[2] = x1; v.b16[3] = x0;
v.b16[4] = y3; v.b16[5] = y2; v.b16[6] = y1; v.b16[7] = y0;
v.b16[8] = z3; v.b16[9] = z2; v.b16[10] = z1; v.b16[11] = z0;
v.b16[12] = w3; v.b16[13] = w2; v.b16[14] = w1; v.b16[15] = w0;
v.b16[0] = x3;
v.b16[1] = x2;
v.b16[2] = x1;
v.b16[3] = x0;
v.b16[4] = y3;
v.b16[5] = y2;
v.b16[6] = y1;
v.b16[7] = y0;
v.b16[8] = z3;
v.b16[9] = z2;
v.b16[10] = z1;
v.b16[11] = z0;
v.b16[12] = w3;
v.b16[13] = w2;
v.b16[14] = w1;
v.b16[15] = w0;
return v;
}
} // namespace alloy
#endif // ALLOY_CORE_H_

View File

@ -16,15 +16,13 @@
#include <alloy/core.h>
namespace alloy {
// TODO(benvanik): go lockfree, and don't hold the lock while emitting.
template <typename T>
class Delegate {
public:
public:
typedef std::function<void(T&)> listener_t;
void AddListener(listener_t const& listener) {
@ -49,18 +47,16 @@ public:
void operator()(T& e) {
std::lock_guard<std::mutex> guard(lock_);
for (auto &listener : listeners_) {
for (auto& listener : listeners_) {
listener(e);
}
}
private:
private:
std::mutex lock_;
std::vector<listener_t> listeners_;
};
} // namespace alloy
#endif // ALLOY_DELEGATE_H_

View File

@ -9,14 +9,13 @@
#include <alloy/frontend/context_info.h>
using namespace alloy;
using namespace alloy::frontend;
namespace alloy {
namespace frontend {
ContextInfo::ContextInfo(size_t size, uintptr_t thread_state_offset)
: size_(size), thread_state_offset_(thread_state_offset) {}
ContextInfo::ContextInfo(size_t size, uintptr_t thread_state_offset) :
size_(size),
thread_state_offset_(thread_state_offset) {
}
ContextInfo::~ContextInfo() {}
ContextInfo::~ContextInfo() {
}
} // namespace frontend
} // namespace alloy

View File

@ -12,13 +12,11 @@
#include <alloy/core.h>
namespace alloy {
namespace frontend {
class ContextInfo {
public:
public:
ContextInfo(size_t size, uintptr_t thread_state_offset);
~ContextInfo();
@ -26,14 +24,12 @@ public:
uintptr_t thread_state_offset() const { return thread_state_offset_; }
private:
private:
size_t size_;
uintptr_t thread_state_offset_;
};
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_CONTEXT_INFO_H_

View File

@ -12,23 +12,17 @@
#include <alloy/frontend/tracing.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::frontend;
using namespace alloy::runtime;
namespace alloy {
namespace frontend {
Frontend::Frontend(runtime::Runtime* runtime)
: runtime_(runtime), context_info_(0) {}
Frontend::Frontend(Runtime* runtime) :
runtime_(runtime), context_info_(0) {
}
Frontend::~Frontend() { delete context_info_; }
Frontend::~Frontend() {
delete context_info_;
}
Memory* Frontend::memory() const { return runtime_->memory(); }
Memory* Frontend::memory() const {
return runtime_->memory();
}
int Frontend::Initialize() { return 0; }
int Frontend::Initialize() {
return 0;
}
} // namespace frontend
} // namespace alloy

View File

@ -16,17 +16,17 @@
#include <alloy/runtime/function.h>
#include <alloy/runtime/symbol_info.h>
namespace alloy { namespace runtime {
class Runtime;
} }
namespace alloy {
namespace runtime {
class Runtime;
} // namespace runtime
} // namespace alloy
namespace alloy {
namespace frontend {
class Frontend {
public:
public:
Frontend(runtime::Runtime* runtime);
virtual ~Frontend();
@ -36,20 +36,17 @@ public:
virtual int Initialize();
virtual int DeclareFunction(
runtime::FunctionInfo* symbol_info) = 0;
virtual int DefineFunction(
runtime::FunctionInfo* symbol_info, uint32_t debug_info_flags,
runtime::Function** out_function) = 0;
virtual int DeclareFunction(runtime::FunctionInfo* symbol_info) = 0;
virtual int DefineFunction(runtime::FunctionInfo* symbol_info,
uint32_t debug_info_flags,
runtime::Function** out_function) = 0;
protected:
protected:
runtime::Runtime* runtime_;
ContextInfo* context_info_;
};
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_FRONTEND_H_

View File

@ -9,19 +9,11 @@
#include <alloy/frontend/ppc/ppc_context.h>
using namespace alloy;
using namespace alloy::frontend;
using namespace alloy::frontend::ppc;
namespace {
uint64_t ParseInt64(const char* value) {
return xestrtoulla(value, NULL, 0);
}
}
namespace alloy {
namespace frontend {
namespace ppc {
uint64_t ParseInt64(const char* value) { return xestrtoulla(value, NULL, 0); }
void PPCContext::SetRegFromString(const char* name, const char* value) {
int n;
@ -32,9 +24,8 @@ void PPCContext::SetRegFromString(const char* name, const char* value) {
}
}
bool PPCContext::CompareRegWithString(
const char* name, const char* value,
char* out_value, size_t out_value_size) {
bool PPCContext::CompareRegWithString(const char* name, const char* value,
char* out_value, size_t out_value_size) {
int n;
if (sscanf(name, "r%d", &n) == 1) {
uint64_t expected = ParseInt64(value);
@ -48,3 +39,7 @@ bool PPCContext::CompareRegWithString(
return false;
}
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -9,10 +9,6 @@
#include <alloy/frontend/ppc/ppc_disasm.h>
using namespace alloy::frontend::ppc;
namespace alloy {
namespace frontend {
namespace ppc {
@ -26,221 +22,210 @@ void Disasm__(InstrData& i, StringBuffer* str) {
}
void Disasm_X_FRT_FRB(InstrData& i, StringBuffer* str) {
str->Append("%*s%s f%d, f%d", i.X.Rc ? -7 : -8, i.type->name, i.X.Rc ? "." : "",
i.X.RT, i.X.RB);
str->Append("%*s%s f%d, f%d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RT, i.X.RB);
}
void Disasm_A_FRT_FRB(InstrData& i, StringBuffer* str) {
str->Append("%*s%s f%d, f%d", i.A.Rc ? -7 : -8, i.type->name, i.A.Rc ? "." : "",
i.A.FRT, i.A.FRB);
str->Append("%*s%s f%d, f%d", i.A.Rc ? -7 : -8, i.type->name,
i.A.Rc ? "." : "", i.A.FRT, i.A.FRB);
}
void Disasm_A_FRT_FRA_FRB(InstrData& i, StringBuffer* str) {
str->Append("%*s%s f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name, i.A.Rc ? "." : "",
i.A.FRT, i.A.FRA, i.A.FRB);
str->Append("%*s%s f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name,
i.A.Rc ? "." : "", i.A.FRT, i.A.FRA, i.A.FRB);
}
void Disasm_A_FRT_FRA_FRB_FRC(InstrData& i, StringBuffer* str) {
str->Append("%*s%s f%d, f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name, i.A.Rc ? "." : "",
i.A.FRT, i.A.FRA, i.A.FRB, i.A.FRC);
str->Append("%*s%s f%d, f%d, f%d, f%d", i.A.Rc ? -7 : -8, i.type->name,
i.A.Rc ? "." : "", i.A.FRT, i.A.FRA, i.A.FRB, i.A.FRC);
}
void Disasm_X_RT_RA_RB(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, r%d, %d", i.type->name,
i.X.RT, i.X.RA, i.X.RB);
str->Append("%-8s r%d, r%d, %d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
}
void Disasm_X_RT_RA0_RB(InstrData& i, StringBuffer* str) {
if (i.X.RA) {
str->Append("%-8s r%d, r%d, %d", i.type->name,
i.X.RT, i.X.RA, i.X.RB);
str->Append("%-8s r%d, r%d, %d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} else {
str->Append("%-8s r%d, 0, %d", i.type->name,
i.X.RT, i.X.RB);
str->Append("%-8s r%d, 0, %d", i.type->name, i.X.RT, i.X.RB);
}
}
void Disasm_X_FRT_RA_RB(InstrData& i, StringBuffer* str) {
str->Append("%-8s f%d, r%d, %d", i.type->name,
i.X.RT, i.X.RA, i.X.RB);
str->Append("%-8s f%d, r%d, %d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
}
void Disasm_X_FRT_RA0_RB(InstrData& i, StringBuffer* str) {
if (i.X.RA) {
str->Append("%-8s f%d, r%d, %d", i.type->name,
i.X.RT, i.X.RA, i.X.RB);
str->Append("%-8s f%d, r%d, %d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} else {
str->Append("%-8s f%d, 0, %d", i.type->name,
i.X.RT, i.X.RB);
str->Append("%-8s f%d, 0, %d", i.type->name, i.X.RT, i.X.RB);
}
}
void Disasm_D_RT_RA_I(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, r%d, %d", i.type->name,
i.D.RT, i.D.RA, (int32_t)(int16_t)XEEXTS16(i.D.DS));
str->Append("%-8s r%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS));
}
void Disasm_D_RT_RA0_I(InstrData& i, StringBuffer* str) {
if (i.D.RA) {
str->Append("%-8s r%d, r%d, %d", i.type->name,
i.D.RT, i.D.RA, (int32_t)(int16_t)XEEXTS16(i.D.DS));
str->Append("%-8s r%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS));
} else {
str->Append("%-8s r%d, 0, %d", i.type->name,
i.D.RT, (int32_t)(int16_t)XEEXTS16(i.D.DS));
str->Append("%-8s r%d, 0, %d", i.type->name, i.D.RT,
(int32_t)(int16_t)XEEXTS16(i.D.DS));
}
}
void Disasm_D_FRT_RA_I(InstrData& i, StringBuffer* str) {
str->Append("%-8s f%d, r%d, %d", i.type->name,
i.D.RT, i.D.RA, (int32_t)(int16_t)XEEXTS16(i.D.DS));
str->Append("%-8s f%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS));
}
void Disasm_D_FRT_RA0_I(InstrData& i, StringBuffer* str) {
if (i.D.RA) {
str->Append("%-8s f%d, r%d, %d", i.type->name,
i.D.RT, i.D.RA, (int32_t)(int16_t)XEEXTS16(i.D.DS));
str->Append("%-8s f%d, r%d, %d", i.type->name, i.D.RT, i.D.RA,
(int32_t)(int16_t)XEEXTS16(i.D.DS));
} else {
str->Append("%-8s f%d, 0, %d", i.type->name,
i.D.RT, (int32_t)(int16_t)XEEXTS16(i.D.DS));
str->Append("%-8s f%d, 0, %d", i.type->name, i.D.RT,
(int32_t)(int16_t)XEEXTS16(i.D.DS));
}
}
void Disasm_DS_RT_RA_I(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, r%d, %d", i.type->name,
i.DS.RT, i.DS.RA, (int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
str->Append("%-8s r%d, r%d, %d", i.type->name, i.DS.RT, i.DS.RA,
(int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
}
void Disasm_DS_RT_RA0_I(InstrData& i, StringBuffer* str) {
if (i.DS.RA) {
str->Append("%-8s r%d, r%d, %d", i.type->name,
i.DS.RT, i.DS.RA, (int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
str->Append("%-8s r%d, r%d, %d", i.type->name, i.DS.RT, i.DS.RA,
(int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
} else {
str->Append("%-8s r%d, 0, %d", i.type->name,
i.DS.RT, (int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
str->Append("%-8s r%d, 0, %d", i.type->name, i.DS.RT,
(int32_t)(int16_t)XEEXTS16(i.DS.DS << 2));
}
}
void Disasm_D_RA(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d", i.type->name,
i.D.RA);
str->Append("%-8s r%d", i.type->name, i.D.RA);
}
void Disasm_X_RA_RB(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, r%d", i.type->name,
i.X.RA, i.X.RB);
str->Append("%-8s r%d, r%d", i.type->name, i.X.RA, i.X.RB);
}
void Disasm_XO_RT_RA_RB(InstrData& i, StringBuffer* str) {
str->Append("%*s%s%s r%d, r%d, r%d", i.XO.Rc ? -7 : -8, i.type->name,
i.XO.OE ? "o" : "", i.XO.Rc ? "." : "",
i.XO.RT, i.XO.RA, i.XO.RB);
i.XO.OE ? "o" : "", i.XO.Rc ? "." : "", i.XO.RT, i.XO.RA,
i.XO.RB);
}
void Disasm_XO_RT_RA(InstrData& i, StringBuffer* str) {
str->Append("%*s%s%s r%d, r%d", i.XO.Rc ? -7 : -8, i.type->name,
i.XO.OE ? "o" : "", i.XO.Rc ? "." : "",
i.XO.RT, i.XO.RA);
i.XO.OE ? "o" : "", i.XO.Rc ? "." : "", i.XO.RT, i.XO.RA);
}
void Disasm_X_RA_RT_RB(InstrData& i, StringBuffer* str) {
str->Append("%*s%s r%d, r%d, r%d", i.X.Rc ? -7 : -8, i.type->name, i.X.Rc ? "." : "",
i.X.RA, i.X.RT, i.X.RB);
str->Append("%*s%s r%d, r%d, r%d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RA, i.X.RT, i.X.RB);
}
void Disasm_D_RA_RT_I(InstrData& i, StringBuffer* str) {
str->Append("%-7s. r%d, r%d, %.4Xh", i.type->name,
i.D.RA, i.D.RT, i.D.DS);
str->Append("%-7s. r%d, r%d, %.4Xh", i.type->name, i.D.RA, i.D.RT, i.D.DS);
}
void Disasm_X_RA_RT(InstrData& i, StringBuffer* str) {
str->Append("%*s%s r%d, r%d", i.X.Rc ? -7 : -8, i.type->name, i.X.Rc ? "." : "",
i.X.RA, i.X.RT);
str->Append("%*s%s r%d, r%d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RA, i.X.RT);
}
#define OP(x) ((((uint32_t)(x)) & 0x3f) << 26)
#define VX128(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x3d0))
#define VX128_1(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x7f3))
#define VX128_2(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x210))
#define VX128_3(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x7f0))
#define VX128_4(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x730))
#define VX128_5(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x10))
#define VX128_P(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x630))
#define OP(x) ((((uint32_t)(x)) & 0x3f) << 26)
#define VX128(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x3d0))
#define VX128_1(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x7f3))
#define VX128_2(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x210))
#define VX128_3(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x7f0))
#define VX128_4(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x730))
#define VX128_5(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x10))
#define VX128_P(op, xop) (OP(op) | (((uint32_t)(xop)) & 0x630))
#define VX128_VD128 (i.VX128.VD128l | (i.VX128.VD128h << 5))
#define VX128_VA128 (i.VX128.VA128l | (i.VX128.VA128h << 5) | (i.VX128.VA128H << 6))
#define VX128_VA128 \
(i.VX128.VA128l | (i.VX128.VA128h << 5) | (i.VX128.VA128H << 6))
#define VX128_VB128 (i.VX128.VB128l | (i.VX128.VB128h << 5))
#define VX128_1_VD128 (i.VX128_1.VD128l | (i.VX128_1.VD128h << 5))
#define VX128_2_VD128 (i.VX128_2.VD128l | (i.VX128_2.VD128h << 5))
#define VX128_2_VA128 (i.VX128_2.VA128l | (i.VX128_2.VA128h << 5) | (i.VX128_2.VA128H << 6))
#define VX128_2_VA128 \
(i.VX128_2.VA128l | (i.VX128_2.VA128h << 5) | (i.VX128_2.VA128H << 6))
#define VX128_2_VB128 (i.VX128_2.VB128l | (i.VX128_2.VD128h << 5))
#define VX128_2_VC (i.VX128_2.VC)
#define VX128_2_VC (i.VX128_2.VC)
#define VX128_3_VD128 (i.VX128_3.VD128l | (i.VX128_3.VD128h << 5))
#define VX128_3_VB128 (i.VX128_3.VB128l | (i.VX128_3.VB128h << 5))
#define VX128_3_IMM (i.VX128_3.IMM)
#define VX128_3_IMM (i.VX128_3.IMM)
#define VX128_4_VD128 (i.VX128_4.VD128l | (i.VX128_4.VD128h << 5))
#define VX128_4_VB128 (i.VX128_4.VB128l | (i.VX128_4.VB128h << 5))
#define VX128_5_VD128 (i.VX128_5.VD128l | (i.VX128_5.VD128h << 5))
#define VX128_5_VA128 (i.VX128_5.VA128l | (i.VX128_5.VA128h << 5)) | (i.VX128_5.VA128H << 6)
#define VX128_5_VA128 \
(i.VX128_5.VA128l | (i.VX128_5.VA128h << 5)) | (i.VX128_5.VA128H << 6)
#define VX128_5_VB128 (i.VX128_5.VB128l | (i.VX128_5.VB128h << 5))
#define VX128_5_SH (i.VX128_5.SH)
#define VX128_5_SH (i.VX128_5.SH)
#define VX128_R_VD128 (i.VX128_R.VD128l | (i.VX128_R.VD128h << 5))
#define VX128_R_VA128 (i.VX128_R.VA128l | (i.VX128_R.VA128h << 5) | (i.VX128_R.VA128H << 6))
#define VX128_R_VA128 \
(i.VX128_R.VA128l | (i.VX128_R.VA128h << 5) | (i.VX128_R.VA128H << 6))
#define VX128_R_VB128 (i.VX128_R.VB128l | (i.VX128_R.VB128h << 5))
void Disasm_X_VX_RA0_RB(InstrData& i, StringBuffer* str) {
if (i.X.RA) {
str->Append("%-8s v%d, r%d, r%d", i.type->name,
i.X.RT, i.X.RA, i.X.RB);
str->Append("%-8s v%d, r%d, r%d", i.type->name, i.X.RT, i.X.RA, i.X.RB);
} else {
str->Append("%-8s v%d, 0, r%d", i.type->name,
i.X.RT, i.X.RB);
str->Append("%-8s v%d, 0, r%d", i.type->name, i.X.RT, i.X.RB);
}
}
void Disasm_VX1281_VD_RA0_RB(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_1_VD128;
if (i.VX128_1.RA) {
str->Append("%-8s v%d, r%d, r%d", i.type->name,
vd, i.VX128_1.RA, i.VX128_1.RB);
str->Append("%-8s v%d, r%d, r%d", i.type->name, vd, i.VX128_1.RA,
i.VX128_1.RB);
} else {
str->Append("%-8s v%d, 0, r%d", i.type->name,
vd, i.VX128_1.RB);
str->Append("%-8s v%d, 0, r%d", i.type->name, vd, i.VX128_1.RB);
}
}
void Disasm_VX1283_VD_VB(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_3_VD128;
const uint32_t vb = VX128_3_VB128;
str->Append("%-8s v%d, v%d", i.type->name,
vd, vb);
str->Append("%-8s v%d, v%d", i.type->name, vd, vb);
}
void Disasm_VX1283_VD_VB_I(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_VD128;
const uint32_t va = VX128_VA128;
const uint32_t uimm = i.VX128_3.IMM;
str->Append("%-8s v%d, v%d, %.2Xh", i.type->name,
vd, va, uimm);
str->Append("%-8s v%d, v%d, %.2Xh", i.type->name, vd, va, uimm);
}
void Disasm_VX_VD_VA_VB(InstrData& i, StringBuffer* str) {
str->Append("%-8s v%d, v%d, v%d", i.type->name,
i.VX.VD, i.VX.VA, i.VX.VB);
str->Append("%-8s v%d, v%d, v%d", i.type->name, i.VX.VD, i.VX.VA, i.VX.VB);
}
void Disasm_VX128_VD_VA_VB(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_VD128;
const uint32_t va = VX128_VA128;
const uint32_t vb = VX128_VB128;
str->Append("%-8s v%d, v%d, v%d", i.type->name,
vd, va, vb);
str->Append("%-8s v%d, v%d, v%d", i.type->name, vd, va, vb);
}
void Disasm_VX128_VD_VA_VD_VB(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_VD128;
const uint32_t va = VX128_VA128;
const uint32_t vb = VX128_VB128;
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name,
vd, va, vd, vb);
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, vd, va, vd, vb);
}
void Disasm_VX1282_VD_VA_VB_VC(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_2_VD128;
const uint32_t va = VX128_2_VA128;
const uint32_t vb = VX128_2_VB128;
const uint32_t vc = i.VX128_2.VC;
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name,
vd, va, vb, vc);
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, vd, va, vb, vc);
}
void Disasm_VXA_VD_VA_VB_VC(InstrData& i, StringBuffer* str) {
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name,
i.VXA.VD, i.VXA.VA, i.VXA.VB, i.VXA.VC);
str->Append("%-8s v%d, v%d, v%d, v%d", i.type->name, i.VXA.VD, i.VXA.VA,
i.VXA.VB, i.VXA.VC);
}
void Disasm_sync(InstrData& i, StringBuffer* str) {
const char* name;
int L = i.X.RT & 3;
switch (L) {
case 0: name = "hwsync"; break;
case 1: name = "lwsync"; break;
default:
case 2:
case 3:
name = "sync";
break;
case 0:
name = "hwsync";
break;
case 1:
name = "lwsync";
break;
default:
case 2:
case 3:
name = "sync";
break;
}
str->Append("%-8s %.2X", name, L);
}
@ -248,10 +233,18 @@ void Disasm_sync(InstrData& i, StringBuffer* str) {
void Disasm_dcbf(InstrData& i, StringBuffer* str) {
const char* name;
switch (i.X.RT & 3) {
case 0: name = "dcbf"; break;
case 1: name = "dcbfl"; break;
case 2: name = "dcbf.RESERVED"; break;
case 3: name = "dcbflp"; break;
case 0:
name = "dcbf";
break;
case 1:
name = "dcbfl";
break;
case 2:
name = "dcbf.RESERVED";
break;
case 3:
name = "dcbflp";
break;
}
str->Append("%-8s r%d, r%d", name, i.X.RA, i.X.RB);
}
@ -266,13 +259,12 @@ void Disasm_dcbz(InstrData& i, StringBuffer* str) {
}
void Disasm_fcmp(InstrData& i, StringBuffer* str) {
str->Append("%-8s cr%d, f%d, f%d", i.type->name,
i.X.RT >> 2, i.X.RA, i.X.RB);
str->Append("%-8s cr%d, f%d, f%d", i.type->name, i.X.RT >> 2, i.X.RA, i.X.RB);
}
void Disasm_mffsx(InstrData& i, StringBuffer* str) {
str->Append("%*s%s f%d, FPSCR", i.X.Rc ? -7 : -8, i.type->name, i.X.Rc ? "." : "",
i.X.RT);
str->Append("%*s%s f%d, FPSCR", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RT);
}
void Disasm_bx(InstrData& i, StringBuffer* str) {
@ -283,8 +275,7 @@ void Disasm_bx(InstrData& i, StringBuffer* str) {
} else {
nia = (uint32_t)(i.address + XEEXTS26(i.I.LI << 2));
}
str->Append("%-8s %.8X", name,
nia);
str->Append("%-8s %.8X", name, nia);
// TODO(benvanik): resolve target name?
}
void Disasm_bcx(InstrData& i, StringBuffer* str) {
@ -295,7 +286,9 @@ void Disasm_bcx(InstrData& i, StringBuffer* str) {
} else {
s1 = "";
}
char s2[8] = { 'c', 'r', 0, };
char s2[8] = {
'c', 'r', 0,
};
if (!XESELECTBITS(i.B.BO, 4, 4)) {
char* s2a = _itoa(i.B.BI >> 2, s2 + 2, 10);
s2a += xestrlena(s2a);
@ -310,14 +303,15 @@ void Disasm_bcx(InstrData& i, StringBuffer* str) {
} else {
nia = (uint32_t)(i.address + XEEXTS16(i.B.BD << 2));
}
str->Append("%-8s %s%s%s%.8X", i.type->name,
s0, s1, s2, nia);
str->Append("%-8s %s%s%s%.8X", i.type->name, s0, s1, s2, nia);
// TODO(benvanik): resolve target name?
}
void Disasm_bcctrx(InstrData& i, StringBuffer* str) {
// TODO(benvanik): mnemonics
const char* s0 = i.XL.LK ? "lr, " : "";
char s2[8] = { 'c', 'r', 0, };
char s2[8] = {
'c', 'r', 0,
};
if (!XESELECTBITS(i.XL.BO, 4, 4)) {
char* s2a = _itoa(i.XL.BI >> 2, s2 + 2, 10);
s2a += xestrlena(s2a);
@ -326,8 +320,7 @@ void Disasm_bcctrx(InstrData& i, StringBuffer* str) {
} else {
s2[0] = 0;
}
str->Append("%-8s %s%sctr", i.type->name,
s0, s2);
str->Append("%-8s %s%sctr", i.type->name, s0, s2);
// TODO(benvanik): resolve target name?
}
void Disasm_bclrx(InstrData& i, StringBuffer* str) {
@ -341,7 +334,9 @@ void Disasm_bclrx(InstrData& i, StringBuffer* str) {
} else {
s1 = "";
}
char s2[8] = { 'c', 'r', 0, };
char s2[8] = {
'c', 'r', 0,
};
if (!XESELECTBITS(i.XL.BO, 4, 4)) {
char* s2a = _itoa(i.XL.BI >> 2, s2 + 2, 10);
s2a += xestrlena(s2a);
@ -350,179 +345,166 @@ void Disasm_bclrx(InstrData& i, StringBuffer* str) {
} else {
s2[0] = 0;
}
str->Append("%-8s %s%s", name,
s1, s2);
str->Append("%-8s %s%s", name, s1, s2);
}
void Disasm_mfcr(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, cr", i.type->name,
i.X.RT);
str->Append("%-8s r%d, cr", i.type->name, i.X.RT);
}
const char* Disasm_spr_name(uint32_t n) {
const char* reg = "???";
switch (n) {
case 1:
reg = "xer";
break;
case 8:
reg = "lr";
break;
case 9:
reg = "ctr";
break;
case 1:
reg = "xer";
break;
case 8:
reg = "lr";
break;
case 9:
reg = "ctr";
break;
}
return reg;
}
void Disasm_mfspr(InstrData& i, StringBuffer* str) {
const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F);
const char* reg = Disasm_spr_name(n);
str->Append("%-8s r%d, %s", i.type->name,
i.XFX.RT, reg);
str->Append("%-8s r%d, %s", i.type->name, i.XFX.RT, reg);
}
void Disasm_mtspr(InstrData& i, StringBuffer* str) {
const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F);
const char* reg = Disasm_spr_name(n);
str->Append("%-8s %s, r%d", i.type->name,
reg, i.XFX.RT);
str->Append("%-8s %s, r%d", i.type->name, reg, i.XFX.RT);
}
void Disasm_mftb(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, tb", i.type->name,
i.XFX.RT);
str->Append("%-8s r%d, tb", i.type->name, i.XFX.RT);
}
void Disasm_mfmsr(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d", i.type->name,
i.X.RT);
str->Append("%-8s r%d", i.type->name, i.X.RT);
}
void Disasm_mtmsr(InstrData& i, StringBuffer* str) {
str->Append("%-8s r%d, %d", i.type->name,
i.X.RT, (i.X.RA & 16) ? 1 : 0);
str->Append("%-8s r%d, %d", i.type->name, i.X.RT, (i.X.RA & 16) ? 1 : 0);
}
void Disasm_cmp(InstrData& i, StringBuffer* str) {
str->Append("%-8s cr%d, %.2X, r%d, r%d", i.type->name,
i.X.RT >> 2, i.X.RT & 1, i.X.RA, i.X.RB);
str->Append("%-8s cr%d, %.2X, r%d, r%d", i.type->name, i.X.RT >> 2,
i.X.RT & 1, i.X.RA, i.X.RB);
}
void Disasm_cmpi(InstrData& i, StringBuffer* str) {
str->Append("%-8s cr%d, %.2X, r%d, %d", i.type->name,
i.D.RT >> 2, i.D.RT & 1, i.D.RA, XEEXTS16(i.D.DS));
str->Append("%-8s cr%d, %.2X, r%d, %d", i.type->name, i.D.RT >> 2, i.D.RT & 1,
i.D.RA, XEEXTS16(i.D.DS));
}
void Disasm_cmpli(InstrData& i, StringBuffer* str) {
str->Append("%-8s cr%d, %.2X, r%d, %.2X", i.type->name,
i.D.RT >> 2, i.D.RT & 1, i.D.RA, XEEXTS16(i.D.DS));
str->Append("%-8s cr%d, %.2X, r%d, %.2X", i.type->name, i.D.RT >> 2,
i.D.RT & 1, i.D.RA, XEEXTS16(i.D.DS));
}
void Disasm_rld(InstrData& i, StringBuffer* str) {
if (i.MD.idx == 0) {
// XEDISASMR(rldiclx, 0x78000000, MD )
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldicl", i.MD.Rc ? "." : "",
i.MD.RA, i.MD.RT, (i.MD.SH5 << 5) | i.MD.SH, (i.MD.MB5 << 5) | i.MD.MB);
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldicl",
i.MD.Rc ? "." : "", i.MD.RA, i.MD.RT, (i.MD.SH5 << 5) | i.MD.SH,
(i.MD.MB5 << 5) | i.MD.MB);
} else if (i.MD.idx == 1) {
// XEDISASMR(rldicrx, 0x78000004, MD )
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldicr", i.MD.Rc ? "." : "",
i.MD.RA, i.MD.RT, (i.MD.SH5 << 5) | i.MD.SH, (i.MD.MB5 << 5) | i.MD.MB);
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldicr",
i.MD.Rc ? "." : "", i.MD.RA, i.MD.RT, (i.MD.SH5 << 5) | i.MD.SH,
(i.MD.MB5 << 5) | i.MD.MB);
} else if (i.MD.idx == 2) {
// XEDISASMR(rldicx, 0x78000008, MD )
uint32_t sh = (i.MD.SH5 << 5) | i.MD.SH;
uint32_t mb = (i.MD.MB5 << 5) | i.MD.MB;
const char* name = (mb == 0x3E) ? "sldi" : "rldic";
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, name, i.MD.Rc ? "." : "",
i.MD.RA, i.MD.RT, sh, mb);
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, name,
i.MD.Rc ? "." : "", i.MD.RA, i.MD.RT, sh, mb);
} else if (i.MDS.idx == 8) {
// XEDISASMR(rldclx, 0x78000010, MDS)
str->Append("%*s%s r%d, r%d, %d, %d", i.MDS.Rc ? -7 : -8, "rldcl", i.MDS.Rc ? "." : "",
i.MDS.RA, i.MDS.RT, i.MDS.RB, (i.MDS.MB5 << 5) | i.MDS.MB);
str->Append("%*s%s r%d, r%d, %d, %d", i.MDS.Rc ? -7 : -8, "rldcl",
i.MDS.Rc ? "." : "", i.MDS.RA, i.MDS.RT, i.MDS.RB,
(i.MDS.MB5 << 5) | i.MDS.MB);
} else if (i.MDS.idx == 9) {
// XEDISASMR(rldcrx, 0x78000012, MDS)
str->Append("%*s%s r%d, r%d, %d, %d", i.MDS.Rc ? -7 : -8, "rldcr", i.MDS.Rc ? "." : "",
i.MDS.RA, i.MDS.RT, i.MDS.RB, (i.MDS.MB5 << 5) | i.MDS.MB);
str->Append("%*s%s r%d, r%d, %d, %d", i.MDS.Rc ? -7 : -8, "rldcr",
i.MDS.Rc ? "." : "", i.MDS.RA, i.MDS.RT, i.MDS.RB,
(i.MDS.MB5 << 5) | i.MDS.MB);
} else if (i.MD.idx == 3) {
// XEDISASMR(rldimix, 0x7800000C, MD )
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldimi", i.MD.Rc ? "." : "",
i.MD.RA, i.MD.RT, (i.MD.SH5 << 5) | i.MD.SH, (i.MD.MB5 << 5) | i.MD.MB);
str->Append("%*s%s r%d, r%d, %d, %d", i.MD.Rc ? -7 : -8, "rldimi",
i.MD.Rc ? "." : "", i.MD.RA, i.MD.RT, (i.MD.SH5 << 5) | i.MD.SH,
(i.MD.MB5 << 5) | i.MD.MB);
} else {
XEASSERTALWAYS();
}
}
void Disasm_rlwim(InstrData& i, StringBuffer* str) {
str->Append("%*s%s r%d, r%d, %d, %d, %d", i.M.Rc ? -7 : -8, i.type->name, i.M.Rc ? "." : "",
i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME);
str->Append("%*s%s r%d, r%d, %d, %d, %d", i.M.Rc ? -7 : -8, i.type->name,
i.M.Rc ? "." : "", i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME);
}
void Disasm_rlwnmx(InstrData& i, StringBuffer* str) {
str->Append("%*s%s r%d, r%d, r%d, %d, %d", i.M.Rc ? -7 : -8, i.type->name, i.M.Rc ? "." : "",
i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME);
str->Append("%*s%s r%d, r%d, r%d, %d, %d", i.M.Rc ? -7 : -8, i.type->name,
i.M.Rc ? "." : "", i.M.RA, i.M.RT, i.M.SH, i.M.MB, i.M.ME);
}
void Disasm_srawix(InstrData& i, StringBuffer* str) {
str->Append("%*s%s r%d, r%d, %d", i.X.Rc ? -7 : -8, i.type->name, i.X.Rc ? "." : "",
i.X.RA, i.X.RT, i.X.RB);
str->Append("%*s%s r%d, r%d, %d", i.X.Rc ? -7 : -8, i.type->name,
i.X.Rc ? "." : "", i.X.RA, i.X.RT, i.X.RB);
}
void Disasm_sradix(InstrData& i, StringBuffer* str) {
str->Append("%*s%s r%d, r%d, %d", i.XS.Rc ? -7 : -8, i.type->name, i.XS.Rc ? "." : "",
i.XS.RA, i.XS.RT, (i.XS.SH5 << 5) | i.XS.SH);
str->Append("%*s%s r%d, r%d, %d", i.XS.Rc ? -7 : -8, i.type->name,
i.XS.Rc ? "." : "", i.XS.RA, i.XS.RT, (i.XS.SH5 << 5) | i.XS.SH);
}
void Disasm_vpermwi128(InstrData& i, StringBuffer* str) {
const uint32_t vd = i.VX128_P.VD128l | (i.VX128_P.VD128h << 5);
const uint32_t vb = i.VX128_P.VB128l | (i.VX128_P.VB128h << 5);
str->Append("%-8s v%d, v%d, %.2X", i.type->name,
vd, vb, i.VX128_P.PERMl | (i.VX128_P.PERMh << 5));
str->Append("%-8s v%d, v%d, %.2X", i.type->name, vd, vb,
i.VX128_P.PERMl | (i.VX128_P.PERMh << 5));
}
void Disasm_vrfin128(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_3_VD128;
const uint32_t vb = VX128_3_VB128;
str->Append("%-8s v%d, v%d", i.type->name,
vd, vb);
str->Append("%-8s v%d, v%d", i.type->name, vd, vb);
}
void Disasm_vrlimi128(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_4_VD128;
const uint32_t vb = VX128_4_VB128;
str->Append("%-8s v%d, v%d, %.2X, %.2X", i.type->name,
vd, vb, i.VX128_4.IMM, i.VX128_4.z);
str->Append("%-8s v%d, v%d, %.2X, %.2X", i.type->name, vd, vb, i.VX128_4.IMM,
i.VX128_4.z);
}
void Disasm_vsldoi128(InstrData& i, StringBuffer* str) {
const uint32_t vd = VX128_5_VD128;
const uint32_t va = VX128_5_VA128;
const uint32_t vb = VX128_5_VB128;
const uint32_t sh = i.VX128_5.SH;
str->Append("%-8s v%d, v%d, v%d, %.2X", i.type->name,
vd, va, vb, sh);
str->Append("%-8s v%d, v%d, v%d, %.2X", i.type->name, vd, va, vb, sh);
}
void Disasm_vspltb(InstrData& i, StringBuffer* str) {
str->Append("%-8s v%d, v%d, %.2X", i.type->name,
i.VX.VD, i.VX.VB, i.VX.VA & 0xF);
str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB,
i.VX.VA & 0xF);
}
void Disasm_vsplth(InstrData& i, StringBuffer* str) {
str->Append("%-8s v%d, v%d, %.2X", i.type->name,
i.VX.VD, i.VX.VB, i.VX.VA & 0x7);
str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB,
i.VX.VA & 0x7);
}
void Disasm_vspltw(InstrData& i, StringBuffer* str) {
str->Append("%-8s v%d, v%d, %.2X", i.type->name,
i.VX.VD, i.VX.VB, i.VX.VA);
str->Append("%-8s v%d, v%d, %.2X", i.type->name, i.VX.VD, i.VX.VB, i.VX.VA);
}
void Disasm_vspltisb(InstrData& i, StringBuffer* str) {
// 5bit -> 8bit sign extend
int8_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xF0) : i.VX.VA;
str->Append("%-8s v%d, %.2X", i.type->name,
i.VX.VD, simm);
str->Append("%-8s v%d, %.2X", i.type->name, i.VX.VD, simm);
}
void Disasm_vspltish(InstrData& i, StringBuffer* str) {
// 5bit -> 16bit sign extend
int16_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xFFF0) : i.VX.VA;
str->Append("%-8s v%d, %.4X", i.type->name,
i.VX.VD, simm);
str->Append("%-8s v%d, %.4X", i.type->name, i.VX.VD, simm);
}
void Disasm_vspltisw(InstrData& i, StringBuffer* str) {
// 5bit -> 32bit sign extend
int32_t simm = (i.VX.VA & 0x10) ? (i.VX.VA | 0xFFFFFFF0) : i.VX.VA;
str->Append("%-8s v%d, %.8X", i.type->name,
i.VX.VD, simm);
str->Append("%-8s v%d, %.8X", i.type->name, i.VX.VD, simm);
}
} // namespace ppc
} // namespace frontend
} // namespace alloy
int alloy::frontend::ppc::DisasmPPC(InstrData& i, StringBuffer* str) {
int DisasmPPC(InstrData& i, StringBuffer* str) {
if (!i.type) {
str->Append("???");
} else {
@ -531,3 +513,6 @@ int alloy::frontend::ppc::DisasmPPC(InstrData& i, StringBuffer* str) {
return 0;
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -12,18 +12,14 @@
#include <alloy/frontend/ppc/ppc_instr.h>
namespace alloy {
namespace frontend {
namespace ppc {
int DisasmPPC(InstrData& i, StringBuffer* str);
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_DISASM_H_

View File

@ -13,25 +13,21 @@
#include <alloy/frontend/ppc/ppc_emit.h>
#include <alloy/frontend/ppc/ppc_instr.h>
namespace alloy {
namespace frontend {
namespace ppc {
#define XEEMITTER(name, opcode, format) int InstrEmit_##name
#define XEREGISTERINSTR(name, opcode) \
RegisterInstrEmit(opcode, (InstrEmitFn)InstrEmit_##name);
RegisterInstrEmit(opcode, (InstrEmitFn)InstrEmit_##name);
#define XEINSTRNOTIMPLEMENTED()
//#define XEINSTRNOTIMPLEMENTED XEASSERTALWAYS
//#define XEINSTRNOTIMPLEMENTED() __debugbreak()
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_EMIT_PRIVATE_H_

View File

@ -12,22 +12,18 @@
#include <alloy/frontend/ppc/ppc_instr.h>
namespace alloy {
namespace frontend {
namespace ppc {
void RegisterEmitCategoryAltivec();
void RegisterEmitCategoryALU();
void RegisterEmitCategoryControl();
void RegisterEmitCategoryFPU();
void RegisterEmitCategoryMemory();
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_EMIT_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -12,21 +12,19 @@
#include <alloy/frontend/ppc/ppc_context.h>
#include <alloy/frontend/ppc/ppc_hir_builder.h>
using namespace alloy::frontend::ppc;
using namespace alloy::hir;
using namespace alloy::runtime;
namespace alloy {
namespace frontend {
namespace ppc {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
int InstrEmit_branch(
PPCHIRBuilder& f, const char* src, uint64_t cia,
Value* nia, bool lk, Value* cond = NULL, bool expect_true = true,
bool nia_is_lr = false) {
using alloy::hir::Label;
using alloy::hir::Value;
int InstrEmit_branch(PPCHIRBuilder& f, const char* src, uint64_t cia,
Value* nia, bool lk, Value* cond = NULL,
bool expect_true = true, bool nia_is_lr = false) {
uint32_t call_flags = 0;
// TODO(benvanik): this may be wrong and overwrite LRs when not desired!
@ -54,8 +52,7 @@ int InstrEmit_branch(
// recursion.
uint64_t nia_value = nia->AsUint64() & 0xFFFFFFFF;
bool is_recursion = false;
if (nia_value == f.symbol_info()->address() &&
lk) {
if (nia_value == f.symbol_info()->address() && lk) {
is_recursion = true;
}
Label* label = is_recursion ? NULL : f.LookupLabel(nia_value);
@ -73,7 +70,7 @@ int InstrEmit_branch(
}
} else {
// Call function.
FunctionInfo* symbol_info = f.LookupFunction(nia_value);
auto symbol_info = f.LookupFunction(nia_value);
if (cond) {
if (!expect_true) {
cond = f.IsFalse(cond);
@ -84,27 +81,27 @@ int InstrEmit_branch(
}
}
} else {
// Indirect branch to pointer.
// Indirect branch to pointer.
// TODO(benvanik): runtime recursion detection?
// TODO(benvanik): runtime recursion detection?
// TODO(benvanik): run a DFA pass to see if we can detect whether this is
// a normal function return that is pulling the LR from the stack that
// it set in the prolog. If so, we can omit the dynamic check!
// TODO(benvanik): run a DFA pass to see if we can detect whether this is
// a normal function return that is pulling the LR from the stack that
// it set in the prolog. If so, we can omit the dynamic check!
//// Dynamic test when branching to LR, which is usually used for the return.
//// We only do this if LK=0 as returns wouldn't set LR.
//// Ideally it's a return and we can just do a simple ret and be done.
//// If it's not, we fall through to the full indirection logic.
//if (!lk && reg == kXEPPCRegLR) {
// // The return block will spill registers for us.
// // TODO(benvanik): 'lr_mismatch' debug info.
// // Note: we need to test on *only* the 32-bit target, as the target ptr may
// // have garbage in the upper 32 bits.
// c.cmp(target.r32(), c.getGpArg(1).r32());
// // TODO(benvanik): evaluate hint here.
// c.je(e.GetReturnLabel(), kCondHintLikely);
//}
//// Dynamic test when branching to LR, which is usually used for the return.
//// We only do this if LK=0 as returns wouldn't set LR.
//// Ideally it's a return and we can just do a simple ret and be done.
//// If it's not, we fall through to the full indirection logic.
// if (!lk && reg == kXEPPCRegLR) {
// // The return block will spill registers for us.
// // TODO(benvanik): 'lr_mismatch' debug info.
// // Note: we need to test on *only* the 32-bit target, as the target ptr may
// // have garbage in the upper 32 bits.
// c.cmp(target.r32(), c.getGpArg(1).r32());
// // TODO(benvanik): evaluate hint here.
// c.je(e.GetReturnLabel(), kCondHintLikely);
//}
#if 0
// This breaks longjump, as that uses blr with a non-return lr.
// It'd be nice to move SET_RETURN_ADDRESS semantics up into context
@ -124,27 +121,26 @@ int InstrEmit_branch(
#else
{
#endif
// Jump to pointer.
bool likely_return = !lk && nia_is_lr;
if (likely_return) {
call_flags |= CALL_POSSIBLE_RETURN;
}
if (cond) {
if (!expect_true) {
cond = f.IsFalse(cond);
}
f.CallIndirectTrue(cond, nia, call_flags);
} else {
f.CallIndirect(nia, call_flags);
// Jump to pointer.
bool likely_return = !lk && nia_is_lr;
if (likely_return) {
call_flags |= CALL_POSSIBLE_RETURN;
}
if (cond) {
if (!expect_true) {
cond = f.IsFalse(cond);
}
f.CallIndirectTrue(cond, nia, call_flags);
} else {
f.CallIndirect(nia, call_flags);
}
}
return 0;
}
return 0;
}
XEEMITTER(bx, 0x48000000, I )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(bx, 0x48000000, I)(PPCHIRBuilder& f, InstrData& i) {
// if AA then
// NIA <- EXTS(LI || 0b00)
// else
@ -159,11 +155,10 @@ XEEMITTER(bx, 0x48000000, I )(PPCHIRBuilder& f, InstrData& i) {
nia = (uint32_t)(i.address + XEEXTS26(i.I.LI << 2));
}
return InstrEmit_branch(
f, "bx", i.address, f.LoadConstant(nia), i.I.LK);
return InstrEmit_branch(f, "bx", i.address, f.LoadConstant(nia), i.I.LK);
}
XEEMITTER(bcx, 0x40000000, B )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(bcx, 0x40000000, B)(PPCHIRBuilder& f, InstrData& i) {
// if ¬BO[2] then
// CTR <- CTR - 1
// ctr_ok <- BO[2] | ((CTR[0:63] != 0) XOR BO[3])
@ -236,11 +231,11 @@ XEEMITTER(bcx, 0x40000000, B )(PPCHIRBuilder& f, InstrData& i) {
} else {
nia = (uint32_t)(i.address + XEEXTS16(i.B.BD << 2));
}
return InstrEmit_branch(
f, "bcx", i.address, f.LoadConstant(nia), i.B.LK, ok, expect_true);
return InstrEmit_branch(f, "bcx", i.address, f.LoadConstant(nia), i.B.LK, ok,
expect_true);
}
XEEMITTER(bcctrx, 0x4C000420, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(bcctrx, 0x4C000420, XL)(PPCHIRBuilder& f, InstrData& i) {
// cond_ok <- BO[0] | (CR[BI+32] ≡ BO[1])
// if cond_ok then
// NIA <- CTR[0:61] || 0b00
@ -268,11 +263,11 @@ XEEMITTER(bcctrx, 0x4C000420, XL )(PPCHIRBuilder& f, InstrData& i) {
}
bool expect_true = !not_cond_ok;
return InstrEmit_branch(
f, "bcctrx", i.address, f.LoadCTR(), i.XL.LK, cond_ok, expect_true);
return InstrEmit_branch(f, "bcctrx", i.address, f.LoadCTR(), i.XL.LK, cond_ok,
expect_true);
}
XEEMITTER(bclrx, 0x4C000020, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(bclrx, 0x4C000020, XL)(PPCHIRBuilder& f, InstrData& i) {
// if ¬BO[2] then
// CTR <- CTR - 1
// ctr_ok <- BO[2] | ((CTR[0:63] != 0) XOR BO[3]
@ -336,71 +331,68 @@ XEEMITTER(bclrx, 0x4C000020, XL )(PPCHIRBuilder& f, InstrData& i) {
expect_true = !not_cond_ok;
}
return InstrEmit_branch(
f, "bclrx", i.address, f.LoadLR(), i.XL.LK, ok, expect_true, true);
return InstrEmit_branch(f, "bclrx", i.address, f.LoadLR(), i.XL.LK, ok,
expect_true, true);
}
// Condition register logical (A-23)
XEEMITTER(crand, 0x4C000202, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(crand, 0x4C000202, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(crandc, 0x4C000102, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(crandc, 0x4C000102, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(creqv, 0x4C000242, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(creqv, 0x4C000242, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(crnand, 0x4C0001C2, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(crnand, 0x4C0001C2, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(crnor, 0x4C000042, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(crnor, 0x4C000042, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(cror, 0x4C000382, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(cror, 0x4C000382, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(crorc, 0x4C000342, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(crorc, 0x4C000342, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(crxor, 0x4C000182, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(crxor, 0x4C000182, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(mcrf, 0x4C000000, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mcrf, 0x4C000000, XL)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
// System linkage (A-24)
XEEMITTER(sc, 0x44000002, SC )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(sc, 0x44000002, SC)(PPCHIRBuilder& f, InstrData& i) {
f.CallExtern(f.symbol_info());
return 0;
}
// Trap (A-25)
int InstrEmit_trap(PPCHIRBuilder& f, InstrData& i,
Value* va, Value* vb, uint32_t TO) {
int InstrEmit_trap(PPCHIRBuilder& f, InstrData& i, Value* va, Value* vb,
uint32_t TO) {
// if (a < b) & TO[0] then TRAP
// if (a > b) & TO[1] then TRAP
// if (a = b) & TO[2] then TRAP
@ -435,7 +427,7 @@ int InstrEmit_trap(PPCHIRBuilder& f, InstrData& i,
return 0;
}
XEEMITTER(td, 0x7C000088, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(td, 0x7C000088, X)(PPCHIRBuilder& f, InstrData& i) {
// a <- (RA)
// b <- (RB)
// if (a < b) & TO[0] then TRAP
@ -448,7 +440,7 @@ XEEMITTER(td, 0x7C000088, X )(PPCHIRBuilder& f, InstrData& i) {
return InstrEmit_trap(f, i, ra, rb, i.X.RT);
}
XEEMITTER(tdi, 0x08000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(tdi, 0x08000000, D)(PPCHIRBuilder& f, InstrData& i) {
// a <- (RA)
// if (a < EXTS(SI)) & TO[0] then TRAP
// if (a > EXTS(SI)) & TO[1] then TRAP
@ -460,7 +452,7 @@ XEEMITTER(tdi, 0x08000000, D )(PPCHIRBuilder& f, InstrData& i) {
return InstrEmit_trap(f, i, ra, rb, i.D.RT);
}
XEEMITTER(tw, 0x7C000008, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(tw, 0x7C000008, X)(PPCHIRBuilder& f, InstrData& i) {
// a <- EXTS((RA)[32:63])
// b <- EXTS((RB)[32:63])
// if (a < b) & TO[0] then TRAP
@ -468,14 +460,14 @@ XEEMITTER(tw, 0x7C000008, X )(PPCHIRBuilder& f, InstrData& i) {
// if (a = b) & TO[2] then TRAP
// if (a <u b) & TO[3] then TRAP
// if (a >u b) & TO[4] then TRAP
Value* ra = f.SignExtend(f.Truncate(
f.LoadGPR(i.X.RA), INT32_TYPE), INT64_TYPE);
Value* rb = f.SignExtend(f.Truncate(
f.LoadGPR(i.X.RB), INT32_TYPE), INT64_TYPE);
Value* ra =
f.SignExtend(f.Truncate(f.LoadGPR(i.X.RA), INT32_TYPE), INT64_TYPE);
Value* rb =
f.SignExtend(f.Truncate(f.LoadGPR(i.X.RB), INT32_TYPE), INT64_TYPE);
return InstrEmit_trap(f, i, ra, rb, i.X.RT);
}
XEEMITTER(twi, 0x0C000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(twi, 0x0C000000, D)(PPCHIRBuilder& f, InstrData& i) {
// a <- EXTS((RA)[32:63])
// if (a < EXTS(SI)) & TO[0] then TRAP
// if (a > EXTS(SI)) & TO[1] then TRAP
@ -488,21 +480,20 @@ XEEMITTER(twi, 0x0C000000, D )(PPCHIRBuilder& f, InstrData& i) {
f.Trap(type);
return 0;
}
Value* ra = f.SignExtend(f.Truncate(
f.LoadGPR(i.D.RA), INT32_TYPE), INT64_TYPE);
Value* ra =
f.SignExtend(f.Truncate(f.LoadGPR(i.D.RA), INT32_TYPE), INT64_TYPE);
Value* rb = f.LoadConstant(XEEXTS16(i.D.DS));
return InstrEmit_trap(f, i, ra, rb, i.D.RT);
}
// Processor control (A-26)
XEEMITTER(mfcr, 0x7C000026, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mfcr, 0x7C000026, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(mfspr, 0x7C0002A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mfspr, 0x7C0002A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
// n <- spr[5:9] || spr[0:4]
// if length(SPR(n)) = 64 then
// RT <- SPR(n)
@ -511,40 +502,40 @@ XEEMITTER(mfspr, 0x7C0002A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
Value* v;
const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F);
switch (n) {
case 1:
// XER
v = f.LoadXER();
break;
case 8:
// LR
v = f.LoadLR();
break;
case 9:
// CTR
v = f.LoadCTR();
break;
// 268 + 269 = TB + TBU
default:
XEINSTRNOTIMPLEMENTED();
return 1;
case 1:
// XER
v = f.LoadXER();
break;
case 8:
// LR
v = f.LoadLR();
break;
case 9:
// CTR
v = f.LoadCTR();
break;
// 268 + 269 = TB + TBU
default:
XEINSTRNOTIMPLEMENTED();
return 1;
}
f.StoreGPR(i.XFX.RT, v);
return 0;
}
XEEMITTER(mftb, 0x7C0002E6, XFX)(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mftb, 0x7C0002E6, XFX)(PPCHIRBuilder& f, InstrData& i) {
Value* time = f.LoadClock();
f.StoreGPR(i.XFX.RT, time);
return 0;
}
XEEMITTER(mtcrf, 0x7C000120, XFX)(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtcrf, 0x7C000120, XFX)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(mtspr, 0x7C0003A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtspr, 0x7C0003A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
// n <- spr[5:9] || spr[0:4]
// if length(SPR(n)) = 64 then
// SPR(n) <- (RS)
@ -555,21 +546,21 @@ XEEMITTER(mtspr, 0x7C0003A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F);
switch (n) {
case 1:
// XER
f.StoreXER(rt);
break;
case 8:
// LR
f.StoreLR(rt);
break;
case 9:
// CTR
f.StoreCTR(rt);
break;
default:
XEINSTRNOTIMPLEMENTED();
return 1;
case 1:
// XER
f.StoreXER(rt);
break;
case 8:
// LR
f.StoreLR(rt);
break;
case 9:
// CTR
f.StoreCTR(rt);
break;
default:
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
@ -578,52 +569,50 @@ XEEMITTER(mtspr, 0x7C0003A6, XFX)(PPCHIRBuilder& f, InstrData& i) {
// TODO(benvanik): MSR is used for toggling interrupts, and it'd be nice to
// obey that setting. It's usually guarding atomic stores.
XEEMITTER(mfmsr, 0x7C0000A6, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mfmsr, 0x7C0000A6, X)(PPCHIRBuilder& f, InstrData& i) {
f.Nop();
return 0;
}
XEEMITTER(mtmsr, 0x7C000124, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtmsr, 0x7C000124, X)(PPCHIRBuilder& f, InstrData& i) {
f.Nop();
return 0;
}
XEEMITTER(mtmsrd, 0x7C000164, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtmsrd, 0x7C000164, X)(PPCHIRBuilder& f, InstrData& i) {
f.Nop();
return 0;
}
void RegisterEmitCategoryControl() {
XEREGISTERINSTR(bx, 0x48000000);
XEREGISTERINSTR(bcx, 0x40000000);
XEREGISTERINSTR(bcctrx, 0x4C000420);
XEREGISTERINSTR(bclrx, 0x4C000020);
XEREGISTERINSTR(crand, 0x4C000202);
XEREGISTERINSTR(crandc, 0x4C000102);
XEREGISTERINSTR(creqv, 0x4C000242);
XEREGISTERINSTR(crnand, 0x4C0001C2);
XEREGISTERINSTR(crnor, 0x4C000042);
XEREGISTERINSTR(cror, 0x4C000382);
XEREGISTERINSTR(crorc, 0x4C000342);
XEREGISTERINSTR(crxor, 0x4C000182);
XEREGISTERINSTR(mcrf, 0x4C000000);
XEREGISTERINSTR(sc, 0x44000002);
XEREGISTERINSTR(td, 0x7C000088);
XEREGISTERINSTR(tdi, 0x08000000);
XEREGISTERINSTR(tw, 0x7C000008);
XEREGISTERINSTR(twi, 0x0C000000);
XEREGISTERINSTR(mfcr, 0x7C000026);
XEREGISTERINSTR(mfspr, 0x7C0002A6);
XEREGISTERINSTR(mftb, 0x7C0002E6);
XEREGISTERINSTR(mtcrf, 0x7C000120);
XEREGISTERINSTR(mtspr, 0x7C0003A6);
XEREGISTERINSTR(mfmsr, 0x7C0000A6);
XEREGISTERINSTR(mtmsr, 0x7C000124);
XEREGISTERINSTR(mtmsrd, 0x7C000164);
XEREGISTERINSTR(bx, 0x48000000);
XEREGISTERINSTR(bcx, 0x40000000);
XEREGISTERINSTR(bcctrx, 0x4C000420);
XEREGISTERINSTR(bclrx, 0x4C000020);
XEREGISTERINSTR(crand, 0x4C000202);
XEREGISTERINSTR(crandc, 0x4C000102);
XEREGISTERINSTR(creqv, 0x4C000242);
XEREGISTERINSTR(crnand, 0x4C0001C2);
XEREGISTERINSTR(crnor, 0x4C000042);
XEREGISTERINSTR(cror, 0x4C000382);
XEREGISTERINSTR(crorc, 0x4C000342);
XEREGISTERINSTR(crxor, 0x4C000182);
XEREGISTERINSTR(mcrf, 0x4C000000);
XEREGISTERINSTR(sc, 0x44000002);
XEREGISTERINSTR(td, 0x7C000088);
XEREGISTERINSTR(tdi, 0x08000000);
XEREGISTERINSTR(tw, 0x7C000008);
XEREGISTERINSTR(twi, 0x0C000000);
XEREGISTERINSTR(mfcr, 0x7C000026);
XEREGISTERINSTR(mfspr, 0x7C0002A6);
XEREGISTERINSTR(mftb, 0x7C0002E6);
XEREGISTERINSTR(mtcrf, 0x7C000120);
XEREGISTERINSTR(mtspr, 0x7C0003A6);
XEREGISTERINSTR(mfmsr, 0x7C0000A6);
XEREGISTERINSTR(mtmsr, 0x7C000124);
XEREGISTERINSTR(mtmsrd, 0x7C000164);
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -12,148 +12,145 @@
#include <alloy/frontend/ppc/ppc_context.h>
#include <alloy/frontend/ppc/ppc_hir_builder.h>
using namespace alloy::frontend::ppc;
using namespace alloy::hir;
using namespace alloy::runtime;
namespace alloy {
namespace frontend {
namespace ppc {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using alloy::hir::RoundMode;
using alloy::hir::Value;
// Good source of information:
// http://mamedev.org/source/src/emu/cpu/powerpc/ppc_ops.c
// The correctness of that code is not reflected here yet -_-
// Enable rounding numbers to single precision as required.
// This adds a bunch of work per operation and I'm not sure it's required.
#define ROUND_TO_SINGLE
// Floating-point arithmetic (A-8)
XEEMITTER(faddx, 0xFC00002A, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(faddx, 0xFC00002A, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) + (frB)
Value* v = f.Add(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(faddsx, 0xEC00002A, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(faddsx, 0xEC00002A, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) + (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);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fdivx, 0xFC000024, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fdivx, 0xFC000024, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- frA / frB
Value* v = f.Div(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fdivsx, 0xEC000024, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fdivsx, 0xEC000024, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- frA / 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);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fmulx, 0xFC000032, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fmulx, 0xFC000032, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) x (frC)
Value* v = f.Mul(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fmulsx, 0xEC000032, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fmulsx, 0xEC000032, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) x (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);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fresx, 0xEC000030, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fresx, 0xEC000030, A)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(frsqrtex, 0xFC000034, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(frsqrtex, 0xFC000034, A)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(fsubx, 0xFC000028, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fsubx, 0xFC000028, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) - (frB)
Value* v = f.Sub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fsubsx, 0xEC000028, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fsubsx, 0xEC000028, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA) - (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);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fselx, 0xFC00002E, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fselx, 0xFC00002E, A)(PPCHIRBuilder& f, InstrData& i) {
// if (frA) >= 0.0
// then frD <- (frC)
// else frD <- (frB)
@ -161,28 +158,28 @@ XEEMITTER(fselx, 0xFC00002E, A )(PPCHIRBuilder& f, InstrData& i) {
Value* v = f.Select(ge, f.LoadFPR(i.A.FRC), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fsqrtx, 0xFC00002C, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fsqrtx, 0xFC00002C, A)(PPCHIRBuilder& f, InstrData& i) {
// Double precision:
// frD <- sqrt(frB)
Value* v = f.Sqrt(f.LoadFPR(i.A.FRA));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fsqrtsx, 0xEC00002C, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fsqrtsx, 0xEC00002C, A)(PPCHIRBuilder& f, InstrData& i) {
// Single precision:
// frD <- sqrt(frB)
Value* v = f.Sqrt(f.LoadFPR(i.A.FRA));
@ -190,144 +187,128 @@ XEEMITTER(fsqrtsx, 0xEC00002C, A )(PPCHIRBuilder& f, InstrData& i) {
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
// Floating-point multiply-add (A-9)
XEEMITTER(fmaddx, 0xFC00003A, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fmaddx, 0xFC00003A, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) + frB
Value* v = f.MulAdd(
f.LoadFPR(i.A.FRA),
f.LoadFPR(i.A.FRC),
f.LoadFPR(i.A.FRB));
Value* v =
f.MulAdd(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fmaddsx, 0xEC00003A, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fmaddsx, 0xEC00003A, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) + frB
Value* v = f.MulAdd(
f.LoadFPR(i.A.FRA),
f.LoadFPR(i.A.FRC),
f.LoadFPR(i.A.FRB));
Value* v =
f.MulAdd(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC), f.LoadFPR(i.A.FRB));
v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fmsubx, 0xFC000038, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fmsubx, 0xFC000038, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) - frB
Value* v = f.MulSub(
f.LoadFPR(i.A.FRA),
f.LoadFPR(i.A.FRC),
f.LoadFPR(i.A.FRB));
Value* v =
f.MulSub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC), f.LoadFPR(i.A.FRB));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fmsubsx, 0xEC000038, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fmsubsx, 0xEC000038, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frA x frC) - frB
Value* v = f.MulSub(
f.LoadFPR(i.A.FRA),
f.LoadFPR(i.A.FRC),
f.LoadFPR(i.A.FRB));
Value* v =
f.MulSub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC), f.LoadFPR(i.A.FRB));
v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fnmaddx, 0xFC00003E, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fnmaddx, 0xFC00003E, A)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(fnmaddsx, 0xEC00003E, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fnmaddsx, 0xEC00003E, A)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(fnmsubx, 0xFC00003C, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fnmsubx, 0xFC00003C, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- -([frA x frC] - frB)
Value* v = f.Neg(f.MulSub(
f.LoadFPR(i.A.FRA),
f.LoadFPR(i.A.FRC),
f.LoadFPR(i.A.FRB)));
Value* v = f.Neg(
f.MulSub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC), f.LoadFPR(i.A.FRB)));
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fnmsubsx, 0xEC00003C, A )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fnmsubsx, 0xEC00003C, A)(PPCHIRBuilder& f, InstrData& i) {
// frD <- -([frA x frC] - frB)
Value* v = f.Neg(f.MulSub(
f.LoadFPR(i.A.FRA),
f.LoadFPR(i.A.FRC),
f.LoadFPR(i.A.FRB)));
Value* v = f.Neg(
f.MulSub(f.LoadFPR(i.A.FRA), f.LoadFPR(i.A.FRC), f.LoadFPR(i.A.FRB)));
v = f.Convert(f.Convert(v, FLOAT32_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
// Floating-point rounding and conversion (A-10)
XEEMITTER(fcfidx, 0xFC00069C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fcfidx, 0xFC00069C, X)(PPCHIRBuilder& f, InstrData& i) {
// frD <- signed_int64_to_double( frB )
Value* v = f.Convert(
f.Cast(f.LoadFPR(i.A.FRB), INT64_TYPE),
FLOAT64_TYPE);
Value* v = f.Convert(f.Cast(f.LoadFPR(i.A.FRB), INT64_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.A.FRT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fctidx, 0xFC00065C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fctidx, 0xFC00065C, X)(PPCHIRBuilder& f, InstrData& i) {
// frD <- double_to_signed_int64( frB )
// TODO(benvanik): pull from FPSCR[RN]
RoundMode round_mode = ROUND_TO_ZERO;
@ -336,19 +317,19 @@ XEEMITTER(fctidx, 0xFC00065C, X )(PPCHIRBuilder& f, InstrData& i) {
f.StoreFPR(i.X.RT, v);
// f.UpdateFPRF(v);
if (i.X.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fctidzx, 0xFC00065E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fctidzx, 0xFC00065E, X)(PPCHIRBuilder& f, InstrData& i) {
// TODO(benvanik): assuming round to zero is always set, is that ok?
return InstrEmit_fctidx(f, i);
}
XEEMITTER(fctiwx, 0xFC00001C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fctiwx, 0xFC00001C, X)(PPCHIRBuilder& f, InstrData& i) {
// frD <- double_to_signed_int32( frB )
// TODO(benvanik): pull from FPSCR[RN]
RoundMode round_mode = ROUND_TO_ZERO;
@ -357,19 +338,19 @@ XEEMITTER(fctiwx, 0xFC00001C, X )(PPCHIRBuilder& f, InstrData& i) {
f.StoreFPR(i.X.RT, v);
// f.UpdateFPRF(v);
if (i.A.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fctiwzx, 0xFC00001E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fctiwzx, 0xFC00001E, X)(PPCHIRBuilder& f, InstrData& i) {
// TODO(benvanik): assuming round to zero is always set, is that ok?
return InstrEmit_fctiwx(f, i);
}
XEEMITTER(frspx, 0xFC000018, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(frspx, 0xFC000018, X)(PPCHIRBuilder& f, InstrData& i) {
// frD <- Round_single(frB)
// TODO(benvanik): pull from FPSCR[RN]
RoundMode round_mode = ROUND_TO_ZERO;
@ -378,14 +359,13 @@ XEEMITTER(frspx, 0xFC000018, X )(PPCHIRBuilder& f, InstrData& i) {
f.StoreFPR(i.X.RT, v);
// f.UpdateFPRF(v);
if (i.X.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
// Floating-point compare (A-11)
int InstrEmit_fcmpx_(PPCHIRBuilder& f, InstrData& i, bool ordered) {
@ -410,22 +390,21 @@ int InstrEmit_fcmpx_(PPCHIRBuilder& f, InstrData& i, bool ordered) {
f.UpdateCR(crf, f.LoadFPR(i.X.RA), f.LoadFPR(i.X.RB), false);
return 0;
}
XEEMITTER(fcmpo, 0xFC000040, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fcmpo, 0xFC000040, X)(PPCHIRBuilder& f, InstrData& i) {
return InstrEmit_fcmpx_(f, i, true);
}
XEEMITTER(fcmpu, 0xFC000000, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fcmpu, 0xFC000000, X)(PPCHIRBuilder& f, InstrData& i) {
return InstrEmit_fcmpx_(f, i, false);
}
// Floating-point status and control register (A
XEEMITTER(mcrfs, 0xFC000080, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mcrfs, 0xFC000080, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(mffsx, 0xFC00048E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mffsx, 0xFC00048E, X)(PPCHIRBuilder& f, InstrData& i) {
if (i.X.Rc) {
XEINSTRNOTIMPLEMENTED();
return 1;
@ -434,17 +413,17 @@ XEEMITTER(mffsx, 0xFC00048E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(mtfsb0x, 0xFC00008C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtfsb0x, 0xFC00008C, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(mtfsb1x, 0xFC00004C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtfsb1x, 0xFC00004C, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(mtfsfx, 0xFC00058E, XFL)(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtfsfx, 0xFC00058E, XFL)(PPCHIRBuilder& f, InstrData& i) {
if (i.XFL.Rc) {
XEINSTRNOTIMPLEMENTED();
return 1;
@ -460,99 +439,96 @@ XEEMITTER(mtfsfx, 0xFC00058E, XFL)(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(mtfsfix, 0xFC00010C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(mtfsfix, 0xFC00010C, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
// Floating-point move (A-21)
XEEMITTER(fabsx, 0xFC000210, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fabsx, 0xFC000210, X)(PPCHIRBuilder& f, InstrData& i) {
// frD <- abs(frB)
Value* v = f.Abs(f.LoadFPR(i.X.RB));
f.StoreFPR(i.X.RT, v);
if (i.X.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fmrx, 0xFC000090, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fmrx, 0xFC000090, X)(PPCHIRBuilder& f, InstrData& i) {
// frD <- (frB)
Value* v = f.LoadFPR(i.X.RB);
f.StoreFPR(i.X.RT, v);
if (i.X.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
XEEMITTER(fnabsx, 0xFC000110, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fnabsx, 0xFC000110, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(fnegx, 0xFC000050, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(fnegx, 0xFC000050, X)(PPCHIRBuilder& f, InstrData& i) {
// frD <- ¬ frB[0] || frB[1-63]
Value* v = f.Neg(f.LoadFPR(i.X.RB));
f.StoreFPR(i.X.RT, v);
if (i.X.Rc) {
//e.update_cr_with_cond(1, v);
// e.update_cr_with_cond(1, v);
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
void RegisterEmitCategoryFPU() {
XEREGISTERINSTR(faddx, 0xFC00002A);
XEREGISTERINSTR(faddsx, 0xEC00002A);
XEREGISTERINSTR(fdivx, 0xFC000024);
XEREGISTERINSTR(fdivsx, 0xEC000024);
XEREGISTERINSTR(fmulx, 0xFC000032);
XEREGISTERINSTR(fmulsx, 0xEC000032);
XEREGISTERINSTR(fresx, 0xEC000030);
XEREGISTERINSTR(frsqrtex, 0xFC000034);
XEREGISTERINSTR(fsubx, 0xFC000028);
XEREGISTERINSTR(fsubsx, 0xEC000028);
XEREGISTERINSTR(fselx, 0xFC00002E);
XEREGISTERINSTR(fsqrtx, 0xFC00002C);
XEREGISTERINSTR(fsqrtsx, 0xEC00002C);
XEREGISTERINSTR(fmaddx, 0xFC00003A);
XEREGISTERINSTR(fmaddsx, 0xEC00003A);
XEREGISTERINSTR(fmsubx, 0xFC000038);
XEREGISTERINSTR(fmsubsx, 0xEC000038);
XEREGISTERINSTR(fnmaddx, 0xFC00003E);
XEREGISTERINSTR(fnmaddsx, 0xEC00003E);
XEREGISTERINSTR(fnmsubx, 0xFC00003C);
XEREGISTERINSTR(fnmsubsx, 0xEC00003C);
XEREGISTERINSTR(fcfidx, 0xFC00069C);
XEREGISTERINSTR(fctidx, 0xFC00065C);
XEREGISTERINSTR(fctidzx, 0xFC00065E);
XEREGISTERINSTR(fctiwx, 0xFC00001C);
XEREGISTERINSTR(fctiwzx, 0xFC00001E);
XEREGISTERINSTR(frspx, 0xFC000018);
XEREGISTERINSTR(fcmpo, 0xFC000040);
XEREGISTERINSTR(fcmpu, 0xFC000000);
XEREGISTERINSTR(mcrfs, 0xFC000080);
XEREGISTERINSTR(mffsx, 0xFC00048E);
XEREGISTERINSTR(mtfsb0x, 0xFC00008C);
XEREGISTERINSTR(mtfsb1x, 0xFC00004C);
XEREGISTERINSTR(mtfsfx, 0xFC00058E);
XEREGISTERINSTR(mtfsfix, 0xFC00010C);
XEREGISTERINSTR(fabsx, 0xFC000210);
XEREGISTERINSTR(fmrx, 0xFC000090);
XEREGISTERINSTR(fnabsx, 0xFC000110);
XEREGISTERINSTR(fnegx, 0xFC000050);
XEREGISTERINSTR(faddx, 0xFC00002A);
XEREGISTERINSTR(faddsx, 0xEC00002A);
XEREGISTERINSTR(fdivx, 0xFC000024);
XEREGISTERINSTR(fdivsx, 0xEC000024);
XEREGISTERINSTR(fmulx, 0xFC000032);
XEREGISTERINSTR(fmulsx, 0xEC000032);
XEREGISTERINSTR(fresx, 0xEC000030);
XEREGISTERINSTR(frsqrtex, 0xFC000034);
XEREGISTERINSTR(fsubx, 0xFC000028);
XEREGISTERINSTR(fsubsx, 0xEC000028);
XEREGISTERINSTR(fselx, 0xFC00002E);
XEREGISTERINSTR(fsqrtx, 0xFC00002C);
XEREGISTERINSTR(fsqrtsx, 0xEC00002C);
XEREGISTERINSTR(fmaddx, 0xFC00003A);
XEREGISTERINSTR(fmaddsx, 0xEC00003A);
XEREGISTERINSTR(fmsubx, 0xFC000038);
XEREGISTERINSTR(fmsubsx, 0xEC000038);
XEREGISTERINSTR(fnmaddx, 0xFC00003E);
XEREGISTERINSTR(fnmaddsx, 0xEC00003E);
XEREGISTERINSTR(fnmsubx, 0xFC00003C);
XEREGISTERINSTR(fnmsubsx, 0xEC00003C);
XEREGISTERINSTR(fcfidx, 0xFC00069C);
XEREGISTERINSTR(fctidx, 0xFC00065C);
XEREGISTERINSTR(fctidzx, 0xFC00065E);
XEREGISTERINSTR(fctiwx, 0xFC00001C);
XEREGISTERINSTR(fctiwzx, 0xFC00001E);
XEREGISTERINSTR(frspx, 0xFC000018);
XEREGISTERINSTR(fcmpo, 0xFC000040);
XEREGISTERINSTR(fcmpu, 0xFC000000);
XEREGISTERINSTR(mcrfs, 0xFC000080);
XEREGISTERINSTR(mffsx, 0xFC00048E);
XEREGISTERINSTR(mtfsb0x, 0xFC00008C);
XEREGISTERINSTR(mtfsb1x, 0xFC00004C);
XEREGISTERINSTR(mtfsfx, 0xFC00058E);
XEREGISTERINSTR(mtfsfix, 0xFC00010C);
XEREGISTERINSTR(fabsx, 0xFC000210);
XEREGISTERINSTR(fmrx, 0xFC000090);
XEREGISTERINSTR(fnabsx, 0xFC000110);
XEREGISTERINSTR(fnegx, 0xFC000050);
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -12,23 +12,22 @@
#include <alloy/frontend/ppc/ppc_context.h>
#include <alloy/frontend/ppc/ppc_hir_builder.h>
using namespace alloy::frontend::ppc;
using namespace alloy::hir;
using namespace alloy::runtime;
namespace alloy {
namespace frontend {
namespace ppc {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using alloy::hir::Value;
#define TRUNCATE_ADDRESSES 0
Value* CalculateEA(PPCHIRBuilder& f, uint32_t ra, uint32_t rb) {
#if TRUNCATE_ADDRESSES
return f.ZeroExtend(f.Add(
f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.Truncate(f.LoadGPR(rb), INT32_TYPE)), INT64_TYPE);
return f.ZeroExtend(f.Add(f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.Truncate(f.LoadGPR(rb), INT32_TYPE)),
INT64_TYPE);
#else
return f.Add(f.LoadGPR(ra), f.LoadGPR(rb));
#endif // TRUNCATE_ADDRESSES
@ -37,9 +36,9 @@ Value* CalculateEA(PPCHIRBuilder& f, uint32_t ra, uint32_t rb) {
Value* CalculateEA_0(PPCHIRBuilder& f, uint32_t ra, uint32_t rb) {
#if TRUNCATE_ADDRESSES
if (ra) {
return f.ZeroExtend(f.Add(
f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.Truncate(f.LoadGPR(rb), INT32_TYPE)), INT64_TYPE);
return f.ZeroExtend(f.Add(f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.Truncate(f.LoadGPR(rb), INT32_TYPE)),
INT64_TYPE);
} else {
return f.ZeroExtend(f.Truncate(f.LoadGPR(rb), INT32_TYPE), INT64_TYPE);
}
@ -54,9 +53,9 @@ Value* CalculateEA_0(PPCHIRBuilder& f, uint32_t ra, uint32_t rb) {
Value* CalculateEA_i(PPCHIRBuilder& f, uint32_t ra, uint64_t imm) {
#if TRUNCATE_ADDRESSES
return f.ZeroExtend(f.Add(
f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.LoadConstant((int32_t)imm)), INT64_TYPE);
return f.ZeroExtend(f.Add(f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.LoadConstant((int32_t)imm)),
INT64_TYPE);
#else
return f.Add(f.LoadGPR(ra), f.LoadConstant(imm));
#endif // TRUNCATE_ADDRESSES
@ -65,9 +64,9 @@ Value* CalculateEA_i(PPCHIRBuilder& f, uint32_t ra, uint64_t imm) {
Value* CalculateEA_0_i(PPCHIRBuilder& f, uint32_t ra, uint64_t imm) {
#if TRUNCATE_ADDRESSES
if (ra) {
return f.ZeroExtend(f.Add(
f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.LoadConstant((int32_t)imm)), INT64_TYPE);
return f.ZeroExtend(f.Add(f.Truncate(f.LoadGPR(ra), INT32_TYPE),
f.LoadConstant((int32_t)imm)),
INT64_TYPE);
} else {
return f.ZeroExtend(f.LoadConstant((int32_t)imm), INT64_TYPE);
}
@ -80,10 +79,9 @@ Value* CalculateEA_0_i(PPCHIRBuilder& f, uint32_t ra, uint64_t imm) {
#endif // TRUNCATE_ADDRESSES
}
// Integer load (A-13)
XEEMITTER(lbz, 0x88000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lbz, 0x88000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -96,7 +94,7 @@ XEEMITTER(lbz, 0x88000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lbzu, 0x8C000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lbzu, 0x8C000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// RT <- i56.0 || MEM(EA, 1)
// RA <- EA
@ -107,7 +105,7 @@ XEEMITTER(lbzu, 0x8C000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lbzux, 0x7C0000EE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lbzux, 0x7C0000EE, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// RT <- i56.0 || MEM(EA, 1)
// RA <- EA
@ -118,7 +116,7 @@ XEEMITTER(lbzux, 0x7C0000EE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lbzx, 0x7C0000AE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lbzx, 0x7C0000AE, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -131,7 +129,7 @@ XEEMITTER(lbzx, 0x7C0000AE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lha, 0xA8000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lha, 0xA8000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -144,17 +142,17 @@ XEEMITTER(lha, 0xA8000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lhau, 0xAC000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhau, 0xAC000000, D)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(lhaux, 0x7C0002EE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhaux, 0x7C0002EE, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(lhax, 0x7C0002AE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhax, 0x7C0002AE, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -167,7 +165,7 @@ XEEMITTER(lhax, 0x7C0002AE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lhz, 0xA0000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhz, 0xA0000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -180,7 +178,7 @@ XEEMITTER(lhz, 0xA0000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lhzu, 0xA4000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhzu, 0xA4000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// RT <- i48.0 || MEM(EA, 2)
// RA <- EA
@ -191,7 +189,7 @@ XEEMITTER(lhzu, 0xA4000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lhzux, 0x7C00026E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhzux, 0x7C00026E, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// RT <- i48.0 || MEM(EA, 2)
// RA <- EA
@ -202,7 +200,7 @@ XEEMITTER(lhzux, 0x7C00026E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lhzx, 0x7C00022E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhzx, 0x7C00022E, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -215,7 +213,7 @@ XEEMITTER(lhzx, 0x7C00022E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwa, 0xE8000002, DS )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwa, 0xE8000002, DS)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -228,7 +226,7 @@ XEEMITTER(lwa, 0xE8000002, DS )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwaux, 0x7C0002EA, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwaux, 0x7C0002EA, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// RT <- EXTS(MEM(EA, 4))
// RA <- EA
@ -239,7 +237,7 @@ XEEMITTER(lwaux, 0x7C0002EA, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwax, 0x7C0002AA, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwax, 0x7C0002AA, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -252,7 +250,7 @@ XEEMITTER(lwax, 0x7C0002AA, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwz, 0x80000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwz, 0x80000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -265,7 +263,7 @@ XEEMITTER(lwz, 0x80000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwzu, 0x84000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwzu, 0x84000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// RT <- i32.0 || MEM(EA, 4)
// RA <- EA
@ -276,7 +274,7 @@ XEEMITTER(lwzu, 0x84000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwzux, 0x7C00006E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwzux, 0x7C00006E, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// RT <- i32.0 || MEM(EA, 4)
// RA <- EA
@ -287,7 +285,7 @@ XEEMITTER(lwzux, 0x7C00006E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwzx, 0x7C00002E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwzx, 0x7C00002E, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -300,8 +298,7 @@ XEEMITTER(lwzx, 0x7C00002E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(ld, 0xE8000000, DS )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(ld, 0xE8000000, DS)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -314,7 +311,7 @@ XEEMITTER(ld, 0xE8000000, DS )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(ldu, 0xE8000001, DS )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(ldu, 0xE8000001, DS)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(DS || 0b00)
// RT <- MEM(EA, 8)
// RA <- EA
@ -325,7 +322,7 @@ XEEMITTER(ldu, 0xE8000001, DS )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(ldux, 0x7C00006A, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(ldux, 0x7C00006A, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// RT <- MEM(EA, 8)
// RA <- EA
@ -336,7 +333,7 @@ XEEMITTER(ldux, 0x7C00006A, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(ldx, 0x7C00002A, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(ldx, 0x7C00002A, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -349,10 +346,9 @@ XEEMITTER(ldx, 0x7C00002A, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
// Integer store (A-14)
XEEMITTER(stb, 0x98000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stb, 0x98000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -364,7 +360,7 @@ XEEMITTER(stb, 0x98000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stbu, 0x9C000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stbu, 0x9C000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// MEM(EA, 1) <- (RS)[56:63]
// RA <- EA
@ -374,7 +370,7 @@ XEEMITTER(stbu, 0x9C000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stbux, 0x7C0001EE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stbux, 0x7C0001EE, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// MEM(EA, 1) <- (RS)[56:63]
// RA <- EA
@ -384,7 +380,7 @@ XEEMITTER(stbux, 0x7C0001EE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stbx, 0x7C0001AE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stbx, 0x7C0001AE, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -396,7 +392,7 @@ XEEMITTER(stbx, 0x7C0001AE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(sth, 0xB0000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(sth, 0xB0000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -408,7 +404,7 @@ XEEMITTER(sth, 0xB0000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(sthu, 0xB4000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(sthu, 0xB4000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// MEM(EA, 2) <- (RS)[48:63]
// RA <- EA
@ -418,7 +414,7 @@ XEEMITTER(sthu, 0xB4000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(sthux, 0x7C00036E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(sthux, 0x7C00036E, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// MEM(EA, 2) <- (RS)[48:63]
// RA <- EA
@ -428,7 +424,7 @@ XEEMITTER(sthux, 0x7C00036E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(sthx, 0x7C00032E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(sthx, 0x7C00032E, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -440,7 +436,7 @@ XEEMITTER(sthx, 0x7C00032E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stw, 0x90000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stw, 0x90000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -452,7 +448,7 @@ XEEMITTER(stw, 0x90000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stwu, 0x94000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stwu, 0x94000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// MEM(EA, 4) <- (RS)[32:63]
// RA <- EA
@ -462,7 +458,7 @@ XEEMITTER(stwu, 0x94000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stwux, 0x7C00016E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stwux, 0x7C00016E, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// MEM(EA, 4) <- (RS)[32:63]
// RA <- EA
@ -472,7 +468,7 @@ XEEMITTER(stwux, 0x7C00016E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stwx, 0x7C00012E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stwx, 0x7C00012E, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -484,7 +480,7 @@ XEEMITTER(stwx, 0x7C00012E, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(std, 0xF8000000, DS )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(std, 0xF8000000, DS)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -496,7 +492,7 @@ XEEMITTER(std, 0xF8000000, DS )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stdu, 0xF8000001, DS )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stdu, 0xF8000001, DS)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(DS || 0b00)
// MEM(EA, 8) <- (RS)
// RA <- EA
@ -506,7 +502,7 @@ XEEMITTER(stdu, 0xF8000001, DS )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stdux, 0x7C00016A, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stdux, 0x7C00016A, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// MEM(EA, 8) <- (RS)
// RA <- EA
@ -528,10 +524,9 @@ XEEMITTER(stdx, 0x7C00012A, X)(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
// Integer load and store with byte reverse (A-1
XEEMITTER(lhbrx, 0x7C00062C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lhbrx, 0x7C00062C, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -544,7 +539,7 @@ XEEMITTER(lhbrx, 0x7C00062C, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwbrx, 0x7C00042C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwbrx, 0x7C00042C, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -557,7 +552,7 @@ XEEMITTER(lwbrx, 0x7C00042C, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(ldbrx, 0x7C000428, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(ldbrx, 0x7C000428, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -570,7 +565,7 @@ XEEMITTER(ldbrx, 0x7C000428, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(sthbrx, 0x7C00072C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(sthbrx, 0x7C00072C, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -582,7 +577,7 @@ XEEMITTER(sthbrx, 0x7C00072C, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stwbrx, 0x7C00052C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stwbrx, 0x7C00052C, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -594,7 +589,7 @@ XEEMITTER(stwbrx, 0x7C00052C, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stdbrx, 0x7C000528, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stdbrx, 0x7C000528, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -606,64 +601,61 @@ XEEMITTER(stdbrx, 0x7C000528, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
// Integer load and store multiple (A-16)
XEEMITTER(lmw, 0xB8000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lmw, 0xB8000000, D)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(stmw, 0xBC000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stmw, 0xBC000000, D)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
// Integer load and store string (A-17)
XEEMITTER(lswi, 0x7C0004AA, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lswi, 0x7C0004AA, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(lswx, 0x7C00042A, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lswx, 0x7C00042A, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(stswi, 0x7C0005AA, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stswi, 0x7C0005AA, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
XEEMITTER(stswx, 0x7C00052A, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stswx, 0x7C00052A, X)(PPCHIRBuilder& f, InstrData& i) {
XEINSTRNOTIMPLEMENTED();
return 1;
}
// Memory synchronization (A-18)
XEEMITTER(eieio, 0x7C0006AC, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(eieio, 0x7C0006AC, X)(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED();
f.Nop();
return 0;
}
XEEMITTER(sync, 0x7C0004AC, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(sync, 0x7C0004AC, X)(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED();
f.Nop();
return 0;
}
XEEMITTER(isync, 0x4C00012C, XL )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(isync, 0x4C00012C, XL)(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED();
f.Nop();
return 0;
}
XEEMITTER(ldarx, 0x7C0000A8, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(ldarx, 0x7C0000A8, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -679,7 +671,7 @@ XEEMITTER(ldarx, 0x7C0000A8, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lwarx, 0x7C000028, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lwarx, 0x7C000028, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -690,12 +682,13 @@ XEEMITTER(lwarx, 0x7C000028, X )(PPCHIRBuilder& f, InstrData& i) {
// RESERVE_ADDR <- real_addr(EA)
// RT <- i32.0 || MEM(EA, 4)
Value* ea = CalculateEA_0(f, i.X.RA, i.X.RB);
Value* rt = f.ZeroExtend(f.ByteSwap(f.LoadAcquire(ea, INT32_TYPE)), INT64_TYPE);
Value* rt =
f.ZeroExtend(f.ByteSwap(f.LoadAcquire(ea, INT32_TYPE)), INT64_TYPE);
f.StoreGPR(i.X.RT, rt);
return 0;
}
XEEMITTER(stdcx, 0x7C0001AD, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stdcx, 0x7C0001AD, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -712,7 +705,7 @@ XEEMITTER(stdcx, 0x7C0001AD, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stwcx, 0x7C00012D, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stwcx, 0x7C00012D, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -729,10 +722,9 @@ XEEMITTER(stwcx, 0x7C00012D, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
// Floating-point load (A-19)
XEEMITTER(lfd, 0xC8000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfd, 0xC8000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -745,7 +737,7 @@ XEEMITTER(lfd, 0xC8000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lfdu, 0xCC000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfdu, 0xCC000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// FRT <- MEM(EA, 8)
// RA <- EA
@ -756,7 +748,7 @@ XEEMITTER(lfdu, 0xCC000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lfdux, 0x7C0004EE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfdux, 0x7C0004EE, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// FRT <- MEM(EA, 8)
// RA <- EA
@ -767,7 +759,7 @@ XEEMITTER(lfdux, 0x7C0004EE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lfdx, 0x7C0004AE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfdx, 0x7C0004AE, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -780,7 +772,7 @@ XEEMITTER(lfdx, 0x7C0004AE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(lfs, 0xC0000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfs, 0xC0000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -789,39 +781,36 @@ XEEMITTER(lfs, 0xC0000000, D )(PPCHIRBuilder& f, InstrData& i) {
// FRT <- DOUBLE(MEM(EA, 4))
Value* ea = CalculateEA_0_i(f, i.D.RA, XEEXTS16(i.D.DS));
Value* rt = f.Convert(
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE),
FLOAT64_TYPE);
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.D.RT, rt);
return 0;
}
XEEMITTER(lfsu, 0xC4000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfsu, 0xC4000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// FRT <- DOUBLE(MEM(EA, 4))
// RA <- EA
Value* ea = CalculateEA_i(f, i.D.RA, XEEXTS16(i.D.DS));
Value* rt = f.Convert(
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE),
FLOAT64_TYPE);
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.D.RT, rt);
f.StoreGPR(i.D.RA, ea);
return 0;
}
XEEMITTER(lfsux, 0x7C00046E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfsux, 0x7C00046E, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// FRT <- DOUBLE(MEM(EA, 4))
// RA <- EA
Value* ea = CalculateEA(f, i.X.RA, i.X.RB);
Value* rt = f.Convert(
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE),
FLOAT64_TYPE);
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.X.RT, rt);
f.StoreGPR(i.X.RA, ea);
return 0;
}
XEEMITTER(lfsx, 0x7C00042E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(lfsx, 0x7C00042E, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -830,16 +819,14 @@ XEEMITTER(lfsx, 0x7C00042E, X )(PPCHIRBuilder& f, InstrData& i) {
// FRT <- DOUBLE(MEM(EA, 4))
Value* ea = CalculateEA_0(f, i.X.RA, i.X.RB);
Value* rt = f.Convert(
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE),
FLOAT64_TYPE);
f.Cast(f.ByteSwap(f.Load(ea, INT32_TYPE)), FLOAT32_TYPE), FLOAT64_TYPE);
f.StoreFPR(i.X.RT, rt);
return 0;
}
// Floating-point store (A-20)
XEEMITTER(stfd, 0xD8000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfd, 0xD8000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -851,7 +838,7 @@ XEEMITTER(stfd, 0xD8000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stfdu, 0xDC000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfdu, 0xDC000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// MEM(EA, 8) <- (FRS)
// RA <- EA
@ -861,7 +848,7 @@ XEEMITTER(stfdu, 0xDC000000, D )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stfdux, 0x7C0005EE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfdux, 0x7C0005EE, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// MEM(EA, 8) <- (FRS)
// RA <- EA
@ -871,7 +858,7 @@ XEEMITTER(stfdux, 0x7C0005EE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stfdx, 0x7C0005AE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfdx, 0x7C0005AE, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -883,7 +870,7 @@ XEEMITTER(stfdx, 0x7C0005AE, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(stfiwx, 0x7C0007AE, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfiwx, 0x7C0007AE, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -891,12 +878,12 @@ XEEMITTER(stfiwx, 0x7C0007AE, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- b + (RB)
// MEM(EA, 4) <- (FRS)[32:63]
Value* ea = CalculateEA_0(f, i.X.RA, i.X.RB);
f.Store(ea, f.ByteSwap(
f.Truncate(f.Cast(f.LoadFPR(i.X.RT), INT64_TYPE), INT32_TYPE)));
f.Store(ea, f.ByteSwap(f.Truncate(f.Cast(f.LoadFPR(i.X.RT), INT64_TYPE),
INT32_TYPE)));
return 0;
}
XEEMITTER(stfs, 0xD0000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfs, 0xD0000000, D)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -904,34 +891,34 @@ XEEMITTER(stfs, 0xD0000000, D )(PPCHIRBuilder& f, InstrData& i) {
// EA <- b + EXTS(D)
// MEM(EA, 4) <- SINGLE(FRS)
Value* ea = CalculateEA_0_i(f, i.D.RA, XEEXTS16(i.D.DS));
f.Store(ea, f.ByteSwap(f.Cast(
f.Convert(f.LoadFPR(i.D.RT), FLOAT32_TYPE), INT32_TYPE)));
f.Store(ea, f.ByteSwap(f.Cast(f.Convert(f.LoadFPR(i.D.RT), FLOAT32_TYPE),
INT32_TYPE)));
return 0;
}
XEEMITTER(stfsu, 0xD4000000, D )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfsu, 0xD4000000, D)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + EXTS(D)
// MEM(EA, 4) <- SINGLE(FRS)
// RA <- EA
Value* ea = CalculateEA_i(f, i.D.RA, XEEXTS16(i.D.DS));
f.Store(ea, f.ByteSwap(f.Cast(
f.Convert(f.LoadFPR(i.D.RT), FLOAT32_TYPE), INT32_TYPE)));
f.Store(ea, f.ByteSwap(f.Cast(f.Convert(f.LoadFPR(i.D.RT), FLOAT32_TYPE),
INT32_TYPE)));
f.StoreGPR(i.D.RA, ea);
return 0;
}
XEEMITTER(stfsux, 0x7C00056E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfsux, 0x7C00056E, X)(PPCHIRBuilder& f, InstrData& i) {
// EA <- (RA) + (RB)
// MEM(EA, 4) <- SINGLE(FRS)
// RA <- EA
Value* ea = CalculateEA(f, i.X.RA, i.X.RB);
f.Store(ea, f.ByteSwap(f.Cast(
f.Convert(f.LoadFPR(i.X.RT), FLOAT32_TYPE), INT32_TYPE)));
f.Store(ea, f.ByteSwap(f.Cast(f.Convert(f.LoadFPR(i.X.RT), FLOAT32_TYPE),
INT32_TYPE)));
f.StoreGPR(i.X.RA, ea);
return 0;
}
XEEMITTER(stfsx, 0x7C00052E, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(stfsx, 0x7C00052E, X)(PPCHIRBuilder& f, InstrData& i) {
// if RA = 0 then
// b <- 0
// else
@ -939,15 +926,14 @@ XEEMITTER(stfsx, 0x7C00052E, X )(PPCHIRBuilder& f, InstrData& i) {
// EA <- b + (RB)
// MEM(EA, 4) <- SINGLE(FRS)
Value* ea = CalculateEA_0(f, i.X.RA, i.X.RB);
f.Store(ea, f.ByteSwap(f.Cast(
f.Convert(f.LoadFPR(i.X.RT), FLOAT32_TYPE), INT32_TYPE)));
f.Store(ea, f.ByteSwap(f.Cast(f.Convert(f.LoadFPR(i.X.RT), FLOAT32_TYPE),
INT32_TYPE)));
return 0;
}
// Cache management (A-27)
XEEMITTER(dcbf, 0x7C0000AC, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(dcbf, 0x7C0000AC, X)(PPCHIRBuilder& f, InstrData& i) {
// No-op for now.
// TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED();
@ -955,7 +941,7 @@ XEEMITTER(dcbf, 0x7C0000AC, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(dcbst, 0x7C00006C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(dcbst, 0x7C00006C, X)(PPCHIRBuilder& f, InstrData& i) {
// No-op for now.
// TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED();
@ -963,7 +949,7 @@ XEEMITTER(dcbst, 0x7C00006C, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(dcbt, 0x7C00022C, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(dcbt, 0x7C00022C, X)(PPCHIRBuilder& f, InstrData& i) {
// No-op for now.
// TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED();
@ -971,7 +957,7 @@ XEEMITTER(dcbt, 0x7C00022C, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(dcbtst, 0x7C0001EC, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(dcbtst, 0x7C0001EC, X)(PPCHIRBuilder& f, InstrData& i) {
// No-op for now.
// TODO(benvanik): use prefetch
// XEINSTRNOTIMPLEMENTED();
@ -979,7 +965,7 @@ XEEMITTER(dcbtst, 0x7C0001EC, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(dcbz, 0x7C0007EC, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(dcbz, 0x7C0007EC, X)(PPCHIRBuilder& f, InstrData& i) {
// No-op for now.
// TODO(benvanik): use prefetch
// or dcbz128 0x7C2007EC
@ -988,98 +974,96 @@ XEEMITTER(dcbz, 0x7C0007EC, X )(PPCHIRBuilder& f, InstrData& i) {
return 0;
}
XEEMITTER(icbi, 0x7C0007AC, X )(PPCHIRBuilder& f, InstrData& i) {
XEEMITTER(icbi, 0x7C0007AC, X)(PPCHIRBuilder& f, InstrData& i) {
// XEINSTRNOTIMPLEMENTED();
f.Nop();
return 0;
}
void RegisterEmitCategoryMemory() {
XEREGISTERINSTR(lbz, 0x88000000);
XEREGISTERINSTR(lbzu, 0x8C000000);
XEREGISTERINSTR(lbzux, 0x7C0000EE);
XEREGISTERINSTR(lbzx, 0x7C0000AE);
XEREGISTERINSTR(lha, 0xA8000000);
XEREGISTERINSTR(lhau, 0xAC000000);
XEREGISTERINSTR(lhaux, 0x7C0002EE);
XEREGISTERINSTR(lhax, 0x7C0002AE);
XEREGISTERINSTR(lhz, 0xA0000000);
XEREGISTERINSTR(lhzu, 0xA4000000);
XEREGISTERINSTR(lhzux, 0x7C00026E);
XEREGISTERINSTR(lhzx, 0x7C00022E);
XEREGISTERINSTR(lwa, 0xE8000002);
XEREGISTERINSTR(lwaux, 0x7C0002EA);
XEREGISTERINSTR(lwax, 0x7C0002AA);
XEREGISTERINSTR(lwz, 0x80000000);
XEREGISTERINSTR(lwzu, 0x84000000);
XEREGISTERINSTR(lwzux, 0x7C00006E);
XEREGISTERINSTR(lwzx, 0x7C00002E);
XEREGISTERINSTR(ld, 0xE8000000);
XEREGISTERINSTR(ldu, 0xE8000001);
XEREGISTERINSTR(ldux, 0x7C00006A);
XEREGISTERINSTR(ldx, 0x7C00002A);
XEREGISTERINSTR(stb, 0x98000000);
XEREGISTERINSTR(stbu, 0x9C000000);
XEREGISTERINSTR(stbux, 0x7C0001EE);
XEREGISTERINSTR(stbx, 0x7C0001AE);
XEREGISTERINSTR(sth, 0xB0000000);
XEREGISTERINSTR(sthu, 0xB4000000);
XEREGISTERINSTR(sthux, 0x7C00036E);
XEREGISTERINSTR(sthx, 0x7C00032E);
XEREGISTERINSTR(stw, 0x90000000);
XEREGISTERINSTR(stwu, 0x94000000);
XEREGISTERINSTR(stwux, 0x7C00016E);
XEREGISTERINSTR(stwx, 0x7C00012E);
XEREGISTERINSTR(std, 0xF8000000);
XEREGISTERINSTR(stdu, 0xF8000001);
XEREGISTERINSTR(stdux, 0x7C00016A);
XEREGISTERINSTR(stdx, 0x7C00012A);
XEREGISTERINSTR(lhbrx, 0x7C00062C);
XEREGISTERINSTR(lwbrx, 0x7C00042C);
XEREGISTERINSTR(ldbrx, 0x7C000428);
XEREGISTERINSTR(sthbrx, 0x7C00072C);
XEREGISTERINSTR(stwbrx, 0x7C00052C);
XEREGISTERINSTR(stdbrx, 0x7C000528);
XEREGISTERINSTR(lmw, 0xB8000000);
XEREGISTERINSTR(stmw, 0xBC000000);
XEREGISTERINSTR(lswi, 0x7C0004AA);
XEREGISTERINSTR(lswx, 0x7C00042A);
XEREGISTERINSTR(stswi, 0x7C0005AA);
XEREGISTERINSTR(stswx, 0x7C00052A);
XEREGISTERINSTR(eieio, 0x7C0006AC);
XEREGISTERINSTR(sync, 0x7C0004AC);
XEREGISTERINSTR(isync, 0x4C00012C);
XEREGISTERINSTR(ldarx, 0x7C0000A8);
XEREGISTERINSTR(lwarx, 0x7C000028);
XEREGISTERINSTR(stdcx, 0x7C0001AD);
XEREGISTERINSTR(stwcx, 0x7C00012D);
XEREGISTERINSTR(lfd, 0xC8000000);
XEREGISTERINSTR(lfdu, 0xCC000000);
XEREGISTERINSTR(lfdux, 0x7C0004EE);
XEREGISTERINSTR(lfdx, 0x7C0004AE);
XEREGISTERINSTR(lfs, 0xC0000000);
XEREGISTERINSTR(lfsu, 0xC4000000);
XEREGISTERINSTR(lfsux, 0x7C00046E);
XEREGISTERINSTR(lfsx, 0x7C00042E);
XEREGISTERINSTR(stfd, 0xD8000000);
XEREGISTERINSTR(stfdu, 0xDC000000);
XEREGISTERINSTR(stfdux, 0x7C0005EE);
XEREGISTERINSTR(stfdx, 0x7C0005AE);
XEREGISTERINSTR(stfiwx, 0x7C0007AE);
XEREGISTERINSTR(stfs, 0xD0000000);
XEREGISTERINSTR(stfsu, 0xD4000000);
XEREGISTERINSTR(stfsux, 0x7C00056E);
XEREGISTERINSTR(stfsx, 0x7C00052E);
XEREGISTERINSTR(dcbf, 0x7C0000AC);
XEREGISTERINSTR(dcbst, 0x7C00006C);
XEREGISTERINSTR(dcbt, 0x7C00022C);
XEREGISTERINSTR(dcbtst, 0x7C0001EC);
XEREGISTERINSTR(dcbz, 0x7C0007EC);
XEREGISTERINSTR(icbi, 0x7C0007AC);
XEREGISTERINSTR(lbz, 0x88000000);
XEREGISTERINSTR(lbzu, 0x8C000000);
XEREGISTERINSTR(lbzux, 0x7C0000EE);
XEREGISTERINSTR(lbzx, 0x7C0000AE);
XEREGISTERINSTR(lha, 0xA8000000);
XEREGISTERINSTR(lhau, 0xAC000000);
XEREGISTERINSTR(lhaux, 0x7C0002EE);
XEREGISTERINSTR(lhax, 0x7C0002AE);
XEREGISTERINSTR(lhz, 0xA0000000);
XEREGISTERINSTR(lhzu, 0xA4000000);
XEREGISTERINSTR(lhzux, 0x7C00026E);
XEREGISTERINSTR(lhzx, 0x7C00022E);
XEREGISTERINSTR(lwa, 0xE8000002);
XEREGISTERINSTR(lwaux, 0x7C0002EA);
XEREGISTERINSTR(lwax, 0x7C0002AA);
XEREGISTERINSTR(lwz, 0x80000000);
XEREGISTERINSTR(lwzu, 0x84000000);
XEREGISTERINSTR(lwzux, 0x7C00006E);
XEREGISTERINSTR(lwzx, 0x7C00002E);
XEREGISTERINSTR(ld, 0xE8000000);
XEREGISTERINSTR(ldu, 0xE8000001);
XEREGISTERINSTR(ldux, 0x7C00006A);
XEREGISTERINSTR(ldx, 0x7C00002A);
XEREGISTERINSTR(stb, 0x98000000);
XEREGISTERINSTR(stbu, 0x9C000000);
XEREGISTERINSTR(stbux, 0x7C0001EE);
XEREGISTERINSTR(stbx, 0x7C0001AE);
XEREGISTERINSTR(sth, 0xB0000000);
XEREGISTERINSTR(sthu, 0xB4000000);
XEREGISTERINSTR(sthux, 0x7C00036E);
XEREGISTERINSTR(sthx, 0x7C00032E);
XEREGISTERINSTR(stw, 0x90000000);
XEREGISTERINSTR(stwu, 0x94000000);
XEREGISTERINSTR(stwux, 0x7C00016E);
XEREGISTERINSTR(stwx, 0x7C00012E);
XEREGISTERINSTR(std, 0xF8000000);
XEREGISTERINSTR(stdu, 0xF8000001);
XEREGISTERINSTR(stdux, 0x7C00016A);
XEREGISTERINSTR(stdx, 0x7C00012A);
XEREGISTERINSTR(lhbrx, 0x7C00062C);
XEREGISTERINSTR(lwbrx, 0x7C00042C);
XEREGISTERINSTR(ldbrx, 0x7C000428);
XEREGISTERINSTR(sthbrx, 0x7C00072C);
XEREGISTERINSTR(stwbrx, 0x7C00052C);
XEREGISTERINSTR(stdbrx, 0x7C000528);
XEREGISTERINSTR(lmw, 0xB8000000);
XEREGISTERINSTR(stmw, 0xBC000000);
XEREGISTERINSTR(lswi, 0x7C0004AA);
XEREGISTERINSTR(lswx, 0x7C00042A);
XEREGISTERINSTR(stswi, 0x7C0005AA);
XEREGISTERINSTR(stswx, 0x7C00052A);
XEREGISTERINSTR(eieio, 0x7C0006AC);
XEREGISTERINSTR(sync, 0x7C0004AC);
XEREGISTERINSTR(isync, 0x4C00012C);
XEREGISTERINSTR(ldarx, 0x7C0000A8);
XEREGISTERINSTR(lwarx, 0x7C000028);
XEREGISTERINSTR(stdcx, 0x7C0001AD);
XEREGISTERINSTR(stwcx, 0x7C00012D);
XEREGISTERINSTR(lfd, 0xC8000000);
XEREGISTERINSTR(lfdu, 0xCC000000);
XEREGISTERINSTR(lfdux, 0x7C0004EE);
XEREGISTERINSTR(lfdx, 0x7C0004AE);
XEREGISTERINSTR(lfs, 0xC0000000);
XEREGISTERINSTR(lfsu, 0xC4000000);
XEREGISTERINSTR(lfsux, 0x7C00046E);
XEREGISTERINSTR(lfsx, 0x7C00042E);
XEREGISTERINSTR(stfd, 0xD8000000);
XEREGISTERINSTR(stfdu, 0xDC000000);
XEREGISTERINSTR(stfdux, 0x7C0005EE);
XEREGISTERINSTR(stfdx, 0x7C0005AE);
XEREGISTERINSTR(stfiwx, 0x7C0007AE);
XEREGISTERINSTR(stfs, 0xD0000000);
XEREGISTERINSTR(stfsu, 0xD4000000);
XEREGISTERINSTR(stfsux, 0x7C00056E);
XEREGISTERINSTR(stfsx, 0x7C00052E);
XEREGISTERINSTR(dcbf, 0x7C0000AC);
XEREGISTERINSTR(dcbst, 0x7C00006C);
XEREGISTERINSTR(dcbt, 0x7C00022C);
XEREGISTERINSTR(dcbtst, 0x7C0001EC);
XEREGISTERINSTR(dcbz, 0x7C0007EC);
XEREGISTERINSTR(icbi, 0x7C0007AC);
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -15,44 +15,40 @@
#include <alloy/frontend/ppc/ppc_emit.h>
#include <alloy/frontend/ppc/ppc_translator.h>
using namespace alloy;
using namespace alloy::frontend;
using namespace alloy::frontend::ppc;
using namespace alloy::runtime;
namespace alloy {
namespace frontend {
namespace ppc {
using alloy::runtime::Function;
using alloy::runtime::FunctionInfo;
using alloy::runtime::Runtime;
namespace {
void InitializeIfNeeded();
void CleanupOnShutdown();
void InitializeIfNeeded();
void CleanupOnShutdown();
void InitializeIfNeeded() {
static bool has_initialized = false;
if (has_initialized) {
return;
}
has_initialized = true;
RegisterEmitCategoryAltivec();
RegisterEmitCategoryALU();
RegisterEmitCategoryControl();
RegisterEmitCategoryFPU();
RegisterEmitCategoryMemory();
atexit(CleanupOnShutdown);
void InitializeIfNeeded() {
static bool has_initialized = false;
if (has_initialized) {
return;
}
has_initialized = true;
void CleanupOnShutdown() {
}
RegisterEmitCategoryAltivec();
RegisterEmitCategoryALU();
RegisterEmitCategoryControl();
RegisterEmitCategoryFPU();
RegisterEmitCategoryMemory();
atexit(CleanupOnShutdown);
}
void CleanupOnShutdown() {}
PPCFrontend::PPCFrontend(Runtime* runtime) :
Frontend(runtime) {
PPCFrontend::PPCFrontend(Runtime* runtime) : Frontend(runtime) {
InitializeIfNeeded();
ContextInfo* info = new ContextInfo(
sizeof(PPCContext),
offsetof(PPCContext, thread_state));
ContextInfo* info =
new ContextInfo(sizeof(PPCContext), offsetof(PPCContext, thread_state));
// Add fields/etc.
context_info_ = info;
}
@ -61,8 +57,7 @@ PPCFrontend::~PPCFrontend() {
// Force cleanup now before we deinit.
translator_pool_.Reset();
alloy::tracing::WriteEvent(EventType::Deinit({
}));
alloy::tracing::WriteEvent(EventType::Deinit({}));
}
int PPCFrontend::Initialize() {
@ -71,14 +66,12 @@ int PPCFrontend::Initialize() {
return result;
}
alloy::tracing::WriteEvent(EventType::Init({
}));
alloy::tracing::WriteEvent(EventType::Init({}));
return result;
}
int PPCFrontend::DeclareFunction(
FunctionInfo* symbol_info) {
int PPCFrontend::DeclareFunction(FunctionInfo* symbol_info) {
// Could scan or something here.
// Could also check to see if it's a well-known function type and classify
// for later.
@ -87,12 +80,16 @@ int PPCFrontend::DeclareFunction(
return 0;
}
int PPCFrontend::DefineFunction(
FunctionInfo* symbol_info, uint32_t debug_info_flags,
Function** out_function) {
int PPCFrontend::DefineFunction(FunctionInfo* symbol_info,
uint32_t debug_info_flags,
Function** out_function) {
PPCTranslator* translator = translator_pool_.Allocate(this);
int result = translator->Translate(
symbol_info, debug_info_flags, out_function);
int result =
translator->Translate(symbol_info, debug_info_flags, out_function);
translator_pool_.Release(translator);
return result;
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -15,7 +15,6 @@
#include <alloy/frontend/frontend.h>
namespace alloy {
namespace frontend {
namespace ppc {
@ -23,26 +22,23 @@ namespace ppc {
class PPCTranslator;
class PPCFrontend : public Frontend {
public:
public:
PPCFrontend(runtime::Runtime* runtime);
virtual ~PPCFrontend();
virtual int Initialize();
virtual int DeclareFunction(
runtime::FunctionInfo* symbol_info);
virtual int DefineFunction(
runtime::FunctionInfo* symbol_info, uint32_t debug_info_flags,
runtime::Function** out_function);
virtual int DeclareFunction(runtime::FunctionInfo* symbol_info);
virtual int DefineFunction(runtime::FunctionInfo* symbol_info,
uint32_t debug_info_flags,
runtime::Function** out_function);
private:
private:
TypePool<PPCTranslator, PPCFrontend*> translator_pool_;
};
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_FRONTEND_H_

View File

@ -18,22 +18,25 @@
#include <alloy/hir/label.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::frontend;
using namespace alloy::frontend::ppc;
namespace alloy {
namespace frontend {
namespace ppc {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::hir;
using namespace alloy::runtime;
using alloy::hir::Label;
using alloy::hir::TypeName;
using alloy::hir::Value;
using alloy::runtime::Runtime;
using alloy::runtime::FunctionInfo;
PPCHIRBuilder::PPCHIRBuilder(PPCFrontend* frontend) :
frontend_(frontend),
HIRBuilder() {
PPCHIRBuilder::PPCHIRBuilder(PPCFrontend* frontend)
: frontend_(frontend), HIRBuilder() {
comment_buffer_ = new StringBuffer(4096);
}
PPCHIRBuilder::~PPCHIRBuilder() {
delete comment_buffer_;
}
PPCHIRBuilder::~PPCHIRBuilder() { delete comment_buffer_; }
void PPCHIRBuilder::Reset() {
start_address_ = 0;
@ -51,13 +54,11 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) {
symbol_info_ = symbol_info;
start_address_ = symbol_info->address();
instr_count_ =
(symbol_info->end_address() - symbol_info->address()) / 4 + 1;
instr_count_ = (symbol_info->end_address() - symbol_info->address()) / 4 + 1;
with_debug_info_ = with_debug_info;
if (with_debug_info_) {
Comment("%s fn %.8X-%.8X %s",
symbol_info->module()->name(),
Comment("%s fn %.8X-%.8X %s", symbol_info->module()->name(),
symbol_info->address(), symbol_info->end_address(),
symbol_info->name());
}
@ -121,7 +122,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) {
if (!i.type) {
XELOGCPU("Invalid instruction %.8X %.8X", i.address, i.code);
Comment("INVALID!");
//TraceInvalidInstruction(i);
// TraceInvalidInstruction(i);
continue;
}
@ -134,11 +135,11 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) {
}
if (!i.type->emit || emit(*this, i)) {
XELOGCPU("Unimplemented instr %.8X %.8X %s",
i.address, i.code, i.type->name);
XELOGCPU("Unimplemented instr %.8X %.8X %s", i.address, i.code,
i.type->name);
Comment("UNIMPLEMENTED!");
//DebugBreak();
//TraceInvalidInstruction(i);
// DebugBreak();
// TraceInvalidInstruction(i);
}
}
@ -147,8 +148,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, bool with_debug_info) {
void PPCHIRBuilder::AnnotateLabel(uint64_t address, Label* label) {
char name_buffer[13];
xesnprintfa(name_buffer, XECOUNT(name_buffer),
"loc_%.8X", (uint32_t)address);
xesnprintfa(name_buffer, XECOUNT(name_buffer), "loc_%.8X", (uint32_t)address);
label->name = (char*)arena_->Alloc(sizeof(name_buffer));
xe_copy_struct(label->name, name_buffer, sizeof(name_buffer));
}
@ -197,10 +197,10 @@ Label* PPCHIRBuilder::LookupLabel(uint64_t address) {
return label;
}
//Value* PPCHIRBuilder::LoadXER() {
// Value* PPCHIRBuilder::LoadXER() {
//}
//
//void PPCHIRBuilder::StoreXER(Value* value) {
// void PPCHIRBuilder::StoreXER(Value* value) {
//}
Value* PPCHIRBuilder::LoadLR() {
@ -235,13 +235,12 @@ void PPCHIRBuilder::StoreCR(uint32_t n, Value* value) {
XEASSERTALWAYS();
}
void PPCHIRBuilder::UpdateCR(
uint32_t n, Value* lhs, bool is_signed) {
void PPCHIRBuilder::UpdateCR(uint32_t n, Value* lhs, bool is_signed) {
UpdateCR(n, lhs, LoadZero(lhs->type), is_signed);
}
void PPCHIRBuilder::UpdateCR(
uint32_t n, Value* lhs, Value* rhs, bool is_signed) {
void PPCHIRBuilder::UpdateCR(uint32_t n, Value* lhs, Value* rhs,
bool is_signed) {
if (is_signed) {
Value* lt = CompareSLT(lhs, rhs);
StoreContext(offsetof(PPCContext, cr0) + (4 * n) + 0, lt);
@ -264,7 +263,8 @@ void PPCHIRBuilder::UpdateCR6(Value* src_value) {
// Testing for all 1's and all 0's.
// if (Rc) CR6 = all_equal | 0 | none_equal | 0
// TODO(benvanik): efficient instruction?
StoreContext(offsetof(PPCContext, cr6.cr6_all_equal), IsFalse(Not(src_value)));
StoreContext(offsetof(PPCContext, cr6.cr6_all_equal),
IsFalse(Not(src_value)));
StoreContext(offsetof(PPCContext, cr6.cr6_none_equal), IsFalse(src_value));
}
@ -282,9 +282,7 @@ Value* PPCHIRBuilder::LoadXER() {
return NULL;
}
void PPCHIRBuilder::StoreXER(Value* value) {
XEASSERTALWAYS();
}
void PPCHIRBuilder::StoreXER(Value* value) { XEASSERTALWAYS(); }
Value* PPCHIRBuilder::LoadCA() {
return LoadContext(offsetof(PPCContext, xer_ca), INT8_TYPE);
@ -305,48 +303,41 @@ void PPCHIRBuilder::StoreSAT(Value* value) {
}
Value* PPCHIRBuilder::LoadGPR(uint32_t reg) {
return LoadContext(
offsetof(PPCContext, r) + reg * 8, INT64_TYPE);
return LoadContext(offsetof(PPCContext, r) + reg * 8, INT64_TYPE);
}
void PPCHIRBuilder::StoreGPR(uint32_t reg, Value* value) {
XEASSERT(value->type == INT64_TYPE);
StoreContext(
offsetof(PPCContext, r) + reg * 8, value);
StoreContext(offsetof(PPCContext, r) + reg * 8, value);
}
Value* PPCHIRBuilder::LoadFPR(uint32_t reg) {
return LoadContext(
offsetof(PPCContext, f) + reg * 8, FLOAT64_TYPE);
return LoadContext(offsetof(PPCContext, f) + reg * 8, FLOAT64_TYPE);
}
void PPCHIRBuilder::StoreFPR(uint32_t reg, Value* value) {
XEASSERT(value->type == FLOAT64_TYPE);
StoreContext(
offsetof(PPCContext, f) + reg * 8, value);
StoreContext(offsetof(PPCContext, f) + reg * 8, value);
}
Value* PPCHIRBuilder::LoadVR(uint32_t reg) {
return LoadContext(
offsetof(PPCContext, v) + reg * 16, VEC128_TYPE);
return LoadContext(offsetof(PPCContext, v) + reg * 16, VEC128_TYPE);
}
void PPCHIRBuilder::StoreVR(uint32_t reg, Value* value) {
XEASSERT(value->type == VEC128_TYPE);
StoreContext(
offsetof(PPCContext, v) + reg * 16, value);
StoreContext(offsetof(PPCContext, v) + reg * 16, value);
}
Value* PPCHIRBuilder::LoadAcquire(
Value* address, TypeName type, uint32_t load_flags) {
AtomicExchange(
LoadContext(offsetof(PPCContext, reserve_address), INT64_TYPE),
Truncate(address, INT32_TYPE));
Value* PPCHIRBuilder::LoadAcquire(Value* address, TypeName type,
uint32_t load_flags) {
AtomicExchange(LoadContext(offsetof(PPCContext, reserve_address), INT64_TYPE),
Truncate(address, INT32_TYPE));
return Load(address, type, load_flags);
}
Value* PPCHIRBuilder::StoreRelease(
Value* address, Value* value, uint32_t store_flags) {
Value* PPCHIRBuilder::StoreRelease(Value* address, Value* value,
uint32_t store_flags) {
Value* old_address = AtomicExchange(
LoadContext(offsetof(PPCContext, reserve_address), INT64_TYPE),
LoadZero(INT32_TYPE));
@ -357,3 +348,7 @@ Value* PPCHIRBuilder::StoreRelease(
MarkLabel(skip_label);
return eq;
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -15,19 +15,18 @@
#include <alloy/runtime/function.h>
#include <alloy/runtime/symbol_info.h>
namespace alloy {
namespace frontend {
namespace ppc {
class PPCFrontend;
class PPCHIRBuilder : public hir::HIRBuilder {
using Instr = alloy::hir::Instr;
using Label = alloy::hir::Label;
using Value = alloy::hir::Value;
public:
public:
PPCHIRBuilder(PPCFrontend* frontend);
virtual ~PPCHIRBuilder();
@ -53,9 +52,9 @@ public:
void StoreFPSCR(Value* value);
Value* LoadXER();
void StoreXER(Value* value);
//void UpdateXERWithOverflow();
//void UpdateXERWithOverflowAndCarry();
//void StoreOV(Value* value);
// void UpdateXERWithOverflow();
// void UpdateXERWithOverflowAndCarry();
// void StoreOV(Value* value);
Value* LoadCA();
void StoreCA(Value* value);
Value* LoadSAT();
@ -68,31 +67,30 @@ public:
Value* LoadVR(uint32_t reg);
void StoreVR(uint32_t reg, Value* value);
Value* LoadAcquire(Value* address, hir::TypeName type, uint32_t load_flags = 0);
Value* LoadAcquire(Value* address, hir::TypeName type,
uint32_t load_flags = 0);
Value* StoreRelease(Value* address, Value* value, uint32_t store_flags = 0);
private:
private:
void AnnotateLabel(uint64_t address, Label* label);
private:
PPCFrontend* frontend_;
private:
PPCFrontend* frontend_;
// Reset whenever needed:
StringBuffer* comment_buffer_;
// Reset each Emit:
bool with_debug_info_;
bool with_debug_info_;
runtime::FunctionInfo* symbol_info_;
uint64_t start_address_;
uint64_t instr_count_;
Instr** instr_offset_list_;
Label** label_list_;
uint64_t start_address_;
uint64_t instr_count_;
Instr** instr_offset_list_;
Label** label_list_;
};
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_HIR_BUILDER_H_

View File

@ -13,11 +13,9 @@
#include <alloy/frontend/ppc/ppc_instr_tables.h>
using namespace alloy;
using namespace alloy::frontend;
using namespace alloy::frontend::ppc;
namespace alloy {
namespace frontend {
namespace ppc {
void InstrOperand::Dump(std::string& out_str) {
if (display) {
@ -92,21 +90,18 @@ void InstrOperand::Dump(std::string& out_str) {
out_str += buffer;
}
void InstrAccessBits::Clear() {
spr = cr = gpr = fpr = 0;
}
void InstrAccessBits::Clear() { spr = cr = gpr = fpr = 0; }
void InstrAccessBits::Extend(InstrAccessBits& other) {
spr |= other.spr;
cr |= other.cr;
gpr |= other.gpr;
fpr |= other.fpr;
vr31_0 |= other.vr31_0;
vr63_32 |= other.vr63_32;
vr95_64 |= other.vr95_64;
vr127_96 |= other.vr127_96;
}
spr |= other.spr;
cr |= other.cr;
gpr |= other.gpr;
fpr |= other.fpr;
vr31_0 |= other.vr31_0;
vr63_32 |= other.vr63_32;
vr95_64 |= other.vr95_64;
vr127_96 |= other.vr127_96;
}
void InstrAccessBits::MarkAccess(InstrRegister& reg) {
uint64_t bits = 0;
@ -128,7 +123,7 @@ void InstrAccessBits::MarkAccess(InstrRegister& reg) {
spr |= bits << (2 * 2);
break;
case InstrRegister::kCR:
cr |= bits << (2 * reg.ordinal);
cr |= bits << (2 * reg.ordinal);
break;
case InstrRegister::kFPSCR:
spr |= bits << (2 * 3);
@ -281,41 +276,31 @@ void InstrAccessBits::Dump(std::string& out_str) {
out_str = str.str();
}
void InstrDisasm::Init(const char* name, const char* info, uint32_t flags) {
this->name = name;
this->info = info;
this->flags = flags;
}
void InstrDisasm::AddLR(InstrRegister::Access access) {
}
void InstrDisasm::AddLR(InstrRegister::Access access) {}
void InstrDisasm::AddCTR(InstrRegister::Access access) {
}
void InstrDisasm::AddCTR(InstrRegister::Access access) {}
void InstrDisasm::AddCR(uint32_t bf, InstrRegister::Access access) {
}
void InstrDisasm::AddCR(uint32_t bf, InstrRegister::Access access) {}
void InstrDisasm::AddFPSCR(InstrRegister::Access access) {
}
void InstrDisasm::AddFPSCR(InstrRegister::Access access) {}
void InstrDisasm::AddRegOperand(
InstrRegister::RegisterSet set, uint32_t ordinal,
InstrRegister::Access access, const char* display) {
}
void InstrDisasm::AddRegOperand(InstrRegister::RegisterSet set,
uint32_t ordinal, InstrRegister::Access access,
const char* display) {}
void InstrDisasm::AddSImmOperand(uint64_t value, size_t width,
const char* display) {
}
const char* display) {}
void InstrDisasm::AddUImmOperand(uint64_t value, size_t width,
const char* display) {
}
const char* display) {}
int InstrDisasm::Finish() {
return 0;
}
int InstrDisasm::Finish() { return 0; }
void InstrDisasm::Dump(std::string& out_str, size_t pad) {
out_str = name;
@ -330,47 +315,55 @@ void InstrDisasm::Dump(std::string& out_str, size_t pad) {
}
}
InstrType* alloy::frontend::ppc::GetInstrType(uint32_t code) {
InstrType* GetInstrType(uint32_t code) {
// Fast lookup via tables.
InstrType* slot = NULL;
switch (code >> 26) {
case 4:
// Opcode = 4, index = bits 10-0 (10)
slot = alloy::frontend::ppc::tables::instr_table_4[XESELECTBITS(code, 0, 10)];
break;
case 19:
// Opcode = 19, index = bits 10-1 (10)
slot = alloy::frontend::ppc::tables::instr_table_19[XESELECTBITS(code, 1, 10)];
break;
case 30:
// Opcode = 30, index = bits 4-1 (4)
// Special cased to an uber instruction.
slot = alloy::frontend::ppc::tables::instr_table_30[XESELECTBITS(code, 0, 0)];
break;
case 31:
// Opcode = 31, index = bits 10-1 (10)
slot = alloy::frontend::ppc::tables::instr_table_31[XESELECTBITS(code, 1, 10)];
break;
case 58:
// Opcode = 58, index = bits 1-0 (2)
slot = alloy::frontend::ppc::tables::instr_table_58[XESELECTBITS(code, 0, 1)];
break;
case 59:
// Opcode = 59, index = bits 5-1 (5)
slot = alloy::frontend::ppc::tables::instr_table_59[XESELECTBITS(code, 1, 5)];
break;
case 62:
// Opcode = 62, index = bits 1-0 (2)
slot = alloy::frontend::ppc::tables::instr_table_62[XESELECTBITS(code, 0, 1)];
break;
case 63:
// Opcode = 63, index = bits 10-1 (10)
slot = alloy::frontend::ppc::tables::instr_table_63[XESELECTBITS(code, 1, 10)];
break;
default:
slot = alloy::frontend::ppc::tables::instr_table[XESELECTBITS(code, 26, 31)];
break;
case 4:
// Opcode = 4, index = bits 10-0 (10)
slot = alloy::frontend::ppc::tables::instr_table_4[XESELECTBITS(code, 0,
10)];
break;
case 19:
// Opcode = 19, index = bits 10-1 (10)
slot = alloy::frontend::ppc::tables::instr_table_19[XESELECTBITS(code, 1,
10)];
break;
case 30:
// Opcode = 30, index = bits 4-1 (4)
// Special cased to an uber instruction.
slot = alloy::frontend::ppc::tables::instr_table_30[XESELECTBITS(code, 0,
0)];
break;
case 31:
// Opcode = 31, index = bits 10-1 (10)
slot = alloy::frontend::ppc::tables::instr_table_31[XESELECTBITS(code, 1,
10)];
break;
case 58:
// Opcode = 58, index = bits 1-0 (2)
slot = alloy::frontend::ppc::tables::instr_table_58[XESELECTBITS(code, 0,
1)];
break;
case 59:
// Opcode = 59, index = bits 5-1 (5)
slot = alloy::frontend::ppc::tables::instr_table_59[XESELECTBITS(code, 1,
5)];
break;
case 62:
// Opcode = 62, index = bits 1-0 (2)
slot = alloy::frontend::ppc::tables::instr_table_62[XESELECTBITS(code, 0,
1)];
break;
case 63:
// Opcode = 63, index = bits 10-1 (10)
slot = alloy::frontend::ppc::tables::instr_table_63[XESELECTBITS(code, 1,
10)];
break;
default:
slot =
alloy::frontend::ppc::tables::instr_table[XESELECTBITS(code, 26, 31)];
break;
}
if (slot && slot->opcode) {
return slot;
@ -379,8 +372,7 @@ InstrType* alloy::frontend::ppc::GetInstrType(uint32_t code) {
// Slow lookup via linear scan.
// This is primarily due to laziness. It could be made fast like the others.
for (size_t n = 0;
n < XECOUNT(alloy::frontend::ppc::tables::instr_table_scan);
n++) {
n < XECOUNT(alloy::frontend::ppc::tables::instr_table_scan); n++) {
slot = &(alloy::frontend::ppc::tables::instr_table_scan[n]);
if (slot->opcode == (code & slot->opcode_mask)) {
return slot;
@ -390,7 +382,7 @@ InstrType* alloy::frontend::ppc::GetInstrType(uint32_t code) {
return NULL;
}
int alloy::frontend::ppc::RegisterInstrEmit(uint32_t code, InstrEmitFn emit) {
int RegisterInstrEmit(uint32_t code, InstrEmitFn emit) {
InstrType* instr_type = GetInstrType(code);
XEASSERTNOTNULL(instr_type);
if (!instr_type) {
@ -400,3 +392,7 @@ int alloy::frontend::ppc::RegisterInstrEmit(uint32_t code, InstrEmitFn emit) {
instr_type->emit = emit;
return 0;
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -15,81 +15,73 @@
#include <string>
#include <vector>
namespace alloy {
namespace frontend {
namespace ppc {
// TODO(benvanik): rename these
typedef enum {
kXEPPCInstrFormatI = 0,
kXEPPCInstrFormatB = 1,
kXEPPCInstrFormatSC = 2,
kXEPPCInstrFormatD = 3,
kXEPPCInstrFormatDS = 4,
kXEPPCInstrFormatX = 5,
kXEPPCInstrFormatXL = 6,
kXEPPCInstrFormatXFX = 7,
kXEPPCInstrFormatXFL = 8,
kXEPPCInstrFormatXS = 9,
kXEPPCInstrFormatXO = 10,
kXEPPCInstrFormatA = 11,
kXEPPCInstrFormatM = 12,
kXEPPCInstrFormatMD = 13,
kXEPPCInstrFormatMDS = 14,
kXEPPCInstrFormatVXA = 15,
kXEPPCInstrFormatVX = 16,
kXEPPCInstrFormatVXR = 17,
kXEPPCInstrFormatVX128 = 18,
kXEPPCInstrFormatVX128_1 = 19,
kXEPPCInstrFormatVX128_2 = 20,
kXEPPCInstrFormatVX128_3 = 21,
kXEPPCInstrFormatVX128_4 = 22,
kXEPPCInstrFormatVX128_5 = 23,
kXEPPCInstrFormatVX128_P = 24,
kXEPPCInstrFormatVX128_R = 25,
kXEPPCInstrFormatXDSS = 26,
kXEPPCInstrFormatI = 0,
kXEPPCInstrFormatB = 1,
kXEPPCInstrFormatSC = 2,
kXEPPCInstrFormatD = 3,
kXEPPCInstrFormatDS = 4,
kXEPPCInstrFormatX = 5,
kXEPPCInstrFormatXL = 6,
kXEPPCInstrFormatXFX = 7,
kXEPPCInstrFormatXFL = 8,
kXEPPCInstrFormatXS = 9,
kXEPPCInstrFormatXO = 10,
kXEPPCInstrFormatA = 11,
kXEPPCInstrFormatM = 12,
kXEPPCInstrFormatMD = 13,
kXEPPCInstrFormatMDS = 14,
kXEPPCInstrFormatVXA = 15,
kXEPPCInstrFormatVX = 16,
kXEPPCInstrFormatVXR = 17,
kXEPPCInstrFormatVX128 = 18,
kXEPPCInstrFormatVX128_1 = 19,
kXEPPCInstrFormatVX128_2 = 20,
kXEPPCInstrFormatVX128_3 = 21,
kXEPPCInstrFormatVX128_4 = 22,
kXEPPCInstrFormatVX128_5 = 23,
kXEPPCInstrFormatVX128_P = 24,
kXEPPCInstrFormatVX128_R = 25,
kXEPPCInstrFormatXDSS = 26,
} xe_ppc_instr_format_e;
typedef enum {
kXEPPCInstrMaskVXR = 0xFC0003FF,
kXEPPCInstrMaskVXA = 0xFC00003F,
kXEPPCInstrMaskVX128 = 0xFC0003D0,
kXEPPCInstrMaskVX128_1 = 0xFC0007F3,
kXEPPCInstrMaskVX128_2 = 0xFC000210,
kXEPPCInstrMaskVX128_3 = 0xFC0007F0,
kXEPPCInstrMaskVX128_4 = 0xFC000730,
kXEPPCInstrMaskVX128_5 = 0xFC000010,
kXEPPCInstrMaskVX128_P = 0xFC000630,
kXEPPCInstrMaskVX128_R = 0xFC000390,
kXEPPCInstrMaskVXR = 0xFC0003FF,
kXEPPCInstrMaskVXA = 0xFC00003F,
kXEPPCInstrMaskVX128 = 0xFC0003D0,
kXEPPCInstrMaskVX128_1 = 0xFC0007F3,
kXEPPCInstrMaskVX128_2 = 0xFC000210,
kXEPPCInstrMaskVX128_3 = 0xFC0007F0,
kXEPPCInstrMaskVX128_4 = 0xFC000730,
kXEPPCInstrMaskVX128_5 = 0xFC000010,
kXEPPCInstrMaskVX128_P = 0xFC000630,
kXEPPCInstrMaskVX128_R = 0xFC000390,
} xe_ppc_instr_mask_e;
typedef enum {
kXEPPCInstrTypeGeneral = (1 << 0),
kXEPPCInstrTypeBranch = (1 << 1),
kXEPPCInstrTypeBranchCond = kXEPPCInstrTypeBranch | (1 << 2),
kXEPPCInstrTypeGeneral = (1 << 0),
kXEPPCInstrTypeBranch = (1 << 1),
kXEPPCInstrTypeBranchCond = kXEPPCInstrTypeBranch | (1 << 2),
kXEPPCInstrTypeBranchAlways = kXEPPCInstrTypeBranch | (1 << 3),
kXEPPCInstrTypeSyscall = (1 << 4),
kXEPPCInstrTypeSyscall = (1 << 4),
} xe_ppc_instr_type_e;
typedef enum {
kXEPPCInstrFlagReserved = 0,
kXEPPCInstrFlagReserved = 0,
} xe_ppc_instr_flag_e;
class InstrType;
static inline int64_t XEEXTS16(uint32_t v) {
return (int64_t)((int16_t)v);
}
static inline int64_t XEEXTS16(uint32_t v) { return (int64_t)((int16_t)v); }
static inline int64_t XEEXTS26(uint32_t v) {
return (int64_t)(v & 0x02000000 ? (int32_t)v | 0xFC000000 : (int32_t)(v));
}
static inline uint64_t XEEXTZ16(uint32_t v) {
return (uint64_t)((uint16_t)v);
}
static inline uint64_t XEEXTZ16(uint32_t v) { return (uint64_t)((uint16_t)v); }
static inline uint64_t XEMASK(uint32_t mstart, uint32_t mstop) {
// if mstart ≤ mstop then
// mask[mstart:mstop] = ones
@ -105,289 +97,338 @@ static inline uint64_t XEMASK(uint32_t mstart, uint32_t mstop) {
return mstart <= mstop ? value : ~value;
}
typedef struct {
InstrType* type;
uint64_t address;
InstrType* type;
uint64_t address;
union {
uint32_t code;
uint32_t code;
// kXEPPCInstrFormatI
struct {
uint32_t LK : 1;
uint32_t AA : 1;
uint32_t LI : 24;
uint32_t : 6;
uint32_t LK : 1;
uint32_t AA : 1;
uint32_t LI : 24;
uint32_t:
6;
} I;
// kXEPPCInstrFormatB
struct {
uint32_t LK : 1;
uint32_t AA : 1;
uint32_t BD : 14;
uint32_t BI : 5;
uint32_t BO : 5;
uint32_t : 6;
uint32_t LK : 1;
uint32_t AA : 1;
uint32_t BD : 14;
uint32_t BI : 5;
uint32_t BO : 5;
uint32_t:
6;
} B;
// kXEPPCInstrFormatSC
// kXEPPCInstrFormatD
struct {
uint32_t DS : 16;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t DS : 16;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} D;
// kXEPPCInstrFormatDS
struct {
uint32_t : 2;
uint32_t DS : 14;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t:
2;
uint32_t DS : 14;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} DS;
// kXEPPCInstrFormatX
struct {
uint32_t Rc : 1;
uint32_t : 10;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t:
10;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} X;
// kXEPPCInstrFormatXL
struct {
uint32_t LK : 1;
uint32_t : 10;
uint32_t BB : 5;
uint32_t BI : 5;
uint32_t BO : 5;
uint32_t : 6;
uint32_t LK : 1;
uint32_t:
10;
uint32_t BB : 5;
uint32_t BI : 5;
uint32_t BO : 5;
uint32_t:
6;
} XL;
// kXEPPCInstrFormatXFX
struct {
uint32_t : 1;
uint32_t : 10;
uint32_t spr : 10;
uint32_t RT : 5;
uint32_t : 6;
uint32_t:
1;
uint32_t:
10;
uint32_t spr : 10;
uint32_t RT : 5;
uint32_t:
6;
} XFX;
// kXEPPCInstrFormatXFL
struct {
uint32_t Rc : 1;
uint32_t : 10;
uint32_t RB : 5;
uint32_t W : 1;
uint32_t FM : 8;
uint32_t L : 1;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t:
10;
uint32_t RB : 5;
uint32_t W : 1;
uint32_t FM : 8;
uint32_t L : 1;
uint32_t:
6;
} XFL;
// kXEPPCInstrFormatXS
struct {
uint32_t Rc : 1;
uint32_t SH5 : 1;
uint32_t : 9;
uint32_t SH : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t SH5 : 1;
uint32_t:
9;
uint32_t SH : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} XS;
// kXEPPCInstrFormatXO
struct {
uint32_t Rc : 1;
uint32_t : 9;
uint32_t OE : 1;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t:
9;
uint32_t OE : 1;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} XO;
// kXEPPCInstrFormatA
struct {
uint32_t Rc : 1;
uint32_t XO : 5;
uint32_t FRC : 5;
uint32_t FRB : 5;
uint32_t FRA : 5;
uint32_t FRT : 5;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t XO : 5;
uint32_t FRC : 5;
uint32_t FRB : 5;
uint32_t FRA : 5;
uint32_t FRT : 5;
uint32_t:
6;
} A;
// kXEPPCInstrFormatM
struct {
uint32_t Rc : 1;
uint32_t ME : 5;
uint32_t MB : 5;
uint32_t SH : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t ME : 5;
uint32_t MB : 5;
uint32_t SH : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} M;
// kXEPPCInstrFormatMD
struct {
uint32_t Rc : 1;
uint32_t SH5 : 1;
uint32_t idx : 3;
uint32_t MB5 : 1;
uint32_t MB : 5;
uint32_t SH : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t SH5 : 1;
uint32_t idx : 3;
uint32_t MB5 : 1;
uint32_t MB : 5;
uint32_t SH : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} MD;
// kXEPPCInstrFormatMDS
struct {
uint32_t Rc : 1;
uint32_t idx : 4;
uint32_t MB5 : 1;
uint32_t MB : 5;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t : 6;
uint32_t Rc : 1;
uint32_t idx : 4;
uint32_t MB5 : 1;
uint32_t MB : 5;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t RT : 5;
uint32_t:
6;
} MDS;
// kXEPPCInstrFormatVXA
struct {
uint32_t : 6;
uint32_t VC : 5;
uint32_t VB : 5;
uint32_t VA : 5;
uint32_t VD : 5;
uint32_t : 6;
uint32_t:
6;
uint32_t VC : 5;
uint32_t VB : 5;
uint32_t VA : 5;
uint32_t VD : 5;
uint32_t:
6;
} VXA;
// kXEPPCInstrFormatVX
struct {
uint32_t : 11;
uint32_t VB : 5;
uint32_t VA : 5;
uint32_t VD : 5;
uint32_t : 6;
uint32_t:
11;
uint32_t VB : 5;
uint32_t VA : 5;
uint32_t VD : 5;
uint32_t:
6;
} VX;
// kXEPPCInstrFormatVXR
struct {
uint32_t : 10;
uint32_t Rc : 1;
uint32_t VB : 5;
uint32_t VA : 5;
uint32_t VD : 5;
uint32_t : 6;
uint32_t:
10;
uint32_t Rc : 1;
uint32_t VB : 5;
uint32_t VA : 5;
uint32_t VD : 5;
uint32_t:
6;
} VXR;
// kXEPPCInstrFormatVX128
struct {
// VD128 = VD128l | (VD128h << 5)
// VA128 = VA128l | (VA128h << 5) | (VA128H << 6)
// VB128 = VB128l | (VB128h << 5)
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t : 1;
uint32_t VA128h : 1;
uint32_t : 4;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t : 6;
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t:
1;
uint32_t VA128h : 1;
uint32_t:
4;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128;
// kXEPPCInstrFormatVX128_1
struct {
// VD128 = VD128l | (VD128h << 5)
uint32_t : 2;
uint32_t VD128h : 2;
uint32_t : 7;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t VD128l : 5;
uint32_t : 6;
// VD128 = VD128l | (VD128h << 5)
uint32_t:
2;
uint32_t VD128h : 2;
uint32_t:
7;
uint32_t RB : 5;
uint32_t RA : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128_1;
// kXEPPCInstrFormatVX128_2
struct {
// VD128 = VD128l | (VD128h << 5)
// VA128 = VA128l | (VA128h << 5) | (VA128H << 6)
// VB128 = VB128l | (VB128h << 5)
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t : 1;
uint32_t VA128h : 1;
uint32_t VC : 3;
uint32_t : 1;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t : 6;
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t:
1;
uint32_t VA128h : 1;
uint32_t VC : 3;
uint32_t:
1;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128_2;
// kXEPPCInstrFormatVX128_3
struct {
// VD128 = VD128l | (VD128h << 5)
// VB128 = VB128l | (VB128h << 5)
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t : 7;
uint32_t VB128l : 5;
uint32_t IMM : 5;
uint32_t VD128l : 5;
uint32_t : 6;
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t:
7;
uint32_t VB128l : 5;
uint32_t IMM : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128_3;
// kXEPPCInstrFormatVX128_4
struct {
// VD128 = VD128l | (VD128h << 5)
// VB128 = VB128l | (VB128h << 5)
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t : 2;
uint32_t z : 2;
uint32_t : 3;
uint32_t VB128l : 5;
uint32_t IMM : 5;
uint32_t VD128l : 5;
uint32_t : 6;
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t:
2;
uint32_t z : 2;
uint32_t:
3;
uint32_t VB128l : 5;
uint32_t IMM : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128_4;
// kXEPPCInstrFormatVX128_5
struct {
// VD128 = VD128l | (VD128h << 5)
// VA128 = VA128l | (VA128h << 5) | (VA128H << 6)
// VB128 = VB128l | (VB128h << 5)
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t : 1;
uint32_t VA128h : 1;
uint32_t SH : 4;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t : 6;
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t:
1;
uint32_t VA128h : 1;
uint32_t SH : 4;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128_5;
// kXEPPCInstrFormatVX128_P
struct {
// VD128 = VD128l | (VD128h << 5)
// VB128 = VB128l | (VB128h << 5)
// PERM = PERMl | (PERMh << 5)
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t : 2;
uint32_t PERMh : 3;
uint32_t : 2;
uint32_t VB128l : 5;
uint32_t PERMl : 5;
uint32_t VD128l : 5;
uint32_t : 6;
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t:
2;
uint32_t PERMh : 3;
uint32_t:
2;
uint32_t VB128l : 5;
uint32_t PERMl : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128_P;
// kXEPPCInstrFormatVX128_R
struct {
// VD128 = VD128l | (VD128h << 5)
// VA128 = VA128l | (VA128h << 5) | (VA128H << 6)
// VB128 = VB128l | (VB128h << 5)
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t : 1;
uint32_t VA128h : 1;
uint32_t Rc : 1;
uint32_t : 3;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t : 6;
uint32_t VB128h : 2;
uint32_t VD128h : 2;
uint32_t:
1;
uint32_t VA128h : 1;
uint32_t Rc : 1;
uint32_t:
3;
uint32_t VA128H : 1;
uint32_t VB128l : 5;
uint32_t VA128l : 5;
uint32_t VD128l : 5;
uint32_t:
6;
} VX128_R;
// kXEPPCInstrFormatXDSS
struct {
@ -395,31 +436,29 @@ typedef struct {
};
} InstrData;
typedef struct {
enum RegisterSet {
kXER,
kLR,
kCTR,
kCR, // 0-7
kCR, // 0-7
kFPSCR,
kGPR, // 0-31
kFPR, // 0-31
kVMX, // 0-127
kGPR, // 0-31
kFPR, // 0-31
kVMX, // 0-127
};
enum Access {
kRead = 1 << 0,
kWrite = 1 << 1,
kReadWrite = kRead | kWrite,
kRead = 1 << 0,
kWrite = 1 << 1,
kReadWrite = kRead | kWrite,
};
RegisterSet set;
uint32_t ordinal;
Access access;
uint32_t ordinal;
Access access;
} InstrRegister;
typedef struct {
enum OperandType {
kRegister,
@ -431,30 +470,34 @@ typedef struct {
union {
InstrRegister reg;
struct {
bool is_signed;
uint64_t value;
size_t width;
bool is_signed;
uint64_t value;
size_t width;
} imm;
};
void Dump(std::string& out_str);
} InstrOperand;
class InstrAccessBits {
public:
InstrAccessBits() :
spr(0), cr(0), gpr(0), fpr(0),
vr31_0(0), vr63_32(0), vr95_64(0), vr127_96(0) {
}
public:
InstrAccessBits()
: spr(0),
cr(0),
gpr(0),
fpr(0),
vr31_0(0),
vr63_32(0),
vr95_64(0),
vr127_96(0) {}
// Bitmasks derived from the accesses to registers.
// Format is 2 bits for each register, even bits indicating reads and odds
// indicating writes.
uint64_t spr; // fpcsr/ctr/lr/xer
uint64_t cr; // cr7/6/5/4/3/2/1/0
uint64_t gpr; // r31-0
uint64_t fpr; // f31-0
uint64_t spr; // fpcsr/ctr/lr/xer
uint64_t cr; // cr7/6/5/4/3/2/1/0
uint64_t gpr; // r31-0
uint64_t fpr; // f31-0
uint64_t vr31_0;
uint64_t vr63_32;
uint64_t vr95_64;
@ -466,21 +509,20 @@ public:
void Dump(std::string& out_str);
};
class InstrDisasm {
public:
public:
enum Flags {
kOE = 1 << 0,
kRc = 1 << 1,
kCA = 1 << 2,
kLR = 1 << 4,
kFP = 1 << 5,
kVMX = 1 << 6,
kOE = 1 << 0,
kRc = 1 << 1,
kCA = 1 << 2,
kLR = 1 << 4,
kFP = 1 << 5,
kVMX = 1 << 6,
};
const char* name;
const char* info;
uint32_t flags;
const char* name;
const char* info;
uint32_t flags;
void Init(const char* name, const char* info, uint32_t flags);
void AddLR(InstrRegister::Access access);
@ -496,32 +538,27 @@ public:
void Dump(std::string& out_str, size_t pad = 13);
};
typedef void (*InstrDisasmFn)(InstrData& i, StringBuffer* str);
typedef void* InstrEmitFn;
class InstrType {
public:
uint32_t opcode;
uint32_t opcode_mask; // Only used for certain opcodes (altivec, etc).
uint32_t format; // xe_ppc_instr_format_e
uint32_t type; // xe_ppc_instr_type_e
uint32_t flags; // xe_ppc_instr_flag_e
public:
uint32_t opcode;
uint32_t opcode_mask; // Only used for certain opcodes (altivec, etc).
uint32_t format; // xe_ppc_instr_format_e
uint32_t type; // xe_ppc_instr_type_e
uint32_t flags; // xe_ppc_instr_flag_e
InstrDisasmFn disasm;
char name[16];
char name[16];
InstrEmitFn emit;
InstrEmitFn emit;
};
InstrType* GetInstrType(uint32_t code);
int RegisterInstrEmit(uint32_t code, InstrEmitFn emit);
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_INSTR_H_

File diff suppressed because it is too large Load Diff

View File

@ -16,18 +16,15 @@
#include <alloy/frontend/ppc/ppc_instr.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::frontend;
using namespace alloy::frontend::ppc;
using namespace alloy::runtime;
namespace alloy {
namespace frontend {
namespace ppc {
using alloy::runtime::FunctionInfo;
PPCScanner::PPCScanner(PPCFrontend* frontend) :
frontend_(frontend) {
}
PPCScanner::PPCScanner(PPCFrontend* frontend) : frontend_(frontend) {}
PPCScanner::~PPCScanner() {
}
PPCScanner::~PPCScanner() {}
bool PPCScanner::IsRestGprLr(uint64_t address) {
FunctionInfo* symbol_info;
@ -80,9 +77,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// Check if the function starts with a mfspr lr, as that's a good indication
// of whether or not this is a normal function with a prolog/epilog.
// Some valid leaf functions won't have this, but most will.
if (address == start_address &&
i.type &&
i.type->opcode == 0x7C0002A6 &&
if (address == start_address && i.type && i.type->opcode == 0x7C0002A6 &&
(((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F)) == 8) {
starts_with_mfspr_lr = true;
}
@ -104,8 +99,8 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// This is generally a return.
if (furthest_target > address) {
// Remaining targets within function, not end.
XELOGSDB("ignoring blr %.8X (branch to %.8X)",
address, furthest_target);
XELOGSDB("ignoring blr %.8X (branch to %.8X)", address,
furthest_target);
} else {
// Function end point.
XELOGSDB("function end %.8X", address);
@ -131,7 +126,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// b/ba/bl/bla
uint32_t target =
(uint32_t)XEEXTS26(i.I.LI << 2) + (i.I.AA ? 0 : (int32_t)address);
if (i.I.LK) {
XELOGSDB("bl %.8X -> %.8X", address, target);
// Queue call target if needed.
@ -142,16 +137,15 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// If the target is back into the function and there's no further target
// we are at the end of a function.
// (Indirect branches may still go beyond, but no way of knowing).
if (target >= start_address &&
target < address && furthest_target <= address) {
if (target >= start_address && target < address &&
furthest_target <= address) {
XELOGSDB("function end %.8X (back b)", address);
ends_fn = true;
}
// If the target is not a branch and it goes to before the current
// address it's definitely a tail call.
if (!ends_fn &&
target < start_address && furthest_target <= address) {
if (!ends_fn && target < start_address && furthest_target <= address) {
XELOGSDB("function end %.8X (back b before addr)", address);
ends_fn = true;
}
@ -160,9 +154,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// Note that sometimes functions stick this in a basic block *inside*
// of the function somewhere, so ensure we don't have any branches over
// it.
if (!ends_fn &&
furthest_target <= address &&
IsRestGprLr(target)) {
if (!ends_fn && furthest_target <= address && IsRestGprLr(target)) {
XELOGSDB("function end %.8X (__restgprlr_*)", address);
ends_fn = true;
}
@ -174,9 +166,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// b KeBugCheck
// This check may hit on functions that jump over data code, so only
// trigger this check in leaf functions (no mfspr lr/prolog).
if (!ends_fn &&
!starts_with_mfspr_lr &&
blocks_found == 1) {
if (!ends_fn && !starts_with_mfspr_lr && blocks_found == 1) {
XELOGSDB("HEURISTIC: ending at simple leaf thunk %.8X", address);
ends_fn = true;
}
@ -206,7 +196,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// TODO(benvanik): perhaps queue up for a speculative check? I think
// we are running over tail-call functions here that branch to
// somewhere else.
//GetOrInsertFunction(target);
// GetOrInsertFunction(target);
}
}
ends_block = true;
@ -220,7 +210,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// Queue call target if needed.
// TODO(benvanik): see if this is correct - not sure anyone makes
// function calls with bcl.
//GetOrInsertFunction(target);
// GetOrInsertFunction(target);
} else {
XELOGSDB("bc %.8X -> %.8X", address, target);
@ -259,8 +249,8 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
address += 4;
if (end_address && address > end_address) {
// Hmm....
XELOGSDB("Ran over function bounds! %.8X-%.8X",
start_address, end_address);
XELOGSDB("Ran over function bounds! %.8X-%.8X", start_address,
end_address);
break;
}
}
@ -270,8 +260,8 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// from someplace valid (like method hints) this may indicate an error.
// It's also possible that we guessed in hole-filling and there's another
// function below this one.
XELOGSDB("Function ran under: %.8X-%.8X ended at %.8X",
start_address, end_address, address + 4);
XELOGSDB("Function ran under: %.8X-%.8X ended at %.8X", start_address,
end_address, address + 4);
}
symbol_info->set_end_address(address);
@ -300,8 +290,7 @@ std::vector<BlockInfo> PPCScanner::FindBlocks(FunctionInfo* symbol_info) {
bool in_block = false;
uint64_t block_start = 0;
InstrData i;
for (uint64_t address = start_address;
address <= end_address; address += 4) {
for (uint64_t address = start_address; address <= end_address; address += 4) {
i.address = address;
i.code = XEGETUINT32BE(p + address);
if (!i.code) {
@ -330,12 +319,12 @@ std::vector<BlockInfo> PPCScanner::FindBlocks(FunctionInfo* symbol_info) {
ends_block = true;
} else if (i.type->opcode == 0x48000000) {
// b/ba/bl/bla
//uint32_t target =
// uint32_t target =
// (uint32_t)XEEXTS26(i.I.LI << 2) + (i.I.AA ? 0 : (int32_t)address);
ends_block = true;
} else if (i.type->opcode == 0x40000000) {
// bc/bca/bcl/bcla
//uint32_t target =
// uint32_t target =
// (uint32_t)XEEXTS16(i.B.BD << 2) + (i.B.AA ? 0 : (int32_t)address);
ends_block = true;
} else if (i.type->opcode == 0x4C000020) {
@ -349,16 +338,14 @@ std::vector<BlockInfo> PPCScanner::FindBlocks(FunctionInfo* symbol_info) {
if (ends_block) {
in_block = false;
block_map[block_start] = {
block_start,
address,
block_start, address,
};
}
}
if (in_block) {
block_map[block_start] = {
block_start,
end_address,
block_start, end_address,
};
}
@ -368,3 +355,7 @@ std::vector<BlockInfo> PPCScanner::FindBlocks(FunctionInfo* symbol_info) {
}
return blocks;
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -13,7 +13,6 @@
#include <alloy/core.h>
#include <alloy/runtime/symbol_info.h>
namespace alloy {
namespace frontend {
namespace ppc {
@ -25,9 +24,8 @@ typedef struct BlockInfo_t {
uint64_t end_address;
} BlockInfo;
class PPCScanner {
public:
public:
PPCScanner(PPCFrontend* frontend);
~PPCScanner();
@ -35,17 +33,15 @@ public:
std::vector<BlockInfo> FindBlocks(runtime::FunctionInfo* symbol_info);
private:
private:
bool IsRestGprLr(uint64_t address);
private:
private:
PPCFrontend* frontend_;
};
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_SCANNER_H_

View File

@ -19,17 +19,20 @@
#include <alloy/frontend/ppc/ppc_scanner.h>
#include <alloy/runtime/runtime.h>
using namespace alloy;
using namespace alloy::backend;
using namespace alloy::compiler;
using namespace alloy::frontend;
using namespace alloy::frontend::ppc;
using namespace alloy::hir;
namespace alloy {
namespace frontend {
namespace ppc {
// TODO(benvanik): remove when enums redefined.
using namespace alloy::runtime;
using alloy::backend::Backend;
using alloy::compiler::Compiler;
using alloy::runtime::Function;
using alloy::runtime::FunctionInfo;
namespace passes = alloy::compiler::passes;
PPCTranslator::PPCTranslator(PPCFrontend* frontend) :
frontend_(frontend) {
PPCTranslator::PPCTranslator(PPCFrontend* frontend) : frontend_(frontend) {
Backend* backend = frontend->runtime()->backend();
scanner_ = new PPCScanner(frontend);
@ -54,21 +57,21 @@ PPCTranslator::PPCTranslator(PPCFrontend* frontend) :
if (validate) compiler_->AddPass(new passes::ValidationPass());
compiler_->AddPass(new passes::SimplificationPass());
if (validate) compiler_->AddPass(new passes::ValidationPass());
//compiler_->AddPass(new passes::DeadStoreEliminationPass());
//if (validate) compiler_->AddPass(new passes::ValidationPass());
// compiler_->AddPass(new passes::DeadStoreEliminationPass());
// if (validate) compiler_->AddPass(new passes::ValidationPass());
compiler_->AddPass(new passes::DeadCodeEliminationPass());
if (validate) compiler_->AddPass(new passes::ValidationPass());
//// Removes all unneeded variables. Try not to add new ones after this.
//compiler_->AddPass(new passes::ValueReductionPass());
//if (validate) compiler_->AddPass(new passes::ValidationPass());
// compiler_->AddPass(new passes::ValueReductionPass());
// if (validate) compiler_->AddPass(new passes::ValidationPass());
// Register allocation for the target backend.
// Will modify the HIR to add loads/stores.
// This should be the last pass before finalization, as after this all
// registers are assigned and ready to be emitted.
compiler_->AddPass(new passes::RegisterAllocationPass(
backend->machine_info()));
compiler_->AddPass(
new passes::RegisterAllocationPass(backend->machine_info()));
if (validate) compiler_->AddPass(new passes::ValidationPass());
// Must come last. The HIR is not really HIR after this.
@ -82,10 +85,9 @@ PPCTranslator::~PPCTranslator() {
delete scanner_;
}
int PPCTranslator::Translate(
FunctionInfo* symbol_info,
uint32_t debug_info_flags,
Function** out_function) {
int PPCTranslator::Translate(FunctionInfo* symbol_info,
uint32_t debug_info_flags,
Function** out_function) {
SCOPE_profile_cpu_f("alloy");
// Scan the function to find its extents. We only need to do this if we
@ -139,10 +141,8 @@ int PPCTranslator::Translate(
}
// Assemble to backend machine code.
result = assembler_->Assemble(
symbol_info, builder_,
debug_info_flags, debug_info,
out_function);
result = assembler_->Assemble(symbol_info, builder_, debug_info_flags,
debug_info, out_function);
XEEXPECTZERO(result);
result = 0;
@ -158,15 +158,14 @@ XECLEANUP:
return result;
};
void PPCTranslator::DumpSource(
runtime::FunctionInfo* symbol_info, StringBuffer* string_buffer) {
void PPCTranslator::DumpSource(runtime::FunctionInfo* symbol_info,
StringBuffer* string_buffer) {
Memory* memory = frontend_->memory();
const uint8_t* p = memory->membase();
string_buffer->Append("%s fn %.8X-%.8X %s\n",
symbol_info->module()->name(),
symbol_info->address(), symbol_info->end_address(),
symbol_info->name());
string_buffer->Append("%s fn %.8X-%.8X %s\n", symbol_info->module()->name(),
symbol_info->address(), symbol_info->end_address(),
symbol_info->name());
auto blocks = scanner_->FindBlocks(symbol_info);
@ -182,10 +181,8 @@ void PPCTranslator::DumpSource(
i.type = GetInstrType(i.code);
// Check labels.
if (block_it != blocks.end() &&
block_it->start_address == address) {
string_buffer->Append(
"%.8X loc_%.8X:\n", address, address);
if (block_it != blocks.end() && block_it->start_address == address) {
string_buffer->Append("%.8X loc_%.8X:\n", address, address);
++block_it;
}
@ -194,3 +191,7 @@ void PPCTranslator::DumpSource(
string_buffer->Append("\n");
}
}
} // namespace ppc
} // namespace frontend
} // namespace alloy

View File

@ -15,7 +15,6 @@
#include <alloy/compiler/compiler.h>
#include <alloy/runtime/symbol_info.h>
namespace alloy {
namespace frontend {
namespace ppc {
@ -24,34 +23,30 @@ class PPCFrontend;
class PPCHIRBuilder;
class PPCScanner;
class PPCTranslator {
public:
public:
PPCTranslator(PPCFrontend* frontend);
~PPCTranslator();
int Translate(runtime::FunctionInfo* symbol_info,
uint32_t debug_info_flags,
int Translate(runtime::FunctionInfo* symbol_info, uint32_t debug_info_flags,
runtime::Function** out_function);
private:
private:
void DumpSource(runtime::FunctionInfo* symbol_info,
StringBuffer* string_buffer);
private:
PPCFrontend* frontend_;
PPCScanner* scanner_;
PPCHIRBuilder* builder_;
compiler::Compiler* compiler_;
backend::Assembler* assembler_;
private:
PPCFrontend* frontend_;
PPCScanner* scanner_;
PPCHIRBuilder* builder_;
compiler::Compiler* compiler_;
backend::Assembler* assembler_;
StringBuffer string_buffer_;
StringBuffer string_buffer_;
};
} // namespace ppc
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_PPC_PPC_TRANSLATOR_H_

View File

@ -13,18 +13,16 @@
#include <alloy/tracing/tracing.h>
#include <alloy/tracing/event_type.h>
namespace alloy {
namespace frontend {
const uint32_t ALLOY_FRONTEND = alloy::tracing::EventType::ALLOY_FRONTEND;
class EventType {
public:
public:
enum {
ALLOY_FRONTEND_INIT = ALLOY_FRONTEND | (1),
ALLOY_FRONTEND_DEINIT = ALLOY_FRONTEND | (2),
ALLOY_FRONTEND_INIT = ALLOY_FRONTEND | (1),
ALLOY_FRONTEND_DEINIT = ALLOY_FRONTEND | (2),
};
typedef struct Init_s {
@ -35,9 +33,7 @@ public:
} Deinit;
};
} // namespace frontend
} // namespace alloy
#endif // ALLOY_FRONTEND_TRACING_H_

View File

@ -11,9 +11,8 @@
#include <alloy/hir/instr.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
void Block::AssertNoCycles() {
Instr* hare = instr_head;
@ -37,3 +36,6 @@ void Block::AssertNoCycles() {
}
}
}
} // namespace hir
} // namespace alloy

View File

@ -14,7 +14,6 @@
XEDECLARECLASS1(llvm, BitVector);
namespace alloy {
namespace hir {
@ -23,14 +22,14 @@ class HIRBuilder;
class Instr;
class Label;
class Edge {
public:
public:
enum EdgeFlags {
UNCONDITIONAL = (1 << 0),
DOMINATES = (1 << 1),
};
public:
public:
Edge* outgoing_next;
Edge* outgoing_prev;
Edge* incoming_next;
@ -42,9 +41,8 @@ public:
uint32_t flags;
};
class Block {
public:
public:
Arena* arena;
Block* next;
@ -65,9 +63,7 @@ public:
void AssertNoCycles();
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_BLOCK_H_

File diff suppressed because it is too large Load Diff

View File

@ -17,17 +17,15 @@
#include <alloy/hir/opcodes.h>
#include <alloy/hir/value.h>
namespace alloy {
namespace hir {
enum FunctionAttributes {
FUNCTION_ATTRIB_INLINE = (1 << 1),
FUNCTION_ATTRIB_INLINE = (1 << 1),
};
class HIRBuilder {
public:
public:
HIRBuilder();
virtual ~HIRBuilder();
@ -86,10 +84,8 @@ public:
void Branch(Label* label, uint32_t branch_flags = 0);
void Branch(Block* block, uint32_t branch_flags = 0);
void BranchTrue(Value* cond, Label* label,
uint32_t branch_flags = 0);
void BranchFalse(Value* cond, Label* label,
uint32_t branch_flags = 0);
void BranchTrue(Value* cond, Label* label, uint32_t branch_flags = 0);
void BranchFalse(Value* cond, Label* label, uint32_t branch_flags = 0);
// phi type_name, Block* b1, Value* v1, Block* b2, Value* v2, etc
@ -162,13 +158,12 @@ public:
uint32_t arithmetic_flags = 0);
Value* VectorAdd(Value* value1, Value* value2, TypeName part_type,
uint32_t arithmetic_flags = 0);
Value* Sub(Value* value1, Value* value2,
uint32_t arithmetic_flags = 0);
Value* Sub(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* Mul(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* MulHi(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* Div(Value* value1, Value* value2, uint32_t arithmetic_flags = 0);
Value* MulAdd(Value* value1, Value* value2, Value* value3); // (1 * 2) + 3
Value* MulSub(Value* value1, Value* value2, Value* value3); // (1 * 2) - 3
Value* MulAdd(Value* value1, Value* value2, Value* value3); // (1 * 2) + 3
Value* MulSub(Value* value1, Value* value2, Value* value3); // (1 * 2) - 3
Value* Neg(Value* value);
Value* Abs(Value* value);
Value* Sqrt(Value* value);
@ -208,48 +203,44 @@ public:
Value* Pack(Value* value, uint32_t pack_flags = 0);
Value* Unpack(Value* value, uint32_t pack_flags = 0);
Value* CompareExchange(Value* address,
Value* compare_value, Value* exchange_value);
Value* CompareExchange(Value* address, Value* compare_value,
Value* exchange_value);
Value* AtomicExchange(Value* address, Value* new_value);
Value* AtomicAdd(Value* address, Value* value);
Value* AtomicSub(Value* address, Value* value);
protected:
protected:
void DumpValue(StringBuffer* str, Value* value);
void DumpOp(
StringBuffer* str, OpcodeSignatureType sig_type, Instr::Op* op);
void DumpOp(StringBuffer* str, OpcodeSignatureType sig_type, Instr::Op* op);
Value* AllocValue(TypeName type = INT64_TYPE);
Value* CloneValue(Value* source);
private:
private:
Block* AppendBlock();
void EndBlock();
bool IsUnconditionalJump(Instr* instr);
Instr* AppendInstr(const OpcodeInfo& opcode, uint16_t flags,
Value* dest = 0);
Instr* AppendInstr(const OpcodeInfo& opcode, uint16_t flags, Value* dest = 0);
Value* CompareXX(const OpcodeInfo& opcode, Value* value1, Value* value2);
Value* VectorCompareXX(
const OpcodeInfo& opcode, Value* value1, Value* value2, TypeName part_type);
Value* VectorCompareXX(const OpcodeInfo& opcode, Value* value1, Value* value2,
TypeName part_type);
protected:
Arena* arena_;
protected:
Arena* arena_;
uint32_t attributes_;
uint32_t attributes_;
uint32_t next_label_id_;
uint32_t next_value_ordinal_;
uint32_t next_label_id_;
uint32_t next_value_ordinal_;
std::vector<Value*> locals_;
Block* block_head_;
Block* block_tail_;
Block* current_block_;
Block* block_head_;
Block* block_tail_;
Block* current_block_;
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_HIR_BUILDER_H_

View File

@ -11,9 +11,8 @@
#include <alloy/hir/block.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
void Instr::set_src1(Value* value) {
if (src1.value == value) {
@ -114,3 +113,6 @@ void Instr::Remove() {
block->instr_tail = prev;
}
}
} // namespace hir
} // namespace alloy

View File

@ -14,9 +14,11 @@
#include <alloy/hir/opcodes.h>
#include <alloy/hir/value.h>
namespace alloy { namespace runtime { class FunctionInfo; } }
namespace alloy {
namespace runtime {
class FunctionInfo;
} // namespace runtime
} // namespace alloy
namespace alloy {
namespace hir {
@ -25,26 +27,26 @@ class Block;
class Label;
class Instr {
public:
Block* block;
Instr* next;
Instr* prev;
public:
Block* block;
Instr* next;
Instr* prev;
const OpcodeInfo* opcode;
uint16_t flags;
uint32_t ordinal;
uint16_t flags;
uint32_t ordinal;
typedef union {
runtime::FunctionInfo* symbol_info;
Label* label;
Value* value;
uint64_t offset;
Label* label;
Value* value;
uint64_t offset;
} Op;
Value* dest;
Op src1;
Op src2;
Op src3;
Value* dest;
Op src1;
Op src2;
Op src3;
Value::Use* src1_use;
Value::Use* src2_use;
@ -59,9 +61,7 @@ public:
void Remove();
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_INSTR_H_

View File

@ -12,28 +12,24 @@
#include <alloy/core.h>
namespace alloy {
namespace hir {
class Block;
class Label {
public:
public:
Block* block;
Label* next;
Label* prev;
uint32_t id;
char* name;
uint32_t id;
char* name;
void* tag;
void* tag;
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_LABEL_H_

View File

@ -9,15 +9,13 @@
#include <alloy/hir/opcodes.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
#define DEFINE_OPCODE(num, name, sig, flags) \
static const OpcodeInfo num##_info = { flags, sig, name, num, };
static const OpcodeInfo num##_info = { \
flags, sig, name, num, \
};
#include <alloy/hir/opcodes.inl>
#undef DEFINE_OPCODE

View File

@ -12,17 +12,15 @@
#include <alloy/core.h>
namespace alloy {
namespace hir {
enum CallFlags {
CALL_TAIL = (1 << 1),
CALL_POSSIBLE_RETURN = (1 << 2),
CALL_TAIL = (1 << 1),
CALL_POSSIBLE_RETURN = (1 << 2),
};
enum BranchFlags {
BRANCH_LIKELY = (1 << 1),
BRANCH_LIKELY = (1 << 1),
BRANCH_UNLIKELY = (1 << 2),
};
enum RoundMode {
@ -33,20 +31,20 @@ enum RoundMode {
ROUND_TO_POSITIVE_INFINITY,
};
enum LoadFlags {
LOAD_NO_ALIAS = (1 << 1),
LOAD_ALIGNED = (1 << 2),
LOAD_UNALIGNED = (1 << 3),
LOAD_VOLATILE = (1 << 4),
LOAD_NO_ALIAS = (1 << 1),
LOAD_ALIGNED = (1 << 2),
LOAD_UNALIGNED = (1 << 3),
LOAD_VOLATILE = (1 << 4),
};
enum StoreFlags {
STORE_NO_ALIAS = (1 << 1),
STORE_ALIGNED = (1 << 2),
STORE_NO_ALIAS = (1 << 1),
STORE_ALIGNED = (1 << 2),
STORE_UNALIGNED = (1 << 3),
STORE_VOLATILE = (1 << 4),
STORE_VOLATILE = (1 << 4),
};
enum PrefetchFlags {
PREFETCH_LOAD = (1 << 1),
PREFETCH_STORE = (1 << 2),
PREFETCH_LOAD = (1 << 1),
PREFETCH_STORE = (1 << 2),
};
enum ArithmeticFlags {
ARITHMETIC_SET_CARRY = (1 << 1),
@ -56,11 +54,8 @@ enum ArithmeticFlags {
enum Permutes {
PERMUTE_XY_ZW = 0x00010405,
};
#define SWIZZLE_MASK(x, y, z, w) ( \
(((x) & 0x3) << 6) | \
(((y) & 0x3) << 4) | \
(((z) & 0x3) << 2) | \
(((w) & 0x3)))
#define SWIZZLE_MASK(x, y, z, w) \
((((x)&0x3) << 6) | (((y)&0x3) << 4) | (((z)&0x3) << 2) | (((w)&0x3)))
enum Swizzles {
SWIZZLE_XYZW_TO_XYZW = SWIZZLE_MASK(0, 1, 2, 3),
SWIZZLE_XYZW_TO_YZWX = SWIZZLE_MASK(1, 2, 3, 0),
@ -78,19 +73,14 @@ enum PackType {
PACK_TYPE_S16_IN_32_HI = 7,
};
enum Opcode {
OPCODE_COMMENT,
OPCODE_NOP,
OPCODE_SOURCE_OFFSET,
OPCODE_DEBUG_BREAK,
OPCODE_DEBUG_BREAK_TRUE,
OPCODE_TRAP,
OPCODE_TRAP_TRUE,
OPCODE_CALL,
OPCODE_CALL_TRUE,
OPCODE_CALL_INDIRECT,
@ -99,11 +89,9 @@ enum Opcode {
OPCODE_RETURN,
OPCODE_RETURN_TRUE,
OPCODE_SET_RETURN_ADDRESS,
OPCODE_BRANCH,
OPCODE_BRANCH_TRUE,
OPCODE_BRANCH_FALSE,
OPCODE_ASSIGN,
OPCODE_CAST,
OPCODE_ZERO_EXTEND,
@ -113,22 +101,16 @@ enum Opcode {
OPCODE_ROUND,
OPCODE_VECTOR_CONVERT_I2F,
OPCODE_VECTOR_CONVERT_F2I,
OPCODE_LOAD_VECTOR_SHL,
OPCODE_LOAD_VECTOR_SHR,
OPCODE_LOAD_CLOCK,
OPCODE_LOAD_LOCAL,
OPCODE_STORE_LOCAL,
OPCODE_LOAD_CONTEXT,
OPCODE_STORE_CONTEXT,
OPCODE_LOAD,
OPCODE_STORE,
OPCODE_PREFETCH,
OPCODE_MAX,
OPCODE_MIN,
OPCODE_SELECT,
@ -152,13 +134,12 @@ enum Opcode {
OPCODE_VECTOR_COMPARE_SGE,
OPCODE_VECTOR_COMPARE_UGT,
OPCODE_VECTOR_COMPARE_UGE,
OPCODE_ADD,
OPCODE_ADD_CARRY,
OPCODE_VECTOR_ADD,
OPCODE_SUB,
OPCODE_MUL,
OPCODE_MUL_HI, // TODO(benvanik): remove this and add INT128 type.
OPCODE_MUL_HI, // TODO(benvanik): remove this and add INT128 type.
OPCODE_DIV,
OPCODE_MUL_ADD,
OPCODE_MUL_SUB,
@ -170,7 +151,6 @@ enum Opcode {
OPCODE_LOG2,
OPCODE_DOT_PRODUCT_3,
OPCODE_DOT_PRODUCT_4,
OPCODE_AND,
OPCODE_OR,
OPCODE_XOR,
@ -191,22 +171,20 @@ enum Opcode {
OPCODE_SWIZZLE,
OPCODE_PACK,
OPCODE_UNPACK,
OPCODE_COMPARE_EXCHANGE,
OPCODE_ATOMIC_EXCHANGE,
OPCODE_ATOMIC_ADD,
OPCODE_ATOMIC_SUB,
__OPCODE_MAX_VALUE, // Keep at end.
__OPCODE_MAX_VALUE, // Keep at end.
};
enum OpcodeFlags {
OPCODE_FLAG_BRANCH = (1 << 1),
OPCODE_FLAG_MEMORY = (1 << 2),
OPCODE_FLAG_BRANCH = (1 << 1),
OPCODE_FLAG_MEMORY = (1 << 2),
OPCODE_FLAG_COMMUNATIVE = (1 << 3),
OPCODE_FLAG_VOLATILE = (1 << 4),
OPCODE_FLAG_IGNORE = (1 << 5),
OPCODE_FLAG_HIDE = (1 << 6),
OPCODE_FLAG_VOLATILE = (1 << 4),
OPCODE_FLAG_IGNORE = (1 << 5),
OPCODE_FLAG_HIDE = (1 << 6),
OPCODE_FLAG_PAIRED_PREV = (1 << 7),
};
@ -220,26 +198,38 @@ enum OpcodeSignatureType {
};
enum OpcodeSignature {
OPCODE_SIG_X = (OPCODE_SIG_TYPE_X),
OPCODE_SIG_X_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_L << 3),
OPCODE_SIG_X_O = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_X_O_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_S = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_S << 3),
OPCODE_SIG_X_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_X_V_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_L << 6),
OPCODE_SIG_X_V_L_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_L << 6) | (OPCODE_SIG_TYPE_L << 9),
OPCODE_SIG_X_V_O = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_X_V_S = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_S << 6),
OPCODE_SIG_X_V_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_V_V_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V = (OPCODE_SIG_TYPE_V),
OPCODE_SIG_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_V_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_V_V_O_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_V_V_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_O << 9),
OPCODE_SIG_V_V_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_X = (OPCODE_SIG_TYPE_X),
OPCODE_SIG_X_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_L << 3),
OPCODE_SIG_X_O = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_X_O_V =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_O << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_S = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_S << 3),
OPCODE_SIG_X_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_X_V_L =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_L << 6),
OPCODE_SIG_X_V_L_L = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_L << 6) | (OPCODE_SIG_TYPE_L << 9),
OPCODE_SIG_X_V_O =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_X_V_S =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_S << 6),
OPCODE_SIG_X_V_V =
(OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_X_V_V_V = (OPCODE_SIG_TYPE_X) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V = (OPCODE_SIG_TYPE_V),
OPCODE_SIG_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_O << 3),
OPCODE_SIG_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3),
OPCODE_SIG_V_V_O =
(OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_O << 6),
OPCODE_SIG_V_V_O_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_O << 6) | (OPCODE_SIG_TYPE_V << 9),
OPCODE_SIG_V_V_V =
(OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) | (OPCODE_SIG_TYPE_V << 6),
OPCODE_SIG_V_V_V_O = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_O << 9),
OPCODE_SIG_V_V_V_V = (OPCODE_SIG_TYPE_V) | (OPCODE_SIG_TYPE_V << 3) |
(OPCODE_SIG_TYPE_V << 6) | (OPCODE_SIG_TYPE_V << 9),
};
#define GET_OPCODE_SIG_TYPE_DEST(sig) (OpcodeSignatureType)(sig & 0x7)
@ -248,21 +238,17 @@ enum OpcodeSignature {
#define GET_OPCODE_SIG_TYPE_SRC3(sig) (OpcodeSignatureType)((sig >> 9) & 0x7)
typedef struct {
uint32_t flags;
uint32_t signature;
uint32_t flags;
uint32_t signature;
const char* name;
Opcode num;
Opcode num;
} OpcodeInfo;
#define DEFINE_OPCODE(num, name, sig, flags) \
extern const OpcodeInfo num##_info;
#define DEFINE_OPCODE(num, name, sig, flags) extern const OpcodeInfo num##_info;
#include <alloy/hir/opcodes.inl>
#undef DEFINE_OPCODE
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_OPCODES_H_

View File

@ -13,23 +13,19 @@
#include <alloy/tracing/tracing.h>
#include <alloy/tracing/event_type.h>
namespace alloy {
namespace hir {
const uint32_t ALLOY_HIR = alloy::tracing::EventType::ALLOY_HIR;
class EventType {
public:
public:
enum {
ALLOY_HIR_FOO = ALLOY_HIR | (0),
ALLOY_HIR_FOO = ALLOY_HIR | (0),
};
};
} // namespace hir
} // namespace alloy
#endif // ALLOY_HIR_TRACING_H_

View File

@ -9,9 +9,8 @@
#include <alloy/hir/value.h>
using namespace alloy;
using namespace alloy::hir;
namespace alloy {
namespace hir {
Value::Use* Value::AddUse(Arena* arena, Instr* instr) {
Use* use = arena->Alloc<Use>();
@ -39,34 +38,34 @@ void Value::RemoveUse(Use* use) {
uint32_t Value::AsUint32() {
XEASSERT(IsConstant());
switch (type) {
case INT8_TYPE:
return constant.i8;
case INT16_TYPE:
return constant.i16;
case INT32_TYPE:
return constant.i32;
case INT64_TYPE:
return (uint32_t)constant.i64;
default:
XEASSERTALWAYS();
return 0;
case INT8_TYPE:
return constant.i8;
case INT16_TYPE:
return constant.i16;
case INT32_TYPE:
return constant.i32;
case INT64_TYPE:
return (uint32_t)constant.i64;
default:
XEASSERTALWAYS();
return 0;
}
}
uint64_t Value::AsUint64() {
XEASSERT(IsConstant());
switch (type) {
case INT8_TYPE:
return constant.i8;
case INT16_TYPE:
return constant.i16;
case INT32_TYPE:
return constant.i32;
case INT64_TYPE:
return constant.i64;
default:
XEASSERTALWAYS();
return 0;
case INT8_TYPE:
return constant.i8;
case INT16_TYPE:
return constant.i16;
case INT32_TYPE:
return constant.i32;
case INT64_TYPE:
return constant.i64;
default:
XEASSERTALWAYS();
return 0;
}
}
@ -77,87 +76,6 @@ void Value::Cast(TypeName target_type) {
void Value::ZeroExtend(TypeName target_type) {
switch (type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
case INT32_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFFFFFF;
return;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::SignExtend(TypeName target_type) {
switch (type) {
case INT8_TYPE:
type = target_type;
switch (target_type) {
case INT16_TYPE:
constant.i16 = constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i8;
break;
}
return;
case INT16_TYPE:
type = target_type;
switch (target_type) {
case INT32_TYPE:
constant.i32 = constant.i16;
break;
case INT64_TYPE:
constant.i64 = constant.i16;
break;
}
return;
case INT32_TYPE:
type = target_type;
switch (target_type) {
case INT64_TYPE:
constant.i64 = constant.i32;
break;
}
return;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::Truncate(TypeName target_type) {
switch (type) {
case INT16_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
}
break;
case INT32_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
}
break;
case INT64_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
@ -170,8 +88,89 @@ void Value::Truncate(TypeName target_type) {
type = target_type;
constant.i64 = constant.i64 & 0xFFFFFFFF;
return;
}
break;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::SignExtend(TypeName target_type) {
switch (type) {
case INT8_TYPE:
type = target_type;
switch (target_type) {
case INT16_TYPE:
constant.i16 = constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i8;
break;
}
return;
case INT16_TYPE:
type = target_type;
switch (target_type) {
case INT32_TYPE:
constant.i32 = constant.i16;
break;
case INT64_TYPE:
constant.i64 = constant.i16;
break;
}
return;
case INT32_TYPE:
type = target_type;
switch (target_type) {
case INT64_TYPE:
constant.i64 = constant.i32;
break;
}
return;
}
// Unsupported types.
XEASSERTALWAYS();
}
void Value::Truncate(TypeName target_type) {
switch (type) {
case INT16_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
}
break;
case INT32_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
}
break;
case INT64_TYPE:
switch (target_type) {
case INT8_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFF;
return;
case INT16_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFF;
return;
case INT32_TYPE:
type = target_type;
constant.i64 = constant.i64 & 0xFFFFFFFF;
return;
}
break;
}
// Unsupported types.
XEASSERTALWAYS();
@ -188,70 +187,70 @@ void Value::Round(RoundMode round_mode) {
}
bool Value::Add(Value* other) {
#define CHECK_DID_CARRY(v1, v2) (((uint64_t)v2) > ~((uint64_t)v1))
#define ADD_DID_CARRY(a, b) CHECK_DID_CARRY(a, b)
#define CHECK_DID_CARRY(v1, v2) (((uint64_t)v2) > ~((uint64_t)v1))
#define ADD_DID_CARRY(a, b) CHECK_DID_CARRY(a, b)
XEASSERT(type == other->type);
bool did_carry = false;
switch (type) {
case INT8_TYPE:
did_carry = ADD_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 += other->constant.i8;
break;
case INT16_TYPE:
did_carry = ADD_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 += other->constant.i16;
break;
case INT32_TYPE:
did_carry = ADD_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 += other->constant.i32;
break;
case INT64_TYPE:
did_carry = ADD_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 += other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 += other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 += other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
did_carry = ADD_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 += other->constant.i8;
break;
case INT16_TYPE:
did_carry = ADD_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 += other->constant.i16;
break;
case INT32_TYPE:
did_carry = ADD_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 += other->constant.i32;
break;
case INT64_TYPE:
did_carry = ADD_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 += other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 += other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 += other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
return did_carry;
}
bool Value::Sub(Value* other) {
#define SUB_DID_CARRY(a, b) (b > a)
#define SUB_DID_CARRY(a, b) (b > a)
XEASSERT(type == other->type);
bool did_carry = false;
switch (type) {
case INT8_TYPE:
did_carry = SUB_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 -= other->constant.i8;
break;
case INT16_TYPE:
did_carry = SUB_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 -= other->constant.i16;
break;
case INT32_TYPE:
did_carry = SUB_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 -= other->constant.i32;
break;
case INT64_TYPE:
did_carry = SUB_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 -= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 -= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 -= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
did_carry = SUB_DID_CARRY(constant.i8, other->constant.i8);
constant.i8 -= other->constant.i8;
break;
case INT16_TYPE:
did_carry = SUB_DID_CARRY(constant.i16, other->constant.i16);
constant.i16 -= other->constant.i16;
break;
case INT32_TYPE:
did_carry = SUB_DID_CARRY(constant.i32, other->constant.i32);
constant.i32 -= other->constant.i32;
break;
case INT64_TYPE:
did_carry = SUB_DID_CARRY(constant.i64, other->constant.i64);
constant.i64 -= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 -= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 -= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
return did_carry;
}
@ -259,54 +258,54 @@ bool Value::Sub(Value* other) {
void Value::Mul(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 *= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 *= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 *= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 *= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 *= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 *= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 *= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 *= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 *= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 *= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 *= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 *= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Div(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 /= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 /= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 /= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 /= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 /= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 /= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 /= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 /= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 /= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 /= other->constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 /= other->constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 /= other->constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
}
@ -322,276 +321,276 @@ void Value::MulSub(Value* dest, Value* value1, Value* value2, Value* value3) {
void Value::Neg() {
switch (type) {
case INT8_TYPE:
constant.i8 = -constant.i8;
break;
case INT16_TYPE:
constant.i16 = -constant.i16;
break;
case INT32_TYPE:
constant.i32 = -constant.i32;
break;
case INT64_TYPE:
constant.i64 = -constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 = -constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 = -constant.f64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = -constant.i8;
break;
case INT16_TYPE:
constant.i16 = -constant.i16;
break;
case INT32_TYPE:
constant.i32 = -constant.i32;
break;
case INT64_TYPE:
constant.i64 = -constant.i64;
break;
case FLOAT32_TYPE:
constant.f32 = -constant.f32;
break;
case FLOAT64_TYPE:
constant.f64 = -constant.f64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Abs() {
switch (type) {
case INT8_TYPE:
constant.i8 = abs(constant.i8);
break;
case INT16_TYPE:
constant.i16 = abs(constant.i16);
break;
case INT32_TYPE:
constant.i32 = abs(constant.i32);
break;
case INT64_TYPE:
constant.i64 = abs(constant.i64);
break;
case FLOAT32_TYPE:
constant.f32 = abs(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = abs(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = abs(constant.i8);
break;
case INT16_TYPE:
constant.i16 = abs(constant.i16);
break;
case INT32_TYPE:
constant.i32 = abs(constant.i32);
break;
case INT64_TYPE:
constant.i64 = abs(constant.i64);
break;
case FLOAT32_TYPE:
constant.f32 = abs(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = abs(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Sqrt() {
switch (type) {
case FLOAT32_TYPE:
constant.f32 = 1.0f / sqrtf(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = 1.0 / sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
case FLOAT32_TYPE:
constant.f32 = 1.0f / sqrtf(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = 1.0 / sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::RSqrt() {
switch (type) {
case FLOAT32_TYPE:
constant.f32 = sqrt(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
case FLOAT32_TYPE:
constant.f32 = sqrt(constant.f32);
break;
case FLOAT64_TYPE:
constant.f64 = sqrt(constant.f64);
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::And(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 &= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 &= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 &= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 &= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 &= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 &= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 &= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 &= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Or(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 |= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 |= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 |= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 |= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 |= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 |= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 |= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 |= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Xor(Value* other) {
XEASSERT(type == other->type);
switch (type) {
case INT8_TYPE:
constant.i8 ^= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 ^= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 ^= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 ^= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 ^= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 ^= other->constant.i16;
break;
case INT32_TYPE:
constant.i32 ^= other->constant.i32;
break;
case INT64_TYPE:
constant.i64 ^= other->constant.i64;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Not() {
switch (type) {
case INT8_TYPE:
constant.i8 = ~constant.i8;
break;
case INT16_TYPE:
constant.i16 = ~constant.i16;
break;
case INT32_TYPE:
constant.i32 = ~constant.i32;
break;
case INT64_TYPE:
constant.i64 = ~constant.i64;
break;
case VEC128_TYPE:
constant.v128.low = ~constant.v128.low;
constant.v128.high = ~constant.v128.high;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = ~constant.i8;
break;
case INT16_TYPE:
constant.i16 = ~constant.i16;
break;
case INT32_TYPE:
constant.i32 = ~constant.i32;
break;
case INT64_TYPE:
constant.i64 = ~constant.i64;
break;
case VEC128_TYPE:
constant.v128.low = ~constant.v128.low;
constant.v128.high = ~constant.v128.high;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Shl(Value* other) {
XEASSERT(other->type == INT8_TYPE);
switch (type) {
case INT8_TYPE:
constant.i8 <<= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 <<= other->constant.i8;
break;
case INT32_TYPE:
constant.i32 <<= other->constant.i8;
break;
case INT64_TYPE:
constant.i64 <<= other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 <<= other->constant.i8;
break;
case INT16_TYPE:
constant.i16 <<= other->constant.i8;
break;
case INT32_TYPE:
constant.i32 <<= other->constant.i8;
break;
case INT64_TYPE:
constant.i64 <<= other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Shr(Value* other) {
XEASSERT(other->type == INT8_TYPE);
switch (type) {
case INT8_TYPE:
constant.i8 = (uint8_t)constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = (uint16_t)constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = (uint32_t)constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = (uint16_t)constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = (uint8_t)constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = (uint16_t)constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = (uint32_t)constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = (uint16_t)constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::Sha(Value* other) {
XEASSERT(other->type == INT8_TYPE);
switch (type) {
case INT8_TYPE:
constant.i8 = constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = constant.i8 >> other->constant.i8;
break;
case INT16_TYPE:
constant.i16 = constant.i16 >> other->constant.i8;
break;
case INT32_TYPE:
constant.i32 = constant.i32 >> other->constant.i8;
break;
case INT64_TYPE:
constant.i64 = constant.i64 >> other->constant.i8;
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::ByteSwap() {
switch (type) {
case INT8_TYPE:
constant.i8 = constant.i8;
break;
case INT16_TYPE:
constant.i16 = XESWAP16(constant.i16);
break;
case INT32_TYPE:
constant.i32 = XESWAP32(constant.i32);
break;
case INT64_TYPE:
constant.i64 = XESWAP64(constant.i64);
break;
case VEC128_TYPE:
for (int n = 0; n < 4; n++) {
constant.v128.i4[n] = XESWAP32(constant.v128.i4[n]);
}
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = constant.i8;
break;
case INT16_TYPE:
constant.i16 = XESWAP16(constant.i16);
break;
case INT32_TYPE:
constant.i32 = XESWAP32(constant.i32);
break;
case INT64_TYPE:
constant.i64 = XESWAP64(constant.i64);
break;
case VEC128_TYPE:
for (int n = 0; n < 4; n++) {
constant.v128.i4[n] = XESWAP32(constant.v128.i4[n]);
}
break;
default:
XEASSERTALWAYS();
break;
}
}
void Value::CountLeadingZeros(const Value* other) {
switch (other->type) {
case INT8_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i8) - 8);
break;
case INT16_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i16));
break;
case INT32_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt(other->constant.i32));
break;
case INT64_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt64(other->constant.i64));
break;
default:
XEASSERTALWAYS();
break;
case INT8_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i8) - 8);
break;
case INT16_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i16));
break;
case INT32_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt(other->constant.i32));
break;
case INT64_TYPE:
constant.i8 = static_cast<uint8_t>(__lzcnt64(other->constant.i64));
break;
default:
XEASSERTALWAYS();
break;
}
}
@ -600,3 +599,6 @@ bool Value::Compare(Opcode opcode, Value* other) {
XEASSERTALWAYS();
return false;
}
} // namespace hir
} // namespace alloy

Some files were not shown because too many files have changed in this diff Show More