inspectfp.py
2.69 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
#!/usr/bin/python
# inspectfp.py <input_file>
import os
import sys
# search the following instructions in the input file
tab = {"double" : ["faddd", "fsubd", "fmuld", "fdivd", "fsqrtd", "fcmdd", "fcmped","fitod","fdtoi","fdtos"],
"single" : ["fadds", "fsubs", "fmuls", "fdivs", "fsqrts", "fcmps", "fcmpes","fitos","fstoi","fstod","fsmuld","fabss","fnegs","fmovs"],
"half" : ["faddh", "fsubh", "fmulh", "fdivh", "fsqrth", "fcmph", "fcmpeh","fitoh","fhtoi","fhtos","fhmuls","fabsh","fmovh"],
"packhalf" : ["faddph","fsubph","fmulph","fdivph","fsqrtph","fcmpph","fcmpeph","fswaph","fmovhu","fmovhl","fmovhul","fmovhlu","fmovhzu","fmovhzl"],
"packsingle" : ["faddps","fsubps","fmulps","fdivps","fsqrtps","fcmpps","fcmpeps"],
"others" : ["ldh","sth"],
}
if len(sys.argv)<2:
print("E: Missing argument. Script needs one argument - input file.")
print("E: The optional second argument contains format ('tab'/'list')")
sys.exit(1)
ctab = []
taby = 0
tabx = 0
for p in tab:
if len(tab[p])>tabx:
tabx = len(tab[p])
ctab.append([0] * len(tab[p]))
taby += 1
with open(sys.argv[1], 'r') as fi:
ctx = fi.readlines()
for ln in ctx:
ty = 0
for p in tab:
for i in range(0,len(tab[p])):
# instructions are placed after <tab> and separated with <dpace> in disassembler
if ln.find("\t"+tab[p][i]+" ")>0:
ctab[ty][i] += 1
ty += 1
fmt = 'tab'
if len(sys.argv)>2:
fmt = sys.argv[2]
if fmt=='tab':
ty=0
print("===== Table of FP instructions ==========================================")
if tabx>6:
for p in tab:
ln = "{:10} ".format(p)
for i in range(0,6):
if (i<len(tab[p])):
ln += "| {:7}: {:4}".format(tab[p][i], ctab[ty][i])
print(ln)
ty += 1
print("-------------------------------------------------------------------------")
ty = 0
for p in tab:
ln = "{:10} ".format(p)
for i in range(6,len(tab[p])):
if (i<len(tab[p])):
ln += "| {:7}: {:4}".format(tab[p][i], ctab[ty][i])
print(ln)
ty += 1
else:
for p in tab:
ln = "{:10} ".format(p)
for i in range(0,len(tab[p])):
ln += "| {:7}: {:4}".format(tab[p][i], ctab[ty][i])
if i==6:
print(ln)
ln = "{:20}".format(" ->")
print(ln)
ty += 1
print("=========================================================================")
elif fmt=='list':
ty = 0;
print("~~~~~ List of FP instructions ~~~~~")
for p in tab:
print("|> {:10} ".format(p))
for i in range(0,len(tab[p])):
ln = "| {:7}: {:4}".format(tab[p][i], ctab[ty][i])
print(ln)
ty += 1
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")