Skip to content

Commit

Permalink
Up to 25% speedup on linux if you're lucky.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf committed Jun 8, 2014
1 parent 12dc73f commit fc4433c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cryptonight_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int scanhash_cryptonight(int thr_id, uint32_t *restrict pdata, const uint32_t *r
#if defined __unix__ && (!defined __APPLE__)
persistentctx = (struct cryptonight_ctx *)mmap(0, sizeof(struct cryptonight_ctx), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
if(persistentctx == MAP_FAILED) persistentctx = (struct cryptonight_ctx *)malloc(sizeof(struct cryptonight_ctx));
madvise(persistentctx, sizeof(struct cryptonight_ctx), MADV_RANDOM | MADV_WILLNEED | MADV_HUGEPAGE);
#elif defined _WIN32
persistentctx = VirtualAlloc(NULL, sizeof(struct cryptonight_ctx), MEM_LARGE_PAGES, PAGE_READWRITE);
if(!persistentctx) persistentctx = (struct cryptonight_ctx *)malloc(sizeof(struct cryptonight_ctx));
Expand All @@ -77,10 +78,16 @@ int scanhash_cryptonight(int thr_id, uint32_t *restrict pdata, const uint32_t *r
cryptonight_hash_ctx(hash, pdata, persistentctx);
if (unlikely(hash[7] < ptarget[7])) {
*hashes_done = n - first_nonce + 1;
#if defined __unix__ && (!defined __APPLE__)
munmap(persistentctx, sizeof(struct cryptonight_ctx));
#endif
return true;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));

*hashes_done = n - first_nonce + 1;
#if defined __unix__ && (!defined __APPLE__)
munmap(persistentctx, sizeof(struct cryptonight_ctx));
#endif
return 0;
}

0 comments on commit fc4433c

Please sign in to comment.