Commit 4b306387 authored by Lyude Paul's avatar Lyude Paul

working wip???? try encoding register files now

This needs additional verification and a closer look.
parent 3b3c7e6c
......@@ -33,7 +33,7 @@ import pprint
try:
import bitstring
from bitstring import BitArray
from bitstring import BitArray, Bits
except Exception:
print("The bitstring module for python3 is needed to run this!", file=stderr)
import sys
......@@ -681,6 +681,18 @@ class RegisterFile:
hex(id(self))
)
class ControlField(IntEnum):
WRITE_FMA_P2 = 1
WRITE_FMA_P2_READ_P3 = 3
READ_P3 = 4
WRITE_ADD_P2 = 5
WRITE_ADD_P2_READ_P3 = 6
FIRST_NONE = 8
FIRST_WRITE_FMA_P2 = 9
NONE = 11
FIRST_READ_P3 = 12
WRITE_FMA_P2_ADD_P3 = 15
class NotEnoughPorts(ParsingException):
def __init__(self, type_, target):
super().__init__('Not enough %s ports for %s' % (type_, target))
......@@ -781,28 +793,78 @@ class RegisterFile:
read_regs.pop().set_port(big_port)
elif len(read_regs) == 1:
reg = read_regs.pop()
if reg.idx > 31:
reg.set_port(1)
else:
reg.set_port(0)
read_regs.pop().set_port(0)
def encode(self):
const_port = self.const_port.encode()
const_port = self.const_port
if const_port:
const_field = self.const_port.encode_const_field()
else:
const_field = 0
inst = self.instruction
reg_file = inst.reg_file
# Figure out the value of the control field
if inst.writes[fma]:
assert inst.writes[fma].port == 2
port0_field = self.ports[0].idx
port1_field = self.ports[1].idx
if port0_field > port1_field:
port0_field = 63 - port0_field
port1_field = 63 - port1_field
if inst.writes[add]:
control_field = self.ControlField.WRITE_FMA_P2_ADD_P3
elif reg_file.ports[3]:
control_field = self.ControlField.WRITE_FMA_P2_READ_P3
elif inst.first:
control_field = self.ControlField.FIRST_WRITE_FMA_P2
else:
control_field = self.ControlField.WRITE_FMA_P2
elif inst.writes[add]:
assert inst.writes[add].port == 2
if reg_file.ports[3]:
control_field = self.ControlField.WRITE_ADD_P2_READ_P3
else:
control_field = self.ControlField.WRITE_ADD_P2
elif reg_file.ports[3]:
if inst.first:
control_field = self.ControlField.FIRST_READ_P3
else:
control_field = self.ControlField.READ_P3
elif inst.first:
control_field = self.ControlField.FIRST_NONE
if self.port3_write:
pass # TODO
else:
if self.ports[2] is not None:
pass
control_field = self.ControlField.NONE
# TODO
port_fields = reg_file.ports.copy()
for idx, port in enumerate(port_fields):
if port is None:
port_fields[idx] = 0
else:
port_fields[idx] = port.idx
if reg_file.ports[1]:
if port_fields[0] > port_fields[1]:
for port, idx in enumerate(port_fields[0:1]):
port_fields[idx] = abs(port_fields[idx] - 63)
return bitstring.pack('uint:8, uint:6, uint:6, uint:5, uint:6, uint:4',
const_field,
port_fields[2],
port_fields[3],
port_fields[0],
port_fields[1],
control_field)
else:
return bitstring.pack('uint:8, uint:6, uint:6, uint:6, bool, uint:4, uint:4=0',
const_field,
port_fields[2],
port_fields[3],
port_fields[0],
reg_file.ports[0] is None,
control_field)
class ConstantSrc:
def __init__(self, high32):
......@@ -822,8 +884,8 @@ class ConstantSrc:
class ImmediateZeroSlot:
@classmethod
def encode(cls):
return bitstring.pack('uint:8', 0)
def encode_const_field(cls):
return 0
@classmethod
def get_src(cls, token):
......@@ -849,8 +911,8 @@ class ImmediateSlot:
else:
return ConstantSrc(token.read_type == ImmediateToken.ReadType.HIGH64)
def encode(self):
return bitstring.pack('uint:8', self.IDX_MAP[idx])
def encode_const_field(self):
return self.IDX_MAP[self.idx] << 4
def __repr__(self):
return "<ImmediateSlot #%d at 0x%x; contents=%s>" % (
......@@ -867,8 +929,8 @@ class Uniform:
return ConstantSrc(token.high32)
def encode(self):
return bitstring.pack('uint:1=1, uint:7', self.idx)
def encode_const_field(self):
return 0x80 | self.idx
def canonical_idx_str(self):
canonical_idx = self.idx * 2
......@@ -1115,6 +1177,8 @@ class Clause:
print('\tInstructions:')
for i in self.instructions:
print('\t\t%s' % i)
print('\t\t\t0x%x' % i.reg_file.encode().uint)
for stage in i.stages:
if hasattr(stage, 'encode'):
encoded = stage.encode()
......@@ -1125,7 +1189,7 @@ class Clause:
else:
encoded_str_tg = encoded
print("\t\t\tEncoded: %s" % encoded_str_tg)
print("\t\t\t%s" % encoded_str_tg)
if self.immediate_slots:
print('\tImmediate slots:')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment