Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/scryptjane/scrypt-jane-chacha.h
1201 views
1
#define SCRYPT_MIX_BASE "ChaCha20/8"
2
3
typedef uint32_t scrypt_mix_word_t;
4
5
#define SCRYPT_WORDTO8_LE U32TO8_LE
6
#define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP
7
8
#define SCRYPT_BLOCK_BYTES 64
9
#define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t))
10
11
/* must have these here in case block bytes is ever != 64 */
12
#include "scrypt-jane-romix-basic.h"
13
14
#include "scrypt-jane-mix_chacha-avx.h"
15
#include "scrypt-jane-mix_chacha-ssse3.h"
16
#include "scrypt-jane-mix_chacha-sse2.h"
17
#include "scrypt-jane-mix_chacha.h"
18
19
#if defined(SCRYPT_CHACHA_AVX)
20
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx
21
#if defined(X86_INTRINSIC_AVX)
22
#define SCRYPT_CHUNKMIX_1_FN scrypt_ChunkMix_avx_1
23
#define SCRYPT_CHUNKMIX_1_XOR_FN scrypt_ChunkMix_avx_1_xor
24
#endif
25
#define SCRYPT_ROMIX_FN scrypt_ROMix_avx
26
#define SCRYPT_MIX_FN chacha_core_avx
27
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop
28
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop
29
#include "scrypt-jane-romix-template.h"
30
#endif
31
32
#if defined(SCRYPT_CHACHA_SSSE3)
33
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse3
34
#if defined(X86_INTRINSIC_SSSE3)
35
#define SCRYPT_CHUNKMIX_1_FN scrypt_ChunkMix_ssse3_1
36
#define SCRYPT_CHUNKMIX_1_XOR_FN scrypt_ChunkMix_ssse3_1_xor
37
#endif
38
#define SCRYPT_ROMIX_FN scrypt_ROMix_ssse3
39
#define SCRYPT_MIX_FN chacha_core_ssse3
40
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop
41
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop
42
#include "scrypt-jane-romix-template.h"
43
#endif
44
45
#if defined(SCRYPT_CHACHA_SSE2)
46
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2
47
#if defined(X86_INTRINSIC_SSE2)
48
#define SCRYPT_CHUNKMIX_1_FN scrypt_ChunkMix_sse2_1
49
#define SCRYPT_CHUNKMIX_1_XOR_FN scrypt_ChunkMix_sse2_1_xor
50
#endif
51
#define SCRYPT_ROMIX_FN scrypt_ROMix_sse2
52
#define SCRYPT_MIX_FN chacha_core_sse2
53
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop
54
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop
55
#include "scrypt-jane-romix-template.h"
56
#endif
57
58
/* cpu agnostic */
59
#define SCRYPT_ROMIX_FN scrypt_ROMix_basic
60
#define SCRYPT_MIX_FN chacha_core_basic
61
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian
62
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian
63
#include "scrypt-jane-romix-template.h"
64
65
#if !defined(SCRYPT_CHOOSE_COMPILETIME)
66
static scrypt_ROMixfn
67
scrypt_getROMix() {
68
size_t cpuflags = detect_cpu();
69
70
#if defined(SCRYPT_CHACHA_AVX)
71
if (cpuflags & cpu_avx)
72
return scrypt_ROMix_avx;
73
else
74
#endif
75
76
#if defined(SCRYPT_CHACHA_SSSE3)
77
if (cpuflags & cpu_ssse3)
78
return scrypt_ROMix_ssse3;
79
else
80
#endif
81
82
#if defined(SCRYPT_CHACHA_SSE2)
83
if (cpuflags & cpu_sse2)
84
return scrypt_ROMix_sse2;
85
else
86
#endif
87
88
return scrypt_ROMix_basic;
89
}
90
#endif
91
92
93
#if defined(SCRYPT_TEST_SPEED)
94
static size_t
95
available_implementations() {
96
size_t cpuflags = detect_cpu();
97
size_t flags = 0;
98
99
#if defined(SCRYPT_CHACHA_AVX)
100
if (cpuflags & cpu_avx)
101
flags |= cpu_avx;
102
#endif
103
104
#if defined(SCRYPT_CHACHA_SSSE3)
105
if (cpuflags & cpu_ssse3)
106
flags |= cpu_ssse3;
107
#endif
108
109
#if defined(SCRYPT_CHACHA_SSE2)
110
if (cpuflags & cpu_sse2)
111
flags |= cpu_sse2;
112
#endif
113
114
return flags;
115
}
116
#endif
117
118
static int
119
scrypt_test_mix() {
120
static const uint8_t expected[16] = {
121
0x48,0x2b,0x2d,0xb8,0xa1,0x33,0x22,0x73,0xcd,0x16,0xc4,0xb4,0xb0,0x7f,0xb1,0x8a,
122
};
123
124
int ret = 1;
125
size_t cpuflags = detect_cpu();
126
127
#if defined(SCRYPT_CHACHA_AVX)
128
if (cpuflags & cpu_avx)
129
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, scrypt_romix_nop, scrypt_romix_nop, expected);
130
#endif
131
132
#if defined(SCRYPT_CHACHA_SSSE3)
133
if (cpuflags & cpu_ssse3)
134
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, scrypt_romix_nop, scrypt_romix_nop, expected);
135
#endif
136
137
#if defined(SCRYPT_CHACHA_SSE2)
138
if (cpuflags & cpu_sse2)
139
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, scrypt_romix_nop, scrypt_romix_nop, expected);
140
#endif
141
142
#if defined(SCRYPT_CHACHA_BASIC)
143
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected);
144
#endif
145
146
return ret;
147
}
148
149
150