From f0f302d80683c9b68fc9b13dac9f590ae1937232 Mon Sep 17 00:00:00 2001 From: Alain D D Williams Date: Tue, 13 Oct 2020 17:54:10 +0100 Subject: [PATCH] attempt at counting output registers --- openpower/sv_analysis.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/openpower/sv_analysis.py b/openpower/sv_analysis.py index ee029a5c5..8f4d266e4 100644 --- a/openpower/sv_analysis.py +++ b/openpower/sv_analysis.py @@ -1,23 +1,33 @@ #!/usr/bin/env python3 +# Initial version written by lkcl Oct 2020 +# This program analyses the Power 9 op codes and looks at in/out register uses +# The results are displayed: +# https://libre-soc.org/openpower/opcode_regs_deduped/ +# +# It finds .csv files in the directory isatables/ + import csv import os from os.path import dirname, join from glob import glob from collections import OrderedDict - +# Return absolute path (ie $PWD) + isatables + name def find_wiki_file(name): filedir = os.path.dirname(os.path.abspath(__file__)) tabledir = join(filedir, 'isatables') file_path = join(tabledir, name) return file_path +# Return an array of dictionaries from the CSV file name: def get_csv(name): file_path = find_wiki_file(name) with open(file_path, 'r') as csvfile: reader = csv.DictReader(csvfile) return list(reader) +# This will return True if all values are true. +# Not sure what this is about def blank_key(row): #for v in row.values(): # if 'SPR' in v: # skip all SPRs @@ -27,14 +37,19 @@ def blank_key(row): return False return True +# General purpose registers have names like: RA, RT, R1, ... +# Floating point registers names like: FRT, FRA, FR1, ..., FRTp, ... +# Return True if field is a register def isreg(field): return field.startswith('R') or field.startswith('FR') +# These are the attributes of the instructions, +# register names keycolumns = ['unit', 'in1', 'in2', 'in3', 'out', 'CR in', 'CR out', ] # don't think we need these: 'ldst len', 'rc', 'lk'] -tablecols = ['unit', 'in', 'out', 'CR in', 'CR out', +tablecols = ['unit', 'in', 'out', 'CR in', 'CR out', 'outcnt', ] # don't think we need these: 'ldst len', 'rc', 'lk'] def create_key(row): @@ -47,13 +62,21 @@ def create_key(row): res['in'] = 0 if isreg(row[key]): res['in'] += 1 + # registers OUT if key == 'out': if isreg(row[key]): res[key] = 'R' else: res[key] = '0' - # CRs + + # If upd is 1 then increment the count of outputs + if 'outcnt' not in res: + res['outcnt'] = 0 + if row['upd'] == '1': + res['outcnt'] += 1 + + # CRs (Condition Register) (CR0 .. CR7) if key.startswith('CR'): if row[key].startswith('NONE'): res[key] = '0' @@ -65,7 +88,7 @@ def create_key(row): res[key] = row[key] else: res[key] = 'OTHER' - # LDST len + # LDST len (LoadStore length) if key.startswith('ldst'): if row[key].startswith('NONE'): res[key] = '0' @@ -82,10 +105,13 @@ def create_key(row): if key == 'lk': res[key] = row[key] + # Convert the numerics 'in' & 'outcnt' to strings res['in'] = str(res['in']) + res['outcnt'] = str(res['outcnt']) return res +# def dformat(d): res = [] for k, v in d.items(): @@ -118,7 +144,10 @@ def process_csvs(): primarykeys = set() dictkeys = OrderedDict() + # Expand that (all .csv files) pth = find_wiki_file("*.csv") + + # Ignore those containing: valid test sprs for fname in glob(pth): if 'valid' in fname: continue @@ -126,8 +155,10 @@ def process_csvs(): continue if 'sprs' in fname: continue + #print (fname) csvname = os.path.split(fname)[1] + # csvname is something like: minor_59.csv, fname the whole path csv = get_csv(fname) csvs[fname] = csv for row in csv: @@ -135,6 +166,7 @@ def process_csvs(): continue dkey = create_key(row) key = tuple(dkey.values()) + # print("key=", key) dictkeys[key] = dkey primarykeys.add(key) if key not in bykey: -- 2.30.2