Monero
assembly_generator_x86.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3 
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the
14  names of its contributors may be used to endorse or promote products
15  derived from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #pragma once
30 
31 #include "common.hpp"
32 #include <sstream>
33 
34 namespace randomx {
35 
36  class Program;
37  class SuperscalarProgram;
38  class AssemblyGeneratorX86;
39  class Instruction;
40 
42 
44  public:
48  void printCode(std::ostream& os) {
49  os << asmCode.rdbuf();
50  }
51  private:
52  void genAddressReg(Instruction&, const char*);
53  void genAddressRegDst(Instruction&, int);
55  void generateCode(Instruction&, int);
56  void traceint(Instruction&);
57  void traceflt(Instruction&);
58  void tracenop(Instruction&);
59  void h_IADD_RS(Instruction&, int);
60  void h_IADD_M(Instruction&, int);
61  void h_ISUB_R(Instruction&, int);
62  void h_ISUB_M(Instruction&, int);
63  void h_IMUL_R(Instruction&, int);
64  void h_IMUL_M(Instruction&, int);
65  void h_IMULH_R(Instruction&, int);
66  void h_IMULH_M(Instruction&, int);
67  void h_ISMULH_R(Instruction&, int);
68  void h_ISMULH_M(Instruction&, int);
69  void h_IMUL_RCP(Instruction&, int);
70  void h_INEG_R(Instruction&, int);
71  void h_IXOR_R(Instruction&, int);
72  void h_IXOR_M(Instruction&, int);
73  void h_IROR_R(Instruction&, int);
74  void h_IROL_R(Instruction&, int);
75  void h_ISWAP_R(Instruction&, int);
76  void h_FSWAP_R(Instruction&, int);
77  void h_FADD_R(Instruction&, int);
78  void h_FADD_M(Instruction&, int);
79  void h_FSUB_R(Instruction&, int);
80  void h_FSUB_M(Instruction&, int);
81  void h_FSCAL_R(Instruction&, int);
82  void h_FMUL_R(Instruction&, int);
83  void h_FDIV_M(Instruction&, int);
84  void h_FSQRT_R(Instruction&, int);
85  void h_CBRANCH(Instruction&, int);
86  void h_CFROUND(Instruction&, int);
87  void h_ISTORE(Instruction&, int);
88  void h_NOP(Instruction&, int);
89 
91  std::stringstream asmCode;
93  };
94 }
void h_FADD_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:477
Definition: allocator.cpp:35
void h_IADD_RS(Instruction &, int)
Definition: assembly_generator_x86.cpp:281
void traceflt(Instruction &)
Definition: assembly_generator_x86.cpp:242
void h_IMUL_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:336
void h_IROR_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:423
void h_FSUB_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:499
void h_IMUL_RCP(Instruction &, int)
Definition: assembly_generator_x86.cpp:447
void h_FADD_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:484
void h_FSCAL_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:507
void generateProgram(Program &prog)
Definition: assembly_generator_x86.cpp:54
int32_t genAddressImm(Instruction &)
Definition: assembly_generator_x86.cpp:277
Definition: instruction.hpp:75
void tracenop(Instruction &)
Definition: assembly_generator_x86.cpp:248
Definition: superscalar_program.hpp:37
void h_FMUL_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:513
void h_IXOR_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:411
void genAddressReg(Instruction &, const char *)
Definition: assembly_generator_x86.cpp:260
void h_FSWAP_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:472
void h_FSUB_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:492
void h_CBRANCH(Instruction &, int)
Definition: assembly_generator_x86.cpp:549
void h_IROL_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:435
void printCode(std::ostream &os)
Definition: assembly_generator_x86.hpp:48
void generateAsm(SuperscalarProgram &prog)
Definition: assembly_generator_x86.cpp:68
void h_FDIV_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:520
void h_IXOR_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:400
void h_NOP(Instruction &, int)
Definition: assembly_generator_x86.cpp:571
void traceint(Instruction &)
Definition: assembly_generator_x86.cpp:236
void(AssemblyGeneratorX86::* InstructionGenerator)(Instruction &, int)
Definition: assembly_generator_x86.hpp:41
void h_IMUL_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:325
void h_IADD_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:290
std::stringstream asmCode
Definition: assembly_generator_x86.hpp:91
Definition: program.hpp:44
int
Definition: pymoduletest.py:17
int registerUsage[RegistersCount]
Definition: assembly_generator_x86.hpp:92
void h_ISUB_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:313
void h_CFROUND(Instruction &, int)
Definition: assembly_generator_x86.cpp:536
void h_ISTORE(Instruction &, int)
Definition: assembly_generator_x86.cpp:565
void generateCode(Instruction &, int)
Definition: assembly_generator_x86.cpp:254
void h_ISMULH_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:371
void h_ISMULH_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:379
void h_INEG_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:394
static char * prog
Definition: mdb_load.c:33
static InstructionGenerator engine[256]
Definition: assembly_generator_x86.hpp:90
void h_IMULH_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:348
constexpr int RegistersCount
Definition: common.hpp:156
void h_FSQRT_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:530
void h_ISWAP_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:460
void h_IMULH_M(Instruction &, int)
Definition: assembly_generator_x86.cpp:356
void h_ISUB_R(Instruction &, int)
Definition: assembly_generator_x86.cpp:302
signed int int32_t
Definition: stdint.h:123
void genAddressRegDst(Instruction &, int)
Definition: assembly_generator_x86.cpp:265
void generateC(SuperscalarProgram &prog)
Definition: assembly_generator_x86.cpp:142
Definition: assembly_generator_x86.hpp:43