RandomWOW/src/instruction.hpp

154 lines
4.3 KiB
C++
Raw Normal View History

/*
Copyright (c) 2018 tevador
This file is part of RandomX.
RandomX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RandomX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RandomX. If not, see<http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <iostream>
2019-03-11 22:04:34 +00:00
#include "blake2/endian.h"
2019-04-20 09:08:01 +00:00
namespace randomx {
class Instruction;
2019-04-20 14:53:06 +00:00
typedef void(Instruction::*InstructionFormatter)(std::ostream&) const;
namespace InstructionType {
constexpr int IADD_RS = 0;
constexpr int IADD_M = 1;
constexpr int IADD_RC = 2;
constexpr int ISUB_R = 3;
constexpr int ISUB_M = 4;
constexpr int IMUL_9C = 5;
constexpr int IMUL_R = 6;
constexpr int IMUL_M = 7;
constexpr int IMULH_R = 8;
constexpr int IMULH_M = 9;
constexpr int ISMULH_R = 10;
constexpr int ISMULH_M = 11;
constexpr int IMUL_RCP = 12;
2019-04-22 16:20:46 +00:00
constexpr int INEG_R = 13;
constexpr int IXOR_R = 14;
constexpr int IXOR_M = 15;
constexpr int IROR_R = 16;
constexpr int IROL_R = 17;
constexpr int ISWAP_R = 18;
constexpr int FSWAP_R = 19;
constexpr int FADD_R = 20;
constexpr int FADD_M = 21;
constexpr int FSUB_R = 22;
constexpr int FSUB_M = 23;
constexpr int FSCAL_R = 24;
constexpr int FMUL_R = 25;
constexpr int FDIV_M = 26;
constexpr int FSQRT_R = 27;
constexpr int COND_R = 28;
constexpr int COND_M = 29;
constexpr int CFROUND = 30;
constexpr int ISTORE = 31;
constexpr int FSTORE = 32;
constexpr int NOP = 33;
}
class Instruction {
public:
2019-03-11 22:04:34 +00:00
uint32_t getImm32() const {
return load32(&imm32);
}
2019-03-28 14:27:10 +00:00
void setImm32(uint32_t val) {
return store32(&imm32, val);
}
const char* getName() const {
return names[opcode];
}
friend std::ostream& operator<<(std::ostream& os, const Instruction& i) {
i.print(os);
return os;
}
int getModMem() const {
return mod % 4;
}
int getModCond() const {
return (mod >> 2) & 7;
}
int getModShift3() const {
return mod >> 5;
}
int getModShift2() const {
return mod >> 6;
}
void setMod(uint8_t val) {
mod = val;
}
2019-04-20 14:53:06 +00:00
uint8_t opcode;
uint8_t dst;
uint8_t src;
private:
uint8_t mod;
2019-03-11 22:04:34 +00:00
uint32_t imm32;
2019-04-20 14:53:06 +00:00
void print(std::ostream&) const;
static const char* names[256];
2019-04-20 14:53:06 +00:00
static InstructionFormatter engine[256];
void genAddressReg(std::ostream& os) const;
void genAddressImm(std::ostream& os) const;
void genAddressRegDst(std::ostream&) const;
void h_IADD_RS(std::ostream&) const;
void h_IADD_M(std::ostream&) const;
void h_IADD_RC(std::ostream&) const;
void h_ISUB_R(std::ostream&) const;
void h_ISUB_M(std::ostream&) const;
void h_IMUL_9C(std::ostream&) const;
void h_IMUL_R(std::ostream&) const;
void h_IMUL_M(std::ostream&) const;
void h_IMULH_R(std::ostream&) const;
void h_IMULH_M(std::ostream&) const;
void h_ISMULH_R(std::ostream&) const;
void h_ISMULH_M(std::ostream&) const;
void h_IMUL_RCP(std::ostream&) const;
void h_ISDIV_C(std::ostream&) const;
void h_INEG_R(std::ostream&) const;
void h_IXOR_R(std::ostream&) const;
void h_IXOR_M(std::ostream&) const;
void h_IROR_R(std::ostream&) const;
void h_IROL_R(std::ostream&) const;
void h_ISWAP_R(std::ostream&) const;
void h_FSWAP_R(std::ostream&) const;
void h_FADD_R(std::ostream&) const;
void h_FADD_M(std::ostream&) const;
void h_FSUB_R(std::ostream&) const;
void h_FSUB_M(std::ostream&) const;
void h_FSCAL_R(std::ostream&) const;
void h_FMUL_R(std::ostream&) const;
void h_FMUL_M(std::ostream&) const;
void h_FDIV_R(std::ostream&) const;
void h_FDIV_M(std::ostream&) const;
void h_FSQRT_R(std::ostream&) const;
void h_COND_R(std::ostream&) const;
void h_COND_M(std::ostream&) const;
void h_CFROUND(std::ostream&) const;
void h_ISTORE(std::ostream&) const;
void h_FSTORE(std::ostream&) const;
void h_NOP(std::ostream&) const;
};
2019-04-20 14:53:06 +00:00
static_assert(sizeof(Instruction) == 8, "Invalid size of struct randomx::Instruction");
}