diff --git a/.gitignore b/.gitignore
index 8356f53..60a43db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,12 @@ obj/
xmr-stak-cpu.layout
xmr-stak-cpu.depend
config-debug.txt
+
+# netbeans project files
+/nbproject/
+
+# tmp files
+*~
+
+# merge original backup files
+*.orig
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 85249c4..e87d69d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,38 +1,133 @@
project(xmr-stak-cpu)
-cmake_minimum_required(VERSION 2.8.10)
+cmake_minimum_required(VERSION 3.0.1)
+# enforce C++11
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+set(CMAKE_CXX_STANDARD 11)
+
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+ set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "install prefix" FORCE)
+endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+
+# allow user to extent CMAKE_PREFIX_PATH via environment variable
+list(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
+
+################################################################################
+# CMake user options
+################################################################################
+
+# gcc 5.1 is the first GNU version without CoW strings
+# https://github.com/fireice-uk/xmr-stak-nvidia/pull/10#issuecomment-290821792
+# If you remove this guard to compile with older gcc versions the miner will produce
+# a high rate of wrong shares.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
message(FATAL_ERROR "GCC version must be at least 5.1!")
endif()
endif()
+set(BUILD_TYPE "Release;Debug")
+if(NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
+endif()
+set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}")
+
+# option to add static libgcc and libstdc++
+option(CMAKE_LINK_STATIC "link as much as possible libraries static" OFF)
+
+################################################################################
+# Find PThreads
+################################################################################
+
+find_package(Threads REQUIRED)
+set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
+
+################################################################################
+# Find microhttpd
+################################################################################
+
+option(MICROHTTPD_REQUIRED "Enable or disable the requirement of microhttp (http deamon)" ON)
find_library(MHTD NAMES microhttpd)
if("${MHTD}" STREQUAL "MHTD-NOTFOUND")
- message(FATAL_ERROR "libmicrohttpd is required")
+ if(MICROHTTPD_REQUIRED)
+ message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_REQUIRED=OFF` to build without http deamon support")
+ else()
+ message(STATUS "microhttpd NOT found: disable http server")
+ add_definitions("-DCONF_NO_HTTPD")
+ endif()
+else()
+ set(LIBS ${LIBS} ${MHTD})
endif()
-find_package(OpenSSL REQUIRED)
-include_directories(${OPENSSL_INCLUDE_DIR})
+###############################################################################
+# Find OpenSSL
+###############################################################################
-#set(CMAKE_VERBOSE_MAKEFILE ON)
-set(CMAKE_CONFIGURATION_TYPES "RELEASE;STATIC")
-if("${CMAKE_BUILD_TYPE}" STREQUAL "")
- set(CMAKE_BUILD_TYPE RELEASE)
+option(OpenSSL_REQUIRED "Enable or disable the requirement of OpenSSL" ON)
+find_package(OpenSSL)
+if(OPENSSL_FOUND)
+ include_directories(${OPENSSL_INCLUDE_DIR})
+ set(LIBS ${LIBS} ${OPENSSL_LIBRARIES})
+else()
+ if(OpenSSL_REQUIRED)
+ message(FATAL_ERROR "OpenSSL NOT found: use `-DOpenSSL_REQUIRED=OFF` to build without SSL support")
+ else()
+ if(NOT OPENSSL_FOUND)
+ add_definitions("-DCONF_NO_TLS")
+ endif()
+ endif()
endif()
-set(CMAKE_C_FLAGS "-DNDEBUG -march=westmere -O3 -m64 -s")
-set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11")
+################################################################################
+# Compile & Link
+################################################################################
-set(CMAKE_EXE_LINKER_FLAGS_RELSEASE "")
-set(CMAKE_EXE_LINKER_FLAGS_STATIC "-static-libgcc -static-libstdc++")
+# activate sse2 and aes-ni
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes")
+
+# activate static libgcc and libstdc++ linking
+if(CMAKE_LINK_STATIC)
+ set(BUILD_SHARED_LIBRARIES OFF)
+ set(DL_LIB ${CMAKE_DL_LIBS})
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+ set(LIBS "-static-libgcc -static-libstdc++ ${LIBS}")
+endif()
+
+file(GLOB SRCFILES_CPP "*.cpp" "crypto/*.cpp")
+file(GLOB SRCFILES_C "crypto/*.c")
+
+add_library(xmr-stak-c
+ STATIC
+ ${SRCFILES_C}
+)
+set_property(TARGET xmr-stak-c PROPERTY C_STANDARD 99)
+
+add_executable(xmr-stak-cpu
+ ${SRCFILES_CPP}
+)
set(EXECUTABLE_OUTPUT_PATH "bin")
+target_link_libraries(xmr-stak-cpu ${LIBS} xmr-stak-c)
-file(GLOB SOURCES "crypto/*.c" "crypto/*.cpp" "*.cpp")
+################################################################################
+# Install
+################################################################################
-add_executable(xmr-stak-cpu ${SOURCES})
-target_link_libraries(xmr-stak-cpu pthread microhttpd crypto ssl)
-
+# do not install the binary if the project and install are equal
+if( NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "${PROJECT_BINARY_DIR}" )
+ install(TARGETS xmr-stak-amd
+ RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+endif()
+
+# avoid overwrite of user defined settings
+# install `config.txt`if file not exists in `${CMAKE_INSTALL_PREFIX}/bin`
+install(CODE " \
+ if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/bin/config.txt)\n \
+ file(INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/config.txt \
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)\n \
+ endif()"
+)
diff --git a/README.md b/README.md
index 43de2e6..c0938e2 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,11 @@
-### XMR-Stak-CPU - Monero mining software
+# XMR-Stak-CPU - Monero mining software
XMR-Stak is a universal Stratum pool miner. This is the CPU-mining version; there is also an [AMD GPU version](https://github.com/fireice-uk/xmr-stak-amd) and an [NVIDA GPU version](https://github.com/fireice-uk/xmr-stak-nvidia)
-#### HTML reports
+## HTML reports
-#### Usage on Windows
+## Usage on Windows
1) Edit the config.txt file to enter your pool login and password.
2) Double click the exe file.
@@ -42,22 +42,27 @@ lBoYbHZRpcWUfDO8o2y+ZQIs+yzMoJHHBBXB9fsHlwq62PTtzjsEVwB2aq9ABzk=
```
-#### Usage on Linux (Debian-based distros)
+## Compile on Linux (Debian-based distros)
+
+### GNU Compiler
```
sudo apt-get install libmicrohttpd-dev libssl-dev cmake build-essential
cmake .
- make
+ make install
```
-GCC version 5.1 or higher is required for full C++11 support. CMake release compile scripts, as well as CodeBlocks build environment for debug builds is included.
+- GCC version 5.1 or higher is required for full C++11 support. CMake release compile scripts, as well as CodeBlocks build environment for debug builds is included.
-To do a static build for a system without gcc 5.1+
+### To do a static build for a system without gcc 5.1+
```
- cmake -DCMAKE_BUILD_TYPE=STATIC
- make
+ cmake -DCMAKE_LINK_STATIC=ON .
+ make install
```
Note - cmake caches variables, so if you want to do a dynamic build later you need to specify '-DCMAKE_BUILD_TYPE=RELEASE'
+
+You can find a complete compile guide under [Advanced Compile Options](#advanced-compile-options).
+
#### CPU mining performance
Performance is nearly identical to the closed source paid miners. Here are some numbers:
@@ -67,16 +72,22 @@ Performance is nearly identical to the closed source paid miners. Here are some
* **Dual X5650** - 466 H/s (depends on NUMA)
* **Dual E5640** - 365 H/s (same as above)
-#### Default dev donation
+## Default dev donation
By default the miner will donate 1% of the hashpower (1 minute in 100 minutes) to my pool. If you want to change that, edit **donate-level.h** before you build the binaries.
If you want to donate directly to support further development, here is my wallet
+fireice-uk:
```
4581HhZkQHgZrZjKeCfCJxZff9E3xCgHGF25zABZz7oR71TnbbgiS7sK9jveE6Dx6uMs2LwszDuvQJgRZQotdpHt1fTdDhk
```
-#### PGP Key
+psychocrypt:
+```
+43NoJVEXo21hGZ6tDG6Z3g4qimiGdJPE6GRxAmiWwm26gwr62Lqo7zRiCJFSBmbkwTGNuuES9ES5TgaVHceuYc4Y75txCTU
+```
+
+## PGP Key
```
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
@@ -110,7 +121,7 @@ c4hC0Yg9Dha1OoE5CJCqVL+ic4vAyB1urAwBlsd/wH8=
-----END PGP PUBLIC KEY BLOCK-----
```
-### Common Issues
+## Common Issues
**SeLockMemoryPrivilege failed**
@@ -160,4 +171,40 @@ You can also do it Windows-style and simply run-as-root, but this is NOT recomme
This typically means you are trying to run it on a CPU that does not have [AES](https://en.wikipedia.org/wiki/AES_instruction_set). This only happens on older version of miner, new version gives better error message (but still wont' work since your CPU doesn't support the required instructions).
+## Advanced Compile Options
+The build system is CMake, if you are not familiar with CMake you can learn more [here](https://cmake.org/runningcmake/).
+
+### Short Description
+
+There are two easy ways to set variables for `cmake` to configure *xmr-stak-cpu*
+- use the ncurses GUI
+ - `ccmake .`
+ - edit your options
+ - end the GUI by pressing the key `c`(create) and than `g`(generate)
+- set Options on the command line
+ - enable a option: `cmake . -DNAME_OF_THE_OPTION=ON`
+ - disable a option `cmake . -DNAME_OF_THE_OPTION=OFF`
+ - set a value `cmake . -DNAME_OF_THE_OPTION=value`
+
+After the configuration you need to call
+`make install` for slow sequential build
+or
+`make -j install` for faster parallel build
+and install.
+
+### xmr-stak-cpu Compile Options
+- `CMAKE_INSTALL_PREFIX` install miner to the home folder
+ - `cmake . -DCMAKE_INSTALL_PREFIX=$HOME/xmr-stak-cpu`
+ - you can find the binary and the `config.txt` file after `make install` in `$HOME/xmr-stak-cpu/bin`
+- `CMAKE_LINK_STATIC` link libgcc and libstdc++ libraries static (default OFF)
+ - disable with `cmake . -DCMAKE_LINK_STATIC=ON`
+-`CMAKE_BUILD_TYPE` set the build type
+ - valid options: `Release` or `Debug`
+ - you should always keep `Release` for your productive miners
+- `MICROHTTPD_REQUIRED` allow to disable/enable the dependency *microhttpd*
+ - by default enabled
+ - there is no *http* interface available if option is disabled: `cmake . -DMICROHTTPD_REQUIRED=OFF`
+- `OpenSSL_REQUIRED`allow to disable/enable the dependency *OpenSSL*
+ - by default enabled
+ - it is not possible to connect to a *https* secured pool if optin is disabled: `cmake . -DOpenSSL_REQUIRED=OFF`
diff --git a/autoAdjust.hpp b/autoAdjust.hpp
new file mode 100644
index 0000000..c9ee9e6
--- /dev/null
+++ b/autoAdjust.hpp
@@ -0,0 +1,154 @@
+#pragma once
+#include "jconf.h"
+#include "console.h"
+
+#ifdef _WIN32
+#include
+#else
+#include
+#endif // _WIN32
+
+// Mask bits between h and l and return the value
+// This enables us to put in values exactly like in the manual
+// For example EBX[31:22] is get_masked(cpu_info[1], 31, 22)
+inline int32_t get_masked(int32_t val, int32_t h, int32_t l)
+{
+ val &= (0x7FFFFFFF >> (31-(h-l))) << l;
+ return val >> l;
+}
+
+class autoAdjust
+{
+public:
+
+ autoAdjust()
+ {
+ }
+
+ void printConfig()
+ {
+ printer::inst()->print_str("The configuration for 'cpu_threads_conf' in your config file is 'null'.\n");
+ printer::inst()->print_str("The miner evaluates your system and prints a suggestion for the section `cpu_threads_conf` to the terminal.\n");
+ printer::inst()->print_str("The values are not optimal, please try to tweak the values based on notes in config.txt.\n");
+ printer::inst()->print_str("Please copy & paste the block within the asterisks to your config.\n\n");
+
+ if(!detectL3Size() || L3KB_size < 1024 || L3KB_size > 102400)
+ {
+ if(L3KB_size < 1024 || L3KB_size > 102400)
+ printer::inst()->print_msg(L0, "Autoconf failed: L3 size sanity check failed - %u KB.", L3KB_size);
+
+ printer::inst()->print_msg(L0, "Autoconf failed: Printing config for a single thread. Please try to add new ones until the hashrate slows down.");
+ printer::inst()->print_str("\n**************** Copy&Paste ****************\n\n");
+ printer::inst()->print_str("\"cpu_threads_conf\" :\n[\n");
+ printer::inst()->print_str(" { \"low_power_mode\" : false, \"no_prefetch\" : true, \"affine_to_cpu\" : false },\n");
+ printer::inst()->print_str("],\n\n**************** Copy&Paste ****************\n");
+ return;
+ }
+
+ printer::inst()->print_msg(L0, "Autoconf L3 size detected at %u KB.", L3KB_size);
+
+ detectCPUConf();
+
+ printer::inst()->print_msg(L0, "Autoconf core count detected as %u on %s.", corecnt,
+ linux_layout ? "Linux" : "Windows");
+
+ printer::inst()->print_str("\n**************** Copy&Paste ****************\n\n");
+ printer::inst()->print_str("\"cpu_threads_conf\" :\n[\n");
+
+ uint32_t aff_id = 0;
+ char strbuf[256];
+ for(uint32_t i=0; i < corecnt; i++)
+ {
+ bool double_mode;
+
+ if(L3KB_size <= 0)
+ break;
+
+ double_mode = L3KB_size / 2048 > (int32_t)(corecnt-i);
+
+ snprintf(strbuf, sizeof(strbuf), " { \"low_power_mode\" : %s, \"no_prefetch\" : true, \"affine_to_cpu\" : %u },\n",
+ double_mode ? "true" : "false", aff_id);
+ printer::inst()->print_str(strbuf);
+
+ if(!linux_layout || old_amd)
+ {
+ aff_id += 2;
+
+ if(aff_id >= corecnt)
+ aff_id = 1;
+ }
+ else
+ aff_id++;
+
+ if(double_mode)
+ L3KB_size -= 4096;
+ else
+ L3KB_size -= 2048;
+ }
+
+ printer::inst()->print_str("],\n\n**************** Copy&Paste ****************\n");
+ }
+
+private:
+ bool detectL3Size()
+ {
+ int32_t cpu_info[4];
+ char cpustr[13] = {0};
+
+ jconf::cpuid(0, 0, cpu_info);
+ memcpy(cpustr, &cpu_info[1], 4);
+ memcpy(cpustr+4, &cpu_info[3], 4);
+ memcpy(cpustr+8, &cpu_info[2], 4);
+
+ if(strcmp(cpustr, "GenuineIntel") == 0)
+ {
+ jconf::cpuid(4, 3, cpu_info);
+
+ if(get_masked(cpu_info[0], 7, 5) != 3)
+ {
+ printer::inst()->print_msg(L0, "Autoconf failed: Couln't find L3 cache page.");
+ return false;
+ }
+
+ L3KB_size = ((get_masked(cpu_info[1], 31, 22) + 1) * (get_masked(cpu_info[1], 21, 12) + 1) *
+ (get_masked(cpu_info[1], 11, 0) + 1) * (cpu_info[2] + 1)) / 1024;
+
+ return true;
+ }
+ else if(strcmp(cpustr, "AuthenticAMD") == 0)
+ {
+ jconf::cpuid(0x80000006, 0, cpu_info);
+
+ L3KB_size = get_masked(cpu_info[3], 31, 18) * 512;
+
+ jconf::cpuid(1, 0, cpu_info);
+ if(get_masked(cpu_info[0], 11, 8) < 0x17) //0x17h is Zen
+ old_amd = true;
+
+ return true;
+ }
+ else
+ {
+ printer::inst()->print_msg(L0, "Autoconf failed: Unknown CPU type: %s.", cpustr);
+ return false;
+ }
+ }
+
+ void detectCPUConf()
+ {
+#ifdef _WIN32
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ corecnt = info.dwNumberOfProcessors;
+ linux_layout = false;
+#else
+ corecnt = sysconf(_SC_NPROCESSORS_ONLN);
+ linux_layout = true;
+#endif // _WIN32
+ }
+
+ int32_t L3KB_size = 0;
+ uint32_t corecnt;
+ bool old_amd = false;
+ bool linux_layout;
+};
diff --git a/cli-miner.cpp b/cli-miner.cpp
index 9eec369..38fb720 100644
--- a/cli-miner.cpp
+++ b/cli-miner.cpp
@@ -26,7 +26,11 @@
#include "jconf.h"
#include "console.h"
#include "donate-level.h"
-#include "httpd.h"
+#include "autoAdjust.hpp"
+
+#ifndef CONF_NO_HTTPD
+# include "httpd.h"
+#endif
#include
#include
@@ -96,6 +100,14 @@ int main(int argc, char *argv[])
return 0;
}
+ if(jconf::inst()->NeedsAutoconf())
+ {
+ autoAdjust adjust;
+ adjust.printConfig();
+ win_exit();
+ return 0;
+ }
+
if (!minethd::self_test())
{
win_exit();
@@ -109,6 +121,7 @@ int main(int argc, char *argv[])
return 0;
}
+#ifndef CONF_NO_HTTPD
if(jconf::inst()->GetHttpdPort() != 0)
{
if (!httpd::inst()->start_daemon())
@@ -117,11 +130,12 @@ int main(int argc, char *argv[])
return 0;
}
}
+#endif
printer::inst()->print_str("-------------------------------------------------------------------\n");
printer::inst()->print_str("XMR-Stak-CPU mining software, CPU Version.\n");
- printer::inst()->print_str("Based on CPU mining code by wolf9466 (heavily optimized by myself).\n");
- printer::inst()->print_str("Brought to you by fireice_uk under GPLv3.\n\n");
+ printer::inst()->print_str("Based on CPU mining code by wolf9466 (heavily optimized by fireice_uk).\n");
+ printer::inst()->print_str("Brought to you by fireice_uk and psychocrypt under GPLv3.\n\n");
char buffer[64];
snprintf(buffer, sizeof(buffer), "Configurable dev donation level is set to %.1f %%\n\n", fDevDonationLevel * 100.0);
printer::inst()->print_str(buffer);
diff --git a/config.txt b/config.txt
index 98d1c3e..0dcb9e9 100644
--- a/config.txt
+++ b/config.txt
@@ -1,18 +1,10 @@
-/*
- * Number of threads. You can configure them below. Cryptonight uses 2MB of memory, so the optimal setting
- * here is the size of your L3 cache divided by 2. Intel mid-to-high end desktop processors have 2MB of L3
- * cache per physical core. Low end cpus can have 1.5 or 1 MB while Xeons can have 2, 2.5 or 3MB per core.
- */
-"cpu_thread_num" : 2,
-
/*
* Thread configuration for each thread. Make sure it matches the number above.
* low_power_mode - This mode will double the cache usage, and double the single thread performance. It will
* consume much less power (as less cores are working), but will max out at around 80-85% of
* the maximum performance.
*
- * no_prefetch - This mode meant for large pages only. It will generate an error if running on slow memory
- * Some sytems can gain up to extra 5% here, but sometimes it will have no difference or make
+ * no_prefetch - Some sytems can gain up to extra 5% here, but sometimes it will have no difference or make
* things slower.
*
* affine_to_cpu - This can be either false (no affinity), or the CPU core number. Note that on hyperthreading
@@ -20,11 +12,18 @@
* even or odd numbered cpu numbers. For Linux it will be usually the lower CPU numbers, so for a 4
* physical core CPU you should select cpu numbers 0-3.
*
+ * On the first run the miner will look at your system and suggest a basic configuration that will work,
+ * you can try to tweak it from there to get the best performance.
+ *
+ * A filled out configuration should look like this:
+ * "cpu_threads_conf" :
+ * [
+ * { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 0 },
+ * { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 1 },
+ * ],
*/
-"cpu_threads_conf" : [
- { "low_power_mode" : false, "no_prefetch" : false, "affine_to_cpu" : 0 },
- { "low_power_mode" : false, "no_prefetch" : false, "affine_to_cpu" : 1 },
-],
+"cpu_threads_conf" :
+null,
/*
* LARGE PAGE SUPPORT
diff --git a/crypto/cryptonight.h b/crypto/cryptonight.h
index f4ec843..978c798 100644
--- a/crypto/cryptonight.h
+++ b/crypto/cryptonight.h
@@ -24,11 +24,6 @@ size_t cryptonight_init(size_t use_fast_mem, size_t use_mlock, alloc_msg* msg);
cryptonight_ctx* cryptonight_alloc_ctx(size_t use_fast_mem, size_t use_mlock, alloc_msg* msg);
void cryptonight_free_ctx(cryptonight_ctx* ctx);
-void cryptonight_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* ctx);
-void cryptonight_hash_ctx_soft(const void* input, size_t len, void* output, cryptonight_ctx* ctx);
-void cryptonight_hash_ctx_np(const void* input, size_t len, void* output, cryptonight_ctx* ctx);
-void cryptonight_double_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* __restrict ctx0, cryptonight_ctx* __restrict ctx1);
-
#ifdef __cplusplus
}
#endif
diff --git a/crypto/cryptonight_aesni.h b/crypto/cryptonight_aesni.h
index 37672c6..6d8479c 100644
--- a/crypto/cryptonight_aesni.h
+++ b/crypto/cryptonight_aesni.h
@@ -27,7 +27,6 @@ static inline uint64_t _umul128(uint64_t a, uint64_t b, uint64_t* hi)
*hi = r >> 64;
return (uint64_t)r;
}
-
#define _mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1)
#else
#include
@@ -150,7 +149,7 @@ static inline void soft_aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i
*x7 = soft_aesenc(*x7, key);
}
-template
+template
void cn_explode_scratchpad(const __m128i* input, __m128i* output)
{
// This is more than we have registers, compiler will assign 2 keys on the stack
@@ -201,16 +200,21 @@ void cn_explode_scratchpad(const __m128i* input, __m128i* output)
_mm_store_si128(output + i + 1, xin1);
_mm_store_si128(output + i + 2, xin2);
_mm_store_si128(output + i + 3, xin3);
- _mm_prefetch((const char*)output + i + 0, _MM_HINT_T2);
+
+ if(PREFETCH)
+ _mm_prefetch((const char*)output + i + 0, _MM_HINT_T2);
+
_mm_store_si128(output + i + 4, xin4);
_mm_store_si128(output + i + 5, xin5);
_mm_store_si128(output + i + 6, xin6);
_mm_store_si128(output + i + 7, xin7);
- _mm_prefetch((const char*)output + i + 4, _MM_HINT_T2);
+
+ if(PREFETCH)
+ _mm_prefetch((const char*)output + i + 4, _MM_HINT_T2);
}
}
-template
+template
void cn_implode_scratchpad(const __m128i* input, __m128i* output)
{
// This is more than we have registers, compiler will assign 2 keys on the stack
@@ -230,12 +234,17 @@ void cn_implode_scratchpad(const __m128i* input, __m128i* output)
for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8)
{
- _mm_prefetch((const char*)input + i + 0, _MM_HINT_NTA);
+ if(PREFETCH)
+ _mm_prefetch((const char*)input + i + 0, _MM_HINT_NTA);
+
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);
- _mm_prefetch((const char*)input + i + 4, _MM_HINT_NTA);
+
+ if(PREFETCH)
+ _mm_prefetch((const char*)input + i + 4, _MM_HINT_NTA);
+
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);
@@ -279,13 +288,13 @@ void cn_implode_scratchpad(const __m128i* input, __m128i* output)
_mm_store_si128(output + 11, xout7);
}
-template
+template
void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_ctx* ctx0)
{
keccak((const uint8_t *)input, len, ctx0->hash_state, 200);
// Optim - 99% time boundary
- cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state);
+ cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state);
uint8_t* l0 = ctx0->long_state;
uint64_t* h0 = (uint64_t*)ctx0->hash_state;
@@ -301,20 +310,25 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c
{
__m128i cx;
cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]);
+
if(SOFT_AES)
cx = soft_aesenc(cx, _mm_set_epi64x(ah0, al0));
else
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0));
+
_mm_store_si128((__m128i *)&l0[idx0 & 0x1FFFF0], _mm_xor_si128(bx0, cx));
idx0 = _mm_cvtsi128_si64(cx);
bx0 = cx;
+
if(PREFETCH)
_mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0);
uint64_t hi, lo, cl, ch;
cl = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[0];
ch = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[1];
+
lo = _umul128(idx0, cl, &hi);
+
al0 += hi;
ah0 += lo;
((uint64_t*)&l0[idx0 & 0x1FFFF0])[0] = al0;
@@ -322,12 +336,13 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c
ah0 ^= ch;
al0 ^= cl;
idx0 = al0;
+
if(PREFETCH)
_mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0);
}
// Optim - 90% time boundary
- cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state);
+ cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state);
// Optim - 99% time boundary
@@ -338,15 +353,15 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c
// This lovely creation will do 2 cn hashes at a time. We have plenty of space on silicon
// to fit temporary vars for two contexts. Function will read len*2 from input and write 64 bytes to output
// We are still limited by L3 cache, so doubling will only work with CPUs where we have more than 2MB to core (Xeons)
-template
+template
void cryptonight_double_hash(const void* input, size_t len, void* output, cryptonight_ctx* __restrict ctx0, cryptonight_ctx* __restrict ctx1)
{
keccak((const uint8_t *)input, len, ctx0->hash_state, 200);
keccak((const uint8_t *)input+len, len, ctx1->hash_state, 200);
// Optim - 99% time boundary
- cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state);
- cn_explode_scratchpad((__m128i*)ctx1->hash_state, (__m128i*)ctx1->long_state);
+ cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state);
+ cn_explode_scratchpad((__m128i*)ctx1->hash_state, (__m128i*)ctx1->long_state);
uint8_t* l0 = ctx0->long_state;
uint64_t* h0 = (uint64_t*)ctx0->hash_state;
@@ -366,50 +381,62 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto
{
__m128i cx;
cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]);
+
if(SOFT_AES)
cx = soft_aesenc(cx, ax0);
else
cx = _mm_aesenc_si128(cx, ax0);
+
_mm_store_si128((__m128i *)&l0[idx0 & 0x1FFFF0], _mm_xor_si128(bx0, cx));
idx0 = _mm_cvtsi128_si64(cx);
bx0 = cx;
+
if(PREFETCH)
_mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0);
cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]);
+
if(SOFT_AES)
cx = soft_aesenc(cx, ax1);
else
cx = _mm_aesenc_si128(cx, ax1);
+
_mm_store_si128((__m128i *)&l1[idx1 & 0x1FFFF0], _mm_xor_si128(bx1, cx));
idx1 = _mm_cvtsi128_si64(cx);
bx1 = cx;
+
if(PREFETCH)
_mm_prefetch((const char*)&l1[idx1 & 0x1FFFF0], _MM_HINT_T0);
uint64_t hi, lo;
cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]);
+
lo = _umul128(idx0, _mm_cvtsi128_si64(cx), &hi);
+
ax0 = _mm_add_epi64(ax0, _mm_set_epi64x(lo, hi));
_mm_store_si128((__m128i*)&l0[idx0 & 0x1FFFF0], ax0);
ax0 = _mm_xor_si128(ax0, cx);
idx0 = _mm_cvtsi128_si64(ax0);
+
if(PREFETCH)
_mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0);
cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]);
+
lo = _umul128(idx1, _mm_cvtsi128_si64(cx), &hi);
+
ax1 = _mm_add_epi64(ax1, _mm_set_epi64x(lo, hi));
_mm_store_si128((__m128i*)&l1[idx1 & 0x1FFFF0], ax1);
ax1 = _mm_xor_si128(ax1, cx);
idx1 = _mm_cvtsi128_si64(ax1);
+
if(PREFETCH)
_mm_prefetch((const char*)&l1[idx1 & 0x1FFFF0], _MM_HINT_T0);
}
// Optim - 90% time boundary
- cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state);
- cn_implode_scratchpad((__m128i*)ctx1->long_state, (__m128i*)ctx1->hash_state);
+ cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state);
+ cn_implode_scratchpad((__m128i*)ctx1->long_state, (__m128i*)ctx1->hash_state);
// Optim - 99% time boundary
diff --git a/crypto/cryptonight_common.cpp b/crypto/cryptonight_common.cpp
index 6955dc1..63ce3a4 100644
--- a/crypto/cryptonight_common.cpp
+++ b/crypto/cryptonight_common.cpp
@@ -114,7 +114,8 @@ cryptonight_ctx* cryptonight_alloc_ctx(size_t use_fast_mem, size_t use_mlock, al
if(use_fast_mem == 0)
{
- ptr->long_state = (uint8_t*)_mm_malloc(MEMORY, 4096);
+ // use 2MiB aligned memory
+ ptr->long_state = (uint8_t*)_mm_malloc(MEMORY, 2*1024*1024);
ptr->ctx_info[0] = 0;
ptr->ctx_info[1] = 0;
return ptr;
@@ -189,23 +190,3 @@ void cryptonight_free_ctx(cryptonight_ctx* ctx)
_mm_free(ctx);
}
-
-void cryptonight_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* ctx)
-{
- cryptonight_hash<0x80000, MEMORY, true, false>(input, len, output, ctx);
-}
-
-void cryptonight_hash_ctx_soft(const void* input, size_t len, void* output, cryptonight_ctx* ctx)
-{
- cryptonight_hash<0x80000, MEMORY, true, true>(input, len, output, ctx);
-}
-
-void cryptonight_hash_ctx_np(const void* input, size_t len, void* output, cryptonight_ctx* ctx)
-{
- cryptonight_hash<0x80000, MEMORY, false, false>(input, len, output, ctx);
-}
-
-void cryptonight_double_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* __restrict ctx0, cryptonight_ctx* __restrict ctx1)
-{
- cryptonight_double_hash<0x80000, MEMORY, false, false>(input, len, output, ctx0, ctx1);
-}
diff --git a/httpd.cpp b/httpd.cpp
index 7e82aa3..7c94f76 100644
--- a/httpd.cpp
+++ b/httpd.cpp
@@ -21,6 +21,8 @@
*
*/
+#ifndef CONF_NO_HTTPD
+
#include
#include
#include
@@ -142,3 +144,5 @@ bool httpd::start_daemon()
return true;
}
+#endif
+
diff --git a/jconf.cpp b/jconf.cpp
index d0dd815..8ed1947 100644
--- a/jconf.cpp
+++ b/jconf.cpp
@@ -45,7 +45,7 @@ using namespace rapidjson;
/*
* This enum needs to match index in oConfigValues, otherwise we will get a runtime error
*/
-enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, bNiceHashMode,
+enum configEnum { aCpuThreadsConf, sUseSlowMem, bNiceHashMode,
bTlsMode, bTlsSecureAlgo, sTlsFingerprint, sPoolAddr, sWalletAddr, sPoolPwd,
iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime,
sOutputFile, iHttpdPort, bPreferIpv4 };
@@ -56,10 +56,10 @@ struct configVal {
Type iType;
};
-//Same order as in configEnum, as per comment above
+// Same order as in configEnum, as per comment above
+// kNullType means any type
configVal oConfigValues[] = {
- { iCpuThreadNum, "cpu_thread_num", kNumberType },
- { aCpuThreadsConf, "cpu_threads_conf", kArrayType },
+ { aCpuThreadsConf, "cpu_threads_conf", kNullType },
{ sUseSlowMem, "use_slow_memory", kStringType },
{ bNiceHashMode, "nicehash_nonce", kTrueType },
{ bTlsMode, "use_tls", kTrueType },
@@ -84,6 +84,8 @@ inline bool checkType(Type have, Type want)
{
if(want == have)
return true;
+ else if(want == kNullType)
+ return true;
else if(want == kTrueType && have == kFalseType)
return true;
else if(want == kFalseType && have == kTrueType)
@@ -111,6 +113,9 @@ jconf::jconf()
bool jconf::GetThreadConfig(size_t id, thd_cfg &cfg)
{
+ if(!prv->configValues[aCpuThreadsConf]->IsArray())
+ return false;
+
if(id >= prv->configValues[aCpuThreadsConf]->Size())
return false;
@@ -139,9 +144,9 @@ bool jconf::GetThreadConfig(size_t id, thd_cfg &cfg)
cfg.bDoubleMode = mode->GetBool();
cfg.bNoPrefetch = no_prefetch->GetBool();
- if(!bHaveAes && (cfg.bDoubleMode || cfg.bNoPrefetch))
+ if(!bHaveAes && cfg.bDoubleMode)
{
- printer::inst()->print_msg(L0, "Invalid thread confg - low_power_mode and no_prefetch are unsupported on CPUs without AES-NI.");
+ printer::inst()->print_msg(L0, "Invalid thread confg - low_power_mode are unsupported on CPUs without AES-NI.");
return false;
}
@@ -206,7 +211,15 @@ bool jconf::PreferIpv4()
size_t jconf::GetThreadCount()
{
- return prv->configValues[aCpuThreadsConf]->Size();
+ if(prv->configValues[aCpuThreadsConf]->IsArray())
+ return prv->configValues[aCpuThreadsConf]->Size();
+ else
+ return 0;
+}
+
+bool jconf::NeedsAutoconf()
+{
+ return !prv->configValues[aCpuThreadsConf]->IsArray();
}
uint64_t jconf::GetCallTimeout()
@@ -249,24 +262,30 @@ const char* jconf::GetOutputFile()
return prv->configValues[sOutputFile]->GetString();
}
+void jconf::cpuid(uint32_t eax, int32_t ecx, int32_t val[4])
+{
+ memset(val, 0, sizeof(int32_t)*4);
+
+#ifdef _WIN32
+ __cpuidex(val, eax, ecx);
+#else
+ __cpuid_count(eax, ecx, val[0], val[1], val[2], val[3]);
+#endif
+}
+
bool jconf::check_cpu_features()
{
constexpr int AESNI_BIT = 1 << 25;
constexpr int SSE2_BIT = 1 << 26;
+ int32_t cpu_info[4];
+ bool bHaveSse2;
- int cpu_info[4];
-#ifdef _WIN32
- __cpuid(cpu_info, 1);
-#else
- __cpuid(1, cpu_info[0], cpu_info[1], cpu_info[2], cpu_info[3]);
-#endif
+ cpuid(1, 0, cpu_info);
bHaveAes = (cpu_info[2] & AESNI_BIT) != 0;
+ bHaveSse2 = (cpu_info[3] & SSE2_BIT) != 0;
- if(!bHaveAes)
- printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates.");
-
- return (cpu_info[3] & SSE2_BIT) != 0;
+ return bHaveSse2;
}
bool jconf::parse_config(const char* sFilename)
@@ -369,23 +388,8 @@ bool jconf::parse_config(const char* sFilename)
}
}
- size_t n_thd = prv->configValues[aCpuThreadsConf]->Size();
- if(prv->configValues[iCpuThreadNum]->GetUint64() != n_thd)
- {
- printer::inst()->print_msg(L0,
- "Invalid config file. Your CPU config array has %llu members, while you want to use %llu threads.",
- int_port(n_thd), int_port(prv->configValues[iCpuThreadNum]->GetUint64()));
- return false;
- }
-
- if(NiceHashMode() && n_thd >= 32)
- {
- printer::inst()->print_msg(L0, "You need to use less than 32 threads in NiceHash mode.");
- return false;
- }
-
thd_cfg c;
- for(size_t i=0; i < n_thd; i++)
+ for(size_t i=0; i < GetThreadCount(); i++)
{
if(!GetThreadConfig(i, c))
{
@@ -394,6 +398,12 @@ bool jconf::parse_config(const char* sFilename)
}
}
+ if(NiceHashMode() && GetThreadCount() >= 32)
+ {
+ printer::inst()->print_msg(L0, "You need to use less than 32 threads in NiceHash mode.");
+ return false;
+ }
+
if(GetSlowMemSetting() == unknown_value)
{
printer::inst()->print_msg(L0,
@@ -442,5 +452,12 @@ bool jconf::parse_config(const char* sFilename)
#endif // _WIN32
printer::inst()->set_verbose_level(prv->configValues[iVerboseLevel]->GetUint64());
+
+ if(!NeedsAutoconf())
+ {
+ if(!bHaveAes)
+ printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates.");
+ }
+
return true;
}
diff --git a/jconf.h b/jconf.h
index 6c3954b..f932728 100644
--- a/jconf.h
+++ b/jconf.h
@@ -29,6 +29,7 @@ public:
size_t GetThreadCount();
bool GetThreadConfig(size_t id, thd_cfg &cfg);
+ bool NeedsAutoconf();
slow_mem_cfg GetSlowMemSetting();
@@ -57,6 +58,8 @@ public:
inline bool HaveHardwareAes() { return bHaveAes; }
+ static void cpuid(uint32_t eax, int32_t ecx, int32_t val[4]);
+
private:
jconf();
static jconf* oInst;
diff --git a/minethd.cpp b/minethd.cpp
index 22471f4..199779e 100644
--- a/minethd.cpp
+++ b/minethd.cpp
@@ -25,6 +25,7 @@
#include
#include
#include
+#include
#include "console.h"
#ifdef _WIN32
@@ -62,7 +63,7 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
#include "executor.h"
#include "minethd.h"
#include "jconf.h"
-#include "crypto/cryptonight.h"
+#include "crypto/cryptonight_aesni.h"
telemetry::telemetry(size_t iThd)
{
@@ -244,42 +245,29 @@ bool minethd::self_test()
return false;
}
- bool bHasLp = ctx0->ctx_info[0] == 1 && ctx1->ctx_info[0] == 1;
- size_t n = jconf::inst()->GetThreadCount();
- jconf::thd_cfg cfg;
- for (size_t i = 0; i < n; i++)
- {
- jconf::inst()->GetThreadConfig(i, cfg);
-
- if(!bHasLp && cfg.bNoPrefetch)
- {
- printer::inst()->print_msg(L0, "Wrong config. You are running in slow memory mode with no_prefetch.");
- cryptonight_free_ctx(ctx0);
- cryptonight_free_ctx(ctx1);
- return false;
- }
- }
-
unsigned char out[64];
bool bResult;
- if(jconf::inst()->HaveHardwareAes())
- {
- cryptonight_hash_ctx("This is a test", 14, out, ctx0);
- bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0;
+ cn_hash_fun hashf;
+ cn_hash_fun_dbl hashdf;
- cryptonight_hash_ctx_np("This is a test", 14, out, ctx0);
- bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0;
+ hashf = func_selector(jconf::inst()->HaveHardwareAes(), false);
+ hashf("This is a test", 14, out, ctx0);
+ bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0;
- cryptonight_double_hash_ctx("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1);
- bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59"
- "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0;
- }
- else
- {
- cryptonight_hash_ctx_soft("This is a test", 14, out, ctx0);
- bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0;
- }
+ hashf = func_selector(jconf::inst()->HaveHardwareAes(), true);
+ hashf("This is a test", 14, out, ctx0);
+ bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0;
+
+ hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), false);
+ hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1);
+ bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59"
+ "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0;
+
+ hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), true);
+ hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1);
+ bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59"
+ "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0;
cryptonight_free_ctx(ctx0);
cryptonight_free_ctx(ctx1);
@@ -350,21 +338,43 @@ void minethd::consume_work()
iConsumeCnt++;
}
+minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch)
+{
+ // We have two independent flag bits in the functions
+ // therefore we will build a binary digit and select the
+ // function as a two digit binary
+ // Digit order SOFT_AES, NO_PREFETCH
+
+ static const cn_hash_fun func_table[4] = {
+ cryptonight_hash<0x80000, MEMORY, false, false>,
+ cryptonight_hash<0x80000, MEMORY, false, true>,
+ cryptonight_hash<0x80000, MEMORY, true, false>,
+ cryptonight_hash<0x80000, MEMORY, true, true>
+ };
+
+ std::bitset<2> digit;
+ digit.set(0, !bNoPrefetch);
+ digit.set(1, !bHaveAes);
+
+ return func_table[digit.to_ulong()];
+}
+
void minethd::work_main()
{
+ cn_hash_fun hash_fun;
cryptonight_ctx* ctx;
uint64_t iCount = 0;
uint64_t* piHashVal;
uint32_t* piNonce;
job_result result;
+ hash_fun = func_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch);
ctx = minethd_alloc_ctx();
piHashVal = (uint64_t*)(result.bResult + 24);
piNonce = (uint32_t*)(oWork.bWorkBlob + 39);
iConsumeCnt++;
- bool bHaveAes = jconf::inst()->HaveHardwareAes();
while (bQuit == 0)
{
if (oWork.bStall)
@@ -401,15 +411,7 @@ void minethd::work_main()
*piNonce = ++result.iNonce;
- if(bHaveAes)
- {
- if(bNoPrefetch)
- cryptonight_hash_ctx_np(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx);
- else
- cryptonight_hash_ctx(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx);
- }
- else
- cryptonight_hash_ctx_soft(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx);
+ hash_fun(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx);
if (*piHashVal < oWork.iTarget)
executor::inst()->push_event(ex_event(result, oWork.iPoolId));
@@ -423,8 +425,30 @@ void minethd::work_main()
cryptonight_free_ctx(ctx);
}
+minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefetch)
+{
+ // We have two independent flag bits in the functions
+ // therefore we will build a binary digit and select the
+ // function as a two digit binary
+ // Digit order SOFT_AES, NO_PREFETCH
+
+ static const cn_hash_fun_dbl func_table[4] = {
+ cryptonight_double_hash<0x80000, MEMORY, false, false>,
+ cryptonight_double_hash<0x80000, MEMORY, false, true>,
+ cryptonight_double_hash<0x80000, MEMORY, true, false>,
+ cryptonight_double_hash<0x80000, MEMORY, true, true>
+ };
+
+ std::bitset<2> digit;
+ digit.set(0, !bNoPrefetch);
+ digit.set(1, !bHaveAes);
+
+ return func_table[digit.to_ulong()];
+}
+
void minethd::double_work_main()
{
+ cn_hash_fun_dbl hash_fun;
cryptonight_ctx* ctx0;
cryptonight_ctx* ctx1;
uint64_t iCount = 0;
@@ -435,6 +459,7 @@ void minethd::double_work_main()
uint32_t iNonce;
job_result res;
+ hash_fun = func_dbl_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch);
ctx0 = minethd_alloc_ctx();
ctx1 = minethd_alloc_ctx();
@@ -484,7 +509,8 @@ void minethd::double_work_main()
*piNonce0 = ++iNonce;
*piNonce1 = ++iNonce;
- cryptonight_double_hash_ctx(bDoubleWorkBlob, oWork.iWorkSize, bDoubleHashOut, ctx0, ctx1);
+
+ hash_fun(bDoubleWorkBlob, oWork.iWorkSize, bDoubleHashOut, ctx0, ctx1);
if (*piHashVal0 < oWork.iTarget)
executor::inst()->push_event(ex_event(job_result(oWork.sJobID, iNonce-1, bDoubleHashOut), oWork.iPoolId));
diff --git a/minethd.h b/minethd.h
index d4470b1..6ba269e 100644
--- a/minethd.h
+++ b/minethd.h
@@ -1,6 +1,7 @@
#pragma once
#include
#include
+#include "crypto/cryptonight.h"
class telemetry
{
@@ -97,6 +98,9 @@ public:
std::atomic iTimestamp;
private:
+ typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx*);
+ typedef void (*cn_hash_fun_dbl)(const void*, size_t, void*, cryptonight_ctx* __restrict, cryptonight_ctx* __restrict);
+
minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch);
// We use the top 10 bits of the nonce for thread and resume
@@ -110,6 +114,9 @@ private:
inline uint32_t calc_nicehash_nonce(uint32_t start, uint32_t resume)
{ return start | (resume * iThreadCount + iThreadNo) << 18; }
+ static cn_hash_fun func_selector(bool bHaveAes, bool bNoPrefetch);
+ static cn_hash_fun_dbl func_dbl_selector(bool bHaveAes, bool bNoPrefetch);
+
void work_main();
void double_work_main();
void consume_work();
diff --git a/xmr-stak-cpu.cbp b/xmr-stak-cpu.cbp
index cc606fd..6d8553c 100644
--- a/xmr-stak-cpu.cbp
+++ b/xmr-stak-cpu.cbp
@@ -59,7 +59,7 @@
-
+
@@ -68,6 +68,7 @@
+