memory copy optimization

This commit is contained in:
mratsim 2018-02-28 17:52:39 +01:00
parent 2c66038c61
commit 78ff9d9305
2 changed files with 6 additions and 8 deletions

View File

@ -43,7 +43,6 @@ proc mulCarry(a, b: uint64): tuple[carry, unit: uint64] =
# Case 1: z0 = a_lo * b_lo
# It cannot overflow
# We only need the hi part of z0, to add to the lo part of z1
z0 = a_lo * 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
# 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
unit = 0'u64
carry = 0'u64

View File

@ -187,17 +187,16 @@ template hashimoto(header: Hash[256],
mix = zipMap(mix, newdata, fnv(x, y))
# 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):
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]
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)
proc hashimoto_light*(full_size:Natural, cache: seq[Hash[512]],