miner.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef __MINER_H__
  2. #define __MINER_H__
  3. #include "cpuminer-config.h"
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. #include <sys/time.h>
  7. #include <pthread.h>
  8. #include <jansson.h>
  9. #include <curl/curl.h>
  10. #ifdef STDC_HEADERS
  11. # include <stdlib.h>
  12. # include <stddef.h>
  13. #else
  14. # ifdef HAVE_STDLIB_H
  15. # include <stdlib.h>
  16. # endif
  17. #endif
  18. #ifdef HAVE_ALLOCA_H
  19. # include <alloca.h>
  20. #elif defined __GNUC__
  21. # define alloca __builtin_alloca
  22. #elif defined _AIX
  23. # define alloca __alloca
  24. #elif defined _MSC_VER
  25. # include <malloc.h>
  26. # define alloca _alloca
  27. #else
  28. # ifndef HAVE_ALLOCA
  29. # ifdef __cplusplus
  30. extern "C"
  31. # endif
  32. void *alloca (size_t);
  33. # endif
  34. #endif
  35. #ifdef __SSE2__
  36. #define WANT_SSE2_4WAY 1
  37. #endif
  38. #if defined(__i386__) || defined(__x86_64__)
  39. #define WANT_VIA_PADLOCK 1
  40. #endif
  41. #if defined(__x86_64__) && defined(__SSE2__) && defined(HAS_YASM)
  42. #define WANT_X8664_SSE2 1
  43. #endif
  44. #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
  45. #define WANT_BUILTIN_BSWAP
  46. #else
  47. #include <byteswap.h>
  48. #endif
  49. #ifdef HAVE_SYSLOG_H
  50. #include <syslog.h>
  51. #else
  52. enum {
  53. LOG_ERR,
  54. LOG_WARNING,
  55. LOG_INFO,
  56. LOG_DEBUG,
  57. };
  58. #endif
  59. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  60. #undef unlikely
  61. #define unlikely(expr) (__builtin_expect((expr), 0))
  62. #else
  63. #undef unlikely
  64. #define unlikely(expr) (expr)
  65. #endif
  66. #if defined(__i386__)
  67. #define WANT_CRYPTOPP_ASM32
  68. #endif
  69. #ifndef ARRAY_SIZE
  70. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  71. #endif
  72. struct thr_info {
  73. int id;
  74. pthread_t pth;
  75. struct thread_q *q;
  76. };
  77. static inline uint32_t swab32(uint32_t v)
  78. {
  79. #ifdef WANT_BUILTIN_BSWAP
  80. return __builtin_bswap32(v);
  81. #else
  82. return bswap_32(v);
  83. #endif
  84. }
  85. static inline void swap256(void *dest_p, const void *src_p)
  86. {
  87. uint32_t *dest = dest_p;
  88. const uint32_t *src = src_p;
  89. dest[0] = src[7];
  90. dest[1] = src[6];
  91. dest[2] = src[5];
  92. dest[3] = src[4];
  93. dest[4] = src[3];
  94. dest[5] = src[2];
  95. dest[6] = src[1];
  96. dest[7] = src[0];
  97. }
  98. extern bool opt_debug;
  99. extern bool opt_protocol;
  100. extern const uint32_t sha256_init_state[];
  101. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  102. const char *rpc_req, bool, bool);
  103. extern char *bin2hex(const unsigned char *p, size_t len);
  104. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  105. extern unsigned int ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
  106. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  107. const unsigned char *ptarget,
  108. uint32_t max_nonce, unsigned long *nHashesDone);
  109. extern unsigned int scanhash_sse2_amd64(int, const unsigned char *pmidstate,
  110. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  111. const unsigned char *ptarget,
  112. uint32_t max_nonce, unsigned long *nHashesDone);
  113. extern bool scanhash_via(int, unsigned char *data_inout,
  114. const unsigned char *target,
  115. uint32_t max_nonce, unsigned long *hashes_done);
  116. extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
  117. unsigned char *hash1, unsigned char *hash,
  118. const unsigned char *target,
  119. uint32_t max_nonce, unsigned long *hashes_done);
  120. extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
  121. unsigned char *hash1, unsigned char *hash,
  122. const unsigned char *target,
  123. uint32_t max_nonce, unsigned long *hashes_done);
  124. extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
  125. unsigned char *hash1, unsigned char *hash,
  126. const unsigned char *target,
  127. uint32_t max_nonce, unsigned long *hashes_done);
  128. extern int scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
  129. unsigned char *phash1, unsigned char *phash,
  130. const unsigned char *ptarget,
  131. uint32_t max_nonce, unsigned long *nHashesDone);
  132. extern int
  133. timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
  134. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  135. extern int opt_scantime;
  136. extern bool want_longpoll;
  137. extern bool have_longpoll;
  138. struct thread_q;
  139. struct work_restart {
  140. volatile unsigned long restart;
  141. char padding[128 - sizeof(unsigned long)];
  142. };
  143. extern pthread_mutex_t time_lock;
  144. extern bool use_syslog;
  145. extern struct thr_info *thr_info;
  146. extern int longpoll_thr_id;
  147. extern struct work_restart *work_restart;
  148. extern void applog(int prio, const char *fmt, ...);
  149. extern struct thread_q *tq_new(void);
  150. extern void tq_free(struct thread_q *tq);
  151. extern bool tq_push(struct thread_q *tq, void *data);
  152. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  153. extern void tq_freeze(struct thread_q *tq);
  154. extern void tq_thaw(struct thread_q *tq);
  155. #endif /* __MINER_H__ */