Skip to content

Commit

Permalink
Merge branch 'master' into lekcyjna/add-pytest-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekcyjna committed Mar 5, 2024
2 parents 3aab641 + 0e4f74d commit f7c5fdf
Show file tree
Hide file tree
Showing 56 changed files with 692 additions and 148 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: "verilog-full-core"
path: core.v
path: |
core.v
core.v.json
build-riscof-tests:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ venv.bak/
# Verilog files
*.v

# Verilog generation debug files
*.v.json

# Waveform dumps
*.vcd
*.gtkw
Expand Down
2 changes: 1 addition & 1 deletion constants/ecp5_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from itertools import chain
from typing import TypeAlias
from amaranth.build.dsl import Subsignal
from amaranth.vendor.lattice_ecp5 import LatticeECP5Platform
from amaranth.vendor import LatticeECP5Platform
from amaranth.build import Resource, Attrs, Pins, Clock, PinsN

from constants.ecp5_pinout import ecp5_bg756_pins, ecp5_bg756_pclk
Expand Down
6 changes: 3 additions & 3 deletions coreblocks/cache/icache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import operator

from amaranth import *
from amaranth.utils import log2_int
from amaranth.utils import exact_log2

from transactron.core import def_method, Priority, TModule
from transactron import Method, Transaction
Expand Down Expand Up @@ -52,7 +52,7 @@ def _(addr: Value) -> None:
m.d.sync += req_addr.eq(addr)
self.bus_master.request_read(
m,
addr=addr >> log2_int(self.params.word_width_bytes),
addr=addr >> exact_log2(self.params.word_width_bytes),
sel=C(1).replicate(self.bus_master.params.data_width // self.bus_master.params.granularity),
)

Expand Down Expand Up @@ -350,7 +350,7 @@ def elaborate(self, platform):

# We address the data RAM using machine words, so we have to
# discard a few least significant bits from the address.
redundant_offset_bits = log2_int(self.params.word_width_bytes)
redundant_offset_bits = exact_log2(self.params.word_width_bytes)
rd_addr = Cat(self.data_rd_addr.offset, self.data_rd_addr.index)[redundant_offset_bits:]
wr_addr = Cat(self.data_wr_addr.offset, self.data_wr_addr.index)[redundant_offset_bits:]

Expand Down
7 changes: 4 additions & 3 deletions coreblocks/cache/refiller.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from amaranth import *
from coreblocks.cache.icache import CacheRefillerInterface
from coreblocks.params import ICacheLayouts, ICacheParameters
from coreblocks.peripherals.bus_adapter import BusMasterInterface
from transactron.core import Transaction
from transactron.lib import C, Cat, Elaboratable, Forwarder, Method, Signal, TModule, def_method
from transactron.lib import Forwarder, Method, TModule, def_method

from amaranth.utils import log2_int
from amaranth.utils import exact_log2


__all__ = ["SimpleCommonBusCacheRefiller"]
Expand Down Expand Up @@ -62,7 +63,7 @@ def _():
address_fwd.write(m, word_counter=next_word_counter, refill_address=refill_address)

return {
"addr": Cat(C(0, log2_int(self.params.word_width_bytes)), word_counter, refill_address),
"addr": Cat(C(0, exact_log2(self.params.word_width_bytes)), word_counter, refill_address),
"data": fetched.data,
"error": fetched.err,
"last": last,
Expand Down
9 changes: 6 additions & 3 deletions coreblocks/frontend/instr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,23 @@ class Encoding:
Encoding(Opcode.OP, Funct3.MIN, Funct7.MIN),
Encoding(Opcode.OP, Funct3.MINU, Funct7.MIN),
Encoding(Opcode.OP, Funct3.ORN, Funct7.ORN),
Encoding(Opcode.OP, Funct3.XNOR, Funct7.XNOR),
],
OpType.BIT_ROTATION: [
Encoding(Opcode.OP, Funct3.ROL, Funct7.ROL),
Encoding(Opcode.OP, Funct3.ROR, Funct7.ROR),
Encoding(Opcode.OP_IMM, Funct3.ROR, Funct7.ROR),
Encoding(Opcode.OP, Funct3.XNOR, Funct7.XNOR),
],
OpType.UNARY_BIT_MANIPULATION_1: [
Encoding(Opcode.OP_IMM, Funct3.ORCB, funct12=Funct12.ORCB),
Encoding(Opcode.OP_IMM, Funct3.REV8, funct12=Funct12.REV8_32),
Encoding(Opcode.OP_IMM, Funct3.SEXTB, funct12=Funct12.SEXTB),
Encoding(Opcode.OP, Funct3.ZEXTH, funct12=Funct12.ZEXTH),
],
# Instructions SEXTH, SEXTHB, CPOP, CLZ and CTZ cannot be distiguished by their Funct7 code
# Instructions SEXTH, SEXTHB, CPOP, CLZ and CTZ cannot be distiguished by their Funct7 code
# ORCB is here because of optimization to not lookup Funct7 in UNARY_BIT_MANIPULATION_1
OpType.UNARY_BIT_MANIPULATION_2: [
Encoding(Opcode.OP_IMM, Funct3.SEXTH, funct12=Funct12.SEXTH),
Encoding(Opcode.OP_IMM, Funct3.ORCB, funct12=Funct12.ORCB),
],
OpType.UNARY_BIT_MANIPULATION_3: [
Encoding(Opcode.OP_IMM, Funct3.CLZ, funct12=Funct12.CLZ),
Expand Down
16 changes: 8 additions & 8 deletions coreblocks/fu/alu.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ def get_instructions(self) -> Sequence[tuple]:
(self.Fn.MAXU, OpType.BIT_MANIPULATION, Funct3.MAXU, Funct7.MAX),
(self.Fn.MIN, OpType.BIT_MANIPULATION, Funct3.MIN, Funct7.MIN),
(self.Fn.MINU, OpType.BIT_MANIPULATION, Funct3.MINU, Funct7.MIN),
(self.Fn.ORCB, OpType.UNARY_BIT_MANIPULATION_1, Funct3.ORCB, Funct7.ORCB),
(self.Fn.REV8, OpType.UNARY_BIT_MANIPULATION_1, Funct3.REV8, Funct7.REV8),
(self.Fn.SEXTB, OpType.UNARY_BIT_MANIPULATION_1, Funct3.SEXTB, Funct7.SEXTB),
(self.Fn.ZEXTH, OpType.UNARY_BIT_MANIPULATION_1, Funct3.ZEXTH, Funct7.ZEXTH),
(self.Fn.CPOP, OpType.UNARY_BIT_MANIPULATION_5, Funct3.CPOP, Funct7.CPOP),
(self.Fn.SEXTH, OpType.UNARY_BIT_MANIPULATION_2, Funct3.SEXTH, Funct7.SEXTH),
(self.Fn.CLZ, OpType.UNARY_BIT_MANIPULATION_3, Funct3.CLZ, Funct7.CLZ),
(self.Fn.CTZ, OpType.UNARY_BIT_MANIPULATION_4, Funct3.CTZ, Funct7.CTZ),
(self.Fn.REV8, OpType.UNARY_BIT_MANIPULATION_1, Funct3.REV8),
(self.Fn.SEXTB, OpType.UNARY_BIT_MANIPULATION_1, Funct3.SEXTB),
(self.Fn.ZEXTH, OpType.UNARY_BIT_MANIPULATION_1, Funct3.ZEXTH),
(self.Fn.ORCB, OpType.UNARY_BIT_MANIPULATION_2, Funct3.ORCB),
(self.Fn.SEXTH, OpType.UNARY_BIT_MANIPULATION_2, Funct3.SEXTH),
(self.Fn.CLZ, OpType.UNARY_BIT_MANIPULATION_3, Funct3.CLZ),
(self.Fn.CTZ, OpType.UNARY_BIT_MANIPULATION_4, Funct3.CTZ),
(self.Fn.CPOP, OpType.UNARY_BIT_MANIPULATION_5, Funct3.CPOP),
]
* self.zbb_enable
)
Expand Down
4 changes: 2 additions & 2 deletions coreblocks/fu/shift_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def get_instructions(self) -> Sequence[tuple]:
(self.Fn.SRL, OpType.SHIFT, Funct3.SR, Funct7.SL),
(self.Fn.SRA, OpType.SHIFT, Funct3.SR, Funct7.SA),
] + [
(self.Fn.ROR, OpType.BIT_MANIPULATION, Funct3.ROR, Funct7.ROR),
(self.Fn.ROL, OpType.BIT_MANIPULATION, Funct3.ROL, Funct7.ROL),
(self.Fn.ROR, OpType.BIT_ROTATION, Funct3.ROR),
(self.Fn.ROL, OpType.BIT_ROTATION, Funct3.ROL),
] * self.zbb_enable


Expand Down
6 changes: 3 additions & 3 deletions coreblocks/lsu/dummyLsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def postprocess_load_data(self, m: ModuleLike, funct3: Value, raw_data: Value, a
m.d.av_comb += data.eq(tmp.as_signed())
with m.Else():
m.d.av_comb += data.eq(tmp)
with m.Case():
with m.Default():
m.d.av_comb += data.eq(raw_data)
return data

Expand All @@ -84,7 +84,7 @@ def prepare_data_to_save(self, m: ModuleLike, funct3: Value, raw_data: Value, ad
m.d.av_comb += data.eq(raw_data[0:8] << (addr[0:2] << 3))
with m.Case(Funct3.H):
m.d.av_comb += data.eq(raw_data[0:16] << (addr[1] << 4))
with m.Case():
with m.Default():
m.d.av_comb += data.eq(raw_data)
return data

Expand All @@ -95,7 +95,7 @@ def check_align(self, m: TModule, funct3: Value, addr: Value):
m.d.av_comb += aligned.eq(addr[0:2] == 0)
with m.Case(Funct3.H, Funct3.HU):
m.d.av_comb += aligned.eq(addr[0] == 0)
with m.Case():
with m.Default():
m.d.av_comb += aligned.eq(1)
return aligned

Expand Down
4 changes: 2 additions & 2 deletions coreblocks/params/genparams.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from amaranth.utils import log2_int
from amaranth.utils import exact_log2

from .isa import ISA, gen_isa_string
from .icache_params import ICacheParameters
Expand Down Expand Up @@ -36,7 +36,7 @@ def __init__(self, cfg: CoreConfiguration):

bytes_in_word = self.isa.xlen // 8
self.wb_params = WishboneParameters(
data_width=self.isa.xlen, addr_width=self.isa.xlen - log2_int(bytes_in_word)
data_width=self.isa.xlen, addr_width=self.isa.xlen - exact_log2(bytes_in_word)
)

self.icache_params = ICacheParameters(
Expand Down
2 changes: 1 addition & 1 deletion coreblocks/params/instr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import abstractmethod, ABC

from amaranth.hdl.ast import ValueCastable
from amaranth.hdl import ValueCastable
from amaranth import *

from transactron.utils import ValueLike
Expand Down
2 changes: 2 additions & 0 deletions coreblocks/params/optypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OpType(IntEnum):
SINGLE_BIT_MANIPULATION = auto()
ADDRESS_GENERATION = auto()
BIT_MANIPULATION = auto()
BIT_ROTATION = auto()
UNARY_BIT_MANIPULATION_1 = auto()
UNARY_BIT_MANIPULATION_2 = auto()
UNARY_BIT_MANIPULATION_3 = auto()
Expand Down Expand Up @@ -88,6 +89,7 @@ class OpType(IntEnum):
],
Extension.ZBB: [
OpType.BIT_MANIPULATION,
OpType.BIT_ROTATION,
OpType.UNARY_BIT_MANIPULATION_1,
OpType.UNARY_BIT_MANIPULATION_2,
OpType.UNARY_BIT_MANIPULATION_3,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
amaranth-yosys==0.35.0.0.post81
git+https://github.com/amaranth-lang/amaranth@94c504afc7d81738ecdc9523a2615ef43ecbf51a
git+https://github.com/amaranth-lang/amaranth@115954b4d957b4ba642ad056ab1670bf5d185fb6
dataclasses-json==0.6.3
20 changes: 12 additions & 8 deletions scripts/gen_verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import sys
import argparse

from amaranth import *
from amaranth.build import Platform
from amaranth.back import verilog
from amaranth import Module, Elaboratable


if __name__ == "__main__":
parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent)
Expand All @@ -16,8 +17,8 @@
from coreblocks.peripherals.wishbone import WishboneBus
from coreblocks.core import Core
from transactron import TransactionModule
from transactron.utils import flatten_signals
from transactron.utils.dependencies import DependencyManager, DependencyContext
from transactron.utils import flatten_signals, DependencyManager, DependencyContext
from transactron.utils.gen import generate_verilog

from coreblocks.params.configurations import *

Expand All @@ -44,14 +45,17 @@ def elaborate(self, platform: Platform):
return tm


def gen_verilog(core_config: CoreConfiguration, output_path):
def gen_verilog(core_config: CoreConfiguration, output_path: str):
with DependencyContext(DependencyManager()):
top = Top(GenParams(core_config))
gp = GenParams(core_config)
top = Top(gp)
ports = list(flatten_signals(top.wb_instr)) + list(flatten_signals(top.wb_data))

with open(output_path, "w") as f:
signals = list(flatten_signals(top.wb_instr)) + list(flatten_signals(top.wb_data))
verilog_text, gen_info = generate_verilog(top, ports)

f.write(verilog.convert(top, ports=signals, strip_internal_attrs=True))
gen_info.encode(f"{output_path}.json")
with open(output_path, "w") as f:
f.write(verilog_text)


def main():
Expand Down
3 changes: 3 additions & 0 deletions scripts/run_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def run_benchmarks_with_cocotb(benchmarks: list[str], traces: bool) -> bool:
arglist += [f"TESTCASE={test_cases}"]

verilog_code = topdir.joinpath("core.v")
gen_info_path = f"{verilog_code}.json"

arglist += [f"VERILOG_SOURCES={verilog_code}"]
arglist += [f"_COREBLOCKS_GEN_INFO={gen_info_path}"]

if traces:
arglist += ["TRACES=1"]
Expand Down
3 changes: 3 additions & 0 deletions scripts/run_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def run_with_cocotb(test_name: str, traces: bool, output: str) -> bool:
arglist += [f"OUTPUT={output}"]

verilog_code = f"{parent}/core.v"
gen_info_path = f"{verilog_code}.json"

arglist += [f"VERILOG_SOURCES={verilog_code}"]
arglist += [f"_COREBLOCKS_GEN_INFO={gen_info_path}"]

if traces:
arglist += ["TRACES=1"]
Expand Down
13 changes: 13 additions & 0 deletions stubs/amaranth/_unused.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
import warnings

__all__ = ["UnusedMustUse", "MustUse"]


class UnusedMustUse(Warning):
pass


class MustUse:
_MustUse__silence : bool
_MustUse__warning : UnusedMustUse
2 changes: 1 addition & 1 deletion stubs/amaranth/build/res.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This type stub file was generated by pyright.
"""

from typing import Any
from ..hdl.ast import *
from ..hdl._ast import *
from ..hdl.rec import *
from ..lib.io import *
from .dsl import *
Expand Down
38 changes: 27 additions & 11 deletions stubs/amaranth/hdl/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
"""
This type stub file was generated by pyright.
"""

from .ast import Array, C, Cat, ClockSignal, Const, Mux, Repl, ResetSignal, Shape, Signal, Value, signed, unsigned
from .dsl import Module
from .cd import ClockDomain
from .ir import Elaboratable, Fragment, Instance
from .mem import Memory
from ._ast import Shape, unsigned, signed, ShapeCastable, ShapeLike
from ._ast import Value, ValueCastable, ValueLike
from ._ast import Const, C, Mux, Cat, Array, Signal, ClockSignal, ResetSignal
from ._dsl import SyntaxError, SyntaxWarning, Module
from ._cd import DomainError, ClockDomain
from ._ir import UnusedElaboratable, Elaboratable, DriverConflict, Fragment, Instance
from ._mem import Memory, ReadPort, WritePort, DummyPort
from .rec import Record
from .xfrm import DomainRenamer, EnableInserter, ResetInserter
from ._xfrm import DomainRenamer, ResetInserter, EnableInserter


__all__ = ["Shape", "unsigned", "signed", "Value", "Const", "C", "Mux", "Cat", "Repl", "Array", "Signal", "ClockSignal", "ResetSignal", "Module", "ClockDomain", "Elaboratable", "Fragment", "Instance", "Memory", "Record", "DomainRenamer", "ResetInserter", "EnableInserter"]
__all__ = [
# _ast
"Shape", "unsigned", "signed", "ShapeCastable", "ShapeLike",
"Value", "ValueCastable", "ValueLike",
"Const", "C", "Mux", "Cat", "Array", "Signal", "ClockSignal", "ResetSignal",
# _dsl
"SyntaxError", "SyntaxWarning", "Module",
# _cd
"DomainError", "ClockDomain",
# _ir
"UnusedElaboratable", "Elaboratable", "DriverConflict", "Fragment", "Instance",
# _mem
"Memory", "ReadPort", "WritePort", "DummyPort",
# _rec
"Record",
# _xfrm
"DomainRenamer", "ResetInserter", "EnableInserter",
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions stubs/amaranth/hdl/ir.pyi → stubs/amaranth/hdl/_ir.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ This type stub file was generated by pyright.
"""

from abc import abstractmethod
from .ast import *
from .cd import *
from ._ast import *
from ._cd import *
from .. import _unused
from transactron.utils import HasElaborate

__all__ = ["Elaboratable", "DriverConflict", "Fragment", "Instance"]
__all__ = ["UnusedElaboratable", "Elaboratable", "DriverConflict", "Fragment", "Instance"]


class UnusedElaboratable(_unused.UnusedMustUse):
...

class Elaboratable():
@abstractmethod
def elaborate(self, platform) -> HasElaborate:
Expand Down
Loading

0 comments on commit f7c5fdf

Please sign in to comment.