miner.h 3.1 KB

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