[libre-riscv-dev] mind melting meta classing

Luke Kenneth Casson Leighton lkcl at lkcl.net
Wed Jul 31 01:02:08 BST 2019


We have around 50 places where SimpleHandshake needs to be *optionally*
replaced at the choice of the users of the IEEE754 FPU API.

Some people, wishing to do an in-order design, would use a "stall capable"
pipeline class that has a global signal telling all classes to stop until
data is ready.

For simple 6600 style designs, a non stalling straight through pipe would
be used.

For our purposes, we need "global immediate cancellation".

It would be absolutely insane to duplicate 50+ classes using a "Mixin"
multiple inheritance scheme, so I asked on stackexchange and someone helped
with python metaclassing.

What we now have is a way to specify, at the top level of the multiple
inheritance tree, in the PipelineSpec object, which class shall
*DYNAMICALLY* be mixed into the pipeline objects.

As in: the class to inherit from, half way down the inheritance tree, is a
PARAMETER, *NOT* a statically derived class.

This means that by changing that *parameter* - the class - all three of the
scenarios above can be done with the same code, *without* needing to create
3 sets of identical 50-duplicated classes.

The technique is extremely obscure and could have a far easier syntax,
however it works.

The next task will be to create the "Cancellable" pipeline, and test it.


crowd-funded eco-conscious hardware: https://www.crowdsupply.com/eoma68

More information about the libre-riscv-dev mailing list