mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 12:09:22 +00:00
New style function selector.
This commit is contained in:
parent
72cd6d168e
commit
903b243308
12 changed files with 287 additions and 31 deletions
|
@ -3,6 +3,7 @@ project(xmrig)
|
||||||
|
|
||||||
option(WITH_LIBCPUID "Use Libcpuid" ON)
|
option(WITH_LIBCPUID "Use Libcpuid" ON)
|
||||||
option(WITH_AEON "CryptoNight-Lite support" ON)
|
option(WITH_AEON "CryptoNight-Lite support" ON)
|
||||||
|
option(WITH_SUMO "CryptoNight-Heavy support" ON)
|
||||||
option(WITH_HTTPD "HTTP REST API" ON)
|
option(WITH_HTTPD "HTTP REST API" ON)
|
||||||
option(BUILD_STATIC "Build static binary" OFF)
|
option(BUILD_STATIC "Build static binary" OFF)
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ set(HEADERS_CRYPTO
|
||||||
src/crypto/c_keccak.h
|
src/crypto/c_keccak.h
|
||||||
src/crypto/c_skein.h
|
src/crypto/c_skein.h
|
||||||
src/crypto/CryptoNight.h
|
src/crypto/CryptoNight.h
|
||||||
|
src/crypto/CryptoNight_constants.h
|
||||||
src/crypto/CryptoNight_monero.h
|
src/crypto/CryptoNight_monero.h
|
||||||
src/crypto/CryptoNight_test.h
|
src/crypto/CryptoNight_test.h
|
||||||
src/crypto/groestl_tables.h
|
src/crypto/groestl_tables.h
|
||||||
|
@ -203,6 +205,10 @@ if (NOT WITH_AEON)
|
||||||
add_definitions(/DXMRIG_NO_AEON)
|
add_definitions(/DXMRIG_NO_AEON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (NOT WITH_SUMO)
|
||||||
|
add_definitions(/DXMRIG_NO_SUMO)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (WITH_HTTPD)
|
if (WITH_HTTPD)
|
||||||
find_package(MHD)
|
find_package(MHD)
|
||||||
|
|
||||||
|
|
|
@ -41,13 +41,13 @@
|
||||||
void (*cryptonight_hash_ctx)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = nullptr;
|
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) \
|
#define CRYPTONIGHT_HASH(NAME, ALGO, SOFT_AES) \
|
||||||
switch (variant) { \
|
switch (variant) { \
|
||||||
case xmrig::VARIANT_V1: \
|
case xmrig::VARIANT_V1: \
|
||||||
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_V1>(input, size, output, ctx); \
|
return cryptonight_##NAME##_hash<ALGO, SOFT_AES, xmrig::VARIANT_V1>(input, size, output, ctx); \
|
||||||
\
|
\
|
||||||
case xmrig::VARIANT_NONE: \
|
case xmrig::VARIANT_NONE: \
|
||||||
return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_NONE>(input, size, output, ctx); \
|
return cryptonight_##NAME##_hash<ALGO, SOFT_AES, xmrig::VARIANT_NONE>(input, size, output, ctx); \
|
||||||
\
|
\
|
||||||
default: \
|
default: \
|
||||||
break; \
|
break; \
|
||||||
|
@ -56,50 +56,50 @@ void (*cryptonight_hash_ctx)(const uint8_t *input, size_t size, uint8_t *output,
|
||||||
|
|
||||||
static void cryptonight_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, struct cryptonight_ctx *ctx, int variant) {
|
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)
|
# if !defined(XMRIG_ARMv7)
|
||||||
CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
|
CRYPTONIGHT_HASH(single, xmrig::CRYPTONIGHT, false)
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
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)
|
# if !defined(XMRIG_ARMv7)
|
||||||
CRYPTONIGHT_HASH(double, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
|
CRYPTONIGHT_HASH(double, xmrig::CRYPTONIGHT, false)
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
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)
|
CRYPTONIGHT_HASH(single, xmrig::CRYPTONIGHT, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
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)
|
CRYPTONIGHT_HASH(double, xmrig::CRYPTONIGHT, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef XMRIG_NO_AEON
|
#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) {
|
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)
|
# if !defined(XMRIG_ARMv7)
|
||||||
CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
|
CRYPTONIGHT_HASH(single, xmrig::CRYPTONIGHT_LITE, false)
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_lite_av2_aesni_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
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)
|
# if !defined(XMRIG_ARMv7)
|
||||||
CRYPTONIGHT_HASH(double, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
|
CRYPTONIGHT_HASH(double, xmrig::CRYPTONIGHT_LITE, false)
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_lite_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
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)
|
CRYPTONIGHT_HASH(single, xmrig::CRYPTONIGHT_LITE, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void cryptonight_lite_av4_softaes_double(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
|
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)
|
CRYPTONIGHT_HASH(double, xmrig::CRYPTONIGHT_LITE, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
|
void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
|
||||||
|
|
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__ */
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "crypto/CryptoNight.h"
|
#include "crypto/CryptoNight.h"
|
||||||
|
#include "crypto/CryptoNight_constants.h"
|
||||||
#include "crypto/CryptoNight_monero.h"
|
#include "crypto/CryptoNight_monero.h"
|
||||||
#include "crypto/soft_aes.h"
|
#include "crypto/soft_aes.h"
|
||||||
|
|
||||||
|
@ -309,9 +310,13 @@ 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)
|
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>();
|
||||||
|
|
||||||
keccak(input, (int) size, ctx->state0, 200);
|
keccak(input, (int) size, ctx->state0, 200);
|
||||||
|
|
||||||
VARIANT1_INIT(0);
|
VARIANT1_INIT(0);
|
||||||
|
@ -367,9 +372,13 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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)
|
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>();
|
||||||
|
|
||||||
keccak(input, (int) size, ctx->state0, 200);
|
keccak(input, (int) size, ctx->state0, 200);
|
||||||
keccak(input + size, (int) size, ctx->state1, 200);
|
keccak(input + size, (int) size, ctx->state1, 200);
|
||||||
|
|
||||||
|
@ -464,4 +473,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);
|
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__ */
|
#endif /* __CRYPTONIGHT_X86_H__ */
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,11 +63,11 @@ Job::Job() :
|
||||||
m_algo(xmrig::CRYPTONIGHT),
|
m_algo(xmrig::CRYPTONIGHT),
|
||||||
m_poolId(-2),
|
m_poolId(-2),
|
||||||
m_threadId(-1),
|
m_threadId(-1),
|
||||||
m_variant(xmrig::VARIANT_AUTO),
|
|
||||||
m_size(0),
|
m_size(0),
|
||||||
m_diff(0),
|
m_diff(0),
|
||||||
m_target(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_algo(algo),
|
||||||
m_poolId(poolId),
|
m_poolId(poolId),
|
||||||
m_threadId(-1),
|
m_threadId(-1),
|
||||||
m_variant(variant),
|
|
||||||
m_size(0),
|
m_size(0),
|
||||||
m_diff(0),
|
m_diff(0),
|
||||||
m_target(0),
|
m_target(0),
|
||||||
m_blob()
|
m_blob()
|
||||||
{
|
{
|
||||||
|
setVariant(variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,10 +175,12 @@ void Job::setVariant(int variant)
|
||||||
case xmrig::VARIANT_AUTO:
|
case xmrig::VARIANT_AUTO:
|
||||||
case xmrig::VARIANT_NONE:
|
case xmrig::VARIANT_NONE:
|
||||||
case xmrig::VARIANT_V1:
|
case xmrig::VARIANT_V1:
|
||||||
m_variant = variant;
|
m_variant = static_cast<xmrig::Variant>(variant);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
assert(false);
|
||||||
|
m_variant = xmrig::VARIANT_AUTO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,6 @@ public:
|
||||||
inline const xmrig::Id &id() const { return m_id; }
|
inline const xmrig::Id &id() const { return m_id; }
|
||||||
inline int poolId() const { return m_poolId; }
|
inline int poolId() const { return m_poolId; }
|
||||||
inline int threadId() const { return m_threadId; }
|
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 size_t size() const { return m_size; }
|
||||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||||
inline uint32_t diff() const { return (uint32_t) m_diff; }
|
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 setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||||
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
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 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); }
|
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_algo;
|
||||||
int m_poolId;
|
int m_poolId;
|
||||||
int m_threadId;
|
int m_threadId;
|
||||||
int m_variant;
|
|
||||||
size_t m_size;
|
size_t m_size;
|
||||||
uint64_t m_diff;
|
uint64_t m_diff;
|
||||||
uint64_t m_target;
|
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.
|
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::Id m_id;
|
||||||
|
xmrig::Variant m_variant;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __JOB_H__ */
|
#endif /* __JOB_H__ */
|
||||||
|
|
|
@ -29,6 +29,13 @@
|
||||||
#include "workers/CpuThread.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) :
|
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_algorithm(algorithm),
|
||||||
m_av(av),
|
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)
|
xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority)
|
||||||
{
|
{
|
||||||
assert(av > AV_AUTO && av < AV_MAX);
|
assert(av > AV_AUTO && av < AV_MAX);
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#include "xmrig.h"
|
#include "xmrig.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct cryptonight_ctx;
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
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(size_t index, Algo algorithm, AlgoVariant av, Multiway multiway, int64_t affinity, int priority, bool softAES, bool prefetch);
|
||||||
~CpuThread();
|
~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);
|
static CpuThread *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority);
|
||||||
|
|
||||||
inline bool isPrefetch() const { return m_prefetch; }
|
inline bool isPrefetch() const { return m_prefetch; }
|
||||||
inline bool isSoftAES() const { return m_softAES; }
|
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 Algo algorithm() const override { return m_algorithm; }
|
||||||
inline int multiway() const override { return m_multiway; }
|
inline int multiway() const override { return m_multiway; }
|
||||||
inline int priority() const override { return m_priority; }
|
inline int priority() const override { return m_priority; }
|
||||||
inline int64_t affinity() const override { return m_affinity; }
|
inline int64_t affinity() const override { return m_affinity; }
|
||||||
inline size_t index() const override { return m_index; }
|
inline size_t index() const override { return m_index; }
|
||||||
inline Type type() const override { return CPU; }
|
inline Type type() const override { return CPU; }
|
||||||
|
|
||||||
# ifndef XMRIG_NO_API
|
# ifndef XMRIG_NO_API
|
||||||
rapidjson::Value toAPI(rapidjson::Document &doc) const override;
|
rapidjson::Value toAPI(rapidjson::Document &doc) const override;
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
#include "crypto/CryptoNight.h"
|
#include "workers/CpuThread.h"
|
||||||
#include "workers/SingleWorker.h"
|
#include "workers/SingleWorker.h"
|
||||||
#include "workers/Workers.h"
|
#include "workers/Workers.h"
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ void SingleWorker::start()
|
||||||
m_count++;
|
m_count++;
|
||||||
*m_job.nonce() = ++m_result.nonce;
|
*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);
|
Workers::submit(m_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "Cpu.h"
|
#include "Cpu.h"
|
||||||
#include "Mem.h"
|
#include "Mem.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
#include "workers/CpuThread.h"
|
||||||
#include "workers/Handle.h"
|
#include "workers/Handle.h"
|
||||||
#include "workers/Worker.h"
|
#include "workers/Worker.h"
|
||||||
|
|
||||||
|
@ -37,7 +38,8 @@ Worker::Worker(Handle *handle) :
|
||||||
m_hashCount(0),
|
m_hashCount(0),
|
||||||
m_timestamp(0),
|
m_timestamp(0),
|
||||||
m_count(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) {
|
// if (Cpu::threads() > 1 && handle->affinity() != -1L) {
|
||||||
// Cpu::setAffinity(m_id, handle->affinity());
|
// Cpu::setAffinity(m_id, handle->affinity());
|
||||||
|
|
|
@ -36,6 +36,11 @@ struct cryptonight_ctx;
|
||||||
class Handle;
|
class Handle;
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
class CpuThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Worker : public IWorker
|
class Worker : public IWorker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -55,6 +60,7 @@ protected:
|
||||||
std::atomic<uint64_t> m_timestamp;
|
std::atomic<uint64_t> m_timestamp;
|
||||||
uint64_t m_count;
|
uint64_t m_count;
|
||||||
uint64_t m_sequence;
|
uint64_t m_sequence;
|
||||||
|
xmrig::CpuThread *m_thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ enum Variant {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} /* xmrig */
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
#endif /* __XMRIG_H__ */
|
#endif /* __XMRIG_H__ */
|
||||||
|
|
Loading…
Reference in a new issue