Browse Source

Calculate midstate in separate function and remove likely/unlikely macros since they're dependent on pools, not code design.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
41daf99537
  1. 45
      cgminer.c

45
cgminer.c

@ -1230,6 +1230,27 @@ static bool jobj_binary(const json_t *obj, const char *key, @@ -1230,6 +1230,27 @@ static bool jobj_binary(const json_t *obj, const char *key,
return true;
}
static void calc_midstate(struct work *work)
{
union {
unsigned char c[64];
uint32_t i[16];
} data;
int swapcounter;
for (swapcounter = 0; swapcounter < 16; swapcounter++)
data.i[swapcounter] = swab32(((uint32_t*) (work->data))[swapcounter]);
sha2_context ctx;
sha2_starts( &ctx, 0 );
sha2_update( &ctx, data.c, 64 );
memcpy(work->midstate, ctx.state, sizeof(work->midstate));
#if defined(__BIG_ENDIAN__) || defined(MIPSEB)
int i;
for (i = 0; i < 8; i++)
(((uint32_t*) (work->midstate))[i]) = swab32(((uint32_t*) (work->midstate))[i]);
#endif
}
static bool work_decode(const json_t *val, struct work *work)
{
if (unlikely(!jobj_binary(val, "data", work->data, sizeof(work->data), true))) {
@ -1237,29 +1258,13 @@ static bool work_decode(const json_t *val, struct work *work) @@ -1237,29 +1258,13 @@ static bool work_decode(const json_t *val, struct work *work)
goto err_out;
}
if (likely(!jobj_binary(val, "midstate",
work->midstate, sizeof(work->midstate), false))) {
applog(LOG_DEBUG, "Calculating midstate locally");
if (!jobj_binary(val, "midstate", work->midstate, sizeof(work->midstate), false)) {
// Calculate it ourselves
union {
unsigned char c[64];
uint32_t i[16];
} data;
int swapcounter;
for (swapcounter = 0; swapcounter < 16; swapcounter++)
data.i[swapcounter] = swab32(((uint32_t*) (work->data))[swapcounter]);
sha2_context ctx;
sha2_starts( &ctx, 0 );
sha2_update( &ctx, data.c, 64 );
memcpy(work->midstate, ctx.state, sizeof(work->midstate));
#if defined(__BIG_ENDIAN__) || defined(MIPSEB)
int i;
for (i = 0; i < 8; i++)
(((uint32_t*) (work->midstate))[i]) = swab32(((uint32_t*) (work->midstate))[i]);
#endif
applog(LOG_DEBUG, "Calculating midstate locally");
calc_midstate(work);
}
if (likely(!jobj_binary(val, "hash1", work->hash1, sizeof(work->hash1), false))) {
if (!jobj_binary(val, "hash1", work->hash1, sizeof(work->hash1), false)) {
// Always the same anyway
memcpy(work->hash1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0", 64);
}

Loading…
Cancel
Save