Browse Source

Merge branch '20130530_portablecpu' into bfgminer

Luke Dashjr 12 years ago
parent
commit
0e187354f5
5 changed files with 43 additions and 24 deletions
  1. 7 3
      Makefile.am
  2. 5 1
      README
  3. 22 15
      driver-cpu.c
  4. 8 5
      driver-cpu.h
  5. 1 0
      miner.c

+ 7 - 3
Makefile.am

@@ -72,13 +72,17 @@ bfgminer_SOURCES += scrypt.c scrypt.h
 endif
 
 if HAS_CPUMINE
-# original CPU related sources, unchanged
 bfgminer_SOURCES	+= \
-		  sha256_generic.c sha256_4way.c sha256_via.c	\
+		  sha256_generic.c sha256_via.c	\
 		  sha256_cryptopp.c sha256_sse2_amd64.c		\
-		  sha256_sse4_amd64.c sha256_sse2_i386.c	\
+		  sha256_sse4_amd64.c 	\
 		  sha256_altivec_4way.c
 
+bfgminer_LDADD += libsse2cpuminer.a
+noinst_LIBRARIES = libsse2cpuminer.a
+libsse2cpuminer_a_SOURCES = sha256_4way.c sha256_sse2_i386.c
+libsse2cpuminer_a_CFLAGS = $(bfgminer_CPPFLAGS) -msse2
+
 # the CPU portion extracted from original main.c
 bfgminer_SOURCES += driver-cpu.h driver-cpu.c
 

+ 5 - 1
README

@@ -298,13 +298,17 @@ For other FPGA details see the README.FPGA
 CPU only options (not included in binaries):
 
 --algo|-a <arg>     Specify sha256 implementation for CPU mining:
+        fastauto*       Quick benchmark at startup to pick a working algorithm
         auto            Benchmark at startup and pick fastest algorithm
         c               Linux kernel sha256, implemented in C
         4way            tcatm's 4-way SSE2 implementation
         via             VIA padlock implementation
         cryptopp        Crypto++ C/C++ implementation
+        cryptopp_asm32  Crypto++ 32-bit assembler implementation
+        sse2_32         SSE2 32 bit implementation for i386 machines
         sse2_64         SSE2 64 bit implementation for x86_64 machines
-        sse4_64         SSE4.1 64 bit implementation for x86_64 machines (default: sse2_64)
+        sse4_64         SSE4.1 64 bit implementation for x86_64 machines
+        altivec_4way    Altivec implementation for PowerPC G4 and G5 machines
 --cpu-threads|-t <arg> Number of miner CPU threads (default: 4)
 --enable-cpu|-C     Enable CPU mining with other mining (default: no CPU mining if other devices exist)
 

+ 22 - 15
driver-cpu.c

@@ -166,6 +166,8 @@ const char *algo_names[] = {
 #ifdef WANT_SCRYPT
     [ALGO_SCRYPT] = "scrypt",
 #endif
+	[ALGO_FASTAUTO] = "fastauto",
+	[ALGO_AUTO] = "auto",
 };
 
 static const sha256_func sha256_funcs[] = {
@@ -201,15 +203,7 @@ static const sha256_func sha256_funcs[] = {
 
 
 #ifdef WANT_CPUMINE
-#if defined(WANT_X8664_SSE4) && defined(__SSE4_1__)
-enum sha256_algos opt_algo = ALGO_SSE4_64;
-#elif defined(WANT_X8664_SSE2) && defined(__SSE2__)
-enum sha256_algos opt_algo = ALGO_SSE2_64;
-#elif defined(WANT_X8632_SSE2) && defined(__SSE2__)
-enum sha256_algos opt_algo = ALGO_SSE2_32;
-#else
-enum sha256_algos opt_algo = ALGO_C;
-#endif
+enum sha256_algos opt_algo = ALGO_FASTAUTO;
 bool opt_usecpu = false;
 static bool forced_n_threads;
 #endif
@@ -245,7 +239,7 @@ double bench_algo_stage3(
 
 	struct timeval end;
 	struct timeval start;
-	uint32_t max_nonce = (1<<22);
+	uint32_t max_nonce = opt_algo == ALGO_FASTAUTO ? (1<<8) : (1<<22);
 	uint32_t last_nonce = 0;
 
 	memcpy(&hash1[0], &hash1_init[0], sizeof(hash1));
@@ -684,11 +678,6 @@ char *set_algo(const char *arg, enum sha256_algos *algo)
 	if (opt_scrypt)
 		return "Can only use scrypt algorithm";
 
-	if (!strcmp(arg, "auto")) {
-		*algo = pick_fastest_algo();
-		return NULL;
-	}
-
 	for (i = 0; i < ARRAY_SIZE(algo_names); i++) {
 		if (algo_names[i] && !strcmp(arg, algo_names[i])) {
 			*algo = i;
@@ -780,8 +769,15 @@ static void cpu_detect()
 	}
 }
 
+static pthread_mutex_t cpualgo_lock;
+
 static bool cpu_thread_prepare(struct thr_info *thr)
 {
+	struct cgpu_info *cgpu = thr->cgpu;
+	
+	if (!(cgpu->device_id || thr->device_thread || cgpu->proc_id))
+		mutex_init(&cpualgo_lock);
+	
 	thread_reportin(thr);
 
 	return true;
@@ -796,6 +792,17 @@ static bool cpu_thread_init(struct thr_info *thr)
 {
 	const int thr_id = thr->id;
 
+	mutex_lock(&cpualgo_lock);
+	switch (opt_algo)
+	{
+		case ALGO_AUTO:
+		case ALGO_FASTAUTO:
+			opt_algo = pick_fastest_algo();
+		default:
+			break;
+	}
+	mutex_unlock(&cpualgo_lock);
+
 	/* Set worker threads to nice 19 and then preferentially to SCHED_IDLE
 	 * and if that fails, then SCHED_BATCH. No need for this to be an
 	 * error if it fails */

+ 8 - 5
driver-cpu.h

@@ -10,7 +10,7 @@
 #define OPT_SHOW_LEN 80
 #endif
 
-#ifdef __SSE2__
+#ifdef __i386__
 #define WANT_SSE2_4WAY 1
 #endif
 
@@ -18,19 +18,19 @@
 #define WANT_ALTIVEC_4WAY 1
 #endif
 
-#if defined(__i386__) && defined(HAS_YASM) && defined(__SSE2__)
+#ifdef __i386__
 #define WANT_X8632_SSE2 1
 #endif
 
-#if (defined(__i386__) || defined(__x86_64__)) &&  !defined(__APPLE__)
+#ifdef __i386__
 #define WANT_VIA_PADLOCK 1
 #endif
 
-#if defined(__x86_64__) && defined(HAS_YASM)
+#ifdef __x86_64__
 #define WANT_X8664_SSE2 1
 #endif
 
-#if defined(__x86_64__) && defined(HAS_YASM) && defined(__SSE4_1__)
+#ifdef __x86_64__
 #define WANT_X8664_SSE4 1
 #endif
 
@@ -49,6 +49,9 @@ enum sha256_algos {
 	ALGO_SSE4_64,		/* SSE4 for x86_64 */
 	ALGO_ALTIVEC_4WAY,	/* parallel Altivec */
 	ALGO_SCRYPT,		/* scrypt */
+	
+	ALGO_FASTAUTO,		/* fast autodetect */
+	ALGO_AUTO		/* autodetect */
 };
 
 extern const char *algo_names[];

+ 1 - 0
miner.c

@@ -1124,6 +1124,7 @@ static struct opt_table opt_config_table[] = {
 	OPT_WITH_ARG("--algo|-a",
 		     set_algo, show_algo, &opt_algo,
 		     "Specify sha256 implementation for CPU mining:\n"
+		     "\tfastauto*\tQuick benchmark at startup to pick a working algorithm\n"
 		     "\tauto\t\tBenchmark at startup and pick fastest algorithm"
 		     "\n\tc\t\tLinux kernel sha256, implemented in C"
 #ifdef WANT_SSE2_4WAY