huge refactoring

This commit is contained in:
Jan Laukemann
2017-09-01 01:00:02 +02:00
parent 745b11352d
commit ff93f11790
4 changed files with 879 additions and 508 deletions

View File

@@ -30,7 +30,11 @@ class Scheduler(object):
def schedule_FCFS(self):
'''
Schedules Instruction Form list via First Come First Serve algorithm.
Returns a tuple containing the graphic output as string and the total throughput time as int
Returns
-------
(str, int)
A tuple containing the graphic output as string and the total throughput time as int.
'''
sched = ''
total = 0
@@ -41,7 +45,7 @@ class Scheduler(object):
searchString = instrForm[0]+'-'+self.get_operand_suffix(instrForm)
entry = self.df.loc[lambda df: df.instr == searchString,'LT':'ports']
tup = entry.ports.values[0]
if(len(tup) == 1 and tup[0] == -1):
if(len(tup) == 1 and tup[0][0] == -1):
raise IndexError()
except IndexError:
# Instruction form not in CSV
@@ -68,7 +72,20 @@ class Scheduler(object):
def test_ports_FCFS(self, occ_ports, needed_ports):
'''
tests if current configuration of ports is possible and returns boolean
Test if current configuration of ports is possible and returns boolean
Parameters
----------
occ_ports : [int]
Tuple to inspect for current port occupation
needed_ports : (int)
Tuple with needed port(s) for particular instruction form
Returns
-------
bool
True if needed ports can get scheduled on current port occupation
False if not
'''
for port in needed_ports:
if(occ_ports[port] != 0):
@@ -76,10 +93,21 @@ class Scheduler(object):
return True
def schedule_Tomasulo(self):
'''
Not implement yet. Schedules Instruction Form list via Tomasulo algorithm.
'''
print('Scheduling with Tomasulo algorithm...')
return ''
def get_head(self):
'''
Creates right heading for CPU architecture.
Returns
-------
str
String containing the header
'''
analysis = 'Throughput Analysis Report\n'+('-'*26)+'\n'
annotations = ( '* - No information for this instruction in database\n'
'\n')
@@ -93,6 +121,21 @@ class Scheduler(object):
return head
def get_line(self, occ_ports, instrName):
'''
Create line with port occupation for output.
Parameters
----------
occ_ports : (int)
Integer tuple containing needed ports
instrName : str
Name of instruction form for output
Returns
-------
str
String for output containing port scheduling for instrName
'''
line = ''
for i in occ_ports:
cycles = ' ' if (i == 0) else float(i)
@@ -102,6 +145,19 @@ class Scheduler(object):
def get_operand_suffix(self, instrForm):
'''
Creates operand suffix out of list of Parameters.
Parameters
----------
instrForm : [str, Parameter, ..., Parameter, str]
Instruction Form data structure
Returns
-------
str
Operand suffix for searching in database
'''
extension = ''
opExt = []
for i in range(1, len(instrForm)-1):

View File

@@ -7,6 +7,14 @@ class Parameter(object):
raise NameError("Type not supported: "+ptype)
def print(self):
'''
Prints Parameter.
Returns
-------
str
Parameter as string
'''
if(self.ptype == "NONE"):
return ""
else:
@@ -44,6 +52,14 @@ class MemAddr(Parameter):
raise NameError("Type not supported: "+name)
def print(self):
'''
Prints MemAddr.
Returns
-------
str
MemAddr as string
'''
mem_format = "MEM("
if(self.sreg):
mem_format += "sreg:"
@@ -100,6 +116,14 @@ class Register(Parameter):
# print(lncnt)
def print(self):
'''
Prints Register.
Returns
-------
str
Register as string
'''
opmask = ""
if(self.mask):
opmask = "{opmask}"

View File

@@ -54,7 +54,7 @@ class Testcase(object):
##----------------------------------------------------------------
# Constructor
def __init__(self, _mnemonic, _param_list, _num_instr='12'):
def __init__(self, _mnemonic, _param_list, _num_instr='32'):
self.instr = _mnemonic.lower()
self.param_list = _param_list
# num_instr must be an even number
@@ -71,6 +71,9 @@ class Testcase(object):
def write_testcase(self):
"""
Write testcase for class attributes in a file.
"""
regs = self.param_list
extension = ''
# Add operands
@@ -94,6 +97,15 @@ class Testcase(object):
# Check operands
def __define_operands(self):
"""
Check for the number of operands and initialise the GPRs if necessary.
Returns
-------
(str, str, str, str, str, str)
String tuple containing types of operands and if needed push/pop operations, the
initialisation of general purpose regs and the copy if registers.
"""
oprnds = self.param_list
op_a, op_b, op_c = ('', '', '')
gprPush, gprPop, zeroGPR = ('', '', '')
@@ -138,8 +150,17 @@ class Testcase(object):
copy = ''
return (op_a, op_b, op_c, gprPush, gprPop, zeroGPR, copy)
# Initialise 11 general purpose registers and set them to zero
def __initialise_gprs(self):
"""
Initialise eleven general purpose registers and set them to zero.
Returns
-------
(str, str, str)
String tuple for push, pop and initalisation operations
"""
gprPush = ''
gprPop = ''
zeroGPR = ''
@@ -154,6 +175,19 @@ class Testcase(object):
# Copy created values in specific register
def __copy_regs(self, reg):
"""
Copy created values in specific register.
Parameters
----------
reg : Register
Register for copying the value
Returns
-------
str
String containing the copy instructions
"""
copy = '\t\t# copy DP 1.0\n'
# Different handling for GPR, MMX and SSE/AVX registers
if(reg.reg_type == 'GPR'):
@@ -188,6 +222,14 @@ class Testcase(object):
def __define_header(self):
"""
Define header.
Returns
-------
(str, str, str, str)
String tuple containing the header, value initalisations and extensions
"""
def_instr = '#define INSTR '+self.instr+'\n'
ninstr = '#define NINST '+self.num_instr+'\n'
pi = ('PI:\n'
@@ -226,8 +268,16 @@ class Testcase(object):
'\t\tvinsert64x4 zmm0, zmm0, ymm0, 0x1\n')
return (def_instr, ninstr, init, expand)
# Create latency loop
def __define_loop_lat(self):
"""
Create latency loop.
Returns
-------
str
Latency loop as string
"""
loop_lat = ('loop:\n'
'\t\tinc i\n')
if(self.num_operands == 1):
@@ -253,8 +303,16 @@ class Testcase(object):
'\t\tjl loop\n')
return loop_lat
# Create throughput loop
def __define_loop_thrpt(self):
"""
Create throughput loop.
Returns
-------
str
Throughput loop as string
"""
loop_thrpt = ('loop:\n'
'\t\tinc i\n')
ext = ''
@@ -278,6 +336,22 @@ class Testcase(object):
def __is_in_dir(self, name, path):
"""
Check if file with the name name is in directory path.
Parameters
----------
name : str
Name of file
path : str
Path of directory
Returns
-------
bool
True if file is in directory
False if file is not in directory
"""
for root, dirs, files in os.walk(path):
if name in files:
return True

1219
osaca.py

File diff suppressed because it is too large Load Diff