I've optimized the hashing algorithm for the Metiscoin miner!
The end result is a 20-25% improvement in hash speed compared to the original miner.
The source code is available here: https://github.com/llamasoft/xptminer-linux
The update is included in my All-In-One EZ setup script for VPS mining: https://bitcointalksearch.org/topic/mts-noobproof-vps-metiscoin-pool-mining-all-in-one-ez-setup-script-turbo-427516
https://github.com/llamasoft/xptminer-linux/commit/b3150197b68e1a6968ec9118c0ad95034e8816e1
Nope, read the comments.
// the state after feeding 76 bytes. The last 4 bytes is the nonce.
sph_keccak512_context ctx_keccak_init;
sph_keccak512_init(&ctx_keccak_init);
sph_keccak512(&ctx_keccak_init, &block->version, 80 - 4);
The first 76 bytes of input are the same, so we keep the hash state after feeding it those bytes. Then, on each pass we "restore" that state, feed it the last 4 bytes (the nonce), then calculate the rest of the hash. So instead of feeding it 80 bytes each pass, we only feed it 4.
Here's the data structure of "block", so it should make more sense:
{
// block data (order and memory layout is important)
uint32 version;
uint8 prevBlockHash[32];
uint8 merkleRoot[32];
uint32 nTime;
uint32 nBits;
uint32 nonce;
// remaining data
uint32 uniqueMerkleSeed;
uint32 height;
uint8 merkleRootOriginal[32]; // used to identify work
uint8 target[32];
uint8 targetShare[32];
}minerMetiscoinBlock_t;
The first 76 bytes correspond to version, prevBlockHash, merkleRoot, nTime, and nBits. These stay the same during each pass of the hash algorithm.
The last 4 bytes are the nonce, that changes each time. No point repeating work if you don't have to.