Monero
Toggle main menu visibility
Loading...
Searching...
No Matches
external
randomx
src
jit_compiler.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
33
namespace
randomx
{
34
35
struct
CodeBuffer
{
36
uint8_t
*
code
;
37
int32_t
codePos
;
38
int32_t
rcpCount
;
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
61
struct
CompilerState
:
public
CodeBuffer
{
62
int32_t
instructionOffsets
[
RANDOMX_PROGRAM_SIZE
];
63
int
registerUsage
[
RegistersCount
];
64
};
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
74
#include "
jit_compiler_fallback.hpp
"
75
#endif
76
77
#if defined(__OpenBSD__) || defined(__NetBSD__) || (defined(__APPLE__) && defined(__aarch64__))
78
#define RANDOMX_FORCE_SECURE
79
#endif
common.hpp
RANDOMX_PROGRAM_SIZE
#define RANDOMX_PROGRAM_SIZE
Definition
configuration.h:56
memcpy
void * memcpy(void *a, const void *b, size_t c)
Definition
glibc_compat.cpp:16
jit_compiler_a64.hpp
jit_compiler_fallback.hpp
jit_compiler_rv64.hpp
jit_compiler_x86.hpp
randomx
Definition
allocator.cpp:35
randomx::RegistersCount
constexpr int RegistersCount
Definition
common.hpp:156
int32_t
signed int int32_t
Definition
stdint.h:123
uint8_t
unsigned char uint8_t
Definition
stdint.h:124
randomx::CodeBuffer
Definition
jit_compiler.hpp:35
randomx::CodeBuffer::code
uint8_t * code
Definition
jit_compiler.hpp:36
randomx::CodeBuffer::codePos
int32_t codePos
Definition
jit_compiler.hpp:37
randomx::CodeBuffer::emit
void emit(const uint8_t *src, int32_t len)
Definition
jit_compiler.hpp:40
randomx::CodeBuffer::emitAt
void emitAt(int32_t codePos, T src)
Definition
jit_compiler.hpp:56
randomx::CodeBuffer::emitAt
void emitAt(int32_t codePos, const uint8_t *src, int32_t len)
Definition
jit_compiler.hpp:51
randomx::CodeBuffer::rcpCount
int32_t rcpCount
Definition
jit_compiler.hpp:38
randomx::CodeBuffer::emit
void emit(T src)
Definition
jit_compiler.hpp:46
randomx::CompilerState
Definition
jit_compiler.hpp:61
randomx::CompilerState::instructionOffsets
int32_t instructionOffsets[RANDOMX_PROGRAM_SIZE]
Definition
jit_compiler.hpp:62
randomx::CompilerState::registerUsage
int registerUsage[RegistersCount]
Definition
jit_compiler.hpp:63
T
#define T(x)
Generated on
for Monero by
1.17.0