-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support of CryptoNight v8 ReverseWaltz #2261
Changes from 2 commits
4457b60
4bfc9d3
c9db128
2f41efd
d10dafc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ R"===( | |
#define cryptonight_superfast 12 | ||
#define cryptonight_gpu 13 | ||
#define cryptonight_conceal 14 | ||
#define cryptonight_v8_reversewaltz 15 | ||
|
||
/* For Mesa clover support */ | ||
#ifdef cl_clang_storage_class_specifiers | ||
|
@@ -639,7 +640,7 @@ __kernel void JOIN(cn0,ALGO)(__global ulong *input, __global uint4 *Scratchpad, | |
R"===( | ||
|
||
// __NV_CL_C_VERSION checks if NVIDIA opencl is used | ||
#if(ALGO == cryptonight_monero_v8 && defined(__NV_CL_C_VERSION)) | ||
#if((ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) && defined(__NV_CL_C_VERSION)) | ||
# define SCRATCHPAD_CHUNK(N) (*(__local uint4*)((__local uchar*)(scratchpad_line) + (idxS ^ (N << 4)))) | ||
# define SCRATCHPAD_CHUNK_GLOBAL (*((__global uint16*)(Scratchpad + (IDX((idx0 & 0x1FFFC0U) >> 4))))) | ||
#else | ||
|
@@ -659,7 +660,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
float4 conc_var = (float4)(0.0f); | ||
#endif | ||
|
||
#if(ALGO == cryptonight_monero_v8) | ||
#if(ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) | ||
ulong b[4]; | ||
uint4 b_x[2]; | ||
// NVIDIA | ||
|
@@ -673,7 +674,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
#endif | ||
__local uint AES0[256], AES1[256]; | ||
|
||
#if(ALGO == cryptonight_monero_v8) | ||
#if(ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) | ||
# if defined(__clang__) && !defined(__NV_CL_C_VERSION) | ||
__local uint RCP[256]; | ||
# endif | ||
|
@@ -689,7 +690,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
AES0[i] = tmp; | ||
AES1[i] = rotate(tmp, 8U); | ||
|
||
#if(ALGO == cryptonight_monero_v8 && (defined(__clang__) && !defined(__NV_CL_C_VERSION))) | ||
#if((ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) && (defined(__clang__) && !defined(__NV_CL_C_VERSION))) | ||
RCP[i] = RCP_C[i]; | ||
#endif | ||
} | ||
|
@@ -723,7 +724,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
|
||
b_x[0] = ((uint4 *)b)[0]; | ||
|
||
#if(ALGO == cryptonight_monero_v8) | ||
#if(ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) | ||
a[1] = states[1] ^ states[5]; | ||
b[2] = states[8] ^ states[10]; | ||
b[3] = states[9] ^ states[11]; | ||
|
@@ -755,7 +756,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
{ | ||
ulong c[2]; | ||
|
||
#if(ALGO == cryptonight_monero_v8 && defined(__NV_CL_C_VERSION)) | ||
#if((ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) && defined(__NV_CL_C_VERSION)) | ||
uint idxS = idx0 & 0x30U; | ||
*scratchpad_line = SCRATCHPAD_CHUNK_GLOBAL; | ||
#endif | ||
|
@@ -794,6 +795,17 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
} | ||
#endif | ||
|
||
#if(ALGO == cryptonight_v8_reversewaltz) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One slight cleanup here: #endif
#if(ALGO == would be better written as: #elif(ALGO == There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I think this code could be made simpler still if you did some // (earlier)
#if(ALGO == cryptonight_monero_v8)
# define CNV8_CHUNK1_INTO chunk1
# define CNV8_CHUNK3_INTO chunk3
#elif(ALGO == cryptonight_v8_reversewaltz)
# define CNV8_CHUNK1_INTO chunk3
# define CNV8_CHUNK3_INTO chunk1
#endif Then you can ditch the second code block entirely and change the first to: #if(ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz)
{
ulong2 CNV8_CHUNK1_INTO = as_ulong2(SCRATCHPAD_CHUNK(1));
ulong2 chunk2 = as_ulong2(SCRATCHPAD_CHUNK(2));
ulong2 CNV8_CHUNK3_INTO = as_ulong2(SCRATCHPAD_CHUNK(3));
SCRATCHPAD_CHUNK(1) = as_uint4(chunk3 + ((ulong2 *)(b_x + 1))[0]);
SCRATCHPAD_CHUNK(2) = as_uint4(chunk1 + ((ulong2 *)b_x)[0]);
SCRATCHPAD_CHUNK(3) = as_uint4(chunk2 + ((ulong2 *)a)[0]);
}
#endif and then... (continued in next comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but it can complicate reading of the code. Also, I wanted to minimize my changes, so I tried to leave original implementation as close to original as I could. However, if @psychocrypt and @fireice-uk agree with your proposal, I'll replace it using defines. |
||
{ | ||
ulong2 chunk3 = as_ulong2(SCRATCHPAD_CHUNK(1)); | ||
ulong2 chunk2 = as_ulong2(SCRATCHPAD_CHUNK(2)); | ||
ulong2 chunk1 = as_ulong2(SCRATCHPAD_CHUNK(3)); | ||
SCRATCHPAD_CHUNK(1) = as_uint4(chunk3 + ((ulong2 *)(b_x + 1))[0]); | ||
SCRATCHPAD_CHUNK(2) = as_uint4(chunk1 + ((ulong2 *)b_x)[0]); | ||
SCRATCHPAD_CHUNK(3) = as_uint4(chunk2 + ((ulong2 *)a)[0]); | ||
} | ||
#endif | ||
|
||
#if(ALGO == cryptonight_monero || ALGO == cryptonight_aeon || ALGO == cryptonight_ipbc || ALGO == cryptonight_stellite || ALGO == cryptonight_masari || ALGO == cryptonight_bittube2) | ||
uint table = 0x75310U; | ||
b_x[0] ^= ((uint4 *)c)[0]; | ||
|
@@ -807,7 +819,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
SCRATCHPAD_CHUNK(0) = b_x[0]; | ||
idx0 = as_uint2(c[0]).s0 & MASK; | ||
|
||
#elif(ALGO == cryptonight_monero_v8) | ||
#elif(ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) | ||
SCRATCHPAD_CHUNK(0) = b_x[0] ^ ((uint4 *)c)[0]; | ||
# ifdef __NV_CL_C_VERSION | ||
// flush shuffled data | ||
|
@@ -826,7 +838,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
uint4 tmp; | ||
tmp = SCRATCHPAD_CHUNK(0); | ||
|
||
#if(ALGO == cryptonight_monero_v8) | ||
#if(ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) | ||
// Use division and square root results from the _previous_ iteration to hide the latency | ||
tmp.s0 ^= division_result.s0; | ||
tmp.s1 ^= division_result.s1 ^ sqrt_result; | ||
|
@@ -853,6 +865,13 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
ulong2 chunk2 = as_ulong2(SCRATCHPAD_CHUNK(2)); | ||
result_mul ^= chunk2; | ||
ulong2 chunk3 = as_ulong2(SCRATCHPAD_CHUNK(3)); | ||
#if(ALGO == cryptonight_v8_reversewaltz) | ||
{ | ||
ulong2 chunk_tmp = chunk3; | ||
chunk3 = chunk1; | ||
chunk1 = chunk_tmp; | ||
} | ||
#endif | ||
SCRATCHPAD_CHUNK(1) = as_uint4(chunk3 + ((ulong2 *)(b_x + 1))[0]); | ||
SCRATCHPAD_CHUNK(2) = as_uint4(chunk1 + ((ulong2 *)b_x)[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The swap above this is not nice: better to remove it and #if(ALGO == cryptonight_v8_reversewaltz)
SCRATCHPAD_CHUNK(1) = as_uint4(chunk1 + ((ulong2 *)(b_x + 1))[0]);
SCRATCHPAD_CHUNK(2) = as_uint4(chunk3 + ((ulong2 *)b_x)[0]);
#else
SCRATCHPAD_CHUNK(1) = as_uint4(chunk3 + ((ulong2 *)(b_x + 1))[0]);
SCRATCHPAD_CHUNK(2) = as_uint4(chunk1 + ((ulong2 *)b_x)[0]);
#endif There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with you. Fixed. Thanks. |
||
SCRATCHPAD_CHUNK(3) = as_uint4(chunk2 + ((ulong2 *)a)[0]); | ||
|
@@ -882,7 +901,7 @@ __kernel void JOIN(cn1,ALGO) (__global uint4 *Scratchpad, __global ulong *states | |
|
||
((uint4 *)a)[0] ^= tmp; | ||
|
||
#if (ALGO == cryptonight_monero_v8) | ||
#if (ALGO == cryptonight_monero_v8 || ALGO == cryptonight_v8_reversewaltz) | ||
# if defined(__NV_CL_C_VERSION) | ||
// flush shuffled data | ||
SCRATCHPAD_CHUNK_GLOBAL = *scratchpad_line; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be 17, not 15, to agree with the value in
xmrstak/backend/cryptonight.hpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Fixed. Thanks, @jagerman.