From 74401e592222c4159a1f96afb52be7b8143560b1 Mon Sep 17 00:00:00 2001
From: psychocrypt <psychocryptHPC@gmail.com>
Date: Sun, 10 Mar 2019 23:13:14 +0100
Subject: [PATCH] CPU: fix cryptonight_r slowdown

If the miner changed the pool (user pool or dev pool) and the network
block of monero has not changed the miner switch to the non asm version.

Add check if the hash function has changed. If the hash function not
point to the asm version the ASM function is recreated.
---
 xmrstak/backend/cpu/crypto/cryptonight_aesni.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/xmrstak/backend/cpu/crypto/cryptonight_aesni.h b/xmrstak/backend/cpu/crypto/cryptonight_aesni.h
index 2a8705b..76418bd 100644
--- a/xmrstak/backend/cpu/crypto/cryptonight_aesni.h
+++ b/xmrstak/backend/cpu/crypto/cryptonight_aesni.h
@@ -1326,7 +1326,10 @@ struct Cryptonight_R_generator
 	template<xmrstak_algo_id ALGO>
 	static void cn_on_new_job(const xmrstak::miner_work& work, cryptonight_ctx** ctx)
 	{
-		if(ctx[0]->cn_r_ctx.height == work.iBlockHeight && ctx[0]->last_algo == POW(cryptonight_r))
+		if(ctx[0]->cn_r_ctx.height == work.iBlockHeight &&
+			ctx[0]->last_algo == POW(cryptonight_r) &&
+			reinterpret_cast<void*>(ctx[0]->hash_fn) == ctx[0]->fun_data
+		)
 			return;
 
 		ctx[0]->last_algo = POW(cryptonight_r);
-- 
GitLab