Implemented VM mode for OpenCL RandomX.

This commit is contained in:
XMRig 2019-09-12 00:01:03 +07:00
parent 4c90f9960e
commit 95daab4bc0
42 changed files with 450 additions and 165 deletions

View file

@ -53,14 +53,7 @@ static inline uint8_t hf_bin2hex(uint8_t c)
}
xmrig::Buffer::Buffer() :
m_data(nullptr),
m_size(0)
{
}
xmrig::Buffer::Buffer(Buffer &&other) :
xmrig::Buffer::Buffer(Buffer &&other) noexcept :
m_data(other.m_data),
m_size(other.m_size)
{
@ -138,11 +131,13 @@ bool xmrig::Buffer::fromHex(const uint8_t *in, size_t size, uint8_t *out)
xmrig::Buffer xmrig::Buffer::fromHex(const char *data, size_t size)
{
if (data == nullptr || size % 2 != 0) {
return Buffer();
return {};
}
Buffer buf(size / 2);
fromHex(data, size, buf.data());
if (!fromHex(data, size, buf.data())) {
return {};
}
return buf;
}
@ -157,12 +152,6 @@ void xmrig::Buffer::toHex(const uint8_t *in, size_t size, uint8_t *out)
}
xmrig::String xmrig::Buffer::toHex(const uint8_t *in, size_t size)
{
return Buffer(reinterpret_cast<const char *>(in), size).toHex();
}
xmrig::String xmrig::Buffer::toHex() const
{
if (m_size == 0) {

View file

@ -35,14 +35,15 @@ namespace xmrig {
class Buffer
{
public:
Buffer();
Buffer(Buffer &&other);
Buffer() = default;
Buffer(Buffer &&other) noexcept;
Buffer(const Buffer &other);
Buffer(const char *data, size_t size);
Buffer(size_t size);
~Buffer();
inline bool isEmpty() const { return size() == 0; }
inline bool isEqual(const Buffer &other) const { return m_size == other.m_size && (m_size == 0 || memcmp(m_data, other.m_data, m_size) == 0); }
inline char *data() { return m_data; }
inline const char *data() const { return m_data; }
@ -55,7 +56,7 @@ public:
inline bool operator!=(const Buffer &other) const { return !isEqual(other); }
inline bool operator==(const Buffer &other) const { return isEqual(other); }
inline Buffer &operator=(Buffer &&other) { move(std::move(other)); return *this; }
inline Buffer &operator=(Buffer &&other) noexcept { move(std::move(other)); return *this; }
inline Buffer &operator=(const Buffer &other) { from(other); return *this; }
@ -67,12 +68,13 @@ public:
inline static bool fromHex(const char *in, size_t size, uint8_t *out) { return fromHex(reinterpret_cast<const uint8_t *>(in), size, out); }
inline static Buffer fromHex(const char *data) { return fromHex(data, strlen(data)); }
inline static Buffer fromHex(const String &str) { return fromHex(str.data(), str.size()); }
inline static String toHex(const char *in, size_t size) { return Buffer(in, size).toHex(); }
inline static String toHex(const uint8_t *in, size_t size) { return Buffer(reinterpret_cast<const char *>(in), size).toHex(); }
inline static void toHex(const char *in, size_t size, char *out) { return toHex(reinterpret_cast<const uint8_t *>(in), size, reinterpret_cast<uint8_t *>(out)); }
inline static void toHex(const uint8_t *in, size_t size, char *out) { return toHex(in, size, reinterpret_cast<uint8_t *>(out)); }
static bool fromHex(const uint8_t *in, size_t size, uint8_t *out);
static Buffer fromHex(const char *data, size_t size);
static String toHex(const uint8_t *in, size_t size);
static void toHex(const uint8_t *in, size_t size, uint8_t *out);
String toHex() const;
@ -80,8 +82,8 @@ private:
void copy(const char *data, size_t size);
void move(Buffer &&other);
char *m_data;
size_t m_size;
char *m_data = nullptr;
size_t m_size = 0;
};