mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 12:09:22 +00:00
Merge branch 'feature-cryptonight-heavy' into dev
This commit is contained in:
commit
7003559c74
42 changed files with 1182 additions and 377 deletions
|
@ -1,8 +1,10 @@
|
|||
# v2.6.0-beta1
|
||||
- [#476](https://github.com/xmrig/xmrig/issues/476) **Added Cryptonight-Heavy support for Sumokoin ASIC resistance fork.**
|
||||
- HTTP server now runs in main loop, it make possible easy extend API without worry about thread synchronization.
|
||||
- Added initial graceful reload support, miner will reload configuration if config file changed, disabled by default until it will be fully implemented and tested.
|
||||
- Added API endpoint `PUT /1/config` to update current config.
|
||||
- Added API endpoint `GET /1/config` to get current active config.
|
||||
- Added API endpoint `GET /1/threads` to get current active threads configuration.
|
||||
- API endpoint `GET /` now deprecated, use `GET /1/summary` instead.
|
||||
- Added `--api-no-ipv6` and similar config option to disable IPv6 support for HTTP API.
|
||||
- Added `--api-no-restricted` to enable full access to api, this option has no effect if `--api-access-token` not specified.
|
||||
|
|
|
@ -3,6 +3,7 @@ project(xmrig)
|
|||
|
||||
option(WITH_LIBCPUID "Use Libcpuid" ON)
|
||||
option(WITH_AEON "CryptoNight-Lite support" ON)
|
||||
option(WITH_SUMO "CryptoNight-Heavy support" ON)
|
||||
option(WITH_HTTPD "HTTP REST API" ON)
|
||||
option(BUILD_STATIC "Build static binary" OFF)
|
||||
|
||||
|
@ -32,6 +33,7 @@ set(HEADERS
|
|||
src/interfaces/ILogBackend.h
|
||||
src/interfaces/IStrategy.h
|
||||
src/interfaces/IStrategyListener.h
|
||||
src/interfaces/IThread.h
|
||||
src/interfaces/IWatcherListener.h
|
||||
src/interfaces/IWorker.h
|
||||
src/log/ConsoleLog.h
|
||||
|
@ -52,6 +54,7 @@ set(HEADERS
|
|||
src/Platform.h
|
||||
src/Summary.h
|
||||
src/version.h
|
||||
src/workers/CpuThread.h
|
||||
src/workers/DoubleWorker.h
|
||||
src/workers/Handle.h
|
||||
src/workers/Hashrate.h
|
||||
|
@ -68,6 +71,7 @@ set(HEADERS_CRYPTO
|
|||
src/crypto/c_keccak.h
|
||||
src/crypto/c_skein.h
|
||||
src/crypto/CryptoNight.h
|
||||
src/crypto/CryptoNight_constants.h
|
||||
src/crypto/CryptoNight_monero.h
|
||||
src/crypto/CryptoNight_test.h
|
||||
src/crypto/groestl_tables.h
|
||||
|
@ -106,6 +110,7 @@ set(SOURCES
|
|||
src/net/Url.cpp
|
||||
src/Platform.cpp
|
||||
src/Summary.cpp
|
||||
src/workers/CpuThread.cpp
|
||||
src/workers/DoubleWorker.cpp
|
||||
src/workers/Handle.cpp
|
||||
src/workers/Hashrate.cpp
|
||||
|
@ -121,7 +126,6 @@ set(SOURCES_CRYPTO
|
|||
src/crypto/c_blake256.c
|
||||
src/crypto/c_jh.c
|
||||
src/crypto/c_skein.c
|
||||
src/crypto/CryptoNight.cpp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
@ -200,6 +204,10 @@ if (NOT WITH_AEON)
|
|||
add_definitions(/DXMRIG_NO_AEON)
|
||||
endif()
|
||||
|
||||
if (NOT WITH_SUMO)
|
||||
add_definitions(/DXMRIG_NO_SUMO)
|
||||
endif()
|
||||
|
||||
if (WITH_HTTPD)
|
||||
find_package(MHD)
|
||||
|
||||
|
|
|
@ -101,13 +101,8 @@ int App::exec()
|
|||
|
||||
background();
|
||||
|
||||
if (!CryptoNight::init(m_controller->config()->algorithm(), m_controller->config()->algoVariant(), m_controller->config()->isDoubleHash())) {
|
||||
LOG_ERR("\"%s\" hash self-test failed.", m_controller->config()->algoName());
|
||||
return 1;
|
||||
}
|
||||
|
||||
Mem::allocate(m_controller->config()->algorithm(),
|
||||
m_controller->config()->threads(),
|
||||
m_controller->config()->threadsCount(),
|
||||
m_controller->config()->isDoubleHash(),
|
||||
m_controller->config()->isHugePages()
|
||||
);
|
||||
|
@ -136,7 +131,7 @@ int App::exec()
|
|||
m_httpd->start();
|
||||
# endif
|
||||
|
||||
Workers::start(m_controller->config()->affinity(), m_controller->config()->priority(), m_controller);
|
||||
Workers::start(m_controller);
|
||||
|
||||
m_controller->network()->connect();
|
||||
|
||||
|
|
19
src/Cpu.cpp
19
src/Cpu.cpp
|
@ -4,8 +4,8 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -39,7 +39,7 @@ int Cpu::m_totalCores = 0;
|
|||
int Cpu::m_totalThreads = 0;
|
||||
|
||||
|
||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
||||
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
|
||||
{
|
||||
if (m_totalThreads == 1) {
|
||||
return 1;
|
||||
|
@ -54,7 +54,18 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
|||
}
|
||||
|
||||
int count = 0;
|
||||
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
|
||||
int size = 2048;
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_LITE) {
|
||||
size = 1024;
|
||||
}
|
||||
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
size = 4096;
|
||||
}
|
||||
|
||||
if (doubleHash) {
|
||||
size *= 2;
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
count = cache / size;
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,6 +28,9 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
class Cpu
|
||||
{
|
||||
public:
|
||||
|
@ -37,7 +40,7 @@ public:
|
|||
BMI2 = 4
|
||||
};
|
||||
|
||||
static int optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage);
|
||||
static int optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage);
|
||||
static void init();
|
||||
static void setAffinity(int id, uint64_t mask);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ int Cpu::m_totalCores = 0;
|
|||
int Cpu::m_totalThreads = 0;
|
||||
|
||||
|
||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
||||
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
|
||||
{
|
||||
return m_totalThreads;
|
||||
}
|
||||
|
|
11
src/Mem.cpp
11
src/Mem.cpp
|
@ -27,8 +27,8 @@
|
|||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "Mem.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
bool Mem::m_doubleHash = false;
|
||||
|
@ -43,15 +43,18 @@ alignas(16) uint8_t *Mem::m_memory = nullptr;
|
|||
cryptonight_ctx *Mem::create(int threadId)
|
||||
{
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) {
|
||||
if (m_algo == xmrig::CRYPTONIGHT_LITE) {
|
||||
return createLite(threadId);
|
||||
}
|
||||
# endif
|
||||
|
||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
||||
const size_t size = m_algo == xmrig::CRYPTONIGHT_HEAVY ? xmrig::cn_select_memory<xmrig::CRYPTONIGHT_HEAVY>()
|
||||
: xmrig::cn_select_memory<xmrig::CRYPTONIGHT>();
|
||||
|
||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[size - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
||||
|
||||
const int ratio = m_doubleHash ? 2 : 1;
|
||||
ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)];
|
||||
ctx->memory = &m_memory[size * (threadId * ratio + 1)];
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
struct cryptonight_ctx;
|
||||
|
||||
|
||||
|
@ -42,7 +45,7 @@ public:
|
|||
Lock = 4
|
||||
};
|
||||
|
||||
static bool allocate(int algo, int threads, bool doubleHash, bool enabled);
|
||||
static bool allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled);
|
||||
static cryptonight_ctx *create(int threadId);
|
||||
static void *calloc(size_t num, size_t size);
|
||||
static void release();
|
||||
|
|
|
@ -40,15 +40,19 @@
|
|||
#include "xmrig.h"
|
||||
|
||||
|
||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
|
||||
{
|
||||
m_algo = algo;
|
||||
m_threads = threads;
|
||||
m_doubleHash = doubleHash;
|
||||
|
||||
const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
m_size = MONERO_MEMORY * (threads * ratio + 1);
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_size *= 2;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
|
||||
return true;
|
||||
|
|
|
@ -145,15 +145,19 @@ static BOOL TrySetLockPagesPrivilege() {
|
|||
}
|
||||
|
||||
|
||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
|
||||
{
|
||||
m_algo = algo;
|
||||
m_threads = threads;
|
||||
m_doubleHash = doubleHash;
|
||||
|
||||
const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
m_size = MONERO_MEMORY * (threads * ratio + 1);
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_size *= 2;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
|
||||
return true;
|
||||
|
|
|
@ -101,7 +101,7 @@ static void print_threads(xmrig::Config *config)
|
|||
}
|
||||
|
||||
Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s",
|
||||
config->threads(),
|
||||
config->threadsCount(),
|
||||
config->algoName(),
|
||||
config->algoVariant(),
|
||||
config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "",
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "Cpu.h"
|
||||
#include "interfaces/IThread.h"
|
||||
#include "Mem.h"
|
||||
#include "net/Job.h"
|
||||
#include "Platform.h"
|
||||
|
@ -67,7 +68,7 @@ static inline double normalize(double d)
|
|||
ApiRouter::ApiRouter(xmrig::Controller *controller) :
|
||||
m_controller(controller)
|
||||
{
|
||||
m_threads = controller->config()->threads();
|
||||
m_threads = controller->config()->threadsCount();
|
||||
m_hashrate = new double[m_threads * 3]();
|
||||
|
||||
memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
|
||||
|
@ -87,7 +88,6 @@ ApiRouter::~ApiRouter()
|
|||
void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
doc.SetObject();
|
||||
|
||||
if (req.match("/1/config")) {
|
||||
if (req.isRestricted()) {
|
||||
|
@ -100,6 +100,14 @@ void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &
|
|||
return finalize(reply, doc);
|
||||
}
|
||||
|
||||
if (req.match("/1/threads")) {
|
||||
getThreads(doc);
|
||||
|
||||
return finalize(reply, doc);
|
||||
}
|
||||
|
||||
doc.SetObject();
|
||||
|
||||
getIdentify(doc);
|
||||
getMiner(doc);
|
||||
getHashrate(doc);
|
||||
|
@ -144,7 +152,7 @@ void ApiRouter::tick(const NetworkState &network)
|
|||
|
||||
void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig)
|
||||
{
|
||||
// updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
|
||||
updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
|
||||
}
|
||||
|
||||
|
||||
|
@ -288,6 +296,18 @@ void ApiRouter::getResults(rapidjson::Document &doc) const
|
|||
}
|
||||
|
||||
|
||||
void ApiRouter::getThreads(rapidjson::Document &doc) const
|
||||
{
|
||||
doc.SetArray();
|
||||
|
||||
const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads();
|
||||
|
||||
for (const xmrig::IThread *thread : threads) {
|
||||
doc.PushBack(thread->toAPI(doc), doc.GetAllocator());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ApiRouter::setWorkerId(const char *id)
|
||||
{
|
||||
memset(m_workerId, 0, sizeof(m_workerId));
|
||||
|
|
|
@ -63,6 +63,7 @@ private:
|
|||
void getIdentify(rapidjson::Document &doc) const;
|
||||
void getMiner(rapidjson::Document &doc) const;
|
||||
void getResults(rapidjson::Document &doc) const;
|
||||
void getThreads(rapidjson::Document &doc) const;
|
||||
void setWorkerId(const char *id);
|
||||
void updateWorkerId(const char *id, const char *previousId);
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ static const char *algoNames[] = {
|
|||
|
||||
|
||||
xmrig::CommonConfig::CommonConfig() :
|
||||
m_algorithm(CRYPTONIGHT),
|
||||
m_adjusted(false),
|
||||
m_apiIPv6(true),
|
||||
m_apiRestricted(true),
|
||||
|
@ -63,7 +64,6 @@ xmrig::CommonConfig::CommonConfig() :
|
|||
m_fileName(nullptr),
|
||||
m_logFile(nullptr),
|
||||
m_userAgent(nullptr),
|
||||
m_algorithm(ALGO_CRYPTONIGHT),
|
||||
m_apiPort(0),
|
||||
m_donateLevel(kDefaultDonateLevel),
|
||||
m_printTime(60),
|
||||
|
@ -95,9 +95,9 @@ xmrig::CommonConfig::~CommonConfig()
|
|||
}
|
||||
|
||||
|
||||
const char *xmrig::CommonConfig::algoName() const
|
||||
const char *xmrig::CommonConfig::algoName(Algo algorithm)
|
||||
{
|
||||
return algoNames[m_algorithm];
|
||||
return algoNames[algorithm];
|
||||
}
|
||||
|
||||
|
||||
|
@ -367,7 +367,7 @@ void xmrig::CommonConfig::setAlgo(const char *algo)
|
|||
if (strcasecmp(algo, "cryptonight-light") == 0) {
|
||||
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");
|
||||
|
||||
m_algorithm = ALGO_CRYPTONIGHT_LITE;
|
||||
m_algorithm = CRYPTONIGHT_LITE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -375,7 +375,7 @@ void xmrig::CommonConfig::setAlgo(const char *algo)
|
|||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (algoNames[i] && strcasecmp(algo, algoNames[i]) == 0) {
|
||||
m_algorithm = (int) i;
|
||||
m_algorithm = static_cast<Algo>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
|
||||
#include "interfaces/IConfig.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
class Url;
|
||||
|
@ -43,19 +44,20 @@ public:
|
|||
CommonConfig();
|
||||
~CommonConfig();
|
||||
|
||||
const char *algoName() const;
|
||||
static const char *algoName(Algo algorithm);
|
||||
|
||||
inline Algo algorithm() const { return m_algorithm; }
|
||||
inline bool isApiIPv6() const { return m_apiIPv6; }
|
||||
inline bool isApiRestricted() const { return m_apiRestricted; }
|
||||
inline bool isBackground() const { return m_background; }
|
||||
inline bool isColors() const { return m_colors; }
|
||||
inline bool isSyslog() const { return m_syslog; }
|
||||
inline const char *algoName() const { return algoName(m_algorithm); }
|
||||
inline const char *apiToken() const { return m_apiToken; }
|
||||
inline const char *apiWorkerId() const { return m_apiWorkerId; }
|
||||
inline const char *logFile() const { return m_logFile; }
|
||||
inline const char *userAgent() const { return m_userAgent; }
|
||||
inline const std::vector<Url*> &pools() const { return m_pools; }
|
||||
inline int algorithm() const { return m_algorithm; }
|
||||
inline int apiPort() const { return m_apiPort; }
|
||||
inline int donateLevel() const { return m_donateLevel; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
|
@ -75,6 +77,7 @@ protected:
|
|||
bool save() override;
|
||||
void setFileName(const char *fileName) override;
|
||||
|
||||
Algo m_algorithm;
|
||||
bool m_adjusted;
|
||||
bool m_apiIPv6;
|
||||
bool m_apiRestricted;
|
||||
|
@ -87,7 +90,6 @@ protected:
|
|||
char *m_fileName;
|
||||
char *m_logFile;
|
||||
char *m_userAgent;
|
||||
int m_algorithm;
|
||||
int m_apiPort;
|
||||
int m_donateLevel;
|
||||
int m_printTime;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/filewritestream.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
|
@ -41,18 +42,17 @@ static char affinity_tmp[20] = { 0 };
|
|||
|
||||
|
||||
xmrig::Config::Config() : xmrig::CommonConfig(),
|
||||
m_algoVariant(AV_AUTO),
|
||||
m_doubleHash(false),
|
||||
m_dryRun(false),
|
||||
m_hugePages(true),
|
||||
m_safe(false),
|
||||
m_algoVariant(0),
|
||||
m_maxCpuUsage(75),
|
||||
m_printTime(60),
|
||||
m_priority(-1),
|
||||
m_threads(0),
|
||||
m_affinity(-1L)
|
||||
m_affinity(-1L),
|
||||
m_threadsCount(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,7 +135,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
|
|||
doc.AddMember("retries", retries(), allocator);
|
||||
doc.AddMember("retry-pause", retryPause(), allocator);
|
||||
doc.AddMember("safe", m_safe, allocator);
|
||||
doc.AddMember("threads", threads(), allocator);
|
||||
doc.AddMember("threads", threadsCount(), allocator);
|
||||
doc.AddMember("user-agent", userAgent() ? rapidjson::Value(rapidjson::StringRef(userAgent())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
|
||||
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
|
@ -159,20 +159,24 @@ bool xmrig::Config::adjust()
|
|||
}
|
||||
|
||||
m_algoVariant = getAlgoVariant();
|
||||
if (m_algoVariant == AV2_AESNI_DOUBLE || m_algoVariant == AV4_SOFT_AES_DOUBLE) {
|
||||
if (m_algoVariant == AV_DOUBLE || m_algoVariant == AV_DOUBLE_SOFT) {
|
||||
m_doubleHash = true;
|
||||
}
|
||||
|
||||
if (!m_threads) {
|
||||
m_threads = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
|
||||
if (!m_threadsCount) {
|
||||
m_threadsCount = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
|
||||
}
|
||||
else if (m_safe) {
|
||||
const int count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
|
||||
if (m_threads > count) {
|
||||
m_threads = count;
|
||||
const size_t count = Cpu::optimalThreadsCount(m_algorithm, m_doubleHash, m_maxCpuUsage);
|
||||
if (m_threadsCount > count) {
|
||||
m_threadsCount = count;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_threadsCount; ++i) {
|
||||
m_threads.push_back(CpuThread::createFromAV(i, m_algorithm, m_algoVariant, m_affinity, m_priority));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -225,7 +229,7 @@ bool xmrig::Config::parseString(int key, const char *arg)
|
|||
|
||||
case xmrig::IConfig::ThreadsKey: /* --threads */
|
||||
if (strncmp(arg, "all", 3) == 0) {
|
||||
m_threads = Cpu::threads();
|
||||
m_threadsCount = Cpu::threads();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -275,14 +279,14 @@ bool xmrig::Config::parseInt(int key, int arg)
|
|||
{
|
||||
switch (key) {
|
||||
case xmrig::IConfig::ThreadsKey: /* --threads */
|
||||
if (m_threads >= 0 && arg < 1024) {
|
||||
m_threads = arg;
|
||||
if (m_threadsCount >= 0 && arg < 1024) {
|
||||
m_threadsCount = arg;
|
||||
}
|
||||
break;
|
||||
|
||||
case xmrig::IConfig::AVKey: /* --av */
|
||||
if (arg >= AV0_AUTO && arg < AV_MAX) {
|
||||
m_algoVariant = arg;
|
||||
if (arg >= AV_AUTO && arg < AV_MAX) {
|
||||
m_algoVariant = static_cast<AlgoVariant>(arg);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -306,20 +310,20 @@ bool xmrig::Config::parseInt(int key, int arg)
|
|||
}
|
||||
|
||||
|
||||
int xmrig::Config::getAlgoVariant() const
|
||||
xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const
|
||||
{
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_algorithm == xmrig::ALGO_CRYPTONIGHT_LITE) {
|
||||
if (m_algorithm == xmrig::CRYPTONIGHT_LITE) {
|
||||
return getAlgoVariantLite();
|
||||
}
|
||||
# endif
|
||||
|
||||
if (m_algoVariant <= AV0_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV1_AESNI : AV3_SOFT_AES;
|
||||
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV_SINGLE : AV_SINGLE_SOFT;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV2_AESNI_DOUBLE) {
|
||||
return m_algoVariant + 2;
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
return static_cast<AlgoVariant>(m_algoVariant + 2);
|
||||
}
|
||||
|
||||
return m_algoVariant;
|
||||
|
@ -327,14 +331,14 @@ int xmrig::Config::getAlgoVariant() const
|
|||
|
||||
|
||||
#ifndef XMRIG_NO_AEON
|
||||
int xmrig::Config::getAlgoVariantLite() const
|
||||
xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const
|
||||
{
|
||||
if (m_algoVariant <= AV0_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV2_AESNI_DOUBLE : AV4_SOFT_AES_DOUBLE;
|
||||
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {
|
||||
return Cpu::hasAES() ? AV_DOUBLE : AV_DOUBLE_SOFT;
|
||||
}
|
||||
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV2_AESNI_DOUBLE) {
|
||||
return m_algoVariant + 2;
|
||||
if (m_safe && !Cpu::hasAES() && m_algoVariant <= AV_DOUBLE) {
|
||||
return static_cast<AlgoVariant>(m_algoVariant + 2);
|
||||
}
|
||||
|
||||
return m_algoVariant;
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
#include "core/CommonConfig.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
class Addr;
|
||||
|
@ -41,6 +42,7 @@ namespace xmrig {
|
|||
|
||||
|
||||
class ConfigLoader;
|
||||
class IThread;
|
||||
class IWatcherListener;
|
||||
|
||||
|
||||
|
@ -57,18 +59,7 @@ class IWatcherListener;
|
|||
*/
|
||||
class Config : public CommonConfig
|
||||
{
|
||||
friend class ConfigLoader;
|
||||
|
||||
public:
|
||||
enum AlgoVariant {
|
||||
AV0_AUTO,
|
||||
AV1_AESNI,
|
||||
AV2_AESNI_DOUBLE,
|
||||
AV3_SOFT_AES,
|
||||
AV4_SOFT_AES_DOUBLE,
|
||||
AV_MAX
|
||||
};
|
||||
|
||||
Config();
|
||||
~Config();
|
||||
|
||||
|
@ -76,13 +67,14 @@ public:
|
|||
|
||||
void getJSON(rapidjson::Document &doc) const override;
|
||||
|
||||
inline AlgoVariant algoVariant() const { return m_algoVariant; }
|
||||
inline bool isDoubleHash() const { return m_doubleHash; }
|
||||
inline bool isDryRun() const { return m_dryRun; }
|
||||
inline bool isHugePages() const { return m_hugePages; }
|
||||
inline int algoVariant() const { return m_algoVariant; }
|
||||
inline const std::vector<IThread *> &threads() const { return m_threads; }
|
||||
inline int printTime() const { return m_printTime; }
|
||||
inline int priority() const { return m_priority; }
|
||||
inline int threads() const { return m_threads; }
|
||||
inline int threadsCount() const { return m_threadsCount; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
|
||||
static Config *load(int argc, char **argv, IWatcherListener *listener);
|
||||
|
@ -97,21 +89,22 @@ protected:
|
|||
private:
|
||||
bool parseInt(int key, int arg);
|
||||
|
||||
int getAlgoVariant() const;
|
||||
AlgoVariant getAlgoVariant() const;
|
||||
# ifndef XMRIG_NO_AEON
|
||||
int getAlgoVariantLite() const;
|
||||
AlgoVariant getAlgoVariantLite() const;
|
||||
# endif
|
||||
|
||||
AlgoVariant m_algoVariant;
|
||||
bool m_doubleHash;
|
||||
bool m_dryRun;
|
||||
bool m_hugePages;
|
||||
bool m_safe;
|
||||
int m_algoVariant;
|
||||
int m_maxCpuUsage;
|
||||
int m_printTime;
|
||||
int m_priority;
|
||||
int m_threads;
|
||||
int64_t m_affinity;
|
||||
size_t m_threadsCount;
|
||||
std::vector<IThread *> m_threads;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,189 +0,0 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
|
||||
|
||||
#if defined(XMRIG_ARM)
|
||||
# include "crypto/CryptoNight_arm.h"
|
||||
#else
|
||||
# include "crypto/CryptoNight_x86.h"
|
||||
#endif
|
||||
|
||||
#include "crypto/CryptoNight_test.h"
|
||||
#include "net/Job.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
void (*cryptonight_hash_ctx)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = nullptr;
|
||||
|
||||
|
||||
#define CRYPTONIGHT_HASH(NAME, ITERATIONS, MEM, MASK, SOFT_AES) \
|
||||
switch (variant) { \
|
||||
case xmrig::VARIANT_V1: \
|
||||
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_V1>(input, size, output, ctx); \
|
||||
\
|
||||
case xmrig::VARIANT_NONE: \
|
||||
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_NONE>(input, size, output, ctx); \
|
||||
\
|
||||
default: \
|
||||
break; \
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, struct cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true)
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true)
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_AEON
|
||||
static void cryptonight_lite_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_lite_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
# if !defined(XMRIG_ARMv7)
|
||||
CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_lite_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, true)
|
||||
}
|
||||
|
||||
|
||||
static void cryptonight_lite_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
||||
CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, true)
|
||||
}
|
||||
|
||||
void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
|
||||
cryptonight_av1_aesni,
|
||||
cryptonight_av2_aesni_double,
|
||||
cryptonight_av3_softaes,
|
||||
cryptonight_av4_softaes_double,
|
||||
cryptonight_lite_av1_aesni,
|
||||
cryptonight_lite_av2_aesni_double,
|
||||
cryptonight_lite_av3_softaes,
|
||||
cryptonight_lite_av4_softaes_double
|
||||
};
|
||||
#else
|
||||
void (*cryptonight_variations[4])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
|
||||
cryptonight_av1_aesni,
|
||||
cryptonight_av2_aesni_double,
|
||||
cryptonight_av3_softaes,
|
||||
cryptonight_av4_softaes_double
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx)
|
||||
{
|
||||
cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx, job.variant());
|
||||
|
||||
return *reinterpret_cast<uint64_t*>(result.result + 24) < job.target();
|
||||
}
|
||||
|
||||
|
||||
bool CryptoNight::init(int algo, int variant, bool doubleHash)
|
||||
{
|
||||
if (variant < 1 || variant > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
const int index = algo == xmrig::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1);
|
||||
# else
|
||||
const int index = variant - 1;
|
||||
# endif
|
||||
|
||||
cryptonight_hash_ctx = cryptonight_variations[index];
|
||||
|
||||
return selfTest(algo, doubleHash);
|
||||
}
|
||||
|
||||
|
||||
void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant)
|
||||
{
|
||||
cryptonight_hash_ctx(input, size, output, ctx, variant);
|
||||
}
|
||||
|
||||
|
||||
bool CryptoNight::selfTest(int algo, bool doubleHash) {
|
||||
if (cryptonight_hash_ctx == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t output[64];
|
||||
|
||||
struct cryptonight_ctx *ctx = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 16));
|
||||
ctx->memory = static_cast<uint8_t *>(_mm_malloc(MONERO_MEMORY * 2, 16));
|
||||
|
||||
cryptonight_hash_ctx(test_input, 76, output, ctx, 0);
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
bool rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, (doubleHash ? 64 : 32)) == 0;
|
||||
# else
|
||||
bool rc = memcmp(output, test_output_v0, (doubleHash ? 64 : 32)) == 0;
|
||||
# endif
|
||||
|
||||
if (rc) {
|
||||
cryptonight_hash_ctx(test_input, 76, output, ctx, 1);
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v1_lite : test_output_v1, (doubleHash ? 64 : 32)) == 0;
|
||||
# else
|
||||
rc = memcmp(output, test_output_v1, (doubleHash ? 64 : 32)) == 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
_mm_free(ctx->memory);
|
||||
_mm_free(ctx);
|
||||
|
||||
return rc;
|
||||
}
|
|
@ -46,19 +46,4 @@ struct cryptonight_ctx {
|
|||
};
|
||||
|
||||
|
||||
class Job;
|
||||
class JobResult;
|
||||
|
||||
|
||||
class CryptoNight
|
||||
{
|
||||
public:
|
||||
static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx);
|
||||
static bool init(int algo, int variant, bool doubleHash);
|
||||
static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant);
|
||||
|
||||
private:
|
||||
static bool selfTest(int algo, bool doubleHash);
|
||||
};
|
||||
|
||||
#endif /* __CRYPTONIGHT_H__ */
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "crypto/CryptoNight_monero.h"
|
||||
#include "crypto/soft_aes.h"
|
||||
|
||||
|
@ -206,7 +207,21 @@ static inline void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2,
|
|||
}
|
||||
|
||||
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
inline void mix_and_propagate(__m128i& x0, __m128i& x1, __m128i& x2, __m128i& x3, __m128i& x4, __m128i& x5, __m128i& x6, __m128i& x7)
|
||||
{
|
||||
__m128i tmp0 = x0;
|
||||
x0 = _mm_xor_si128(x0, x1);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
x2 = _mm_xor_si128(x2, x3);
|
||||
x3 = _mm_xor_si128(x3, x4);
|
||||
x4 = _mm_xor_si128(x4, x5);
|
||||
x5 = _mm_xor_si128(x5, x6);
|
||||
x6 = _mm_xor_si128(x6, x7);
|
||||
x7 = _mm_xor_si128(x7, tmp0);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7;
|
||||
|
@ -223,6 +238,40 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
|||
xin6 = _mm_load_si128(input + 10);
|
||||
xin7 = _mm_load_si128(input + 11);
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
}
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k1, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k2, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k3, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k4, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k5, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k6, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k7, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k8, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
xin0 ^= k9;
|
||||
xin1 ^= k9;
|
||||
xin2 ^= k9;
|
||||
xin3 ^= k9;
|
||||
xin4 ^= k9;
|
||||
xin5 ^= k9;
|
||||
xin6 ^= k9;
|
||||
xin7 ^= k9;
|
||||
}
|
||||
else {
|
||||
aes_round<SOFT_AES>(k9, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
}
|
||||
|
||||
mix_and_propagate(xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
|
@ -264,7 +313,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
|||
}
|
||||
|
||||
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7;
|
||||
|
@ -319,6 +368,85 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
|||
else {
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
xout0 = _mm_xor_si128(_mm_load_si128(input + i + 0), xout0);
|
||||
xout1 = _mm_xor_si128(_mm_load_si128(input + i + 1), xout1);
|
||||
xout2 = _mm_xor_si128(_mm_load_si128(input + i + 2), xout2);
|
||||
xout3 = _mm_xor_si128(_mm_load_si128(input + i + 3), xout3);
|
||||
xout4 = _mm_xor_si128(_mm_load_si128(input + i + 4), xout4);
|
||||
xout5 = _mm_xor_si128(_mm_load_si128(input + i + 5), xout5);
|
||||
xout6 = _mm_xor_si128(_mm_load_si128(input + i + 6), xout6);
|
||||
xout7 = _mm_xor_si128(_mm_load_si128(input + i + 7), xout7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
xout0 ^= k9;
|
||||
xout1 ^= k9;
|
||||
xout2 ^= k9;
|
||||
xout3 ^= k9;
|
||||
xout4 ^= k9;
|
||||
xout5 ^= k9;
|
||||
xout6 ^= k9;
|
||||
xout7 ^= k9;
|
||||
}
|
||||
else {
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
if (!SOFT_AES) {
|
||||
aes_round<SOFT_AES>(_mm_setzero_si128(), &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
if (!SOFT_AES) {
|
||||
xout0 ^= k9;
|
||||
xout1 ^= k9;
|
||||
xout2 ^= k9;
|
||||
xout3 ^= k9;
|
||||
xout4 ^= k9;
|
||||
xout5 ^= k9;
|
||||
xout6 ^= k9;
|
||||
xout7 ^= k9;
|
||||
}
|
||||
else {
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
}
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
_mm_store_si128(output + 4, xout0);
|
||||
|
@ -332,14 +460,23 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
|||
}
|
||||
|
||||
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 32);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
|
||||
VARIANT1_INIT(0);
|
||||
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
|
@ -384,18 +521,36 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
|
|||
ah0 ^= ch;
|
||||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
|
||||
}
|
||||
|
||||
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 64);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
keccak(input + size, (int) size, ctx->state1, 200);
|
||||
|
||||
|
@ -407,8 +562,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
uint64_t* h1 = reinterpret_cast<uint64_t*>(ctx->state1);
|
||||
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
uint64_t al1 = h1[0] ^ h1[4];
|
||||
|
@ -465,6 +620,15 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
|
||||
cl = ((uint64_t*) &l1[idx1 & MASK])[0];
|
||||
ch = ((uint64_t*) &l1[idx1 & MASK])[1];
|
||||
lo = __umul128(idx1, cl, &hi);
|
||||
|
@ -480,10 +644,19 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
ah1 ^= ch;
|
||||
al1 ^= cl;
|
||||
idx1 = al1;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l1[idx1 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l1[idx1 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l1[idx1 & MASK])[0] = n ^ q;
|
||||
idx1 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
|
||||
keccakf(h0, 24);
|
||||
keccakf(h1, 24);
|
||||
|
@ -492,4 +665,22 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* __CRYPTONIGHT_ARM_H__ */
|
||||
|
|
117
src/crypto/CryptoNight_constants.h
Normal file
117
src/crypto/CryptoNight_constants.h
Normal file
|
@ -0,0 +1,117 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CRYPTONIGHT_CONSTANTS_H__
|
||||
#define __CRYPTONIGHT_CONSTANTS_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
namespace xmrig
|
||||
{
|
||||
|
||||
constexpr const size_t CRYPTONIGHT_MEMORY = 2 * 1024 * 1024;
|
||||
constexpr const uint32_t CRYPTONIGHT_MASK = 0x1FFFF0;
|
||||
constexpr const uint32_t CRYPTONIGHT_ITER = 0x80000;
|
||||
|
||||
constexpr const size_t CRYPTONIGHT_LITE_MEMORY = 1 * 1024 * 1024;
|
||||
constexpr const uint32_t CRYPTONIGHT_LITE_MASK = 0xFFFF0;
|
||||
constexpr const uint32_t CRYPTONIGHT_LITE_ITER = 0x40000;
|
||||
|
||||
constexpr const size_t CRYPTONIGHT_HEAVY_MEMORY = 4 * 1024 * 1024;
|
||||
constexpr const uint32_t CRYPTONIGHT_HEAVY_MASK = 0x3FFFF0;
|
||||
constexpr const uint32_t CRYPTONIGHT_HEAVY_ITER = 0x40000;
|
||||
|
||||
|
||||
template<Algo ALGO> inline constexpr size_t cn_select_memory() { return 0; }
|
||||
template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT>() { return CRYPTONIGHT_MEMORY; }
|
||||
template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT_LITE>() { return CRYPTONIGHT_LITE_MEMORY; }
|
||||
template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT_HEAVY>() { return CRYPTONIGHT_HEAVY_MEMORY; }
|
||||
|
||||
inline size_t cn_select_memory(Algo algorithm)
|
||||
{
|
||||
switch(algorithm)
|
||||
{
|
||||
case CRYPTONIGHT:
|
||||
return CRYPTONIGHT_MEMORY;
|
||||
|
||||
case CRYPTONIGHT_LITE:
|
||||
return CRYPTONIGHT_LITE_MEMORY;
|
||||
|
||||
case CRYPTONIGHT_HEAVY:
|
||||
return CRYPTONIGHT_HEAVY_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<Algo ALGO> inline constexpr uint32_t cn_select_mask() { return 0; }
|
||||
template<> inline constexpr uint32_t cn_select_mask<CRYPTONIGHT>() { return CRYPTONIGHT_MASK; }
|
||||
template<> inline constexpr uint32_t cn_select_mask<CRYPTONIGHT_LITE>() { return CRYPTONIGHT_LITE_MASK; }
|
||||
template<> inline constexpr uint32_t cn_select_mask<CRYPTONIGHT_HEAVY>() { return CRYPTONIGHT_HEAVY_MASK; }
|
||||
|
||||
inline uint32_t cn_select_mask(Algo algorithm)
|
||||
{
|
||||
switch(algorithm)
|
||||
{
|
||||
case CRYPTONIGHT:
|
||||
return CRYPTONIGHT_MASK;
|
||||
|
||||
case CRYPTONIGHT_LITE:
|
||||
return CRYPTONIGHT_LITE_MASK;
|
||||
|
||||
case CRYPTONIGHT_HEAVY:
|
||||
return CRYPTONIGHT_HEAVY_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<Algo ALGO> inline constexpr uint32_t cn_select_iter() { return 0; }
|
||||
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT>() { return CRYPTONIGHT_ITER; }
|
||||
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_LITE>() { return CRYPTONIGHT_LITE_ITER; }
|
||||
template<> inline constexpr uint32_t cn_select_iter<CRYPTONIGHT_HEAVY>() { return CRYPTONIGHT_HEAVY_ITER; }
|
||||
|
||||
inline uint32_t cn_select_iter(Algo algorithm)
|
||||
{
|
||||
switch(algorithm)
|
||||
{
|
||||
case CRYPTONIGHT:
|
||||
return CRYPTONIGHT_ITER;
|
||||
|
||||
case CRYPTONIGHT_LITE:
|
||||
return CRYPTONIGHT_LITE_ITER;
|
||||
|
||||
case CRYPTONIGHT_HEAVY:
|
||||
return CRYPTONIGHT_HEAVY_ITER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __CRYPTONIGHT_CONSTANTS_H__ */
|
|
@ -66,7 +66,7 @@ const static uint8_t test_output_v0_lite[64] = {
|
|||
};
|
||||
|
||||
|
||||
// AEON v2
|
||||
// AEON v7
|
||||
const static uint8_t test_output_v1_lite[64] = {
|
||||
0x87, 0xC4, 0xE5, 0x70, 0x65, 0x3E, 0xB4, 0xC2, 0xB4, 0x2B, 0x7A, 0x0D, 0x54, 0x65, 0x59, 0x45,
|
||||
0x2D, 0xFA, 0xB5, 0x73, 0xB8, 0x2E, 0xC5, 0x2F, 0x15, 0x2B, 0x7F, 0xF9, 0x8E, 0x79, 0x44, 0x6F,
|
||||
|
@ -76,4 +76,14 @@ const static uint8_t test_output_v1_lite[64] = {
|
|||
#endif
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_SUMO
|
||||
const static uint8_t test_output_heavy[64] = {
|
||||
0x4D, 0x94, 0x7D, 0xD6, 0xDB, 0x6E, 0x07, 0x48, 0x26, 0x4A, 0x51, 0x2E, 0xAC, 0xF3, 0x25, 0x4A,
|
||||
0x1F, 0x1A, 0xA2, 0x5B, 0xFC, 0x0A, 0xAD, 0x82, 0xDE, 0xA8, 0x99, 0x96, 0x88, 0x52, 0xD2, 0x7D,
|
||||
0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64,
|
||||
0xBB, 0xE1, 0x18, 0x7F, 0x55, 0x01, 0x4B, 0x39, 0xE5, 0xF3, 0xD6, 0x93, 0x28, 0xE4, 0x8F, 0xC2
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __CRYPTONIGHT_TEST_H__ */
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "crypto/CryptoNight_monero.h"
|
||||
#include "crypto/soft_aes.h"
|
||||
|
||||
|
@ -217,7 +218,21 @@ static inline void aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i* x2,
|
|||
}
|
||||
|
||||
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
inline void mix_and_propagate(__m128i& x0, __m128i& x1, __m128i& x2, __m128i& x3, __m128i& x4, __m128i& x5, __m128i& x6, __m128i& x7)
|
||||
{
|
||||
__m128i tmp0 = x0;
|
||||
x0 = _mm_xor_si128(x0, x1);
|
||||
x1 = _mm_xor_si128(x1, x2);
|
||||
x2 = _mm_xor_si128(x2, x3);
|
||||
x3 = _mm_xor_si128(x3, x4);
|
||||
x4 = _mm_xor_si128(x4, x5);
|
||||
x5 = _mm_xor_si128(x5, x6);
|
||||
x6 = _mm_xor_si128(x6, x7);
|
||||
x7 = _mm_xor_si128(x7, tmp0);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7;
|
||||
|
@ -234,6 +249,23 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
|||
xin6 = _mm_load_si128(input + 10);
|
||||
xin7 = _mm_load_si128(input + 11);
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
aes_round<SOFT_AES>(k0, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k1, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k2, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k3, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k4, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k5, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k6, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k7, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k8, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k9, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
|
||||
mix_and_propagate(xin0, xin1, xin2, xin3, xin4, xin5, xin6, xin7);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
aes_round<SOFT_AES>(k0, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
aes_round<SOFT_AES>(k1, &xin0, &xin1, &xin2, &xin3, &xin4, &xin5, &xin6, &xin7);
|
||||
|
@ -258,7 +290,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
|
|||
}
|
||||
|
||||
|
||||
template<size_t MEM, bool SOFT_AES>
|
||||
template<xmrig::Algo ALGO, size_t MEM, bool SOFT_AES>
|
||||
static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
||||
{
|
||||
__m128i xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7;
|
||||
|
@ -296,6 +328,51 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
|||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) {
|
||||
xout0 = _mm_xor_si128(_mm_load_si128(input + i + 0), xout0);
|
||||
xout1 = _mm_xor_si128(_mm_load_si128(input + i + 1), xout1);
|
||||
xout2 = _mm_xor_si128(_mm_load_si128(input + i + 2), xout2);
|
||||
xout3 = _mm_xor_si128(_mm_load_si128(input + i + 3), xout3);
|
||||
xout4 = _mm_xor_si128(_mm_load_si128(input + i + 4), xout4);
|
||||
xout5 = _mm_xor_si128(_mm_load_si128(input + i + 5), xout5);
|
||||
xout6 = _mm_xor_si128(_mm_load_si128(input + i + 6), xout6);
|
||||
xout7 = _mm_xor_si128(_mm_load_si128(input + i + 7), xout7);
|
||||
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
aes_round<SOFT_AES>(k0, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k1, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k2, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k3, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k4, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k5, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k6, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k7, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k8, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
aes_round<SOFT_AES>(k9, &xout0, &xout1, &xout2, &xout3, &xout4, &xout5, &xout6, &xout7);
|
||||
|
||||
mix_and_propagate(xout0, xout1, xout2, xout3, xout4, xout5, xout6, xout7);
|
||||
}
|
||||
}
|
||||
|
||||
_mm_store_si128(output + 4, xout0);
|
||||
|
@ -309,14 +386,23 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
|||
}
|
||||
|
||||
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 32);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
|
||||
VARIANT1_INIT(0);
|
||||
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
|
||||
const uint8_t* l0 = ctx->memory;
|
||||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
|
@ -358,18 +444,36 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
|
|||
ah0 ^= ch;
|
||||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
|
||||
|
||||
keccakf(h0, 24);
|
||||
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
|
||||
}
|
||||
|
||||
|
||||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
constexpr size_t MASK = xmrig::cn_select_mask<ALGO>();
|
||||
constexpr size_t ITERATIONS = xmrig::cn_select_iter<ALGO>();
|
||||
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
|
||||
|
||||
if (VARIANT > 0 && size < 43) {
|
||||
memset(output, 0, 64);
|
||||
return;
|
||||
}
|
||||
|
||||
keccak(input, (int) size, ctx->state0, 200);
|
||||
keccak(input + size, (int) size, ctx->state1, 200);
|
||||
|
||||
|
@ -381,8 +485,8 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
|
||||
uint64_t* h1 = reinterpret_cast<uint64_t*>(ctx->state1);
|
||||
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h0, (__m128i*) l0);
|
||||
cn_explode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) h1, (__m128i*) l1);
|
||||
|
||||
uint64_t al0 = h0[0] ^ h0[4];
|
||||
uint64_t al1 = h1[0] ^ h1[4];
|
||||
|
@ -437,6 +541,15 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
al0 ^= cl;
|
||||
idx0 = al0;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l0[idx0 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l0[idx0 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l0[idx0 & MASK])[0] = n ^ q;
|
||||
idx0 = d ^ q;
|
||||
}
|
||||
|
||||
cl = ((uint64_t*) &l1[idx1 & MASK])[0];
|
||||
ch = ((uint64_t*) &l1[idx1 & MASK])[1];
|
||||
lo = __umul128(idx1, cl, &hi);
|
||||
|
@ -452,10 +565,19 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
ah1 ^= ch;
|
||||
al1 ^= cl;
|
||||
idx1 = al1;
|
||||
|
||||
if (ALGO == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
int64_t n = ((int64_t*)&l1[idx1 & MASK])[0];
|
||||
int32_t d = ((int32_t*)&l1[idx1 & MASK])[2];
|
||||
int64_t q = n / (d | 0x5);
|
||||
|
||||
((int64_t*)&l1[idx1 & MASK])[0] = n ^ q;
|
||||
idx1 = d ^ q;
|
||||
}
|
||||
}
|
||||
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l0, (__m128i*) h0);
|
||||
cn_implode_scratchpad<ALGO, MEM, SOFT_AES>((__m128i*) l1, (__m128i*) h1);
|
||||
|
||||
keccakf(h0, 24);
|
||||
keccakf(h1, 24);
|
||||
|
@ -464,4 +586,22 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si
|
|||
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, output + 32);
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_triple_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_quad_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<xmrig::Algo ALGO, bool SOFT_AES, int VARIANT>
|
||||
inline void cryptonight_penta_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* __CRYPTONIGHT_X86_H__ */
|
||||
|
|
64
src/interfaces/IThread.h
Normal file
64
src/interfaces/IThread.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2018 XMRig <support@xmrig.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __ITHREAD_H__
|
||||
#define __ITHREAD_H__
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "rapidjson/fwd.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IThread
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
CPU,
|
||||
OpenCL,
|
||||
CUDA
|
||||
};
|
||||
|
||||
virtual ~IThread() {}
|
||||
|
||||
virtual Algo algorithm() const = 0;
|
||||
virtual int multiway() const = 0;
|
||||
virtual int priority() const = 0;
|
||||
virtual int64_t affinity() const = 0;
|
||||
virtual size_t index() const = 0;
|
||||
virtual Type type() const = 0;
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
virtual rapidjson::Value toAPI(rapidjson::Document &doc) const = 0;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif // __ITHREAD_H__
|
|
@ -4,8 +4,8 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -33,9 +33,10 @@ class IWorker
|
|||
public:
|
||||
virtual ~IWorker() {}
|
||||
|
||||
virtual bool start() = 0;
|
||||
virtual size_t id() const = 0;
|
||||
virtual uint64_t hashCount() const = 0;
|
||||
virtual uint64_t timestamp() const = 0;
|
||||
virtual void start() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
@ -59,14 +60,14 @@ static inline char hf_bin2hex(unsigned char c)
|
|||
Job::Job() :
|
||||
m_nicehash(false),
|
||||
m_coin(),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_poolId(-2),
|
||||
m_threadId(-1),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_size(0),
|
||||
m_diff(0),
|
||||
m_target(0),
|
||||
m_blob()
|
||||
m_blob(),
|
||||
m_variant(xmrig::VARIANT_AUTO)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -77,12 +78,12 @@ Job::Job(int poolId, bool nicehash, int algo, int variant) :
|
|||
m_algo(algo),
|
||||
m_poolId(poolId),
|
||||
m_threadId(-1),
|
||||
m_variant(variant),
|
||||
m_size(0),
|
||||
m_diff(0),
|
||||
m_target(0),
|
||||
m_blob()
|
||||
{
|
||||
setVariant(variant);
|
||||
}
|
||||
|
||||
|
||||
|
@ -164,7 +165,7 @@ void Job::setCoin(const char *coin)
|
|||
}
|
||||
|
||||
strncpy(m_coin, coin, sizeof(m_coin));
|
||||
m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::ALGO_CRYPTONIGHT_LITE : xmrig::ALGO_CRYPTONIGHT;
|
||||
m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::CRYPTONIGHT_LITE : xmrig::CRYPTONIGHT;
|
||||
}
|
||||
|
||||
|
||||
|
@ -174,10 +175,12 @@ void Job::setVariant(int variant)
|
|||
case xmrig::VARIANT_AUTO:
|
||||
case xmrig::VARIANT_NONE:
|
||||
case xmrig::VARIANT_V1:
|
||||
m_variant = variant;
|
||||
m_variant = static_cast<xmrig::Variant>(variant);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
m_variant = xmrig::VARIANT_AUTO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ public:
|
|||
inline const xmrig::Id &id() const { return m_id; }
|
||||
inline int poolId() const { return m_poolId; }
|
||||
inline int threadId() const { return m_threadId; }
|
||||
inline int variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? 1 : 0) : m_variant); }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
inline uint32_t diff() const { return (uint32_t) m_diff; }
|
||||
|
@ -63,6 +62,7 @@ public:
|
|||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
||||
inline xmrig::Variant variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_V1 : xmrig::VARIANT_NONE) : m_variant); }
|
||||
|
||||
static bool fromHex(const char* in, unsigned int len, unsigned char* out);
|
||||
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
|
||||
|
@ -78,12 +78,12 @@ private:
|
|||
int m_algo;
|
||||
int m_poolId;
|
||||
int m_threadId;
|
||||
int m_variant;
|
||||
size_t m_size;
|
||||
uint64_t m_diff;
|
||||
uint64_t m_target;
|
||||
uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
|
||||
xmrig::Id m_id;
|
||||
xmrig::Variant m_variant;
|
||||
};
|
||||
|
||||
#endif /* __JOB_H__ */
|
||||
|
|
|
@ -41,7 +41,7 @@ Url::Url() :
|
|||
m_host(nullptr),
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_keepAlive(0),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_url(nullptr),
|
||||
|
@ -66,7 +66,7 @@ Url::Url(const char *url) :
|
|||
m_host(nullptr),
|
||||
m_password(nullptr),
|
||||
m_user(nullptr),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_keepAlive(0),
|
||||
m_variant(xmrig::VARIANT_AUTO),
|
||||
m_url(nullptr),
|
||||
|
@ -80,7 +80,7 @@ Url::Url(const char *host, uint16_t port, const char *user, const char *password
|
|||
m_nicehash(nicehash),
|
||||
m_password(password ? strdup(password) : nullptr),
|
||||
m_user(user ? strdup(user) : nullptr),
|
||||
m_algo(xmrig::ALGO_CRYPTONIGHT),
|
||||
m_algo(xmrig::CRYPTONIGHT),
|
||||
m_keepAlive(keepAlive),
|
||||
m_variant(variant),
|
||||
m_url(nullptr),
|
||||
|
|
|
@ -59,11 +59,15 @@ DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyL
|
|||
keccak(reinterpret_cast<const uint8_t *>(user), static_cast<int>(strlen(user)), hash, sizeof(hash));
|
||||
Job::toHex(hash, 32, userId);
|
||||
|
||||
if (algo == xmrig::ALGO_CRYPTONIGHT) {
|
||||
if (algo == xmrig::CRYPTONIGHT) {
|
||||
m_pools.push_back(new Url(kDonatePool1, 6666, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool1, 80, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false));
|
||||
}
|
||||
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_pools.push_back(new Url(kDonatePool1, 8888, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool1, 8889, userId, nullptr, false, true));
|
||||
}
|
||||
else {
|
||||
m_pools.push_back(new Url(kDonatePool1, 5555, userId, nullptr, false, true));
|
||||
m_pools.push_back(new Url(kDonatePool1, 7777, userId, nullptr, false, true));
|
||||
|
|
216
src/workers/CpuThread.cpp
Normal file
216
src/workers/CpuThread.cpp
Normal file
|
@ -0,0 +1,216 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#include "core/CommonConfig.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "workers/CpuThread.h"
|
||||
|
||||
|
||||
#if defined(XMRIG_ARM)
|
||||
# include "crypto/CryptoNight_arm.h"
|
||||
#else
|
||||
# include "crypto/CryptoNight_x86.h"
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::CpuThread::CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch) :
|
||||
m_algorithm(algorithm),
|
||||
m_av(av),
|
||||
m_prefetch(prefetch),
|
||||
m_softAES(softAES),
|
||||
m_priority(priority),
|
||||
m_affinity(affinity),
|
||||
m_multiway(multiway),
|
||||
m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuThread::~CpuThread()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant av, Variant variant)
|
||||
{
|
||||
assert(variant == VARIANT_NONE || variant == VARIANT_V1);
|
||||
|
||||
static const cn_hash_fun func_table[50] = {
|
||||
cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, false, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_NONE>,
|
||||
|
||||
cryptonight_single_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, false, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_V1>,
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, false, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, true, VARIANT_NONE>,
|
||||
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_single_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, false, VARIANT_V1>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_LITE, true, VARIANT_V1>,
|
||||
# else
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
# endif
|
||||
|
||||
# ifndef XMRIG_NO_SUMO
|
||||
cryptonight_single_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_single_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_double_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_HEAVY, false, VARIANT_NONE>,
|
||||
cryptonight_triple_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_quad_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
cryptonight_penta_hash<CRYPTONIGHT_HEAVY, true, VARIANT_NONE>,
|
||||
# else
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
# endif
|
||||
};
|
||||
|
||||
# ifndef XMRIG_NO_SUMO
|
||||
if (algorithm == CRYPTONIGHT_HEAVY) {
|
||||
variant = VARIANT_NONE;
|
||||
}
|
||||
# endif
|
||||
|
||||
return func_table[20 * algorithm + 10 * variant + av - 1];
|
||||
}
|
||||
|
||||
|
||||
xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority)
|
||||
{
|
||||
assert(av > AV_AUTO && av < AV_MAX);
|
||||
|
||||
Multiway multiway = SingleWay;
|
||||
bool softAES = false;
|
||||
|
||||
switch (av) {
|
||||
case AV_SINGLE_SOFT:
|
||||
softAES = true;
|
||||
break;
|
||||
|
||||
case AV_DOUBLE:
|
||||
multiway = DoubleWay;
|
||||
case AV_DOUBLE_SOFT:
|
||||
softAES = true;
|
||||
break;
|
||||
|
||||
case AV_TRIPLE:
|
||||
multiway = TripleWay;
|
||||
case AV_TRIPLE_SOFT:
|
||||
softAES = true;
|
||||
break;
|
||||
|
||||
case AV_QUAD:
|
||||
multiway = QuadWay;
|
||||
case AV_QUAD_SOFT:
|
||||
softAES = true;
|
||||
break;
|
||||
|
||||
case AV_PENTA:
|
||||
multiway = PentaWay;
|
||||
case AV_PENTA_SOFT:
|
||||
softAES = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
int64_t cpuId = -1L;
|
||||
|
||||
if (affinity != -1L) {
|
||||
size_t idx = 0;
|
||||
|
||||
for (size_t i = 0; i < 64; i++) {
|
||||
if (!(affinity & (1ULL << i))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (idx == index) {
|
||||
cpuId = i;
|
||||
break;
|
||||
}
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
return new CpuThread(index, algorithm, av, multiway, cpuId, priority, softAES, false);
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_NO_API
|
||||
rapidjson::Value xmrig::CpuThread::toAPI(rapidjson::Document &doc) const
|
||||
{
|
||||
rapidjson::Value obj(rapidjson::kObjectType);
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
obj.AddMember("type", "cpu", allocator);
|
||||
obj.AddMember("algo", rapidjson::StringRef(CommonConfig::algoName(algorithm())), allocator);
|
||||
obj.AddMember("av", m_av, allocator);
|
||||
obj.AddMember("low_power_mode", multiway(), allocator);
|
||||
obj.AddMember("affine_to_cpu", affinity(), allocator);
|
||||
obj.AddMember("priority", priority(), allocator);
|
||||
obj.AddMember("soft_aes", isSoftAES(), allocator);
|
||||
|
||||
return obj;
|
||||
}
|
||||
#endif
|
87
src/workers/CpuThread.h
Normal file
87
src/workers/CpuThread.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CPUTHREAD_H__
|
||||
#define __CPUTHREAD_H__
|
||||
|
||||
|
||||
#include "interfaces/IThread.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
struct cryptonight_ctx;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class CpuThread : public IThread
|
||||
{
|
||||
public:
|
||||
enum Multiway {
|
||||
SingleWay = 1,
|
||||
DoubleWay,
|
||||
TripleWay,
|
||||
QuadWay,
|
||||
PentaWay
|
||||
};
|
||||
|
||||
CpuThread(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch);
|
||||
~CpuThread();
|
||||
|
||||
typedef void (*cn_hash_fun)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx);
|
||||
|
||||
static cn_hash_fun fn(Algo algorithm, AlgoVariant av, Variant variant);
|
||||
static CpuThread *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority);
|
||||
|
||||
inline bool isPrefetch() const { return m_prefetch; }
|
||||
inline bool isSoftAES() const { return m_softAES; }
|
||||
inline cn_hash_fun fn(Variant variant) const { return fn(m_algorithm, m_av, variant); }
|
||||
|
||||
inline Algo algorithm() const override { return m_algorithm; }
|
||||
inline int multiway() const override { return m_multiway; }
|
||||
inline int priority() const override { return m_priority; }
|
||||
inline int64_t affinity() const override { return m_affinity; }
|
||||
inline size_t index() const override { return m_index; }
|
||||
inline Type type() const override { return CPU; }
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
rapidjson::Value toAPI(rapidjson::Document &doc) const override;
|
||||
# endif
|
||||
|
||||
private:
|
||||
const Algo m_algorithm;
|
||||
const AlgoVariant m_av;
|
||||
const bool m_prefetch;
|
||||
const bool m_softAES;
|
||||
const int m_priority;
|
||||
const int64_t m_affinity;
|
||||
const Multiway m_multiway;
|
||||
const size_t m_index;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __CPUTHREAD_H__ */
|
|
@ -26,7 +26,8 @@
|
|||
#include <thread>
|
||||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_test.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "workers/DoubleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
@ -61,8 +62,12 @@ DoubleWorker::~DoubleWorker()
|
|||
}
|
||||
|
||||
|
||||
void DoubleWorker::start()
|
||||
bool DoubleWorker::start()
|
||||
{
|
||||
if (!selfTest()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (Workers::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
do {
|
||||
|
@ -86,7 +91,7 @@ void DoubleWorker::start()
|
|||
*Job::nonce(m_state->blob) = ++m_state->nonce1;
|
||||
*Job::nonce(m_state->blob + m_state->job.size()) = ++m_state->nonce2;
|
||||
|
||||
CryptoNight::hash(m_state->blob, m_state->job.size(), m_hash, m_ctx, m_state->job.variant());
|
||||
m_thread->fn(m_state->job.variant())(m_state->blob, m_state->job.size(), m_hash, m_ctx);
|
||||
|
||||
if (*reinterpret_cast<uint64_t*>(m_hash + 24) < m_state->job.target()) {
|
||||
Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce1, m_hash, m_state->job.diff()));
|
||||
|
@ -101,6 +106,8 @@ void DoubleWorker::start()
|
|||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -115,6 +122,32 @@ bool DoubleWorker::resume(const Job &job)
|
|||
}
|
||||
|
||||
|
||||
bool DoubleWorker::selfTest()
|
||||
{
|
||||
if (m_thread->fn(xmrig::VARIANT_NONE) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_thread->fn(xmrig::VARIANT_NONE)(test_input, 76, m_hash, m_ctx);
|
||||
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_hash, test_output_v0, 64) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_hash, m_ctx);
|
||||
|
||||
return memcmp(m_hash, test_output_v1, 64) == 0;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_hash, test_output_v0_lite, 64) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_hash, m_ctx);
|
||||
|
||||
return memcmp(m_hash, test_output_v1_lite, 64) == 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
return memcmp(m_hash, test_output_heavy, 64) == 0;
|
||||
}
|
||||
|
||||
|
||||
void DoubleWorker::consumeJob()
|
||||
{
|
||||
Job job = Workers::job();
|
||||
|
@ -134,12 +167,12 @@ void DoubleWorker::consumeJob()
|
|||
memcpy(m_state->blob + m_state->job.size(), m_state->job.blob(), m_state->job.size());
|
||||
|
||||
if (m_state->job.isNicehash()) {
|
||||
m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / (m_threads * 2) * m_id);
|
||||
m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / (m_threads * 2) * (m_id + m_threads));
|
||||
m_state->nonce1 = (*Job::nonce(m_state->blob) & 0xff000000U) + (0xffffffU / m_totalWays * m_id);
|
||||
m_state->nonce2 = (*Job::nonce(m_state->blob + m_state->job.size()) & 0xff000000U) + (0xffffffU / m_totalWays * (m_id + m_totalThreads));
|
||||
}
|
||||
else {
|
||||
m_state->nonce1 = 0xffffffffU / (m_threads * 2) * m_id;
|
||||
m_state->nonce2 = 0xffffffffU / (m_threads * 2) * (m_id + m_threads);
|
||||
m_state->nonce1 = 0xffffffffU / m_totalWays * m_id;
|
||||
m_state->nonce2 = 0xffffffffU / m_totalWays * (m_id + m_totalThreads);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,10 +40,11 @@ public:
|
|||
DoubleWorker(Handle *handle);
|
||||
~DoubleWorker();
|
||||
|
||||
void start() override;
|
||||
bool start() override;
|
||||
|
||||
private:
|
||||
bool resume(const Job &job);
|
||||
bool selfTest();
|
||||
void consumeJob();
|
||||
void save(const Job &job);
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,12 +25,12 @@
|
|||
#include "workers/Handle.h"
|
||||
|
||||
|
||||
Handle::Handle(int threadId, int threads, int64_t affinity, int priority) :
|
||||
m_priority(priority),
|
||||
m_threadId(threadId),
|
||||
m_threads(threads),
|
||||
Handle::Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays, int64_t affinity) :
|
||||
m_affinity(affinity),
|
||||
m_worker(nullptr)
|
||||
m_worker(nullptr),
|
||||
m_totalThreads(totalThreads),
|
||||
m_totalWays(totalWays),
|
||||
m_config(config)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,30 +29,34 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#include "interfaces/IThread.h"
|
||||
|
||||
|
||||
class IWorker;
|
||||
|
||||
|
||||
class Handle
|
||||
{
|
||||
public:
|
||||
Handle(int threadId, int threads, int64_t affinity, int priority);
|
||||
Handle(xmrig::IThread *config, size_t totalThreads, size_t totalWays, int64_t affinity);
|
||||
void join();
|
||||
void start(void (*callback) (void *));
|
||||
|
||||
inline int priority() const { return m_priority; }
|
||||
inline int threadId() const { return m_threadId; }
|
||||
inline int threads() const { return m_threads; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
inline IWorker *worker() const { return m_worker; }
|
||||
inline size_t threadId() const { return m_config->index(); }
|
||||
inline size_t totalThreads() const { return m_totalThreads; }
|
||||
inline size_t totalWays() const { return m_totalWays; }
|
||||
inline void setWorker(IWorker *worker) { m_worker = worker; }
|
||||
inline xmrig::IThread *config() const { return m_config; }
|
||||
|
||||
private:
|
||||
int m_priority;
|
||||
int m_threadId;
|
||||
int m_threads;
|
||||
int64_t m_affinity;
|
||||
IWorker *m_worker;
|
||||
size_t m_totalThreads;
|
||||
size_t m_totalWays;
|
||||
uv_thread_t m_thread;
|
||||
xmrig::IThread *m_config;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
#include <thread>
|
||||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_test.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
|
@ -37,8 +38,12 @@ SingleWorker::SingleWorker(Handle *handle)
|
|||
}
|
||||
|
||||
|
||||
void SingleWorker::start()
|
||||
bool SingleWorker::start()
|
||||
{
|
||||
if (!selfTest()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (Workers::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
do {
|
||||
|
@ -61,7 +66,8 @@ void SingleWorker::start()
|
|||
m_count++;
|
||||
*m_job.nonce() = ++m_result.nonce;
|
||||
|
||||
if (CryptoNight::hash(m_job, m_result, m_ctx)) {
|
||||
m_thread->fn(m_job.variant())(m_job.blob(), m_job.size(), m_result.result, m_ctx);
|
||||
if (*reinterpret_cast<uint64_t*>(m_result.result + 24) < m_job.target()) {
|
||||
Workers::submit(m_result);
|
||||
}
|
||||
|
||||
|
@ -70,6 +76,8 @@ void SingleWorker::start()
|
|||
|
||||
consumeJob();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,6 +94,32 @@ bool SingleWorker::resume(const Job &job)
|
|||
}
|
||||
|
||||
|
||||
bool SingleWorker::selfTest()
|
||||
{
|
||||
if (m_thread->fn(xmrig::VARIANT_NONE) == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_thread->fn(xmrig::VARIANT_NONE)(test_input, 76, m_result.result, m_ctx);
|
||||
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT && memcmp(m_result.result, test_output_v0, 32) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_result.result, m_ctx);
|
||||
|
||||
return memcmp(m_result.result, test_output_v1, 32) == 0;
|
||||
}
|
||||
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_thread->algorithm() == xmrig::CRYPTONIGHT_LITE && memcmp(m_result.result, test_output_v0_lite, 32) == 0) {
|
||||
m_thread->fn(xmrig::VARIANT_V1)(test_input, 76, m_result.result, m_ctx);
|
||||
|
||||
return memcmp(m_result.result, test_output_v1_lite, 32) == 0;
|
||||
}
|
||||
# endif
|
||||
|
||||
return memcmp(m_result.result, test_output_heavy, 32) == 0;
|
||||
}
|
||||
|
||||
|
||||
void SingleWorker::consumeJob()
|
||||
{
|
||||
Job job = Workers::job();
|
||||
|
@ -104,10 +138,10 @@ void SingleWorker::consumeJob()
|
|||
m_result = m_job;
|
||||
|
||||
if (m_job.isNicehash()) {
|
||||
m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_threads * m_id);
|
||||
m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_totalWays * m_id);
|
||||
}
|
||||
else {
|
||||
m_result.nonce = 0xffffffffU / m_threads * m_id;
|
||||
m_result.nonce = 0xffffffffU / m_totalWays * m_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,11 @@ class SingleWorker : public Worker
|
|||
public:
|
||||
SingleWorker(Handle *handle);
|
||||
|
||||
void start() override;
|
||||
bool start() override;
|
||||
|
||||
private:
|
||||
bool resume(const Job &job);
|
||||
bool selfTest();
|
||||
void consumeJob();
|
||||
void save(const Job &job);
|
||||
|
||||
|
|
|
@ -27,23 +27,26 @@
|
|||
#include "Cpu.h"
|
||||
#include "Mem.h"
|
||||
#include "Platform.h"
|
||||
#include "workers/CpuThread.h"
|
||||
#include "workers/Handle.h"
|
||||
#include "workers/Worker.h"
|
||||
|
||||
|
||||
Worker::Worker(Handle *handle) :
|
||||
m_id(handle->threadId()),
|
||||
m_threads(handle->threads()),
|
||||
m_totalThreads(handle->totalThreads()),
|
||||
m_totalWays(handle->totalWays()),
|
||||
m_hashCount(0),
|
||||
m_timestamp(0),
|
||||
m_count(0),
|
||||
m_sequence(0)
|
||||
m_sequence(0),
|
||||
m_thread(static_cast<xmrig::CpuThread *>(handle->config()))
|
||||
{
|
||||
if (Cpu::threads() > 1 && handle->affinity() != -1L) {
|
||||
Cpu::setAffinity(m_id, handle->affinity());
|
||||
}
|
||||
|
||||
Platform::setThreadPriority(handle->priority());
|
||||
Platform::setThreadPriority(handle->config()->priority());
|
||||
m_ctx = Mem::create(m_id);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,12 +36,18 @@ struct cryptonight_ctx;
|
|||
class Handle;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class CpuThread;
|
||||
}
|
||||
|
||||
|
||||
class Worker : public IWorker
|
||||
{
|
||||
public:
|
||||
Worker(Handle *handle);
|
||||
~Worker();
|
||||
|
||||
inline size_t id() const override { return m_id; }
|
||||
inline uint64_t hashCount() const override { return m_hashCount.load(std::memory_order_relaxed); }
|
||||
inline uint64_t timestamp() const override { return m_timestamp.load(std::memory_order_relaxed); }
|
||||
|
||||
|
@ -49,12 +55,14 @@ protected:
|
|||
void storeStats();
|
||||
|
||||
cryptonight_ctx *m_ctx;
|
||||
int m_id;
|
||||
int m_threads;
|
||||
size_t m_id;
|
||||
size_t m_totalThreads;
|
||||
size_t m_totalWays;
|
||||
std::atomic<uint64_t> m_hashCount;
|
||||
std::atomic<uint64_t> m_timestamp;
|
||||
uint64_t m_count;
|
||||
uint64_t m_sequence;
|
||||
xmrig::CpuThread *m_thread;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,10 +22,14 @@
|
|||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "core/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
#include "interfaces/IThread.h"
|
||||
#include "Mem.h"
|
||||
#include "workers/DoubleWorker.h"
|
||||
#include "workers/Handle.h"
|
||||
|
@ -33,6 +37,8 @@
|
|||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
||||
#include "log/Log.h"
|
||||
|
||||
|
||||
bool Workers::m_active = false;
|
||||
bool Workers::m_enabled = true;
|
||||
|
@ -102,10 +108,16 @@ void Workers::setJob(const Job &job, bool donate)
|
|||
}
|
||||
|
||||
|
||||
void Workers::start(int64_t affinity, int priority, xmrig::Controller *controller)
|
||||
void Workers::start(xmrig::Controller *controller)
|
||||
{
|
||||
const int threads = Mem::threads();
|
||||
m_hashrate = new Hashrate(threads, controller);
|
||||
const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
|
||||
|
||||
size_t totalWays = 0;
|
||||
for (const xmrig::IThread *thread : threads) {
|
||||
totalWays += thread->multiway();
|
||||
}
|
||||
|
||||
m_hashrate = new Hashrate(threads.size(), controller);
|
||||
|
||||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
|
@ -117,8 +129,8 @@ void Workers::start(int64_t affinity, int priority, xmrig::Controller *controlle
|
|||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
|
||||
|
||||
for (int i = 0; i < threads; ++i) {
|
||||
Handle *handle = new Handle(i, threads, affinity, priority);
|
||||
for (xmrig::IThread *thread : threads) {
|
||||
Handle *handle = new Handle(thread, threads.size(), totalWays, controller->config()->affinity());
|
||||
m_workers.push_back(handle);
|
||||
handle->start(Workers::onReady);
|
||||
}
|
||||
|
@ -160,7 +172,13 @@ void Workers::onReady(void *arg)
|
|||
handle->setWorker(new SingleWorker(handle));
|
||||
}
|
||||
|
||||
handle->worker()->start();
|
||||
const bool rc = handle->worker()->start();
|
||||
|
||||
if (!rc) {
|
||||
uv_mutex_lock(&m_mutex);
|
||||
LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id());
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
static void printHashrate(bool detail);
|
||||
static void setEnabled(bool enabled);
|
||||
static void setJob(const Job &job, bool donate);
|
||||
static void start(int64_t affinity, int priority, xmrig::Controller *controller);
|
||||
static void start(xmrig::Controller *controller);
|
||||
static void stop();
|
||||
static void submit(const JobResult &result);
|
||||
|
||||
|
|
35
src/xmrig.h
35
src/xmrig.h
|
@ -30,19 +30,40 @@ namespace xmrig
|
|||
|
||||
|
||||
enum Algo {
|
||||
ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
|
||||
ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
||||
ALGO_CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */
|
||||
CRYPTONIGHT, /* CryptoNight (Monero) */
|
||||
CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
|
||||
CRYPTONIGHT_HEAVY, /* CryptoNight-Heavy (SUMO) */
|
||||
};
|
||||
|
||||
|
||||
//--av=1 For CPUs with hardware AES.
|
||||
//--av=2 Lower power mode (double hash) of 1.
|
||||
//--av=3 Software AES implementation.
|
||||
//--av=4 Lower power mode (double hash) of 3.
|
||||
enum AlgoVariant {
|
||||
AV_AUTO, // --av=0 Automatic mode.
|
||||
AV_SINGLE, // --av=1 Single hash mode
|
||||
AV_DOUBLE, // --av=2 Double hash mode
|
||||
AV_SINGLE_SOFT, // --av=3 Single hash mode (Software AES)
|
||||
AV_DOUBLE_SOFT, // --av=4 Double hash mode (Software AES)
|
||||
AV_TRIPLE, // --av=5 Triple hash mode
|
||||
AV_QUAD, // --av=6 Quard hash mode
|
||||
AV_PENTA, // --av=7 Penta hash mode
|
||||
AV_TRIPLE_SOFT, // --av=8 Triple hash mode (Software AES)
|
||||
AV_QUAD_SOFT, // --av=9 Quard hash mode (Software AES)
|
||||
AV_PENTA_SOFT, // --av=10 Penta hash mode (Software AES)
|
||||
AV_MAX
|
||||
};
|
||||
|
||||
|
||||
enum Variant {
|
||||
VARIANT_AUTO = -1,
|
||||
VARIANT_NONE = 0,
|
||||
VARIANT_V1 = 1
|
||||
VARIANT_AUTO = -1, // Autodetect
|
||||
VARIANT_NONE = 0, // Original CryptoNight
|
||||
VARIANT_V1 = 1 // Monero v7 PoW
|
||||
};
|
||||
|
||||
} /* xmrig */
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* __XMRIG_H__ */
|
||||
|
|
Loading…
Reference in a new issue