Commit 9bec1e158e0e913cc9166b1f01a75e029ef9a998

Con Kolivas 2012-08-24T01:06:17

Simplify macros in output kernels avoiding apparent loops and local variables.

diff --git a/diablo120823.cl b/diablo120823.cl
index f4055aa..b287f4f 100644
--- a/diablo120823.cl
+++ b/diablo120823.cl
@@ -1245,49 +1245,35 @@ void search(
 #define FOUND (0x0F)
 
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 
 #if defined(VECTORS4)
 	bool result = any(ZA[924] == 0x136032EDU);
 
 	if (result) {
-		uint found;
-
 		if (ZA[924].x == 0x136032EDU)
-			SETFOUND(found, Znonce.x);
+			SETFOUND(Znonce.x);
 		if (ZA[924].y == 0x136032EDU)
-			SETFOUND(found, Znonce.y);
+			SETFOUND(Znonce.y);
 		if (ZA[924].z == 0x136032EDU)
-			SETFOUND(found, Znonce.z);
+			SETFOUND(Znonce.z);
 		if (ZA[924].w == 0x136032EDU)
-			SETFOUND(found, Znonce.w);
+			SETFOUND(Znonce.w);
 	}
 #elif defined(VECTORS2)
 	bool result = any(ZA[924] == 0x136032EDU);
 
 	if (result) {
-		uint found;
-
 		if (ZA[924].x == 0x136032EDU)
-			SETFOUND(found, Znonce.x);
+			SETFOUND(Znonce.x);
 		if (ZA[924].y == 0x136032EDU)
-			SETFOUND(found, Znonce.y);
+			SETFOUND(Znonce.y);
 	}
 #else
-	if (ZA[924] == 0x136032EDU) {
-		uint found;
-
-		SETFOUND(found, Znonce);
-	}
+	if (ZA[924] == 0x136032EDU)
+		SETFOUND(Znonce);
 #endif
 }
diff --git a/diakgcn120823.cl b/diakgcn120823.cl
index fb4b154..b8e7686 100644
--- a/diakgcn120823.cl
+++ b/diakgcn120823.cl
@@ -574,45 +574,31 @@ __kernel
 #define FOUND (0x0F)
 
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 
 #ifdef VECTORS4
 	if ((V[7].x == 0x136032edU) ^ (V[7].y == 0x136032edU) ^ (V[7].z == 0x136032edU) ^ (V[7].w == 0x136032edU)) {
-		uint found;
-
 		if (V[7].x == 0x136032edU)
-			SETFOUND(found, nonce.x);
+			SETFOUND(nonce.x);
 		if (V[7].y == 0x136032edU)
-			SETFOUND(found, nonce.y);
+			SETFOUND(nonce.y);
 		if (V[7].z == 0x136032edU)
-			SETFOUND(found, nonce.z);
+			SETFOUND(nonce.z);
 		if (V[7].w == 0x136032edU)
-			SETFOUND(found, nonce.w);
+			SETFOUND(nonce.w);
 	}
 #elif defined VECTORS2
 	if ((V[7].x == 0x136032edU) + (V[7].y == 0x136032edU)) {
-		uint found;
-
 		if (V[7].x == 0x136032edU)
-			SETFOUND(found, nonce.x);
+			SETFOUND(nonce.x);
 		if (V[7].y == 0x136032edU)
-			SETFOUND(found, nonce.y);
+			SETFOUND(nonce.y);
 	}
 #else
-	if (V[7] == 0x136032edU) {
-		uint found;
-
-		SETFOUND(found, nonce);
-	}
+	if (V[7] == 0x136032edU)
+		SETFOUND(nonce);
 #endif
 }
diff --git a/phatk120823.cl b/phatk120823.cl
index 4693cd8..fb1ce3c 100644
--- a/phatk120823.cl
+++ b/phatk120823.cl
@@ -390,47 +390,33 @@ void search(	const uint state0, const uint state1, const uint state2, const uint
 #define FOUND (0x0F)
 
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 
 #ifdef VECTORS4
 	bool result = W[117].x & W[117].y & W[117].z & W[117].w;
 	if (!result) {
-		uint found;
-
 		if (!W[117].x)
-			SETFOUND(found, W[3].x);
+			SETFOUND(W[3].x);
 		if (!W[117].y)
-			SETFOUND(found, W[3].y);
+			SETFOUND(W[3].y);
 		if (!W[117].z)
-			SETFOUND(found, W[3].z);
+			SETFOUND(W[3].z);
 		if (!W[117].w)
-			SETFOUND(found, W[3].w);
+			SETFOUND(W[3].w);
 	}
 #elif defined VECTORS2
 	bool result = W[117].x & W[117].y;
 	if (!result) {
-		uint found;
-
 		if (!W[117].x)
-			SETFOUND(found, W[3].x);
+			SETFOUND(W[3].x);
 		if (!W[117].y)
-			SETFOUND(found, W[3].y);
+			SETFOUND(W[3].y);
 	}
 #else
-	if (!W[117]) {
-		uint found;
-
-		SETFOUND(found, W[3]);
-	}
+	if (!W[117])
+		SETFOUND(W[3]);
 #endif
 }
diff --git a/poclbm120823.cl b/poclbm120823.cl
index 64bdb27..9ae2ee9 100644
--- a/poclbm120823.cl
+++ b/poclbm120823.cl
@@ -1324,39 +1324,26 @@ Vals[2]+=ch(Vals[1],Vals[4],Vals[3]);
 #define FOUND (0x0F)
 
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 
 #if defined(VECTORS2) || defined(VECTORS4)
-
 	if (any(Vals[2] == 0x136032edU)) {
-		uint found;
-
 		if (Vals[2].x == 0x136032edU)
-			SETFOUND(found, nonce.x);
+			SETFOUND(nonce.x);
 		if (Vals[2].y == 0x136032edU)
-			SETFOUND(found, nonce.y);
+			SETFOUND(nonce.y);
 #if defined(VECTORS4)
 		if (Vals[2].z == 0x136032edU)
-			SETFOUND(found, nonce.z);
+			SETFOUND(nonce.z);
 		if (Vals[2].w == 0x136032edU)
-			SETFOUND(found, nonce.w);
+			SETFOUND(nonce.w);
 #endif
 	}
 #else
-	if (Vals[2] == 0x136032edU) {
-		uint found;
-
-		SETFOUND(found, nonce);
-	}
+	if (Vals[2] == 0x136032edU)
+		SETFOUND(nonce);
 #endif
 }
diff --git a/scrypt120823.cl b/scrypt120823.cl
index bcc0b70..4b88458 100644
--- a/scrypt120823.cl
+++ b/scrypt120823.cl
@@ -685,16 +685,9 @@ void scrypt_core(uint4 X[8], __global uint4*restrict lookup)
 #define FOUND (0x0F)
 
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 
 __attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
@@ -734,11 +727,8 @@ const uint4 midstate0, const uint4 midstate16, const uint target)
 	SHA256(&ostate0,&ostate1, tmp0, tmp1, (uint4)(0x80000000U, 0U, 0U, 0U), (uint4)(0U, 0U, 0U, 0x300U));
 
 	bool result = (EndianSwap(ostate1.w) <= target);
-	if (result) {
-		uint found;
-
-		SETFOUND(found, gid);
-	}
+	if (result)
+		SETFOUND(gid);
 }
 
 /*-