2010-11-27 07:29:56 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "miner.h"
|
|
|
|
|
|
|
|
#ifdef WANT_VIA_PADLOCK
|
|
|
|
|
|
|
|
static void via_sha256(void *hash, void *buf, unsigned len)
|
|
|
|
{
|
|
|
|
unsigned stat = 0;
|
|
|
|
asm volatile(".byte 0xf3, 0x0f, 0xa6, 0xd0"
|
|
|
|
:"+S"(buf), "+a"(stat)
|
|
|
|
:"c"(len), "D" (hash)
|
|
|
|
:"memory");
|
|
|
|
}
|
|
|
|
|
2011-03-18 03:02:28 +01:00
|
|
|
bool scanhash_via(int thr_id, unsigned char *data_inout,
|
2011-02-03 06:46:55 +01:00
|
|
|
const unsigned char *target,
|
2011-01-29 06:56:24 +01:00
|
|
|
uint32_t max_nonce, unsigned long *hashes_done)
|
2010-11-27 07:29:56 +01:00
|
|
|
{
|
|
|
|
unsigned char data[128] __attribute__((aligned(128)));
|
2010-12-24 02:21:00 +01:00
|
|
|
unsigned char tmp_hash[32] __attribute__((aligned(128)));
|
2010-12-06 06:57:48 +01:00
|
|
|
unsigned char tmp_hash1[32] __attribute__((aligned(128)));
|
2010-12-24 02:21:00 +01:00
|
|
|
uint32_t *data32 = (uint32_t *) data;
|
|
|
|
uint32_t *hash32 = (uint32_t *) tmp_hash;
|
2010-12-20 03:37:30 +01:00
|
|
|
uint32_t *nonce = (uint32_t *)(data + 64 + 12);
|
2010-11-27 07:29:56 +01:00
|
|
|
uint32_t n = 0;
|
|
|
|
unsigned long stat_ctr = 0;
|
|
|
|
int i;
|
|
|
|
|
2011-03-18 03:02:28 +01:00
|
|
|
work_restart[thr_id].restart = 0;
|
|
|
|
|
2010-11-27 07:29:56 +01:00
|
|
|
/* bitcoin gives us big endian input, but via wants LE,
|
|
|
|
* so we reverse the swapping bitcoin has already done (extra work)
|
2010-11-27 09:45:47 +01:00
|
|
|
* in order to permit the hardware to swap everything
|
|
|
|
* back to BE again (extra work).
|
2010-11-27 07:29:56 +01:00
|
|
|
*/
|
2010-12-24 02:21:00 +01:00
|
|
|
for (i = 0; i < 128/4; i++)
|
|
|
|
data32[i] = swab32(((uint32_t *)data_inout)[i]);
|
2010-11-27 07:29:56 +01:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
n++;
|
|
|
|
*nonce = n;
|
|
|
|
|
|
|
|
/* first SHA256 transform */
|
|
|
|
memcpy(tmp_hash1, sha256_init_state, 32);
|
|
|
|
via_sha256(tmp_hash1, data, 80); /* or maybe 128? */
|
|
|
|
|
|
|
|
for (i = 0; i < 32/4; i++)
|
|
|
|
((uint32_t *)tmp_hash1)[i] =
|
|
|
|
swab32(((uint32_t *)tmp_hash1)[i]);
|
|
|
|
|
|
|
|
/* second SHA256 transform */
|
2010-12-24 02:21:00 +01:00
|
|
|
memcpy(tmp_hash, sha256_init_state, 32);
|
|
|
|
via_sha256(tmp_hash, tmp_hash1, 32);
|
2010-11-27 07:29:56 +01:00
|
|
|
|
|
|
|
stat_ctr++;
|
|
|
|
|
2011-02-17 07:22:55 +01:00
|
|
|
if (unlikely((hash32[7] == 0) && fulltest(tmp_hash, target))) {
|
2010-12-24 02:21:00 +01:00
|
|
|
/* swap nonce'd data back into original storage area;
|
|
|
|
* TODO: only swap back the nonce, rather than all data
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 128/4; i++) {
|
|
|
|
uint32_t *dout32 = (uint32_t *) data_inout;
|
|
|
|
dout32[i] = swab32(data32[i]);
|
|
|
|
}
|
|
|
|
|
2010-11-27 07:29:56 +01:00
|
|
|
*hashes_done = stat_ctr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-18 03:02:28 +01:00
|
|
|
if ((n >= max_nonce) || work_restart[thr_id].restart) {
|
2010-11-27 07:29:56 +01:00
|
|
|
*hashes_done = stat_ctr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WANT_VIA_PADLOCK */
|
|
|
|
|