OSDN Git Service

new repo
[bytom/vapor.git] / mining / tensority / cgo_algorithm / lib / cSimdTs.cpp
1 #include <iostream>
2 #include <cstdio>
3 #include <map>
4 #include <mutex>
5 #include <signal.h>
6 #include "cSimdTs.h"
7 #include "BytomPoW.h"
8 #include "seed.h"
9
10 using namespace std;
11
12 BytomMatList16* matList_int16;
13 uint8_t result[32] = {0};
14 map <vector<uint8_t>, BytomMatList16*> seedCache;
15 static const int cacheSize = 42; //"Answer to the Ultimate Question of Life, the Universe, and Everything"
16 mutex mtx;
17
18 uint8_t *SimdTs(uint8_t blockheader[32], uint8_t seed[32]){
19     mtx.lock();
20     vector<uint8_t> seedVec(seed, seed + 32);
21
22     if(seedCache.find(seedVec) != seedCache.end()) {
23         // printf("\t---%s---\n", "Seed already exists in the cache.");
24         matList_int16 = seedCache[seedVec];
25     } else {
26         uint32_t exted[32];
27         extend(exted, seed); // extends seed to exted
28         Words32 extSeed;
29         init_seed(extSeed, exted);
30
31         matList_int16 = new BytomMatList16;
32         matList_int16->init(extSeed);
33
34         seedCache.insert(make_pair(seedVec, matList_int16));
35     }
36
37     iter_mineBytom(blockheader, 32, result);
38
39     if(seedCache.size() > cacheSize) {
40         for(map<vector<uint8_t>, BytomMatList16*>::iterator it=seedCache.begin(); it!=seedCache.end(); ++it){
41             delete it->second;
42         }
43         seedCache.clear();
44     }
45
46     mtx.unlock();
47     return result;
48 }