Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/scryptjane/scrypt-jane-salsa64.h
1201 views
1
#define SCRYPT_MIX_BASE "Salsa64/8"
2
3
typedef uint64_t scrypt_mix_word_t;
4
5
#define SCRYPT_WORDTO8_LE U64TO8_LE
6
#define SCRYPT_WORD_ENDIAN_SWAP U64_SWAP
7
8
#define SCRYPT_BLOCK_BYTES 128
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_salsa64-avx.h"
15
#include "scrypt-jane-mix_salsa64-ssse3.h"
16
#include "scrypt-jane-mix_salsa64-sse2.h"
17
#include "scrypt-jane-mix_salsa64.h"
18
19
#if defined(SCRYPT_SALSA64_AVX)
20
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx
21
#define SCRYPT_ROMIX_FN scrypt_ROMix_avx
22
#define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2
23
#define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2
24
#include "scrypt-jane-romix-template.h"
25
#endif
26
27
#if defined(SCRYPT_SALSA64_SSSE3)
28
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse3
29
#define SCRYPT_ROMIX_FN scrypt_ROMix_ssse3
30
#define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2
31
#define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2
32
#include "scrypt-jane-romix-template.h"
33
#endif
34
35
#if defined(SCRYPT_SALSA64_SSE2)
36
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2
37
#define SCRYPT_ROMIX_FN scrypt_ROMix_sse2
38
#define SCRYPT_ROMIX_TANGLE_FN salsa64_core_tangle_sse2
39
#define SCRYPT_ROMIX_UNTANGLE_FN salsa64_core_tangle_sse2
40
#include "scrypt-jane-romix-template.h"
41
#endif
42
43
/* cpu agnostic */
44
#define SCRYPT_ROMIX_FN scrypt_ROMix_basic
45
#define SCRYPT_MIX_FN salsa64_core_basic
46
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian
47
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian
48
#include "scrypt-jane-romix-template.h"
49
50
#if !defined(SCRYPT_CHOOSE_COMPILETIME)
51
static scrypt_ROMixfn
52
scrypt_getROMix() {
53
size_t cpuflags = detect_cpu();
54
55
#if defined(SCRYPT_SALSA64_AVX)
56
if (cpuflags & cpu_avx)
57
return scrypt_ROMix_avx;
58
else
59
#endif
60
61
#if defined(SCRYPT_SALSA64_SSSE3)
62
if (cpuflags & cpu_ssse3)
63
return scrypt_ROMix_ssse3;
64
else
65
#endif
66
67
#if defined(SCRYPT_SALSA64_SSE2)
68
if (cpuflags & cpu_sse2)
69
return scrypt_ROMix_sse2;
70
else
71
#endif
72
73
return scrypt_ROMix_basic;
74
}
75
#endif
76
77
78
#if defined(SCRYPT_TEST_SPEED)
79
static size_t
80
available_implementations() {
81
size_t cpuflags = detect_cpu();
82
size_t flags = 0;
83
84
#if defined(SCRYPT_SALSA64_AVX)
85
if (cpuflags & cpu_avx)
86
flags |= cpu_avx;
87
#endif
88
89
#if defined(SCRYPT_SALSA64_SSSE3)
90
if (cpuflags & cpu_ssse3)
91
flags |= cpu_ssse3;
92
#endif
93
94
#if defined(SCRYPT_SALSA64_SSE2)
95
if (cpuflags & cpu_sse2)
96
flags |= cpu_sse2;
97
#endif
98
99
return flags;
100
}
101
#endif
102
103
static int
104
scrypt_test_mix() {
105
static const uint8_t expected[16] = {
106
0xf8,0x92,0x9b,0xf8,0xcc,0x1d,0xce,0x2e,0x13,0x82,0xac,0x96,0xb2,0x6c,0xee,0x2c,
107
};
108
109
int ret = 1;
110
size_t cpuflags = detect_cpu();
111
112
#if defined(SCRYPT_SALSA64_AVX)
113
if (cpuflags & cpu_avx)
114
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected);
115
#endif
116
117
#if defined(SCRYPT_SALSA64_SSSE3)
118
if (cpuflags & cpu_ssse3)
119
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected);
120
#endif
121
122
#if defined(SCRYPT_SALSA64_SSE2)
123
if (cpuflags & cpu_sse2)
124
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, salsa64_core_tangle_sse2, salsa64_core_tangle_sse2, expected);
125
#endif
126
127
#if defined(SCRYPT_SALSA64_BASIC)
128
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected);
129
#endif
130
131
return ret;
132
}
133
134
135