miner.h 4.5 KB

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