miner.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #if HAVE_BYTESWAP_H
  48. #include <byteswap.h>
  49. #elif defined(USE_SYS_ENDIAN_H)
  50. #include <sys/endian.h>
  51. #elif defined(__APPLE__)
  52. #include <libkern/OSByteOrder.h>
  53. #define bswap_16 OSSwapInt16
  54. #define bswap_32 OSSwapInt32
  55. #define bswap_64 OSSwapInt64
  56. #else
  57. #define bswap_16(value) \
  58. ((((value) & 0xff) << 8) | ((value) >> 8))
  59. #define bswap_32(value) \
  60. (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
  61. (uint32_t)bswap_16((uint16_t)((value) >> 16)))
  62. #define bswap_64(value) \
  63. (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
  64. << 32) | \
  65. (uint64_t)bswap_32((uint32_t)((value) >> 32)))
  66. #endif
  67. #endif /* !defined(__GLXBYTEORDER_H__) */
  68. #ifdef HAVE_SYSLOG_H
  69. #include <syslog.h>
  70. #else
  71. enum {
  72. LOG_ERR,
  73. LOG_WARNING,
  74. LOG_INFO,
  75. LOG_DEBUG,
  76. };
  77. #endif
  78. #undef unlikely
  79. #undef likely
  80. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  81. #define unlikely(expr) (__builtin_expect(!!(expr), 0))
  82. #define likely(expr) (__builtin_expect(!!(expr), 1))
  83. #else
  84. #define unlikely(expr) (expr)
  85. #define likely(expr) (expr)
  86. #endif
  87. #if defined(__i386__)
  88. #define WANT_CRYPTOPP_ASM32
  89. #endif
  90. #ifndef ARRAY_SIZE
  91. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  92. #endif
  93. struct thr_info {
  94. int id;
  95. pthread_t pth;
  96. struct thread_q *q;
  97. };
  98. static inline uint32_t swab32(uint32_t v)
  99. {
  100. #ifdef WANT_BUILTIN_BSWAP
  101. return __builtin_bswap32(v);
  102. #else
  103. return bswap_32(v);
  104. #endif
  105. }
  106. static inline void swap256(void *dest_p, const void *src_p)
  107. {
  108. uint32_t *dest = dest_p;
  109. const uint32_t *src = src_p;
  110. dest[0] = src[7];
  111. dest[1] = src[6];
  112. dest[2] = src[5];
  113. dest[3] = src[4];
  114. dest[4] = src[3];
  115. dest[5] = src[2];
  116. dest[6] = src[1];
  117. dest[7] = src[0];
  118. }
  119. extern bool opt_debug;
  120. extern bool opt_protocol;
  121. extern const uint32_t sha256_init_state[];
  122. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  123. const char *rpc_req, bool, bool);
  124. extern char *bin2hex(const unsigned char *p, size_t len);
  125. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  126. extern unsigned int ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
  127. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  128. const unsigned char *ptarget,
  129. uint32_t max_nonce, unsigned long *nHashesDone);
  130. extern unsigned int scanhash_sse2_amd64(int, const unsigned char *pmidstate,
  131. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  132. const unsigned char *ptarget,
  133. uint32_t max_nonce, unsigned long *nHashesDone);
  134. extern bool scanhash_via(int, unsigned char *data_inout,
  135. const unsigned char *target,
  136. uint32_t max_nonce, unsigned long *hashes_done);
  137. extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
  138. unsigned char *hash1, unsigned char *hash,
  139. const unsigned char *target,
  140. uint32_t max_nonce, unsigned long *hashes_done);
  141. extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
  142. unsigned char *hash1, unsigned char *hash,
  143. const unsigned char *target,
  144. uint32_t max_nonce, unsigned long *hashes_done);
  145. extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
  146. unsigned char *hash1, unsigned char *hash,
  147. const unsigned char *target,
  148. uint32_t max_nonce, unsigned long *hashes_done);
  149. extern int scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
  150. unsigned char *phash1, unsigned char *phash,
  151. const unsigned char *ptarget,
  152. uint32_t max_nonce, unsigned long *nHashesDone);
  153. extern int
  154. timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
  155. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  156. extern int opt_scantime;
  157. extern bool want_longpoll;
  158. extern bool have_longpoll;
  159. struct thread_q;
  160. struct work_restart {
  161. volatile unsigned long restart;
  162. char padding[128 - sizeof(unsigned long)];
  163. };
  164. extern pthread_mutex_t time_lock;
  165. extern bool use_syslog;
  166. extern struct thr_info *thr_info;
  167. extern int longpoll_thr_id;
  168. extern struct work_restart *work_restart;
  169. extern void applog(int prio, const char *fmt, ...);
  170. extern struct thread_q *tq_new(void);
  171. extern void tq_free(struct thread_q *tq);
  172. extern bool tq_push(struct thread_q *tq, void *data);
  173. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  174. extern void tq_freeze(struct thread_q *tq);
  175. extern void tq_thaw(struct thread_q *tq);
  176. #endif /* __MINER_H__ */