Commit 713e8be629402915e9b9918c65bce2bf50a178e5

zefir 2012-02-04T14:22:47

move CPU chipset specific optimization into device-cpu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
diff --git a/api.c b/api.c
index ac34ff4..b2013f8 100644
--- a/api.c
+++ b/api.c
@@ -20,6 +20,7 @@
 
 #include "compat.h"
 #include "miner.h"
+#include "device-cpu.h" /* for algo_names[], TODO: re-factor dependency */
 
 #if defined(unix) || defined(__APPLE__)
 	#include <errno.h>
diff --git a/cgminer.c b/cgminer.c
index 9275459..3110e0a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -42,9 +42,6 @@
 #include "compat.h"
 #include "miner.h"
 #include "findnonce.h"
-#include "bench_block.h"
-#include "ocl.h"
-#include "uthash.h"
 #include "adl.h"
 #include "device-cpu.h"
 #include "device-gpu.h"
diff --git a/device-cpu.c b/device-cpu.c
index 2bc9251..9faf236 100644
--- a/device-cpu.c
+++ b/device-cpu.c
@@ -81,6 +81,60 @@ extern char *set_int_range(const char *arg, int *i, int min, int max);
 extern int dev_from_id(int thr_id);
 
 
+/* chipset-optimized hash functions */
+extern bool ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
+	unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
+	const unsigned char *ptarget,
+	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
+
+extern bool ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
+	unsigned char *pdata,
+	unsigned char *phash1, unsigned char *phash,
+	const unsigned char *ptarget,
+	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
+
+extern bool scanhash_via(int, const unsigned char *pmidstate,
+	unsigned char *pdata,
+	unsigned char *phash1, unsigned char *phash,
+	const unsigned char *target,
+	uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
+
+extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
+	      unsigned char *hash1, unsigned char *hash,
+	      const unsigned char *target,
+	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
+
+extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
+	      unsigned char *hash1, unsigned char *hash,
+	      const unsigned char *target,
+	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
+
+extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
+	      unsigned char *hash1, unsigned char *hash,
+	      const unsigned char *target,
+	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
+
+extern bool scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
+	unsigned char *phash1, unsigned char *phash,
+	const unsigned char *ptarget,
+	uint32_t max_nonce, uint32_t *last_nonce,
+	uint32_t nonce);
+
+extern bool scanhash_sse4_64(int, const unsigned char *pmidstate, unsigned char *pdata,
+	unsigned char *phash1, unsigned char *phash,
+	const unsigned char *ptarget,
+	uint32_t max_nonce, uint32_t *last_nonce,
+	uint32_t nonce);
+
+extern bool scanhash_sse2_32(int, const unsigned char *pmidstate, unsigned char *pdata,
+	unsigned char *phash1, unsigned char *phash,
+	const unsigned char *ptarget,
+	uint32_t max_nonce, uint32_t *last_nonce,
+	uint32_t nonce);
+
+
+
+
 #ifdef WANT_CPUMINE
 static size_t max_name_len = 0;
 static char *name_spaces_pad = NULL;
diff --git a/device-cpu.h b/device-cpu.h
index c2c8f3a..59d7557 100644
--- a/device-cpu.h
+++ b/device-cpu.h
@@ -1,12 +1,51 @@
 #ifndef __DEVICE_CPU_H__
 #define __DEVICE_CPU_H__
 
-#include "miner.h"
+#include "miner.h" /* for work_restart, TODO: re-factor dependency */
+
+#include "config.h"
+#include <stdbool.h>
 
 #ifndef OPT_SHOW_LEN
 #define OPT_SHOW_LEN 80
 #endif
 
+#ifdef __SSE2__
+#define WANT_SSE2_4WAY 1
+#endif
+
+#ifdef __ALTIVEC__
+#define WANT_ALTIVEC_4WAY 1
+#endif
+
+#if defined(__i386__) && defined(HAS_YASM) && defined(__SSE2__)
+#define WANT_X8632_SSE2 1
+#endif
+
+#if (defined(__i386__) || defined(__x86_64__)) &&  !defined(__APPLE__)
+#define WANT_VIA_PADLOCK 1
+#endif
+
+#if defined(__x86_64__) && defined(HAS_YASM)
+#define WANT_X8664_SSE2 1
+#endif
+
+#if defined(__x86_64__) && defined(HAS_YASM)
+#define WANT_X8664_SSE4 1
+#endif
+
+enum sha256_algos {
+	ALGO_C,			/* plain C */
+	ALGO_4WAY,		/* parallel SSE2 */
+	ALGO_VIA,		/* VIA padlock */
+	ALGO_CRYPTOPP,		/* Crypto++ (C) */
+	ALGO_CRYPTOPP_ASM32,	/* Crypto++ 32-bit assembly */
+	ALGO_SSE2_32,		/* SSE2 for x86_32 */
+	ALGO_SSE2_64,		/* SSE2 for x86_64 */
+	ALGO_SSE4_64,		/* SSE4 for x86_64 */
+	ALGO_ALTIVEC_4WAY,	/* parallel Altivec */
+};
+
 extern const char *algo_names[];
 extern bool opt_usecpu;
 extern struct device_api cpu_api;
diff --git a/device-gpu.c b/device-gpu.c
index 44697e0..e9c9d78 100644
--- a/device-gpu.c
+++ b/device-gpu.c
@@ -26,7 +26,7 @@
 
 #include "compat.h"
 #include "miner.h"
-#include "device-cpu.h"
+#include "device-gpu.h"
 #include "findnonce.h"
 #include "ocl.h"
 #include "adl.h"
@@ -58,6 +58,12 @@ extern void decay_time(double *f, double fadd);
 
 /**********************************************/
 
+#ifdef HAVE_ADL
+extern float gpu_temp(int gpu);
+extern int gpu_fanspeed(int gpu);
+extern int gpu_fanpercent(int gpu);
+#endif
+
 
 #ifdef HAVE_OPENCL
 char *set_vector(const char *arg, int *i)
diff --git a/device-gpu.h b/device-gpu.h
index 84a855a..46108e7 100644
--- a/device-gpu.h
+++ b/device-gpu.h
@@ -20,6 +20,7 @@ void manage_gpu(void);
 extern void pause_dynamic_threads(int gpu);
 
 extern bool have_opencl;
+extern int opt_platform_id;
 
 extern struct device_api opencl_api;
 
diff --git a/findnonce.c b/findnonce.c
index 2781dd6..61bc82b 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -16,9 +16,7 @@
 #include <pthread.h>
 #include <string.h>
 
-#include "ocl.h"
 #include "findnonce.h"
-#include "miner.h"
 
 const uint32_t SHA256_K[64] = {
 	0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
diff --git a/miner.h b/miner.h
index 6905088..72fdb24 100644
--- a/miner.h
+++ b/miner.h
@@ -60,30 +60,6 @@ void *alloca (size_t);
  #include "ADL_SDK/adl_sdk.h"
 #endif
 
-#ifdef __SSE2__
-#define WANT_SSE2_4WAY 1
-#endif
-
-#ifdef __ALTIVEC__
-#define WANT_ALTIVEC_4WAY 1
-#endif
-
-#if defined(__i386__) && defined(HAS_YASM) && defined(__SSE2__)
-#define WANT_X8632_SSE2 1
-#endif
-
-#if (defined(__i386__) || defined(__x86_64__)) &&  !defined(__APPLE__)
-#define WANT_VIA_PADLOCK 1
-#endif
-
-#if defined(__x86_64__) && defined(HAS_YASM)
-#define WANT_X8664_SSE2 1
-#endif
-
-#if defined(__x86_64__) && defined(HAS_YASM)
-#define WANT_X8664_SSE4 1
-#endif
-
 #if !defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
 #define bswap_16 __builtin_bswap16
 #define bswap_32 __builtin_bswap32
@@ -157,19 +133,6 @@ enum {
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 
-enum sha256_algos {
-	ALGO_C,			/* plain C */
-	ALGO_4WAY,		/* parallel SSE2 */
-	ALGO_VIA,		/* VIA padlock */
-	ALGO_CRYPTOPP,		/* Crypto++ (C) */
-	ALGO_CRYPTOPP_ASM32,	/* Crypto++ 32-bit assembly */
-	ALGO_SSE2_32,		/* SSE2 for x86_32 */
-	ALGO_SSE2_64,		/* SSE2 for x86_64 */
-	ALGO_SSE4_64,		/* SSE4 for x86_64 */
-	ALGO_ALTIVEC_4WAY,	/* parallel Altivec */
-};
-
-
 enum alive {
 	LIFE_WELL,
 	LIFE_SICK,
@@ -473,56 +436,6 @@ typedef bool (*sha256_func)(int thr_id, const unsigned char *pmidstate,
 	uint32_t *last_nonce,
 	uint32_t nonce);
 
-extern bool ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
-	unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
-	const unsigned char *ptarget,
-	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
-
-extern bool ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
-	unsigned char *pdata,
-	unsigned char *phash1, unsigned char *phash,
-	const unsigned char *ptarget,
-	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
-
-extern bool scanhash_via(int, const unsigned char *pmidstate,
-	unsigned char *pdata,
-	unsigned char *phash1, unsigned char *phash,
-	const unsigned char *target,
-	uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
-
-extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
-	      unsigned char *hash1, unsigned char *hash,
-	      const unsigned char *target,
-	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
-
-extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
-	      unsigned char *hash1, unsigned char *hash,
-	      const unsigned char *target,
-	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
-
-extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
-	      unsigned char *hash1, unsigned char *hash,
-	      const unsigned char *target,
-	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
-
-extern bool scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
-	unsigned char *phash1, unsigned char *phash,
-	const unsigned char *ptarget,
-	uint32_t max_nonce, uint32_t *last_nonce,
-	uint32_t nonce);
-
-extern bool scanhash_sse4_64(int, const unsigned char *pmidstate, unsigned char *pdata,
-	unsigned char *phash1, unsigned char *phash,
-	const unsigned char *ptarget,
-	uint32_t max_nonce, uint32_t *last_nonce,
-	uint32_t nonce);
-
-extern bool scanhash_sse2_32(int, const unsigned char *pmidstate, unsigned char *pdata,
-	unsigned char *phash1, unsigned char *phash,
-	const unsigned char *ptarget,
-	uint32_t max_nonce, uint32_t *last_nonce,
-	uint32_t nonce);
-
 extern int
 timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
 
@@ -542,9 +455,6 @@ extern void kill_work(void);
 extern void reinit_device(struct cgpu_info *cgpu);
 
 #ifdef HAVE_ADL
-extern float gpu_temp(int gpu);
-extern int gpu_fanspeed(int gpu);
-extern int gpu_fanpercent(int gpu);
 extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
 extern int set_fanspeed(int gpu, int iFanSpeed);
 extern int set_vddc(int gpu, float fVddc);
diff --git a/ocl.h b/ocl.h
index 1a2b80d..9718a96 100644
--- a/ocl.h
+++ b/ocl.h
@@ -30,6 +30,5 @@ typedef struct {
 extern char *file_contents(const char *filename, int *length);
 extern int clDevicesNum(void);
 extern _clState *initCl(unsigned int gpu, char *name, size_t nameSize);
-extern int opt_platform_id;
 #endif /* HAVE_OPENCL */
 #endif /* __OCL_H__ */
diff --git a/sha256_4way.c b/sha256_4way.c
index 15e852a..7bad83b 100644
--- a/sha256_4way.c
+++ b/sha256_4way.c
@@ -4,8 +4,7 @@
 
 // tcatm's 4-way 128-bit SSE2 SHA-256
 
-#include "config.h"
-#include "miner.h"
+#include "device-cpu.h"
 
 #ifdef WANT_SSE2_4WAY
 
diff --git a/sha256_altivec_4way.c b/sha256_altivec_4way.c
index aa50486..13cafba 100644
--- a/sha256_altivec_4way.c
+++ b/sha256_altivec_4way.c
@@ -9,8 +9,7 @@
 //
 
 
-//#include "config.h"
-#include "miner.h"
+#include "device-cpu.h"
 
 #ifdef WANT_ALTIVEC_4WAY
 
diff --git a/sha256_sse2_amd64.c b/sha256_sse2_amd64.c
index 5c82314..952431b 100644
--- a/sha256_sse2_amd64.c
+++ b/sha256_sse2_amd64.c
@@ -9,9 +9,7 @@
  *
  */
 
-#include "config.h"
-
-#include "miner.h"
+#include "device-cpu.h"
 
 #ifdef WANT_X8664_SSE2
 
diff --git a/sha256_sse2_i386.c b/sha256_sse2_i386.c
index 321626f..1a4bb2f 100644
--- a/sha256_sse2_i386.c
+++ b/sha256_sse2_i386.c
@@ -9,9 +9,7 @@
  *
  */
 
-#include "config.h"
-
-#include "miner.h"
+#include "device-cpu.h"
 
 #ifdef WANT_X8632_SSE2
 
diff --git a/sha256_sse4_amd64.c b/sha256_sse4_amd64.c
index 67e0604..b08a2a1 100644
--- a/sha256_sse4_amd64.c
+++ b/sha256_sse4_amd64.c
@@ -9,9 +9,7 @@
  *
  */
 
-#include "config.h"
-
-#include "miner.h"
+#include "device-cpu.h"
 
 #ifdef WANT_X8664_SSE4
 
diff --git a/sha256_via.c b/sha256_via.c
index 550807c..b74c272 100644
--- a/sha256_via.c
+++ b/sha256_via.c
@@ -1,5 +1,5 @@
 
-#include "config.h"
+#include "device-cpu.h"
 
 #include <stdint.h>
 #include <stdlib.h>