mirror of
https://github.com/status-im/nim-ethash.git
synced 2025-02-26 19:00:30 +00:00
memory copy optimization
This commit is contained in:
parent
2c66038c61
commit
78ff9d9305
@ -43,7 +43,6 @@ proc mulCarry(a, b: uint64): tuple[carry, unit: uint64] =
|
|||||||
|
|
||||||
# Case 1: z0 = a_lo * b_lo
|
# Case 1: z0 = a_lo * b_lo
|
||||||
# It cannot overflow
|
# It cannot overflow
|
||||||
# We only need the hi part of z0, to add to the lo part of z1
|
|
||||||
z0 = a_lo * b_lo
|
z0 = a_lo * b_lo
|
||||||
|
|
||||||
# Case 2: z1 = a_lo * b_hi + a_hi * b_lo
|
# Case 2: z1 = a_lo * b_hi + a_hi * b_lo
|
||||||
@ -89,7 +88,7 @@ proc isValid(nonce: uint64,
|
|||||||
|
|
||||||
# First we convert the Hash[256] to an array of 4 uint64 and then
|
# First we convert the Hash[256] to an array of 4 uint64 and then
|
||||||
# only consider the most significant
|
# only consider the most significant
|
||||||
let hash_qwords = cast[array[4, uint64]](candidate_hash.value)
|
let hash_qwords = cast[ptr array[4, uint64]](candidate_hash.value.unsafeAddr)
|
||||||
var
|
var
|
||||||
unit = 0'u64
|
unit = 0'u64
|
||||||
carry = 0'u64
|
carry = 0'u64
|
||||||
|
@ -187,17 +187,16 @@ template hashimoto(header: Hash[256],
|
|||||||
mix = zipMap(mix, newdata, fnv(x, y))
|
mix = zipMap(mix, newdata, fnv(x, y))
|
||||||
|
|
||||||
# compress mix
|
# compress mix
|
||||||
var cmix{.noInit.}: array[8, uint32]
|
# ⚠⚠ Warning ⚠⚠: Another bigEndian littleEndian issue?
|
||||||
|
# It doesn't seem like the uint32 in cmix need to be changed to big endian
|
||||||
|
# cmix is an alias to the result.mix_digest
|
||||||
|
let cmix = cast[ptr array[8, uint32]](addr result.mix_digest)
|
||||||
for i in countup(0, mix.len - 1, 4):
|
for i in countup(0, mix.len - 1, 4):
|
||||||
cmix[i div 4] = mix[i].fnv(mix[i+1]).fnv(mix[i+2]).fnv(mix[i+3])
|
cmix[i div 4] = mix[i].fnv(mix[i+1]).fnv(mix[i+2]).fnv(mix[i+3])
|
||||||
|
|
||||||
# ⚠⚠ Warning ⚠⚠: Another bigEndian littleEndian issue?
|
|
||||||
# It doesn't seem like the uint32 in cmix need to be changed to big endian
|
|
||||||
result.mix_digest = cast[Hash[256]](cmix)
|
|
||||||
|
|
||||||
var concat{.noInit.}: array[64 + 32, byte]
|
var concat{.noInit.}: array[64 + 32, byte]
|
||||||
concat[0..<64] = s_bytes[]
|
concat[0..<64] = s_bytes[]
|
||||||
concat[64..<96] = cast[array[32, byte]](cmix)
|
concat[64..<96] = cast[array[32, byte]](result.mix_digest)
|
||||||
result.value = keccak_256(concat)
|
result.value = keccak_256(concat)
|
||||||
|
|
||||||
proc hashimoto_light*(full_size:Natural, cache: seq[Hash[512]],
|
proc hashimoto_light*(full_size:Natural, cache: seq[Hash[512]],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user