Skip to content

Commit

Permalink
Merge branch 'master' into tilk/assertions-cocotb
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk authored Mar 5, 2024
2 parents 2666ea6 + 3393996 commit 2395311
Show file tree
Hide file tree
Showing 51 changed files with 499 additions and 311 deletions.
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
8 changes: 0 additions & 8 deletions coreblocks/frontend/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ def __init__(self, gen_params: GenParams, icache: CacheInterface, cont: Method)
# ExceptionCauseRegister uses separate Transaction for it, so performace is not affected.
self.stall_exception.add_conflict(self.resume, Priority.LEFT)

# PC of the last fetched instruction. For now only used in tests.
self.pc = Signal(self.gen_params.isa.xlen)

def elaborate(self, platform):
m = TModule()

Expand Down Expand Up @@ -91,7 +88,6 @@ def stall(exception=False):
with m.If(unsafe_instr):
stall()

m.d.sync += self.pc.eq(target.addr)
m.d.comb += instr.eq(res.instr)

self.cont(m, instr=instr, pc=target.addr, access_fault=fetch_error, rvc=0)
Expand Down Expand Up @@ -138,9 +134,6 @@ def __init__(self, gen_params: GenParams, icache: CacheInterface, cont: Method)

self.perf_rvc = HwCounter("frontend.ifu.rvc", "Number of decompressed RVC instructions")

# PC of the last fetched instruction. For now only used in tests.
self.pc = Signal(self.gen_params.isa.xlen)

def elaborate(self, platform) -> TModule:
m = TModule()

Expand Down Expand Up @@ -231,7 +224,6 @@ def elaborate(self, platform) -> TModule:
m.d.sync += stalled_unsafe.eq(1)
m.d.sync += flushing.eq(1)

m.d.sync += self.pc.eq(current_pc)
with m.If(~cache_resp.error):
m.d.sync += current_pc.eq(current_pc + Mux(is_rvc, C(2, 3), C(4, 3)))

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
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
36 changes: 31 additions & 5 deletions stubs/amaranth/hdl/mem.pyi → stubs/amaranth/hdl/_mem.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,33 @@ This type stub file was generated by pyright.

from typing import Optional
from .ast import *
from .ir import Elaboratable
from .ir import Elaboratable, Fragment

__all__ = ["Memory", "ReadPort", "WritePort", "DummyPort"]
__all__ = ["Memory", "ReadPort", "WritePort", "DummyPort", "MemoryInstance"]
class Memory:
"""A word addressable storage.
"""
Parameters
----------
width : int
Access granularity. Each storage element of this memory is ``width`` bits in size.
depth : int
Word count. This memory contains ``depth`` storage elements.
init : list of int
Initial values. At power on, each storage element in this memory is initialized to
the corresponding element of ``init``, if any, or to zero otherwise.
Uninitialized memories are not currently supported.
name : str
Name hint for this memory. If ``None`` (default) the name is inferred from the variable
name this ``Signal`` is assigned to.
attrs : dict
Dictionary of synthesis attributes.
Attributes
----------
width : int
depth : int
init : list of int
attrs : dict
"""
width: int
depth: int
attrs: dict
Expand Down Expand Up @@ -90,4 +110,10 @@ class DummyPort:
...



class MemoryInstance(Fragment):
memory: Memory
read_ports: list[ReadPort]
write_ports: list[WritePort]
attrs: dict
def __init__(self, memory: Memory, read_ports: list[ReadPort], write_ports: list[WritePort]) -> None:
...
File renamed without changes.
2 changes: 1 addition & 1 deletion stubs/amaranth/lib/data.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from abc import ABCMeta, abstractmethod
from collections.abc import Iterator, Mapping
from typing import TypeVar, Generic, Self
from amaranth.hdl import *
from amaranth.hdl.ast import Assign, ShapeCastable, ValueCastable
from amaranth.hdl._ast import Assign, ShapeCastable, ValueCastable
from transactron.utils._typing import ShapeLike, ValueLike

__all__ = ["Field", "Layout", "StructLayout", "UnionLayout", "ArrayLayout", "FlexibleLayout", "View", "Struct", "Union"]
Expand Down
2 changes: 1 addition & 1 deletion stubs/amaranth/lib/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This type stub file was generated by pyright.
import enum as py_enum
from typing import Generic, Optional, TypeVar, Self, overload
from amaranth import *
from ..hdl.ast import Assign, ValueCastable, ShapeCastable, ValueLike
from ..hdl._ast import Assign, ValueCastable, ShapeCastable, ValueLike

__all__ = ['EnumMeta', 'Enum', 'IntEnum', 'Flag', 'IntFlag', 'EnumView', 'FlagView', 'auto', 'unique']

Expand Down
Loading

0 comments on commit 2395311

Please sign in to comment.