mirror of
https://github.com/Mr-Wiseguy/N64Recomp.git
synced 2024-12-26 17:36:16 +00:00
5b17bf8bb5
* Initial implementation of binary operation table * Initial implementation of unary operation table * More binary op types, moved binary expression string generation into separate function * Added and implemented conditional branch instruction table * Fixed likely swap on bgezal, fixed extra indent branch close and missing indent on branch statement * Add operands for other uses of float registers * Added CHECK_FR generation to binary operation processing, moved float comparison instructions to binary op table * Finished moving float arithmetic instructions to operation tables * Added store instruction operation table * Created Generator interface, separated operation types and tables and C generation code into new files * Fix mov.d using the wrong input operand * Move recompiler core logic into a core library and make the existing CLI consume the core library * Removed unnecessary config input to recompilation functions * Moved parts of recomp_port.h into new internal headers in src folder * Changed recomp port naming to N64Recomp * Remove some unused code and document which Context fields are actually required for recompilation * Implement mod symbol parsing * Restructure mod symbols to make replacements global instead of per-section * Refactor elf parsing into static Context method for reusability * Move elf parsing into a separate library * WIP elf to mod tool, currently working without relocations or API exports/imports * Make mod tool emit relocs and patch binary for non-relocatable symbol references as needed * Implemented writing import and exports in the mod tool * Add dependencies to the mod symbol format, finish exporting and importing of mod symbols * Add first pass offline mod recompiler (generates C from mods that can be compiled and linked into a dynamic library) * Add strict mode and ability to generate exports for normal recompilation (for patches) * Move mod context fields into base context, move import symbols into separate vector, misc cleanup * Some cleanup by making some Context members private * Add events (from dependencies and exported) and callbacks to the mod symbol format and add support to them in elf parsing * Add runtime-driven fields to offline mod recompiler, fix event symbol relocs using the wrong section in the mod tool * Move file header writing outside of function recompilation * Allow cross-section relocations, encode exact target section in mod relocations, add way to tag reference symbol relocations * Add local symbol addresses array to offline mod recompiler output and rename original one to reference section addresses * Add more comments to the offline mod recompiler's output * Fix handling of section load addresses to match objcopy behavior, added event parsing to dependency tomls, minor cleanup * Fixed incorrect size used for finding section segments * Add missing includes for libstdc++ * Rework callbacks and imports to use the section name for identifying the dependency instead of relying on per-dependency tomls
201 lines
4.6 KiB
C++
201 lines
4.6 KiB
C++
#ifndef __OPERATIONS_H__
|
|
#define __OPERATIONS_H__
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "rabbitizer.hpp"
|
|
|
|
namespace N64Recomp {
|
|
using InstrId = rabbitizer::InstrId::UniqueId;
|
|
using Cop0Reg = rabbitizer::Registers::Cpu::Cop0;
|
|
|
|
enum class StoreOpType {
|
|
SD,
|
|
SDL,
|
|
SDR,
|
|
SW,
|
|
SWL,
|
|
SWR,
|
|
SH,
|
|
SB,
|
|
SDC1,
|
|
SWC1
|
|
};
|
|
|
|
enum class UnaryOpType {
|
|
None,
|
|
ToS32,
|
|
ToU32,
|
|
ToS64,
|
|
ToU64,
|
|
NegateS32,
|
|
NegateS64,
|
|
Lui,
|
|
Mask5, // Mask to 5 bits
|
|
Mask6, // Mask to 5 bits
|
|
ToInt32, // Functionally equivalent to ToS32, only exists for parity with old codegen
|
|
Negate,
|
|
AbsFloat,
|
|
AbsDouble,
|
|
SqrtFloat,
|
|
SqrtDouble,
|
|
ConvertSFromW,
|
|
ConvertWFromS,
|
|
ConvertDFromW,
|
|
ConvertWFromD,
|
|
ConvertDFromS,
|
|
ConvertSFromD,
|
|
ConvertDFromL,
|
|
ConvertLFromD,
|
|
ConvertSFromL,
|
|
ConvertLFromS,
|
|
TruncateWFromS,
|
|
TruncateWFromD,
|
|
RoundWFromS,
|
|
RoundWFromD,
|
|
CeilWFromS,
|
|
CeilWFromD,
|
|
FloorWFromS,
|
|
FloorWFromD
|
|
};
|
|
|
|
enum class BinaryOpType {
|
|
// Addition/subtraction
|
|
Add32,
|
|
Sub32,
|
|
Add64,
|
|
Sub64,
|
|
// Float arithmetic
|
|
AddFloat,
|
|
AddDouble,
|
|
SubFloat,
|
|
SubDouble,
|
|
MulFloat,
|
|
MulDouble,
|
|
DivFloat,
|
|
DivDouble,
|
|
// Bitwise
|
|
And64,
|
|
Or64,
|
|
Nor64,
|
|
Xor64,
|
|
Sll32,
|
|
Sll64,
|
|
Srl32,
|
|
Srl64,
|
|
Sra32,
|
|
Sra64,
|
|
// Comparisons
|
|
Equal,
|
|
NotEqual,
|
|
Less,
|
|
LessEq,
|
|
Greater,
|
|
GreaterEq,
|
|
// Loads
|
|
LD,
|
|
LW,
|
|
LWU,
|
|
LH,
|
|
LHU,
|
|
LB,
|
|
LBU,
|
|
LDL,
|
|
LDR,
|
|
LWL,
|
|
LWR,
|
|
// Fixed result
|
|
True,
|
|
False,
|
|
|
|
COUNT,
|
|
};
|
|
|
|
enum class Operand {
|
|
Rd, // GPR
|
|
Rs, // GPR
|
|
Rt, // GPR
|
|
Fd, // FPR
|
|
Fs, // FPR
|
|
Ft, // FPR
|
|
FdDouble, // Double float in fd FPR
|
|
FsDouble, // Double float in fs FPR
|
|
FtDouble, // Double float in ft FPR
|
|
// Raw low 32-bit values of FPRs with handling for mips3 float mode behavior
|
|
FdU32L,
|
|
FsU32L,
|
|
FtU32L,
|
|
// Raw high 32-bit values of FPRs with handling for mips3 float mode behavior
|
|
FdU32H,
|
|
FsU32H,
|
|
FtU32H,
|
|
// Raw 64-bit values of FPRs
|
|
FdU64,
|
|
FsU64,
|
|
FtU64,
|
|
ImmU16, // 16-bit immediate, unsigned
|
|
ImmS16, // 16-bit immediate, signed
|
|
Sa, // Shift amount
|
|
Sa32, // Shift amount plus 32
|
|
Cop1cs, // Coprocessor 1 Condition Signal
|
|
Hi,
|
|
Lo,
|
|
Zero,
|
|
|
|
Base = Rs, // Alias for Rs for loads
|
|
};
|
|
|
|
struct StoreOp {
|
|
StoreOpType type;
|
|
Operand value_input;
|
|
};
|
|
|
|
struct UnaryOp {
|
|
UnaryOpType operation;
|
|
Operand output;
|
|
Operand input;
|
|
// Whether the FR bit needs to be checked for odd float registers for this instruction.
|
|
bool check_fr = false;
|
|
// Whether the input need to be checked for being NaN.
|
|
bool check_nan = false;
|
|
};
|
|
|
|
struct BinaryOperands {
|
|
// Operation to apply to each operand before applying the binary operation to them.
|
|
UnaryOpType operand_operations[2];
|
|
// The source of the input operands.
|
|
Operand operands[2];
|
|
};
|
|
|
|
struct BinaryOp {
|
|
// The type of binary operation this represents.
|
|
BinaryOpType type;
|
|
// The output operand.
|
|
Operand output;
|
|
// The input operands.
|
|
BinaryOperands operands;
|
|
// Whether the FR bit needs to be checked for odd float registers for this instruction.
|
|
bool check_fr = false;
|
|
// Whether the inputs need to be checked for being NaN.
|
|
bool check_nan = false;
|
|
};
|
|
|
|
struct ConditionalBranchOp {
|
|
// The type of binary operation to use for this compare
|
|
BinaryOpType comparison;
|
|
// The input operands.
|
|
BinaryOperands operands;
|
|
// Whether this jump should link for returns.
|
|
bool link;
|
|
// Whether this jump has "likely" behavior (doesn't execute the delay slot if skipped).
|
|
bool likely;
|
|
};
|
|
|
|
extern const std::unordered_map<InstrId, UnaryOp> unary_ops;
|
|
extern const std::unordered_map<InstrId, BinaryOp> binary_ops;
|
|
extern const std::unordered_map<InstrId, ConditionalBranchOp> conditional_branch_ops;
|
|
extern const std::unordered_map<InstrId, StoreOp> store_ops;
|
|
}
|
|
|
|
#endif
|