Merge integer unpacking code
This commit is contained in:
commit
1cf20a8348
58
blkmaker.c
58
blkmaker.c
@ -49,6 +49,35 @@ bool _blkmk_dblsha256(void *hash, const void *data, size_t datasz) {
|
||||
|
||||
#define max_varint_size (9)
|
||||
|
||||
static
|
||||
char varintEncode(unsigned char *out, uint64_t n) {
|
||||
if (n < 0xfd)
|
||||
{
|
||||
out[0] = n;
|
||||
return 1;
|
||||
}
|
||||
char L;
|
||||
if (n <= 0xffff)
|
||||
{
|
||||
out[0] = '\xfd';
|
||||
L = 3;
|
||||
}
|
||||
else
|
||||
if (n <= 0xffffffff)
|
||||
{
|
||||
out[0] = '\xfe';
|
||||
L = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
out[0] = '\xff';
|
||||
L = 9;
|
||||
}
|
||||
for (unsigned char i = 1; i < L; ++i)
|
||||
out[i] = (n >> ((i - 1) * 8)) % 256;
|
||||
return L;
|
||||
}
|
||||
|
||||
uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const script, const size_t scriptsz, bool * const inout_newcb) {
|
||||
if (tmpl->cbtxn && !(*inout_newcb && (tmpl->mutations & BMM_GENERATE)))
|
||||
{
|
||||
@ -473,35 +502,6 @@ unsigned long blkmk_work_left(const blktemplate_t *tmpl) {
|
||||
return BLKMK_UNLIMITED_WORK_COUNT;
|
||||
}
|
||||
|
||||
static
|
||||
char varintEncode(unsigned char *out, uint64_t n) {
|
||||
if (n < 0xfd)
|
||||
{
|
||||
out[0] = n;
|
||||
return 1;
|
||||
}
|
||||
char L;
|
||||
if (n <= 0xffff)
|
||||
{
|
||||
out[0] = '\xfd';
|
||||
L = 3;
|
||||
}
|
||||
else
|
||||
if (n <= 0xffffffff)
|
||||
{
|
||||
out[0] = '\xfe';
|
||||
L = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
out[0] = '\xff';
|
||||
L = 9;
|
||||
}
|
||||
for (unsigned char i = 1; i < L; ++i)
|
||||
out[i] = (n >> ((i - 1) * 8)) % 256;
|
||||
return L;
|
||||
}
|
||||
|
||||
static char *blkmk_assemble_submission2_internal(blktemplate_t * const tmpl, const unsigned char * const data, const void * const extranonce, const size_t extranoncesz, blknonce_t nonce, const bool foreign)
|
||||
{
|
||||
const bool incl_gentxn = (foreign || (!(tmpl->mutations & BMAb_TRUNCATE && !extranoncesz)));
|
||||
|
||||
32
private.h
32
private.h
@ -27,4 +27,36 @@ int blkmk_flsl(unsigned long n)
|
||||
return i;
|
||||
}
|
||||
|
||||
static inline
|
||||
uint16_t upk_u16le(const void * const bufp, const int offset)
|
||||
{
|
||||
const uint8_t * const buf = bufp;
|
||||
return (((uint16_t)buf[offset+0]) << 0)
|
||||
| (((uint16_t)buf[offset+1]) << 8);
|
||||
}
|
||||
|
||||
static inline
|
||||
uint32_t upk_u32le(const void * const bufp, const int offset)
|
||||
{
|
||||
const uint8_t * const buf = bufp;
|
||||
return (((uint32_t)buf[offset+0]) << 0)
|
||||
| (((uint32_t)buf[offset+1]) << 8)
|
||||
| (((uint32_t)buf[offset+2]) << 0x10)
|
||||
| (((uint32_t)buf[offset+3]) << 0x18);
|
||||
}
|
||||
|
||||
static inline
|
||||
uint64_t upk_u64le(const void * const bufp, const int offset)
|
||||
{
|
||||
const uint8_t * const buf = bufp;
|
||||
return (((uint64_t)buf[offset+0]) << 0)
|
||||
| (((uint64_t)buf[offset+1]) << 8)
|
||||
| (((uint64_t)buf[offset+2]) << 0x10)
|
||||
| (((uint64_t)buf[offset+3]) << 0x18)
|
||||
| (((uint64_t)buf[offset+4]) << 0x20)
|
||||
| (((uint64_t)buf[offset+5]) << 0x28)
|
||||
| (((uint64_t)buf[offset+6]) << 0x30)
|
||||
| (((uint64_t)buf[offset+7]) << 0x38);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user