Skip to content

Instantly share code, notes, and snippets.

@soronpo
soronpo / cell_histogram.scala
Created August 5, 2026 13:10
DFHDL #449 minimized - 2 designs, 31 lines
import dfhdl.*
class cell_histogram(
val IMAGE_WIDTH: Int <> CONST = 640,
val INPUT_BIN_WIDTH: Int <> CONST = 11,
val OUTPUT_BIN_WIDTH: Int <> CONST = 14
) extends EDDesign:
val BINS: Int <> CONST = 9 + 1
val PARTIAL_HISTOGRAM_WIDTH: Int <> CONST = INPUT_BIN_WIDTH * BINS
val CELLS_PER_ROW: Int <> CONST = IMAGE_WIDTH / 8
val histogram_adder = new partial_histogram_add(
@soronpo
soronpo / cell_histogram.scala
Created August 5, 2026 12:59
DFHDL #449 minimized - 2 files, 63 lines
import dfhdl.*
class cell_histogram(
val IMAGE_WIDTH: Int <> CONST = 640,
val INPUT_BIN_WIDTH: Int <> CONST = 11,
val OUTPUT_BIN_WIDTH: Int <> CONST = 14
) extends EDDesign:
val BINS: Int <> CONST = 9 + 1
val PARTIAL_HISTOGRAM_WIDTH: Int <> CONST = INPUT_BIN_WIDTH * BINS
val CELLS_PER_ROW: Int <> CONST = IMAGE_WIDTH / 8
val cell_buff = new lin_buff(
@soronpo
soronpo / binning.scala
Created August 5, 2026 12:45
DFHDL #449 minimized - 7 files, 95 lines, no ports
import dfhdl.*
class binning(
val DATA_WIDTH: Int <> CONST = 8,
val IMAGE_WIDTH: Int <> CONST = 640,
val IMAGE_HEIGHT: Int <> CONST = 480
) extends EDDesign:
val image_line_buff = new lin_buff(
BUFFER_WIDTH = DATA_WIDTH, BUFFER_DEPTH = IMAGE_WIDTH,
BLOCK_WIDTH = 3, BLOCK_HEIGHT = 3)
@soronpo
soronpo / abs.scala
Created August 5, 2026 12:22
DFHDL #449 minimized - 8 files, 262 lines
import dfhdl.*
// unreferenced by anything; present in the compilation unit only
class abs(val DATA_WIDTH: Int <> CONST = 8) extends EDDesign:
val i = Bits(DATA_WIDTH) <> IN
val o = Bits(DATA_WIDTH) <> OUT
o <> i
@soronpo
soronpo / abs.scala
Last active August 5, 2026 11:54
DFHDL #449 - stale elaboration cache repro (17 files + script)
import dfhdl.*
class abs(
val DATA_WIDTH: Int <> CONST = 8
) extends EDDesign:
val data_in1, data_in2 = Bits(DATA_WIDTH + 1) <> IN
val is_upper_bin = Bit <> OUT
val data_out1, data_out2 = Bits(DATA_WIDTH) <> OUT
val input_sign1, input_sign2 = Bit <> VAR
@soronpo
soronpo / AES.scala
Created December 22, 2022 14:57
DFiant HDL AES Encryption
package AES
import dfhdl.{apply => _, *}
export dfhdl.apply
import scala.annotation.targetName
//////////////////////////////////////////////////////////////////////////////////////////////////////
// AES Byte
//////////////////////////////////////////////////////////////////////////////////////////////////////
```
Exception in thread "pool-5-thread-2" java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:163)
at dotty.tools.dotc.ast.tpd$.New(tpd.scala:494)
at dotty.tools.dotc.core.Annotations$Annotation$.apply(Annotations.scala:191)
at dotty.tools.dotc.core.Annotations$Annotation$.apply(Annotations.scala:182)
at dotty.tools.dotc.core.classfile.ClassfileParser.parseAttribute$1(ClassfileParser.scala:734)
at dotty.tools.dotc.core.classfile.ClassfileParser.parseAttributes$$anonfun$1(ClassfileParser.scala:792)
at scala.runtime.java8.JFunction1$mcVI$sp.apply(JFunction1$mcVI$sp.scala:18)
@soronpo
soronpo / gist:64d5548fb5a544e3b9d9d4f1717b4722
Created October 17, 2021 12:47
Full stack trace error
error] dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; type OutW#32239 in trait CompanionsDFBits$Token$Candidate, defined in Period(1..55, run = 2), is referred to in run Period(1..1, run = 3)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.staleSymbolError(Denotations.scala:955)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:754)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:803)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:877)
[error] dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:122)
[error] dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:116)
[error] dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:109)
[error] dotty.tools.dotc.core.Symbols$.toDenot(Symbols.scala:494)
[error] dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:2493)
@soronpo
soronpo / CPU.scala
Last active September 29, 2021 12:49
//This is a DFiant-equivalent design of https://github.com/tommythorn/silice-examples/blob/master/cpu.ice
import DFiant.*
class CPU(using DFC) extends DFDesign:
val leds = DFBits(8) <> OUT
val rf = DFBits(32).X(16) <> VAR init Vector(
0, 1, 1, 0, 100, 0, 1
).padTo(16, 0).map(_.toBits(32))
// A add, B blt
val code = DFBits(32).X(32) const Vector(
2019-12-24 00:34:03
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.231-b11 mixed mode):
"classloader-cache-cleanup-0" #13 daemon prio=5 os_prio=0 tid=0x00000000560d6000 nid=0x41c in Object.wait() [0x000000005b2ef000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000c14784a8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(Unknown Source)
- locked <0x00000000c14784a8> (a java.lang.ref.ReferenceQueue$Lock)
at sbt.internal.classpath.ClassLoaderCache$CleanupThread.run(ClassLoaderCache.scala:102)