From 23345de129714605c6b63e136b439c99dee72c68 Mon Sep 17 00:00:00 2001 From: lkcl Date: Sat, 9 Oct 2021 15:38:46 +0100 Subject: [PATCH] --- 3d_gpu/architecture/dynamic_simd/shape.mdwn | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/3d_gpu/architecture/dynamic_simd/shape.mdwn b/3d_gpu/architecture/dynamic_simd/shape.mdwn index 6cb0259ed..8be82debf 100644 --- a/3d_gpu/architecture/dynamic_simd/shape.mdwn +++ b/3d_gpu/architecture/dynamic_simd/shape.mdwn @@ -102,4 +102,28 @@ occur on `Shape.width`. >>> print(x2.signed) True +With this capability it becomes possible to use the Liskov Substitution +Principle in dynamically compiling code that switches between scalar and +SIMD: + + # scalar context + scalarctx = scl = object() + scl.XLEN = 64 + scl.SigKls = Signal + # SIMD context + simdctx = sdc = object() + sdc = SimdShape(64, ....) + sdc.SigKls = SimdSignal + sdc.elwidth = Signal(2) + # select one + if compiletime_switch == 'SIMD': + ctx = simdctx + else: + ctx = scalarctx + + # exact same code switching context at compile time + m = Module(): + with ctx: + x = ctx.SigKls(ctx.XLEN) + ... -- 2.30.2