blob: d81965f6fbf02ee31d6d2029bee56521d6790402 [file]
# Copyright 2020 Project U-Ray Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
frame_set_bits = {}
group_set_bits = {}
line_re = re.compile(r'F(0x[0-9A-Fa-f]+)W(\d+)B(\d+)')
with open("bram.dump", "r") as df:
for line in df:
m = line_re.match(line)
if not m:
continue
frame = int(m[1], 16)
if (frame >> 24) != 0x01:
continue
frame = frame & 0xFF
if frame not in frame_set_bits:
frame_set_bits[frame] = set()
framebit = int(m[2]) * 32 + int(m[3])
frame_set_bits[frame].add(framebit)
with open("bram.txt", "r") as ef:
for line in ef:
frame, startbit, site_y, data, parity = line.strip().split(" ")
frame = int(frame)
startbit = int(startbit)
site_y = int(site_y)
data = [int(x) for x in data]
parity = [int(x) for x in parity]
if (frame, startbit) not in group_set_bits:
group_set_bits[frame, startbit] = set()
for i, d in enumerate(data):
if d != 1:
continue
group_set_bits[frame, startbit].add("%d_%d" % (site_y, i))
for i, d in enumerate(parity):
if d != 1:
continue
group_set_bits[frame, startbit].add("%d_P%d" % (site_y, i))
#features = []
#for y in range(2):
# features += ["%d_%d" % (y, i) for i in range(64)]
# features += ["%d_P%d" % (y, i) for i in range(8)]
bram_permute = []
for i, prefix in enumerate(("0_", "0_P", "1_", "1_P")):
permute = []
for j in range(8 if prefix.endswith("P") else 64):
f = "%s%d" % (prefix, j)
candidates = None
for group, features in group_set_bits.items():
if f not in features:
continue
frame, startbit = group
if frame not in frame_set_bits:
continue
set_bits = frame_set_bits[frame]
if candidates is None:
candidates = set()
for b in range(startbit, startbit + 240):
if b in set_bits:
candidates.add(b - startbit)
else:
todelete = []
for c in candidates:
if (startbit + c) not in set_bits:
todelete.append(c)
for t in todelete:
candidates.remove(t)
print("%s: %s" % (f, " ".join([str(c) for c in sorted(candidates)])))
permute.append(list(candidates)[0])
bram_permute.append(permute)
for i, cname in enumerate(("bram_y0_permute", "bram_p_y0_permute", "bram_y1_permute", "bram_p_y1_permute")):
p = bram_permute[i]
print("static const int %s[%d] = {%s};" % (
cname, len(p), ", ".join(str(x) for x in p)
))