]> git.cryptolib.org Git - avr-crypto-lib.git/blob - host/data2wiki.rb
optimizing norx32
[avr-crypto-lib.git] / host / data2wiki.rb
1 #!/usr/bin/ruby
2 # performnce to wiki
3
4 =begin
5     This file is part of the AVR-Crypto-Lib.
6     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
7
8     This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 =end
21
22 =begin
23  === Twister-256 performance === 
24     type:                     hash
25     hashsize (bits):           256
26     ctxsize (bytes):            80
27     blocksize (bits):          512
28     init (cycles):             425
29     nextBlock (cycles):      36535
30     lastBlock (cycles):       8071
31     ctx2hash (cycles):       19431
32
33    text    data     bss     dec     hex filename
34    6801      32       0    6833    1ab1 bin/bmw_c/bmw_small.o
35 =end
36
37 def get_size_string(impl, algo)
38   fmap = File.open('algo_implementation/'+impl+'.algos', 'r')
39   fsize = File.open('size_log/'+impl+'.size', 'r')
40   modules = nil
41   while l=fmap.gets
42     if m=l.match(/^([^:]*):(.*)$/)
43       if m[1] == algo
44         modules = m[2].split(/[\s]+/)
45       end
46     end
47   end
48   if modules==nil
49     puts("ERROR: no module list found for #{impl}/#{algo} !")
50     return nil
51   end
52   fmap.close()
53   str = ''
54   sum = 0
55   lb = fsize.gets()
56   while lb = fsize.gets()
57     m = lb.match(/[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w_\/-]*)/)
58     name = m[6]+'.o'
59     if modules.include?(name)
60       str += "<br> \n" + name+': '+m[4]
61       sum += m[4].to_i
62     end
63   end
64   fsize.close()
65   return sum
66 end
67
68 def process_hashfunction(fin, name, impl)
69   lb = fin.readline()
70   m = lb.match(/hashsize \(bits\):[\s]*([\d]*)/)
71   if(!m)
72         printf("unexpected string %s\n", lb)
73   end
74   hashsize = m[1].to_i()
75   lb = fin.readline()
76   m = lb.match(/ctxsize \(bytes\):[\s]*([\d]+)/)
77   ctxsize = m[1].to_i()
78   lb = fin.readline()
79   m = lb.match(/blocksize \(bits\):[\s]*([\d]+)/)
80   blocksize = m[1].to_i()
81   lb = fin.readline()
82   m = lb.match(/init \(cycles\):[\s]*([\d]+)/)
83   inittime = m[1].to_i()
84   lb = fin.readline()
85   m = lb.match(/nextBlock \(cycles\):[\s]*([\d]+)/)
86   nextblocktime = m[1].to_i()  
87   lb = fin.readline()
88   m = lb.match(/lastBlock \(cycles\):[\s]*([\d]+)/)
89   lastblocktime = m[1].to_i()
90   lb = fin.readline()
91   m = lb.match(/ctx2hash \(cycles\):[\s]*([\d]+)/)
92   convtime = m[1].to_i()
93   begin
94     lb = fin.gets()
95   end until lb==nil || m = lb.match(/init \(bytes\):[\s]*([\d]*)/)
96   if lb
97     initstack = m[1].to_i()
98     lb = fin.readline()
99     m = lb.match(/nextBlock \(bytes\):[\s]*([\d]*)/)
100     nextblockstack = m[1].to_i()
101     lb = fin.readline()
102     m = lb.match(/lastBlock \(bytes\):[\s]*([\d]*)/)
103     lastblockstack = m[1].to_i()
104     lb = fin.readline()
105     m = lb.match(/ctx2hash \(bytes\):[\s]*([\d]*)/)
106     convstack = m[1].to_i()
107     s1 = (initstack>nextblockstack)?initstack:nextblockstack
108     s2 = (lastblockstack>convstack)?lastblockstack:convstack
109     stack = (s1>s2)?s1:s2  
110   else
111     stack = 0
112   end  
113   size = get_size_string(impl, name)
114   printf("| %20s || %6s || %3s || %6d || %7d || %7d || %7d || %7d ||" +
115          " %7d || %7d || %9.2f || %7d || || || \n|-\n" , 
116         name, $variant, $lang, size, ctxsize, stack, hashsize, blocksize, 
117             inittime, nextblocktime, nextblocktime.to_f/(blocksize/8),
118                 lastblocktime+convtime)
119 end
120
121
122 $handlers = Hash.new
123 $handlers.default = 0
124 $handlers["hashfunction"] = 1 #process_hashfunction
125
126 def process_file(fname)
127   fin = File.open(fname, "r")
128   impl = fname.match(/([^.]*).txt$/)[1]
129   $lang = "asm"
130   $lang = "C" if impl.match(/^[^_]*_[cC]/)
131   $variant = $lang
132   if m=impl.match(/_([^_]*)$/)
133     $variant = m[1]
134   end
135   if $variant == 'c'
136     $variant = 'C'
137   end
138   begin
139     begin
140           if fin.eof()
141                 return
142           end
143       lb = fin.readline()
144     end while !m=lb.match(/=== (.*) performance ===/)
145     name = m[1];
146     lb = fin.readline()
147     m = lb.match(/type:[\s]*([\w]*)/)
148     type = m[1]
149     if $handlers[type] != 0
150     #  handlers[type](fin, name)
151     #  puts "DBG: process "fname+'-'+name+'-'+impl
152       process_hashfunction(fin, name, impl)
153     else
154       printf("ERROR: unsupported type: %s !\n", type)
155     end 
156   end while(true)
157   fin.close()
158 end
159
160 for i in (0..ARGV.size-1)
161   process_file(ARGV[i])
162 end
163
164
165
166
167
168
169