Browse Source

Changing bounds checks

cl-refactor
Matthew Wampler-Doty 10 years ago
parent
commit
2bb0cebe69
  1. 4
      data_sizes.h
  2. 19
      internal.c

4
data_sizes.h

@ -49,7 +49,7 @@ extern "C" {
// While[! PrimeQ[i], i--]; // While[! PrimeQ[i], i--];
// Sow[i*MixBytes]; j++]]]][[2]][[1]] // Sow[i*MixBytes]; j++]]]][[2]][[1]]
static const size_t dag_sizes[] = { static const size_t dag_sizes[2048] = {
1073739904U, 1082130304U, 1090514816U, 1098906752U, 1107293056U, 1073739904U, 1082130304U, 1090514816U, 1098906752U, 1107293056U,
1115684224U, 1124070016U, 1132461952U, 1140849536U, 1149232768U, 1115684224U, 1124070016U, 1132461952U, 1140849536U, 1149232768U,
1157627776U, 1166013824U, 1174404736U, 1182786944U, 1191180416U, 1157627776U, 1166013824U, 1174404736U, 1182786944U, 1191180416U,
@ -478,7 +478,7 @@ static const size_t dag_sizes[] = {
// While[! PrimeQ[i], i--]; // While[! PrimeQ[i], i--];
// Sow[i*HashBytes]; j++]]]][[2]][[1]] // Sow[i*HashBytes]; j++]]]][[2]][[1]]
const size_t cache_sizes[] = { const size_t cache_sizes[2048] = {
1048384U, 1055552U, 1064512U, 1072832U, 1080896U, 1089344U, 1096768U, 1048384U, 1055552U, 1064512U, 1072832U, 1080896U, 1089344U, 1096768U,
1104448U, 1113664U, 1121216U, 1130176U, 1138624U, 1146304U, 1155008U, 1104448U, 1113664U, 1121216U, 1130176U, 1138624U, 1146304U, 1155008U,
1162816U, 1171264U, 1179328U, 1187392U, 1195456U, 1203392U, 1210816U, 1162816U, 1171264U, 1179328U, 1187392U, 1195456U, 1203392U, 1210816U,

19
internal.c

@ -38,12 +38,12 @@
#endif // WITH_CRYPTOPP #endif // WITH_CRYPTOPP
size_t ethash_get_datasize(const uint32_t block_number) { size_t ethash_get_datasize(const uint32_t block_number) {
assert(block_number / EPOCH_LENGTH < 500); assert(block_number / EPOCH_LENGTH < 2048);
return dag_sizes[block_number / EPOCH_LENGTH]; return dag_sizes[block_number / EPOCH_LENGTH];
} }
size_t ethash_get_cachesize(const uint32_t block_number) { size_t ethash_get_cachesize(const uint32_t block_number) {
assert(block_number / EPOCH_LENGTH < 500); assert(block_number / EPOCH_LENGTH < 2048);
return cache_sizes[block_number / EPOCH_LENGTH]; return cache_sizes[block_number / EPOCH_LENGTH];
} }
@ -68,8 +68,7 @@ void static ethash_compute_cache_nodes(
uint32_t const idx = nodes[i].words[0] % num_nodes; uint32_t const idx = nodes[i].words[0] % num_nodes;
node data; node data;
data = nodes[(num_nodes - 1 + i) % num_nodes]; data = nodes[(num_nodes - 1 + i) % num_nodes];
for (unsigned w = 0; w != NODE_WORDS; ++w) for (unsigned w = 0; w != NODE_WORDS; ++w) {
{
data.words[w] ^= nodes[idx].words[w]; data.words[w] ^= nodes[idx].words[w];
} }
SHA3_512(nodes[i].bytes, data.bytes, sizeof(data)); SHA3_512(nodes[i].bytes, data.bytes, sizeof(data));
@ -115,8 +114,7 @@ void ethash_calculate_dag_item(
__m128i xmm3 = ret->xmm[3]; __m128i xmm3 = ret->xmm[3];
#endif #endif
for (unsigned i = 0; i != DAG_PARENTS; ++i) for (unsigned i = 0; i != DAG_PARENTS; ++i) {
{
uint32_t parent_index = ((node_index ^ i) * FNV_PRIME ^ ret->words[i % NODE_WORDS]) % num_parent_nodes; uint32_t parent_index = ((node_index ^ i) * FNV_PRIME ^ ret->words[i % NODE_WORDS]) % num_parent_nodes;
node const *parent = &cache_nodes[parent_index]; node const *parent = &cache_nodes[parent_index];
@ -203,12 +201,10 @@ static void ethash_hash(
num_full_pages = (unsigned) (params->full_size / page_size); num_full_pages = (unsigned) (params->full_size / page_size);
for (unsigned i = 0; i != ACCESSES; ++i) for (unsigned i = 0; i != ACCESSES; ++i) {
{
uint32_t const index = ((s_mix->words[0] ^ i) * FNV_PRIME ^ mix->words[i % MIX_WORDS]) % num_full_pages; uint32_t const index = ((s_mix->words[0] ^ i) * FNV_PRIME ^ mix->words[i % MIX_WORDS]) % num_full_pages;
for (unsigned n = 0; n != MIX_NODES; ++n) for (unsigned n = 0; n != MIX_NODES; ++n) {
{
const node *dag_node = &full_nodes[MIX_NODES * index + n]; const node *dag_node = &full_nodes[MIX_NODES * index + n];
if (!full_nodes) { if (!full_nodes) {
@ -241,8 +237,7 @@ static void ethash_hash(
} }
// compress mix // compress mix
for (unsigned w = 0; w != MIX_WORDS; w += 4) for (unsigned w = 0; w != MIX_WORDS; w += 4) {
{
uint32_t reduction = mix->words[w + 0]; uint32_t reduction = mix->words[w + 0];
reduction = reduction * FNV_PRIME ^ mix->words[w + 1]; reduction = reduction * FNV_PRIME ^ mix->words[w + 1];
reduction = reduction * FNV_PRIME ^ mix->words[w + 2]; reduction = reduction * FNV_PRIME ^ mix->words[w + 2];

Loading…
Cancel
Save