New style function selector.

This commit is contained in:
XMRig 2018-04-03 02:55:28 +07:00
parent 72cd6d168e
commit 903b243308
12 changed files with 287 additions and 31 deletions

View file

@ -29,6 +29,13 @@
#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),
@ -47,6 +54,86 @@ 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);

View file

@ -29,6 +29,9 @@
#include "xmrig.h"
struct cryptonight_ctx;
namespace xmrig {
@ -46,17 +49,21 @@ public:
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 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; }
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;

View file

@ -26,7 +26,7 @@
#include <thread>
#include "crypto/CryptoNight.h"
#include "workers/CpuThread.h"
#include "workers/SingleWorker.h"
#include "workers/Workers.h"
@ -61,7 +61,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);
}

View file

@ -27,6 +27,7 @@
#include "Cpu.h"
#include "Mem.h"
#include "Platform.h"
#include "workers/CpuThread.h"
#include "workers/Handle.h"
#include "workers/Worker.h"
@ -37,7 +38,8 @@ Worker::Worker(Handle *handle) :
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());

View file

@ -36,6 +36,11 @@ struct cryptonight_ctx;
class Handle;
namespace xmrig {
class CpuThread;
}
class Worker : public IWorker
{
public:
@ -55,6 +60,7 @@ protected:
std::atomic<uint64_t> m_timestamp;
uint64_t m_count;
uint64_t m_sequence;
xmrig::CpuThread *m_thread;
};