miner.h 2.6 KB

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