├── .gitattributes
├── .gitignore
├── .travis.yml
├── CMakeLists.txt
├── LICENSE
├── README.md
├── THIRD-PARTY-LICENSES
├── build.sh
├── doc
├── FAQ.md
├── compile.md
├── compile_FreeBSD.md
├── compile_Linux.md
├── compile_Windows.md
├── compile_macOS.md
├── tuning-cpu.md
├── tuning-gpu.md
└── usage.md
└── xmrstak
├── backend
├── amd
│ ├── OclCryptonightR_gen.cpp
│ ├── OclCryptonightR_gen.hpp
│ ├── amd_gpu
│ │ ├── gpu.cpp
│ │ ├── gpu.hpp
│ │ └── opencl
│ │ │ ├── blake256.cl
│ │ │ ├── cryptonight.cl
│ │ │ ├── cryptonight_gpu.cl
│ │ │ ├── cryptonight_r.rtcl
│ │ │ ├── cryptonight_r_def.rtcl
│ │ │ ├── fast_div_heavy.cl
│ │ │ ├── fast_int_math_v2.cl
│ │ │ ├── groestl256.cl
│ │ │ ├── jh.cl
│ │ │ ├── wolf-aes.cl
│ │ │ └── wolf-skein.cl
│ ├── autoAdjust.hpp
│ ├── config.tpl
│ ├── jconf.cpp
│ ├── jconf.hpp
│ ├── minethd.cpp
│ └── minethd.hpp
├── backendConnector.cpp
├── backendConnector.hpp
├── cpu
│ ├── autoAdjust.hpp
│ ├── autoAdjustHwloc.hpp
│ ├── common.h
│ ├── config.tpl
│ ├── cpuType.cpp
│ ├── cpuType.hpp
│ ├── crypto
│ │ ├── CryptonightR_gen.cpp
│ │ ├── asm
│ │ │ ├── cnR
│ │ │ │ ├── CryptonightR_soft_aes_template.inc
│ │ │ │ ├── CryptonightR_soft_aes_template_win.inc
│ │ │ │ ├── CryptonightR_template.S
│ │ │ │ ├── CryptonightR_template.asm
│ │ │ │ ├── CryptonightR_template.h
│ │ │ │ ├── CryptonightR_template.inc
│ │ │ │ ├── CryptonightR_template_win.inc
│ │ │ │ ├── CryptonightWOW_template.inc
│ │ │ │ └── CryptonightWOW_template_win.inc
│ │ │ ├── cryptonight_v8_double_main_loop_sandybridge_linux.inc
│ │ │ ├── cryptonight_v8_double_main_loop_sandybridge_win64.inc
│ │ │ ├── cryptonight_v8_main_loop.S
│ │ │ ├── cryptonight_v8_main_loop.asm
│ │ │ ├── cryptonight_v8_main_loop_ivybridge_linux.inc
│ │ │ ├── cryptonight_v8_main_loop_ivybridge_win64.inc
│ │ │ ├── cryptonight_v8_main_loop_ryzen_linux.inc
│ │ │ └── cryptonight_v8_main_loop_ryzen_win64.inc
│ │ ├── c_blake256.c
│ │ ├── c_blake256.h
│ │ ├── c_skein.c
│ │ ├── c_skein.h
│ │ ├── cn_gpu.hpp
│ │ ├── cn_gpu_avx.cpp
│ │ ├── cn_gpu_ssse3.cpp
│ │ ├── cryptonight.hpp
│ │ ├── cryptonight_aesni_p.hpp
│ │ ├── cryptonight_common.cpp
│ │ ├── cryptonight_common_p.hpp
│ │ ├── cryptonight_gpu_p.hpp
│ │ ├── cryptonight_main_p.hpp
│ │ ├── cryptonight_softaes_p.hpp
│ │ ├── extrahashes_p.hpp
│ │ ├── groestl.cpp
│ │ ├── groestl.hpp
│ │ ├── groestl_tables.hpp
│ │ ├── hash.h
│ │ ├── jh.cpp
│ │ ├── jh.hpp
│ │ ├── keccak.cpp
│ │ ├── keccak.hpp
│ │ ├── skein_port.h
│ │ ├── soft_aes.hpp
│ │ ├── soft_aes_p.hpp
│ │ └── variant4_random_math.h
│ ├── hwlocMemory.cpp
│ ├── hwlocMemory.hpp
│ ├── jconf.cpp
│ ├── jconf.hpp
│ ├── minethd.cpp
│ └── minethd.hpp
├── cryptonight.hpp
├── globalStates.cpp
├── globalStates.hpp
├── iBackend.hpp
├── miner_work.hpp
├── nvidia
│ ├── CudaCryptonightR_gen.cpp
│ ├── CudaCryptonightR_gen.hpp
│ ├── autoAdjust.hpp
│ ├── config.tpl
│ ├── jconf.cpp
│ ├── jconf.hpp
│ ├── minethd.cpp
│ ├── minethd.hpp
│ └── nvcc_code
│ │ ├── cryptonight.hpp
│ │ ├── cuda_aes.hpp
│ │ ├── cuda_blake.hpp
│ │ ├── cuda_core.cu
│ │ ├── cuda_cryptonight_gpu.hpp
│ │ ├── cuda_cryptonight_r.curt
│ │ ├── cuda_device.hpp
│ │ ├── cuda_extra.cu
│ │ ├── cuda_extra.hpp
│ │ ├── cuda_fast_div_heavy.hpp
│ │ ├── cuda_fast_int_math_v2.hpp
│ │ ├── cuda_groestl.hpp
│ │ ├── cuda_jh.hpp
│ │ ├── cuda_keccak.hpp
│ │ └── cuda_skein.hpp
├── plugin.hpp
└── pool_data.hpp
├── cli
├── cli-miner.cpp
├── colors.hpp
└── xmr-stak.manifest
├── config.tpl
├── cpputil
├── LICENSE.txt
└── read_write_lock.h
├── donate-level.hpp
├── http
├── httpd.cpp
├── httpd.hpp
├── webdesign.cpp
└── webdesign.hpp
├── jconf.cpp
├── jconf.hpp
├── misc
├── coinDescription.hpp
├── configEditor.hpp
├── console.cpp
├── console.hpp
├── environment.hpp
├── executor.cpp
├── executor.hpp
├── home_dir.hpp
├── jext.hpp
├── telemetry.cpp
├── telemetry.hpp
├── thdq.hpp
├── uac.cpp
├── uac.hpp
├── utility.cpp
└── utility.hpp
├── net
├── jpsock.cpp
├── jpsock.hpp
├── msgstruct.hpp
├── socket.cpp
├── socket.hpp
└── socks.hpp
├── params.hpp
├── picosha2
└── picosha2.hpp
├── pools.tpl
├── rapidjson
├── allocators.h
├── document.h
├── encodedstream.h
├── encodings.h
├── error
│ ├── en.h
│ └── error.h
├── filereadstream.h
├── filewritestream.h
├── fwd.h
├── internal
│ ├── biginteger.h
│ ├── diyfp.h
│ ├── dtoa.h
│ ├── ieee754.h
│ ├── itoa.h
│ ├── meta.h
│ ├── pow10.h
│ ├── regex.h
│ ├── stack.h
│ ├── strfunc.h
│ ├── strtod.h
│ └── swap.h
├── istreamwrapper.h
├── memorybuffer.h
├── memorystream.h
├── msinttypes
│ ├── inttypes.h
│ └── stdint.h
├── ostreamwrapper.h
├── pointer.h
├── prettywriter.h
├── rapidjson.h
├── reader.h
├── schema.h
├── stream.h
├── stringbuffer.h
└── writer.h
├── version.cpp
└── version.hpp
/.gitattributes:
--------------------------------------------------------------------------------
1 | xmrstak/version.cpp export-subst
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
3 | build/
4 | xmr-stak-cpu.layout
5 | xmr-stak-cpu.depend
6 | config-debug.txt
7 |
8 | # netbeans project files
9 | /nbproject/
10 |
11 | # tmp files
12 | *~
13 |
14 | # merge original backup files
15 | *.orig
16 |
17 | # KDevelop files
18 | .kdev4/
19 | xmr-stak.kdev4
20 |
21 | # Idea/Clion project files
22 | cmake-build-release/
23 | cmake-build-debug/
24 | \.idea/
25 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | dist: trusty
2 |
3 | osx_image: xcode8.3
4 |
5 | sudo: false
6 |
7 | language: cpp
8 |
9 | cache:
10 | apt: true
11 | directories:
12 | - $HOME/.cache/cuda
13 |
14 | addons:
15 | apt:
16 | packages: &default_packages
17 | - cmake
18 | - libmicrohttpd-dev
19 | - libssl-dev
20 | - libhwloc-dev
21 |
22 | env:
23 | global:
24 | - CUDA_ROOT: $HOME/.cache/cuda
25 |
26 | matrix:
27 | include:
28 | - os: linux
29 | compiler: gcc
30 | addons:
31 | apt:
32 | sources:
33 | - ubuntu-toolchain-r-test
34 | packages:
35 | - *default_packages
36 | - gcc-5
37 | - g++-5
38 | env:
39 | - CMAKE_CXX_COMPILER=g++-5
40 | - CMAKE_C_COMPILER=gcc-5
41 | - XMRSTAK_CMAKE_FLAGS="-DCUDA_ARCH=30 -DOpenCL_ENABLE=OFF"
42 |
43 | - os: linux
44 | compiler: gcc
45 | addons:
46 | apt:
47 | sources:
48 | - ubuntu-toolchain-r-test
49 | packages:
50 | - *default_packages
51 | - gcc-6
52 | - g++-6
53 | env:
54 | - CMAKE_CXX_COMPILER=g++-6
55 | - CMAKE_C_COMPILER=gcc-6
56 | - XMRSTAK_CMAKE_FLAGS="-DCUDA_ENABLE=OFF -DOpenCL_ENABLE=OFF"
57 |
58 | # test with disabled HWLOC, MICROHTTPD, OpenSSL and no accelerators
59 | - os: linux
60 | compiler: gcc
61 | addons:
62 | apt:
63 | sources:
64 | - ubuntu-toolchain-r-test
65 | packages:
66 | - *default_packages
67 | - gcc-6
68 | - g++-6
69 | env:
70 | - CMAKE_CXX_COMPILER=g++-6
71 | - CMAKE_C_COMPILER=gcc-6
72 | - XMRSTAK_CMAKE_FLAGS="-DCUDA_ENABLE=OFF -DOpenCL_ENABLE=OFF -DHWLOC_ENABLE=OFF -DOpenSSL_ENABLE=OFF -DMICROHTTPD_ENABLE=OFF"
73 |
74 | - os: linux
75 | compiler: gcc
76 | addons:
77 | apt:
78 | sources:
79 | - ubuntu-toolchain-r-test
80 | packages:
81 | - *default_packages
82 | - gcc-7
83 | - g++-7
84 | env:
85 | - CMAKE_CXX_COMPILER=g++-7
86 | - CMAKE_C_COMPILER=gcc-7
87 | - XMRSTAK_CMAKE_FLAGS="-DCUDA_ENABLE=OFF -DOpenCL_ENABLE=OFF"
88 |
89 | - os: osx
90 | compiler: gcc
91 | env:
92 | - XMRSTAK_CMAKE_FLAGS="-DCUDA_ENABLE=OFF -DOpenCL_ENABLE=OFF"
93 |
94 | before_install:
95 | - . CI/checkPRBranch
96 | - if [ $TRAVIS_OS_NAME = osx ] ; then
97 | brew update;
98 | fi
99 | - export PATH=$CUDA_ROOT/bin:$PATH
100 |
101 | install:
102 |
103 | # CUDA
104 | - if [ $TRAVIS_OS_NAME != osx ]; then
105 | NVCC_FOUND=$(which nvcc >/dev/null && { echo 0; } || { echo 1; });
106 | if [ $NVCC_FOUND -ne 0 ]; then
107 | mkdir -p $CUDA_ROOT &&
108 | cd $CUDA_ROOT &&
109 | travis_retry wget https://developer.nvidia.com/compute/cuda/8.0/prod/local_installers/cuda_8.0.44_linux-run &&
110 | ls -la &&
111 | chmod u+x *-run &&
112 | ./cuda_8.0.44_linux-run --silent --toolkit --toolkitpath=$CUDA_ROOT &&
113 | rm -rf ./cuda_8.0.44_linux-run $CUDA_ROOT/{samples,jre,doc,share} &&
114 | cd -;
115 | fi
116 | fi;
117 |
118 | script:
119 | - if [ $TRAVIS_OS_NAME = osx ]; then
120 | brew install hwloc;
121 | cmake -DMICROHTTPD_ENABLE=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ${XMRSTAK_CMAKE_FLAGS} .;
122 | else
123 | cmake -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} ${XMRSTAK_CMAKE_FLAGS} .;
124 | fi;
125 | - make VERBOSE=1 install
126 | - ./bin/xmr-stak --help
127 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CryptoGoblin - CryptoNight CPU/GPU mining tool
2 | **For coins based on the cryptonight algorithm family.**
3 | **Support for Monero, Electroneum, Aeon, Sumokoin, Edollar and many more.**
4 |
5 | CryptoGoblin is a greedy mining goblin that will push the cpu to get as many hashes as possible,
6 | if you believe in cpu-rights, then this might not be the mining tool for you.
7 |
8 | ## Overview
9 | * [Download](https://github.com/Dead2/CryptoGoblin/releases)
10 | * [Documentation](https://github.com/Dead2/CryptoGoblin/tree/master/doc)
11 |
12 | CryptoGoblin was forked from xmr-stak in early 2017, it utilizes several GCC compiler-specific tweaks and
13 | many other (medium, small, minor and micro) optimizations to get the most speed out of your cpu.
14 | CryptoGoblin can also be compiled using MSVC, but several of the optimizations will not be activated.
15 |
16 | ## Installation and Configuration
17 | If you are using Windows, download the pre-compiled windows binaries, or compile them yourself.
18 | If you are using Linux, MacOS, BSD or similar, you need to compile them yourself.
19 |
20 | After you have compiled or downloaded the executables, just run the miner without any configuration files,
21 | and it will help you generate the config files. After that, you can optionally tune your configuration.
22 | * [CPU Tuning](doc/tuning-cpu.md)
23 | * [GPU Tuning](doc/tuning-gpu.md)
24 |
25 | ## Windows
26 | Download the pre-compiled binaries [here](https://github.com/Dead2/CryptoGoblin/releases)
27 |
28 | ## Compilation
29 | CryptoGoblin includes a script `build.sh` that can be edited to easily change important settings
30 | and then run to start the compilation.
31 |
32 | To compile, run:
33 | `./build.sh`
34 |
35 | For more information about compiling and dependencies, please have a look at the documentation
36 | targeting your OS/distro [here](https://github.com/Dead2/CryptoGoblin/tree/master/doc).
37 |
38 | ## Donation
39 | Dev fee mining is set to 1.4%, and part of it goes to xmr-stak authors.
40 |
41 | If you want to make a little donation directly to me (Dead2), transfers or donation mining (at pool.supportxmr.com:3333), my XMR address is:
42 | ```
43 | 45obtQLBPgyZL8Xb4qFFdZQLZugJzkHUo7oHeKd2zZSmfjxRg6WKhAjD4o1eb6LjK1RY2V4sp1nmDAity9Ks9NvZHw8z1EL
44 | ```
45 | Any donation is much appreciated.
46 |
47 |
--------------------------------------------------------------------------------
/THIRD-PARTY-LICENSES:
--------------------------------------------------------------------------------
1 | This application bundles the following third-party software in accordance with the following licenses:
2 |
3 | -------------------------------------------------------------------------
4 |
5 | Package: Original NVidia mining code
6 | Authors: tsiv and KlausT
7 | License: GNU GPLv3
8 | Notes: Improvements are (c) of Xmr-Stak team and are covered by GNU GPLv3
9 |
10 | -------------------------------------------------------------------------
11 |
12 | Package: Original AMD mining code
13 | Authors: wolf9466
14 | License: MIT License
15 | Notes: Improvements are (c) of Xmr-Stak team and are covered by GNU GPLv3
16 |
17 | -------------------------------------------------------------------------
18 |
19 | Package: RapidJSON
20 | Authors: THL A29 Limited, a Tencent company, and Milo Yip
21 | License: MIT License and BSD License
22 |
23 | -------------------------------------------------------------------------
24 |
25 | Package: PicoSHA2
26 | Authors: okdshin
27 | License: MIT License
28 |
29 | -------------------------------------------------------------------------
30 |
31 | Package: cpputil
32 | Authors: Will Zhang
33 | Source: https://github.com/willzhang4a58/cpputil
34 | License: MIT License
35 |
36 | -------------------------------------------------------------------------
37 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Enable HWLOC library support? Defaults to ON
4 | hwloc="ON"
5 |
6 | # Enable webserver support? Defaults to ON
7 | microhttpd="ON"
8 |
9 | # Enable OpenSSL encryption support? Defaults to ON
10 | openssl="ON"
11 |
12 | # Enable CPU mining support? Defaults to ON
13 | cpu="ON"
14 |
15 | # Enable Nvidia CUDA GPU mining support? Defaults to ON
16 | cuda="ON"
17 |
18 | # Enable OpenCL mining support? Defaults to ON
19 | opencl="ON"
20 |
21 | # Enable GCC's LTO optimized compilation mode? Defaults to ON
22 | lto="ON"
23 |
24 | # Verbose compilation? Defaults to OFF
25 | verbose="OFF"
26 |
27 | # Install path
28 | installprefix="/opt/CryptoGoblin/"
29 |
30 | # Advanced cmake options, space delimited.
31 | cmakeopt=""
32 |
33 | # Make portable executable? This enables optimizations for cpus newer than "arch"
34 | # and enables static compilation of libgcc and libstdc++. Defaults to OFF
35 | # Not needed when using "arch=native" and using the executable on the local machine
36 | portable="OFF"
37 |
38 | # Optionally force enable/disable static build by uncommenting:
39 | # static="ON"
40 |
41 | # Disable all algorithms except the one needed by Monero/XMR. This results
42 | # in a smaller executable and can give a tiny speedup. Defaults to OFF
43 | # This will make the miner unable to work properly for any other algorithm.
44 | onlyxmr="OFF"
45 |
46 | # What is the oldest cpu the compiled binary needs to work with?
47 | # Choose "native" if you only need to support the local machine.
48 | # If you need to support other computers, choosing an older cpu is safer.
49 | # Supported parameters depend on your gcc version.
50 | # See: https://gcc.gnu.org/onlinedocs/gcc-6.4.0/gcc/x86-Options.html
51 |
52 | ## Default to native ##
53 | arch=native
54 |
55 | ## AMD cpus ##
56 | #arch="athlon64"
57 | #arch="athlon64-sse3"
58 | #arch="barcelona"
59 | #arch="bdver1"
60 | #arch="bdver2"
61 | #arch="bdver3"
62 | #arch="bdver4"
63 | #arch="znver1"
64 | #arch="btver1"
65 | #arch="btver2"
66 |
67 | ## Intel cpus ##
68 | #arch="nocona"
69 | #arch="core2"
70 | #arch="nehalem"
71 | #arch="westmere"
72 | #arch="sandybridge"
73 | #arch="ivybridge"
74 | #arch="haswell"
75 | #arch="broadwell"
76 | #arch="skylake"
77 | #arch="bonnell"
78 | #arch="silvermont"
79 | #arch="knl"
80 | #arch="skylake-avx512"
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | #########################
90 | # Usually no need to change anything below this point
91 | ##########
92 |
93 | # Enable static linking if portable is enabled
94 | if [ -z "$static" ]
95 | then
96 | static="OFF"
97 | if [ "$portable" == "ON" ]
98 | then
99 | static="ON"
100 | fi
101 | fi
102 |
103 | rm -rf CMakeFiles/ CMakeCache.txt
104 | mkdir -p build
105 | cd build
106 | rm -rf CMakeFiles/ CMakeCache.txt
107 |
108 | set -x
109 | cmake .. -L -DCMAKE_VERBOSE_MAKEFILE="$verbose" -DCMAKE_LINK_STATIC="$static" -DCMAKE_INSTALL_PREFIX="$installprefix" -DARCH="$arch" -DCG_LTO="$lto" -DCG_PORTABLE="$portable" -DCG_ONLY_XMR="$onlyxmr" -DHWLOC_ENABLE="$hwloc" -DMICROHTTPD_ENABLE="$microhttpd" -DOpenSSL_ENABLE="$openssl" -DCPU_ENABLE="$cpu" -DCUDA_ENABLE="$cuda" -DOpenCL_ENABLE="$opencl" $cmakeopt
110 |
111 | make -j3
112 | set +x
113 |
114 | strip --strip-all -R .comment build/bin/CryptoGoblin
115 |
116 | cd ..
117 | echo "If compilation succeeded, you can now run 'make install', or run/copy the executable directly in/from the build/bin/ folder"
118 |
--------------------------------------------------------------------------------
/doc/FAQ.md:
--------------------------------------------------------------------------------
1 | # FAQ
2 |
3 | ## Content Overview
4 | * ["Obtaining SeLockMemoryPrivilege failed."](#obtaining-selockmemoryprivilege-failed)
5 | * [VirtualAlloc failed](#virtualalloc-failed)
6 | * [Error msvcp140.dll and vcruntime140.dll not available](#error-msvcp140dll-and-vcruntime140dll-not-available)
7 | * [Error: MEMORY ALLOC FAILED: mmap failed](#error-memory-alloc-failed-mmap-failed)
8 | * [Illegal instruction (core dumped)](#illegal-instruction)
9 | * [Virus Protection Alert](#virus-protection-alert)
10 | * [Change Currency to Mine](#change-currency-to-mine)
11 | * [How can I mine Monero](#how-can-i-mine-monero)
12 | * [Which currency must be chosen if my fork coin is not listed](#which-currency-must-be-chosen-if-my-fork-coin-is-not-listed)
13 |
14 | ## "Obtaining SeLockMemoryPrivilege failed."
15 |
16 | For professional versions of Windows see [this article](https://msdn.microsoft.com/en-gb/library/ms190730.aspx).
17 | Make sure to reboot afterwards!
18 |
19 | For Windows 7/10 Home:
20 |
21 | 1) Download and install [Windows Server 2003 Resource Kit Tools](https://www.microsoft.com/en-us/download/details.aspx?id=17657). Ignore any incompatibility warning during installation.
22 |
23 | 2) Open cmd or PowerShell as an administrator.
24 |
25 | 3) Use `ntrights -u %USERNAME% +r SeLockMemoryPrivilege` where %USERNAME% is the user that will be running the program.
26 |
27 | 4) Reboot.
28 |
29 | Reference: http://rybkaforum.net/cgi-bin/rybkaforum/topic_show.pl?pid=259791#pid259791
30 |
31 | *Warning: Do not download ntrights.exe from any other site other than the offical Microsoft download page.*
32 |
33 | ## VirtualAlloc failed
34 |
35 | If you set up the user rights properly ([see above](https://github.com/Dead2/CryptoGoblin/blob/master/doc/FAQ.md#selockmemoryprivilege-failed)), and your system has 4-8GB of RAM (50%+ use), there is a significant chance that there simply won't be a large enough chunk of contiguous memory because Windows is fairly bad at mitigating memory fragmentation.
36 |
37 | If that happens, disable all auto-staring applications and run the miner after a reboot.
38 |
39 | ## Error msvcp140.dll and vcruntime140.dll not available
40 |
41 | Download and install this [runtime package](https://go.microsoft.com/fwlink/?LinkId=746572) from Microsoft. *Warning: Do NOT use "missing dll" sites - dll's are exe files with another name, and it is a fairly safe bet that any dll on a shady site like that will be trojaned. Please download offical runtimes from Microsoft above.*
42 |
43 |
44 | ## Error: MEMORY ALLOC FAILED: mmap failed
45 |
46 | On Linux you will need to configure large page support and increase your ulimit -l.
47 |
48 | To set large page support, add the following lines to /etc/sysctl.conf:
49 |
50 | vm.nr_hugepages=128
51 |
52 | To increase the ulimit, add following lines to /etc/security/limits.conf:
53 |
54 | * soft memlock 262144
55 | * hard memlock 262144
56 |
57 | You WILL need to log out and log back in for these settings to take affect on your user (no need to reboot, just relogin in your session).
58 |
59 | You can also do it Windows-style and simply run-as-root, but this is NOT recommended for security reasons.
60 |
61 | ## Illegal Instruction
62 |
63 | This means that the program attempted to use an instruction that the cpu does not support. This might be caused by choosing to compile for native instead of generic architecture.
64 |
65 | ## Virus Protection Alert
66 |
67 | Some virus protection software flags the miner binary as *malware*. This is a false positive — the software does not contain any malware (and since it is open source, you can verify that yourself!)
68 | If your antivirus software flags **CryptoGoblin**, it will likely move it to its quarantine area. You may have to whitelist **CryptoGoblin** in your antivirus.
69 |
70 | ## Change Currency to Mine
71 |
72 | If the miner is compiled for Monero and Aeon than you can change
73 | - the value `currency` in the config *or*
74 | - start the miner with the [command line option](usage.md) `--currency monero` or `--currency aeon`
75 | - run `CryptoGoblin --help` to see all supported currencies and algorithms
76 |
77 | ## How can I mine Monero
78 |
79 | Set the value `currency` in `pools.txt` to `monero`.
80 |
81 | ## Which currency must be chosen if my fork coin is not listed
82 |
83 | If your coin you want to mine is not listed please check the documentation of the coin and try to find out if `cryptonight`, `cryptonight-lite` or `cryptonight-heavy` is the used algorithm.
84 | Select one of these generic coin algorithms.
85 |
--------------------------------------------------------------------------------
/doc/compile_FreeBSD.md:
--------------------------------------------------------------------------------
1 | # Compile **CryptoGoblin** for FreeBSD
2 |
3 | ## Install Dependencies
4 |
5 | *Note: This guide is tested for FreeBSD 11.0-RELEASE*
6 |
7 | From the root shell, run the following commands:
8 |
9 | ```bash
10 | pkg install git libmicrohttpd hwloc cmake
11 | ```
12 | Type 'y' and hit enter to proceed with installing the packages.
13 |
14 | ```bash
15 | git clone https://github.com/Dead2/CryptoGoblin.git
16 | cd CryptoGoblin
17 | # Edit build.sh
18 | ./build.sh
19 | # (Optional:) make install
20 | ```
21 |
22 | Now you have the binary located at "build/bin/CryptoGoblin" and the needed shared libraries.
23 |
--------------------------------------------------------------------------------
/doc/compile_Linux.md:
--------------------------------------------------------------------------------
1 | # Compile **CryptoGoblin** for Linux
2 |
3 | ## Install Dependencies
4 |
5 | ## AMD APP SDK 3.0 (only needed to use AMD GPUs)
6 |
7 | - download and install the latest version from https://www.dropbox.com/sh/mpg882ekirnsfa7/AADWz5X-TgVdsmWt0QwMgTWLa/AMD-APP-SDKInstaller-v3.0.130.136-GA-linux64.tar.bz2?dl=0
8 | (do not wonder why it is a link to a dropbox but AMD has removed the SDK downloads, see https://community.amd.com/thread/228059)
9 |
10 | For linux also the OpenSource driver ROCm 1.9.X+ is a well working alternative, see https://rocm.github.io/ROCmInstall.html
11 | ROCm is not supporting old GPUs please check if your GPU is supported https://rocm.github.io/hardware.html.
12 |
13 | ## Cuda 8.0+ (only needed to use NVIDIA GPUs)
14 |
15 | - download and install [https://developer.nvidia.com/cuda-downloads](https://developer.nvidia.com/cuda-downloads)
16 | - for minimal install choose `Custom installation options` during the install and select
17 | - CUDA/Develpment
18 | - CUDA/Runtime
19 | - Driver components
20 |
21 | ## GNU Compiler
22 |
23 | - Remember to edit build.sh before running it, use your favourite text editor, for example 'nano'.
24 | - gcc and g++ version 5.1 or higher is required for full C++11 support.
25 | - Some newer gcc versions are not supported by CUDA (e.g. Ubuntu 17.10).
26 | - This will require installing gcc 5 and enabling the 'cudacomp' option in build.sh.
27 |
28 | ### Ubuntu / Debian
29 | ```bash
30 | sudo apt install libmicrohttpd-dev libssl-dev cmake build-essential libhwloc-dev
31 | git clone https://github.com/Dead2/CryptoGoblin.git
32 | cd CryptoGoblin
33 | # Edit build.sh
34 | ./build.sh
35 | # (Optional:) make install
36 | ```
37 |
38 | ### Arch
39 | ```bash
40 | sudo pacman -S --needed base-devel hwloc openssl cmake libmicrohttpd
41 | git clone https://github.com/Dead2/CryptoGoblin.git
42 | cd CryptoGoblin
43 | # Edit build.sh
44 | ./build.sh
45 | # (Optional:) make install
46 | ```
47 |
48 | ### Fedora
49 | ```bash
50 | sudo dnf install gcc gcc-c++ hwloc-devel libmicrohttpd-devel libstdc++-static make openssl-devel cmake
51 | git clone https://github.com/Dead2/CryptoGoblin.git
52 | cd CryptoGoblin
53 | # Edit build.sh
54 | ./build.sh
55 | # (Optional:) make install
56 | ```
57 |
58 | ### CentOS
59 | ```bash
60 | sudo yum install centos-release-scl epel-release
61 | sudo yum install cmake3 devtoolset-7-gcc* hwloc-devel libmicrohttpd-devel openssl-devel make
62 | scl enable devtoolset-7 bash
63 | git clone https://github.com/Dead2/CryptoGoblin.git
64 | cd CryptoGoblin
65 | # Edit build.sh
66 | ./build.sh
67 | # (Optional:) make install
68 | ```
69 |
70 | ### Ubuntu 14.04
71 | ```bash
72 | sudo add-apt-repository ppa:ubuntu-toolchain-r/test
73 | sudo apt update
74 | sudo apt install gcc-5 g++-5 make
75 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 1 --slave /usr/bin/g++ g++ /usr/bin/g++-5
76 | curl -L http://www.cmake.org/files/v3.4/cmake-3.4.1.tar.gz | tar -xvzf - -C /tmp/
77 | cd /tmp/cmake-3.4.1/ && ./configure && make && sudo make install && cd -
78 | sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
79 | sudo apt install libmicrohttpd-dev libssl-dev libhwloc-dev
80 | git clone https://github.com/Dead2/CryptoGoblin.git
81 | cd CryptoGoblin
82 | * Edit build.sh, set cmake to 'cmake3'
83 | ./build.sh
84 | # (Optional:) make install
85 | ```
86 |
87 | ### TinyCore Linux 8.x
88 | TinyCore is 32-bit only, but there is an x86-64 port, known as "Pure 64,"
89 | hosted on the TinyCore home page, and it works well.
90 | Beware that huge page support is not enabled in the kernel distributed
91 | with Pure 64. Consider http://wiki.tinycorelinux.net/wiki:custom_kernel
92 | Note that as of yet there are no distro packages for microhttpd or hwloc.
93 | hwloc is easy enough to install manually though, shown below.
94 | Also note that only CPU mining has been tested on this platform, thus the
95 | disabling of CUDA and OpenCL shown below.
96 | ```bash
97 | tce-load -iw openssl-dev.tcz cmake.tcz make.tcz gcc.tcz git.tcz \
98 | glibc_base-dev.tcz linux-4.8.1_api_headers.tcz glibc_add_lib.tcz
99 | ```
100 | If you want the optional hwloc functionality, compile it first:
101 | ```bash
102 | wget https://www.open-mpi.org/software/hwloc/v1.11/downloads/hwloc-1.11.8.tar.gz
103 | tar xzvf hwloc-1.11.8.tar.gz
104 | cd hwloc-1.11.8
105 | ./configure --prefix=/usr/local
106 | make
107 | sudo make install
108 | cd ..
109 | ```
110 | Then compile CryptoGoblin itself:
111 | ```bash
112 | git clone http://github.com/Dead2/CryptoGoblin
113 | cd CryptoGoblin
114 | * Edit build.sh, set cmake to 'cmake3'
115 | ./build.sh
116 | # (Optional:) make install
117 | ```
118 |
--------------------------------------------------------------------------------
/doc/compile_macOS.md:
--------------------------------------------------------------------------------
1 | # Compile **CryptoGoblin** for macOS
2 |
3 | ## Installing dependencies
4 |
5 | Assuming you already have [Homebrew](https://brew.sh) installed, the installation of dependencies is pretty straightforward and will generate the `CryptoGoblin` binary in the `build/bin/` directory.
6 |
7 |
8 | ### Common
9 | ```bash
10 | brew install hwloc libmicrohttpd gcc openssl cmake
11 | ```
12 |
13 | ### For NVIDIA GPUs
14 | ```bash
15 | brew tap caskroom/drivers
16 | brew cask install nvidia-cuda
17 | ```
18 |
19 | ## Compiling
20 | ```bash
21 | git clone https://github.com/Dead2/CryptoGoblin.git
22 | cd CryptoGoblin
23 | # Edit build.sh
24 | ./build.sh
25 | # (Optional:) make install
26 | ```
27 |
--------------------------------------------------------------------------------
/doc/usage.md:
--------------------------------------------------------------------------------
1 | # HowTo Use CryptoGoblin
2 |
3 | ## Content Overview
4 | * [Configuration](#configuration)
5 | * [Usage on Windows](#usage-on-windows)
6 | * [Usage on Linux](#usage-on-linux)
7 | * [Command Line Options](#command-line-options)
8 | * [HTML and JSON API report configuraton](#html-and-json-api-report-configuraton)
9 |
10 | ## Configurations
11 |
12 | Before you started the miner the first time there are no config files available.
13 | Config files will be created at the first start.
14 | The number of files depends on the available backends.
15 | `config.txt` contains the common miner settings.
16 | `pools.txt` contains the selected mining pools and currency to mine.
17 | `amd.txt`, `cpu.txt` and `nvidia.txt` contains miner backend specific settings and can be used for further tuning ([Tuning Guide](tuning.md)).
18 |
19 | Note: If the pool is ignoring the option `rig_id` in `pools.txt` to name your worker please check the pool documentation how a worker name can be set.
20 |
21 | ## Usage on Windows
22 | 1) Double click the `CryptoGoblin.exe` file
23 | 2) Fill in the pool url settings, currency, username and password
24 |
25 | `set XMRSTAK_NOWAIT=1` disable the dialog `Press any key to exit.` for non UAC execution.
26 |
27 |
28 | ## Usage on Linux & macOS
29 | 1) Open a terminal within the folder with the binary
30 | 2) Start the miner with `./CryptoGoblin`
31 |
32 | ## Command Line Options
33 |
34 | The miner allow to overwrite some of the settings via command line options.
35 | Run `CryptoGoblin --help` to show all available command line options.
36 |
37 | ## HTML and JSON API report configuraton
38 |
39 | To configure the reports shown on the [README](../README.md) side you need to edit the httpd_port variable. Then enable wifi on your phone and navigate to [miner ip address]:[httpd_port] in your phone browser. If you want to use the data in scripts, you can get the JSON version of the data at url [miner ip address]:[httpd_port]/api.json
40 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/OclCryptonightR_gen.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/backend/cryptonight.hpp"
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | #if defined(__APPLE__)
10 | #include
11 | #else
12 | #include
13 | #endif
14 |
15 | #include "xmrstak/backend/amd/amd_gpu/gpu.hpp"
16 |
17 | namespace xmrstak
18 | {
19 | namespace amd
20 | {
21 |
22 | cl_program CryptonightR_get_program(GpuContext* ctx, const xmrstak_algo algo,
23 | uint64_t height_offset, uint64_t height_chunk_size, uint32_t precompile_count, bool background = false);
24 |
25 | } // namespace amd
26 | } // namespace xmrstak
27 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/amd_gpu/opencl/blake256.cl:
--------------------------------------------------------------------------------
1 | R"===(
2 | /*
3 | * blake256 kernel implementation.
4 | *
5 | * ==========================(LICENSE BEGIN)============================
6 | * Copyright (c) 2014 djm34
7 | * Copyright (c) 2014 tpruvot
8 | * Permission is hereby granted, free of charge, to any person obtaining
9 | * a copy of this software and associated documentation files (the
10 | * "Software"), to deal in the Software without restriction, including
11 | * without limitation the rights to use, copy, modify, merge, publish,
12 | * distribute, sublicense, and/or sell copies of the Software, and to
13 | * permit persons to whom the Software is furnished to do so, subject to
14 | * the following conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 | *
27 | * ===========================(LICENSE END)=============================
28 | *
29 | * @author djm34
30 | */
31 | __constant static const int sigma[16][16] = {
32 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
33 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
34 | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
35 | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
36 | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
37 | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
38 | { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
39 | { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
40 | { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
41 | { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
42 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
43 | { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
44 | { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
45 | { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
46 | { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
47 | { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
48 | };
49 |
50 |
51 | __constant static const sph_u32 c_IV256[8] = {
52 | 0x6A09E667, 0xBB67AE85,
53 | 0x3C6EF372, 0xA54FF53A,
54 | 0x510E527F, 0x9B05688C,
55 | 0x1F83D9AB, 0x5BE0CD19
56 | };
57 |
58 | /* Second part (64-80) msg never change, store it */
59 | __constant static const sph_u32 c_Padding[16] = {
60 | 0, 0, 0, 0,
61 | 0x80000000, 0, 0, 0,
62 | 0, 0, 0, 0,
63 | 0, 1, 0, 640,
64 | };
65 | __constant static const sph_u32 c_u256[16] = {
66 | 0x243F6A88, 0x85A308D3,
67 | 0x13198A2E, 0x03707344,
68 | 0xA4093822, 0x299F31D0,
69 | 0x082EFA98, 0xEC4E6C89,
70 | 0x452821E6, 0x38D01377,
71 | 0xBE5466CF, 0x34E90C6C,
72 | 0xC0AC29B7, 0xC97C50DD,
73 | 0x3F84D5B5, 0xB5470917
74 | };
75 |
76 | #define GS(a,b,c,d,x) { \
77 | const sph_u32 idx1 = sigma[r][x]; \
78 | const sph_u32 idx2 = sigma[r][x+1]; \
79 | v[a] += (m[idx1] ^ c_u256[idx2]) + v[b]; \
80 | v[d] ^= v[a]; \
81 | v[d] = rotate(v[d], 16U); \
82 | v[c] += v[d]; \
83 | v[b] ^= v[c]; \
84 | v[b] = rotate(v[b], 20U); \
85 | \
86 | v[a] += (m[idx2] ^ c_u256[idx1]) + v[b]; \
87 | v[d] ^= v[a]; \
88 | v[d] = rotate(v[d], 24U); \
89 | v[c] += v[d]; \
90 | v[b] ^= v[c]; \
91 | v[b] = rotate(v[b], 25U); \
92 | }
93 | )==="
94 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/amd_gpu/opencl/cryptonight_r_def.rtcl:
--------------------------------------------------------------------------------
1 | R"===(
2 | /*
3 | * This program is free software: you can redistribute it and/or modify
4 | * it under the terms of the GNU General Public License as published by
5 | * the Free Software Foundation, either version 3 of the License, or
6 | * any later version.
7 | *
8 | * This program is distributed in the hope that it will be useful,
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | * GNU General Public License for more details.
12 | *
13 | * You should have received a copy of the GNU General Public License
14 | * along with this program. If not, see .
15 | *
16 | */
17 |
18 | #define cryptonight_r_wow 15
19 | #define cryptonight_r 16
20 |
21 | #define MEM_CHUNK (1 << MEM_CHUNK_EXPONENT)
22 |
23 | #if(STRIDED_INDEX==0)
24 | # define IDX(x) (x)
25 | #elif(STRIDED_INDEX==1)
26 | # define IDX(x) (mul24(((uint)(x)), Threads))
27 | #elif(STRIDED_INDEX==2)
28 | # define IDX(x) (((x) % MEM_CHUNK) + ((x) / MEM_CHUNK) * WORKSIZE * MEM_CHUNK)
29 | #elif(STRIDED_INDEX==3)
30 | # define IDX(x) ((x) * WORKSIZE)
31 | #endif
32 |
33 | )==="
34 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/amd_gpu/opencl/fast_div_heavy.cl:
--------------------------------------------------------------------------------
1 | R"===(
2 |
3 | #if(ALGO == cryptonight_heavy || ALGO == cryptonight_haven || ALGO == cryptonight_bittube2 || ALGO == cryptonight_superfast)
4 | inline long fast_div_heavy(long _a, int _b)
5 | {
6 | long a = abs(_a);
7 | int b = abs(_b);
8 | float rcp = native_recip(convert_float_rte(b));
9 | float rcp2 = as_float(as_uint(rcp) + (32U << 23));
10 | ulong q1 = convert_ulong(convert_float_rte(as_int2(a).s1) * rcp2);
11 | a -= q1 * as_uint(b);
12 | float q2f = convert_float_rte(as_int2(a >> 12).s0) * rcp;
13 | q2f = as_float(as_uint(q2f) + (12U << 23));
14 | long q2 = convert_long_rte(q2f);
15 | int a2 = as_int2(a).s0 - as_int2(q2).s0 * b;
16 | int q3 = convert_int_rte(convert_float_rte(a2) * rcp);
17 | q3 += (a2 - q3 * b) >> 31;
18 | const long q = q1 + q2 + q3;
19 | return ((as_int2(_a).s1 ^ _b) < 0) ? -q : q;
20 | }
21 | #endif
22 | )==="
23 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/amd_gpu/opencl/wolf-skein.cl:
--------------------------------------------------------------------------------
1 | R"===(
2 | #ifndef WOLF_SKEIN_CL
3 | #define WOLF_SKEIN_CL
4 |
5 | // Vectorized Skein implementation macros and functions by Wolf
6 | // Updated by taisel
7 |
8 | #define SKEIN_KS_PARITY 0x1BD11BDAA9FC1A22
9 |
10 | static const __constant ulong SKEIN256_IV[8] =
11 | {
12 | 0xCCD044A12FDB3E13UL, 0xE83590301A79A9EBUL,
13 | 0x55AEA0614F816E6FUL, 0x2A2767A4AE9B94DBUL,
14 | 0xEC06025E74DD7683UL, 0xE7A436CDC4746251UL,
15 | 0xC36FBAF9393AD185UL, 0x3EEDBA1833EDFC13UL
16 | };
17 |
18 | static const __constant ulong SKEIN512_256_IV[8] =
19 | {
20 | 0xCCD044A12FDB3E13UL, 0xE83590301A79A9EBUL,
21 | 0x55AEA0614F816E6FUL, 0x2A2767A4AE9B94DBUL,
22 | 0xEC06025E74DD7683UL, 0xE7A436CDC4746251UL,
23 | 0xC36FBAF9393AD185UL, 0x3EEDBA1833EDFC13UL
24 | };
25 |
26 | #define SKEIN_INJECT_KEY(p, s, q) do { \
27 | p += h; \
28 | p.s5 += t[s]; \
29 | p.s6 += t[select(s + 1U, 0U, s == 2U)]; \
30 | p.s7 += q; \
31 | } while(0)
32 |
33 | ulong SKEIN_ROT(const uint2 x, const uint y)
34 | {
35 | if(y < 32) return(as_ulong(amd_bitalign(x, x.s10, 32 - y)));
36 | else return(as_ulong(amd_bitalign(x.s10, x, 32 - (y - 32))));
37 | }
38 |
39 | void SkeinMix8(ulong4 *pv0, ulong4 *pv1, const ulong4 rc)
40 | {
41 | *pv0 += *pv1;
42 | (*pv1).s0 = SKEIN_ROT(as_uint2((*pv1).s0), rc.s0);
43 | (*pv1).s1 = SKEIN_ROT(as_uint2((*pv1).s1), rc.s1);
44 | (*pv1).s2 = SKEIN_ROT(as_uint2((*pv1).s2), rc.s2);
45 | (*pv1).s3 = SKEIN_ROT(as_uint2((*pv1).s3), rc.s3);
46 | *pv1 ^= *pv0;
47 | }
48 |
49 | ulong8 SkeinEvenRound(ulong8 p, const ulong8 h, const ulong *t, const uint s, const uint q)
50 | {
51 | SKEIN_INJECT_KEY(p, s, q);
52 | ulong4 pv0 = p.even, pv1 = p.odd;
53 |
54 | SkeinMix8(&pv0, &pv1, (ulong4)(46, 36, 19, 37));
55 | pv0 = shuffle(pv0, (ulong4)(1, 2, 3, 0));
56 | pv1 = shuffle(pv1, (ulong4)(0, 3, 2, 1));
57 |
58 | SkeinMix8(&pv0, &pv1, (ulong4)(33, 27, 14, 42));
59 | pv0 = shuffle(pv0, (ulong4)(1, 2, 3, 0));
60 | pv1 = shuffle(pv1, (ulong4)(0, 3, 2, 1));
61 |
62 | SkeinMix8(&pv0, &pv1, (ulong4)(17, 49, 36, 39));
63 | pv0 = shuffle(pv0, (ulong4)(1, 2, 3, 0));
64 | pv1 = shuffle(pv1, (ulong4)(0, 3, 2, 1));
65 |
66 | SkeinMix8(&pv0, &pv1, (ulong4)(44, 9, 54, 56));
67 | return(shuffle2(pv0, pv1, (ulong8)(1, 4, 2, 7, 3, 6, 0, 5)));
68 | }
69 |
70 | ulong8 SkeinOddRound(ulong8 p, const ulong8 h, const ulong *t, const uint s, const uint q)
71 | {
72 | SKEIN_INJECT_KEY(p, s, q);
73 | ulong4 pv0 = p.even, pv1 = p.odd;
74 |
75 | SkeinMix8(&pv0, &pv1, (ulong4)(39, 30, 34, 24));
76 | pv0 = shuffle(pv0, (ulong4)(1, 2, 3, 0));
77 | pv1 = shuffle(pv1, (ulong4)(0, 3, 2, 1));
78 |
79 | SkeinMix8(&pv0, &pv1, (ulong4)(13, 50, 10, 17));
80 | pv0 = shuffle(pv0, (ulong4)(1, 2, 3, 0));
81 | pv1 = shuffle(pv1, (ulong4)(0, 3, 2, 1));
82 |
83 | SkeinMix8(&pv0, &pv1, (ulong4)(25, 29, 39, 43));
84 | pv0 = shuffle(pv0, (ulong4)(1, 2, 3, 0));
85 | pv1 = shuffle(pv1, (ulong4)(0, 3, 2, 1));
86 |
87 | SkeinMix8(&pv0, &pv1, (ulong4)(8, 35, 56, 22));
88 | return(shuffle2(pv0, pv1, (ulong8)(1, 4, 2, 7, 3, 6, 0, 5)));
89 | }
90 |
91 | ulong8 Skein512Block(ulong8 p, ulong8 h, ulong h8, const ulong *t)
92 | {
93 | #pragma unroll
94 | for(int i = 0; i < 18; ++i)
95 | {
96 | p = SkeinEvenRound(p, h, t, 0U, i);
97 | ++i;
98 | ulong tmp = h.s0;
99 | h = shuffle(h, (ulong8)(1, 2, 3, 4, 5, 6, 7, 0));
100 | h.s7 = h8;
101 | h8 = tmp;
102 | p = SkeinOddRound(p, h, t, 1U, i);
103 | ++i;
104 | tmp = h.s0;
105 | h = shuffle(h, (ulong8)(1, 2, 3, 4, 5, 6, 7, 0));
106 | h.s7 = h8;
107 | h8 = tmp;
108 | p = SkeinEvenRound(p, h, t, 2U, i);
109 | ++i;
110 | tmp = h.s0;
111 | h = shuffle(h, (ulong8)(1, 2, 3, 4, 5, 6, 7, 0));
112 | h.s7 = h8;
113 | h8 = tmp;
114 | p = SkeinOddRound(p, h, t, 0U, i);
115 | ++i;
116 | tmp = h.s0;
117 | h = shuffle(h, (ulong8)(1, 2, 3, 4, 5, 6, 7, 0));
118 | h.s7 = h8;
119 | h8 = tmp;
120 | p = SkeinEvenRound(p, h, t, 1U, i);
121 | ++i;
122 | tmp = h.s0;
123 | h = shuffle(h, (ulong8)(1, 2, 3, 4, 5, 6, 7, 0));
124 | h.s7 = h8;
125 | h8 = tmp;
126 | p = SkeinOddRound(p, h, t, 2U, i);
127 | tmp = h.s0;
128 | h = shuffle(h, (ulong8)(1, 2, 3, 4, 5, 6, 7, 0));
129 | h.s7 = h8;
130 | h8 = tmp;
131 | }
132 |
133 | p += h;
134 | p.s5 += t[0];
135 | p.s6 += t[1];
136 | p.s7 += 18;
137 | return(p);
138 | }
139 |
140 | #endif
141 |
142 | )==="
143 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/config.tpl:
--------------------------------------------------------------------------------
1 | R"===(// generated by XMRSTAK_VERSION
2 |
3 | /*
4 | * GPU configuration. You should play around with intensity and worksize as the fastest settings will vary.
5 | * index - GPU index number usually starts from 0
6 | * intensity - Number of parallel GPU threads (nothing to do with CPU threads)
7 | * worksize - Number of local GPU threads (nothing to do with CPU threads)
8 | * affine_to_cpu - This will affine the thread to a CPU. This can make a GPU miner play along nicer with a CPU miner.
9 | * strided_index - switch memory pattern used for the scratchpad memory
10 | * 3 = chunked memory, chunk size based on the 'worksize'
11 | * required: intensity must be a multiple of worksize
12 | * 2 = chunked memory, chunk size is controlled by 'mem_chunk'
13 | * required: intensity must be a multiple of worksize
14 | * 1 or true = use 16 byte contiguous memory per thread, the next memory block has offset of intensity blocks
15 | * (for cryptonight_v8 and monero it is equal to strided_index = 0)
16 | * 0 or false = use a contiguous block of memory per thread
17 | * mem_chunk - range 0 to 18: set the number of elements (16byte) per chunk
18 | * this value is only used if 'strided_index' == 2
19 | * element count is computed with the equation: 2 to the power of 'mem_chunk' e.g. 4 means a chunk of 16 elements(256 byte)
20 | * unroll - allow to control how often the POW main loop is unrolled; valid range [1;128) - for most OpenCL implementations it must be a power of two.
21 | * comp_mode - Compatibility enable/disable the automatic guard around compute kernel which allows
22 | * to use an intensity which is not the multiple of the worksize.
23 | * If you set false and the intensity is not multiple of the worksize the miner can crash:
24 | * in this case set the intensity to a multiple of the worksize or activate comp_mode.
25 | * interleave - Controls the starting point in time between two threads on the same GPU device relative to the last started thread.
26 | * This option has only an effect if two compute threads using the same GPU device: valid range [0;100]
27 | * 0 = disable thread interleaving
28 | * 40 = each working thread waits until 40% of the hash calculation of the previously started thread is finished
29 | * "gpu_threads_conf" :
30 | * [
31 | * { "index" : 0, "intensity" : 1000, "worksize" : 8, "affine_to_cpu" : false,
32 | * "strided_index" : true, "mem_chunk" : 2, "unroll" : 8, "comp_mode" : true,
33 | * "interleave" : 40
34 | * },
35 | * ],
36 | * If you do not wish to mine with your AMD GPU(s) then use:
37 | * "gpu_threads_conf" :
38 | * null,
39 | */
40 |
41 | "gpu_threads_conf" : [
42 | GPUCONFIG
43 | ],
44 |
45 | /*
46 | * number of rounds per intensity performed to find the best intensity settings
47 | *
48 | * WARNING: experimental option
49 | *
50 | * 0 = disable auto tuning
51 | * 10 or higher = recommended value if you not already know the best intensity
52 | */
53 | "auto_tune" : 0,
54 |
55 | /*
56 | * Platform index. This will be 0 unless you have different OpenCL platform - eg. AMD and Intel.
57 | */
58 | "platform_index" : PLATFORMINDEX,
59 | )==="
60 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/jconf.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/params.hpp"
4 |
5 | #include
6 | #include
7 |
8 | namespace xmrstak
9 | {
10 | namespace amd
11 | {
12 |
13 | class jconf
14 | {
15 | public:
16 | static jconf* inst()
17 | {
18 | if (oInst == nullptr) oInst = new jconf;
19 | return oInst;
20 | };
21 |
22 | bool parse_config(const char* sFilename = params::inst().configFileAMD.c_str());
23 |
24 | struct thd_cfg {
25 | size_t index;
26 | size_t intensity;
27 | size_t w_size;
28 | long long cpu_aff;
29 | int stridedIndex;
30 | int interleave = 40;
31 | int memChunk;
32 | int unroll;
33 | bool compMode;
34 | };
35 |
36 | size_t GetThreadCount();
37 | bool GetThreadConfig(size_t id, thd_cfg &cfg);
38 |
39 | size_t GetAutoTune();
40 | size_t GetPlatformIdx();
41 |
42 | private:
43 | jconf();
44 | static jconf* oInst;
45 |
46 | struct opaque_private;
47 | opaque_private* prv;
48 |
49 | };
50 |
51 | } // namespace amd
52 | } // namespace xmrstak
53 |
--------------------------------------------------------------------------------
/xmrstak/backend/amd/minethd.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "amd_gpu/gpu.hpp"
4 | #include "jconf.hpp"
5 | #include "xmrstak/backend/cpu/crypto/cryptonight.hpp"
6 | #include "xmrstak/backend/miner_work.hpp"
7 | #include "xmrstak/backend/iBackend.hpp"
8 | #include "xmrstak/misc/environment.hpp"
9 |
10 | #include
11 | #include
12 | #include
13 |
14 | namespace xmrstak
15 | {
16 | namespace amd
17 | {
18 |
19 | class minethd : public iBackend
20 | {
21 | public:
22 |
23 | static std::vector* thread_starter(uint32_t threadOffset, miner_work& pWork);
24 | static bool init_gpus();
25 |
26 | private:
27 | typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx**, const xmrstak_algo&);
28 |
29 | minethd(miner_work& pWork, size_t iNo, GpuContext* ctx, const jconf::thd_cfg cfg);
30 |
31 | void work_main();
32 |
33 | uint64_t iJobNo;
34 |
35 | miner_work oWork;
36 |
37 | std::promise order_fix;
38 | std::mutex thd_aff_set;
39 |
40 | std::thread oWorkThd;
41 | int64_t affinity;
42 | uint32_t autoTune;
43 |
44 | bool bQuit;
45 | bool bNoPrefetch;
46 |
47 | //Mutable ptr to vector below, different for each thread
48 | GpuContext* pGpuCtx;
49 |
50 | // WARNING - this vector (but not its contents) must be immutable
51 | // once the threads are started
52 | static std::vector vGpuData;
53 | };
54 |
55 | } // namespace amd
56 | } // namespace xmrstak
57 |
--------------------------------------------------------------------------------
/xmrstak/backend/backendConnector.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU General Public License
13 | * along with this program. If not, see .
14 | *
15 | * Additional permission under GNU GPL version 3 section 7
16 | *
17 | * If you modify this Program, or any covered work, by linking or combining
18 | * it with OpenSSL (or a modified version of that library), containing parts
19 | * covered by the terms of OpenSSL License and SSLeay License, the licensors
20 | * of this Program grant you additional permission to convey the resulting work.
21 | *
22 | */
23 |
24 | #include "iBackend.hpp"
25 | #include "backendConnector.hpp"
26 | #include "miner_work.hpp"
27 | #include "globalStates.hpp"
28 | #include "plugin.hpp"
29 | #include "xmrstak/misc/environment.hpp"
30 | #include "xmrstak/misc/console.hpp"
31 | #include "xmrstak/params.hpp"
32 |
33 | #include "cpu/minethd.hpp"
34 | #ifndef CONF_NO_CUDA
35 | # include "nvidia/minethd.hpp"
36 | #endif
37 | #ifndef CONF_NO_OPENCL
38 | # include "amd/minethd.hpp"
39 | #endif
40 |
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 |
49 |
50 | namespace xmrstak
51 | {
52 |
53 | bool BackendConnector::self_test()
54 | {
55 | return cpu::minethd::self_test();
56 | }
57 |
58 | std::vector* BackendConnector::thread_starter(miner_work& pWork)
59 | {
60 |
61 | std::vector* pvThreads = new std::vector;
62 |
63 | #ifndef CONF_NO_OPENCL
64 | if(params::inst().useAMD)
65 | {
66 | const std::string backendName = xmrstak::params::inst().openCLVendor;
67 | plugin amdplugin;
68 | amdplugin.load(backendName, "CryptoGoblin_opencl");
69 | std::vector* amdThreads = amdplugin.startBackend(static_cast(pvThreads->size()), pWork, environment::inst());
70 | size_t numWorkers = 0u;
71 | if(amdThreads != nullptr)
72 | {
73 | pvThreads->insert(std::end(*pvThreads), std::begin(*amdThreads), std::end(*amdThreads));
74 | numWorkers = amdThreads->size();
75 | delete amdThreads;
76 | }
77 | if(numWorkers == 0)
78 | printer::inst()->print_msg(L0, "WARNING: backend %s (OpenCL) disabled.", backendName.c_str());
79 | }
80 | #endif
81 |
82 | #ifndef CONF_NO_CUDA
83 | if(params::inst().useNVIDIA)
84 | {
85 | plugin nvidiaplugin;
86 | std::vector libNames = {"CryptoGoblin_cuda10_0", "CryptoGoblin_cuda9_2", "CryptoGoblin_cuda"};
87 | size_t numWorkers = 0u;
88 |
89 | for( const auto & name : libNames)
90 | {
91 | printer::inst()->print_msg(L0, "NVIDIA: try to load library '%s'", name.c_str());
92 | nvidiaplugin.load("NVIDIA", name);
93 | std::vector* nvidiaThreads = nvidiaplugin.startBackend(static_cast(pvThreads->size()), pWork, environment::inst());
94 | if(nvidiaThreads != nullptr)
95 | {
96 | pvThreads->insert(std::end(*pvThreads), std::begin(*nvidiaThreads), std::end(*nvidiaThreads));
97 | numWorkers = nvidiaThreads->size();
98 | delete nvidiaThreads;
99 | }
100 | else
101 | {
102 | // remove the plugin if we have found no GPUs
103 | nvidiaplugin.unload();
104 | }
105 | // we found at leat one working GPU
106 | if(numWorkers != 0)
107 | {
108 | printer::inst()->print_msg(L0, "NVIDIA: use library '%s'", name.c_str());
109 | break;
110 | }
111 | }
112 | if(numWorkers == 0)
113 | printer::inst()->print_msg(L0, "WARNING: backend NVIDIA disabled.");
114 | }
115 | #endif
116 |
117 | #ifndef CONF_NO_CPU
118 | if(params::inst().useCPU)
119 | {
120 | auto cpuThreads = cpu::minethd::thread_starter(static_cast(pvThreads->size()), pWork);
121 | pvThreads->insert(std::end(*pvThreads), std::begin(cpuThreads), std::end(cpuThreads));
122 | if(cpuThreads.size() == 0)
123 | printer::inst()->print_msg(L0, "WARNING: backend CPU disabled.");
124 | }
125 | #endif
126 |
127 | globalStates::inst().iThreadCount = pvThreads->size();
128 | return pvThreads;
129 | }
130 |
131 | } // namespace xmrstak
132 |
--------------------------------------------------------------------------------
/xmrstak/backend/backendConnector.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "iBackend.hpp"
4 | #include "miner_work.hpp"
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 |
12 | namespace xmrstak
13 | {
14 |
15 | struct BackendConnector
16 | {
17 | static std::vector* thread_starter(miner_work& pWork);
18 | static bool self_test();
19 | };
20 |
21 | } // namespace xmrstak
22 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/common.h:
--------------------------------------------------------------------------------
1 | #ifndef COMMON_H
2 | #define COMMON_H
3 |
4 | #define XMR_HASHBITLEN 256U
5 | #define XMR_DATABITLEN 1600ULL
6 |
7 |
8 | #ifdef HAVE_ALWAYS_INLINE
9 | # define ALWAYS_INLINE __attribute__((always_inline))
10 | #else
11 | # define ALWAYS_INLINE
12 | #endif
13 |
14 | #ifdef HAVE_FLATTEN
15 | # ifdef DO_FLATTEN1
16 | # define FLATTEN __attribute__((flatten))
17 | # else
18 | # define FLATTEN
19 | # endif
20 | # ifdef DO_FLATTEN2
21 | # define FLATTEN2 __attribute__((flatten))
22 | # else
23 | # define FLATTEN2
24 | # endif
25 | # ifdef DO_FLATTEN3
26 | # define FLATTEN3 __attribute__((flatten))
27 | # else
28 | # define FLATTEN3
29 | # endif
30 | #else
31 | # define FLATTEN
32 | # define FLATTEN2
33 | # define FLATTEN3
34 | #endif
35 |
36 | #ifdef HAVE_ALIGNED
37 | # define ALIGN(x) __attribute__((aligned (x)))
38 | #else
39 | # define ALIGN(x)
40 | #endif
41 |
42 | #ifdef HAVE_OPTIMIZE
43 | # define OPTIMIZE(x) __attribute__((optimize (x)))
44 | #else
45 | # define OPTIMIZE(x)
46 | #endif
47 |
48 | #ifdef HAVE_TARGET_CLONES
49 | # define TARGETS(x) __attribute__((target_clones(x)))
50 | #else
51 | # define TARGETS(x)
52 | #endif
53 |
54 | #ifdef HAVE_LIKELY
55 | # define likely(x) __builtin_expect((x),1)
56 | # define unlikely(x) __builtin_expect((x),0)
57 | #endif
58 |
59 |
60 | #ifdef DEBUG
61 | #include
62 | static void print_hex_memory(void *mem, int len) {
63 | int i;
64 | unsigned char *p = (unsigned char *)mem;
65 | for (i=0;i
5 | #include
6 | #include
7 |
8 | #ifdef _WIN32
9 | #define strcasecmp _stricmp
10 | #include
11 | #else
12 | #include
13 | #endif
14 |
15 | namespace xmrstak
16 | {
17 | namespace cpu
18 | {
19 | void cpuid(uint32_t eax, int32_t ecx, int32_t val[4])
20 | {
21 | std::memset(val, 0, sizeof(int32_t)*4);
22 |
23 | #ifdef _WIN32
24 | __cpuidex(val, eax, ecx);
25 | #else
26 | __cpuid_count(eax, ecx, val[0], val[1], val[2], val[3]);
27 | #endif
28 | }
29 |
30 | int32_t get_masked(int32_t val, int32_t h, int32_t l)
31 | {
32 | val &= (0x7FFFFFFF >> (31-(h-l))) << l;
33 | return val >> l;
34 | }
35 |
36 | bool has_feature(int32_t val, int32_t bit)
37 | {
38 | int32_t mask = 1 << bit;
39 | return (val & mask) != 0u;
40 |
41 | }
42 |
43 | Model getModel()
44 | {
45 | int32_t cpu_info[4];
46 | char cpustr[13] = {0};
47 |
48 | cpuid(0, 0, cpu_info);
49 | std::memcpy(cpustr, &cpu_info[1], 4);
50 | std::memcpy(cpustr+4, &cpu_info[3], 4);
51 | std::memcpy(cpustr+8, &cpu_info[2], 4);
52 |
53 | Model result;
54 |
55 | cpuid(1, 0, cpu_info);
56 |
57 | result.family = get_masked(cpu_info[0], 12, 8);
58 | result.model = get_masked(cpu_info[0], 8, 4) | get_masked(cpu_info[0], 20, 16) << 4;
59 | result.type_name = cpustr;
60 |
61 | // feature bits https://en.wikipedia.org/wiki/CPUID
62 | // sse2
63 | result.sse2 = has_feature(cpu_info[3], 26);
64 | // aes-ni
65 | result.aes = has_feature(cpu_info[2], 25);
66 | // avx
67 | result.avx = has_feature(cpu_info[2], 28);
68 |
69 | if(strcmp(cpustr, "AuthenticAMD") == 0)
70 | {
71 | if(result.family == 0xF)
72 | result.family += get_masked(cpu_info[0], 28, 20);
73 | }
74 |
75 | return result;
76 | }
77 |
78 | } // namespace cpu
79 | } // namespace xmrstak
80 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/cpuType.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 |
7 | namespace xmrstak
8 | {
9 | namespace cpu
10 | {
11 | struct Model
12 | {
13 | uint32_t family = 0u;
14 | uint32_t model = 0u;
15 | bool aes = false;
16 | bool sse2 = false;
17 | bool avx = false;
18 | std::string type_name = "unknown";
19 | };
20 |
21 | Model getModel();
22 |
23 | /** Mask bits between h and l and return the value
24 | *
25 | * This enables us to put in values exactly like in the manual
26 | * For example EBX[30:22] is get_masked(cpu_info[1], 31, 22)
27 | */
28 | int32_t get_masked(int32_t val, int32_t h, int32_t l);
29 |
30 |
31 | } // namespace cpu
32 | } // namespace xmrstak
33 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S:
--------------------------------------------------------------------------------
1 | #ifdef __APPLE__
2 | # define ALIGN(x) .align 6
3 | #else
4 | # define ALIGN(x) .align x
5 | #endif
6 | .intel_syntax noprefix
7 | #ifdef __APPLE__
8 | # define FN_PREFIX(fn) _ ## fn
9 | .text
10 | #else
11 | # define FN_PREFIX(fn) fn
12 | .section .text
13 | #endif
14 | .global FN_PREFIX(cryptonight_v8_mainloop_ivybridge_asm)
15 | .global FN_PREFIX(cryptonight_v8_mainloop_ryzen_asm)
16 | .global FN_PREFIX(cryptonight_v8_double_mainloop_sandybridge_asm)
17 |
18 | ALIGN(64)
19 | FN_PREFIX(cryptonight_v8_mainloop_ivybridge_asm):
20 | sub rsp, 48
21 | #ifdef __MINGW32__
22 | #include "cryptonight_v8_main_loop_ivybridge_win64.inc"
23 | #else
24 | mov rcx, rdi
25 | #include "cryptonight_v8_main_loop_ivybridge_linux.inc"
26 | #endif
27 | add rsp, 48
28 | ret 0
29 | mov eax, 3735929054
30 |
31 | ALIGN(64)
32 | FN_PREFIX(cryptonight_v8_mainloop_ryzen_asm):
33 | sub rsp, 48
34 | #ifdef __MINGW32__
35 | #include "cryptonight_v8_main_loop_ryzen_win64.inc"
36 | #else
37 | mov rcx, rdi
38 | #include "cryptonight_v8_main_loop_ryzen_linux.inc"
39 | #endif
40 | add rsp, 48
41 | ret 0
42 | mov eax, 3735929054
43 |
44 | ALIGN(64)
45 | FN_PREFIX(cryptonight_v8_double_mainloop_sandybridge_asm):
46 | sub rsp, 48
47 | #ifdef __MINGW32__
48 | #include "cryptonight_v8_double_main_loop_sandybridge_win64.inc"
49 | #else
50 | mov rcx, rdi
51 | mov rdx, rsi
52 | #include "cryptonight_v8_double_main_loop_sandybridge_linux.inc"
53 | #endif
54 | add rsp, 48
55 | ret 0
56 | mov eax, 3735929054
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.asm:
--------------------------------------------------------------------------------
1 | _TEXT_CNV8_MAINLOOP SEGMENT PAGE READ EXECUTE
2 | PUBLIC cryptonight_v8_mainloop_ivybridge_asm
3 | PUBLIC cryptonight_v8_mainloop_ryzen_asm
4 | PUBLIC cryptonight_v8_double_mainloop_sandybridge_asm
5 |
6 | ALIGN(64)
7 | cryptonight_v8_mainloop_ivybridge_asm PROC
8 | INCLUDE cryptonight_v8_main_loop_ivybridge_win64.inc
9 | ret 0
10 | mov eax, 3735929054
11 | cryptonight_v8_mainloop_ivybridge_asm ENDP
12 |
13 | ALIGN(64)
14 | cryptonight_v8_mainloop_ryzen_asm PROC
15 | INCLUDE cryptonight_v8_main_loop_ryzen_win64.inc
16 | ret 0
17 | mov eax, 3735929054
18 | cryptonight_v8_mainloop_ryzen_asm ENDP
19 |
20 | ALIGN(64)
21 | cryptonight_v8_double_mainloop_sandybridge_asm PROC
22 | INCLUDE cryptonight_v8_double_main_loop_sandybridge_win64.inc
23 | ret 0
24 | mov eax, 3735929054
25 | cryptonight_v8_double_mainloop_sandybridge_asm ENDP
26 |
27 | _TEXT_CNV8_MAINLOOP ENDS
28 | END
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop_ivybridge_linux.inc:
--------------------------------------------------------------------------------
1 | mov QWORD PTR [rsp+24], rbx
2 | push rbp
3 | push rsi
4 | push rdi
5 | push r12
6 | push r13
7 | push r14
8 | push r15
9 | sub rsp, 80
10 |
11 | stmxcsr DWORD PTR [rsp]
12 | mov DWORD PTR [rsp+4], 24448
13 | ldmxcsr DWORD PTR [rsp+4]
14 |
15 | mov rax, QWORD PTR [rcx+48]
16 | mov r9, rcx
17 | xor rax, QWORD PTR [rcx+16]
18 | mov esi, 524288
19 | mov r8, QWORD PTR [rcx+32]
20 | mov r13d, -2147483647
21 | xor r8, QWORD PTR [rcx]
22 | mov r11, QWORD PTR [rcx+40]
23 | mov r10, r8
24 | mov rdx, QWORD PTR [rcx+56]
25 | movq xmm4, rax
26 | xor rdx, QWORD PTR [rcx+24]
27 | xor r11, QWORD PTR [rcx+8]
28 | mov rbx, QWORD PTR [rcx+224]
29 | mov rax, QWORD PTR [r9+80]
30 | xor rax, QWORD PTR [r9+64]
31 | movq xmm0, rdx
32 | mov rcx, QWORD PTR [rcx+88]
33 | xor rcx, QWORD PTR [r9+72]
34 | movq xmm3, QWORD PTR [r9+104]
35 | movaps XMMWORD PTR [rsp+64], xmm6
36 | movaps XMMWORD PTR [rsp+48], xmm7
37 | movaps XMMWORD PTR [rsp+32], xmm8
38 | and r10d, 2097136
39 | movq xmm5, rax
40 |
41 | xor eax, eax
42 | mov QWORD PTR [rsp+16], rax
43 |
44 | mov ax, 1023
45 | shl rax, 52
46 | movq xmm8, rax
47 | mov r15, QWORD PTR [r9+96]
48 | punpcklqdq xmm4, xmm0
49 | movq xmm0, rcx
50 | punpcklqdq xmm5, xmm0
51 | movdqu xmm6, XMMWORD PTR [r10+rbx]
52 |
53 | ALIGN(64)
54 | main_loop_ivybridge:
55 | lea rdx, QWORD PTR [r10+rbx]
56 | mov ecx, r10d
57 | mov eax, r10d
58 | mov rdi, r15
59 | xor ecx, 16
60 | xor eax, 32
61 | xor r10d, 48
62 | movq xmm0, r11
63 | movq xmm7, r8
64 | punpcklqdq xmm7, xmm0
65 | aesenc xmm6, xmm7
66 | movq rbp, xmm6
67 | mov r9, rbp
68 | and r9d, 2097136
69 | movdqu xmm2, XMMWORD PTR [rcx+rbx]
70 | movdqu xmm1, XMMWORD PTR [rax+rbx]
71 | movdqu xmm0, XMMWORD PTR [r10+rbx]
72 | paddq xmm1, xmm7
73 | paddq xmm0, xmm5
74 | paddq xmm2, xmm4
75 | movdqu XMMWORD PTR [rcx+rbx], xmm0
76 | movdqu XMMWORD PTR [rax+rbx], xmm2
77 | movdqu XMMWORD PTR [r10+rbx], xmm1
78 | mov r10, r9
79 | xor r10d, 32
80 | movq rcx, xmm3
81 | mov rax, rcx
82 | shl rax, 32
83 | xor rdi, rax
84 | movdqa xmm0, xmm6
85 | pxor xmm0, xmm4
86 | movdqu XMMWORD PTR [rdx], xmm0
87 | xor rdi, QWORD PTR [r9+rbx]
88 | lea r14, QWORD PTR [r9+rbx]
89 | mov r12, QWORD PTR [r14+8]
90 | xor edx, edx
91 | lea r9d, DWORD PTR [ecx+ecx]
92 | add r9d, ebp
93 | movdqa xmm0, xmm6
94 | psrldq xmm0, 8
95 | or r9d, r13d
96 | movq rax, xmm0
97 | div r9
98 | xorps xmm3, xmm3
99 | mov eax, eax
100 | shl rdx, 32
101 | add rdx, rax
102 | lea r9, QWORD PTR [rdx+rbp]
103 | mov r15, rdx
104 | mov rax, r9
105 | shr rax, 12
106 | movq xmm0, rax
107 | paddq xmm0, xmm8
108 | sqrtsd xmm3, xmm0
109 | psubq xmm3, XMMWORD PTR [rsp+16]
110 | movq rdx, xmm3
111 | test edx, 524287
112 | je sqrt_fixup_ivybridge
113 | psrlq xmm3, 19
114 | psubq xmm3, XMMWORD PTR [rsp+16]
115 | sqrt_fixup_ivybridge_ret:
116 |
117 | mov ecx, r10d
118 | mov rax, rdi
119 | mul rbp
120 | movq xmm2, rdx
121 | xor rdx, [rcx+rbx]
122 | add r8, rdx
123 | mov QWORD PTR [r14], r8
124 | xor r8, rdi
125 | mov edi, r8d
126 | and edi, 2097136
127 | movq xmm0, rax
128 | xor rax, [rcx+rbx+8]
129 | add r11, rax
130 | mov QWORD PTR [r14+8], r11
131 | punpcklqdq xmm2, xmm0
132 |
133 | mov r9d, r10d
134 | xor r9d, 48
135 | xor r10d, 16
136 | pxor xmm2, XMMWORD PTR [r9+rbx]
137 | movdqu xmm0, XMMWORD PTR [r10+rbx]
138 | paddq xmm0, xmm5
139 | movdqu xmm1, XMMWORD PTR [rcx+rbx]
140 | paddq xmm2, xmm4
141 | paddq xmm1, xmm7
142 | movdqa xmm5, xmm4
143 | movdqu XMMWORD PTR [r9+rbx], xmm0
144 | movdqa xmm4, xmm6
145 | movdqu XMMWORD PTR [rcx+rbx], xmm2
146 | movdqu XMMWORD PTR [r10+rbx], xmm1
147 | movdqu xmm6, [rdi+rbx]
148 | mov r10d, edi
149 | xor r11, r12
150 | dec rsi
151 | jne main_loop_ivybridge
152 |
153 | ldmxcsr DWORD PTR [rsp]
154 | mov rbx, QWORD PTR [rsp+160]
155 | movaps xmm6, XMMWORD PTR [rsp+64]
156 | movaps xmm7, XMMWORD PTR [rsp+48]
157 | movaps xmm8, XMMWORD PTR [rsp+32]
158 | add rsp, 80
159 | pop r15
160 | pop r14
161 | pop r13
162 | pop r12
163 | pop rdi
164 | pop rsi
165 | pop rbp
166 | jmp cnv2_main_loop_ivybridge_endp
167 |
168 | sqrt_fixup_ivybridge:
169 | dec rdx
170 | mov r13d, -1022
171 | shl r13, 32
172 | mov rax, rdx
173 | shr rdx, 19
174 | shr rax, 20
175 | mov rcx, rdx
176 | sub rcx, rax
177 | add rax, r13
178 | not r13
179 | sub rcx, r13
180 | mov r13d, -2147483647
181 | imul rcx, rax
182 | sub rcx, r9
183 | adc rdx, 0
184 | movq xmm3, rdx
185 | jmp sqrt_fixup_ivybridge_ret
186 |
187 | cnv2_main_loop_ivybridge_endp:
188 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop_ivybridge_win64.inc:
--------------------------------------------------------------------------------
1 | mov QWORD PTR [rsp+24], rbx
2 | push rbp
3 | push rsi
4 | push rdi
5 | push r12
6 | push r13
7 | push r14
8 | push r15
9 | sub rsp, 80
10 |
11 | stmxcsr DWORD PTR [rsp]
12 | mov DWORD PTR [rsp+4], 24448
13 | ldmxcsr DWORD PTR [rsp+4]
14 |
15 | mov rax, QWORD PTR [rcx+48]
16 | mov r9, rcx
17 | xor rax, QWORD PTR [rcx+16]
18 | mov esi, 524288
19 | mov r8, QWORD PTR [rcx+32]
20 | mov r13d, -2147483647
21 | xor r8, QWORD PTR [rcx]
22 | mov r11, QWORD PTR [rcx+40]
23 | mov r10, r8
24 | mov rdx, QWORD PTR [rcx+56]
25 | movd xmm4, rax
26 | xor rdx, QWORD PTR [rcx+24]
27 | xor r11, QWORD PTR [rcx+8]
28 | mov rbx, QWORD PTR [rcx+224]
29 | mov rax, QWORD PTR [r9+80]
30 | xor rax, QWORD PTR [r9+64]
31 | movd xmm0, rdx
32 | mov rcx, QWORD PTR [rcx+88]
33 | xor rcx, QWORD PTR [r9+72]
34 | movq xmm3, QWORD PTR [r9+104]
35 | movaps XMMWORD PTR [rsp+64], xmm6
36 | movaps XMMWORD PTR [rsp+48], xmm7
37 | movaps XMMWORD PTR [rsp+32], xmm8
38 | and r10d, 2097136
39 | movd xmm5, rax
40 |
41 | xor eax, eax
42 | mov QWORD PTR [rsp+16], rax
43 |
44 | mov ax, 1023
45 | shl rax, 52
46 | movd xmm8, rax
47 | mov r15, QWORD PTR [r9+96]
48 | punpcklqdq xmm4, xmm0
49 | movd xmm0, rcx
50 | punpcklqdq xmm5, xmm0
51 | movdqu xmm6, XMMWORD PTR [r10+rbx]
52 |
53 | ALIGN(64)
54 | main_loop_ivybridge:
55 | lea rdx, QWORD PTR [r10+rbx]
56 | mov ecx, r10d
57 | mov eax, r10d
58 | mov rdi, r15
59 | xor ecx, 16
60 | xor eax, 32
61 | xor r10d, 48
62 | movd xmm0, r11
63 | movd xmm7, r8
64 | punpcklqdq xmm7, xmm0
65 | aesenc xmm6, xmm7
66 | movd rbp, xmm6
67 | mov r9, rbp
68 | and r9d, 2097136
69 | movdqu xmm2, XMMWORD PTR [rcx+rbx]
70 | movdqu xmm1, XMMWORD PTR [rax+rbx]
71 | movdqu xmm0, XMMWORD PTR [r10+rbx]
72 | paddq xmm1, xmm7
73 | paddq xmm0, xmm5
74 | paddq xmm2, xmm4
75 | movdqu XMMWORD PTR [rcx+rbx], xmm0
76 | movdqu XMMWORD PTR [rax+rbx], xmm2
77 | movdqu XMMWORD PTR [r10+rbx], xmm1
78 | mov r10, r9
79 | xor r10d, 32
80 | movd rcx, xmm3
81 | mov rax, rcx
82 | shl rax, 32
83 | xor rdi, rax
84 | movdqa xmm0, xmm6
85 | pxor xmm0, xmm4
86 | movdqu XMMWORD PTR [rdx], xmm0
87 | xor rdi, QWORD PTR [r9+rbx]
88 | lea r14, QWORD PTR [r9+rbx]
89 | mov r12, QWORD PTR [r14+8]
90 | xor edx, edx
91 | lea r9d, DWORD PTR [ecx+ecx]
92 | add r9d, ebp
93 | movdqa xmm0, xmm6
94 | psrldq xmm0, 8
95 | or r9d, r13d
96 | movd rax, xmm0
97 | div r9
98 | xorps xmm3, xmm3
99 | mov eax, eax
100 | shl rdx, 32
101 | add rdx, rax
102 | lea r9, QWORD PTR [rdx+rbp]
103 | mov r15, rdx
104 | mov rax, r9
105 | shr rax, 12
106 | movd xmm0, rax
107 | paddq xmm0, xmm8
108 | sqrtsd xmm3, xmm0
109 | psubq xmm3, XMMWORD PTR [rsp+16]
110 | movd rdx, xmm3
111 | test edx, 524287
112 | je sqrt_fixup_ivybridge
113 | psrlq xmm3, 19
114 | psubq xmm3, XMMWORD PTR [rsp+16]
115 | sqrt_fixup_ivybridge_ret:
116 |
117 | mov ecx, r10d
118 | mov rax, rdi
119 | mul rbp
120 | movd xmm2, rdx
121 | xor rdx, [rcx+rbx]
122 | add r8, rdx
123 | mov QWORD PTR [r14], r8
124 | xor r8, rdi
125 | mov edi, r8d
126 | and edi, 2097136
127 | movd xmm0, rax
128 | xor rax, [rcx+rbx+8]
129 | add r11, rax
130 | mov QWORD PTR [r14+8], r11
131 | punpcklqdq xmm2, xmm0
132 |
133 | mov r9d, r10d
134 | xor r9d, 48
135 | xor r10d, 16
136 | pxor xmm2, XMMWORD PTR [r9+rbx]
137 | movdqu xmm0, XMMWORD PTR [r10+rbx]
138 | paddq xmm0, xmm5
139 | movdqu xmm1, XMMWORD PTR [rcx+rbx]
140 | paddq xmm2, xmm4
141 | paddq xmm1, xmm7
142 | movdqa xmm5, xmm4
143 | movdqu XMMWORD PTR [r9+rbx], xmm0
144 | movdqa xmm4, xmm6
145 | movdqu XMMWORD PTR [rcx+rbx], xmm2
146 | movdqu XMMWORD PTR [r10+rbx], xmm1
147 | movdqu xmm6, [rdi+rbx]
148 | mov r10d, edi
149 | xor r11, r12
150 | dec rsi
151 | jne main_loop_ivybridge
152 |
153 | ldmxcsr DWORD PTR [rsp]
154 | mov rbx, QWORD PTR [rsp+160]
155 | movaps xmm6, XMMWORD PTR [rsp+64]
156 | movaps xmm7, XMMWORD PTR [rsp+48]
157 | movaps xmm8, XMMWORD PTR [rsp+32]
158 | add rsp, 80
159 | pop r15
160 | pop r14
161 | pop r13
162 | pop r12
163 | pop rdi
164 | pop rsi
165 | pop rbp
166 | jmp cnv2_main_loop_ivybridge_endp
167 |
168 | sqrt_fixup_ivybridge:
169 | dec rdx
170 | mov r13d, -1022
171 | shl r13, 32
172 | mov rax, rdx
173 | shr rdx, 19
174 | shr rax, 20
175 | mov rcx, rdx
176 | sub rcx, rax
177 | add rax, r13
178 | not r13
179 | sub rcx, r13
180 | mov r13d, -2147483647
181 | imul rcx, rax
182 | sub rcx, r9
183 | adc rdx, 0
184 | movd xmm3, rdx
185 | jmp sqrt_fixup_ivybridge_ret
186 |
187 | cnv2_main_loop_ivybridge_endp:
188 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop_ryzen_linux.inc:
--------------------------------------------------------------------------------
1 | mov QWORD PTR [rsp+16], rbx
2 | mov QWORD PTR [rsp+24], rbp
3 | mov QWORD PTR [rsp+32], rsi
4 | push rdi
5 | push r12
6 | push r13
7 | push r14
8 | push r15
9 | sub rsp, 64
10 |
11 | stmxcsr DWORD PTR [rsp]
12 | mov DWORD PTR [rsp+4], 24448
13 | ldmxcsr DWORD PTR [rsp+4]
14 |
15 | mov rax, QWORD PTR [rcx+48]
16 | mov r9, rcx
17 | xor rax, QWORD PTR [rcx+16]
18 | mov ebp, 524288
19 | mov r8, QWORD PTR [rcx+32]
20 | xor r8, QWORD PTR [rcx]
21 | mov r11, QWORD PTR [rcx+40]
22 | mov r10, r8
23 | mov rdx, QWORD PTR [rcx+56]
24 | movq xmm3, rax
25 | xor rdx, QWORD PTR [rcx+24]
26 | xor r11, QWORD PTR [rcx+8]
27 | mov rbx, QWORD PTR [rcx+224]
28 | mov rax, QWORD PTR [r9+80]
29 | xor rax, QWORD PTR [r9+64]
30 | movq xmm0, rdx
31 | mov rcx, QWORD PTR [rcx+88]
32 | xor rcx, QWORD PTR [r9+72]
33 | mov rdi, QWORD PTR [r9+104]
34 | and r10d, 2097136
35 | movaps XMMWORD PTR [rsp+48], xmm6
36 | movq xmm4, rax
37 | movaps XMMWORD PTR [rsp+32], xmm7
38 | movaps XMMWORD PTR [rsp+16], xmm8
39 | xorps xmm8, xmm8
40 | mov ax, 1023
41 | shl rax, 52
42 | movq xmm7, rax
43 | mov r15, QWORD PTR [r9+96]
44 | punpcklqdq xmm3, xmm0
45 | movq xmm0, rcx
46 | punpcklqdq xmm4, xmm0
47 |
48 | ALIGN(64)
49 | main_loop_ryzen:
50 | movdqa xmm5, XMMWORD PTR [r10+rbx]
51 | movq xmm0, r11
52 | movq xmm6, r8
53 | punpcklqdq xmm6, xmm0
54 | lea rdx, QWORD PTR [r10+rbx]
55 | lea r9, QWORD PTR [rdi+rdi]
56 | shl rdi, 32
57 |
58 | mov ecx, r10d
59 | mov eax, r10d
60 | xor ecx, 16
61 | xor eax, 32
62 | xor r10d, 48
63 | aesenc xmm5, xmm6
64 | movdqa xmm2, XMMWORD PTR [rcx+rbx]
65 | movdqa xmm1, XMMWORD PTR [rax+rbx]
66 | movdqa xmm0, XMMWORD PTR [r10+rbx]
67 | paddq xmm2, xmm3
68 | paddq xmm1, xmm6
69 | paddq xmm0, xmm4
70 | movdqa XMMWORD PTR [rcx+rbx], xmm0
71 | movdqa XMMWORD PTR [rax+rbx], xmm2
72 | movdqa XMMWORD PTR [r10+rbx], xmm1
73 |
74 | movaps xmm1, xmm8
75 | mov rsi, r15
76 | xor rsi, rdi
77 | movq r14, xmm5
78 | movdqa xmm0, xmm5
79 | pxor xmm0, xmm3
80 | mov r10, r14
81 | and r10d, 2097136
82 | movdqa XMMWORD PTR [rdx], xmm0
83 | xor rsi, QWORD PTR [r10+rbx]
84 | lea r12, QWORD PTR [r10+rbx]
85 | mov r13, QWORD PTR [r10+rbx+8]
86 |
87 | add r9d, r14d
88 | or r9d, -2147483647
89 | xor edx, edx
90 | movdqa xmm0, xmm5
91 | psrldq xmm0, 8
92 | movq rax, xmm0
93 |
94 | div r9
95 | movq xmm0, rax
96 | movq xmm1, rdx
97 | punpckldq xmm0, xmm1
98 | movq r15, xmm0
99 | paddq xmm0, xmm5
100 | movdqa xmm2, xmm0
101 | psrlq xmm0, 12
102 | paddq xmm0, xmm7
103 | sqrtsd xmm1, xmm0
104 | movq rdi, xmm1
105 | test rdi, 524287
106 | je sqrt_fixup_ryzen
107 | shr rdi, 19
108 |
109 | sqrt_fixup_ryzen_ret:
110 | mov rax, rsi
111 | mul r14
112 | movq xmm1, rax
113 | movq xmm0, rdx
114 | punpcklqdq xmm0, xmm1
115 |
116 | mov r9d, r10d
117 | mov ecx, r10d
118 | xor r9d, 16
119 | xor ecx, 32
120 | xor r10d, 48
121 | movdqa xmm1, XMMWORD PTR [rcx+rbx]
122 | xor rdx, [rcx+rbx]
123 | xor rax, [rcx+rbx+8]
124 | movdqa xmm2, XMMWORD PTR [r9+rbx]
125 | pxor xmm2, xmm0
126 | paddq xmm4, XMMWORD PTR [r10+rbx]
127 | paddq xmm2, xmm3
128 | paddq xmm1, xmm6
129 | movdqa XMMWORD PTR [r9+rbx], xmm4
130 | movdqa XMMWORD PTR [rcx+rbx], xmm2
131 | movdqa XMMWORD PTR [r10+rbx], xmm1
132 |
133 | movdqa xmm4, xmm3
134 | add r8, rdx
135 | add r11, rax
136 | mov QWORD PTR [r12], r8
137 | xor r8, rsi
138 | mov QWORD PTR [r12+8], r11
139 | mov r10, r8
140 | xor r11, r13
141 | and r10d, 2097136
142 | movdqa xmm3, xmm5
143 | dec ebp
144 | jne main_loop_ryzen
145 |
146 | ldmxcsr DWORD PTR [rsp]
147 | movaps xmm6, XMMWORD PTR [rsp+48]
148 | lea r11, QWORD PTR [rsp+64]
149 | mov rbx, QWORD PTR [r11+56]
150 | mov rbp, QWORD PTR [r11+64]
151 | mov rsi, QWORD PTR [r11+72]
152 | movaps xmm8, XMMWORD PTR [r11-48]
153 | movaps xmm7, XMMWORD PTR [rsp+32]
154 | mov rsp, r11
155 | pop r15
156 | pop r14
157 | pop r13
158 | pop r12
159 | pop rdi
160 | jmp cnv2_main_loop_ryzen_endp
161 |
162 | sqrt_fixup_ryzen:
163 | movq r9, xmm2
164 | dec rdi
165 | mov edx, -1022
166 | shl rdx, 32
167 | mov rax, rdi
168 | shr rdi, 19
169 | shr rax, 20
170 | mov rcx, rdi
171 | sub rcx, rax
172 | lea rcx, [rcx+rdx+1]
173 | add rax, rdx
174 | imul rcx, rax
175 | sub rcx, r9
176 | adc rdi, 0
177 | jmp sqrt_fixup_ryzen_ret
178 |
179 | cnv2_main_loop_ryzen_endp:
180 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop_ryzen_win64.inc:
--------------------------------------------------------------------------------
1 | mov QWORD PTR [rsp+16], rbx
2 | mov QWORD PTR [rsp+24], rbp
3 | mov QWORD PTR [rsp+32], rsi
4 | push rdi
5 | push r12
6 | push r13
7 | push r14
8 | push r15
9 | sub rsp, 64
10 |
11 | stmxcsr DWORD PTR [rsp]
12 | mov DWORD PTR [rsp+4], 24448
13 | ldmxcsr DWORD PTR [rsp+4]
14 |
15 | mov rax, QWORD PTR [rcx+48]
16 | mov r9, rcx
17 | xor rax, QWORD PTR [rcx+16]
18 | mov ebp, 524288
19 | mov r8, QWORD PTR [rcx+32]
20 | xor r8, QWORD PTR [rcx]
21 | mov r11, QWORD PTR [rcx+40]
22 | mov r10, r8
23 | mov rdx, QWORD PTR [rcx+56]
24 | movd xmm3, rax
25 | xor rdx, QWORD PTR [rcx+24]
26 | xor r11, QWORD PTR [rcx+8]
27 | mov rbx, QWORD PTR [rcx+224]
28 | mov rax, QWORD PTR [r9+80]
29 | xor rax, QWORD PTR [r9+64]
30 | movd xmm0, rdx
31 | mov rcx, QWORD PTR [rcx+88]
32 | xor rcx, QWORD PTR [r9+72]
33 | mov rdi, QWORD PTR [r9+104]
34 | and r10d, 2097136
35 | movaps XMMWORD PTR [rsp+48], xmm6
36 | movd xmm4, rax
37 | movaps XMMWORD PTR [rsp+32], xmm7
38 | movaps XMMWORD PTR [rsp+16], xmm8
39 | xorps xmm8, xmm8
40 | mov ax, 1023
41 | shl rax, 52
42 | movd xmm7, rax
43 | mov r15, QWORD PTR [r9+96]
44 | punpcklqdq xmm3, xmm0
45 | movd xmm0, rcx
46 | punpcklqdq xmm4, xmm0
47 |
48 | ALIGN(64)
49 | main_loop_ryzen:
50 | movdqa xmm5, XMMWORD PTR [r10+rbx]
51 | movd xmm0, r11
52 | movd xmm6, r8
53 | punpcklqdq xmm6, xmm0
54 | lea rdx, QWORD PTR [r10+rbx]
55 | lea r9, QWORD PTR [rdi+rdi]
56 | shl rdi, 32
57 |
58 | mov ecx, r10d
59 | mov eax, r10d
60 | xor ecx, 16
61 | xor eax, 32
62 | xor r10d, 48
63 | aesenc xmm5, xmm6
64 | movdqa xmm2, XMMWORD PTR [rcx+rbx]
65 | movdqa xmm1, XMMWORD PTR [rax+rbx]
66 | movdqa xmm0, XMMWORD PTR [r10+rbx]
67 | paddq xmm2, xmm3
68 | paddq xmm1, xmm6
69 | paddq xmm0, xmm4
70 | movdqa XMMWORD PTR [rcx+rbx], xmm0
71 | movdqa XMMWORD PTR [rax+rbx], xmm2
72 | movdqa XMMWORD PTR [r10+rbx], xmm1
73 |
74 | movaps xmm1, xmm8
75 | mov rsi, r15
76 | xor rsi, rdi
77 | movd r14, xmm5
78 | movdqa xmm0, xmm5
79 | pxor xmm0, xmm3
80 | mov r10, r14
81 | and r10d, 2097136
82 | movdqa XMMWORD PTR [rdx], xmm0
83 | xor rsi, QWORD PTR [r10+rbx]
84 | lea r12, QWORD PTR [r10+rbx]
85 | mov r13, QWORD PTR [r10+rbx+8]
86 |
87 | add r9d, r14d
88 | or r9d, -2147483647
89 | xor edx, edx
90 | movdqa xmm0, xmm5
91 | psrldq xmm0, 8
92 | movd rax, xmm0
93 |
94 | div r9
95 | movd xmm0, rax
96 | movd xmm1, rdx
97 | punpckldq xmm0, xmm1
98 | movd r15, xmm0
99 | paddq xmm0, xmm5
100 | movdqa xmm2, xmm0
101 | psrlq xmm0, 12
102 | paddq xmm0, xmm7
103 | sqrtsd xmm1, xmm0
104 | movd rdi, xmm1
105 | test rdi, 524287
106 | je sqrt_fixup_ryzen
107 | shr rdi, 19
108 |
109 | sqrt_fixup_ryzen_ret:
110 | mov rax, rsi
111 | mul r14
112 | movd xmm1, rax
113 | movd xmm0, rdx
114 | punpcklqdq xmm0, xmm1
115 |
116 | mov r9d, r10d
117 | mov ecx, r10d
118 | xor r9d, 16
119 | xor ecx, 32
120 | xor r10d, 48
121 | movdqa xmm1, XMMWORD PTR [rcx+rbx]
122 | xor rdx, [rcx+rbx]
123 | xor rax, [rcx+rbx+8]
124 | movdqa xmm2, XMMWORD PTR [r9+rbx]
125 | pxor xmm2, xmm0
126 | paddq xmm4, XMMWORD PTR [r10+rbx]
127 | paddq xmm2, xmm3
128 | paddq xmm1, xmm6
129 | movdqa XMMWORD PTR [r9+rbx], xmm4
130 | movdqa XMMWORD PTR [rcx+rbx], xmm2
131 | movdqa XMMWORD PTR [r10+rbx], xmm1
132 |
133 | movdqa xmm4, xmm3
134 | add r8, rdx
135 | add r11, rax
136 | mov QWORD PTR [r12], r8
137 | xor r8, rsi
138 | mov QWORD PTR [r12+8], r11
139 | mov r10, r8
140 | xor r11, r13
141 | and r10d, 2097136
142 | movdqa xmm3, xmm5
143 | dec ebp
144 | jne main_loop_ryzen
145 |
146 | ldmxcsr DWORD PTR [rsp]
147 | movaps xmm6, XMMWORD PTR [rsp+48]
148 | lea r11, QWORD PTR [rsp+64]
149 | mov rbx, QWORD PTR [r11+56]
150 | mov rbp, QWORD PTR [r11+64]
151 | mov rsi, QWORD PTR [r11+72]
152 | movaps xmm8, XMMWORD PTR [r11-48]
153 | movaps xmm7, XMMWORD PTR [rsp+32]
154 | mov rsp, r11
155 | pop r15
156 | pop r14
157 | pop r13
158 | pop r12
159 | pop rdi
160 | jmp cnv2_main_loop_ryzen_endp
161 |
162 | sqrt_fixup_ryzen:
163 | movd r9, xmm2
164 | dec rdi
165 | mov edx, -1022
166 | shl rdx, 32
167 | mov rax, rdi
168 | shr rdi, 19
169 | shr rax, 20
170 | mov rcx, rdi
171 | sub rcx, rax
172 | lea rcx, [rcx+rdx+1]
173 | add rax, rdx
174 | imul rcx, rax
175 | sub rcx, r9
176 | adc rdi, 0
177 | jmp sqrt_fixup_ryzen_ret
178 |
179 | cnv2_main_loop_ryzen_endp:
180 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/c_blake256.h:
--------------------------------------------------------------------------------
1 | #ifndef _BLAKE256_H_
2 | #define _BLAKE256_H_
3 |
4 | #include
5 |
6 | typedef struct {
7 | uint32_t h[8], s[4], t[2];
8 | int buflen, nullt;
9 | uint8_t buf[64];
10 | } state;
11 |
12 | typedef struct {
13 | state inner;
14 | state outer;
15 | } hmac_state;
16 |
17 | void blake256_init(state *);
18 | void blake224_init(state *);
19 |
20 | void blake256_update(state *, const uint8_t *, uint64_t);
21 | void blake224_update(state *, const uint8_t *, uint64_t);
22 |
23 | void blake256_final(state *, uint8_t *);
24 | void blake224_final(state *, uint8_t *);
25 |
26 | void blake256_hash(uint8_t *, const uint8_t *, uint64_t);
27 | void blake224_hash(uint8_t *, const uint8_t *, uint64_t);
28 |
29 | /* HMAC functions: */
30 |
31 | void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t);
32 | void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t);
33 |
34 | void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t);
35 | void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t);
36 |
37 | void hmac_blake256_final(hmac_state *, uint8_t *);
38 | void hmac_blake224_final(hmac_state *, uint8_t *);
39 |
40 | void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t);
41 | void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t);
42 |
43 | #endif /* _BLAKE256_H_ */
44 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/c_skein.h:
--------------------------------------------------------------------------------
1 | #ifndef _SKEIN_H_
2 | #define _SKEIN_H_ 1
3 | /**************************************************************************
4 | **
5 | ** Interface declarations and internal definitions for Skein hashing.
6 | **
7 | ** Source code author: Doug Whiting, 2008.
8 | **
9 | ** This algorithm and source code is released to the public domain.
10 | **
11 | ***************************************************************************
12 | **
13 | ** The following compile-time switches may be defined to control some
14 | ** tradeoffs between speed, code size, error checking, and security.
15 | **
16 | ** The "default" note explains what happens when the switch is not defined.
17 | **
18 | ** SKEIN_DEBUG -- make callouts from inside Skein code
19 | ** to examine/display intermediate values.
20 | ** [default: no callouts (no overhead)]
21 | **
22 | ** SKEIN_ERR_CHECK -- how error checking is handled inside Skein
23 | ** code. If not defined, most error checking
24 | ** is disabled (for performance). Otherwise,
25 | ** the switch value is interpreted as:
26 | ** 0: use assert() to flag errors
27 | ** 1: return SKEIN_FAIL to flag errors
28 | **
29 | ***************************************************************************/
30 | #include "skein_port.h" /* get platform-specific definitions */
31 |
32 | typedef enum
33 | {
34 | SKEIN_SUCCESS = 0, /* return codes from Skein calls */
35 | SKEIN_FAIL = 1,
36 | SKEIN_BAD_HASHLEN = 2
37 | }
38 | SkeinHashReturn;
39 |
40 | typedef size_t SkeinDataLength; /* bit count type */
41 | typedef u08b_t SkeinBitSequence; /* bit stream type */
42 |
43 | /* "all-in-one" call */
44 | SkeinHashReturn skein_hash(int hashbitlen, const SkeinBitSequence *data,
45 | SkeinDataLength databitlen, SkeinBitSequence *hashval);
46 |
47 | void xmr_skein(const SkeinBitSequence *data, SkeinBitSequence *hashval);
48 |
49 | #endif /* ifndef _SKEIN_H_ */
50 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/cn_gpu.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/backend/cryptonight.hpp"
4 | #include
5 |
6 | #if defined(_WIN32) || defined(_WIN64)
7 | #include
8 | #include
9 | #define HAS_WIN_INTRIN_API
10 | #endif
11 |
12 | #ifdef __GNUC__
13 | #include
14 | #if !defined(HAS_WIN_INTRIN_API)
15 | #include
16 | #endif // !defined(HAS_WIN_INTRIN_API)
17 | #endif // __GNUC__
18 |
19 | inline void cngpu_cpuid(uint32_t eax, int32_t ecx, int32_t val[4])
20 | {
21 | val[0] = 0;
22 | val[1] = 0;
23 | val[2] = 0;
24 | val[3] = 0;
25 |
26 | #if defined(HAS_WIN_INTRIN_API)
27 | __cpuidex(val, eax, ecx);
28 | #else
29 | __cpuid_count(eax, ecx, val[0], val[1], val[2], val[3]);
30 | #endif
31 | }
32 |
33 | inline bool cngpu_check_avx2()
34 | {
35 | int32_t cpu_info[4];
36 | cngpu_cpuid(7, 0, cpu_info);
37 | return (cpu_info[1] & (1 << 5)) != 0;
38 | }
39 |
40 | void cn_gpu_inner_avx(const uint8_t* spad, uint8_t* lpad, const xmrstak_algo& algo);
41 |
42 | void cn_gpu_inner_ssse3(const uint8_t* spad, uint8_t* lpad, const xmrstak_algo& algo);
43 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/cryptonight.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../common.h"
3 | #include
4 | #include
5 |
6 | #if defined(__GNUC__)
7 | # if defined(_WIN64)
8 | # include
9 | # else
10 | # include
11 | # define _umul128 _xmr_umul128
12 | # endif
13 | #else
14 | # include
15 | #endif // __GNUC__
16 |
17 | #include "variant4_random_math.h"
18 |
19 | #if defined _MSC_VER
20 | #define ABI_ATTRIBUTE
21 | #else
22 | #define ABI_ATTRIBUTE __attribute__((ms_abi))
23 | #endif
24 |
25 | struct cryptonight_ctx;
26 |
27 | typedef void (*cn_mainloop_fun)(cryptonight_ctx *ctx);
28 | typedef void (*cn_double_mainloop_fun)(cryptonight_ctx*, cryptonight_ctx*);
29 | typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx**, const xmrstak_algo&);
30 |
31 | void v4_compile_code(size_t N, cryptonight_ctx* ctx, int code_size);
32 | void v4_soft_aes_compile_code(size_t N, cryptonight_ctx* ctx, int code_size);
33 |
34 | struct extra_ctx_r
35 | {
36 | uint64_t height = 0;
37 | // the buffer must be able to hold NUM_INSTRUCTIONS_MAX and a termination instruction
38 | V4_Instruction code[NUM_INSTRUCTIONS_MAX + 1];
39 | };
40 |
41 | struct cryptonight_ctx
42 | {
43 | uint8_t hash_state[224]; // Need only 200, explicit align
44 | uint8_t* long_state = nullptr;
45 | uint8_t ctx_info[40]; //Use some of the extra memory for flags (0=hugepages, 1=mlocked)
46 | const uint32_t* saes_table = nullptr;
47 | cn_mainloop_fun loop_fn = nullptr;
48 | cn_hash_fun hash_fn = nullptr;
49 | uint8_t* fun_data = nullptr;
50 | int asm_version = 0;
51 | xmrstak_algo last_algo = invalid_algo;
52 |
53 | union
54 | {
55 | extra_ctx_r cn_r_ctx;
56 | };
57 | } ALIGN(64);
58 |
59 | struct alloc_msg
60 | {
61 | const char* warning;
62 | };
63 |
64 | size_t cryptonight_init(size_t use_fast_mem, size_t use_mlock, alloc_msg* msg);
65 | cryptonight_ctx* cryptonight_alloc_ctx(size_t use_fast_mem, size_t use_mlock, alloc_msg* msg);
66 | void cryptonight_free_ctx(cryptonight_ctx* ctx);
67 |
68 | void* allocateExecutableMemory(size_t size);
69 | void protectExecutableMemory(void *p, size_t size);
70 | void unprotectExecutableMemory(void *p, size_t size);
71 | void flushInstructionCache(void *p, size_t size);
72 |
73 | extern void(*const extra_hashes[4])(const void *, char *);
74 | extern "C" void cryptonight_v8_mainloop_ivybridge_asm(cryptonight_ctx* ctx0);
75 | extern "C" void cryptonight_v8_mainloop_ryzen_asm(cryptonight_ctx* ctx0);
76 | extern "C" void cryptonight_v8_double_mainloop_sandybridge_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1);
77 |
78 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/cryptonight_gpu_p.hpp:
--------------------------------------------------------------------------------
1 | #include "cn_gpu.hpp"
2 |
3 | template
4 | void cn_explode_scratchpad_gpu(const uint8_t* input, uint8_t* output, const xmrstak_algo& algo)
5 | {
6 | constexpr size_t hash_size = 200; // 25x8 bytes
7 | ALIGN(16) uint64_t hash[25];
8 | const size_t mem = algo.Mem();
9 |
10 | for (uint64_t i = 0; i < mem / 512; i++)
11 | {
12 | memcpy(hash, input, hash_size);
13 | hash[0] ^= i;
14 |
15 | keccakf_24(hash);
16 | memcpy(output, hash, 160);
17 | output+=160;
18 |
19 | keccakf_24(hash);
20 | memcpy(output, hash, 176);
21 | output+=176;
22 |
23 | keccakf_24(hash);
24 | memcpy(output, hash, 176);
25 | output+=176;
26 |
27 | if(PREFETCH)
28 | {
29 | _mm_prefetch((const char*)output - 512, _MM_HINT_T2);
30 | _mm_prefetch((const char*)output - 384, _MM_HINT_T2);
31 | _mm_prefetch((const char*)output - 256, _MM_HINT_T2);
32 | _mm_prefetch((const char*)output - 128, _MM_HINT_T2);
33 | }
34 | }
35 | }
36 |
37 | struct Cryptonight_hash_gpu
38 | {
39 | static constexpr size_t N = 1;
40 |
41 | template
42 | static void hash(const void* input, size_t len, void* output, cryptonight_ctx** ctx, const xmrstak_algo& algo)
43 | {
44 | set_float_rounding_mode_nearest();
45 | keccak_200((const uint8_t *)input, len, ctx[0]->hash_state);
46 | cn_explode_scratchpad_gpu(ctx[0]->hash_state, ctx[0]->long_state, algo);
47 |
48 | if(cngpu_check_avx2())
49 | cn_gpu_inner_avx(ctx[0]->hash_state, ctx[0]->long_state, algo);
50 | else
51 | cn_gpu_inner_ssse3(ctx[0]->hash_state, ctx[0]->long_state, algo);
52 |
53 | if(SOFT_AES)
54 | cn_implode_scratchpad((__m128i*)ctx[0]->long_state, (__m128i*)ctx[0]->hash_state, algo);
55 | else
56 | soft_cn_implode_scratchpad((__m128i*)ctx[0]->long_state, (__m128i*)ctx[0]->hash_state, algo);
57 | keccakf_24((uint64_t*)ctx[0]->hash_state);
58 | memcpy(output, ctx[0]->hash_state, 32);
59 | }
60 | };
61 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/extrahashes_p.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU General Public License
13 | * along with this program. If not, see .
14 | *
15 | * Additional permission under GNU GPL version 3 section 7
16 | *
17 | * If you modify this Program, or any covered work, by linking or combining
18 | * it with OpenSSL (or a modified version of that library), containing parts
19 | * covered by the terms of OpenSSL License and SSLeay License, the licensors
20 | * of this Program grant you additional permission to convey the resulting work.
21 | *
22 | */
23 |
24 | extern "C"
25 | {
26 | #include "c_blake256.h"
27 | #include "c_skein.h"
28 | }
29 | #include "groestl.hpp"
30 | #include "jh.hpp"
31 |
32 | void do_blake_hash(const void* input, char* output) {
33 | blake256_hash((uint8_t*)output, (const uint8_t*)input, 200);
34 | }
35 |
36 | void do_groestl_hash(const void* input, char* output) {
37 | xmr_groestl((const uint8_t*)input, (uint8_t*)output);
38 | }
39 |
40 | void do_jh_hash(const void* input, char* output) {
41 | xmr_jh256((const uint8_t*)input, (uint8_t*)output);
42 | }
43 |
44 | void do_skein_hash(const void* input, char* output) {
45 | xmr_skein((const uint8_t*)input, (uint8_t*)output);
46 | }
47 |
48 | void (* const extra_hashes[4])(const void *, char *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
49 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/groestl.hpp:
--------------------------------------------------------------------------------
1 | #ifndef __hash_h
2 | #define __hash_h
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | /* some sizes (number of bytes) */
10 | #define ROWS 8
11 | #define LENGTHFIELDLEN ROWS
12 | #define COLS512 8
13 | #define SIZE512 (ROWS*COLS512)
14 |
15 | #define ROUNDS512 10
16 | #define HASH_BIT_LEN 256
17 |
18 | #define ROTL64(a,n) __rolq(a,n)
19 |
20 | #define EXT_BYTE(var,n) ((uint8_t)((uint64_t)(var) >> (8*n)))
21 | #define U64BIG(a) \
22 | ((ROTL64(a, 8) & (0x000000FF000000FFULL)) | \
23 | (ROTL64(a,24) & (0x0000FF000000FF00ULL)) | \
24 | (ROTL64(a,40) & (0x00FF000000FF0000ULL)) | \
25 | (ROTL64(a,56) & (0xFF000000FF000000ULL)))
26 |
27 |
28 | typedef unsigned char BitSequence;
29 | void xmr_groestl(const BitSequence* input, BitSequence* output);
30 |
31 | #endif /* __hash_h */
32 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/hash.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | typedef unsigned char BitSequence;
6 | typedef uint32_t DataLength;
7 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/jh.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | void xmr_jh256(const BitSequence *data, BitSequence *hashval);
4 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/keccak.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../common.h"
3 |
4 | // update the state
5 | void keccakf_24(uint64_t st[25]);
6 |
7 | // compute a keccak hash (md) of given byte length from "in"
8 | void keccak_200(const uint8_t *in, int inlen, uint8_t *md);
9 |
10 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/crypto/soft_aes.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU General Public License
13 | * along with this program. If not, see .
14 | *
15 | * Additional permission under GNU GPL version 3 section 7
16 | *
17 | * If you modify this Program, or any covered work, by linking or combining
18 | * it with OpenSSL (or a modified version of that library), containing parts
19 | * covered by the terms of OpenSSL License and SSLeay License, the licensors
20 | * of this Program grant you additional permission to convey the resulting work.
21 | *
22 | */
23 |
24 | /*
25 | * Parts of this file are originally copyright (c) 2014-2017, The Monero Project
26 | */
27 | #pragma once
28 |
29 | #ifdef __GNUC__
30 | # ifdef _WIN64
31 | # include
32 | # else
33 | # include
34 | # endif
35 | #else
36 | # include
37 | #endif // __GNUC__
38 |
39 | #include
40 |
41 | #define TABLE_ALIGN 64
42 |
43 | #define saes_data(w) {\
44 | w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
45 | w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
46 | w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
47 | w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
48 | w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
49 | w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
50 | w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
51 | w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
52 | w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
53 | w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
54 | w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
55 | w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
56 | w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
57 | w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
58 | w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
59 | w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
60 | w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
61 | w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
62 | w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
63 | w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
64 | w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
65 | w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
66 | w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
67 | w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
68 | w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
69 | w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
70 | w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
71 | w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
72 | w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
73 | w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
74 | w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
75 | w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
76 |
77 | #define SAES_WPOLY 0x011b
78 | #define to_byte(x) ((x) & 0xff)
79 | #define bval(x,n) to_byte((x) >> (8 * (n)))
80 |
81 | #define saes_b2w(b0, b1, b2, b3) (((uint32_t)(b3) << 24) | \
82 | ((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0))
83 |
84 | #define saes_f2(x) ((x<<1) ^ (((x>>7) & 1) * SAES_WPOLY))
85 | #define saes_f3(x) (saes_f2(x) ^ x)
86 | #define saes_h0(x) (x)
87 |
88 | #define saes_u0(p) saes_b2w( saes_f2(p), p, p, saes_f3(p))
89 | #define saes_u1(p) saes_b2w( saes_f3(p), saes_f2(p), p, p)
90 | #define saes_u2(p) saes_b2w( p, saes_f3(p), saes_f2(p), p)
91 | #define saes_u3(p) saes_b2w( p, p, saes_f3(p), saes_f2(p))
92 |
93 | alignas(TABLE_ALIGN) const uint32_t saes_table[4][256] = { saes_data(saes_u0), saes_data(saes_u1), saes_data(saes_u2), saes_data(saes_u3) };
94 | alignas(TABLE_ALIGN) const uint8_t saes_sbox[256] = saes_data(saes_h0);
95 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/hwlocMemory.cpp:
--------------------------------------------------------------------------------
1 | #include "xmrstak/backend/cpu/hwlocMemory.hpp"
2 |
3 | #ifndef CONF_NO_HWLOC
4 |
5 | #include "xmrstak/misc/console.hpp"
6 | #include "xmrstak/cli/colors.hpp"
7 |
8 | #include
9 |
10 | /** pin memory to NUMA node
11 | *
12 | * Set the default memory policy for the current thread to bind memory to the
13 | * NUMA node.
14 | *
15 | * @param puId core id
16 | */
17 | void bindMemoryToNUMANode( size_t puId )
18 | {
19 | int depth;
20 | hwloc_topology_t topology;
21 |
22 | hwloc_topology_init(&topology);
23 | hwloc_topology_load(topology);
24 |
25 | if(!hwloc_topology_get_support(topology)->membind->set_thisthread_membind)
26 | {
27 | #ifdef EXTRAWARNINGS
28 | printer::inst()->print_msg(L0, YELLOW("hwloc: set_thisthread_membind not supported"));
29 | #endif
30 | hwloc_topology_destroy(topology);
31 | return;
32 | }
33 |
34 | depth = hwloc_get_type_depth(topology, HWLOC_OBJ_PU);
35 |
36 | for( uint32_t i = 0;
37 | i < hwloc_get_nbobjs_by_depth(topology, depth);
38 | i++ )
39 | {
40 | hwloc_obj_t pu = hwloc_get_obj_by_depth(topology, depth, i);
41 | if( pu->os_index == puId )
42 | {
43 | if( 0 > hwloc_set_membind_nodeset(
44 | topology,
45 | pu->nodeset,
46 | HWLOC_MEMBIND_BIND,
47 | HWLOC_MEMBIND_THREAD))
48 | {
49 | #ifdef EXTRAWARNINGS
50 | printer::inst()->print_msg(L0, YELLOW("hwloc: can't bind memory, continuing"));
51 | #endif
52 | }
53 | else
54 | {
55 | printer::inst()->print_msg(L0, GREEN("hwloc: memory pinned to NUMA mode"));
56 | break;
57 | }
58 | }
59 | }
60 |
61 | hwloc_topology_destroy(topology);
62 | }
63 | #else
64 |
65 | void bindMemoryToNUMANode( size_t )
66 | {
67 | }
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/hwlocMemory.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | /** pin memory to NUMA node
6 | *
7 | * Set the default memory policy for the current thread to bind memory to the
8 | * NUMA node.
9 | *
10 | * @param puId core id
11 | */
12 | void bindMemoryToNUMANode( size_t puId );
13 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/jconf.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/params.hpp"
4 |
5 | #include
6 | #include
7 |
8 | namespace xmrstak
9 | {
10 | namespace cpu
11 | {
12 |
13 | class jconf
14 | {
15 | public:
16 | static jconf* inst()
17 | {
18 | if (oInst == nullptr) oInst = new jconf;
19 | return oInst;
20 | };
21 |
22 | bool parse_config(const char* sFilename = params::inst().configFileCPU.c_str());
23 |
24 | struct thd_cfg {
25 | int iMultiway;
26 | bool bPrefetch;
27 | std::string asm_version_str;
28 | long long iCpuAff;
29 | };
30 |
31 | size_t GetThreadCount();
32 | bool GetThreadConfig(size_t id, thd_cfg &cfg);
33 | bool NeedsAutoconf();
34 |
35 | private:
36 | jconf();
37 | static jconf* oInst;
38 |
39 | struct opaque_private;
40 | opaque_private* prv;
41 | };
42 |
43 | } // namespace cpu
44 | } // namespace xmrstak
45 |
--------------------------------------------------------------------------------
/xmrstak/backend/cpu/minethd.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/jconf.hpp"
4 | #include "crypto/cryptonight.hpp"
5 | #include "xmrstak/backend/miner_work.hpp"
6 | #include "xmrstak/backend/iBackend.hpp"
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 |
15 | namespace xmrstak
16 | {
17 | namespace cpu
18 | {
19 | std::string getAsmName(const uint32_t num_hashes);
20 |
21 |
22 | class minethd : public iBackend
23 | {
24 | public:
25 | static std::vector thread_starter(uint32_t threadOffset, miner_work& pWork);
26 | static bool self_test();
27 |
28 | typedef void (*cn_on_new_job)(const miner_work&, cryptonight_ctx**);
29 |
30 | static void func_selector(cryptonight_ctx**, bool bHaveAes, bool bPrefetch, const xmrstak_algo& algo);
31 | static bool thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id);
32 |
33 | static cryptonight_ctx* minethd_alloc_ctx();
34 |
35 | template
36 | static void func_multi_selector(cryptonight_ctx**, minethd::cn_on_new_job& on_new_job, bool bHaveAes, bool bPrefetch, const xmrstak_algo& algo, const std::string& asm_version_str = "off");
37 |
38 | private:
39 | template
40 | static bool testrunner(const xmrstak_algo& algo, cryptonight_ctx **ctx, const std::string& selected_asm);
41 |
42 | minethd(miner_work& pWork, size_t iNo, int iMultiway, bool prefetch, int64_t affinity, const std::string& asm_version);
43 |
44 | template
45 | void multiway_work_main();
46 |
47 | template
48 | void prep_multiway_work(uint8_t *bWorkBlob, uint32_t **piNonce);
49 |
50 | void work_main();
51 | void double_work_main();
52 | void triple_work_main();
53 | void quad_work_main();
54 | void penta_work_main();
55 |
56 | uint64_t iJobNo;
57 |
58 | miner_work oWork;
59 |
60 | std::promise order_fix;
61 | std::mutex thd_aff_set;
62 |
63 | std::thread oWorkThd;
64 | int64_t affinity;
65 |
66 | bool bQuit;
67 | bool bPrefetch;
68 |
69 | std::string asm_version_str = "off";
70 | };
71 |
72 | } // namespace cpu
73 | } // namespace xmrstak
74 |
--------------------------------------------------------------------------------
/xmrstak/backend/globalStates.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU General Public License
13 | * along with this program. If not, see .
14 | *
15 | * Additional permission under GNU GPL version 3 section 7
16 | *
17 | * If you modify this Program, or any covered work, by linking or combining
18 | * it with OpenSSL (or a modified version of that library), containing parts
19 | * covered by the terms of OpenSSL License and SSLeay License, the licensors
20 | * of this Program grant you additional permission to convey the resulting work.
21 | *
22 | */
23 |
24 | #include "miner_work.hpp"
25 | #include "globalStates.hpp"
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 |
33 | namespace xmrstak
34 | {
35 |
36 | void globalStates::consume_work(miner_work& threadWork, uint64_t& currentJobId)
37 | {
38 | jobLock.ReadLock();
39 |
40 | threadWork = oGlobalWork;
41 | currentJobId = iGlobalJobNo.load(std::memory_order_relaxed);
42 |
43 | jobLock.UnLock();
44 | }
45 |
46 | void globalStates::switch_work(miner_work&& pWork, pool_data& dat)
47 | {
48 | jobLock.WriteLock();
49 |
50 | /* This notifies all threads that the job has changed.
51 | * To avoid duplicated shared this must be done before the nonce is exchanged.
52 | */
53 | iGlobalJobNo++;
54 |
55 | size_t xid = dat.pool_id;
56 | dat.pool_id = pool_id;
57 | pool_id = xid;
58 |
59 | /* Maybe a worker thread is updating the nonce while we read it.
60 | * To avoid duplicated share calculations the job ID is checked in the worker thread
61 | * after the nonce is read.
62 | */
63 | dat.iSavedNonce = iGlobalNonce.exchange(dat.iSavedNonce, std::memory_order_relaxed);
64 | oGlobalWork = std::move(pWork);
65 |
66 | jobLock.UnLock();
67 | }
68 |
69 | } // namespace xmrstak
70 |
--------------------------------------------------------------------------------
/xmrstak/backend/globalStates.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/backend/miner_work.hpp"
4 | #include "xmrstak/misc/environment.hpp"
5 | #include "xmrstak/misc/console.hpp"
6 | #include "xmrstak/backend/pool_data.hpp"
7 | #include "xmrstak/cpputil/read_write_lock.h"
8 |
9 | #include
10 |
11 | namespace xmrstak
12 | {
13 |
14 | struct globalStates
15 | {
16 | static inline globalStates& inst()
17 | {
18 | auto& env = environment::inst();
19 | if(env.pglobalStates == nullptr)
20 | env.pglobalStates = new globalStates;
21 | return *env.pglobalStates;
22 | }
23 |
24 | //pool_data is in-out winapi style
25 | void switch_work(miner_work&& pWork, pool_data& dat);
26 |
27 | inline void calc_start_nonce(uint32_t& nonce, bool use_nicehash, uint32_t reserve_count)
28 | {
29 | if(use_nicehash)
30 | nonce = (nonce & 0xFF000000) | iGlobalNonce.fetch_add(reserve_count);
31 | else
32 | nonce = iGlobalNonce.fetch_add(reserve_count);
33 | }
34 |
35 | void consume_work( miner_work& threadWork, uint64_t& currentJobId);
36 |
37 | miner_work oGlobalWork;
38 | std::atomic iGlobalJobNo;
39 | std::atomic iConsumeCnt;
40 | std::atomic iGlobalNonce;
41 | uint64_t iThreadCount;
42 | size_t pool_id = invalid_pool_id;
43 |
44 | private:
45 | globalStates() : iGlobalJobNo(0), iConsumeCnt(0), iThreadCount(0)
46 | {
47 | }
48 |
49 | ::cpputil::RWLock jobLock;
50 | };
51 |
52 | } // namespace xmrstak
53 |
--------------------------------------------------------------------------------
/xmrstak/backend/iBackend.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/backend/globalStates.hpp"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | template
12 | constexpr std::size_t countof(T const (&)[N]) noexcept
13 | {
14 | return N;
15 | }
16 |
17 | namespace xmrstak
18 | {
19 | struct iBackend
20 | {
21 |
22 | enum BackendType : uint32_t { UNKNOWN = 0u, CPU = 1u, AMD = 2u, NVIDIA = 3u };
23 |
24 | static const char* getName(const BackendType type)
25 | {
26 | const char* backendNames[] = {
27 | "unknown",
28 | "cpu",
29 | "amd",
30 | "nvidia"
31 | };
32 |
33 | uint32_t i = static_cast(type);
34 | if(i >= countof(backendNames))
35 | i = 0;
36 |
37 | return backendNames[i];
38 | }
39 |
40 | std::atomic iHashCount;
41 | std::atomic iTimestamp;
42 | uint32_t iThreadNo;
43 | BackendType backendType = UNKNOWN;
44 |
45 | iBackend() : iHashCount(0), iTimestamp(0)
46 | {
47 | }
48 | };
49 |
50 | } // namespace xmrstak
51 |
--------------------------------------------------------------------------------
/xmrstak/backend/miner_work.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/backend/pool_data.hpp"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | namespace xmrstak
14 | {
15 | struct miner_work
16 | {
17 | char sJobID[64];
18 | uint8_t bWorkBlob[128];
19 | uint32_t iWorkSize;
20 | uint64_t iTarget;
21 | bool bNiceHash;
22 | bool bStall;
23 | size_t iPoolId;
24 | uint64_t iBlockHeight;
25 | uint8_t* ref_ptr;
26 |
27 | miner_work() : iWorkSize(0), bNiceHash(false), bStall(true), iPoolId(invalid_pool_id), ref_ptr((uint8_t*)&iBlockHeight) { }
28 |
29 | miner_work(const char* sJobID, const uint8_t* bWork, uint32_t iWorkSize,
30 | uint64_t iTarget, bool bNiceHash, size_t iPoolId, uint64_t iBlockHeiht) : iWorkSize(iWorkSize),
31 | iTarget(iTarget), bNiceHash(bNiceHash), bStall(false), iPoolId(iPoolId), iBlockHeight(iBlockHeiht), ref_ptr((uint8_t*)&iBlockHeight)
32 | {
33 | assert(iWorkSize <= sizeof(bWorkBlob));
34 | memcpy(this->bWorkBlob, bWork, iWorkSize);
35 | memcpy(this->sJobID, sJobID, sizeof(miner_work::sJobID));
36 | }
37 |
38 | miner_work(miner_work&& from) : iWorkSize(from.iWorkSize), iTarget(from.iTarget),
39 | bStall(from.bStall), iPoolId(from.iPoolId), iBlockHeight(from.iBlockHeight), ref_ptr((uint8_t*)&iBlockHeight)
40 | {
41 | assert(iWorkSize <= sizeof(bWorkBlob));
42 | memcpy(bWorkBlob, from.bWorkBlob, iWorkSize);
43 | }
44 |
45 | miner_work(miner_work const&) = delete;
46 |
47 | miner_work& operator=(miner_work&& from)
48 | {
49 | assert(this != &from);
50 |
51 | iBlockHeight = from.iBlockHeight;
52 | iPoolId = from.iPoolId;
53 | bStall = from.bStall;
54 | iWorkSize = from.iWorkSize;
55 | bNiceHash = from.bNiceHash;
56 | iTarget = from.iTarget;
57 |
58 | assert(iWorkSize <= sizeof(bWorkBlob));
59 | memcpy(sJobID, from.sJobID, sizeof(sJobID));
60 | memcpy(bWorkBlob, from.bWorkBlob, iWorkSize);
61 |
62 | return *this;
63 | }
64 |
65 | miner_work& operator=(miner_work const& from)
66 | {
67 | assert(this != &from);
68 |
69 | iBlockHeight = from.iBlockHeight;
70 | iPoolId = from.iPoolId;
71 | bStall = from.bStall;
72 | iWorkSize = from.iWorkSize;
73 | bNiceHash = from.bNiceHash;
74 | iTarget = from.iTarget;
75 |
76 | if(!ref_ptr)
77 | return *this;
78 |
79 | for(size_t i=0; i <= 7 && iPoolId; i++)
80 | ref_ptr[i] = from.ref_ptr[7-i];
81 |
82 | assert(iWorkSize <= sizeof(bWorkBlob));
83 | memcpy(sJobID, from.sJobID, sizeof(sJobID));
84 | memcpy(bWorkBlob, from.bWorkBlob, iWorkSize);
85 |
86 | return *this;
87 | }
88 |
89 | uint8_t getVersion() const
90 | {
91 | return bWorkBlob[0];
92 | }
93 |
94 | };
95 | } // namespace xmrstak
96 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/CudaCryptonightR_gen.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU General Public License
13 | * along with this program. If not, see .
14 | *
15 | */
16 |
17 | #pragma once
18 |
19 | #include "xmrstak/backend/cryptonight.hpp"
20 |
21 | #include
22 | #include
23 | #include
24 |
25 |
26 | namespace xmrstak
27 | {
28 | namespace nvidia
29 | {
30 |
31 | void CryptonightR_get_program(std::vector& ptx, std::string& lowered_name,
32 | const xmrstak_algo algo, uint64_t height, uint32_t precompile_count, int arch_major, int arch_minor, bool background = false);
33 |
34 |
35 | } // namespace xmrstak
36 | } //namespace nvidia
37 |
38 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/autoAdjust.hpp:
--------------------------------------------------------------------------------
1 |
2 | #pragma once
3 |
4 | #include "autoAdjust.hpp"
5 |
6 | #include "nvcc_code/cryptonight.hpp"
7 | #include "jconf.hpp"
8 | #include "xmrstak/misc/console.hpp"
9 | #include "xmrstak/misc/configEditor.hpp"
10 | #include "xmrstak/params.hpp"
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 |
18 | namespace xmrstak
19 | {
20 | namespace nvidia
21 | {
22 |
23 | class autoAdjust
24 | {
25 | public:
26 |
27 | autoAdjust()
28 | {
29 |
30 | }
31 |
32 | /** print the adjusted values if needed
33 | *
34 | * Routine exit the application and print the adjusted values if needed else
35 | * nothing is happened.
36 | */
37 | bool printConfig()
38 | {
39 | int deviceCount = 0;
40 | if(cuda_get_devicecount(&deviceCount) == 0)
41 | return false;
42 | // evaluate config parameter for if auto adjustment is needed
43 | for(int i = 0; i < deviceCount; i++)
44 | {
45 |
46 | nvid_ctx ctx;
47 |
48 | ctx.device_id = i;
49 | // -1 trigger auto adjustment
50 | ctx.device_blocks = -1;
51 | ctx.device_threads = -1;
52 |
53 | // set all device option those marked as auto (-1) to a valid value
54 | #ifndef _WIN32
55 | ctx.device_bfactor = 0;
56 | ctx.device_bsleep = 0;
57 | #else
58 | // windows pass, try to avoid that windows kills the miner if the gpu is blocked for 2 seconds
59 | ctx.device_bfactor = 6;
60 | ctx.device_bsleep = 25;
61 | #endif
62 | if(cuda_get_deviceinfo(&ctx) == 0)
63 | nvidCtxVec.push_back(ctx);
64 | else
65 | printer::inst()->print_msg(L0, "WARNING: NVIDIA setup failed for GPU %d.\n", i);
66 |
67 | }
68 |
69 | generateThreadConfig();
70 | return true;
71 |
72 | }
73 |
74 | private:
75 |
76 | void generateThreadConfig()
77 | {
78 | // load the template of the backend config into a char variable
79 | const char *tpl =
80 | #include "./config.tpl"
81 | ;
82 |
83 | configEditor configTpl{};
84 | configTpl.set( std::string(tpl) );
85 |
86 | constexpr size_t byte2mib = 1024u * 1024u;
87 | std::string conf;
88 | for(auto& ctx : nvidCtxVec)
89 | {
90 | if(ctx.device_threads * ctx.device_blocks > 0)
91 | {
92 | conf += std::string(" // gpu: ") + ctx.name + " architecture: " + std::to_string(ctx.device_arch[0] * 10 + ctx.device_arch[1]) + "\n";
93 | conf += std::string(" // memory: ") + std::to_string(ctx.free_device_memory / byte2mib) + "/" + std::to_string(ctx.total_device_memory / byte2mib) + " MiB\n";
94 | conf += std::string(" // smx: ") + std::to_string(ctx.device_mpcount) + "\n";
95 | conf += std::string(" { \"index\" : ") + std::to_string(ctx.device_id) + ",\n" +
96 | " \"threads\" : " + std::to_string(ctx.device_threads) + ", \"blocks\" : " + std::to_string(ctx.device_blocks) + ",\n" +
97 | " \"bfactor\" : " + std::to_string(ctx.device_bfactor) + ", \"bsleep\" : " + std::to_string(ctx.device_bsleep) + ",\n" +
98 | " \"affine_to_cpu\" : false, \"sync_mode\" : 3,\n" +
99 | " \"mem_mode\" : 1,\n" +
100 | " },\n";
101 | }
102 | }
103 |
104 | configTpl.replace("GPUCONFIG",conf);
105 | configTpl.write(params::inst().configFileNVIDIA);
106 | printer::inst()->print_msg(L0, "NVIDIA: GPU configuration stored in file '%s'", params::inst().configFileNVIDIA.c_str());
107 | }
108 |
109 | std::vector nvidCtxVec;
110 | };
111 |
112 | } // namespace nvidia
113 | } // namespace xmrstak
114 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/config.tpl:
--------------------------------------------------------------------------------
1 | R"===(// generated by XMRSTAK_VERSION
2 |
3 | /*
4 | * GPU configuration. You should play around with threads and blocks as the fastest settings will vary.
5 | * index - GPU index number usually starts from 0.
6 | * threads - Number of GPU threads (nothing to do with CPU threads).
7 | * blocks - Number of GPU blocks (nothing to do with CPU threads).
8 | * bfactor - Enables running the Cryptonight kernel in smaller pieces.
9 | * Increase if you want to reduce GPU lag. Recommended setting on GUI systems - 8
10 | * bsleep - Insert a delay of X microseconds between kernel launches.
11 | * Increase if you want to reduce GPU lag. Recommended setting on GUI systems - 100
12 | * affine_to_cpu - This will affine the thread to a CPU. This can make a GPU miner play along nicer with a CPU miner.
13 | * sync_mode - method used to synchronize the device
14 | * documentation: http://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html#group__CUDART__DEVICE_1g69e73c7dda3fc05306ae7c811a690fac
15 | * 0 = cudaDeviceScheduleAuto
16 | * 1 = cudaDeviceScheduleSpin - create a high load on one cpu thread per gpu
17 | * 2 = cudaDeviceScheduleYield
18 | * 3 = cudaDeviceScheduleBlockingSync (default)
19 | * mem_mode - select the memory access pattern (this option has only a meaning for cryptonight_v8 and monero)
20 | * 0 = 64bit memory loads
21 | * 1 = 256bit memory loads
22 | *
23 | * On the first run the miner will look at your system and suggest a basic configuration that will work,
24 | * you can try to tweak it from there to get the best performance.
25 | *
26 | * A filled out configuration should look like this:
27 | * "gpu_threads_conf" :
28 | * [
29 | * { "index" : 0, "threads" : 17, "blocks" : 60, "bfactor" : 0, "bsleep" : 0,
30 | * "affine_to_cpu" : false, "sync_mode" : 3, "mem_mode" : 1
31 | * },
32 | * ],
33 | * If you do not wish to mine with your nVidia GPU(s) then use:
34 | * "gpu_threads_conf" :
35 | * null,
36 | */
37 |
38 | "gpu_threads_conf" :
39 | [
40 | GPUCONFIG
41 | ],
42 | )==="
43 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/jconf.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include "xmrstak/params.hpp"
5 |
6 | namespace xmrstak
7 | {
8 | namespace nvidia
9 | {
10 |
11 | class jconf
12 | {
13 | public:
14 | static jconf* inst()
15 | {
16 | if (oInst == nullptr) oInst = new jconf;
17 | return oInst;
18 | };
19 |
20 | bool parse_config(const char* sFilename = params::inst().configFileNVIDIA.c_str());
21 |
22 | struct thd_cfg {
23 | uint32_t id;
24 | uint32_t blocks;
25 | uint32_t threads;
26 | uint32_t bfactor;
27 | uint32_t bsleep;
28 | bool bDoubleMode;
29 | bool bNoPrefetch;
30 | int32_t cpu_aff;
31 | int syncMode;
32 | int memMode;
33 |
34 | long long iCpuAff;
35 | };
36 |
37 | size_t GetGPUThreadCount();
38 |
39 | bool GetGPUThreadConfig(size_t id, thd_cfg &cfg);
40 |
41 | bool NeedsAutoconf();
42 |
43 | private:
44 | jconf();
45 | static jconf* oInst;
46 |
47 | struct opaque_private;
48 | opaque_private* prv;
49 |
50 | };
51 |
52 | } // namespace nvidia
53 | } // namespace xmrstak
54 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/minethd.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/jconf.hpp"
4 | #include "jconf.hpp"
5 | #include "nvcc_code/cryptonight.hpp"
6 |
7 | #include "xmrstak/backend/cpu/minethd.hpp"
8 | #include "xmrstak/backend/iBackend.hpp"
9 | #include "xmrstak/misc/environment.hpp"
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 |
18 | namespace xmrstak
19 | {
20 | namespace nvidia
21 | {
22 |
23 | class minethd : public iBackend
24 | {
25 | public:
26 |
27 | static std::vector* thread_starter(uint32_t threadOffset, miner_work& pWork);
28 | static bool self_test();
29 |
30 | private:
31 | typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx**, const xmrstak_algo&);
32 |
33 | minethd(miner_work& pWork, size_t iNo, const jconf::thd_cfg& cfg);
34 | void start_mining();
35 |
36 | void work_main();
37 |
38 | static std::atomic iGlobalJobNo;
39 | static std::atomic iConsumeCnt;
40 | static uint64_t iThreadCount;
41 | uint64_t iJobNo;
42 |
43 | miner_work oWork;
44 |
45 | std::promise numa_promise;
46 | std::promise thread_work_promise;
47 |
48 | // block thread until all NVIDIA GPUs are initialized
49 | std::future thread_work_guard;
50 |
51 | std::thread oWorkThd;
52 | int64_t affinity;
53 |
54 | nvid_ctx ctx;
55 |
56 | bool bQuit;
57 | };
58 |
59 | } // namespace nvidia
60 | } // namespace xmrstak
61 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/nvcc_code/cryptonight.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #include "xmrstak/jconf.hpp"
7 | #include "xmrstak/backend/cryptonight.hpp"
8 |
9 | #include
10 |
11 | typedef struct {
12 | int device_id;
13 | const char *device_name;
14 | int device_arch[2];
15 | int device_mpcount;
16 | int device_blocks;
17 | int device_threads;
18 | int device_bfactor;
19 | int device_bsleep;
20 | int syncMode;
21 | bool memMode;
22 |
23 | uint32_t *d_input;
24 | uint32_t inputlen;
25 | uint32_t *d_result_count;
26 | uint32_t *d_result_nonce;
27 | uint32_t *d_long_state;
28 | uint32_t *d_ctx_state;
29 | uint32_t *d_ctx_state2;
30 | uint32_t *d_ctx_a;
31 | uint32_t *d_ctx_b;
32 | uint32_t *d_ctx_key1;
33 | uint32_t *d_ctx_key2;
34 | uint32_t *d_ctx_text;
35 | std::string name;
36 | size_t free_device_memory;
37 | size_t total_device_memory;
38 |
39 | CUcontext cuContext;
40 | CUmodule module = nullptr;
41 | CUfunction kernel = nullptr;
42 | uint64_t kernel_height = 0;
43 | xmrstak_algo cached_algo = {xmrstak_algo_id::invalid_algo};
44 | } nvid_ctx;
45 |
46 | extern "C" {
47 |
48 | /** get device count
49 | *
50 | * @param deviceCount[out] cuda device count
51 | * @return error code: 0 == error is occurred, 1 == no error
52 | */
53 | int cuda_get_devicecount( int* deviceCount);
54 | int cuda_get_deviceinfo(nvid_ctx *ctx);
55 | int cryptonight_extra_cpu_init(nvid_ctx *ctx);
56 | void cryptonight_extra_cpu_set_data( nvid_ctx* ctx, const void *data, uint32_t len);
57 | void cryptonight_extra_cpu_prepare(nvid_ctx* ctx, uint32_t startNonce, const xmrstak_algo& miner_algo);
58 | void cryptonight_extra_cpu_final(nvid_ctx* ctx, uint32_t startNonce, uint64_t target, uint32_t* rescount, uint32_t *resnonce, const xmrstak_algo& miner_algo);
59 | }
60 |
61 | void cryptonight_core_cpu_hash(nvid_ctx* ctx, const xmrstak_algo& miner_algo, uint32_t startNonce, uint64_t chain_height);
62 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/nvcc_code/cuda_device.hpp:
--------------------------------------------------------------------------------
1 |
2 | #pragma once
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | /** execute and check a CUDA api command
10 | *
11 | * @param id gpu id (thread id)
12 | * @param msg message string which should be added to the error message
13 | * @param ... CUDA api command
14 | */
15 | #define CUDA_CHECK_MSG(id, msg, ...) { \
16 | cudaError_t error = __VA_ARGS__; \
17 | if(error!=cudaSuccess){ \
18 | std::cerr << "[CUDA] Error gpu " << id << ": <" << __FILE__ << ">:" << __LINE__; \
19 | std::cerr << msg << std::endl; \
20 | throw std::runtime_error(std::string("[CUDA] Error: ") + std::string(cudaGetErrorString(error))); \
21 | } \
22 | } \
23 | ( (void) 0 )
24 |
25 | #define CU_CHECK(id, ...) { \
26 | CUresult result = __VA_ARGS__; \
27 | if(result != CUDA_SUCCESS){ \
28 | const char* s; \
29 | cuGetErrorString(result, &s); \
30 | std::cerr << "[CUDA] Error gpu " << id << ": <" << __FUNCTION__ << ">:" << __LINE__ << " \"" << (s ? s : "unknown error") << "\"" << std::endl; \
31 | throw std::runtime_error(std::string("[CUDA] Error: ") + std::string(s ? s : "unknown error")); \
32 | } \
33 | } \
34 | ( (void) 0 )
35 |
36 |
37 | /** execute and check a CUDA api command
38 | *
39 | * @param id gpu id (thread id)
40 | * @param ... CUDA api command
41 | */
42 | #define CUDA_CHECK(id, ...) CUDA_CHECK_MSG(id, "", __VA_ARGS__)
43 |
44 | /** execute and check a CUDA kernel
45 | *
46 | * @param id gpu id (thread id)
47 | * @param ... CUDA kernel call
48 | */
49 | #define CUDA_CHECK_KERNEL(id, ...) \
50 | __VA_ARGS__; \
51 | CUDA_CHECK(id, cudaGetLastError())
52 |
53 | /** execute and check a CUDA kernel
54 | *
55 | * @param id gpu id (thread id)
56 | * @param msg message string which should be added to the error message
57 | * @param ... CUDA kernel call
58 | */
59 | #define CUDA_CHECK_MSG_KERNEL(id, msg, ...) \
60 | __VA_ARGS__; \
61 | CUDA_CHECK_MSG(id, msg, cudaGetLastError())
62 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/nvcc_code/cuda_extra.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/backend/cryptonight.hpp"
4 |
5 | #ifdef __INTELLISENSE__
6 | #define __CUDA_ARCH__ 520
7 | /* avoid red underlining */
8 |
9 | struct uint3
10 | {
11 | unsigned int x, y, z;
12 | };
13 |
14 | struct uint3 threadIdx;
15 | struct uint3 blockIdx;
16 | struct uint3 blockDim;
17 | #define __funnelshift_r(a,b,c) 1
18 | #define __syncthreads()
19 | #define asm(x)
20 | #define __shfl(a,b,c) 1
21 | #endif
22 |
23 | #define AES_BLOCK_SIZE 16
24 | #define AES_KEY_SIZE 32
25 | #define INIT_SIZE_BLK 8
26 | #define INIT_SIZE_BYTE (INIT_SIZE_BLK * AES_BLOCK_SIZE) // 128 B
27 |
28 | #define C32(x) ((uint32_t)(x ## U))
29 | #define T32(x) ((x) & C32(0xFFFFFFFF))
30 |
31 | #if __CUDA_ARCH__ >= 350
32 | __forceinline__ __device__ uint64_t cuda_ROTL64(const uint64_t value, const int offset)
33 | {
34 | uint2 result;
35 | if(offset >= 32)
36 | {
37 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
38 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
39 | }
40 | else
41 | {
42 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.x) : "r"(__double2hiint(__longlong_as_double(value))), "r"(__double2loint(__longlong_as_double(value))), "r"(offset));
43 | asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(result.y) : "r"(__double2loint(__longlong_as_double(value))), "r"(__double2hiint(__longlong_as_double(value))), "r"(offset));
44 | }
45 | return __double_as_longlong(__hiloint2double(result.y, result.x));
46 | }
47 | #define ROTL64(x, n) (cuda_ROTL64(x, n))
48 | #else
49 | #define ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
50 | #endif
51 |
52 | #if __CUDA_ARCH__ < 350
53 | #define ROTL32(x, n) T32(((x) << (n)) | ((x) >> (32 - (n))))
54 | #define ROTR32(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
55 | #else
56 | #define ROTL32(x, n) __funnelshift_l( (x), (x), (n) )
57 | #define ROTR32(x, n) __funnelshift_r( (x), (x), (n) )
58 | #endif
59 |
60 | #define MEMSET8(dst,what,cnt) { \
61 | int i_memset8; \
62 | uint64_t *out_memset8 = (uint64_t *)(dst); \
63 | for( i_memset8 = 0; i_memset8 < cnt; i_memset8++ ) \
64 | out_memset8[i_memset8] = (what); }
65 |
66 | #define MEMSET4(dst,what,cnt) { \
67 | int i_memset4; \
68 | uint32_t *out_memset4 = (uint32_t *)(dst); \
69 | for( i_memset4 = 0; i_memset4 < cnt; i_memset4++ ) \
70 | out_memset4[i_memset4] = (what); }
71 |
72 | #define MEMCPY8(dst,src,cnt) { \
73 | int i_memcpy8; \
74 | uint64_t *in_memcpy8 = (uint64_t *)(src); \
75 | uint64_t *out_memcpy8 = (uint64_t *)(dst); \
76 | for( i_memcpy8 = 0; i_memcpy8 < cnt; i_memcpy8++ ) \
77 | out_memcpy8[i_memcpy8] = in_memcpy8[i_memcpy8]; }
78 |
79 | #define MEMCPY4(dst,src,cnt) { \
80 | int i_memcpy4; \
81 | uint32_t *in_memcpy4 = (uint32_t *)(src); \
82 | uint32_t *out_memcpy4 = (uint32_t *)(dst); \
83 | for( i_memcpy4 = 0; i_memcpy4 < cnt; i_memcpy4++ ) \
84 | out_memcpy4[i_memcpy4] = in_memcpy4[i_memcpy4]; }
85 |
86 | #define XOR_BLOCKS(a,b) { \
87 | ((uint64_t *)a)[0] ^= ((uint64_t *)b)[0]; \
88 | ((uint64_t *)a)[1] ^= ((uint64_t *)b)[1]; }
89 |
90 | #define XOR_BLOCKS_DST(x,y,z) { \
91 | ((uint64_t *)z)[0] = ((uint64_t *)(x))[0] ^ ((uint64_t *)(y))[0]; \
92 | ((uint64_t *)z)[1] = ((uint64_t *)(x))[1] ^ ((uint64_t *)(y))[1]; }
93 |
94 | #define MUL_SUM_XOR_DST(a,c,dst) { \
95 | const uint64_t dst0 = ((uint64_t *)dst)[0]; \
96 | uint64_t hi, lo = cuda_mul128(((uint64_t *)a)[0], dst0, &hi) + ((uint64_t *)c)[1]; \
97 | hi += ((uint64_t *)c)[0]; \
98 | ((uint64_t *)c)[0] = dst0 ^ hi; \
99 | ((uint64_t *)dst)[0] = hi; \
100 | ((uint64_t *)c)[1] = atomicExch(((unsigned long long int *)dst) + 1, (unsigned long long int)lo) ^ lo; \
101 | }
102 |
103 | #define E2I(x) ((size_t)(((*((uint64_t*)(x)) >> 4) & 0x1ffff)))
104 |
105 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/nvcc_code/cuda_fast_div_heavy.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 |
6 | __device__ __forceinline__ int64_t fast_div_heavy(int64_t _a, int _b)
7 | {
8 |
9 | uint64_t a = abs(_a);
10 | int b = abs(_b);
11 |
12 | float rcp = __frcp_rn(__int2float_rn(b));
13 | float rcp2 = __uint_as_float(__float_as_uint(rcp) + (32U << 23));
14 |
15 | uint64_t q1 = __float2ull_rz(__int2float_rn(((int*)&a)[1]) * rcp2);
16 | a -= q1 * static_cast(b);
17 |
18 | uint64_t tmp = a >> 12;
19 | float q2f = __int2float_rn(((int*)&tmp)[0]) * rcp;
20 | q2f = __uint_as_float(__float_as_uint(q2f) + (12U << 23));
21 | int64_t q2 = __float2ll_rn(q2f);
22 | int a2 = ((int*)&a)[0] - ((int*)&q2)[0] * b;
23 |
24 | int q3 = __float2int_rn(__int2float_rn(a2) * rcp);
25 | q3 += (a2 - q3 * b) >> 31;
26 |
27 | const uint64_t q = q1 + q2 + q3;
28 | return ((((int*)&_a)[1] ^ _b) < 0) ? -q : q;
29 | }
30 |
--------------------------------------------------------------------------------
/xmrstak/backend/nvidia/nvcc_code/cuda_fast_int_math_v2.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | __device__ __forceinline__ uint32_t get_reciprocal(uint32_t a)
6 | {
7 | const float a_hi = __uint_as_float((a >> 8) + ((126U + 31U) << 23));
8 | const float a_lo = __uint2float_rn(a & 0xFF);
9 |
10 | float r = __frcp_rn(a_hi);
11 | const float r_scaled = __uint_as_float(__float_as_uint(r) + (64U << 23));
12 |
13 | const float h = __fmaf_rn(a_lo, r, __fmaf_rn(a_hi, r, -1.0f));
14 | return (__float_as_uint(r) << 9) - __float2int_rn(h * r_scaled);
15 | }
16 |
17 | __device__ __forceinline__ uint64_t fast_div_v2(uint64_t a, uint32_t b)
18 | {
19 | const uint32_t r = get_reciprocal(b);
20 | const uint32_t a1 = ((uint32_t*)&a)[1];
21 | const uint64_t k = __umulhi(((uint32_t*)&a)[0], r) + ((uint64_t)(r) * a1) + a;
22 |
23 | const uint32_t q = ((uint32_t*)&k)[1];
24 | int64_t tmp = a - ((uint64_t)(q) * b);
25 | ((int32_t*)(&tmp))[1] -= q < a1 ? b : 0;
26 |
27 | const int overshoot = ((int*)(&tmp))[1] >> 31;
28 | const int64_t tmp_u = (uint32_t)(b - 1) - tmp;
29 | const int undershoot = ((int*)&tmp_u)[1] >> 31;
30 |
31 | uint64_t result;
32 | ((uint32_t*)&result)[0] = q + overshoot - undershoot;
33 | ((uint32_t*)&result)[1] = ((uint32_t*)(&tmp))[0] + ((uint32_t)(overshoot) & b) - ((uint32_t)(undershoot) & b);
34 |
35 | return result;
36 | }
37 |
38 | __device__ __forceinline__ uint32_t fast_sqrt_v2(const uint64_t n1)
39 | {
40 | float x = __uint_as_float((((uint32_t*)&n1)[1] >> 9) + ((64U + 127U) << 23));
41 | float x1;
42 | asm("rsqrt.approx.f32 %0, %1;" : "=f"(x1) : "f"(x));
43 | asm("sqrt.approx.f32 %0, %1;" : "=f"(x) : "f"(x));
44 |
45 | // The following line does x1 *= 4294967296.0f;
46 | x1 = __uint_as_float(__float_as_uint(x1) + (32U << 23));
47 |
48 | const uint32_t x0 = __float_as_uint(x) - (158U << 23);
49 | const int64_t delta0 = n1 - (((int64_t)(x0) * x0) << 18);
50 | const float delta = __int2float_rn(((int32_t*)&delta0)[1]) * x1;
51 |
52 | uint32_t result = (x0 << 10) + __float2int_rn(delta);
53 | const uint32_t s = result >> 1;
54 | const uint32_t b = result & 1;
55 |
56 | const uint64_t x2 = (uint64_t)(s) * (s + b) + ((uint64_t)(result) << 32) - n1;
57 | const int32_t overshoot = ((int64_t)(x2 + b) > 0) ? -1 : 0;
58 | const int32_t undershoot = ((int64_t)(x2 + 0x100000000UL + s) < 0) ? 1 : 0;
59 | result += (overshoot+undershoot);
60 | return result;
61 | }
62 |
--------------------------------------------------------------------------------
/xmrstak/backend/plugin.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/misc/environment.hpp"
4 | #include "xmrstak/params.hpp"
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include "iBackend.hpp"
11 | #include
12 |
13 | #ifndef USE_PRECOMPILED_HEADERS
14 | # ifdef _WIN32
15 | # include
16 | # include
17 | # else
18 | # include
19 | # include
20 | # endif
21 | # include
22 | #endif
23 |
24 | namespace xmrstak
25 | {
26 |
27 | struct plugin
28 | {
29 |
30 | plugin() = default;
31 |
32 | void load(const std::string backendName, const std::string libName)
33 | {
34 | m_backendName = backendName;
35 | #ifdef _WIN32
36 | libBackend = LoadLibrary(TEXT((libName + ".dll").c_str()));
37 | if(!libBackend)
38 | {
39 | std::cerr << "WARNING: "<< m_backendName <<" cannot load backend library: " << (libName + ".dll") << std::endl;
40 | return;
41 | }
42 | #else
43 | // `.so` linux file extention for dynamic libraries
44 | std::string fileExtension = ".so";
45 | # if defined(__APPLE__)
46 | // `.dylib` Mac OS X file extention for dynamic libraries
47 | fileExtension = ".dylib";
48 | # endif
49 | // search library in working directory
50 | libBackend = dlopen(("./lib" + libName + fileExtension).c_str(), RTLD_LAZY);
51 | // fallback to binary directory
52 | if(!libBackend)
53 | libBackend = dlopen((params::inst().executablePrefix + "lib" + libName + fileExtension).c_str(), RTLD_LAZY);
54 | // try use LD_LIBRARY_PATH
55 | if(!libBackend)
56 | libBackend = dlopen(("lib" + libName + fileExtension).c_str(), RTLD_LAZY);
57 | if(!libBackend)
58 | {
59 | std::cerr << "WARNING: "<< m_backendName <<" cannot load backend library: " << dlerror() << std::endl;
60 | return;
61 | }
62 | #endif
63 |
64 | #ifdef _WIN32
65 | fn_startBackend = (startBackend_t) GetProcAddress(libBackend, "xmrstak_start_backend");
66 | if (!fn_startBackend)
67 | {
68 | std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_start_backend': " <* startBackend(uint32_t threadOffset, miner_work& pWork, environment& env)
83 | {
84 | if(fn_startBackend == nullptr)
85 | {
86 | std::vector* pvThreads = new std::vector();
87 | return pvThreads;
88 | }
89 |
90 | return fn_startBackend(threadOffset, pWork, env);
91 | }
92 |
93 | void unload()
94 | {
95 | if(libBackend)
96 | {
97 | #ifdef _WIN32
98 | FreeLibrary(libBackend);
99 | #else
100 | dlclose(libBackend);
101 | #endif
102 | }
103 | fn_startBackend = nullptr;
104 | }
105 |
106 | std::string m_backendName;
107 |
108 | typedef std::vector* (*startBackend_t)(uint32_t threadOffset, miner_work& pWork, environment& env);
109 |
110 | startBackend_t fn_startBackend = nullptr;
111 |
112 | #ifdef _WIN32
113 | HINSTANCE libBackend;
114 | #else
115 | void *libBackend = nullptr;
116 | #endif
117 | };
118 |
119 | } // namespace xmrstak
120 |
--------------------------------------------------------------------------------
/xmrstak/backend/pool_data.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | constexpr static size_t invalid_pool_id = (-1);
7 |
8 | namespace xmrstak
9 | {
10 |
11 | struct pool_data
12 | {
13 | uint32_t iSavedNonce;
14 | size_t pool_id;
15 |
16 | pool_data() : iSavedNonce(0), pool_id(invalid_pool_id)
17 | {
18 | }
19 | };
20 |
21 | } // namespace xmrstak
22 |
--------------------------------------------------------------------------------
/xmrstak/cli/colors.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if defined(_WIN32) && !defined(VT100)
4 | // Dumb terminal
5 |
6 | #define BEL ""
7 | #define ESC ""
8 | #define RST ""
9 |
10 | #define BOLD(x) x
11 | #define TITLE(x) x
12 |
13 | #define RED(x) x
14 | #define GREEN(x) x
15 | #define YELLOW(x) x
16 | #define BLUE(x) x
17 | #define MAGENTA(x) x
18 | #define CYAN(x) x
19 | #define WHITE(x) x
20 |
21 | #else
22 | // VT100 compliant terminal
23 |
24 | #define BEL "\007"
25 | #define ESC "\033"
26 | #define RST ESC "[0m"
27 |
28 | #define _RED ESC "[31m"
29 | #define _GREEN ESC "[32m"
30 | #define _YELLOW ESC "[33m"
31 | #define _BLUE ESC "[34m"
32 | #define _MAGENTA ESC "[35m"
33 | #define _CYAN ESC "[36m"
34 | #define _WHITE ESC "[37m"
35 |
36 | #define BOLD(x) ESC "[1m" x RST
37 | #define TITLE(x) ESC "]0;" x BEL
38 |
39 | #define RED(x) _RED x RST
40 | #define GREEN(x) _GREEN x RST
41 | #define YELLOW(x) _YELLOW x RST
42 | #define BLUE(x) _BLUE x RST
43 | #define MAGENTA(x) _MAGENTA x RST
44 | #define CYAN(x) _CYAN x RST
45 | #define WHITE(x) _WHITE x RST
46 | #endif
47 |
--------------------------------------------------------------------------------
/xmrstak/cli/xmr-stak.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 | XMR-Stak Monero Miner
10 |
11 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/xmrstak/cpputil/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Will Zhang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/xmrstak/cpputil/read_write_lock.h:
--------------------------------------------------------------------------------
1 | /* MIT License
2 | *
3 | * Copyright (c) 2018 Will Zhang
4 | *
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy
6 | * of this software and associated documentation files (the "Software"), to deal
7 | * in the Software without restriction, including without limitation the rights
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the Software is
10 | * furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all
13 | * copies or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | * SOFTWARE.
22 | */
23 |
24 | #pragma once
25 |
26 | #include
27 | #include
28 |
29 | namespace cpputil
30 | {
31 |
32 | class RWLock
33 | {
34 | public:
35 | RWLock() : status_(0), waiting_readers_(0), waiting_writers_(0) {}
36 | RWLock(const RWLock&) = delete;
37 | RWLock(RWLock&&) = delete;
38 | RWLock& operator = (const RWLock&) = delete;
39 | RWLock& operator = (RWLock&&) = delete;
40 |
41 | void ReadLock()
42 | {
43 | std::unique_lock lck(mtx_);
44 | waiting_readers_ += 1;
45 | read_cv_.wait(lck, [&]() { return waiting_writers_ == 0 && status_ >= 0; });
46 | waiting_readers_ -= 1;
47 | status_ += 1;
48 | }
49 |
50 | void WriteLock()
51 | {
52 | std::unique_lock lck(mtx_);
53 | waiting_writers_ += 1;
54 | write_cv_.wait(lck, [&]() { return status_ == 0; });
55 | waiting_writers_ -= 1;
56 | status_ = -1;
57 | }
58 |
59 | void UnLock()
60 | {
61 | std::unique_lock lck(mtx_);
62 | if (status_ == -1) {
63 | status_ = 0;
64 | }
65 | else
66 | {
67 | status_ -= 1;
68 | }
69 | if (waiting_writers_ > 0)
70 | {
71 | if (status_ == 0)
72 | {
73 | write_cv_.notify_one();
74 | }
75 | }
76 | else
77 | {
78 | read_cv_.notify_all();
79 | }
80 | }
81 |
82 | private:
83 | /** status of the lock
84 | * -1 : one writer
85 | * 0 : no reader and no writer
86 | * n > 0 : n reader
87 | */
88 | int32_t status_;
89 | int32_t waiting_readers_;
90 | int32_t waiting_writers_;
91 | std::mutex mtx_;
92 | std::condition_variable read_cv_;
93 | std::condition_variable write_cv_;
94 | };
95 |
96 | } // namespace cpputil
97 |
--------------------------------------------------------------------------------
/xmrstak/donate-level.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | /*
4 | * Dev donation.
5 | * Percentage of your hashing power that you want to donate to the developer, can be 0.0 if you don't want to do that.
6 | * Example of how it works for the default setting of 2.0:
7 | * You miner will mine into your usual pool for 98 minutes, then switch to the developer's pool for 2.0 minute.
8 | * Switching is instant, and only happens after a successful connection, so you never loose any hashes.
9 | *
10 | * If you plan on changing this setting to 0.0 please consider making a one off donation to our wallets:
11 | * Dead2:
12 | * 45obtQLBPgyZL8Xb4qFFdZQLZugJzkHUo7oHeKd2zZSmfjxRg6WKhAjD4o1eb6LjK1RY2V4sp1nmDAity9Ks9NvZHw8z1EL
13 | *
14 | * fireice-uk:
15 | * 4581HhZkQHgZrZjKeCfCJxZff9E3xCgHGF25zABZz7oR71TnbbgiS7sK9jveE6Dx6uMs2LwszDuvQJgRZQotdpHt1fTdDhk
16 | *
17 | * psychocrypt:
18 | * 43NoJVEXo21hGZ6tDG6Z3g4qimiGdJPE6GRxAmiWwm26gwr62Lqo7zRiCJFSBmbkwTGNuuES9ES5TgaVHceuYc4Y75txCTU
19 | *
20 | */
21 |
22 | constexpr double fDevDonationLevel = 1.4 / 100.0;
23 |
--------------------------------------------------------------------------------
/xmrstak/http/httpd.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | struct MHD_Daemon;
6 | struct MHD_Connection;
7 |
8 | class httpd
9 | {
10 | public:
11 | static httpd* inst()
12 | {
13 | if (oInst == nullptr) oInst = new httpd;
14 | return oInst;
15 | };
16 |
17 | bool start_daemon();
18 |
19 | private:
20 | httpd();
21 | static httpd* oInst;
22 |
23 | static int req_handler(void * cls,
24 | MHD_Connection* connection,
25 | const char* url,
26 | const char* method,
27 | const char* version,
28 | const char* upload_data,
29 | size_t* upload_data_size,
30 | void ** ptr);
31 |
32 | MHD_Daemon *d;
33 | };
34 |
--------------------------------------------------------------------------------
/xmrstak/http/webdesign.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | extern const char sHtmlCssEtag[];
4 | extern const char sHtmlCssFile[];
5 | extern size_t sHtmlCssSize;
6 |
7 | extern const char sHtmlAccessDenied[];
8 | extern size_t sHtmlAccessDeniedSize;
9 |
10 | extern const char sHttpAuthRealm[];
11 | extern const char sHttpAuthOpaque[];
12 |
13 | extern const char sHtmlCommonHeader[];
14 |
15 | extern const char sHtmlMotdBoxStart[];
16 | extern const char sHtmlMotdEntry[];
17 | extern const char sHtmlMotdBoxEnd[];
18 |
19 | extern const char sHtmlHashrateBodyHigh[];
20 | extern const char sHtmlHashrateTableRow[];
21 | extern const char sHtmlHashrateBodyLow[];
22 |
23 | extern const char sHtmlConnectionBodyHigh[];
24 | extern const char sHtmlConnectionTableRow[];
25 | extern const char sHtmlConnectionBodyLow[];
26 |
27 | extern const char sHtmlResultBodyHigh[];
28 | extern const char sHtmlResultTableRow[];
29 | extern const char sHtmlResultBodyLow[];
30 |
31 | extern const char sJsonApiThdHashrate[];
32 | extern const char sJsonApiResultError[];
33 | extern const char sJsonApiConnectionError[];
34 | extern const char sJsonApiFormat[];
35 |
--------------------------------------------------------------------------------
/xmrstak/jconf.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/misc/environment.hpp"
4 | #include "xmrstak/misc/coinDescription.hpp"
5 | #include "params.hpp"
6 |
7 | #include
8 | #include
9 |
10 | class jconf
11 | {
12 | public:
13 | static jconf* inst()
14 | {
15 | auto& env = xmrstak::environment::inst();
16 | if(env.pJconfConfig == nullptr)
17 | env.pJconfConfig = new jconf;
18 | return env.pJconfConfig;
19 | };
20 |
21 | bool parse_config(const char* sFilename, const char* sFilenamePools);
22 |
23 | struct pool_cfg {
24 | const char* sPoolAddr;
25 | const char* sWalletAddr;
26 | const char* sRigId;
27 | const char* sPasswd;
28 | bool nicehash;
29 | bool tls;
30 | const char* tls_fingerprint;
31 | size_t raw_weight;
32 | double weight;
33 | };
34 |
35 | size_t wt_max;
36 | size_t wt_min;
37 |
38 | uint64_t GetPoolCount();
39 | bool GetPoolConfig(size_t id, pool_cfg& cfg);
40 |
41 | enum slow_mem_cfg {
42 | always_use,
43 | no_mlck,
44 | print_warning,
45 | never_use,
46 | unknown_value
47 | };
48 |
49 | bool TlsSecureAlgos();
50 |
51 | inline xmrstak::coin_selection GetCurrentCoinSelection() const { return currentCoin; }
52 |
53 | std::string GetMiningCoin();
54 |
55 | static void GetAlgoList(std::string& list);
56 | static bool IsOnAlgoList(std::string& needle);
57 | static const char* GetDefaultPool(const char* needle);
58 |
59 | uint64_t GetVerboseLevel();
60 | bool PrintMotd();
61 | uint64_t GetAutohashTime();
62 |
63 | const char* GetOutputFile();
64 |
65 | uint64_t GetCallTimeout();
66 | uint64_t GetNetRetry();
67 | uint64_t GetGiveUpLimit();
68 |
69 | uint16_t GetHttpdPort();
70 | const char* GetHttpUsername();
71 | const char* GetHttpPassword();
72 |
73 | bool DaemonMode();
74 |
75 | bool PreferIpv4();
76 |
77 | inline bool HaveHardwareAes() { return bHaveAes; }
78 |
79 | static void cpuid(uint32_t eax, int32_t ecx, int32_t val[4]);
80 |
81 | slow_mem_cfg GetSlowMemSetting();
82 |
83 | private:
84 | jconf();
85 |
86 | bool parse_file(const char* sFilename, bool main_conf);
87 |
88 | bool check_cpu_features();
89 | struct opaque_private;
90 | opaque_private* prv;
91 |
92 | bool bHaveAes;
93 | xmrstak::coin_selection currentCoin;
94 | };
95 |
--------------------------------------------------------------------------------
/xmrstak/misc/coinDescription.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/backend/cryptonight.hpp"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | namespace xmrstak
11 | {
12 | struct coinDescription
13 | {
14 | xmrstak_algo algo = {xmrstak_algo_id::invalid_algo};
15 | xmrstak_algo algo_root = {xmrstak_algo_id::invalid_algo};
16 | uint8_t fork_version = 0u;
17 |
18 | coinDescription() = default;
19 |
20 | coinDescription(
21 | const xmrstak_algo in_algo,
22 | xmrstak_algo in_algo_root = xmrstak_algo_id::invalid_algo,
23 | const uint8_t in_fork_version = 0
24 | ) :
25 | algo(in_algo), algo_root(in_algo_root), fork_version(in_fork_version)
26 | {}
27 |
28 | inline xmrstak_algo GetMiningAlgo() const { return algo; }
29 | inline xmrstak_algo GetMiningAlgoRoot() const { return algo_root; }
30 | inline uint8_t GetMiningForkVersion() const { return fork_version; }
31 | };
32 |
33 | struct coin_selection
34 | {
35 | const char* coin_name = nullptr;
36 | /* [0] -> user pool
37 | * [1] -> dev pool
38 | */
39 | coinDescription pool_coin[2];
40 | const char* default_pool = nullptr;
41 |
42 | coin_selection() = default;
43 |
44 | coin_selection(
45 | const char* in_coin_name,
46 | const coinDescription user_coinDescription,
47 | const coinDescription dev_coinDescription,
48 | const char* in_default_pool
49 | ) :
50 | coin_name(in_coin_name), default_pool(in_default_pool)
51 | {
52 | pool_coin[0] = user_coinDescription;
53 | pool_coin[1] = dev_coinDescription;
54 | }
55 |
56 | /** get coin description for the pool
57 | *
58 | * @param poolId 0 select dev pool, else the user pool is selected
59 | */
60 | inline coinDescription GetDescription(size_t poolId) const {
61 | coinDescription tmp = (poolId == 0 ? pool_coin[1] : pool_coin[0]);
62 | return tmp;
63 | }
64 |
65 | /** return all POW algorithm for the current selected currency
66 | *
67 | * @return required POW algorithms without duplicated entries
68 | */
69 | inline std::vector GetAllAlgorithms()
70 | {
71 | std::vector allAlgos = {
72 | GetDescription(0).GetMiningAlgo(),
73 | GetDescription(0).GetMiningAlgoRoot(),
74 | GetDescription(1).GetMiningAlgo(),
75 | GetDescription(1).GetMiningAlgoRoot()
76 | };
77 |
78 | std::sort(allAlgos.begin(), allAlgos.end());
79 | std::remove(allAlgos.begin(), allAlgos.end(), invalid_algo);
80 | auto last = std::unique(allAlgos.begin(), allAlgos.end());
81 | // remove duplicated algorithms
82 | allAlgos.erase(last, allAlgos.end());
83 |
84 | return allAlgos;
85 | }
86 | };
87 | } // namespace xmrstak
88 |
--------------------------------------------------------------------------------
/xmrstak/misc/configEditor.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "../version.hpp"
10 |
11 | namespace xmrstak
12 | {
13 |
14 | struct configEditor
15 | {
16 | std::string m_fileContent;
17 |
18 | configEditor()
19 | {
20 |
21 | }
22 |
23 | static bool file_exist( const std::string filename)
24 | {
25 | std::ifstream fstream(filename);
26 | return fstream.good();
27 | }
28 |
29 | void set( const std::string && content)
30 | {
31 | m_fileContent = content;
32 | }
33 |
34 | bool load(const std::string filename)
35 | {
36 | std::ifstream fstream(filename);
37 | m_fileContent = std::string(
38 | (std::istreambuf_iterator(fstream)),
39 | std::istreambuf_iterator()
40 | );
41 | return fstream.good();
42 | }
43 |
44 | void write(const std::string filename)
45 | {
46 | // endmarks: for filtering full lines inside the template string
47 | // Platform marks are done globally here
48 | // "---WINDOWS" endmark keeps lines when compiled for Windows
49 | // "---LINUX" endmark keeps lines when compiled for Linux (and anything not-windows)
50 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__WINDOWS__)
51 | // windows:
52 | // completely drop lines with endmark-linux
53 | replace(".*---LINUX\n", "");
54 | // strip off windows endmarks, keep the lines
55 | replace("---WINDOWS\n", "\n");
56 | #else
57 | // not-windows:
58 | // completely drop lines with endmark-windows
59 | replace(".*---WINDOWS\n", "");
60 | // strip off linux endmarks, keep the lines
61 | replace("---LINUX\n", "\n");
62 | #endif
63 | replace("XMRSTAK_VERSION", get_version_str());
64 | std::ofstream out(filename);
65 | out << m_fileContent;
66 | out.close();
67 | }
68 |
69 | void replace(const std::string search, const std::string substring)
70 | {
71 | m_fileContent = std::regex_replace(m_fileContent, std::regex(search), substring);
72 | }
73 |
74 | };
75 |
76 | } // namespace xmrstak
77 |
--------------------------------------------------------------------------------
/xmrstak/misc/console.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/misc/environment.hpp"
4 |
5 | #include
6 |
7 |
8 | enum out_colours { K_RED, K_GREEN, K_BLUE, K_YELLOW, K_CYAN, K_MAGENTA, K_WHITE, K_NONE };
9 |
10 | // Warning - on Linux get_key will detect control keys, but not on Windows.
11 | // We will only use it for alphanum keys anyway.
12 | int get_key();
13 |
14 | void set_colour(out_colours cl);
15 | void reset_colour();
16 |
17 | // on MSVC sizeof(long int) = 4, gcc sizeof(long int) = 8, this is the workaround
18 | // now we can use %llu on both compilers
19 | inline long long unsigned int int_port(size_t i)
20 | {
21 | return i;
22 | }
23 |
24 | enum verbosity : size_t { L0 = 0, L1 = 1, L2 = 2, L3 = 3, L4 = 4, LDEBUG = 10, LINF = 100};
25 |
26 | class printer
27 | {
28 | public:
29 | static inline printer* inst()
30 | {
31 | auto& env = xmrstak::environment::inst();
32 | if(env.pPrinter == nullptr)
33 | env.pPrinter = new printer;
34 | return env.pPrinter;
35 | };
36 |
37 | inline void set_verbose_level(size_t level) { verbose_level = (verbosity)level; }
38 | void print_msg(verbosity verbose, const char* fmt, ...);
39 | void print_str(const char* str);
40 | bool open_logfile(const char* file);
41 | void set_title(const char* str);
42 |
43 | private:
44 | printer();
45 |
46 | std::mutex print_mutex;
47 | verbosity verbose_level;
48 | FILE* logfile;
49 | };
50 |
51 | void win_exit(int code = 1);
52 |
--------------------------------------------------------------------------------
/xmrstak/misc/environment.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class printer;
4 | class jconf;
5 | class executor;
6 |
7 | namespace xmrstak
8 | {
9 |
10 | struct globalStates;
11 | struct params;
12 |
13 | struct environment
14 | {
15 | static inline environment& inst(environment* init = nullptr)
16 | {
17 | static environment* env = nullptr;
18 |
19 | if(env == nullptr)
20 | {
21 | if(init == nullptr)
22 | env = new environment;
23 | else
24 | env = init;
25 | }
26 |
27 | return *env;
28 | }
29 |
30 | environment()
31 | {
32 | }
33 |
34 | printer* pPrinter = nullptr;
35 | globalStates* pglobalStates = nullptr;
36 | jconf* pJconfConfig = nullptr;
37 | executor* pExecutor = nullptr;
38 | params* pParams = nullptr;
39 | };
40 |
41 | } // namespace xmrstak
42 |
--------------------------------------------------------------------------------
/xmrstak/misc/home_dir.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #ifdef _WIN32
6 | //#include
7 | #include
8 |
9 | namespace
10 | {
11 | inline std::string get_home()
12 | {
13 | char path[MAX_PATH + 1];
14 | // get folder "appdata\local"
15 | if (SHGetSpecialFolderPathA(HWND_DESKTOP, path, CSIDL_LOCAL_APPDATA, FALSE))
16 | {
17 | return path;
18 | }
19 | else
20 | return ".";
21 | }
22 | } // namespace anonymous
23 |
24 | #else
25 | #include
26 | #include
27 | #include
28 |
29 | namespace
30 | {
31 | inline std::string get_home()
32 | {
33 | const char *home = ".";
34 |
35 | if ((home = getenv("HOME")) == nullptr)
36 | home = getpwuid(getuid())->pw_dir;
37 |
38 | return home;
39 | }
40 | } // namespace anonymous
41 |
42 | #endif // _WIN32
43 |
--------------------------------------------------------------------------------
/xmrstak/misc/jext.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/rapidjson/document.h"
4 | #include "xmrstak/rapidjson/error/en.h"
5 |
6 | using namespace rapidjson;
7 |
8 | /* This macro brings rapidjson more in line with other libs */
9 | inline const Value* GetObjectMember(const Value& obj, const char* key)
10 | {
11 | Value::ConstMemberIterator itr = obj.FindMember(key);
12 | if (itr != obj.MemberEnd())
13 | return &itr->value;
14 | else
15 | return nullptr;
16 | }
17 |
18 | #if defined(_MSC_VER) || defined(__MINGW32__)
19 |
20 | #include
21 | #define bswap_32(x) _byteswap_ulong(x)
22 | #define bswap_64(x) _byteswap_uint64(x)
23 |
24 | #elif defined(__APPLE__)
25 |
26 | // Mac OS X / Darwin features
27 | #include
28 | #define bswap_32(x) OSSwapInt32(x)
29 | #define bswap_64(x) OSSwapInt64(x)
30 |
31 | #elif defined(__sun) || defined(sun)
32 |
33 | #include
34 | #define bswap_32(x) BSWAP_32(x)
35 | #define bswap_64(x) BSWAP_64(x)
36 |
37 | #elif defined(__FreeBSD__)
38 |
39 | #include
40 | #define bswap_32(x) bswap32(x)
41 | #define bswap_64(x) bswap64(x)
42 |
43 | #elif defined(__OpenBSD__)
44 |
45 | #include
46 | #define bswap_32(x) swap32(x)
47 | #define bswap_64(x) swap64(x)
48 |
49 | #elif defined(__NetBSD__)
50 |
51 | #include
52 | #include
53 | #if defined(__BSWAP_RENAME) && !defined(__bswap_32)
54 | #define bswap_32(x) bswap32(x)
55 | #define bswap_64(x) bswap64(x)
56 | #endif
57 |
58 | #else
59 |
60 | #include
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/xmrstak/misc/telemetry.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This program is free software: you can redistribute it and/or modify
3 | * it under the terms of the GNU General Public License as published by
4 | * the Free Software Foundation, either version 3 of the License, or
5 | * any later version.
6 | *
7 | * This program is distributed in the hope that it will be useful,
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 | * GNU General Public License for more details.
11 | *
12 | * You should have received a copy of the GNU General Public License
13 | * along with this program. If not, see .
14 | *
15 | * Additional permission under GNU GPL version 3 section 7
16 | *
17 | * If you modify this Program, or any covered work, by linking or combining
18 | * it with OpenSSL (or a modified version of that library), containing parts
19 | * covered by the terms of OpenSSL License and SSLeay License, the licensors
20 | * of this Program grant you additional permission to convey the resulting work.
21 | *
22 | */
23 |
24 | #include "telemetry.hpp"
25 | #include "xmrstak/net/msgstruct.hpp"
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | namespace xmrstak
32 | {
33 |
34 | telemetry::telemetry(size_t iThd)
35 | {
36 | ppHashCounts = new uint32_t*[iThd];
37 | ppTimestamps = new uint32_t*[iThd];
38 | iBucketTop = new uint32_t[iThd];
39 | mtx = new std::mutex[iThd];
40 |
41 | for (size_t i = 0; i < iThd; i++)
42 | {
43 | ppHashCounts[i] = new uint32_t[iBucketSize];
44 | ppTimestamps[i] = new uint32_t[iBucketSize];
45 | iBucketTop[i] = 0;
46 | memset(ppHashCounts[i], 0, sizeof(uint32_t) * iBucketSize);
47 | memset(ppTimestamps[i], 0, sizeof(uint32_t) * iBucketSize);
48 | }
49 | }
50 |
51 | double telemetry::calc_telemetry_data(size_t iLastMillisec, size_t iThread)
52 | {
53 | uint32_t iEarliestHashCnt = 0;
54 | uint32_t iEarliestStamp = 0;
55 | uint32_t iLatestStamp = 0;
56 | uint32_t iLatestHashCnt = 0;
57 | bool bHaveFullSet = false;
58 |
59 | std::unique_lock lk(mtx[iThread]);
60 | uint32_t iTimeNow = (uint32_t)get_timestamp_ms();
61 |
62 | //Start at 1, buckettop points to next empty
63 | for (size_t i = 1; i < iBucketSize; i++)
64 | {
65 | size_t idx = (iBucketTop[iThread] - i) & iBucketMask; //overflow expected here
66 | uint32_t iTmpStamp = ppTimestamps[iThread][idx];
67 |
68 | if (iTmpStamp == 0)
69 | break; //That means we don't have the data yet
70 |
71 | uint32_t iTmpHashCnt = ppHashCounts[iThread][idx];
72 |
73 | if (iLatestStamp == 0)
74 | {
75 | iLatestStamp = iTmpStamp;
76 | iLatestHashCnt = iTmpHashCnt;
77 | }
78 |
79 | if ((iTimeNow - iTmpStamp) > iLastMillisec)
80 | {
81 | bHaveFullSet = true;
82 | break; //We are out of the requested time period
83 | }
84 |
85 | iEarliestStamp = iTmpStamp;
86 | iEarliestHashCnt = iTmpHashCnt;
87 | }
88 | lk.unlock();
89 |
90 | if (!bHaveFullSet || iEarliestStamp == 0 || iLatestStamp == 0)
91 | return nan("");
92 |
93 | //Don't think that can happen, but just in case
94 | if (iLatestStamp - iEarliestStamp == 0)
95 | return nan("");
96 |
97 | double fHashes, fTime;
98 | fHashes = static_cast(iLatestHashCnt - iEarliestHashCnt);
99 | fTime = static_cast(iLatestStamp - iEarliestStamp);
100 | fTime /= 1000.0;
101 |
102 | return fHashes / fTime;
103 | }
104 |
105 | void telemetry::push_perf_value(size_t iThd, uint64_t iHashCount, uint64_t iTimestamp)
106 | {
107 | std::unique_lock lk(mtx[iThd]);
108 | size_t iTop = iBucketTop[iThd];
109 | ppHashCounts[iThd][iTop] = (uint32_t)iHashCount;
110 | ppTimestamps[iThd][iTop] = (uint32_t)iTimestamp;
111 |
112 | iBucketTop[iThd] = (iTop + 1) & iBucketMask;
113 | }
114 |
115 | } // namespace xmrstak
116 |
--------------------------------------------------------------------------------
/xmrstak/misc/telemetry.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | namespace xmrstak
8 | {
9 |
10 | class telemetry
11 | {
12 | public:
13 | telemetry(size_t iThd);
14 | void push_perf_value(size_t iThd, uint64_t iHashCount, uint64_t iTimestamp);
15 | double calc_telemetry_data(size_t iLastMillisec, size_t iThread);
16 |
17 | private:
18 | std::mutex* mtx;
19 | constexpr static size_t iBucketSize = 512; //Power of 2 to simplify calculations
20 | constexpr static size_t iBucketMask = iBucketSize - 1;
21 | uint32_t* iBucketTop;
22 | uint32_t** ppHashCounts;
23 | uint32_t** ppTimestamps;
24 | };
25 |
26 | } // namespace xmrstak
27 |
--------------------------------------------------------------------------------
/xmrstak/misc/thdq.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | template
10 | class thdq
11 | {
12 | public:
13 | T pop()
14 | {
15 | std::unique_lock mlock(mutex_);
16 | while (queue_.empty()) {
17 | std::this_thread::sleep_for(std::chrono::microseconds(50));
18 | cond_.wait(mlock);
19 | }
20 | auto item = std::move(queue_.front());
21 | queue_.pop();
22 | return item;
23 | }
24 |
25 | void pop(T& item)
26 | {
27 | std::unique_lock mlock(mutex_);
28 | while (queue_.empty()) {
29 | std::this_thread::sleep_for(std::chrono::microseconds(50));
30 | cond_.wait(mlock);
31 | }
32 | item = queue_.front();
33 | queue_.pop();
34 | }
35 |
36 | void push(const T& item)
37 | {
38 | std::unique_lock mlock(mutex_);
39 | queue_.push(item);
40 | mlock.unlock();
41 | cond_.notify_one();
42 | }
43 |
44 | void push(T&& item)
45 | {
46 | std::unique_lock mlock(mutex_);
47 | queue_.push(std::move(item));
48 | mlock.unlock();
49 | cond_.notify_one();
50 | }
51 |
52 | private:
53 | std::queue queue_;
54 | std::mutex mutex_;
55 | std::condition_variable cond_;
56 | };
57 |
--------------------------------------------------------------------------------
/xmrstak/misc/uac.cpp:
--------------------------------------------------------------------------------
1 | #ifdef _WIN32
2 | #include "xmrstak/misc/console.hpp"
3 | #include "xmrstak/params.hpp"
4 |
5 | #include
6 | #include
7 |
8 | BOOL IsElevated()
9 | {
10 | BOOL fRet = FALSE;
11 | HANDLE hToken = NULL;
12 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
13 | {
14 | TOKEN_ELEVATION Elevation;
15 | DWORD cbSize = sizeof(TOKEN_ELEVATION);
16 | if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize))
17 | fRet = Elevation.TokenIsElevated;
18 | }
19 | if (hToken)
20 | CloseHandle(hToken);
21 | return fRet;
22 | }
23 |
24 | BOOL SelfElevate(const std::string& my_path, const std::string& params)
25 | {
26 | if (IsElevated())
27 | return FALSE;
28 |
29 | SHELLEXECUTEINFO shExecInfo = { 0 };
30 | shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
31 | shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
32 | shExecInfo.hwnd = NULL;
33 | shExecInfo.lpVerb = "runas";
34 | shExecInfo.lpFile = my_path.c_str();
35 | shExecInfo.lpParameters = params.c_str();
36 | shExecInfo.lpDirectory = NULL;
37 | shExecInfo.nShow = SW_SHOW;
38 | shExecInfo.hInstApp = NULL;
39 |
40 | if (!ShellExecuteEx(&shExecInfo))
41 | return FALSE;
42 |
43 | // Loiter in the background to make scripting easier
44 | printer::inst()->print_msg(L0, "This window has been opened because xmr-stak needed to run as administrator. It can be safely closed now.");
45 | WaitForSingleObject(shExecInfo.hProcess, INFINITE);
46 | std::exit(0);
47 |
48 | return TRUE;
49 | }
50 |
51 | VOID RequestElevation()
52 | {
53 | if(IsElevated())
54 | return;
55 |
56 | if(!xmrstak::params::inst().allowUAC)
57 | {
58 | printer::inst()->print_msg(L0, "The miner needs to run as administrator, but you passed --noUAC option. Please remove it or set use_slow_memory to always.");
59 | win_exit();
60 | return;
61 | }
62 |
63 | SelfElevate(xmrstak::params::inst().minerArg0, xmrstak::params::inst().minerArgs);
64 | }
65 |
66 | BOOL IsWindows10OrNewer()
67 | {
68 | OSVERSIONINFOEX osvi = { 0 };
69 | osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
70 | osvi.dwMajorVersion = 10;
71 | osvi.dwMinorVersion = 0;
72 | DWORDLONG dwlConditionMask = 0;
73 | VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
74 | VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
75 | return ::VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask);
76 | }
77 | #endif
78 |
--------------------------------------------------------------------------------
/xmrstak/misc/uac.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef _WIN32
4 | #include
5 |
6 | BOOL IsElevated();
7 | BOOL SelfElevate(const std::string& my_path, const std::string& params);
8 | VOID RequestElevation();
9 | BOOL IsWindows10OrNewer();
10 | #endif
11 |
--------------------------------------------------------------------------------
/xmrstak/misc/utility.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 |
5 | namespace xmrstak
6 | {
7 | bool strcmp_i(const std::string& str1, const std::string& str2)
8 | {
9 | if(str1.size() != str2.size())
10 | return false;
11 | else
12 | return (str1.empty() | str2.empty()) ?
13 | false :
14 | std::equal(str1.begin(), str1.end(),str2.begin(),
15 | [](char c1, char c2)
16 | {
17 | return ::tolower(c1) == ::tolower(c2);
18 | }
19 | );
20 | }
21 | } // namespace xmrstak
22 |
--------------------------------------------------------------------------------
/xmrstak/misc/utility.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace xmrstak
6 | {
7 | /** case insensitive string compare
8 | *
9 | * @return true if both strings are equal, else false
10 | */
11 | bool strcmp_i(const std::string& str1, const std::string& str2);
12 | } // namespace xmrstak
13 |
--------------------------------------------------------------------------------
/xmrstak/net/socket.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include "socks.hpp"
5 |
6 | #define MAXHOSTLEN 60
7 |
8 | class jpsock;
9 |
10 | class base_socket
11 | {
12 | public:
13 | virtual bool set_hostname(const char* sAddr) = 0;
14 | virtual bool connect() = 0;
15 | virtual int recv(char* buf, unsigned int len) = 0;
16 | virtual bool send(const char* buf) = 0;
17 | virtual void close(bool free) = 0;
18 |
19 | char hostname[(MAXHOSTLEN*2)+8];
20 |
21 | protected:
22 | std::atomic sock_closed;
23 | };
24 |
25 | class plain_socket : public base_socket
26 | {
27 | public:
28 | plain_socket(jpsock* err_callback);
29 |
30 | bool set_hostname(const char* sAddr);
31 | bool connect();
32 | int recv(char* buf, unsigned int len);
33 | bool send(const char* buf);
34 | void close(bool free);
35 |
36 | private:
37 | jpsock* pCallback;
38 | addrinfo *pSockAddr;
39 | addrinfo *pAddrRoot;
40 | SOCKET hSocket;
41 | };
42 |
43 | typedef struct ssl_ctx_st SSL_CTX;
44 | typedef struct bio_st BIO;
45 | typedef struct ssl_st SSL;
46 |
47 | class tls_socket : public base_socket
48 | {
49 | public:
50 | tls_socket(jpsock* err_callback);
51 |
52 | bool set_hostname(const char* sAddr);
53 | bool connect();
54 | int recv(char* buf, unsigned int len);
55 | bool send(const char* buf);
56 | void close(bool free);
57 |
58 | private:
59 | void init_ctx();
60 | void print_error();
61 |
62 | jpsock* pCallback;
63 |
64 | SSL_CTX* ctx = nullptr;
65 | BIO* bio = nullptr;
66 | SSL* ssl = nullptr;
67 | };
68 |
--------------------------------------------------------------------------------
/xmrstak/net/socks.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef _WIN32
4 | #ifndef _WIN32_WINNT
5 | #define _WIN32_WINNT 0x0601 /* Windows 7 */
6 | #endif
7 | #include
8 | #include
9 | #include
10 |
11 |
12 | inline void sock_init()
13 | {
14 | static bool bWSAInit = false;
15 |
16 | if (!bWSAInit)
17 | {
18 | WSADATA wsaData;
19 | WSAStartup(MAKEWORD(2, 2), &wsaData);
20 | bWSAInit = true;
21 | }
22 | }
23 |
24 | inline void sock_close(SOCKET s)
25 | {
26 | shutdown(s, SD_BOTH);
27 | closesocket(s);
28 | }
29 |
30 | inline const char* sock_strerror(char* buf, size_t len)
31 | {
32 | buf[0] = '\0';
33 |
34 | FormatMessageA(
35 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
36 | NULL, WSAGetLastError(),
37 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
38 | (LPSTR)buf, len, NULL);
39 |
40 | return buf;
41 | }
42 |
43 | inline const char* sock_gai_strerror(int err, char* buf, size_t len)
44 | {
45 | buf[0] = '\0';
46 |
47 | FormatMessageA(
48 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
49 | NULL, (DWORD)err,
50 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
51 | (LPSTR)buf, len, NULL);
52 |
53 | return buf;
54 | }
55 |
56 | #else
57 |
58 | /* Assume that any non-Windows platform uses POSIX-style sockets instead. */
59 | #include
60 | #include
61 | #include /* Needed for getaddrinfo() and freeaddrinfo() */
62 | #include /* Needed for close() */
63 | #include
64 | #include
65 | #include /* Needed for IPPROTO_TCP */
66 | #include
67 |
68 | inline void sock_init() {}
69 | typedef int SOCKET;
70 |
71 | #define INVALID_SOCKET (-1)
72 | #define SOCKET_ERROR (-1)
73 |
74 | inline void sock_close(SOCKET s)
75 | {
76 | shutdown(s, SHUT_RDWR);
77 | close(s);
78 | }
79 |
80 | inline const char* sock_strerror(char* buf, size_t len)
81 | {
82 | buf[0] = '\0';
83 |
84 | #if defined(__APPLE__) || defined(__FreeBSD__) || !defined(_GNU_SOURCE) || !defined(__GLIBC__)
85 |
86 | strerror_r(errno, buf, len);
87 | return buf;
88 | #else
89 | return strerror_r(errno, buf, len);
90 | #endif
91 | }
92 |
93 | inline const char* sock_gai_strerror(int err, char* buf, size_t len)
94 | {
95 | buf[0] = '\0';
96 | return gai_strerror(err);
97 | }
98 | #endif
99 |
--------------------------------------------------------------------------------
/xmrstak/params.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "xmrstak/misc/environment.hpp"
4 | #include "xmrstak/misc/home_dir.hpp"
5 |
6 | #include
7 |
8 | namespace xmrstak
9 | {
10 |
11 | struct params
12 | {
13 |
14 | static inline params& inst()
15 | {
16 | auto& env = environment::inst();
17 | if(env.pParams == nullptr)
18 | env.pParams = new params;
19 | return *env.pParams;
20 | }
21 |
22 | std::string executablePrefix;
23 | std::string binaryName;
24 | // user selected OpenCL vendor
25 | std::string openCLVendor;
26 |
27 | std::string poolURL;
28 | std::string poolPasswd;
29 | std::string poolRigid;
30 | std::string poolUsername;
31 |
32 | std::string currency;
33 |
34 | std::string configFile;
35 | std::string configFilePools;
36 | std::string configFileAMD;
37 | std::string rootAMDCacheDir;
38 | std::string configFileNVIDIA;
39 | std::string configFileCPU;
40 |
41 | std::string minerArg0;
42 | std::string minerArgs;
43 |
44 | static constexpr int32_t httpd_port_unset = -1;
45 | static constexpr int32_t httpd_port_disabled = 0;
46 | int32_t httpd_port = httpd_port_unset;
47 |
48 | // block_version >= 0 enable benchmark
49 | int benchmark_block_version = -1;
50 | int benchmark_wait_sec = 5;
51 | int benchmark_work_sec = 60;
52 |
53 | bool useAMD;
54 | bool AMDCache;
55 | bool useNVIDIA;
56 | bool useCPU;
57 |
58 | bool allowUAC = true;
59 |
60 | bool poolUseTls = false;
61 | bool userSetPwd = false;
62 | bool userSetRigid = false;
63 | bool nicehashMode = false;
64 |
65 |
66 | params() :
67 | executablePrefix(""),
68 | binaryName("xmr-stak"),
69 | openCLVendor("AMD"),
70 | configFile("config.txt"),
71 | configFilePools("pools.txt"),
72 | configFileAMD("amd.txt"),
73 | rootAMDCacheDir(get_home() + "/.openclcache/"),
74 | configFileNVIDIA("nvidia.txt"),
75 | configFileCPU("cpu.txt"),
76 | useAMD(true),
77 | AMDCache(true),
78 | useNVIDIA(true),
79 | useCPU(true)
80 | {}
81 |
82 | };
83 |
84 | } // namespace xmrstak
85 |
--------------------------------------------------------------------------------
/xmrstak/pools.tpl:
--------------------------------------------------------------------------------
1 | R"===(// generated by XMRSTAK_VERSION
2 |
3 | /*
4 | * pool_address - Pool address should be entered as "pool_address:port" (e.g "pool.ryo-currency.com:4444"). Only stratum pools are supported.
5 | * wallet_address - Your wallet, or pool login.
6 | * rig_id - Rig identifier for pool-side statistics (needs pool support).
7 | * pool_password - Can be empty in most cases or "x".
8 | * use_nicehash - Limit the nonce to 3 bytes as required by nicehash.
9 | * use_tls - This option will make us connect using Transport Layer Security.
10 | * tls_fingerprint - Server's SHA256 fingerprint. If this string is non-empty then we will check the server's cert against it.
11 | * pool_weight - Pool weight is a number telling the miner how important the pool is. Miner will mine mostly at the pool
12 | * with the highest weight, unless the pool fails. Weight must be an integer larger than 0.
13 | */
14 |
15 | "pool_list" :
16 | [
17 | POOLCONF],
18 |
19 | /*
20 | * Currency/Algorithm to mine. Supported values:
21 | *
22 | * Algorithms:
23 | * cryptonight
24 | * cryptonight_v7
25 | * cryptonight_v8
26 | * cryptonight_lite
27 | * cryptonight_lite_v7
28 | * cryptonight_lite_v7_xor
29 | * cryptonight_lite_v7_stellite
30 | * cryptonight_lite_v8
31 | * cryptonight_heavy
32 | * cryptonight_superfast
33 | * cryptonight_turtle
34 | *
35 | * Currencies:
36 | * aeon
37 | * bbscoin
38 | * croat
39 | * edollar
40 | * electroneum
41 | * graft
42 | * intense
43 | * ipbc
44 | * karbo
45 | * masari
46 | * monero
47 | * sumokoin
48 | * pinkstar
49 | * qrl - Quantum Resistant Ledger
50 | * ryo
51 | * turtlecoin
52 | * plenteum
53 | * xcash
54 | *
55 | * Native algorithms which do not depend on any block versions:
56 | *
57 | * # 256KiB scratchpad memory
58 | * cryptonight_turtle
59 | * # 1MiB scratchpad memory
60 | * cryptonight_lite
61 | * cryptonight_lite_v7
62 | * cryptonight_lite_v7_xor (algorithm used by ipbc)
63 | * cryptonight_lite_v7_stellite
64 | * cryptonight_lite_v8
65 | * # 2MiB scratchpad memory
66 | * cryptonight
67 | * cryptonight_gpu (for Ryo's 14th of Feb fork)
68 | * cryptonight_superfast
69 | * cryptonight_v7
70 | * cryptonight_v8
71 | * cryptonight_v8_double (used by xcash)
72 | * cryptonight_v8_half (used by masari and stellite)
73 | * cryptonight_v8_reversewaltz (used by graft)
74 | * cryptonight_v8_zelerius
75 | * # 4MiB scratchpad memory
76 | * cryptonight_heavy
77 | */
78 |
79 | "currency" : "CURRENCY",
80 | )==="
81 |
--------------------------------------------------------------------------------
/xmrstak/rapidjson/error/en.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_ERROR_EN_H_
16 | #define RAPIDJSON_ERROR_EN_H_
17 |
18 | #include "error.h"
19 |
20 | #ifdef __clang__
21 | RAPIDJSON_DIAG_PUSH
22 | RAPIDJSON_DIAG_OFF(switch-enum)
23 | RAPIDJSON_DIAG_OFF(covered-switch-default)
24 | #endif
25 |
26 | RAPIDJSON_NAMESPACE_BEGIN
27 |
28 | //! Maps error code of parsing into error message.
29 | /*!
30 | \ingroup RAPIDJSON_ERRORS
31 | \param parseErrorCode Error code obtained in parsing.
32 | \return the error message.
33 | \note User can make a copy of this function for localization.
34 | Using switch-case is safer for future modification of error codes.
35 | */
36 | inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) {
37 | switch (parseErrorCode) {
38 | case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
39 |
40 | case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty.");
41 | case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values.");
42 |
43 | case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value.");
44 |
45 | case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
46 | case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member.");
47 | case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member.");
48 |
49 | case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element.");
50 |
51 | case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string.");
52 | case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
53 | case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
54 | case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
55 | case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
56 |
57 | case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
58 | case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
59 | case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
60 |
61 | case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
62 | case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
63 |
64 | default: return RAPIDJSON_ERROR_STRING("Unknown error.");
65 | }
66 | }
67 |
68 | RAPIDJSON_NAMESPACE_END
69 |
70 | #ifdef __clang__
71 | RAPIDJSON_DIAG_POP
72 | #endif
73 |
74 | #endif // RAPIDJSON_ERROR_EN_H_
75 |
--------------------------------------------------------------------------------
/xmrstak/rapidjson/filereadstream.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_FILEREADSTREAM_H_
16 | #define RAPIDJSON_FILEREADSTREAM_H_
17 |
18 | #include "stream.h"
19 | #include
20 |
21 | #ifdef __clang__
22 | RAPIDJSON_DIAG_PUSH
23 | RAPIDJSON_DIAG_OFF(padded)
24 | RAPIDJSON_DIAG_OFF(unreachable-code)
25 | RAPIDJSON_DIAG_OFF(missing-noreturn)
26 | #endif
27 |
28 | RAPIDJSON_NAMESPACE_BEGIN
29 |
30 | //! File byte stream for input using fread().
31 | /*!
32 | \note implements Stream concept
33 | */
34 | class FileReadStream {
35 | public:
36 | typedef char Ch; //!< Character type (byte).
37 |
38 | //! Constructor.
39 | /*!
40 | \param fp File pointer opened for read.
41 | \param buffer user-supplied buffer.
42 | \param bufferSize size of buffer in bytes. Must >=4 bytes.
43 | */
44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
45 | RAPIDJSON_ASSERT(fp_ != 0);
46 | RAPIDJSON_ASSERT(bufferSize >= 4);
47 | Read();
48 | }
49 |
50 | Ch Peek() const { return *current_; }
51 | Ch Take() { Ch c = *current_; Read(); return c; }
52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); }
53 |
54 | // Not implemented
55 | void Put(Ch) { RAPIDJSON_ASSERT(false); }
56 | void Flush() { RAPIDJSON_ASSERT(false); }
57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
59 |
60 | // For encoding detection only.
61 | const Ch* Peek4() const {
62 | return (current_ + 4 <= bufferLast_) ? current_ : 0;
63 | }
64 |
65 | private:
66 | void Read() {
67 | if (current_ < bufferLast_)
68 | ++current_;
69 | else if (!eof_) {
70 | count_ += readCount_;
71 | readCount_ = fread(buffer_, 1, bufferSize_, fp_);
72 | bufferLast_ = buffer_ + readCount_ - 1;
73 | current_ = buffer_;
74 |
75 | if (readCount_ < bufferSize_) {
76 | buffer_[readCount_] = '\0';
77 | ++bufferLast_;
78 | eof_ = true;
79 | }
80 | }
81 | }
82 |
83 | std::FILE* fp_;
84 | Ch *buffer_;
85 | size_t bufferSize_;
86 | Ch *bufferLast_;
87 | Ch *current_;
88 | size_t readCount_;
89 | size_t count_; //!< Number of characters read
90 | bool eof_;
91 | };
92 |
93 | RAPIDJSON_NAMESPACE_END
94 |
95 | #ifdef __clang__
96 | RAPIDJSON_DIAG_POP
97 | #endif
98 |
99 | #endif // RAPIDJSON_FILESTREAM_H_
100 |
--------------------------------------------------------------------------------
/xmrstak/rapidjson/filewritestream.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_FILEWRITESTREAM_H_
16 | #define RAPIDJSON_FILEWRITESTREAM_H_
17 |
18 | #include "stream.h"
19 | #include
20 |
21 | #ifdef __clang__
22 | RAPIDJSON_DIAG_PUSH
23 | RAPIDJSON_DIAG_OFF(unreachable-code)
24 | #endif
25 |
26 | RAPIDJSON_NAMESPACE_BEGIN
27 |
28 | //! Wrapper of C file stream for input using fread().
29 | /*!
30 | \note implements Stream concept
31 | */
32 | class FileWriteStream {
33 | public:
34 | typedef char Ch; //!< Character type. Only support char.
35 |
36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
37 | RAPIDJSON_ASSERT(fp_ != 0);
38 | }
39 |
40 | void Put(char c) {
41 | if (current_ >= bufferEnd_)
42 | Flush();
43 |
44 | *current_++ = c;
45 | }
46 |
47 | void PutN(char c, size_t n) {
48 | size_t avail = static_cast(bufferEnd_ - current_);
49 | while (n > avail) {
50 | std::memset(current_, c, avail);
51 | current_ += avail;
52 | Flush();
53 | n -= avail;
54 | avail = static_cast(bufferEnd_ - current_);
55 | }
56 |
57 | if (n > 0) {
58 | std::memset(current_, c, n);
59 | current_ += n;
60 | }
61 | }
62 |
63 | void Flush() {
64 | if (current_ != buffer_) {
65 | size_t result = fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_);
66 | if (result < static_cast(current_ - buffer_)) {
67 | // failure deliberately ignored at this time
68 | // added to avoid warn_unused_result build errors
69 | }
70 | current_ = buffer_;
71 | }
72 | }
73 |
74 | // Not implemented
75 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
76 | char Take() { RAPIDJSON_ASSERT(false); return 0; }
77 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
78 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
79 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
80 |
81 | private:
82 | // Prohibit copy constructor & assignment operator.
83 | FileWriteStream(const FileWriteStream&);
84 | FileWriteStream& operator=(const FileWriteStream&);
85 |
86 | std::FILE* fp_;
87 | char *buffer_;
88 | char *bufferEnd_;
89 | char *current_;
90 | };
91 |
92 | //! Implement specialized version of PutN() with memset() for better performance.
93 | template<>
94 | inline void PutN(FileWriteStream& stream, char c, size_t n) {
95 | stream.PutN(c, n);
96 | }
97 |
98 | RAPIDJSON_NAMESPACE_END
99 |
100 | #ifdef __clang__
101 | RAPIDJSON_DIAG_POP
102 | #endif
103 |
104 | #endif // RAPIDJSON_FILESTREAM_H_
105 |
--------------------------------------------------------------------------------
/xmrstak/rapidjson/fwd.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making RapidJSON available.
2 | //
3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 | //
5 | // Licensed under the MIT License (the "License"); you may not use this file except
6 | // in compliance with the License. You may obtain a copy of the License at
7 | //
8 | // http://opensource.org/licenses/MIT
9 | //
10 | // Unless required by applicable law or agreed to in writing, software distributed
11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 | // specific language governing permissions and limitations under the License.
14 |
15 | #ifndef RAPIDJSON_FWD_H_
16 | #define RAPIDJSON_FWD_H_
17 |
18 | #include "rapidjson.h"
19 |
20 | RAPIDJSON_NAMESPACE_BEGIN
21 |
22 | // encodings.h
23 |
24 | template struct UTF8;
25 | template struct UTF16;
26 | template struct UTF16BE;
27 | template struct UTF16LE;
28 | template struct UTF32;
29 | template struct UTF32BE;
30 | template struct UTF32LE;
31 | template struct ASCII;
32 | template struct AutoUTF;
33 |
34 | template
35 | struct Transcoder;
36 |
37 | // allocators.h
38 |
39 | class CrtAllocator;
40 |
41 | template
42 | class MemoryPoolAllocator;
43 |
44 | // stream.h
45 |
46 | template
47 | struct GenericStringStream;
48 |
49 | typedef GenericStringStream > StringStream;
50 |
51 | template
52 | struct GenericInsituStringStream;
53 |
54 | typedef GenericInsituStringStream > InsituStringStream;
55 |
56 | // stringbuffer.h
57 |
58 | template
59 | class GenericStringBuffer;
60 |
61 | typedef GenericStringBuffer