[libre-riscv-dev] mind melting meta classing

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


http://git.libre-riscv.org/?p=ieee754fpu.git;a=blob;f=src/ieee754/pipeline.py;h=2e57245920126fdd75c97b2c6fe4792f25e8ca43;hb=9d91ad05b8944ea652cfd4f050dbe6837e4332f8

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.

L.



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


More information about the libre-riscv-dev mailing list