Commit 910ad79368f034c5419e05ea85a17974ce189e08

kanoi 2014-01-24T19:39:21

Merge pull request #537 from kanoi/master bab - remove libbitfury dependency since it requires USB

diff --git a/configure.ac b/configure.ac
index 7bfdc23..fa8274e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -288,7 +288,7 @@ else
 	want_usbutils=false
 fi
 
-if test x$bab$bitfury != xnono; then
+if test x$bitfury != xno; then
 	want_libbitfury=true
 else
 	want_libbitfury=false
diff --git a/driver-bab.c b/driver-bab.c
index e0b54c6..e09d5f2 100644
--- a/driver-bab.c
+++ b/driver-bab.c
@@ -15,7 +15,6 @@
 #include "compat.h"
 #include "miner.h"
 #include "sha2.h"
-#include "libbitfury.h"
 #include "klist.h"
 #include <ctype.h>
 
@@ -521,6 +520,67 @@ struct bab_info {
 // Don't send work more often than this
 #define BAB_EXPECTED_WORK_DELAY_mS 899
 
+static void bab_ms3steps(uint32_t *p)
+{
+	uint32_t a, b, c, d, e, f, g, h, new_e, new_a;
+	int i;
+
+	a = p[0];
+	b = p[1];
+	c = p[2];
+	d = p[3];
+	e = p[4];
+	f = p[5];
+	g = p[6];
+	h = p[7];
+	for (i = 0; i < 3; i++) {
+		new_e = p[i+16] + sha256_k[i] + h + CH(e,f,g) + SHA256_F2(e) + d;
+		new_a = p[i+16] + sha256_k[i] + h + CH(e,f,g) + SHA256_F2(e) +
+			SHA256_F1(a) + MAJ(a,b,c);
+		d = c;
+		c = b;
+		b = a;
+		a = new_a;
+		h = g;
+		g = f;
+		f = e;
+		e = new_e;
+	}
+	p[15] = a;
+	p[14] = b;
+	p[13] = c;
+	p[12] = d;
+	p[11] = e;
+	p[10] = f;
+	p[9] = g;
+	p[8] = h;
+}
+
+static uint32_t bab_decnonce(uint32_t in)
+{
+	uint32_t out;
+
+	/* First part load */
+	out = (in & 0xFF) << 24;
+	in >>= 8;
+
+	/* Byte reversal */
+	in = (((in & 0xaaaaaaaa) >> 1) | ((in & 0x55555555) << 1));
+	in = (((in & 0xcccccccc) >> 2) | ((in & 0x33333333) << 2));
+	in = (((in & 0xf0f0f0f0) >> 4) | ((in & 0x0f0f0f0f) << 4));
+
+	out |= (in >> 2) & 0x3FFFFF;
+
+	/* Extraction */
+	if (in & 1)
+		out |= (1 << 23);
+	if (in & 2)
+		out |= (1 << 22);
+
+	out -= 0x800004;
+	return out;
+}
+
 static void cleanup_older(struct cgpu_info *babcgpu, int chip, K_ITEM *witem)
 {
 	struct bab_info *babinfo = (struct bab_info *)(babcgpu->device_data);
@@ -1772,7 +1832,7 @@ static K_ITEM *process_nonce(struct thr_info *thr, struct cgpu_info *babcgpu, K_
 		try_fin = BAB_OFF_OTHER_FIN;
 	}
 
-	nonce = decnonce(raw_nonce);
+	nonce = bab_decnonce(raw_nonce);
 
 	cgtime(&now);
 
@@ -1998,7 +2058,7 @@ static bool bab_do_work(struct cgpu_info *babcgpu)
 			memcpy((void *)&(DATAW(witem)->chip_input.merkle7),
 				(void *)&(DATAW(witem)->work->data[WORK_MERKLE7]), MERKLE_BYTES);
 
-			ms3steps((void *)&(DATAW(witem)->chip_input));
+			bab_ms3steps((void *)&(DATAW(witem)->chip_input));
 
 			DATAW(witem)->ci_setup = true;
 		}