(no commit message)
authorlkcl <lkcl@web>
Sat, 9 Oct 2021 14:38:46 +0000 (15:38 +0100)
committerIkiWiki <ikiwiki.info>
Sat, 9 Oct 2021 14:38:46 +0000 (15:38 +0100)
3d_gpu/architecture/dynamic_simd/shape.mdwn

index 6cb0259ed18e62d2fb09a12fb8e30937296262cc..8be82debf35add23c77dd1f4e4f2e5d4fbfd1036 100644 (file)
@@ -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)
+        ...