Monero
Loading...
Searching...
No Matches
jit_compiler.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, 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
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#pragma once
30
31#include "common.hpp"
32
33namespace randomx {
34
35 struct CodeBuffer {
39
40 void emit(const uint8_t* src, int32_t len) {
41 memcpy(&code[codePos], src, len);
42 codePos += len;
43 }
44
45 template<typename T>
46 void emit(T src) {
47 memcpy(&code[codePos], &src, sizeof(src));
48 codePos += sizeof(src);
49 }
50
51 void emitAt(int32_t codePos, const uint8_t* src, int32_t len) {
52 memcpy(&code[codePos], src, len);
53 }
54
55 template<typename T>
56 void emitAt(int32_t codePos, T src) {
57 memcpy(&code[codePos], &src, sizeof(src));
58 }
59 };
60
65}
66
67#if defined(RANDOMX_COMPILER_X86)
68#include "jit_compiler_x86.hpp"
69#elif defined(RANDOMX_COMPILER_A64)
70#include "jit_compiler_a64.hpp"
71#elif defined(RANDOMX_COMPILER_RV64)
72#include "jit_compiler_rv64.hpp"
73#else
75#endif
76
77#if defined(__OpenBSD__) || defined(__NetBSD__) || (defined(__APPLE__) && defined(__aarch64__))
78#define RANDOMX_FORCE_SECURE
79#endif
#define RANDOMX_PROGRAM_SIZE
Definition configuration.h:56
void * memcpy(void *a, const void *b, size_t c)
Definition glibc_compat.cpp:16
Definition allocator.cpp:35
constexpr int RegistersCount
Definition common.hpp:156
signed int int32_t
Definition stdint.h:123
unsigned char uint8_t
Definition stdint.h:124
Definition jit_compiler.hpp:35
uint8_t * code
Definition jit_compiler.hpp:36
int32_t codePos
Definition jit_compiler.hpp:37
void emit(const uint8_t *src, int32_t len)
Definition jit_compiler.hpp:40
void emitAt(int32_t codePos, T src)
Definition jit_compiler.hpp:56
void emitAt(int32_t codePos, const uint8_t *src, int32_t len)
Definition jit_compiler.hpp:51
int32_t rcpCount
Definition jit_compiler.hpp:38
void emit(T src)
Definition jit_compiler.hpp:46
Definition jit_compiler.hpp:61
int32_t instructionOffsets[RANDOMX_PROGRAM_SIZE]
Definition jit_compiler.hpp:62
int registerUsage[RegistersCount]
Definition jit_compiler.hpp:63
#define T(x)