2c5153ed5d33f71fb516b14be4fc872dab555f79
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2 # See Notices.txt for copyright information
5 Copyright (C) 2020 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
7 dynamic-partitionable class similar to Signal, which, when the partition
8 is fully open will be identical to Signal. when partitions are closed,
9 the class turns into a SIMD variant of Signal. *this is dynamic*.
11 the basic fundamental idea is: write code once, and if you want a SIMD
12 version of it, use SimdSignal in place of Signal. job done.
13 this however requires the code to *not* be designed to use nmigen.If,
14 nmigen.Case, or other constructs: only Mux and other logic.
16 * http://bugs.libre-riscv.org/show_bug.cgi?id=132
19 from ieee754
.part_mul_add
.adder
import PartitionedAdder
20 from ieee754
.part_cmp
.eq_gt_ge
import PartitionedEqGtGe
21 from ieee754
.part_bits
.xor
import PartitionedXOR
22 from ieee754
.part_bits
.bool import PartitionedBool
23 from ieee754
.part_bits
.all
import PartitionedAll
24 from ieee754
.part_shift
.part_shift_dynamic
import PartitionedDynamicShift
25 from ieee754
.part_shift
.part_shift_scalar
import PartitionedScalarShift
26 from ieee754
.part_mul_add
.partpoints
import make_partition2
, PartitionPoints
27 from ieee754
.part_mux
.part_mux
import PMux
28 from ieee754
.part_ass
.passign
import PAssign
29 from ieee754
.part_cat
.pcat
import PCat
30 from ieee754
.part_repl
.prepl
import PRepl
31 from ieee754
.part
.simd_scope
import SimdScope
32 from ieee754
.part
.layout_experiment
import layout
33 from operator
import or_
, xor
, and_
, not_
35 from nmigen
import (Signal
, Const
, Cat
)
36 from nmigen
.hdl
.ast
import UserValue
, Shape
40 if isinstance(op1
, SimdSignal
):
45 def applyop(op1
, op2
, op
):
46 if isinstance(op1
, SimdSignal
):
47 result
= SimdSignal
.like(op1
)
49 result
= SimdSignal
.like(op2
)
50 result
.m
.d
.comb
+= result
.sig
.eq(op(getsig(op1
), getsig(op2
)))
56 # for sub-modules to be created on-demand. Mux is done slightly
57 # differently (has its own global)
58 for name
in ['add', 'eq', 'gt', 'ge', 'ls', 'xor', 'bool', 'all']:
62 def get_runlengths(pbit
, size
):
65 # identify where the 1s are, which indicates "start of a new partition"
66 # we want a list of the lengths of all partitions
68 if pbit
& (1 << i
): # it's a 1: ends old partition, starts new
69 res
.append(count
) # add partition
70 count
= 1 # start again
73 # end reached, add whatever is left. could have done this by creating
74 # "fake" extra bit on the partitions, but hey
80 # Prototype https://bugs.libre-soc.org/show_bug.cgi?id=713#c53
81 # this provides a "compatibility" layer with existing SimdSignal
82 # behaviour. the idea is that this interface defines which "combinations"
83 # of partition selections are relevant, and as an added bonus it says
84 # which partition lanes are completely irrelevant (padding, blank).
85 class PartType
: # TODO decide name
86 def __init__(self
, psig
):
90 return list(self
.psig
.partpoints
.values())
93 return Cat(self
.get_mask())
96 return range(1 << len(self
.get_mask()))
98 def get_num_elements(self
, pbit
):
99 keys
= list(self
.psig
.partpoints
.keys())
100 return len(get_runlengths(pbit
, len(keys
)))
102 def get_el_range(self
, pbit
, el_num
):
103 """based on the element number and the current elwid/pbit (case)
104 return the range start/end of the element within its underlying signal
105 this function is not at all designed to be efficient.
107 keys
= list(self
.psig
.partpoints
.keys())
108 runs
= get_runlengths(pbit
, len(keys
))
109 keys
= [0] + keys
+ [len(self
.psig
.sig
)]
111 for i
in range(el_num
):
114 numparts
= runs
[el_num
]
115 return range(keys
[y
], keys
[y
+numparts
])
118 def blanklanes(self
):
122 # this one would be an elwidth version
123 # see https://bugs.libre-soc.org/show_bug.cgi?id=713#c34
124 # it requires an "adapter" which is the layout() function
125 # where the PartitionPoints was *created* by the layout()
126 # function and this class then "understands" the relationship
127 # between elwidth and the PartitionPoints that were created
129 class ElwidPartType
: # TODO decide name
130 def __init__(self
, psig
):
134 return list(self
.psig
._shape
.partpoints
.values()) # i think
136 def get_switch(self
):
137 return self
.psig
.scope
.elwid
# switch on elwid: match get_cases()
140 return self
.psig
._shape
.bitp
.keys() # all possible values of elwid
143 def blanklanes(self
):
144 return self
.psig
.shape
.blankmask
147 # declares priority of the SimdShape
148 PRIORITY_FIXED
= 0b01
149 PRIORITY_ELWID
= 0b10
152 class SimdShape(Shape
):
153 """a SIMD variant of Shape. supports:
154 * fixed overall width with variable (maxed-out) element lengths
155 * fixed element widths with overall size auto-determined
156 * both fixed overall width and fixed element widths
158 Documentation / Analysis:
159 https://libre-soc.org/3d_gpu/architecture/dynamic_simd/shape/
161 naming is preserved to be compatible with Shape(): the (calculated *or*
162 given) fixed_width is *explicitly* passed through as Shape.width
163 in order to ensure downcasting works as expected.
165 the width parameter is exactly what would be expected if this was
166 a Scalar Shape: it can however be given a dictionary of alternative
167 widths on a per-elwid basis.
169 a mode flag records what behaviour is required for arithmetic operators.
170 see wiki documentation: it's... complicated.
173 def __init__(self
, scope
, width
=None, # this is actually widths_at_elwid
175 fixed_width
=None): # fixed overall width
176 # record the mode and scope
178 self
.fixed_width
= fixed_width
179 self
.widths_at_elwid
= width
181 # when both of these are set it creates mode_flag=PRIORITY_BOTH
182 # otherwise creates a priority of either FIXED width or ELWIDs
183 if self
.fixed_width
is not None:
184 self
.mode_flag |
= PRIORITY_FIXED
185 if self
.widths_at_elwid
is not None:
186 self
.mode_flag |
= PRIORITY_ELWID
188 print("SimdShape width", width
, "fixed_width", fixed_width
)
189 # this check is done inside layout but do it again here anyway
190 assert self
.fixed_width
!= None or self
.widths_at_elwid
!= None, \
191 "both width (widths_at_elwid) and fixed_width cannot be None"
193 if scope
is not None:
194 (pp
, bitp
, lpoints
, bmask
, width
, lane_shapes
, part_wid
) = \
197 self
.widths_at_elwid
,
200 self
.bitp
= bitp
# binary values for partpoints at each elwidth
201 self
.lpoints
= lpoints
# layout ranges
202 self
.blankmask
= bmask
# blanking mask (partitions always padding)
203 self
.partwid
= part_wid
# smallest alignment start point for elements
204 self
.lane_shapes
= lane_shapes
206 # pass through the calculated width to Shape() so that when/if
207 # objects using this Shape are downcast, they know exactly how to
208 # get *all* bits and need know absolutely nothing about SIMD at all
209 Shape
.__init
__(self
, width
, signed
)
212 def like(cls
, shape
, *, scope
=None):
215 return SimdShape(scope
, shape
.widths_at_elwid
, shape
.signed
,
218 def __mul__(self
, other
):
219 if isinstance(other
, int):
220 # for integer multiply, by a nice coincidence it does not
221 # matter if the LHS is PRIORITY_FIXED or PRIORITY_ELWID.
222 # however the priority has to be preserved.
226 # first, check if fixed_width is needed (if originally,
227 # self was constructed with a fixed_width=None we must
228 # *return* another SimdShape with a fixed_width=None)
229 if self
.mode_flag
& PRIORITY_FIXED
:
230 fixed_width
= self
.width
* other
232 # likewise for lane elwidths: if, originally, self was constructed
233 # with [widths_at_elwidth==lane_shapes==]width not None,
234 # the return result also has to set up explicit lane_shapes
235 if self
.mode_flag
& PRIORITY_ELWID
:
236 lane_shapes
= {k
: v
* other
for k
, v
in self
.lane_shapes
}
238 # wheww, got everything.
239 return SimdShape(self
.scope
, # same scope
240 width
=lane_shapes
, # widths_at_elwid
241 signed
=self
.signed
, # same sign? hmmm XXX
242 fixed_width
=fixed_width
) # overall width
244 raise NotImplementedError(
245 f
"Multiplying a SimdShape by {type(other)} isn't implemented")
247 # TODO (and go over examples, sigh). this is deliberately *after*
248 # the raise NotImplementedError because it needs review.
250 # also probably TODO: potentially the other argument could be
251 # a Shape() not a SimdShape(). sigh.
253 # for SimdShape-to-SimdShape multiply, the rules are slightly
254 # different: both sides have to be PRIORITY_FIXED for a
255 # PRIORITY_FIXED result to be returned. if either (or both)
256 # of the LHS and RHS were given elwidths (lane_shapes != None)
257 # then tough luck: the return result is still PRIORITY_ELWID.
258 # TODO: review that. it *might* be the case (again, due to
259 # a coincidence of multiply, that when PRIORITY_BOTH is set
260 # it is possible to return a PRIORITY_BOTH result. but..
266 # first, check if this is fixed_width mode. this is *only*
267 # possible if *both* LHS *and* RHS are PRIORITY_FIXED.
268 if (self
.mode_flag
== PRIORITY_FIXED
and
269 other
.mode_flag
== PRIORITY_FIXED
):
270 fixed_width
= self
.width
* other
.width
272 # (XXX assume other is SimdShape) - when PRIORITY_ELWID
273 # the result *has* to be a PRIORITY_ELWID (FIXED is *IGNORED*)
274 # use *either* the computed *or* the given lane_shapes
275 lane_shapes
= {k
: v
* other
.lane_shapes
[k
] \
276 for k
, v
in self
.lane_shapes
}
278 # wheww, got everything.
279 return SimdShape(self
.scope
, # same scope
280 width
=lane_shapes
, # widths_at_elwid
281 signed
=self
.signed
, # same sign? hmmm XXX
282 fixed_width
=fixed_width
) # overall width
285 def __rmul__(self
, other
):
286 return self
.__mul
__(other
)
288 def __add__(self
, other
):
289 if isinstance(other
, int):
290 lane_shapes
= {k
: v
+ other
for k
, v
in self
.lane_shapes
}
291 return SimdShape(self
.scope
, lane_shapes
, signed
=self
.signed
)
292 elif isinstance(other
, SimdShape
):
293 # XXX MO, must be equivalent, not the same object.
294 # requires an eq override just like in Shape.
295 assert other
.scope
is self
.scope
, "scope mismatch"
296 o
= other
.lane_shapes
297 lane_shapes
= {k
: v
+ o
[k
] for k
, v
in self
.lane_shapes
}
298 # XXX not correct, we need a width-hint, not an overwrite
299 # lane_shapes argument...
300 return SimdShape(self
.scope
, lane_shapes
, signed
=self
.signed
,
301 fixed_width
=self
.width
+ other
.width
)
303 raise NotImplementedError(
304 f
"Adding a SimdShape to {type(other)} isn't implemented")
306 def __radd__(self
, other
):
307 return self
.__add
__(other
)
310 class SimdSignal(UserValue
):
311 # XXX ################################################### XXX
312 # XXX Keep these functions in the same order as ast.Value XXX
313 # XXX ################################################### XXX
314 def __init__(self
, mask
, shape
=None, *args
,
315 src_loc_at
=0, fixed_width
=None, **kwargs
):
316 super().__init
__(src_loc_at
=src_loc_at
)
317 print("SimdSignal shape", shape
)
318 # create partition points
319 if isinstance(mask
, SimdScope
): # mask parameter is a SimdScope
321 self
.ptype
= ElwidPartType(self
)
322 # SimdShapes can be created with an empty scope. check that now
323 if isinstance(shape
, SimdScope
):
324 if shape
.scope
is None:
325 shape
= SimdScope
.like(shape
, scope
=self
.scope
)
327 # adapt shape to a SimdShape
328 shape
= SimdShape(self
.scope
, shape
, fixed_width
=fixed_width
)
330 self
.sig
= Signal(shape
, *args
, **kwargs
)
331 # get partpoints from SimdShape
332 self
.partpoints
= shape
.partpoints
334 self
.sig
= Signal(shape
, *args
, **kwargs
)
335 width
= len(self
.sig
) # get signal width
336 if isinstance(mask
, PartitionPoints
):
337 self
.partpoints
= mask
339 self
.partpoints
= make_partition2(mask
, width
)
340 self
.ptype
= PartType(self
)
342 def set_module(self
, m
):
345 def get_modname(self
, category
):
346 modnames
[category
] += 1
347 return "%s_%d" % (category
, modnames
[category
])
350 def like(other
, *args
, **kwargs
):
351 """Builds a new SimdSignal with the same PartitionPoints and
352 Signal properties as the other"""
353 result
= SimdSignal(PartitionPoints(other
.partpoints
))
354 result
.sig
= Signal
.like(other
.sig
, *args
, **kwargs
)
361 # nmigen-redirected constructs (Mux, Cat, Switch, Assign)
363 # TODO, http://bugs.libre-riscv.org/show_bug.cgi?id=716
364 # def __Part__(self, offset, width, stride=1, *, src_loc_at=0):
365 raise NotImplementedError("TODO: implement as "
366 "(self>>(offset*stride)[:width]")
367 # TODO, http://bugs.libre-riscv.org/show_bug.cgi?id=716
369 def __Slice__(self
, start
, stop
, *, src_loc_at
=0):
370 # NO. Swizzled shall NOT be deployed, it violates
371 # Project Development Practices
372 raise NotImplementedError("TODO: need PartitionedSlice")
374 def __Repl__(self
, count
, *, src_loc_at
=0):
375 return PRepl(self
.m
, self
, count
, self
.ptype
)
377 def __Cat__(self
, *args
, src_loc_at
=0):
378 print("partsig cat", self
, args
)
379 # TODO: need SwizzledSimdValue-aware Cat
380 args
= [self
] + list(args
)
382 assert isinstance(sig
, SimdSignal
), \
383 "All SimdSignal.__Cat__ arguments must be " \
384 "a SimdSignal. %s is not." % repr(sig
)
385 return PCat(self
.m
, args
, self
.ptype
)
387 def __Mux__(self
, val1
, val2
):
388 # print ("partsig mux", self, val1, val2)
389 assert len(val1
) == len(val2
), \
390 "SimdSignal width sources must be the same " \
391 "val1 == %d, val2 == %d" % (len(val1
), len(val2
))
392 return PMux(self
.m
, self
.partpoints
, self
, val1
, val2
, self
.ptype
)
394 def __Assign__(self
, val
, *, src_loc_at
=0):
395 print("partsig assign", self
, val
)
396 # this is a truly awful hack, outlined here:
397 # https://bugs.libre-soc.org/show_bug.cgi?id=731#c13
398 # during the period between constructing Simd-aware sub-modules
399 # and the elaborate() being called on them there is a window of
400 # opportunity to indicate which of those submodules is LHS and
401 # which is RHS. manic laughter is permitted. *gibber*.
402 if hasattr(self
, "_hack_submodule"):
403 self
._hack
_submodule
.set_lhs_mode(True)
404 if hasattr(val
, "_hack_submodule"):
405 val
._hack
_submodule
.set_lhs_mode(False)
406 return PAssign(self
.m
, self
, val
, self
.ptype
)
408 # TODO, http://bugs.libre-riscv.org/show_bug.cgi?id=458
409 # def __Switch__(self, cases, *, src_loc=None, src_loc_at=0,
412 # no override needed, Value.__bool__ sufficient
413 # def __bool__(self):
415 # unary ops that do not require partitioning
417 def __invert__(self
):
418 result
= SimdSignal
.like(self
)
419 self
.m
.d
.comb
+= result
.sig
.eq(~self
.sig
)
422 # unary ops that require partitioning
425 z
= Const(0, len(self
.sig
))
426 result
, _
= self
.sub_op(z
, self
)
429 # binary ops that need partitioning
431 def add_op(self
, op1
, op2
, carry
):
434 pa
= PartitionedAdder(len(op1
), self
.partpoints
)
435 setattr(self
.m
.submodules
, self
.get_modname('add'), pa
)
439 comb
+= pa
.carry_in
.eq(carry
)
440 result
= SimdSignal
.like(self
)
441 comb
+= result
.sig
.eq(pa
.output
)
442 return result
, pa
.carry_out
444 def sub_op(self
, op1
, op2
, carry
=~
0):
447 pa
= PartitionedAdder(len(op1
), self
.partpoints
)
448 setattr(self
.m
.submodules
, self
.get_modname('add'), pa
)
451 comb
+= pa
.b
.eq(~op2
)
452 comb
+= pa
.carry_in
.eq(carry
)
453 result
= SimdSignal
.like(self
)
454 comb
+= result
.sig
.eq(pa
.output
)
455 return result
, pa
.carry_out
457 def __add__(self
, other
):
458 result
, _
= self
.add_op(self
, other
, carry
=0)
461 def __radd__(self
, other
):
462 # https://bugs.libre-soc.org/show_bug.cgi?id=718
463 result
, _
= self
.add_op(other
, self
)
466 def __sub__(self
, other
):
467 result
, _
= self
.sub_op(self
, other
)
470 def __rsub__(self
, other
):
471 # https://bugs.libre-soc.org/show_bug.cgi?id=718
472 result
, _
= self
.sub_op(other
, self
)
475 def __mul__(self
, other
):
476 raise NotImplementedError # too complicated at the moment
477 return Operator("*", [self
, other
])
479 def __rmul__(self
, other
):
480 raise NotImplementedError # too complicated at the moment
481 return Operator("*", [other
, self
])
483 # not needed: same as Value.__check_divisor
484 # def __check_divisor(self):
486 def __mod__(self
, other
):
487 raise NotImplementedError
488 other
= Value
.cast(other
)
489 other
.__check
_divisor
()
490 return Operator("%", [self
, other
])
492 def __rmod__(self
, other
):
493 raise NotImplementedError
494 self
.__check
_divisor
()
495 return Operator("%", [other
, self
])
497 def __floordiv__(self
, other
):
498 raise NotImplementedError
499 other
= Value
.cast(other
)
500 other
.__check
_divisor
()
501 return Operator("//", [self
, other
])
503 def __rfloordiv__(self
, other
):
504 raise NotImplementedError
505 self
.__check
_divisor
()
506 return Operator("//", [other
, self
])
508 # not needed: same as Value.__check_shamt
509 # def __check_shamt(self):
511 # TODO: detect if the 2nd operand is a Const, a Signal or a
512 # SimdSignal. if it's a Const or a Signal, a global shift
513 # can occur. if it's a SimdSignal, that's much more interesting.
514 def ls_op(self
, op1
, op2
, carry
, shr_flag
=0):
516 if isinstance(op2
, Const
) or isinstance(op2
, Signal
):
518 pa
= PartitionedScalarShift(len(op1
), self
.partpoints
)
522 pa
= PartitionedDynamicShift(len(op1
), self
.partpoints
)
524 # TODO: case where the *shifter* is a SimdSignal but
525 # the thing *being* Shifted is a scalar (Signal, expression)
526 # https://bugs.libre-soc.org/show_bug.cgi?id=718
527 setattr(self
.m
.submodules
, self
.get_modname('ls'), pa
)
530 comb
+= pa
.data
.eq(op1
)
531 comb
+= pa
.shifter
.eq(op2
)
532 comb
+= pa
.shift_right
.eq(shr_flag
)
536 comb
+= pa
.shift_right
.eq(shr_flag
)
537 # XXX TODO: carry-in, carry-out (for arithmetic shift)
538 #comb += pa.carry_in.eq(carry)
539 return (pa
.output
, 0)
541 def __lshift__(self
, other
):
542 z
= Const(0, len(self
.partpoints
)+1)
543 result
, _
= self
.ls_op(self
, other
, carry
=z
) # TODO, carry
546 def __rlshift__(self
, other
):
547 # https://bugs.libre-soc.org/show_bug.cgi?id=718
548 raise NotImplementedError
549 return Operator("<<", [other
, self
])
551 def __rshift__(self
, other
):
552 z
= Const(0, len(self
.partpoints
)+1)
553 result
, _
= self
.ls_op(self
, other
, carry
=z
, shr_flag
=1) # TODO, carry
556 def __rrshift__(self
, other
):
557 # https://bugs.libre-soc.org/show_bug.cgi?id=718
558 raise NotImplementedError
559 return Operator(">>", [other
, self
])
561 # binary ops that don't require partitioning
563 def __and__(self
, other
):
564 return applyop(self
, other
, and_
)
566 def __rand__(self
, other
):
567 return applyop(other
, self
, and_
)
569 def __or__(self
, other
):
570 return applyop(self
, other
, or_
)
572 def __ror__(self
, other
):
573 return applyop(other
, self
, or_
)
575 def __xor__(self
, other
):
576 return applyop(self
, other
, xor
)
578 def __rxor__(self
, other
):
579 return applyop(other
, self
, xor
)
581 # binary comparison ops that need partitioning
583 def _compare(self
, width
, op1
, op2
, opname
, optype
):
584 # print (opname, op1, op2)
585 pa
= PartitionedEqGtGe(width
, self
.partpoints
)
586 setattr(self
.m
.submodules
, self
.get_modname(opname
), pa
)
588 comb
+= pa
.opcode
.eq(optype
) # set opcode
589 if isinstance(op1
, SimdSignal
):
590 comb
+= pa
.a
.eq(op1
.sig
)
593 if isinstance(op2
, SimdSignal
):
594 comb
+= pa
.b
.eq(op2
.sig
)
599 def __eq__(self
, other
):
600 width
= len(self
.sig
)
601 return self
._compare
(width
, self
, other
, "eq", PartitionedEqGtGe
.EQ
)
603 def __ne__(self
, other
):
604 width
= len(self
.sig
)
605 eq
= self
._compare
(width
, self
, other
, "eq", PartitionedEqGtGe
.EQ
)
606 ne
= Signal(eq
.width
)
607 self
.m
.d
.comb
+= ne
.eq(~eq
)
610 def __lt__(self
, other
):
611 width
= len(self
.sig
)
612 # swap operands, use gt to do lt
613 return self
._compare
(width
, other
, self
, "gt", PartitionedEqGtGe
.GT
)
615 def __le__(self
, other
):
616 width
= len(self
.sig
)
617 # swap operands, use ge to do le
618 return self
._compare
(width
, other
, self
, "ge", PartitionedEqGtGe
.GE
)
620 def __gt__(self
, other
):
621 width
= len(self
.sig
)
622 return self
._compare
(width
, self
, other
, "gt", PartitionedEqGtGe
.GT
)
624 def __ge__(self
, other
):
625 width
= len(self
.sig
)
626 return self
._compare
(width
, self
, other
, "ge", PartitionedEqGtGe
.GE
)
628 # no override needed: Value.__abs__ is general enough it does the job
634 # TODO, http://bugs.libre-riscv.org/show_bug.cgi?id=716
635 # def __getitem__(self, key):
637 def __new_sign(self
, signed
):
638 # XXX NO - SimdShape not Shape
639 print("XXX requires SimdShape not Shape")
640 shape
= Shape(len(self
), signed
=signed
)
641 result
= SimdSignal
.like(self
, shape
=shape
)
642 self
.m
.d
.comb
+= result
.sig
.eq(self
.sig
)
645 # http://bugs.libre-riscv.org/show_bug.cgi?id=719
646 def as_unsigned(self
):
647 return self
.__new
_sign
(False)
650 return self
.__new
_sign
(True)
655 """Conversion to boolean.
660 ``1`` if any bits are set, ``0`` otherwise.
662 width
= len(self
.sig
)
663 pa
= PartitionedBool(width
, self
.partpoints
)
664 setattr(self
.m
.submodules
, self
.get_modname("bool"), pa
)
665 self
.m
.d
.comb
+= pa
.a
.eq(self
.sig
)
669 """Check if any bits are ``1``.
674 ``1`` if any bits are set, ``0`` otherwise.
676 return self
!= Const(0) # leverage the __ne__ operator here
677 return Operator("r|", [self
])
680 """Check if all bits are ``1``.
685 ``1`` if all bits are set, ``0`` otherwise.
687 # something wrong with PartitionedAll, but self == Const(-1)"
688 # XXX https://bugs.libre-soc.org/show_bug.cgi?id=176#c17
689 #width = len(self.sig)
690 #pa = PartitionedAll(width, self.partpoints)
691 #setattr(self.m.submodules, self.get_modname("all"), pa)
692 #self.m.d.comb += pa.a.eq(self.sig)
694 return self
== Const(-1) # leverage the __eq__ operator here
697 """Compute pairwise exclusive-or of every bit.
702 ``1`` if an odd number of bits are set, ``0`` if an
703 even number of bits are set.
705 width
= len(self
.sig
)
706 pa
= PartitionedXOR(width
, self
.partpoints
)
707 setattr(self
.m
.submodules
, self
.get_modname("xor"), pa
)
708 self
.m
.d
.comb
+= pa
.a
.eq(self
.sig
)
711 # not needed: Value.implies does the job
712 # def implies(premise, conclusion):
714 # TODO. contains a Value.cast which means an override is needed (on both)
715 # def bit_select(self, offset, width):
716 # def word_select(self, offset, width):
718 # not needed: Value.matches, amazingly, should do the job
719 # def matches(self, *patterns):
721 # TODO, http://bugs.libre-riscv.org/show_bug.cgi?id=713
723 return self
.sig
.shape()
726 # temporary to allow tracking back through git revision history
727 PartitionedSignal
= SimdSignal