|
import json |
|
from collections import Counter |
|
|
|
def info_good(info): |
|
# Ignore Zcmt and Zcmp |
|
return not any('_zcmt' in e or '_zcmp' in e for e in info['extension']) |
|
|
|
def get_instr_space(info): |
|
n = int(info['mask'], 0).bit_count() |
|
return 2 ** (32 - n) |
|
|
|
def get_space_by_ext(data): |
|
ctr = Counter() |
|
|
|
for name, info in data.items(): |
|
ctr['/'.join(info['extension'])] += get_instr_space(info) |
|
|
|
return ctr |
|
|
|
if __name__ == '__main__': |
|
with open('instr_dict.json', 'rb') as instr_dict: |
|
data = json.load(instr_dict) |
|
data = { name: info for name, info in data.items() if info_good(info) } |
|
per_instr_space = { name: get_instr_space(info) for name, info in data.items() } |
|
|
|
print('By instruction:') |
|
for name, space in sorted(per_instr_space.items(), key=lambda i: (-i[1], i[0])): |
|
norm_name = name.replace('_', '.') |
|
print(f'{norm_name} {space / 2**32:.2g}') |
|
print() |
|
|
|
print('By extension:') |
|
per_ext_space = get_space_by_ext(data) |
|
for name, space in sorted(per_ext_space.items(), key=lambda i: (-i[1], i[0])): |
|
print(f'{name} {space / 2**32:.2g}') |
|
print() |
|
|
|
total_used = sum(per_instr_space.values()) |
|
total_free = 2**32 - total_used |
|
|
|
print(f'Total of {100 * total_used / 2**32:.2f}% RISC-V encoding space is used') |
|
|
|
rvc_used = sum(use for name, use in per_ext_space.items() if '_c' in name or '_zc' in name) |
|
print(f' ... {100 * rvc_used / 2**32:.2f}% is RVC') |
|
print(f' ... {100 * (total_used - rvc_used) / 2**32:.2f}% is 32-bit instructions') |
|
|
|
print(f'{100 * (total_used - rvc_used) / (2**32 / 4):.2f}% of >= 32-bit encoding is used') |