miner.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  79. #undef unlikely
  80. #define unlikely(expr) (__builtin_expect((expr), 0))
  81. #else
  82. #undef unlikely
  83. #define unlikely(expr) (expr)
  84. #endif
  85. #if defined(__i386__)
  86. #define WANT_CRYPTOPP_ASM32
  87. #endif
  88. #ifndef ARRAY_SIZE
  89. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  90. #endif
  91. struct thr_info {
  92. int id;
  93. pthread_t pth;
  94. struct thread_q *q;
  95. };
  96. static inline uint32_t swab32(uint32_t v)
  97. {
  98. #ifdef WANT_BUILTIN_BSWAP
  99. return __builtin_bswap32(v);
  100. #else
  101. return bswap_32(v);
  102. #endif
  103. }
  104. static inline void swap256(void *dest_p, const void *src_p)
  105. {
  106. uint32_t *dest = dest_p;
  107. const uint32_t *src = src_p;
  108. dest[0] = src[7];
  109. dest[1] = src[6];
  110. dest[2] = src[5];
  111. dest[3] = src[4];
  112. dest[4] = src[3];
  113. dest[5] = src[2];
  114. dest[6] = src[1];
  115. dest[7] = src[0];
  116. }
  117. extern bool opt_debug;
  118. extern bool opt_protocol;
  119. extern const uint32_t sha256_init_state[];
  120. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  121. const char *rpc_req, bool, bool);
  122. extern char *bin2hex(const unsigned char *p, size_t len);
  123. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  124. extern unsigned int ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
  125. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  126. const unsigned char *ptarget,
  127. uint32_t max_nonce, unsigned long *nHashesDone);
  128. extern unsigned int scanhash_sse2_amd64(int, const unsigned char *pmidstate,
  129. unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
  130. const unsigned char *ptarget,
  131. uint32_t max_nonce, unsigned long *nHashesDone);
  132. extern bool scanhash_via(int, unsigned char *data_inout,
  133. const unsigned char *target,
  134. uint32_t max_nonce, unsigned long *hashes_done);
  135. extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
  136. unsigned char *hash1, unsigned char *hash,
  137. const unsigned char *target,
  138. uint32_t max_nonce, unsigned long *hashes_done);
  139. extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
  140. unsigned char *hash1, unsigned char *hash,
  141. const unsigned char *target,
  142. uint32_t max_nonce, unsigned long *hashes_done);
  143. extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
  144. unsigned char *hash1, unsigned char *hash,
  145. const unsigned char *target,
  146. uint32_t max_nonce, unsigned long *hashes_done);
  147. extern int scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
  148. unsigned char *phash1, unsigned char *phash,
  149. const unsigned char *ptarget,
  150. uint32_t max_nonce, unsigned long *nHashesDone);
  151. extern int
  152. timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
  153. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  154. extern int opt_scantime;
  155. extern bool want_longpoll;
  156. extern bool have_longpoll;
  157. struct thread_q;
  158. struct work_restart {
  159. volatile unsigned long restart;
  160. char padding[128 - sizeof(unsigned long)];
  161. };
  162. extern pthread_mutex_t time_lock;
  163. extern bool use_syslog;
  164. extern struct thr_info *thr_info;
  165. extern int longpoll_thr_id;
  166. extern struct work_restart *work_restart;
  167. extern void applog(int prio, const char *fmt, ...);
  168. extern struct thread_q *tq_new(void);
  169. extern void tq_free(struct thread_q *tq);
  170. extern bool tq_push(struct thread_q *tq, void *data);
  171. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  172. extern void tq_freeze(struct thread_q *tq);
  173. extern void tq_thaw(struct thread_q *tq);
  174. #endif /* __MINER_H__ */