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

lkcl luke.leighton at gmail.com
Fri Oct 22 22:45:56 BST 2021

argh k9 mail client crashed, took out 30 mins reply. monster headache, have to rest.  brief inline, explain when better.

On October 22, 2021 8:19:24 PM UTC, Jacob Lifshay <programmerjake at gmail.com> wrote:
>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>
>>>On Fri, Oct 22, 2021, 04:05 lkcl <luke.leighton at gmail.com> wrote:
>>>> also: given the "carrying of context" (PartType), the idea of
>>>> out SimdSignal.ptype and making it a global is *definitely* a
>>>> 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
>>>> that rely on any globals of any kind, please) but it's just not
>>>To be clear, SimdSignal would always access its SimdScope through a
>>>variable, specifically: self.shape.scope.
>>simply passing in the SimdScope as an argument to all SimdSignals, via
>new function >SimdScope.Signal, is sufficient.
>>modifying SimdShape after-the-fact to add in scope? mmm... yyeah,
>it doesn't matter how it >gets there.
>>(this will make sense when you read the comments / commits of a few
>Apparently you didn't know that I already read the git commits before
>writing the email you're replying to.

cant guess everything.

> I intended for SimdShape to be
>container class that holds all layout information for the shape of a
>SimdSignal, it is immutable and shared between all SimdSignals that
>the same shape (technically there can be different SimdShape instances
>the same shape, but they are all equivalent -- sorta like (1, 2) can
>different instances but all such instances are entirely equivalent).

still doable.  set_scope function ok.

>SimdShape needs a scope member if we want it to derive from Shape in
>manner you were demanding, 

not demanding. oversight. sorry.

>otherwise it won't know how to calculate its
>width member.

true. what's chain there

>SimdShape needs to *not* have a SimdSignal member,

of course not. absurd.  other way round, yes. or access to it.

> which would be kinda
>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
>        # copy all members, idk if this is legal in Python, but you get
>the idea

yes. generally a pain though.

SimdShape.set_scope(), called inside ContextManager, should be ok.

check if already called, check if same.  never going to use multiple scopes within one module so ok.

>           self.__dict__ = el_shapes.__dict__.copy() # __frozen is also
>            return
>        if scope is None:
>            scope = SimdScope.get()

no globals.  has to go.

>        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,
>      # 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
>        return (self.scope, self.el_shapes, self.fixed_width) \
>            == (r.scope, r.el_shapes, r.fixed_width)

More information about the Libre-soc-dev mailing list