[Libre-soc-dev] my current plan regarding simdsignal

Jacob Lifshay programmerjake at gmail.com
Fri Oct 22 21:19:24 BST 2021


On Fri, Oct 22, 2021, 10:46 lkcl <luke.leighton at gmail.com> wrote:
>On October 22, 2021 5:28:29 PM UTC, Jacob Lifshay <programmerjake at gmail.com>
wrote:
>>On Fri, Oct 22, 2021, 04:05 lkcl <luke.leighton at gmail.com> wrote:
>>> also: given the "carrying of context" (PartType), the idea of
>>throwing
>>> out SimdSignal.ptype and making it a global is *definitely* a
>>nonstarter.
>>> it was already a non-starter due to being global (which is frowned
>>> on in general, in python, so please don't start making design
>>assumptions
>>> that rely on any globals of any kind, please) but it's just not going
>>to
>>work.
>>
>>To be clear, SimdSignal would always access its SimdScope through a
>>member
>>variable, specifically: self.shape.scope.
>
>simply passing in the SimdScope as an argument to all SimdSignals, via the
new function >SimdScope.Signal, is sufficient.
>
>modifying SimdShape after-the-fact to add in scope? mmm... yyeah, honestly
it doesn't matter how it >gets there.
>
>(this will make sense when you read the comments / commits of a few hours
ago)

Apparently you didn't know that I already read the git commits before
writing the email you're replying to. I intended for SimdShape to be the
container class that holds all layout information for the shape of a
SimdSignal, it is immutable and shared between all SimdSignals that have
the same shape (technically there can be different SimdShape instances for
the same shape, but they are all equivalent -- sorta like (1, 2) can have
different instances but all such instances are entirely equivalent).

SimdShape needs a scope member if we want it to derive from Shape in the
manner you were demanding, otherwise it won't know how to calculate its
width member.

SimdShape needs to *not* have a SimdSignal member, which would be kinda
like:
For this example:
k = "abc"
d = {k: 1}
Demanding that the string k must have a k.d member that points to d since d
uses k, which is patently absurd.

I'm proposing that SimdShape be basically:

class SimdShape(Shape):
    def __init__(self, el_shapes=None, *, fixed_width=None, scope=None):
        if isinstance(el_shapes, SimdShape):
            assert fixed_width is None
            assert scope is None or scope is el_shapes.scope, "scope
mismatch"
            # copy all members, idk if this is legal in Python, but you get
the idea
            self.__dict__ = el_shapes.__dict__.copy() # __frozen is also
copied
            return
        if scope is None:
            scope = SimdScope.get()
        assert isinstance(scope, SimdScope)
        self.scope = scope
        # convert el_shapes to a SimdMap of Shapes
        if el_shapes is None:
            el_shapes = 1 # default to u1, just like Signal()
        self.el_shapes = SimdMap.map(Shape.cast, el_shapes)
        def merge_signed(a, b):
            assert a == b, "all elements must have same signedness"
            return a
        signed = reduce(merge_signed, map(lambda s: s.signed,
self.el_shapes.values()))
        # rest of layout() inlined here, assigning to member vars instead
of returning
        super().__init__(width, signed)
        self.__frozen = True

    __frozen = False

    def __setattr__(self, name, value):
        if self.__frozen:
            raise ValueError("SimdShape is immutable")
        super().__setattr__(name, value)

    def __delattr__(self, name):
        if self.__frozen:
            raise ValueError("SimdShape is immutable")
        super().__delattr__(name)

    def __hash__(self):
        return hash((self.scope, self.el_shapes, self.fixed_width))

    def __eq__(self, r):
        if not isinstance(r, SimdScope):
            return False # stop SimdScope == Scope, since they're not
equivalent
        return (self.scope, self.el_shapes, self.fixed_width) \
            == (r.scope, r.el_shapes, r.fixed_width)

Jacob

>


More information about the Libre-soc-dev mailing list