forked from AsmOptC-RiscV/Assembly-Optimized-C-RiscV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench-rweather.py
121 lines (105 loc) · 3.56 KB
/
bench-rweather.py
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
118
119
120
121
#!/usr/bin/python3
import os
from utils.BenchSetup import riscvOVPSim, SiFive
from utils.tools import read, save, bcolors
from progress.bar import Bar
def parse(output):
for l in output:
line = l.split("\t")
if len(line) > 3:
if (line[0] == '128' or line[0] == '28') and line[1] == '128':
return line[2:-1]
def get_fun(scheme):
functions = {
'crypto_aead_encrypt' : '',
'crypto_aead_encrypt_2' : '',
'crypto_aead_encrypt_3' : '',
'crypto_aead_encrypt_4' : '',
'crypto_aead_encrypt_5' : '',
'crypto_aead_encrypt_6' : '',
'crypto_aead_encrypt_7' : '',
}
with open(scheme + "/base.h") as f:
content = f.readlines()
for line in content:
line = line.strip()
line = line.split(' ')
if len(line) == 3:
if line[0][:2] != '//':
if line[1][:19] == 'crypto_aead_encrypt':
functions[line[1]] = line[2]
return(functions)
def print_latex_header(benches, compiler):
output_str = ""
output_str += "\\begin{center}" + "\n"
output_str += "\t\\begin{longtable}{l r r r}" + "\n"
output_str += "\t\\caption{Cycle counts for different ciphers implementations " + compiler + " compiled with \\texttt{-O3} for encrypting 128 bytes of message and 128 bytes of associated data.}" + "\n"
output_str += "\t\t\t\\\\" + "\n"
output_str += "\t\t\t\\toprule" + "\n"
output_str += "\t\t\tImplementation\t\t\t& " + benches[0].name() + "\t& " + benches[1].name() + " \t& Relative\\\\" + "\n"
output_str += "\t\t\t\\midrule" + "\n"
return output_str
def print_latex_footer():
output_str = ""
output_str += "\t\t\t\\bottomrule" + "\n"
output_str += "\t\\label{tab:rweather-bench}" + "\n"
output_str += "\t\\end{longtable}" + "\n"
output_str += "\\end{center}" + "\n"
return output_str
def print_latex(datas, ciphers, j):
output_str = ""
template = "\t\t\t\\Cipher{{{cipher}}} \t& {riscv} \t& {sifive} \t& {sign}{relative}\\% \\\\\n"
keys = ['crypto_aead_encrypt',
'crypto_aead_encrypt_2',
'crypto_aead_encrypt_3',
'crypto_aead_encrypt_4',
'crypto_aead_encrypt_5',
'crypto_aead_encrypt_6',
'crypto_aead_encrypt_7']
i = 0
for k in keys:
if ciphers.get(k) != '':
relative = round((int(datas[1][j][i]) - int(datas[0][j][i]))*100/float(datas[0][j][i]))
if relative > 0:
sign = '+'
else:
sign = '-'
output_str += template.format(cipher=ciphers.get(k), riscv=datas[0][j][i], sifive=datas[1][j][i], sign=sign, relative=relative)
i += 1
return output_str
# Setup
ciphers = ['rweather/' + f for f in os.listdir('rweather/')]
ciphers.sort()
results = [[],[]]
compiler = "clang-10"
benches = [riscvOVPSim(), SiFive()]
bar = Bar('Processing', max=len(benches) * len(ciphers))
# Measure
for cipher in ciphers:
b = 0
for bench in benches:
bench.clean()
bench.build(cipher, compiler)
bench.compile()
output = bench.exec()
results[b].append(parse(output))
b += 1
bar.next()
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
output_str = ""
# Print
output_str += print_latex_header(benches, compiler)
for j in range(len(ciphers)):
cipher_names = get_fun(ciphers[j])
output_str += print_latex(results, cipher_names, j)
output_str += print_latex_footer()
print(output_str)
save('paper/_bench.tex', output_str.replace("_", "\_"))