miner.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef __MINER_H__
  2. #define __MINER_H__
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include <sys/time.h>
  6. #include <pthread.h>
  7. #include <jansson.h>
  8. #include <curl/curl.h>
  9. #ifdef __SSE2__
  10. #define WANT_SSE2_4WAY 1
  11. #endif
  12. #if defined(__i386__) || defined(__x86_64__)
  13. #define WANT_VIA_PADLOCK 1
  14. #endif
  15. #if defined(__x86_64__) && defined(__SSE2__) && defined(HAS_YASM)
  16. #define WANT_X8664_SSE2 1
  17. #endif
  18. #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
  19. #define WANT_BUILTIN_BSWAP
  20. #else
  21. #include <byteswap.h>
  22. #endif
  23. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  24. #undef unlikely
  25. #define unlikely(expr) (__builtin_expect((expr), 0))
  26. #else
  27. #undef unlikely
  28. #define unlikely(expr) (expr)
  29. #endif
  30. #if defined(__i386__)
  31. #define WANT_CRYPTOPP_ASM32
  32. #endif
  33. #ifndef ARRAY_SIZE
  34. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  35. #endif
  36. static inline uint32_t swab32(uint32_t v)
  37. {
  38. #ifdef WANT_BUILTIN_BSWAP
  39. return __builtin_bswap32(v);
  40. #else
  41. return bswap_32(v);
  42. #endif
  43. }
  44. static inline void swap256(void *dest_p, const void *src_p)
  45. {
  46. uint32_t *dest = dest_p;
  47. const uint32_t *src = src_p;
  48. dest[0] = src[7];
  49. dest[1] = src[6];
  50. dest[2] = src[5];
  51. dest[3] = src[4];
  52. dest[4] = src[3];
  53. dest[5] = src[2];
  54. dest[6] = src[1];
  55. dest[7] = src[0];
  56. }
  57. extern bool opt_debug;
  58. extern bool opt_protocol;
  59. extern const uint32_t sha256_init_state[];
  60. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  61. const char *rpc_req);
  62. extern char *bin2hex(const unsigned char *p, size_t len);
  63. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  64. extern unsigned int ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
  65. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  66. const unsigned char *ptarget,
  67. uint32_t max_nonce, unsigned long *nHashesDone);
  68. extern unsigned int scanhash_sse2_amd64(int, const unsigned char *pmidstate,
  69. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  70. const unsigned char *ptarget,
  71. uint32_t max_nonce, unsigned long *nHashesDone);
  72. extern bool scanhash_via(int, unsigned char *data_inout,
  73. const unsigned char *target,
  74. uint32_t max_nonce, unsigned long *hashes_done);
  75. extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
  76. unsigned char *hash1, unsigned char *hash,
  77. const unsigned char *target,
  78. uint32_t max_nonce, unsigned long *hashes_done);
  79. extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
  80. unsigned char *hash1, unsigned char *hash,
  81. const unsigned char *target,
  82. uint32_t max_nonce, unsigned long *hashes_done);
  83. extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
  84. unsigned char *hash1, unsigned char *hash,
  85. const unsigned char *target,
  86. uint32_t max_nonce, unsigned long *hashes_done);
  87. extern int scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
  88. unsigned char *phash1, unsigned char *phash,
  89. const unsigned char *ptarget,
  90. uint32_t max_nonce, unsigned long *nHashesDone);
  91. extern int
  92. timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
  93. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  94. struct thread_q;
  95. struct work_restart {
  96. volatile unsigned long restart;
  97. };
  98. extern struct work_restart *work_restart;
  99. extern void restart_threads(void);
  100. extern struct thread_q *tq_new(void);
  101. extern void tq_free(struct thread_q *tq);
  102. extern bool tq_push(struct thread_q *tq, void *data);
  103. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  104. extern void tq_freeze(struct thread_q *tq);
  105. extern void tq_thaw(struct thread_q *tq);
  106. #endif /* __MINER_H__ */