-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·117 lines (96 loc) · 3.8 KB
/
main.cpp
File metadata and controls
executable file
·117 lines (96 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <vector>
#include <iterator>
#include <fstream>
#include <algorithm>
#include <random>
#include "zebra.hpp"
#include "city.hpp"
#include "shift.c"
//#include "struct.c"
#include "newStract.c"
int main(int argc, char *argv[])
{
if(argc < 2) {
std::cerr << "Usage: " << argv[0] << " input" << std::endl;
return -1;
}
// how to use cityhash lib
// uint32_t input = 1233;
// uint32_t val = CityHash32((char *)&input, 4);
// std::cout << val << std::endl;
// return 0;
std::vector<entry_type> entry_list;
// 初期設定
uint32_t cycles_high_s, cycles_low_s, cycles_high_e, cycles_low_e;
__asm__ volatile ("CPUID\n\t"
"RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (cycles_high_s), "=r" (cycles_low_s)::
"%rax", "%rbx", "%rcx", "%rdx");
__asm__ volatile ("RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t"
"CPUID\n\t": "=r" (cycles_high_e), "=r" (cycles_low_e)::
"%rax", "%rbx", "%rcx", "%rdx");
__asm__ volatile ("CPUID\n\t"
"RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (cycles_high_s), "=r" (cycles_low_s)::
"%rax", "%rbx", "%rcx", "%rdx");
__asm__ volatile ("RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t"
"CPUID\n\t": "=r" (cycles_high_e), "=r" (cycles_low_e)::
"%rax", "%rbx", "%rcx", "%rdx");
read_zebra_data(entry_list, argv[1]);
printf("size = \n");
std::cout << entry_list.size() << std::endl;
printf("\n");
//----------------------書き加えたもの、要素を
std::random_device seed_gen;
std::mt19937 engine(seed_gen());
std::shuffle( entry_list.begin(), entry_list.end(),engine);
entry_list.erase(entry_list.begin() + std::stoi(argv[2]), entry_list.end());
//-------------------------------------
shiftToBit(entry_list);
//std::string str = makebit_a(argv[2],argv[3],argv[4],argv[5]);
std::string str = "";
_node *start = makeStruct(entry_list,str);
// start tsc measurement
//----------------もう一回シャッフル
std::random_device seed_gean;
std::mt19937 eangine(seed_gen());
std::shuffle( entry_list.begin(), entry_list.end(),eangine);
//-------------------------------
uint64_t all_number = 0;
for (int i = 0; i < 99; ++i)
{
std::string prefix = make_answer_prefix(entry_list[i].prefix);
uint64_t number = 0;
__asm__ volatile ("CPUID\n\t"
"RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (cycles_high_s), "=r" (cycles_low_s)::
"%rax", "%rbx", "%rcx", "%rdx");
search(start,prefix);
__asm__ volatile("RDTSCP\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t"
"CPUID\n\t": "=r" (cycles_high_e), "=r" (cycles_low_e)::
"%rax", "%rbx", "%rcx", "%rdx");
uint64_t start_clock = (((uint64_t)cycles_high_s << 32) | cycles_low_s);
uint64_t end_clock = (((uint64_t)cycles_high_e << 32) | cycles_low_e);
number = (end_clock - start_clock);
std::cout << number << std::endl;
all_number += number;
}
all_number /= 100;
// end tsc measurement
std::cout << all_number << std::endl;
// std::copy(entry_list.begin(), entry_list.end(), std::ostream_iterator<entry_type>(std::cout, "\n"));
std::for_each(entry_list.begin(), entry_list.end(), [](const entry_type& obj) {
// std::cout << obj.prefix << std::endl;
});
return 0;
}