Browse Source

icarus: Minor optimisation (swap byte order in 32-bit always-aligned groups, and skip pointless memory copy)

Luke Dashjr 11 years ago
parent
commit
2b3baa2ae6
2 changed files with 13 additions and 16 deletions
  1. 2 16
      driver-icarus.c
  2. 11 0
      miner.h

+ 2 - 16
driver-icarus.c

@@ -151,18 +151,6 @@ extern const struct bfg_set_device_definition icarus_set_device_funcs[];
 
 extern void convert_icarus_to_cairnsmore(struct cgpu_info *);
 
-static void rev(unsigned char *s, size_t l)
-{
-	size_t i, j;
-	unsigned char t;
-
-	for (i = 0, j = l - 1; i < j; i++, j--) {
-		t = s[i];
-		s[i] = s[j];
-		s[j] = t;
-	}
-}
-
 static inline
 uint32_t icarus_nonce32toh(const struct ICARUS_INFO * const info, const uint32_t nonce)
 {
@@ -744,8 +732,8 @@ bool icarus_job_prepare(struct thr_info *thr, struct work *work, __maybe_unused
 	struct icarus_state * const state = thr->cgpu_data;
 	uint8_t * const ob_bin = state->ob_bin;
 	
-	memcpy(ob_bin, work->midstate, 32);
-	memcpy(ob_bin + 52, work->data + 64, 12);
+	swab256(ob_bin, work->midstate);
+	bswap_96p(&ob_bin[0x34], &work->data[0x40]);
 	if (!(memcmp(&ob_bin[56], "\xff\xff\xff\xff", 4)
 	   || memcmp(&ob_bin, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32))) {
 		// This sequence is used on cairnsmore bitstreams for commands, NEVER send it otherwise
@@ -753,8 +741,6 @@ bool icarus_job_prepare(struct thr_info *thr, struct work *work, __maybe_unused
 		       icarus->proc_repr);
 		ob_bin[56] = 0;
 	}
-	rev(ob_bin, 32);
-	rev(ob_bin + 52, 12);
 	
 	return true;
 }

+ 11 - 0
miner.h

@@ -724,6 +724,17 @@ static inline void swab256(void *dest_p, const void *src_p)
 	dest[7] = swab32(src[0]);
 }
 
+static inline
+void bswap_96p(void * const dest_p, const void * const src_p)
+{
+	uint32_t * const dest = dest_p;
+	const uint32_t * const src = src_p;
+	
+	dest[0] = bswap_32(src[2]);
+	dest[1] = bswap_32(src[1]);
+	dest[2] = bswap_32(src[0]);
+}
+
 #define flip32(dest_p, src_p) swap32yes(dest_p, src_p, 32 / 4)
 
 #define WATCHDOG_INTERVAL  2